1 //===-- SBBlock.cpp ---------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "lldb/API/SBBlock.h"
11 #include "lldb/API/SBFileSpec.h"
12 #include "lldb/API/SBStream.h"
13 #include "lldb/Symbol/Block.h"
14 #include "lldb/Symbol/Function.h"
15 #include "lldb/Symbol/SymbolContext.h"
16 
17 using namespace lldb;
18 using namespace lldb_private;
19 
20 
21 SBBlock::SBBlock () :
22     m_opaque_ptr (NULL)
23 {
24 }
25 
26 SBBlock::SBBlock (lldb_private::Block *lldb_object_ptr) :
27     m_opaque_ptr (lldb_object_ptr)
28 {
29 }
30 
31 SBBlock::SBBlock(const SBBlock &rhs) :
32     m_opaque_ptr (rhs.m_opaque_ptr)
33 {
34 }
35 
36 const SBBlock &
37 SBBlock::operator = (const SBBlock &rhs)
38 {
39     m_opaque_ptr = rhs.m_opaque_ptr;
40     return *this;
41 }
42 
43 SBBlock::~SBBlock ()
44 {
45     m_opaque_ptr = NULL;
46 }
47 
48 bool
49 SBBlock::IsValid () const
50 {
51     return m_opaque_ptr != NULL;
52 }
53 
54 bool
55 SBBlock::IsInlined () const
56 {
57     if (m_opaque_ptr)
58         return m_opaque_ptr->GetInlinedFunctionInfo () != NULL;
59     return false;
60 }
61 
62 const char *
63 SBBlock::GetInlinedName () const
64 {
65     if (m_opaque_ptr)
66     {
67         const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo ();
68         if (inlined_info)
69             return inlined_info->GetName().AsCString (NULL);
70     }
71     return NULL;
72 }
73 
74 SBFileSpec
75 SBBlock::GetInlinedCallSiteFile () const
76 {
77     SBFileSpec sb_file;
78     if (m_opaque_ptr)
79     {
80         const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo ();
81         if (inlined_info)
82             sb_file.SetFileSpec (inlined_info->GetCallSite().GetFile());
83     }
84     return sb_file;
85 }
86 
87 uint32_t
88 SBBlock::GetInlinedCallSiteLine () const
89 {
90     if (m_opaque_ptr)
91     {
92         const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo ();
93         if (inlined_info)
94             return inlined_info->GetCallSite().GetLine();
95     }
96     return 0;
97 }
98 
99 uint32_t
100 SBBlock::GetInlinedCallSiteColumn () const
101 {
102     if (m_opaque_ptr)
103     {
104         const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo ();
105         if (inlined_info)
106             return inlined_info->GetCallSite().GetColumn();
107     }
108     return 0;
109 }
110 
111 void
112 SBBlock::AppendVariables (bool can_create, bool get_parent_variables, lldb_private::VariableList *var_list)
113 {
114     if (IsValid())
115     {
116         bool show_inline = true;
117         m_opaque_ptr->AppendVariables (can_create, get_parent_variables, show_inline, var_list);
118     }
119 }
120 
121 SBBlock
122 SBBlock::GetParent ()
123 {
124     SBBlock sb_block;
125     if (m_opaque_ptr)
126         sb_block.m_opaque_ptr = m_opaque_ptr->GetParent();
127     return sb_block;
128 }
129 
130 SBBlock
131 SBBlock::GetSibling ()
132 {
133     SBBlock sb_block;
134     if (m_opaque_ptr)
135         sb_block.m_opaque_ptr = m_opaque_ptr->GetSibling();
136     return sb_block;
137 }
138 
139 SBBlock
140 SBBlock::GetFirstChild ()
141 {
142     SBBlock sb_block;
143     if (m_opaque_ptr)
144         sb_block.m_opaque_ptr = m_opaque_ptr->GetFirstChild();
145     return sb_block;
146 }
147 
148 const lldb_private::Block *
149 SBBlock::get () const
150 {
151     return m_opaque_ptr;
152 }
153 
154 void
155 SBBlock::reset (lldb_private::Block *block)
156 {
157     m_opaque_ptr = block;
158 }
159 
160 bool
161 SBBlock::GetDescription (SBStream &description)
162 {
163     if (m_opaque_ptr)
164     {
165         lldb::user_id_t id = m_opaque_ptr->GetID();
166         description.Printf ("Block: {id: %d} ", id);
167         if (IsInlined())
168         {
169             description.Printf (" (inlined, '%s') ", GetInlinedName());
170         }
171         lldb_private::SymbolContext sc;
172         m_opaque_ptr->CalculateSymbolContext (&sc);
173         if (sc.function)
174         {
175             m_opaque_ptr->DumpAddressRanges (description.get(),
176                                              sc.function->GetAddressRange().GetBaseAddress().GetFileAddress());
177         }
178     }
179     else
180         description.Printf ("No value");
181 
182     return true;
183 }
184