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;
123 ModuleSP module_sp(
125 if (target_sp && module_sp) {
126 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
127 const bool force_live_memory = true;
129 module_sp->GetArchitecture(), nullptr, flavor,
130 target_sp->GetDisassemblyCPU(), target_sp->GetDisassemblyFeatures(),
131 *target_sp, m_opaque_ptr->GetAddressRange(), force_live_memory));
132 }
133 }
134 return sb_instructions;
135}
136
138
140 m_opaque_ptr = lldb_object_ptr;
141}
142
144 LLDB_INSTRUMENT_VA(this);
145
146 SBAddress addr;
147 if (m_opaque_ptr)
149 return addr;
150}
151
152SBAddress SBFunction::GetEndAddress() {
153 LLDB_INSTRUMENT_VA(this);
154
155 SBAddress addr;
156 if (m_opaque_ptr) {
158 if (!ranges.empty()) {
159 // Return the end of the first range, use GetRanges to get all ranges.
160 addr.SetAddress(ranges.front().GetBaseAddress());
161 addr->Slide(ranges.front().GetByteSize());
162 }
163 }
164 return addr;
165}
166
168 LLDB_INSTRUMENT_VA(this);
169
171 if (m_opaque_ptr)
173
174 return ranges;
175}
176
177const char *SBFunction::GetArgumentName(uint32_t arg_idx) {
178 LLDB_INSTRUMENT_VA(this, arg_idx);
179
180 if (!m_opaque_ptr)
181 return nullptr;
182
183 Block &block = m_opaque_ptr->GetBlock(true);
184 VariableListSP variable_list_sp = block.GetBlockVariableList(true);
185 if (!variable_list_sp)
186 return nullptr;
187
188 VariableList arguments;
190 arguments, true);
191 lldb::VariableSP variable_sp = arguments.GetVariableAtIndex(arg_idx);
192 if (!variable_sp)
193 return nullptr;
194
195 return variable_sp->GetName().GetCString();
196}
197
199 LLDB_INSTRUMENT_VA(this);
200
201 if (m_opaque_ptr)
203 return 0;
204}
205
207 LLDB_INSTRUMENT_VA(this);
208
209 SBType sb_type;
210 if (m_opaque_ptr) {
211 Type *function_type = m_opaque_ptr->GetType();
212 if (function_type)
213 sb_type.ref().SetType(function_type->shared_from_this());
214 }
215 return sb_type;
216}
217
219 LLDB_INSTRUMENT_VA(this);
220
221 SBBlock sb_block;
222 if (m_opaque_ptr)
223 sb_block.SetPtr(&m_opaque_ptr->GetBlock(true));
224 return sb_block;
225}
226
228 LLDB_INSTRUMENT_VA(this);
229
230 if (m_opaque_ptr) {
233 }
235}
236
238 LLDB_INSTRUMENT_VA(this);
239
240 if (m_opaque_ptr) {
243 }
244 return false;
245}
#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:198
const char * GetArgumentName(uint32_t arg_idx)
Definition: SBFunction.cpp:177
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:143
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:218
lldb_private::Function * get()
Definition: SBFunction.cpp:137
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:139
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:167
lldb::LanguageType GetLanguage()
Definition: SBFunction.cpp:227
lldb::SBType GetType()
Definition: SBFunction.cpp:206
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:407
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 AddressRange & GetAddressRange()
DEPRECATED: Use GetAddressRanges instead.
Definition: Function.h:448
ConstString GetName() const
Definition: Function.cpp:720
const Mangled & GetMangled() const
Definition: Function.h:532
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