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"
14#include "lldb/Core/Module.h"
17#include "lldb/Symbol/Type.h"
20#include "lldb/Target/Target.h"
22
23using namespace lldb;
24using namespace lldb_private;
25
27
29 : m_opaque_ptr(lldb_object_ptr) {}
30
32 : m_opaque_ptr(rhs.m_opaque_ptr) {
33 LLDB_INSTRUMENT_VA(this, rhs);
34}
35
37 LLDB_INSTRUMENT_VA(this, rhs);
38
40 return *this;
41}
42
44
45bool SBFunction::IsValid() const {
47 return this->operator bool();
48}
49SBFunction::operator bool() const {
51
52 return m_opaque_ptr != nullptr;
53}
54
55const char *SBFunction::GetName() const {
57
58 if (m_opaque_ptr)
59 return m_opaque_ptr->GetName().AsCString();
60
61 return nullptr;
62}
63
64const char *SBFunction::GetDisplayName() const {
66
67 if (m_opaque_ptr)
69
70 return nullptr;
71}
72
73const char *SBFunction::GetMangledName() const {
75
76 if (m_opaque_ptr)
78 return nullptr;
79}
80
81bool SBFunction::operator==(const SBFunction &rhs) const {
82 LLDB_INSTRUMENT_VA(this, rhs);
83
84 return m_opaque_ptr == rhs.m_opaque_ptr;
85}
86
87bool SBFunction::operator!=(const SBFunction &rhs) const {
88 LLDB_INSTRUMENT_VA(this, rhs);
89
90 return m_opaque_ptr != rhs.m_opaque_ptr;
91}
92
94 LLDB_INSTRUMENT_VA(this, s);
95
96 if (m_opaque_ptr) {
97 s.Printf("SBFunction: id = 0x%8.8" PRIx64 ", name = %s",
99 Type *func_type = m_opaque_ptr->GetType();
100 if (func_type)
101 s.Printf(", type = %s", func_type->GetName().AsCString());
102 return true;
103 }
104 s.Printf("No value");
105 return false;
106}
107
109 LLDB_INSTRUMENT_VA(this, target);
110
111 return GetInstructions(target, nullptr);
112}
113
115 const char *flavor) {
116 LLDB_INSTRUMENT_VA(this, target, flavor);
117
118 SBInstructionList sb_instructions;
119 if (m_opaque_ptr) {
120 TargetSP target_sp(target.GetSP());
121 std::unique_lock<std::recursive_mutex> lock;
122 ModuleSP module_sp(
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, *target_sp,
129 m_opaque_ptr->GetAddressRange(), force_live_memory));
130 }
131 }
132 return sb_instructions;
133}
134
136
138 m_opaque_ptr = lldb_object_ptr;
139}
140
142 LLDB_INSTRUMENT_VA(this);
143
144 SBAddress addr;
145 if (m_opaque_ptr)
147 return addr;
148}
149
151 LLDB_INSTRUMENT_VA(this);
152
153 SBAddress addr;
154 if (m_opaque_ptr) {
156 if (byte_size > 0) {
158 addr->Slide(byte_size);
159 }
160 }
161 return addr;
162}
163
165 LLDB_INSTRUMENT_VA(this);
166
168 if (m_opaque_ptr) {
171 ranges.Append(std::move(range));
172 }
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(...)
void Append(const lldb::SBAddressRange &addr_range)
AddressRangeUP m_opaque_up
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:73
lldb::SBAddress GetEndAddress()
Definition: SBFunction.cpp:150
lldb_private::Function * m_opaque_ptr
Definition: SBFunction.h:80
bool GetDescription(lldb::SBStream &description)
Definition: SBFunction.cpp:93
lldb::SBAddress GetStartAddress()
Definition: SBFunction.cpp:141
const lldb::SBFunction & operator=(const lldb::SBFunction &rhs)
Definition: SBFunction.cpp:36
bool IsValid() const
Definition: SBFunction.cpp:45
const char * GetDisplayName() const
Definition: SBFunction.cpp:64
lldb::SBBlock GetBlock()
Definition: SBFunction.cpp:218
lldb_private::Function * get()
Definition: SBFunction.cpp:135
lldb::SBInstructionList GetInstructions(lldb::SBTarget target)
Definition: SBFunction.cpp:108
bool operator!=(const lldb::SBFunction &rhs) const
Definition: SBFunction.cpp:87
void reset(lldb_private::Function *lldb_object_ptr)
Definition: SBFunction.cpp:137
bool operator==(const lldb::SBFunction &rhs) const
Definition: SBFunction.cpp:81
const char * GetName() const
Definition: SBFunction.cpp:55
lldb::SBAddressRangeList GetRanges()
Definition: SBFunction.cpp:164
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:585
lldb_private::TypeImpl & ref()
Definition: SBType.cpp:99
Address & GetBaseAddress()
Get accessor for the base address of the range.
Definition: AddressRange.h:211
lldb::addr_t GetByteSize() const
Get accessor for the byte size of this range.
Definition: AddressRange.h:223
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:415
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, Target &target, const AddressRange &disasm_range, bool force_live_memory=false)
A class that describes a function.
Definition: Function.h:399
const AddressRange & GetAddressRange()
Definition: Function.h:447
ConstString GetName() const
Definition: Function.cpp:693
const Mangled & GetMangled() const
Definition: Function.h:528
Type * GetType()
Get accessor for the type that describes the function return value type, and parameter types.
Definition: Function.cpp:539
uint32_t GetPrologueByteSize()
Get the size of the prologue instructions for this function.
Definition: Function.cpp:567
CompileUnit * GetCompileUnit()
Get accessor for the compile unit that owns this function.
Definition: Function.cpp:386
Block & GetBlock(bool can_create)
Get accessor for the block list.
Definition: Function.cpp:371
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:940
ConstString GetName()
Definition: Type.cpp:432
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:481
std::shared_ptr< lldb_private::Variable > VariableSP
Definition: lldb-forward.h:480
uint64_t addr_t
Definition: lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:442
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:369
@ eValueTypeVariableArgument
function argument variables
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:47