LLDB mainline
SBSymbol.cpp
Go to the documentation of this file.
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//===----------------------------------------------------------------------===//
8
9#include "lldb/API/SBSymbol.h"
10#include "lldb/API/SBStream.h"
12#include "lldb/Core/Module.h"
13#include "lldb/Symbol/Symbol.h"
15#include "lldb/Target/Target.h"
17
18using namespace lldb;
19using namespace lldb_private;
20
22
24 : m_opaque_ptr(lldb_object_ptr) {}
25
29
31 LLDB_INSTRUMENT_VA(this, rhs);
32
34 return *this;
35}
36
38
40 m_opaque_ptr = lldb_object_ptr;
41}
42
43bool SBSymbol::IsValid() const {
45 return this->operator bool();
46}
47SBSymbol::operator bool() const {
49
50 return m_opaque_ptr != nullptr;
51}
52
53const char *SBSymbol::GetName() const {
55
56 const char *name = nullptr;
57 if (m_opaque_ptr)
58 name = m_opaque_ptr->GetName().AsCString();
59
60 return name;
61}
62
63const char *SBSymbol::GetDisplayName() const {
65
66 const char *name = nullptr;
67 if (m_opaque_ptr)
68 name = m_opaque_ptr->GetMangled().GetDisplayDemangledName().AsCString();
69
70 return name;
71}
72
73const char *SBSymbol::GetMangledName() const {
75
76 const char *name = nullptr;
77 if (m_opaque_ptr)
78 name = m_opaque_ptr->GetMangled().GetMangledName().AsCString();
79 return name;
80}
81
82const char *SBSymbol::GetBaseName() const {
84
85 if (!m_opaque_ptr)
86 return nullptr;
87
88 return m_opaque_ptr->GetMangled().GetBaseName().AsCString();
89}
90
91bool SBSymbol::operator==(const SBSymbol &rhs) const {
92 LLDB_INSTRUMENT_VA(this, rhs);
93
94 return m_opaque_ptr == rhs.m_opaque_ptr;
95}
96
97bool SBSymbol::operator!=(const SBSymbol &rhs) const {
98 LLDB_INSTRUMENT_VA(this, rhs);
99
100 return m_opaque_ptr != rhs.m_opaque_ptr;
101}
102
104 LLDB_INSTRUMENT_VA(this, description);
105
106 Stream &strm = description.ref();
107
108 if (m_opaque_ptr) {
109 m_opaque_ptr->GetDescription(&strm, lldb::eDescriptionLevelFull, nullptr);
110 } else
111 strm.PutCString("No value");
112
113 return true;
114}
115
117 LLDB_INSTRUMENT_VA(this, target);
118
119 return GetInstructions(target, nullptr);
120}
121
123 const char *flavor_string) {
124 LLDB_INSTRUMENT_VA(this, target, flavor_string);
125
126 SBInstructionList sb_instructions;
127 if (m_opaque_ptr) {
128 TargetSP target_sp(target.GetSP());
129 std::unique_lock<std::recursive_mutex> lock;
130 if (target_sp && m_opaque_ptr->ValueIsAddress()) {
131 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
132 const Address &symbol_addr = m_opaque_ptr->GetAddressRef();
133 ModuleSP module_sp = symbol_addr.GetModule();
134 if (module_sp) {
135 AddressRange symbol_range(symbol_addr, m_opaque_ptr->GetByteSize());
136 const bool force_live_memory = true;
138 module_sp->GetArchitecture(), nullptr, flavor_string,
139 target_sp->GetDisassemblyCPU(), target_sp->GetDisassemblyFeatures(),
140 *target_sp, symbol_range, force_live_memory));
141 }
142 }
143 }
144 return sb_instructions;
145}
146
148
150
152 LLDB_INSTRUMENT_VA(this);
153
154 SBAddress addr;
155 if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress()) {
156 addr.SetAddress(m_opaque_ptr->GetAddressRef());
157 }
158 return addr;
159}
160
162 LLDB_INSTRUMENT_VA(this);
163
164 SBAddress addr;
165 if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress()) {
166 lldb::addr_t range_size = m_opaque_ptr->GetByteSize();
167 if (range_size > 0) {
168 addr.SetAddress(m_opaque_ptr->GetAddressRef());
169 addr->Slide(m_opaque_ptr->GetByteSize());
170 }
171 }
172 return addr;
173}
174
176 LLDB_INSTRUMENT_VA(this);
177 if (m_opaque_ptr)
178 return m_opaque_ptr->GetRawValue();
179 return 0;
180}
181
183 LLDB_INSTRUMENT_VA(this);
184 if (m_opaque_ptr && m_opaque_ptr->GetByteSizeIsValid())
185 return m_opaque_ptr->GetByteSize();
186 return 0;
187}
188
190 LLDB_INSTRUMENT_VA(this);
191
192 if (m_opaque_ptr)
193 return m_opaque_ptr->GetPrologueByteSize();
194 return 0;
195}
196
198 LLDB_INSTRUMENT_VA(this);
199
200 if (m_opaque_ptr)
201 return m_opaque_ptr->GetType();
202 return eSymbolTypeInvalid;
203}
204
205uint32_t SBSymbol::GetID() {
206 LLDB_INSTRUMENT_VA(this);
207
208 if (m_opaque_ptr)
209 return m_opaque_ptr->GetID();
210 return 0;
211}
212
214 LLDB_INSTRUMENT_VA(this);
215
216 if (m_opaque_ptr)
217 return m_opaque_ptr->IsExternal();
218 return false;
219}
220
222 LLDB_INSTRUMENT_VA(this);
223
224 if (m_opaque_ptr)
225 return m_opaque_ptr->IsSynthetic();
226 return false;
227}
228
230 LLDB_INSTRUMENT_VA(this);
231
232 if (m_opaque_ptr)
233 return m_opaque_ptr->IsDebug();
234 return false;
235}
236
238 LLDB_INSTRUMENT_VA(symbol_type);
239
240 return Symbol::GetTypeAsString(symbol_type);
241}
242
#define LLDB_INSTRUMENT_VA(...)
void SetAddress(lldb::SBSection section, lldb::addr_t offset)
Definition SBAddress.cpp:88
void SetDisassembler(const lldb::DisassemblerSP &opaque_sp)
lldb_private::Stream & ref()
Definition SBStream.cpp:177
const char * GetBaseName() const
Definition SBSymbol.cpp:82
uint64_t GetValue()
Get the raw value of a symbol.
Definition SBSymbol.cpp:175
SymbolType GetType()
Definition SBSymbol.cpp:197
const char * GetDisplayName() const
Definition SBSymbol.cpp:63
const char * GetMangledName() const
Definition SBSymbol.cpp:73
static lldb::SymbolType GetTypeFromString(const char *str)
Get the symbol type from a string representation.
Definition SBSymbol.cpp:243
uint32_t GetPrologueByteSize()
Definition SBSymbol.cpp:189
bool IsSynthetic()
Definition SBSymbol.cpp:221
void reset(lldb_private::Symbol *)
Definition SBSymbol.cpp:149
bool GetDescription(lldb::SBStream &description)
Definition SBSymbol.cpp:103
SBAddress GetStartAddress()
Get the start address of this symbol.
Definition SBSymbol.cpp:151
friend class SBAddress
Definition SBSymbol.h:125
SBAddress GetEndAddress()
Get the end address of this symbol.
Definition SBSymbol.cpp:161
bool operator==(const lldb::SBSymbol &rhs) const
Definition SBSymbol.cpp:91
lldb_private::Symbol * m_opaque_ptr
Definition SBSymbol.h:134
bool IsDebug()
Returns true if the symbol is a debug symbol.
Definition SBSymbol.cpp:229
bool IsValid() const
Definition SBSymbol.cpp:43
const lldb::SBSymbol & operator=(const lldb::SBSymbol &rhs)
Definition SBSymbol.cpp:30
const char * GetName() const
Definition SBSymbol.cpp:53
uint64_t GetSize()
Get the size of the symbol.
Definition SBSymbol.cpp:182
static const char * GetTypeAsString(lldb::SymbolType symbol_type)
Get the string representation of a symbol type.
Definition SBSymbol.cpp:237
void SetSymbol(lldb_private::Symbol *lldb_object_ptr)
Definition SBSymbol.cpp:39
lldb::SBInstructionList GetInstructions(lldb::SBTarget target)
Definition SBSymbol.cpp:116
bool IsExternal()
Definition SBSymbol.cpp:213
bool operator!=(const lldb::SBSymbol &rhs) const
Definition SBSymbol.cpp:97
lldb_private::Symbol * get()
Definition SBSymbol.cpp:147
uint32_t GetID()
Get the ID of this symbol, usually the original symbol table index.
Definition SBSymbol.cpp:205
lldb::TargetSP GetSP() const
Definition SBTarget.cpp:578
A section + offset based address range class.
A section + offset based address class.
Definition Address.h:62
bool Slide(int64_t offset)
Definition Address.h:452
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
Definition Address.cpp:273
static lldb::DisassemblerSP DisassembleRange(const ArchSpec &arch, const char *plugin_name, const char *flavor, const char *cpu, const char *features, Target &target, llvm::ArrayRef< AddressRange > disasm_ranges, bool force_live_memory=false)
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:65
const char * GetTypeAsString() const
Definition Symbol.cpp:395
static lldb::SymbolType GetTypeFromString(const char *str)
Definition Symbol.cpp:779
A class that represents a running process on the host machine.
@ eDescriptionLevelFull
SymbolType
Symbol types.
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::Module > ModuleSP