blob: 76c607f707891f2f65b16916c9078dda00d52ca4 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- 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"
Caroline Tice98f930f2010-09-20 05:20:02 +000011#include "lldb/API/SBStream.h"
Caroline Tice7826c882010-10-26 03:11:13 +000012#include "lldb/Core/Log.h"
Greg Clayton49ce6822010-10-31 03:01:06 +000013#include "lldb/Symbol/Function.h"
14#include "lldb/Symbol/Symbol.h"
15#include "lldb/Symbol/SymbolContext.h"
Chris Lattner24943d22010-06-08 16:52:24 +000016
17using namespace lldb;
18using namespace lldb_private;
19
20
21
22SBSymbolContext::SBSymbolContext () :
Greg Clayton63094e02010-06-23 01:19:29 +000023 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000024{
25}
26
27SBSymbolContext::SBSymbolContext (const SymbolContext *sc_ptr) :
Greg Clayton63094e02010-06-23 01:19:29 +000028 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000029{
30 if (sc_ptr)
Greg Clayton63094e02010-06-23 01:19:29 +000031 m_opaque_ap.reset (new SymbolContext (*sc_ptr));
Chris Lattner24943d22010-06-08 16:52:24 +000032}
33
34SBSymbolContext::SBSymbolContext (const SBSymbolContext& rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +000035 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000036{
37 if (rhs.IsValid())
Caroline Ticee49ec182010-09-22 23:01:29 +000038 {
39 if (m_opaque_ap.get())
40 *m_opaque_ap = *rhs.m_opaque_ap;
41 else
42 ref() = *rhs.m_opaque_ap;
43 }
Chris Lattner24943d22010-06-08 16:52:24 +000044}
45
46SBSymbolContext::~SBSymbolContext ()
47{
48}
49
50const SBSymbolContext &
51SBSymbolContext::operator = (const SBSymbolContext &rhs)
52{
53 if (this != &rhs)
54 {
55 if (rhs.IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +000056 m_opaque_ap.reset (new lldb_private::SymbolContext(*rhs.m_opaque_ap.get()));
Chris Lattner24943d22010-06-08 16:52:24 +000057 }
58 return *this;
59}
60
61void
62SBSymbolContext::SetSymbolContext (const SymbolContext *sc_ptr)
63{
64 if (sc_ptr)
65 {
Greg Clayton63094e02010-06-23 01:19:29 +000066 if (m_opaque_ap.get())
67 *m_opaque_ap = *sc_ptr;
Chris Lattner24943d22010-06-08 16:52:24 +000068 else
Greg Clayton63094e02010-06-23 01:19:29 +000069 m_opaque_ap.reset (new SymbolContext (*sc_ptr));
Chris Lattner24943d22010-06-08 16:52:24 +000070 }
71 else
72 {
Greg Clayton63094e02010-06-23 01:19:29 +000073 if (m_opaque_ap.get())
74 m_opaque_ap->Clear();
Chris Lattner24943d22010-06-08 16:52:24 +000075 }
76}
77
78bool
79SBSymbolContext::IsValid () const
80{
Greg Clayton63094e02010-06-23 01:19:29 +000081 return m_opaque_ap.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000082}
83
84
85
86SBModule
87SBSymbolContext::GetModule ()
88{
Greg Claytone005f2c2010-11-06 01:53:30 +000089 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000090
Chris Lattner24943d22010-06-08 16:52:24 +000091 SBModule sb_module;
Greg Clayton63094e02010-06-23 01:19:29 +000092 if (m_opaque_ap.get())
93 sb_module.SetModule(m_opaque_ap->module_sp);
Caroline Tice7826c882010-10-26 03:11:13 +000094
95 if (log)
96 {
97 SBStream sstr;
98 sb_module.GetDescription (sstr);
Greg Claytona66ba462010-10-30 04:51:46 +000099 log->Printf ("SBSymbolContext(%p)::GetModule () => SBModule(%p): %s",
100 m_opaque_ap.get(), sb_module.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000101 }
102
Chris Lattner24943d22010-06-08 16:52:24 +0000103 return sb_module;
104}
105
106SBCompileUnit
107SBSymbolContext::GetCompileUnit ()
108{
Greg Clayton63094e02010-06-23 01:19:29 +0000109 return SBCompileUnit (m_opaque_ap.get() ? m_opaque_ap->comp_unit : NULL);
Chris Lattner24943d22010-06-08 16:52:24 +0000110}
111
112SBFunction
113SBSymbolContext::GetFunction ()
114{
Greg Claytone005f2c2010-11-06 01:53:30 +0000115 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000116
Greg Clayton49ce6822010-10-31 03:01:06 +0000117 Function *function = NULL;
118
119 if (m_opaque_ap.get())
120 function = m_opaque_ap->function;
121
122 SBFunction sb_function (function);
Caroline Tice7826c882010-10-26 03:11:13 +0000123
124 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000125 log->Printf ("SBSymbolContext(%p)::GetFunction () => SBFunction(%p)",
126 m_opaque_ap.get(), function);
Caroline Tice7826c882010-10-26 03:11:13 +0000127
Greg Clayton49ce6822010-10-31 03:01:06 +0000128 return sb_function;
Chris Lattner24943d22010-06-08 16:52:24 +0000129}
130
131SBBlock
132SBSymbolContext::GetBlock ()
133{
Greg Clayton63094e02010-06-23 01:19:29 +0000134 return SBBlock (m_opaque_ap.get() ? m_opaque_ap->block : NULL);
Chris Lattner24943d22010-06-08 16:52:24 +0000135}
136
137SBLineEntry
138SBSymbolContext::GetLineEntry ()
139{
Greg Claytone005f2c2010-11-06 01:53:30 +0000140 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000141
Chris Lattner24943d22010-06-08 16:52:24 +0000142 SBLineEntry sb_line_entry;
Greg Clayton63094e02010-06-23 01:19:29 +0000143 if (m_opaque_ap.get())
144 sb_line_entry.SetLineEntry (m_opaque_ap->line_entry);
Chris Lattner24943d22010-06-08 16:52:24 +0000145
Caroline Tice7826c882010-10-26 03:11:13 +0000146 if (log)
147 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000148 log->Printf ("SBSymbolContext(%p)::GetLineEntry () => SBLineEntry(%p)",
149 m_opaque_ap.get(), sb_line_entry.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000150 }
151
Chris Lattner24943d22010-06-08 16:52:24 +0000152 return sb_line_entry;
153}
154
155SBSymbol
156SBSymbolContext::GetSymbol ()
157{
Greg Claytone005f2c2010-11-06 01:53:30 +0000158 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000159
Greg Clayton49ce6822010-10-31 03:01:06 +0000160 Symbol *symbol = NULL;
161
162 if (m_opaque_ap.get())
163 symbol = m_opaque_ap->symbol;
164
165 SBSymbol sb_symbol (symbol);
Caroline Tice7826c882010-10-26 03:11:13 +0000166
167 if (log)
168 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000169 log->Printf ("SBSymbolContext(%p)::GetSymbol () => SBSymbol(%p)",
170 m_opaque_ap.get(), symbol);
Caroline Tice7826c882010-10-26 03:11:13 +0000171 }
172
Greg Clayton49ce6822010-10-31 03:01:06 +0000173 return sb_symbol;
Chris Lattner24943d22010-06-08 16:52:24 +0000174}
175
176lldb_private::SymbolContext*
177SBSymbolContext::operator->() const
178{
Greg Clayton63094e02010-06-23 01:19:29 +0000179 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000180}
181
Greg Clayton466f6c42010-09-10 18:31:35 +0000182
183const lldb_private::SymbolContext&
184SBSymbolContext::operator*() const
185{
186 assert (m_opaque_ap.get());
187 return *m_opaque_ap.get();
188}
189
190
191lldb_private::SymbolContext&
192SBSymbolContext::operator*()
193{
194 if (m_opaque_ap.get() == NULL)
195 m_opaque_ap.reset (new SymbolContext);
196 return *m_opaque_ap.get();
197}
198
Caroline Ticee49ec182010-09-22 23:01:29 +0000199lldb_private::SymbolContext&
200SBSymbolContext::ref()
201{
202 if (m_opaque_ap.get() == NULL)
203 m_opaque_ap.reset (new SymbolContext);
204 return *m_opaque_ap.get();
205}
206
Chris Lattner24943d22010-06-08 16:52:24 +0000207lldb_private::SymbolContext *
Greg Clayton466f6c42010-09-10 18:31:35 +0000208SBSymbolContext::get() const
Chris Lattner24943d22010-06-08 16:52:24 +0000209{
Greg Clayton63094e02010-06-23 01:19:29 +0000210 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000211}
212
Caroline Tice98f930f2010-09-20 05:20:02 +0000213bool
214SBSymbolContext::GetDescription (SBStream &description)
215{
216 if (m_opaque_ap.get())
217 {
Caroline Ticee49ec182010-09-22 23:01:29 +0000218 description.ref();
Caroline Tice98f930f2010-09-20 05:20:02 +0000219 m_opaque_ap->GetDescription (description.get(), lldb::eDescriptionLevelFull, NULL);
220 }
221 else
222 description.Printf ("No value");
Chris Lattner24943d22010-06-08 16:52:24 +0000223
Caroline Tice98f930f2010-09-20 05:20:02 +0000224 return true;
225}