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 std::unique_lock<std::recursive_mutex> lock;
131 if (target_sp && m_opaque_ptr->ValueIsAddress()) {
132 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
133 const Address &symbol_addr = m_opaque_ptr->GetAddressRef();
134 ModuleSP module_sp = symbol_addr.GetModule();
135 if (module_sp) {
136 AddressRange symbol_range(symbol_addr, m_opaque_ptr->GetByteSize());
137 const bool force_live_memory = true;
139 module_sp->GetArchitecture(), nullptr, flavor_string,
140 target_sp->GetDisassemblyCPU(), target_sp->GetDisassemblyFeatures(),
141 *target_sp, symbol_range, force_live_memory));
142 }
143 }
144 }
145 return sb_instructions;
146}
147
149
151
153 LLDB_INSTRUMENT_VA(this);
154
155 SBAddress addr;
156 if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress()) {
157 addr.SetAddress(m_opaque_ptr->GetAddressRef());
158 }
159 return addr;
160}
161
163 LLDB_INSTRUMENT_VA(this);
164
165 SBAddress addr;
166 if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress()) {
167 lldb::addr_t range_size = m_opaque_ptr->GetByteSize();
168 if (range_size > 0) {
169 addr.SetAddress(m_opaque_ptr->GetAddressRef());
170 addr->Slide(m_opaque_ptr->GetByteSize());
171 }
172 }
173 return addr;
174}
175
177 LLDB_INSTRUMENT_VA(this);
178 if (m_opaque_ptr)
179 return m_opaque_ptr->GetRawValue();
180 return 0;
181}
182
184 LLDB_INSTRUMENT_VA(this);
185 if (m_opaque_ptr && m_opaque_ptr->GetByteSizeIsValid())
186 return m_opaque_ptr->GetByteSize();
187 return 0;
188}
189
191 LLDB_INSTRUMENT_VA(this);
192
193 if (m_opaque_ptr)
194 return m_opaque_ptr->GetPrologueByteSize();
195 return 0;
196}
197
199 LLDB_INSTRUMENT_VA(this);
200
201 if (m_opaque_ptr)
202 return m_opaque_ptr->GetType();
203 return eSymbolTypeInvalid;
204}
205
206uint32_t SBSymbol::GetID() const {
207 LLDB_INSTRUMENT_VA(this);
208
209 if (m_opaque_ptr)
210 return m_opaque_ptr->GetID();
212}
213
215 LLDB_INSTRUMENT_VA(this);
216
217 if (m_opaque_ptr)
218 return m_opaque_ptr->IsExternal();
219 return false;
220}
221
223 LLDB_INSTRUMENT_VA(this);
224
225 if (m_opaque_ptr)
226 return m_opaque_ptr->IsSynthetic();
227 return false;
228}
229
230bool SBSymbol::IsDebug() const {
231 LLDB_INSTRUMENT_VA(this);
232
233 if (m_opaque_ptr)
234 return m_opaque_ptr->IsDebug();
235 return false;
236}
237
239 LLDB_INSTRUMENT_VA(symbol_type);
240
241 return Symbol::GetTypeAsString(symbol_type);
242}
243
#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:178
const char * GetBaseName() const
Definition SBSymbol.cpp:83
uint64_t GetValue()
Get the raw value of a symbol.
Definition SBSymbol.cpp:176
SymbolType GetType()
Definition SBSymbol.cpp:198
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:244
uint32_t GetPrologueByteSize()
Definition SBSymbol.cpp:190
bool IsSynthetic()
Definition SBSymbol.cpp:222
void reset(lldb_private::Symbol *)
Definition SBSymbol.cpp:150
bool IsDebug() const
Returns true if the symbol is a debug symbol.
Definition SBSymbol.cpp:230
bool GetDescription(lldb::SBStream &description)
Definition SBSymbol.cpp:104
SBAddress GetStartAddress()
Get the start address of this symbol.
Definition SBSymbol.cpp:152
friend class SBAddress
Definition SBSymbol.h:126
SBAddress GetEndAddress()
Get the end address of this symbol.
Definition SBSymbol.cpp:162
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:183
static const char * GetTypeAsString(lldb::SymbolType symbol_type)
Get the string representation of a symbol type.
Definition SBSymbol.cpp:238
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:214
bool operator!=(const lldb::SBSymbol &rhs) const
Definition SBSymbol.cpp:98
lldb_private::Symbol * get()
Definition SBSymbol.cpp:148
uint32_t GetID() const
Get the ID of this symbol, usually the original symbol table index.
Definition SBSymbol.cpp:206
lldb::TargetSP GetSP() const
Definition SBTarget.cpp:592
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:63
const char * GetTypeAsString() const
Definition Symbol.cpp:395
static lldb::SymbolType GetTypeFromString(const char *str)
Definition Symbol.cpp:779
#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