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
33 : m_opaque_ptr(rhs.m_opaque_ptr) {
34 LLDB_INSTRUMENT_VA(this, rhs);
35}
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();
61
62 return nullptr;
63}
64
65const char *SBFunction::GetDisplayName() const {
67
68 if (m_opaque_ptr)
70
71 return nullptr;
72}
73
74const char *SBFunction::GetMangledName() const {
76
77 if (m_opaque_ptr)
79 return nullptr;
80}
81
82bool SBFunction::operator==(const SBFunction &rhs) const {
83 LLDB_INSTRUMENT_VA(this, rhs);
84
85 return m_opaque_ptr == rhs.m_opaque_ptr;
86}
87
88bool SBFunction::operator!=(const SBFunction &rhs) const {
89 LLDB_INSTRUMENT_VA(this, rhs);
90
91 return m_opaque_ptr != rhs.m_opaque_ptr;
92}
93
95 LLDB_INSTRUMENT_VA(this, s);
96
97 if (m_opaque_ptr) {
98 s.Printf("SBFunction: id = 0x%8.8" PRIx64 ", name = %s",
100 Type *func_type = m_opaque_ptr->GetType();
101 if (func_type)
102 s.Printf(", type = %s", func_type->GetName().AsCString());
103 return true;
104 }
105 s.Printf("No value");
106 return false;
107}
108
110 LLDB_INSTRUMENT_VA(this, target);
111
112 return GetInstructions(target, nullptr);
113}
114
116 const char *flavor) {
117 LLDB_INSTRUMENT_VA(this, target, flavor);
118
119 SBInstructionList sb_instructions;
120 if (m_opaque_ptr) {
121 TargetSP target_sp(target.GetSP());
122 std::unique_lock<std::recursive_mutex> lock;
124 if (target_sp && module_sp) {
125 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
126 const bool force_live_memory = true;
128 module_sp->GetArchitecture(), nullptr, flavor,
129 target_sp->GetDisassemblyCPU(), target_sp->GetDisassemblyFeatures(),
130 *target_sp, m_opaque_ptr->GetAddressRange(), force_live_memory));
131 }
132 }
133 return sb_instructions;
134}
135
137
139 m_opaque_ptr = lldb_object_ptr;
140}
141
143 LLDB_INSTRUMENT_VA(this);
144
145 SBAddress addr;
146 if (m_opaque_ptr)
148 return addr;
149}
150
151SBAddress SBFunction::GetEndAddress() {
152 LLDB_INSTRUMENT_VA(this);
153
154 SBAddress addr;
155 if (m_opaque_ptr) {
157 if (!ranges.empty()) {
158 // Return the end of the first range, use GetRanges to get all ranges.
159 addr.SetAddress(ranges.front().GetBaseAddress());
160 addr->Slide(ranges.front().GetByteSize());
161 }
162 }
163 return addr;
164}
165
167 LLDB_INSTRUMENT_VA(this);
168
170 if (m_opaque_ptr)
172
173 return ranges;
174}
175
176const char *SBFunction::GetArgumentName(uint32_t arg_idx) {
177 LLDB_INSTRUMENT_VA(this, arg_idx);
178
179 if (!m_opaque_ptr)
180 return nullptr;
181
182 Block &block = m_opaque_ptr->GetBlock(true);
183 VariableListSP variable_list_sp = block.GetBlockVariableList(true);
184 if (!variable_list_sp)
185 return nullptr;
186
187 VariableList arguments;
189 arguments, true);
190 lldb::VariableSP variable_sp = arguments.GetVariableAtIndex(arg_idx);
191 if (!variable_sp)
192 return nullptr;
193
194 return variable_sp->GetName().GetCString();
195}
196
198 LLDB_INSTRUMENT_VA(this);
199
200 if (m_opaque_ptr)
202 return 0;
203}
204
206 LLDB_INSTRUMENT_VA(this);
207
208 SBType sb_type;
209 if (m_opaque_ptr) {
210 Type *function_type = m_opaque_ptr->GetType();
211 if (function_type)
212 sb_type.ref().SetType(function_type->shared_from_this());
213 }
214 return sb_type;
215}
216
218 LLDB_INSTRUMENT_VA(this);
219
220 SBBlock sb_block;
221 if (m_opaque_ptr)
222 sb_block.SetPtr(&m_opaque_ptr->GetBlock(true));
223 return sb_block;
224}
225
227 LLDB_INSTRUMENT_VA(this);
228
229 if (m_opaque_ptr) {
232 }
234}
235
237 LLDB_INSTRUMENT_VA(this);
238
239 if (m_opaque_ptr) {
242 }
243 return false;
244}
#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:162
uint32_t GetPrologueByteSize()
Definition: SBFunction.cpp:197
const char * GetArgumentName(uint32_t arg_idx)
Definition: SBFunction.cpp:176
const char * GetMangledName() const
Definition: SBFunction.cpp:74
lldb_private::Function * m_opaque_ptr
Definition: SBFunction.h:82
bool GetDescription(lldb::SBStream &description)
Definition: SBFunction.cpp:94
lldb::SBAddress GetStartAddress()
Definition: SBFunction.cpp:142
const lldb::SBFunction & operator=(const lldb::SBFunction &rhs)
Definition: SBFunction.cpp:37
bool IsValid() const
Definition: SBFunction.cpp:46
const char * GetDisplayName() const
Definition: SBFunction.cpp:65
lldb::SBBlock GetBlock()
Definition: SBFunction.cpp:217
lldb_private::Function * get()
Definition: SBFunction.cpp:136
lldb::SBInstructionList GetInstructions(lldb::SBTarget target)
Definition: SBFunction.cpp:109
bool operator!=(const lldb::SBFunction &rhs) const
Definition: SBFunction.cpp:88
void reset(lldb_private::Function *lldb_object_ptr)
Definition: SBFunction.cpp:138
bool operator==(const lldb::SBFunction &rhs) const
Definition: SBFunction.cpp:82
const char * GetName() const
Definition: SBFunction.cpp:56
LLDB_DEPRECATED_FIXME("Not compatible with discontinuous functions.", "GetRanges()") lldb lldb::SBAddressRangeList GetRanges()
Definition: SBFunction.cpp:166
lldb::LanguageType GetLanguage()
Definition: SBFunction.cpp:226
lldb::SBType GetType()
Definition: SBFunction.cpp:205
void SetDisassembler(const lldb::DisassemblerSP &opaque_sp)
lldb::TargetSP GetSP() const
Definition: SBTarget.cpp:593
lldb_private::TypeImpl & ref()
Definition: SBType.cpp:99
Address & GetBaseAddress()
Get accessor for the base address of the range.
Definition: AddressRange.h:211
bool Slide(int64_t offset)
Definition: Address.h:459
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
Definition: Address.cpp:285
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:405
bool GetIsOptimized()
Get whether compiler optimizations were enabled for this compile unit.
lldb::LanguageType GetLanguage()
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:188
static lldb::DisassemblerSP DisassembleRange(const ArchSpec &arch, const char *plugin_name, const char *flavor, const char *cpu, const char *features, Target &target, const AddressRange &disasm_range, bool force_live_memory=false)
A class that describes a function.
Definition: Function.h:399
const Address & GetAddress() const
Return the address of the function (its entry point).
Definition: Function.h:455
const AddressRange & GetAddressRange()
DEPRECATED: Use GetAddressRanges instead.
Definition: Function.h:448
ConstString GetName() const
Definition: Function.cpp:719
const Mangled & GetMangled() const
Definition: Function.h:537
Type * GetType()
Get accessor for the type that describes the function return value type, and parameter types.
Definition: Function.cpp:566
uint32_t GetPrologueByteSize()
Get the size of the prologue instructions for this function.
Definition: Function.cpp:594
AddressRanges GetAddressRanges()
Definition: Function.h:450
CompileUnit * GetCompileUnit()
Get accessor for the compile unit that owns this function.
Definition: Function.cpp:411
Block & GetBlock(bool can_create)
Get accessor for the block list.
Definition: Function.cpp:396
ConstString & GetMangledName()
Mangled name get accessor.
Definition: Mangled.h:145
ConstString GetDisplayDemangledName() const
Display demangled name get accessor.
Definition: Mangled.cpp:320
void SetType(const lldb::TypeSP &type_sp)
Definition: Type.cpp:954
ConstString GetName()
Definition: Type.cpp:440
lldb::VariableSP GetVariableAtIndex(size_t idx) const
size_t AppendVariablesWithScope(lldb::ValueType type, VariableList &var_list, bool if_unique=true)
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
std::shared_ptr< lldb_private::VariableList > VariableListSP
Definition: lldb-forward.h:487
std::shared_ptr< lldb_private::Variable > VariableSP
Definition: lldb-forward.h:486
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:448
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:373
@ eValueTypeVariableArgument
function argument variables
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:47