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