[lldb][dwarf] Compute fully qualified names on simplified template names with DWARFT...
[llvm-project.git] / lldb / source / API / SBSymbol.cpp
blob79477dd3a70fc61cf95276801a40a32960ec6ef1
1 //===-- SBSymbol.cpp ------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "lldb/API/SBSymbol.h"
10 #include "lldb/API/SBStream.h"
11 #include "lldb/Core/Disassembler.h"
12 #include "lldb/Core/Module.h"
13 #include "lldb/Symbol/Symbol.h"
14 #include "lldb/Target/ExecutionContext.h"
15 #include "lldb/Target/Target.h"
16 #include "lldb/Utility/Instrumentation.h"
18 using namespace lldb;
19 using namespace lldb_private;
21 SBSymbol::SBSymbol() { LLDB_INSTRUMENT_VA(this); }
23 SBSymbol::SBSymbol(lldb_private::Symbol *lldb_object_ptr)
24 : m_opaque_ptr(lldb_object_ptr) {}
26 SBSymbol::SBSymbol(const lldb::SBSymbol &rhs) : m_opaque_ptr(rhs.m_opaque_ptr) {
27 LLDB_INSTRUMENT_VA(this, rhs);
30 const SBSymbol &SBSymbol::operator=(const SBSymbol &rhs) {
31 LLDB_INSTRUMENT_VA(this, rhs);
33 m_opaque_ptr = rhs.m_opaque_ptr;
34 return *this;
37 SBSymbol::~SBSymbol() { m_opaque_ptr = nullptr; }
39 void SBSymbol::SetSymbol(lldb_private::Symbol *lldb_object_ptr) {
40 m_opaque_ptr = lldb_object_ptr;
43 bool SBSymbol::IsValid() const {
44 LLDB_INSTRUMENT_VA(this);
45 return this->operator bool();
47 SBSymbol::operator bool() const {
48 LLDB_INSTRUMENT_VA(this);
50 return m_opaque_ptr != nullptr;
53 const char *SBSymbol::GetName() const {
54 LLDB_INSTRUMENT_VA(this);
56 const char *name = nullptr;
57 if (m_opaque_ptr)
58 name = m_opaque_ptr->GetName().AsCString();
60 return name;
63 const char *SBSymbol::GetDisplayName() const {
64 LLDB_INSTRUMENT_VA(this);
66 const char *name = nullptr;
67 if (m_opaque_ptr)
68 name = m_opaque_ptr->GetMangled().GetDisplayDemangledName().AsCString();
70 return name;
73 const char *SBSymbol::GetMangledName() const {
74 LLDB_INSTRUMENT_VA(this);
76 const char *name = nullptr;
77 if (m_opaque_ptr)
78 name = m_opaque_ptr->GetMangled().GetMangledName().AsCString();
79 return name;
82 bool SBSymbol::operator==(const SBSymbol &rhs) const {
83 LLDB_INSTRUMENT_VA(this, rhs);
85 return m_opaque_ptr == rhs.m_opaque_ptr;
88 bool SBSymbol::operator!=(const SBSymbol &rhs) const {
89 LLDB_INSTRUMENT_VA(this, rhs);
91 return m_opaque_ptr != rhs.m_opaque_ptr;
94 bool SBSymbol::GetDescription(SBStream &description) {
95 LLDB_INSTRUMENT_VA(this, description);
97 Stream &strm = description.ref();
99 if (m_opaque_ptr) {
100 m_opaque_ptr->GetDescription(&strm, lldb::eDescriptionLevelFull, nullptr);
101 } else
102 strm.PutCString("No value");
104 return true;
107 SBInstructionList SBSymbol::GetInstructions(SBTarget target) {
108 LLDB_INSTRUMENT_VA(this, target);
110 return GetInstructions(target, nullptr);
113 SBInstructionList SBSymbol::GetInstructions(SBTarget target,
114 const char *flavor_string) {
115 LLDB_INSTRUMENT_VA(this, target, flavor_string);
117 SBInstructionList sb_instructions;
118 if (m_opaque_ptr) {
119 TargetSP target_sp(target.GetSP());
120 std::unique_lock<std::recursive_mutex> lock;
121 if (target_sp && m_opaque_ptr->ValueIsAddress()) {
122 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
123 const Address &symbol_addr = m_opaque_ptr->GetAddressRef();
124 ModuleSP module_sp = symbol_addr.GetModule();
125 if (module_sp) {
126 AddressRange symbol_range(symbol_addr, m_opaque_ptr->GetByteSize());
127 const bool force_live_memory = true;
128 sb_instructions.SetDisassembler(Disassembler::DisassembleRange(
129 module_sp->GetArchitecture(), nullptr, flavor_string,
130 target_sp->GetDisassemblyCPU(), target_sp->GetDisassemblyFeatures(),
131 *target_sp, symbol_range, force_live_memory));
135 return sb_instructions;
138 lldb_private::Symbol *SBSymbol::get() { return m_opaque_ptr; }
140 void SBSymbol::reset(lldb_private::Symbol *symbol) { m_opaque_ptr = symbol; }
142 SBAddress SBSymbol::GetStartAddress() {
143 LLDB_INSTRUMENT_VA(this);
145 SBAddress addr;
146 if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress()) {
147 addr.SetAddress(m_opaque_ptr->GetAddressRef());
149 return addr;
152 SBAddress SBSymbol::GetEndAddress() {
153 LLDB_INSTRUMENT_VA(this);
155 SBAddress addr;
156 if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress()) {
157 lldb::addr_t range_size = m_opaque_ptr->GetByteSize();
158 if (range_size > 0) {
159 addr.SetAddress(m_opaque_ptr->GetAddressRef());
160 addr->Slide(m_opaque_ptr->GetByteSize());
163 return addr;
166 uint64_t SBSymbol::GetValue() {
167 LLDB_INSTRUMENT_VA(this);
168 if (m_opaque_ptr)
169 return m_opaque_ptr->GetRawValue();
170 return 0;
173 uint64_t SBSymbol::GetSize() {
174 LLDB_INSTRUMENT_VA(this);
175 if (m_opaque_ptr && m_opaque_ptr->GetByteSizeIsValid())
176 return m_opaque_ptr->GetByteSize();
177 return 0;
180 uint32_t SBSymbol::GetPrologueByteSize() {
181 LLDB_INSTRUMENT_VA(this);
183 if (m_opaque_ptr)
184 return m_opaque_ptr->GetPrologueByteSize();
185 return 0;
188 SymbolType SBSymbol::GetType() {
189 LLDB_INSTRUMENT_VA(this);
191 if (m_opaque_ptr)
192 return m_opaque_ptr->GetType();
193 return eSymbolTypeInvalid;
196 bool SBSymbol::IsExternal() {
197 LLDB_INSTRUMENT_VA(this);
199 if (m_opaque_ptr)
200 return m_opaque_ptr->IsExternal();
201 return false;
204 bool SBSymbol::IsSynthetic() {
205 LLDB_INSTRUMENT_VA(this);
207 if (m_opaque_ptr)
208 return m_opaque_ptr->IsSynthetic();
209 return false;