1 //===-- SBSymbol.cpp --------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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"
20 using namespace lldb_private;
22 SBSymbol::SBSymbol () :
27 SBSymbol::SBSymbol (lldb_private::Symbol *lldb_object_ptr) :
28 m_opaque_ptr (lldb_object_ptr)
32 SBSymbol::SBSymbol (const lldb::SBSymbol &rhs) :
33 m_opaque_ptr (rhs.m_opaque_ptr)
38 SBSymbol::operator = (const SBSymbol &rhs)
40 m_opaque_ptr = rhs.m_opaque_ptr;
44 SBSymbol::~SBSymbol ()
50 SBSymbol::SetSymbol (lldb_private::Symbol *lldb_object_ptr)
52 m_opaque_ptr = lldb_object_ptr;
56 SBSymbol::IsValid () const
58 return m_opaque_ptr != NULL;
62 SBSymbol::GetName() const
64 const char *name = NULL;
66 name = m_opaque_ptr->GetName().AsCString();
68 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
70 log->Printf ("SBSymbol(%p)::GetName () => \"%s\"",
71 static_cast<void*>(m_opaque_ptr), name ? name : "");
76 SBSymbol::GetDisplayName() const
78 const char *name = NULL;
80 name = m_opaque_ptr->GetMangled().GetDisplayDemangledName(m_opaque_ptr->GetLanguage()).AsCString();
82 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
84 log->Printf ("SBSymbol(%p)::GetDisplayName () => \"%s\"",
85 static_cast<void*>(m_opaque_ptr), name ? name : "");
90 SBSymbol::GetMangledName () const
92 const char *name = NULL;
94 name = m_opaque_ptr->GetMangled().GetMangledName().AsCString();
95 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
97 log->Printf ("SBSymbol(%p)::GetMangledName () => \"%s\"",
98 static_cast<void*>(m_opaque_ptr), name ? name : "");
105 SBSymbol::operator == (const SBSymbol &rhs) const
107 return m_opaque_ptr == rhs.m_opaque_ptr;
111 SBSymbol::operator != (const SBSymbol &rhs) const
113 return m_opaque_ptr != rhs.m_opaque_ptr;
117 SBSymbol::GetDescription (SBStream &description)
119 Stream &strm = description.ref();
123 m_opaque_ptr->GetDescription (&strm,
124 lldb::eDescriptionLevelFull, NULL);
127 strm.PutCString ("No value");
133 SBSymbol::GetInstructions (SBTarget target)
135 return GetInstructions (target, NULL);
139 SBSymbol::GetInstructions (SBTarget target, const char *flavor_string)
141 SBInstructionList sb_instructions;
144 ExecutionContext exe_ctx;
145 TargetSP target_sp (target.GetSP());
146 std::unique_lock<std::recursive_mutex> lock;
149 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
151 target_sp->CalculateExecutionContext (exe_ctx);
153 if (m_opaque_ptr->ValueIsAddress())
155 const Address &symbol_addr = m_opaque_ptr->GetAddressRef();
156 ModuleSP module_sp = symbol_addr.GetModule();
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 (),
170 return sb_instructions;
173 lldb_private::Symbol *
180 SBSymbol::reset (lldb_private::Symbol *symbol)
182 m_opaque_ptr = symbol;
186 SBSymbol::GetStartAddress ()
189 if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress())
191 addr.SetAddress (&m_opaque_ptr->GetAddressRef());
197 SBSymbol::GetEndAddress ()
200 if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress())
202 lldb::addr_t range_size = m_opaque_ptr->GetByteSize();
205 addr.SetAddress (&m_opaque_ptr->GetAddressRef());
206 addr->Slide (m_opaque_ptr->GetByteSize());
213 SBSymbol::GetPrologueByteSize ()
216 return m_opaque_ptr->GetPrologueByteSize();
224 return m_opaque_ptr->GetType();
225 return eSymbolTypeInvalid;
229 SBSymbol::IsExternal()
232 return m_opaque_ptr->IsExternal();
237 SBSymbol::IsSynthetic()
240 return m_opaque_ptr->IsSynthetic();