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->GetMangled().GetName().AsCString();
68 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
70 log->Printf ("SBSymbol(%p)::GetName () => \"%s\"", m_opaque_ptr, name ? name : "");
75 SBSymbol::GetMangledName () const
77 const char *name = NULL;
79 name = m_opaque_ptr->GetMangled().GetMangledName().AsCString();
80 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
82 log->Printf ("SBSymbol(%p)::GetMangledName () => \"%s\"", m_opaque_ptr, name ? name : "");
89 SBSymbol::operator == (const SBSymbol &rhs) const
91 return m_opaque_ptr == rhs.m_opaque_ptr;
95 SBSymbol::operator != (const SBSymbol &rhs) const
97 return m_opaque_ptr != rhs.m_opaque_ptr;
101 SBSymbol::GetDescription (SBStream &description)
103 Stream &strm = description.ref();
107 m_opaque_ptr->GetDescription (&strm,
108 lldb::eDescriptionLevelFull, NULL);
111 strm.PutCString ("No value");
117 SBSymbol::GetInstructions (SBTarget target)
119 return GetInstructions (target, NULL);
123 SBSymbol::GetInstructions (SBTarget target, const char *flavor_string)
125 SBInstructionList sb_instructions;
128 Mutex::Locker api_locker;
129 ExecutionContext exe_ctx;
130 TargetSP target_sp (target.GetSP());
133 api_locker.Lock (target_sp->GetAPIMutex());
134 target_sp->CalculateExecutionContext (exe_ctx);
136 if (m_opaque_ptr->ValueIsAddress())
138 ModuleSP module_sp (m_opaque_ptr->GetAddress().GetModule());
141 AddressRange symbol_range (m_opaque_ptr->GetAddress(), m_opaque_ptr->GetByteSize());
142 sb_instructions.SetDisassembler (Disassembler::DisassembleRange (module_sp->GetArchitecture (),
150 return sb_instructions;
153 lldb_private::Symbol *
160 SBSymbol::reset (lldb_private::Symbol *symbol)
162 m_opaque_ptr = symbol;
166 SBSymbol::GetStartAddress ()
169 if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress())
171 addr.SetAddress (&m_opaque_ptr->GetAddress());
177 SBSymbol::GetEndAddress ()
180 if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress())
182 lldb::addr_t range_size = m_opaque_ptr->GetByteSize();
185 addr.SetAddress (&m_opaque_ptr->GetAddress());
186 addr->Slide (m_opaque_ptr->GetByteSize());
193 SBSymbol::GetPrologueByteSize ()
196 return m_opaque_ptr->GetPrologueByteSize();
204 return m_opaque_ptr->GetType();
205 return eSymbolTypeInvalid;
209 SBSymbol::IsExternal()
212 return m_opaque_ptr->IsExternal();
217 SBSymbol::IsSynthetic()
220 return m_opaque_ptr->IsSynthetic();