[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / lldb / source / API / SBSymbol.cpp
blob6cc90e0ee368b3568a79cc32f9340d22ae2d4157
1 //===-- SBSymbol.cpp --------------------------------------------*- C++ -*-===//
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 "SBReproducerPrivate.h"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/Core/Disassembler.h"
13 #include "lldb/Core/Module.h"
14 #include "lldb/Symbol/Symbol.h"
15 #include "lldb/Target/ExecutionContext.h"
16 #include "lldb/Target/Target.h"
18 using namespace lldb;
19 using namespace lldb_private;
21 SBSymbol::SBSymbol() : m_opaque_ptr(nullptr) {
22 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBSymbol);
25 SBSymbol::SBSymbol(lldb_private::Symbol *lldb_object_ptr)
26 : m_opaque_ptr(lldb_object_ptr) {}
28 SBSymbol::SBSymbol(const lldb::SBSymbol &rhs) : m_opaque_ptr(rhs.m_opaque_ptr) {
29 LLDB_RECORD_CONSTRUCTOR(SBSymbol, (const lldb::SBSymbol &), rhs);
32 const SBSymbol &SBSymbol::operator=(const SBSymbol &rhs) {
33 LLDB_RECORD_METHOD(const lldb::SBSymbol &,
34 SBSymbol, operator=,(const lldb::SBSymbol &), rhs);
36 m_opaque_ptr = rhs.m_opaque_ptr;
37 return LLDB_RECORD_RESULT(*this);
40 SBSymbol::~SBSymbol() { m_opaque_ptr = nullptr; }
42 void SBSymbol::SetSymbol(lldb_private::Symbol *lldb_object_ptr) {
43 m_opaque_ptr = lldb_object_ptr;
46 bool SBSymbol::IsValid() const {
47 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBSymbol, IsValid);
48 return this->operator bool();
50 SBSymbol::operator bool() const {
51 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBSymbol, operator bool);
53 return m_opaque_ptr != nullptr;
56 const char *SBSymbol::GetName() const {
57 LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBSymbol, GetName);
59 const char *name = nullptr;
60 if (m_opaque_ptr)
61 name = m_opaque_ptr->GetName().AsCString();
63 return name;
66 const char *SBSymbol::GetDisplayName() const {
67 LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBSymbol, GetDisplayName);
69 const char *name = nullptr;
70 if (m_opaque_ptr)
71 name = m_opaque_ptr->GetMangled()
72 .GetDisplayDemangledName(m_opaque_ptr->GetLanguage())
73 .AsCString();
75 return name;
78 const char *SBSymbol::GetMangledName() const {
79 LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBSymbol, GetMangledName);
81 const char *name = nullptr;
82 if (m_opaque_ptr)
83 name = m_opaque_ptr->GetMangled().GetMangledName().AsCString();
84 return name;
87 bool SBSymbol::operator==(const SBSymbol &rhs) const {
88 LLDB_RECORD_METHOD_CONST(bool, SBSymbol, operator==,(const lldb::SBSymbol &),
89 rhs);
91 return m_opaque_ptr == rhs.m_opaque_ptr;
94 bool SBSymbol::operator!=(const SBSymbol &rhs) const {
95 LLDB_RECORD_METHOD_CONST(bool, SBSymbol, operator!=,(const lldb::SBSymbol &),
96 rhs);
98 return m_opaque_ptr != rhs.m_opaque_ptr;
101 bool SBSymbol::GetDescription(SBStream &description) {
102 LLDB_RECORD_METHOD(bool, SBSymbol, GetDescription, (lldb::SBStream &),
103 description);
105 Stream &strm = description.ref();
107 if (m_opaque_ptr) {
108 m_opaque_ptr->GetDescription(&strm, lldb::eDescriptionLevelFull, nullptr);
109 } else
110 strm.PutCString("No value");
112 return true;
115 SBInstructionList SBSymbol::GetInstructions(SBTarget target) {
116 LLDB_RECORD_METHOD(lldb::SBInstructionList, SBSymbol, GetInstructions,
117 (lldb::SBTarget), target);
119 return LLDB_RECORD_RESULT(GetInstructions(target, nullptr));
122 SBInstructionList SBSymbol::GetInstructions(SBTarget target,
123 const char *flavor_string) {
124 LLDB_RECORD_METHOD(lldb::SBInstructionList, SBSymbol, GetInstructions,
125 (lldb::SBTarget, const char *), target, flavor_string);
127 SBInstructionList sb_instructions;
128 if (m_opaque_ptr) {
129 ExecutionContext exe_ctx;
130 TargetSP target_sp(target.GetSP());
131 std::unique_lock<std::recursive_mutex> lock;
132 if (target_sp) {
133 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
135 target_sp->CalculateExecutionContext(exe_ctx);
137 if (m_opaque_ptr->ValueIsAddress()) {
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 prefer_file_cache = false;
143 sb_instructions.SetDisassembler(Disassembler::DisassembleRange(
144 module_sp->GetArchitecture(), nullptr, flavor_string, exe_ctx,
145 symbol_range, prefer_file_cache));
149 return LLDB_RECORD_RESULT(sb_instructions);
152 lldb_private::Symbol *SBSymbol::get() { return m_opaque_ptr; }
154 void SBSymbol::reset(lldb_private::Symbol *symbol) { m_opaque_ptr = symbol; }
156 SBAddress SBSymbol::GetStartAddress() {
157 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBAddress, SBSymbol, GetStartAddress);
159 SBAddress addr;
160 if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress()) {
161 addr.SetAddress(&m_opaque_ptr->GetAddressRef());
163 return LLDB_RECORD_RESULT(addr);
166 SBAddress SBSymbol::GetEndAddress() {
167 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBAddress, SBSymbol, GetEndAddress);
169 SBAddress addr;
170 if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress()) {
171 lldb::addr_t range_size = m_opaque_ptr->GetByteSize();
172 if (range_size > 0) {
173 addr.SetAddress(&m_opaque_ptr->GetAddressRef());
174 addr->Slide(m_opaque_ptr->GetByteSize());
177 return LLDB_RECORD_RESULT(addr);
180 uint32_t SBSymbol::GetPrologueByteSize() {
181 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBSymbol, GetPrologueByteSize);
183 if (m_opaque_ptr)
184 return m_opaque_ptr->GetPrologueByteSize();
185 return 0;
188 SymbolType SBSymbol::GetType() {
189 LLDB_RECORD_METHOD_NO_ARGS(lldb::SymbolType, SBSymbol, GetType);
191 if (m_opaque_ptr)
192 return m_opaque_ptr->GetType();
193 return eSymbolTypeInvalid;
196 bool SBSymbol::IsExternal() {
197 LLDB_RECORD_METHOD_NO_ARGS(bool, SBSymbol, IsExternal);
199 if (m_opaque_ptr)
200 return m_opaque_ptr->IsExternal();
201 return false;
204 bool SBSymbol::IsSynthetic() {
205 LLDB_RECORD_METHOD_NO_ARGS(bool, SBSymbol, IsSynthetic);
207 if (m_opaque_ptr)
208 return m_opaque_ptr->IsSynthetic();
209 return false;
212 namespace lldb_private {
213 namespace repro {
215 template <>
216 void RegisterMethods<SBSymbol>(Registry &R) {
217 LLDB_REGISTER_CONSTRUCTOR(SBSymbol, ());
218 LLDB_REGISTER_CONSTRUCTOR(SBSymbol, (const lldb::SBSymbol &));
219 LLDB_REGISTER_METHOD(const lldb::SBSymbol &,
220 SBSymbol, operator=,(const lldb::SBSymbol &));
221 LLDB_REGISTER_METHOD_CONST(bool, SBSymbol, IsValid, ());
222 LLDB_REGISTER_METHOD_CONST(bool, SBSymbol, operator bool, ());
223 LLDB_REGISTER_METHOD_CONST(const char *, SBSymbol, GetName, ());
224 LLDB_REGISTER_METHOD_CONST(const char *, SBSymbol, GetDisplayName, ());
225 LLDB_REGISTER_METHOD_CONST(const char *, SBSymbol, GetMangledName, ());
226 LLDB_REGISTER_METHOD_CONST(bool,
227 SBSymbol, operator==,(const lldb::SBSymbol &));
228 LLDB_REGISTER_METHOD_CONST(bool,
229 SBSymbol, operator!=,(const lldb::SBSymbol &));
230 LLDB_REGISTER_METHOD(bool, SBSymbol, GetDescription, (lldb::SBStream &));
231 LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBSymbol, GetInstructions,
232 (lldb::SBTarget));
233 LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBSymbol, GetInstructions,
234 (lldb::SBTarget, const char *));
235 LLDB_REGISTER_METHOD(lldb::SBAddress, SBSymbol, GetStartAddress, ());
236 LLDB_REGISTER_METHOD(lldb::SBAddress, SBSymbol, GetEndAddress, ());
237 LLDB_REGISTER_METHOD(uint32_t, SBSymbol, GetPrologueByteSize, ());
238 LLDB_REGISTER_METHOD(lldb::SymbolType, SBSymbol, GetType, ());
239 LLDB_REGISTER_METHOD(bool, SBSymbol, IsExternal, ());
240 LLDB_REGISTER_METHOD(bool, SBSymbol, IsSynthetic, ());