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(nullptr);
59
60 return name;
61}
62
63const char *SBSymbol::GetDisplayName() const {
65
66 const char *name = nullptr;
67 if (m_opaque_ptr)
68 name =
69 m_opaque_ptr->GetMangled().GetDisplayDemangledName().AsCString(nullptr);
70
71 return name;
72}
73
74const char *SBSymbol::GetMangledName() const {
76
77 const char *name = nullptr;
78 if (m_opaque_ptr)
79 name = m_opaque_ptr->GetMangled().GetMangledName().AsCString(nullptr);
80 return name;
81}
82
83const char *SBSymbol::GetBaseName() const {
85
86 if (!m_opaque_ptr)
87 return nullptr;
88
89 return m_opaque_ptr->GetMangled().GetBaseName().AsCString(nullptr);
90}
91
92bool SBSymbol::operator==(const SBSymbol &rhs) const {
93 LLDB_INSTRUMENT_VA(this, rhs);
94
95 return m_opaque_ptr == rhs.m_opaque_ptr;
96}
97
98bool SBSymbol::operator!=(const SBSymbol &rhs) const {
99 LLDB_INSTRUMENT_VA(this, rhs);
100
101 return m_opaque_ptr != rhs.m_opaque_ptr;
102}
103
105 LLDB_INSTRUMENT_VA(this, description);
106
107 Stream &strm = description.ref();
108
109 if (m_opaque_ptr) {
110 m_opaque_ptr->GetDescription(&strm, lldb::eDescriptionLevelFull, nullptr);
111 } else
112 strm.PutCString("No value");
113
114 return true;
115}
116
118 LLDB_INSTRUMENT_VA(this, target);
119
120 return GetInstructions(target, nullptr);
121}
122
124 const char *flavor_string) {
125 LLDB_INSTRUMENT_VA(this, target, flavor_string);
126
127 SBInstructionList sb_instructions;
128 if (m_opaque_ptr) {
129 TargetSP target_sp(target.GetSP());
130 TargetAPIMutex api_lock;
131 std::unique_lock<TargetAPIMutex> guard;
132 if (target_sp && m_opaque_ptr->ValueIsAddress()) {
133 api_lock = TargetAPIMutex(target_sp->GetAPIMutex());
134 guard = std::unique_lock<TargetAPIMutex>(api_lock);
135 const Address &symbol_addr = m_opaque_ptr->GetAddressRef();
136 ModuleSP module_sp = symbol_addr.GetModule();
137 if (module_sp) {
138 AddressRange symbol_range(symbol_addr, m_opaque_ptr->GetByteSize());
139 const bool force_live_memory = true;
141 module_sp->GetArchitecture(), nullptr, flavor_string,
142 target_sp->GetDisassemblyCPU(), target_sp->GetDisassemblyFeatures(),
143 *target_sp, symbol_range, force_live_memory));
144 }
145 }
146 }
147 return sb_instructions;
148}
149
151
153
155 LLDB_INSTRUMENT_VA(this);
156
157 SBAddress addr;
158 if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress()) {
159 addr.SetAddress(m_opaque_ptr->GetAddressRef());
160 }
161 return addr;
162}
163
165 LLDB_INSTRUMENT_VA(this);
166
167 SBAddress addr;
168 if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress()) {
169 lldb::addr_t range_size = m_opaque_ptr->GetByteSize();
170 if (range_size > 0) {
171 addr.SetAddress(m_opaque_ptr->GetAddressRef());
172 addr->Slide(m_opaque_ptr->GetByteSize());
173 }
174 }
175 return addr;
176}
177
179 LLDB_INSTRUMENT_VA(this);
180 if (m_opaque_ptr)
181 return m_opaque_ptr->GetRawValue();
182 return 0;
183}
184
186 LLDB_INSTRUMENT_VA(this);
187 if (m_opaque_ptr && m_opaque_ptr->GetByteSizeIsValid())
188 return m_opaque_ptr->GetByteSize();
189 return 0;
190}
191
193 LLDB_INSTRUMENT_VA(this);
194
195 if (m_opaque_ptr)
196 return m_opaque_ptr->GetPrologueByteSize();
197 return 0;
198}
199
201 LLDB_INSTRUMENT_VA(this);
202
203 if (m_opaque_ptr)
204 return m_opaque_ptr->GetType();
205 return eSymbolTypeInvalid;
206}
207
208uint32_t SBSymbol::GetID() const {
209 LLDB_INSTRUMENT_VA(this);
210
211 if (m_opaque_ptr)
212 return m_opaque_ptr->GetID();
214}
215
217 LLDB_INSTRUMENT_VA(this);
218
219 if (m_opaque_ptr)
220 return m_opaque_ptr->IsExternal();
221 return false;
222}
223
225 LLDB_INSTRUMENT_VA(this);
226
227 if (m_opaque_ptr)
228 return m_opaque_ptr->IsSynthetic();
229 return false;
230}
231
232bool SBSymbol::IsDebug() const {
233 LLDB_INSTRUMENT_VA(this);
234
235 if (m_opaque_ptr)
236 return m_opaque_ptr->IsDebug();
237 return false;
238}
239
241 LLDB_INSTRUMENT_VA(symbol_type);
242
243 return Symbol::GetTypeAsString(symbol_type);
244}
245
#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:179
const char * GetBaseName() const
Definition SBSymbol.cpp:83
uint64_t GetValue()
Get the raw value of a symbol.
Definition SBSymbol.cpp:178
SymbolType GetType()
Definition SBSymbol.cpp:200
const char * GetDisplayName() const
Definition SBSymbol.cpp:63
const char * GetMangledName() const
Definition SBSymbol.cpp:74
static lldb::SymbolType GetTypeFromString(const char *str)
Get the symbol type from a string representation.
Definition SBSymbol.cpp:246
uint32_t GetPrologueByteSize()
Definition SBSymbol.cpp:192
bool IsSynthetic()
Definition SBSymbol.cpp:224
void reset(lldb_private::Symbol *)
Definition SBSymbol.cpp:152
bool IsDebug() const
Returns true if the symbol is a debug symbol.
Definition SBSymbol.cpp:232
bool GetDescription(lldb::SBStream &description)
Definition SBSymbol.cpp:104
SBAddress GetStartAddress()
Get the start address of this symbol.
Definition SBSymbol.cpp:154
friend class SBAddress
Definition SBSymbol.h:126
SBAddress GetEndAddress()
Get the end address of this symbol.
Definition SBSymbol.cpp:164
bool operator==(const lldb::SBSymbol &rhs) const
Definition SBSymbol.cpp:92
lldb_private::Symbol * m_opaque_ptr
Definition SBSymbol.h:135
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:185
static const char * GetTypeAsString(lldb::SymbolType symbol_type)
Get the string representation of a symbol type.
Definition SBSymbol.cpp:240
void SetSymbol(lldb_private::Symbol *lldb_object_ptr)
Definition SBSymbol.cpp:39
lldb::SBInstructionList GetInstructions(lldb::SBTarget target)
Definition SBSymbol.cpp:117
bool IsExternal()
Definition SBSymbol.cpp:216
bool operator!=(const lldb::SBSymbol &rhs) const
Definition SBSymbol.cpp:98
lldb_private::Symbol * get()
Definition SBSymbol.cpp:150
uint32_t GetID() const
Get the ID of this symbol, usually the original symbol table index.
Definition SBSymbol.cpp:208
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: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:63
const char * GetTypeAsString() const
Definition Symbol.cpp:433
static lldb::SymbolType GetTypeFromString(const char *str)
Definition Symbol.cpp:865
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