LLDB mainline
SBFunction.cpp
Go to the documentation of this file.
1//===-- SBFunction.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
11#include "lldb/API/SBProcess.h"
12#include "lldb/API/SBStream.h"
15#include "lldb/Core/Module.h"
18#include "lldb/Symbol/Type.h"
21#include "lldb/Target/Target.h"
23
24using namespace lldb;
25using namespace lldb_private;
26
28
30 : m_opaque_ptr(lldb_object_ptr) {}
31
36
38 LLDB_INSTRUMENT_VA(this, rhs);
39
41 return *this;
42}
43
45
46bool SBFunction::IsValid() const {
48 return this->operator bool();
49}
50SBFunction::operator bool() const {
52
53 return m_opaque_ptr != nullptr;
54}
55
56const char *SBFunction::GetName() const {
58
59 if (m_opaque_ptr)
60 return m_opaque_ptr->GetName().AsCString(nullptr);
61
62 return nullptr;
63}
64
65const char *SBFunction::GetDisplayName() const {
67
68 if (m_opaque_ptr)
69 return m_opaque_ptr->GetMangled().GetDisplayDemangledName().AsCString(
70 nullptr);
71
72 return nullptr;
73}
74
75const char *SBFunction::GetMangledName() const {
77
78 if (m_opaque_ptr)
79 return m_opaque_ptr->GetMangled().GetMangledName().AsCString(nullptr);
80 return nullptr;
81}
82
83const char *SBFunction::GetBaseName() const {
85
86 if (!m_opaque_ptr)
87 return nullptr;
88
89 return m_opaque_ptr->GetMangled().GetBaseName().AsCString(nullptr);
90}
91
92bool SBFunction::operator==(const SBFunction &rhs) const {
93 LLDB_INSTRUMENT_VA(this, rhs);
94
95 return m_opaque_ptr == rhs.m_opaque_ptr;
96}
97
98bool SBFunction::operator!=(const SBFunction &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, s);
106
107 if (m_opaque_ptr) {
108 s.Printf("SBFunction: id = 0x%8.8" PRIx64 ", name = %s",
109 m_opaque_ptr->GetID(), m_opaque_ptr->GetName().AsCString(""));
110 Type *func_type = m_opaque_ptr->GetType();
111 if (func_type)
112 s.Printf(", type = %s", func_type->GetName().AsCString(""));
113 return true;
114 }
115 s.Printf("No value");
116 return false;
117}
118
120 LLDB_INSTRUMENT_VA(this, target);
121
122 return GetInstructions(target, nullptr);
123}
124
126 const char *flavor) {
127 LLDB_INSTRUMENT_VA(this, target, flavor);
128
129 SBInstructionList sb_instructions;
130 if (m_opaque_ptr) {
131 TargetSP target_sp(target.GetSP());
132 std::unique_lock<std::recursive_mutex> lock;
133 ModuleSP module_sp(m_opaque_ptr->GetAddress().GetModule());
134 if (target_sp && module_sp) {
135 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
136 const bool force_live_memory = true;
138 module_sp->GetArchitecture(), nullptr, flavor,
139 target_sp->GetDisassemblyCPU(), target_sp->GetDisassemblyFeatures(),
140 *target_sp, m_opaque_ptr->GetAddressRanges(), force_live_memory));
141 }
142 }
143 return sb_instructions;
144}
145
147
149 m_opaque_ptr = lldb_object_ptr;
150}
151
153 LLDB_INSTRUMENT_VA(this);
154
155 SBAddress addr;
156 if (m_opaque_ptr)
157 addr.SetAddress(m_opaque_ptr->GetAddress());
158 return addr;
159}
160
161SBAddress SBFunction::GetEndAddress() {
162 LLDB_INSTRUMENT_VA(this);
163
164 SBAddress addr;
165 if (m_opaque_ptr) {
167 if (!ranges.empty()) {
168 // Return the end of the first range, use GetRanges to get all ranges.
169 addr.SetAddress(ranges.front().GetBaseAddress());
170 addr->Slide(ranges.front().GetByteSize());
171 }
172 }
173 return addr;
174}
175
177 LLDB_INSTRUMENT_VA(this);
178
180 if (m_opaque_ptr)
181 ranges.ref() = AddressRangeListImpl(m_opaque_ptr->GetAddressRanges());
182
183 return ranges;
184}
185
186const char *SBFunction::GetArgumentName(uint32_t arg_idx) {
187 LLDB_INSTRUMENT_VA(this, arg_idx);
188
189 if (!m_opaque_ptr)
190 return nullptr;
191
192 Block &block = m_opaque_ptr->GetBlock(true);
193 VariableListSP variable_list_sp = block.GetBlockVariableList(true);
194 if (!variable_list_sp)
195 return nullptr;
196
197 VariableList arguments;
198 variable_list_sp->AppendVariablesWithScope(eValueTypeVariableArgument,
199 arguments, true);
200 lldb::VariableSP variable_sp = arguments.GetVariableAtIndex(arg_idx);
201 if (!variable_sp)
202 return nullptr;
203
204 return variable_sp->GetName().GetCString();
205}
206
208 LLDB_INSTRUMENT_VA(this);
209
210 if (m_opaque_ptr)
211 return m_opaque_ptr->GetPrologueByteSize();
212 return 0;
213}
214
216 LLDB_INSTRUMENT_VA(this);
217
218 SBType sb_type;
219 if (m_opaque_ptr) {
220 Type *function_type = m_opaque_ptr->GetType();
221 if (function_type)
222 sb_type.ref().SetType(function_type->shared_from_this());
223 }
224 return sb_type;
225}
226
228 LLDB_INSTRUMENT_VA(this);
229
230 SBBlock sb_block;
231 if (m_opaque_ptr)
232 sb_block.SetPtr(&m_opaque_ptr->GetBlock(true));
233 return sb_block;
234}
235
237 LLDB_INSTRUMENT_VA(this);
238
239 if (m_opaque_ptr) {
240 if (m_opaque_ptr->GetCompileUnit())
241 return m_opaque_ptr->GetCompileUnit()->GetLanguage();
242 }
244}
245
247 LLDB_INSTRUMENT_VA(this);
248
249 if (m_opaque_ptr) {
250 if (m_opaque_ptr->GetCompileUnit())
251 return m_opaque_ptr->GetCompileUnit()->GetIsOptimized();
252 }
253 return false;
254}
#define LLDB_INSTRUMENT_VA(...)
lldb_private::AddressRangeListImpl & ref() const
void SetAddress(lldb::SBSection section, lldb::addr_t offset)
Definition SBAddress.cpp:88
void SetPtr(lldb_private::Block *lldb_object_ptr)
Definition SBBlock.cpp:178
uint32_t GetPrologueByteSize()
const char * GetBaseName() const
const char * GetArgumentName(uint32_t arg_idx)
const char * GetMangledName() const
lldb_private::Function * m_opaque_ptr
Definition SBFunction.h:84
bool GetDescription(lldb::SBStream &description)
lldb::SBAddress GetStartAddress()
const lldb::SBFunction & operator=(const lldb::SBFunction &rhs)
friend class SBAddress
Definition SBFunction.h:78
bool IsValid() const
const char * GetDisplayName() const
lldb::SBBlock GetBlock()
lldb_private::Function * get()
lldb::SBInstructionList GetInstructions(lldb::SBTarget target)
bool operator!=(const lldb::SBFunction &rhs) const
void reset(lldb_private::Function *lldb_object_ptr)
bool operator==(const lldb::SBFunction &rhs) const
const char * GetName() const
LLDB_DEPRECATED_FIXME("Not compatible with discontinuous functions.", "GetRanges()") lldb lldb::SBAddressRangeList GetRanges()
lldb::LanguageType GetLanguage()
lldb::SBType GetType()
void SetDisassembler(const lldb::DisassemblerSP &opaque_sp)
lldb::TargetSP GetSP() const
Definition SBTarget.cpp:592
lldb_private::TypeImpl & ref()
Definition SBType.cpp:99
bool Slide(int64_t offset)
Definition Address.h:452
A class that describes a single lexical block.
Definition Block.h:41
lldb::VariableListSP GetBlockVariableList(bool can_create)
Get the variable list for this block only.
Definition Block.cpp:392
const char * AsCString(const char *value_if_empty) const
Get the string value as a C string.
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 class that describes a function.
Definition Function.h:400
AddressRanges GetAddressRanges()
Definition Function.h:448
void SetType(const lldb::TypeSP &type_sp)
Definition Type.cpp:964
ConstString GetName()
Definition Type.cpp:441
lldb::VariableSP GetVariableAtIndex(size_t idx) const
A class that represents a running process on the host machine.
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
std::shared_ptr< lldb_private::VariableList > VariableListSP
std::shared_ptr< lldb_private::Variable > VariableSP
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::Module > ModuleSP
@ eValueTypeVariableArgument
function argument variables