]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/API/SBSymbol.cpp
Vendor import of lldb release_39 branch r276489:
[FreeBSD/FreeBSD.git] / source / API / SBSymbol.cpp
1 //===-- SBSymbol.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/SBSymbol.h"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/Core/Disassembler.h"
13 #include "lldb/Core/Log.h"
14 #include "lldb/Core/Module.h"
15 #include "lldb/Symbol/Symbol.h"
16 #include "lldb/Target/ExecutionContext.h"
17 #include "lldb/Target/Target.h"
18
19 using namespace lldb;
20 using namespace lldb_private;
21
22 SBSymbol::SBSymbol () :
23     m_opaque_ptr (NULL)
24 {
25 }
26
27 SBSymbol::SBSymbol (lldb_private::Symbol *lldb_object_ptr) :
28     m_opaque_ptr (lldb_object_ptr)
29 {
30 }
31
32 SBSymbol::SBSymbol (const lldb::SBSymbol &rhs) :
33     m_opaque_ptr (rhs.m_opaque_ptr)
34 {
35 }
36
37 const SBSymbol &
38 SBSymbol::operator = (const SBSymbol &rhs)
39 {
40     m_opaque_ptr = rhs.m_opaque_ptr;
41     return *this;
42 }
43
44 SBSymbol::~SBSymbol ()
45 {
46     m_opaque_ptr = NULL;
47 }
48
49 void
50 SBSymbol::SetSymbol (lldb_private::Symbol *lldb_object_ptr)
51 {
52     m_opaque_ptr = lldb_object_ptr;
53 }
54
55 bool
56 SBSymbol::IsValid () const
57 {
58     return m_opaque_ptr != NULL;
59 }
60
61 const char *
62 SBSymbol::GetName() const
63 {
64     const char *name = NULL;
65     if (m_opaque_ptr)
66         name = m_opaque_ptr->GetName().AsCString();
67
68     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
69     if (log)
70         log->Printf ("SBSymbol(%p)::GetName () => \"%s\"",
71                      static_cast<void*>(m_opaque_ptr), name ? name : "");
72     return name;
73 }
74
75 const char *
76 SBSymbol::GetDisplayName() const
77 {
78     const char *name = NULL;
79     if (m_opaque_ptr)
80         name = m_opaque_ptr->GetMangled().GetDisplayDemangledName(m_opaque_ptr->GetLanguage()).AsCString();
81     
82     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
83     if (log)
84     log->Printf ("SBSymbol(%p)::GetDisplayName () => \"%s\"",
85                  static_cast<void*>(m_opaque_ptr), name ? name : "");
86     return name;
87 }
88
89 const char *
90 SBSymbol::GetMangledName () const
91 {
92     const char *name = NULL;
93     if (m_opaque_ptr)
94         name = m_opaque_ptr->GetMangled().GetMangledName().AsCString();
95     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
96     if (log)
97         log->Printf ("SBSymbol(%p)::GetMangledName () => \"%s\"",
98                      static_cast<void*>(m_opaque_ptr), name ? name : "");
99
100     return name;
101 }
102
103
104 bool
105 SBSymbol::operator == (const SBSymbol &rhs) const
106 {
107     return m_opaque_ptr == rhs.m_opaque_ptr;
108 }
109
110 bool
111 SBSymbol::operator != (const SBSymbol &rhs) const
112 {
113     return m_opaque_ptr != rhs.m_opaque_ptr;
114 }
115
116 bool
117 SBSymbol::GetDescription (SBStream &description)
118 {
119     Stream &strm = description.ref();
120
121     if (m_opaque_ptr)
122     {
123         m_opaque_ptr->GetDescription (&strm,
124                                       lldb::eDescriptionLevelFull, NULL);
125     }
126     else
127         strm.PutCString ("No value");
128     
129     return true;
130 }
131
132 SBInstructionList
133 SBSymbol::GetInstructions (SBTarget target)
134 {
135     return GetInstructions (target, NULL);
136 }
137
138 SBInstructionList
139 SBSymbol::GetInstructions (SBTarget target, const char *flavor_string)
140 {
141     SBInstructionList sb_instructions;
142     if (m_opaque_ptr)
143     {
144         ExecutionContext exe_ctx;
145         TargetSP target_sp (target.GetSP());
146         std::unique_lock<std::recursive_mutex> lock;
147         if (target_sp)
148         {
149             lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
150
151             target_sp->CalculateExecutionContext (exe_ctx);
152         }
153         if (m_opaque_ptr->ValueIsAddress())
154         {
155             const Address &symbol_addr = m_opaque_ptr->GetAddressRef();
156             ModuleSP module_sp = symbol_addr.GetModule();
157             if (module_sp)
158             {
159                 AddressRange symbol_range (symbol_addr, m_opaque_ptr->GetByteSize());
160                 const bool prefer_file_cache = false;
161                 sb_instructions.SetDisassembler (Disassembler::DisassembleRange (module_sp->GetArchitecture (),
162                                                                                  NULL,
163                                                                                  flavor_string,
164                                                                                  exe_ctx,
165                                                                                  symbol_range,
166                                                                                  prefer_file_cache));
167             }
168         }
169     }
170     return sb_instructions;
171 }
172
173 lldb_private::Symbol *
174 SBSymbol::get ()
175 {
176     return m_opaque_ptr;
177 }
178
179 void
180 SBSymbol::reset (lldb_private::Symbol *symbol)
181 {
182     m_opaque_ptr = symbol;
183 }
184
185 SBAddress
186 SBSymbol::GetStartAddress ()
187 {
188     SBAddress addr;
189     if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress())
190     {
191         addr.SetAddress (&m_opaque_ptr->GetAddressRef());
192     }
193     return addr;
194 }
195
196 SBAddress
197 SBSymbol::GetEndAddress ()
198 {
199     SBAddress addr;
200     if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress())
201     {
202         lldb::addr_t range_size = m_opaque_ptr->GetByteSize();
203         if (range_size > 0)
204         {
205             addr.SetAddress (&m_opaque_ptr->GetAddressRef());
206             addr->Slide (m_opaque_ptr->GetByteSize());
207         }
208     }
209     return addr;
210 }
211
212 uint32_t
213 SBSymbol::GetPrologueByteSize ()
214 {
215     if (m_opaque_ptr)
216         return m_opaque_ptr->GetPrologueByteSize();
217     return 0;
218 }
219
220 SymbolType
221 SBSymbol::GetType ()
222 {
223     if (m_opaque_ptr)
224         return m_opaque_ptr->GetType();
225     return eSymbolTypeInvalid;
226 }
227
228 bool
229 SBSymbol::IsExternal()
230 {
231     if (m_opaque_ptr)
232         return m_opaque_ptr->IsExternal();
233     return false;
234 }
235
236 bool
237 SBSymbol::IsSynthetic()
238 {
239     if (m_opaque_ptr)
240         return m_opaque_ptr->IsSynthetic();
241     return false;
242 }
243