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"
18
19using namespace lldb;
20using namespace lldb_private;
21
23
25 : m_opaque_ptr(lldb_object_ptr) {}
26
30
32 LLDB_INSTRUMENT_VA(this, rhs);
33
35 return *this;
36}
37
39
41 m_opaque_ptr = lldb_object_ptr;
42}
43
44bool SBSymbol::IsValid() const {
46 return this->operator bool();
47}
48SBSymbol::operator bool() const {
50
51 return m_opaque_ptr != nullptr;
52}
53
54const char *SBSymbol::GetName() const {
56
57 const char *name = nullptr;
58 if (m_opaque_ptr)
60
61 return name;
62}
63
64const char *SBSymbol::GetDisplayName() const {
66
67 const char *name = nullptr;
68 if (m_opaque_ptr)
70 m_opaque_ptr->GetMangled().GetDisplayDemangledName());
71
72 return name;
73}
74
75const char *SBSymbol::GetMangledName() const {
77
78 const char *name = nullptr;
79 if (m_opaque_ptr)
81 m_opaque_ptr->GetMangled().GetMangledName());
82 return name;
83}
84
85const char *SBSymbol::GetBaseName() const {
87
88 if (!m_opaque_ptr)
89 return nullptr;
90
92 m_opaque_ptr->GetMangled().GetBaseName());
93}
94
95bool SBSymbol::operator==(const SBSymbol &rhs) const {
96 LLDB_INSTRUMENT_VA(this, rhs);
97
98 return m_opaque_ptr == rhs.m_opaque_ptr;
99}
100
101bool SBSymbol::operator!=(const SBSymbol &rhs) const {
102 LLDB_INSTRUMENT_VA(this, rhs);
103
104 return m_opaque_ptr != rhs.m_opaque_ptr;
105}
106
108 LLDB_INSTRUMENT_VA(this, description);
109
110 Stream &strm = description.ref();
111
112 if (m_opaque_ptr) {
113 m_opaque_ptr->GetDescription(&strm, lldb::eDescriptionLevelFull, nullptr);
114 } else
115 strm.PutCString("No value");
116
117 return true;
118}
119
121 LLDB_INSTRUMENT_VA(this, target);
122
123 return GetInstructions(target, nullptr);
124}
125
127 const char *flavor_string) {
128 LLDB_INSTRUMENT_VA(this, target, flavor_string);
129
130 SBInstructionList sb_instructions;
131 if (m_opaque_ptr) {
132 TargetSP target_sp(target.GetSP());
133 TargetAPIMutex api_lock;
134 std::unique_lock<TargetAPIMutex> guard;
135 if (target_sp && m_opaque_ptr->ValueIsAddress()) {
136 api_lock = TargetAPIMutex(target_sp->GetAPIMutex());
137 guard = std::unique_lock<TargetAPIMutex>(api_lock);
138 const Address &symbol_addr = m_opaque_ptr->GetAddressRef();
139 ModuleSP module_sp = symbol_addr.GetModule();
140 if (module_sp) {
141 AddressRange symbol_range(symbol_addr, m_opaque_ptr->GetByteSize());
142 const bool force_live_memory = true;
144 module_sp->GetArchitecture(), nullptr, flavor_string,
145 target_sp->GetDisassemblyCPU(), target_sp->GetDisassemblyFeatures(),
146 *target_sp, symbol_range, force_live_memory));
147 }
148 }
149 }
150 return sb_instructions;
151}
152
154
156
158 LLDB_INSTRUMENT_VA(this);
159
160 SBAddress addr;
161 if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress()) {
162 addr.SetAddress(m_opaque_ptr->GetAddressRef());
163 }
164 return addr;
165}
166
168 LLDB_INSTRUMENT_VA(this);
169
170 SBAddress addr;
171 if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress()) {
172 lldb::addr_t range_size = m_opaque_ptr->GetByteSize();
173 if (range_size > 0) {
174 addr.SetAddress(m_opaque_ptr->GetAddressRef());
175 addr->Slide(m_opaque_ptr->GetByteSize());
176 }
177 }
178 return addr;
179}
180
182 LLDB_INSTRUMENT_VA(this);
183 if (m_opaque_ptr)
184 return m_opaque_ptr->GetRawValue();
185 return 0;
186}
187
189 LLDB_INSTRUMENT_VA(this);
190 if (m_opaque_ptr && m_opaque_ptr->GetByteSizeIsValid())
191 return m_opaque_ptr->GetByteSize();
192 return 0;
193}
194
196 LLDB_INSTRUMENT_VA(this);
197
198 if (m_opaque_ptr)
199 return m_opaque_ptr->GetPrologueByteSize();
200 return 0;
201}
202
204 LLDB_INSTRUMENT_VA(this);
205
206 if (m_opaque_ptr)
207 return m_opaque_ptr->GetType();
208 return eSymbolTypeInvalid;
209}
210
211uint32_t SBSymbol::GetID() const {
212 LLDB_INSTRUMENT_VA(this);
213
214 if (m_opaque_ptr)
215 return m_opaque_ptr->GetID();
217}
218
220 LLDB_INSTRUMENT_VA(this);
221
222 if (m_opaque_ptr)
223 return m_opaque_ptr->IsExternal();
224 return false;
225}
226
228 LLDB_INSTRUMENT_VA(this);
229
230 if (m_opaque_ptr)
231 return m_opaque_ptr->IsSynthetic();
232 return false;
233}
234
235bool SBSymbol::IsDebug() const {
236 LLDB_INSTRUMENT_VA(this);
237
238 if (m_opaque_ptr)
239 return m_opaque_ptr->IsDebug();
240 return false;
241}
242
244 LLDB_INSTRUMENT_VA(symbol_type);
245
246 return Symbol::GetTypeAsString(symbol_type);
247}
248
#define LLDB_INSTRUMENT_VA(...)
void SetAddress(lldb::SBSection section, lldb::addr_t offset)
Definition SBAddress.cpp:90
void SetDisassembler(const lldb::DisassemblerSP &opaque_sp)
lldb_private::Stream & ref()
Definition SBStream.cpp:179
const char * GetBaseName() const
Definition SBSymbol.cpp:85
uint64_t GetValue()
Get the raw value of a symbol.
Definition SBSymbol.cpp:181
SymbolType GetType()
Definition SBSymbol.cpp:203
const char * GetDisplayName() const
Definition SBSymbol.cpp:64
const char * GetMangledName() const
Definition SBSymbol.cpp:75
static lldb::SymbolType GetTypeFromString(const char *str)
Get the symbol type from a string representation.
Definition SBSymbol.cpp:249
uint32_t GetPrologueByteSize()
Definition SBSymbol.cpp:195
bool IsSynthetic()
Definition SBSymbol.cpp:227
void reset(lldb_private::Symbol *)
Definition SBSymbol.cpp:155
bool IsDebug() const
Returns true if the symbol is a debug symbol.
Definition SBSymbol.cpp:235
bool GetDescription(lldb::SBStream &description)
Definition SBSymbol.cpp:107
SBAddress GetStartAddress()
Get the start address of this symbol.
Definition SBSymbol.cpp:157
friend class SBAddress
Definition SBSymbol.h:126
SBAddress GetEndAddress()
Get the end address of this symbol.
Definition SBSymbol.cpp:167
bool operator==(const lldb::SBSymbol &rhs) const
Definition SBSymbol.cpp:95
lldb_private::Symbol * m_opaque_ptr
Definition SBSymbol.h:135
bool IsValid() const
Definition SBSymbol.cpp:44
const lldb::SBSymbol & operator=(const lldb::SBSymbol &rhs)
Definition SBSymbol.cpp:31
const char * GetName() const
Definition SBSymbol.cpp:54
uint64_t GetSize()
Get the size of the symbol.
Definition SBSymbol.cpp:188
static const char * GetTypeAsString(lldb::SymbolType symbol_type)
Get the string representation of a symbol type.
Definition SBSymbol.cpp:243
void SetSymbol(lldb_private::Symbol *lldb_object_ptr)
Definition SBSymbol.cpp:40
lldb::SBInstructionList GetInstructions(lldb::SBTarget target)
Definition SBSymbol.cpp:120
bool IsExternal()
Definition SBSymbol.cpp:219
bool operator!=(const lldb::SBSymbol &rhs) const
Definition SBSymbol.cpp:101
lldb_private::Symbol * get()
Definition SBSymbol.cpp:153
uint32_t GetID() const
Get the ID of this symbol, usually the original symbol table index.
Definition SBSymbol.cpp:211
lldb::TargetSP GetSP() const
Definition SBTarget.cpp:600
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:446
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
Definition Address.cpp:275
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:63
const char * InternNonEmpty(llvm::StringRef str) const
Like Intern, but an empty string yields nullptr.
Definition StringPool.h:81
static StringPoolRef GetSystemPool()
The system pool. Only valid between Initialize and Terminate.
const char * GetTypeAsString() const
Definition Symbol.cpp:434
static lldb::SymbolType GetTypeFromString(const char *str)
Definition Symbol.cpp:949
A Lockable handle over a Target's API mutex, returned by Target::GetAPIMutex() and backing the public...
#define LLDB_INVALID_SYMBOL_ID
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