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/Module.h"
14 #include "lldb/Symbol/Symbol.h"
15 #include "lldb/Target/ExecutionContext.h"
16 #include "lldb/Target/Target.h"
17 #include "lldb/Utility/Log.h"
20 using namespace lldb_private;
22 SBSymbol::SBSymbol() : m_opaque_ptr(NULL) {}
24 SBSymbol::SBSymbol(lldb_private::Symbol *lldb_object_ptr)
25 : m_opaque_ptr(lldb_object_ptr) {}
27 SBSymbol::SBSymbol(const lldb::SBSymbol &rhs)
28 : m_opaque_ptr(rhs.m_opaque_ptr) {}
30 const SBSymbol &SBSymbol::operator=(const SBSymbol &rhs) {
31 m_opaque_ptr = rhs.m_opaque_ptr;
35 SBSymbol::~SBSymbol() { m_opaque_ptr = NULL; }
37 void SBSymbol::SetSymbol(lldb_private::Symbol *lldb_object_ptr) {
38 m_opaque_ptr = lldb_object_ptr;
41 bool SBSymbol::IsValid() const { return m_opaque_ptr != NULL; }
43 const char *SBSymbol::GetName() const {
44 const char *name = NULL;
46 name = m_opaque_ptr->GetName().AsCString();
48 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
50 log->Printf("SBSymbol(%p)::GetName () => \"%s\"",
51 static_cast<void *>(m_opaque_ptr), name ? name : "");
55 const char *SBSymbol::GetDisplayName() const {
56 const char *name = NULL;
58 name = m_opaque_ptr->GetMangled()
59 .GetDisplayDemangledName(m_opaque_ptr->GetLanguage())
62 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
64 log->Printf("SBSymbol(%p)::GetDisplayName () => \"%s\"",
65 static_cast<void *>(m_opaque_ptr), name ? name : "");
69 const char *SBSymbol::GetMangledName() const {
70 const char *name = NULL;
72 name = m_opaque_ptr->GetMangled().GetMangledName().AsCString();
73 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
75 log->Printf("SBSymbol(%p)::GetMangledName () => \"%s\"",
76 static_cast<void *>(m_opaque_ptr), name ? name : "");
81 bool SBSymbol::operator==(const SBSymbol &rhs) const {
82 return m_opaque_ptr == rhs.m_opaque_ptr;
85 bool SBSymbol::operator!=(const SBSymbol &rhs) const {
86 return m_opaque_ptr != rhs.m_opaque_ptr;
89 bool SBSymbol::GetDescription(SBStream &description) {
90 Stream &strm = description.ref();
93 m_opaque_ptr->GetDescription(&strm, lldb::eDescriptionLevelFull, NULL);
95 strm.PutCString("No value");
100 SBInstructionList SBSymbol::GetInstructions(SBTarget target) {
101 return GetInstructions(target, NULL);
104 SBInstructionList SBSymbol::GetInstructions(SBTarget target,
105 const char *flavor_string) {
106 SBInstructionList sb_instructions;
108 ExecutionContext exe_ctx;
109 TargetSP target_sp(target.GetSP());
110 std::unique_lock<std::recursive_mutex> lock;
112 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
114 target_sp->CalculateExecutionContext(exe_ctx);
116 if (m_opaque_ptr->ValueIsAddress()) {
117 const Address &symbol_addr = m_opaque_ptr->GetAddressRef();
118 ModuleSP module_sp = symbol_addr.GetModule();
120 AddressRange symbol_range(symbol_addr, m_opaque_ptr->GetByteSize());
121 const bool prefer_file_cache = false;
122 sb_instructions.SetDisassembler(Disassembler::DisassembleRange(
123 module_sp->GetArchitecture(), NULL, flavor_string, exe_ctx,
124 symbol_range, prefer_file_cache));
128 return sb_instructions;
131 lldb_private::Symbol *SBSymbol::get() { return m_opaque_ptr; }
133 void SBSymbol::reset(lldb_private::Symbol *symbol) { m_opaque_ptr = symbol; }
135 SBAddress SBSymbol::GetStartAddress() {
137 if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress()) {
138 addr.SetAddress(&m_opaque_ptr->GetAddressRef());
143 SBAddress SBSymbol::GetEndAddress() {
145 if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress()) {
146 lldb::addr_t range_size = m_opaque_ptr->GetByteSize();
147 if (range_size > 0) {
148 addr.SetAddress(&m_opaque_ptr->GetAddressRef());
149 addr->Slide(m_opaque_ptr->GetByteSize());
155 uint32_t SBSymbol::GetPrologueByteSize() {
157 return m_opaque_ptr->GetPrologueByteSize();
161 SymbolType SBSymbol::GetType() {
163 return m_opaque_ptr->GetType();
164 return eSymbolTypeInvalid;
167 bool SBSymbol::IsExternal() {
169 return m_opaque_ptr->IsExternal();
173 bool SBSymbol::IsSynthetic() {
175 return m_opaque_ptr->IsSynthetic();