1 //===-- SBSymbolContext.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/SBSymbolContext.h"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/Core/Log.h"
13 #include "lldb/Core/Module.h"
14 #include "lldb/Symbol/Function.h"
15 #include "lldb/Symbol/Symbol.h"
16 #include "lldb/Symbol/SymbolContext.h"
17
18 using namespace lldb;
19 using namespace lldb_private;
20
21
22
SBSymbolContext()23 SBSymbolContext::SBSymbolContext () :
24 m_opaque_ap ()
25 {
26 }
27
SBSymbolContext(const SymbolContext * sc_ptr)28 SBSymbolContext::SBSymbolContext (const SymbolContext *sc_ptr) :
29 m_opaque_ap ()
30 {
31 if (sc_ptr)
32 m_opaque_ap.reset (new SymbolContext (*sc_ptr));
33 }
34
SBSymbolContext(const SBSymbolContext & rhs)35 SBSymbolContext::SBSymbolContext (const SBSymbolContext& rhs) :
36 m_opaque_ap ()
37 {
38 if (rhs.IsValid())
39 {
40 if (m_opaque_ap.get())
41 *m_opaque_ap = *rhs.m_opaque_ap;
42 else
43 ref() = *rhs.m_opaque_ap;
44 }
45 }
46
~SBSymbolContext()47 SBSymbolContext::~SBSymbolContext ()
48 {
49 }
50
51 const SBSymbolContext &
operator =(const SBSymbolContext & rhs)52 SBSymbolContext::operator = (const SBSymbolContext &rhs)
53 {
54 if (this != &rhs)
55 {
56 if (rhs.IsValid())
57 m_opaque_ap.reset (new lldb_private::SymbolContext(*rhs.m_opaque_ap.get()));
58 }
59 return *this;
60 }
61
62 void
SetSymbolContext(const SymbolContext * sc_ptr)63 SBSymbolContext::SetSymbolContext (const SymbolContext *sc_ptr)
64 {
65 if (sc_ptr)
66 {
67 if (m_opaque_ap.get())
68 *m_opaque_ap = *sc_ptr;
69 else
70 m_opaque_ap.reset (new SymbolContext (*sc_ptr));
71 }
72 else
73 {
74 if (m_opaque_ap.get())
75 m_opaque_ap->Clear(true);
76 }
77 }
78
79 bool
IsValid() const80 SBSymbolContext::IsValid () const
81 {
82 return m_opaque_ap.get() != NULL;
83 }
84
85
86
87 SBModule
GetModule()88 SBSymbolContext::GetModule ()
89 {
90 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
91
92 SBModule sb_module;
93 ModuleSP module_sp;
94 if (m_opaque_ap.get())
95 {
96 module_sp = m_opaque_ap->module_sp;
97 sb_module.SetSP (module_sp);
98 }
99
100 if (log)
101 {
102 SBStream sstr;
103 sb_module.GetDescription (sstr);
104 log->Printf ("SBSymbolContext(%p)::GetModule () => SBModule(%p): %s",
105 m_opaque_ap.get(), module_sp.get(), sstr.GetData());
106 }
107
108 return sb_module;
109 }
110
111 SBCompileUnit
GetCompileUnit()112 SBSymbolContext::GetCompileUnit ()
113 {
114 return SBCompileUnit (m_opaque_ap.get() ? m_opaque_ap->comp_unit : NULL);
115 }
116
117 SBFunction
GetFunction()118 SBSymbolContext::GetFunction ()
119 {
120 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
121
122 Function *function = NULL;
123
124 if (m_opaque_ap.get())
125 function = m_opaque_ap->function;
126
127 SBFunction sb_function (function);
128
129 if (log)
130 log->Printf ("SBSymbolContext(%p)::GetFunction () => SBFunction(%p)",
131 m_opaque_ap.get(), function);
132
133 return sb_function;
134 }
135
136 SBBlock
GetBlock()137 SBSymbolContext::GetBlock ()
138 {
139 return SBBlock (m_opaque_ap.get() ? m_opaque_ap->block : NULL);
140 }
141
142 SBLineEntry
GetLineEntry()143 SBSymbolContext::GetLineEntry ()
144 {
145 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
146
147 SBLineEntry sb_line_entry;
148 if (m_opaque_ap.get())
149 sb_line_entry.SetLineEntry (m_opaque_ap->line_entry);
150
151 if (log)
152 {
153 log->Printf ("SBSymbolContext(%p)::GetLineEntry () => SBLineEntry(%p)",
154 m_opaque_ap.get(), sb_line_entry.get());
155 }
156
157 return sb_line_entry;
158 }
159
160 SBSymbol
GetSymbol()161 SBSymbolContext::GetSymbol ()
162 {
163 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
164
165 Symbol *symbol = NULL;
166
167 if (m_opaque_ap.get())
168 symbol = m_opaque_ap->symbol;
169
170 SBSymbol sb_symbol (symbol);
171
172 if (log)
173 {
174 log->Printf ("SBSymbolContext(%p)::GetSymbol () => SBSymbol(%p)",
175 m_opaque_ap.get(), symbol);
176 }
177
178 return sb_symbol;
179 }
180
181 void
SetModule(lldb::SBModule module)182 SBSymbolContext::SetModule (lldb::SBModule module)
183 {
184 ref().module_sp = module.GetSP();
185 }
186
187 void
SetCompileUnit(lldb::SBCompileUnit compile_unit)188 SBSymbolContext::SetCompileUnit (lldb::SBCompileUnit compile_unit)
189 {
190 ref().comp_unit = compile_unit.get();
191 }
192
193 void
SetFunction(lldb::SBFunction function)194 SBSymbolContext::SetFunction (lldb::SBFunction function)
195 {
196 ref().function = function.get();
197 }
198
199 void
SetBlock(lldb::SBBlock block)200 SBSymbolContext::SetBlock (lldb::SBBlock block)
201 {
202 ref().block = block.GetPtr();
203 }
204
205 void
SetLineEntry(lldb::SBLineEntry line_entry)206 SBSymbolContext::SetLineEntry (lldb::SBLineEntry line_entry)
207 {
208 if (line_entry.IsValid())
209 ref().line_entry = line_entry.ref();
210 else
211 ref().line_entry.Clear();
212 }
213
214 void
SetSymbol(lldb::SBSymbol symbol)215 SBSymbolContext::SetSymbol (lldb::SBSymbol symbol)
216 {
217 ref().symbol = symbol.get();
218 }
219
220
221 lldb_private::SymbolContext*
operator ->() const222 SBSymbolContext::operator->() const
223 {
224 return m_opaque_ap.get();
225 }
226
227
228 const lldb_private::SymbolContext&
operator *() const229 SBSymbolContext::operator*() const
230 {
231 assert (m_opaque_ap.get());
232 return *m_opaque_ap.get();
233 }
234
235
236 lldb_private::SymbolContext&
operator *()237 SBSymbolContext::operator*()
238 {
239 if (m_opaque_ap.get() == NULL)
240 m_opaque_ap.reset (new SymbolContext);
241 return *m_opaque_ap.get();
242 }
243
244 lldb_private::SymbolContext&
ref()245 SBSymbolContext::ref()
246 {
247 if (m_opaque_ap.get() == NULL)
248 m_opaque_ap.reset (new SymbolContext);
249 return *m_opaque_ap.get();
250 }
251
252 lldb_private::SymbolContext *
get() const253 SBSymbolContext::get() const
254 {
255 return m_opaque_ap.get();
256 }
257
258 bool
GetDescription(SBStream & description)259 SBSymbolContext::GetDescription (SBStream &description)
260 {
261 Stream &strm = description.ref();
262
263 if (m_opaque_ap.get())
264 {
265 m_opaque_ap->GetDescription (&strm, lldb::eDescriptionLevelFull, NULL);
266 }
267 else
268 strm.PutCString ("No value");
269
270 return true;
271 }
272
273 SBSymbolContext
GetParentOfInlinedScope(const SBAddress & curr_frame_pc,SBAddress & parent_frame_addr) const274 SBSymbolContext::GetParentOfInlinedScope (const SBAddress &curr_frame_pc,
275 SBAddress &parent_frame_addr) const
276 {
277 SBSymbolContext sb_sc;
278 if (m_opaque_ap.get() && curr_frame_pc.IsValid())
279 {
280 if (m_opaque_ap->GetParentOfInlinedScope (curr_frame_pc.ref(), sb_sc.ref(), parent_frame_addr.ref()))
281 return sb_sc;
282 }
283 return SBSymbolContext();
284 }
285
286