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
10#include "lldb/API/SBProcess.h"
11#include "lldb/API/SBStream.h"
13#include "lldb/Core/Module.h"
16#include "lldb/Symbol/Type.h"
19#include "lldb/Target/Target.h"
21
22using namespace lldb;
23using namespace lldb_private;
24
26
28 : m_opaque_ptr(lldb_object_ptr) {}
29
31 : m_opaque_ptr(rhs.m_opaque_ptr) {
32 LLDB_INSTRUMENT_VA(this, rhs);
33}
34
36 LLDB_INSTRUMENT_VA(this, rhs);
37
39 return *this;
40}
41
43
44bool SBFunction::IsValid() const {
46 return this->operator bool();
47}
48SBFunction::operator bool() const {
50
51 return m_opaque_ptr != nullptr;
52}
53
54const char *SBFunction::GetName() const {
56
57 if (m_opaque_ptr)
58 return m_opaque_ptr->GetName().AsCString();
59
60 return nullptr;
61}
62
63const char *SBFunction::GetDisplayName() const {
65
66 if (m_opaque_ptr)
68
69 return nullptr;
70}
71
72const char *SBFunction::GetMangledName() const {
74
75 if (m_opaque_ptr)
77 return nullptr;
78}
79
80bool SBFunction::operator==(const SBFunction &rhs) const {
81 LLDB_INSTRUMENT_VA(this, rhs);
82
83 return m_opaque_ptr == rhs.m_opaque_ptr;
84}
85
86bool SBFunction::operator!=(const SBFunction &rhs) const {
87 LLDB_INSTRUMENT_VA(this, rhs);
88
89 return m_opaque_ptr != rhs.m_opaque_ptr;
90}
91
93 LLDB_INSTRUMENT_VA(this, s);
94
95 if (m_opaque_ptr) {
96 s.Printf("SBFunction: id = 0x%8.8" PRIx64 ", name = %s",
98 Type *func_type = m_opaque_ptr->GetType();
99 if (func_type)
100 s.Printf(", type = %s", func_type->GetName().AsCString());
101 return true;
102 }
103 s.Printf("No value");
104 return false;
105}
106
108 LLDB_INSTRUMENT_VA(this, target);
109
110 return GetInstructions(target, nullptr);
111}
112
114 const char *flavor) {
115 LLDB_INSTRUMENT_VA(this, target, flavor);
116
117 SBInstructionList sb_instructions;
118 if (m_opaque_ptr) {
119 TargetSP target_sp(target.GetSP());
120 std::unique_lock<std::recursive_mutex> lock;
121 ModuleSP module_sp(
123 if (target_sp && module_sp) {
124 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
125 const bool force_live_memory = true;
127 module_sp->GetArchitecture(), nullptr, flavor, *target_sp,
128 m_opaque_ptr->GetAddressRange(), force_live_memory));
129 }
130 }
131 return sb_instructions;
132}
133
135
137 m_opaque_ptr = lldb_object_ptr;
138}
139
141 LLDB_INSTRUMENT_VA(this);
142
143 SBAddress addr;
144 if (m_opaque_ptr)
146 return addr;
147}
148
150 LLDB_INSTRUMENT_VA(this);
151
152 SBAddress addr;
153 if (m_opaque_ptr) {
155 if (byte_size > 0) {
157 addr->Slide(byte_size);
158 }
159 }
160 return addr;
161}
162
163const char *SBFunction::GetArgumentName(uint32_t arg_idx) {
164 LLDB_INSTRUMENT_VA(this, arg_idx);
165
166 if (!m_opaque_ptr)
167 return nullptr;
168
169 Block &block = m_opaque_ptr->GetBlock(true);
170 VariableListSP variable_list_sp = block.GetBlockVariableList(true);
171 if (!variable_list_sp)
172 return nullptr;
173
174 VariableList arguments;
176 arguments, true);
177 lldb::VariableSP variable_sp = arguments.GetVariableAtIndex(arg_idx);
178 if (!variable_sp)
179 return nullptr;
180
181 return variable_sp->GetName().GetCString();
182}
183
185 LLDB_INSTRUMENT_VA(this);
186
187 if (m_opaque_ptr)
189 return 0;
190}
191
193 LLDB_INSTRUMENT_VA(this);
194
195 SBType sb_type;
196 if (m_opaque_ptr) {
197 Type *function_type = m_opaque_ptr->GetType();
198 if (function_type)
199 sb_type.ref().SetType(function_type->shared_from_this());
200 }
201 return sb_type;
202}
203
205 LLDB_INSTRUMENT_VA(this);
206
207 SBBlock sb_block;
208 if (m_opaque_ptr)
209 sb_block.SetPtr(&m_opaque_ptr->GetBlock(true));
210 return sb_block;
211}
212
214 LLDB_INSTRUMENT_VA(this);
215
216 if (m_opaque_ptr) {
219 }
221}
222
224 LLDB_INSTRUMENT_VA(this);
225
226 if (m_opaque_ptr) {
229 }
230 return false;
231}
#define LLDB_INSTRUMENT_VA(...)
void SetAddress(lldb::SBSection section, lldb::addr_t offset)
Definition: SBAddress.cpp:88
void SetPtr(lldb_private::Block *lldb_object_ptr)
Definition: SBBlock.cpp:161
uint32_t GetPrologueByteSize()
Definition: SBFunction.cpp:184
const char * GetArgumentName(uint32_t arg_idx)
Definition: SBFunction.cpp:163
const char * GetMangledName() const
Definition: SBFunction.cpp:72
lldb::SBAddress GetEndAddress()
Definition: SBFunction.cpp:149
lldb_private::Function * m_opaque_ptr
Definition: SBFunction.h:77
bool GetDescription(lldb::SBStream &description)
Definition: SBFunction.cpp:92
lldb::SBAddress GetStartAddress()
Definition: SBFunction.cpp:140
const lldb::SBFunction & operator=(const lldb::SBFunction &rhs)
Definition: SBFunction.cpp:35
bool IsValid() const
Definition: SBFunction.cpp:44
const char * GetDisplayName() const
Definition: SBFunction.cpp:63
lldb::SBBlock GetBlock()
Definition: SBFunction.cpp:204
lldb_private::Function * get()
Definition: SBFunction.cpp:134
lldb::SBInstructionList GetInstructions(lldb::SBTarget target)
Definition: SBFunction.cpp:107
bool operator!=(const lldb::SBFunction &rhs) const
Definition: SBFunction.cpp:86
void reset(lldb_private::Function *lldb_object_ptr)
Definition: SBFunction.cpp:136
bool operator==(const lldb::SBFunction &rhs) const
Definition: SBFunction.cpp:80
const char * GetName() const
Definition: SBFunction.cpp:54
lldb::LanguageType GetLanguage()
Definition: SBFunction.cpp:213
lldb::SBType GetType()
Definition: SBFunction.cpp:192
void SetDisassembler(const lldb::DisassemblerSP &opaque_sp)
lldb::TargetSP GetSP() const
Definition: SBTarget.cpp:585
lldb_private::TypeImpl & ref()
Definition: SBType.cpp:93
Address & GetBaseAddress()
Get accessor for the base address of the range.
Definition: AddressRange.h:209
lldb::addr_t GetByteSize() const
Get accessor for the byte size of this range.
Definition: AddressRange.h:221
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:399
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:692
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:538
uint32_t GetPrologueByteSize()
Get the size of the prologue instructions for this function.
Definition: Function.cpp:566
CompileUnit * GetCompileUnit()
Get accessor for the compile unit that owns this function.
Definition: Function.cpp:385
Block & GetBlock(bool can_create)
Get accessor for the block list.
Definition: Function.cpp:370
ConstString & GetMangledName()
Mangled name get accessor.
Definition: Mangled.h:145
ConstString GetDisplayDemangledName() const
Display demangled name get accessor.
Definition: Mangled.cpp:312
void SetType(const lldb::TypeSP &type_sp)
Definition: Type.cpp:934
ConstString GetName()
Definition: Type.cpp:428
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: SBAttachInfo.h:14
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:475
std::shared_ptr< lldb_private::Variable > VariableSP
Definition: lldb-forward.h:474
uint64_t addr_t
Definition: lldb-types.h:79
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:436
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:365
@ eValueTypeVariableArgument
function argument variables
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:47