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"
24
25using namespace lldb;
26using namespace lldb_private;
27
29
31 : m_opaque_ptr(lldb_object_ptr) {}
32
37
39 LLDB_INSTRUMENT_VA(this, rhs);
40
42 return *this;
43}
44
46
47bool SBFunction::IsValid() const {
49 return this->operator bool();
50}
51SBFunction::operator bool() const {
53
54 return m_opaque_ptr != nullptr;
55}
56
57const char *SBFunction::GetName() const {
59
60 if (m_opaque_ptr)
62
63 return nullptr;
64}
65
66const char *SBFunction::GetDisplayName() const {
68
69 if (m_opaque_ptr)
71 m_opaque_ptr->GetMangled().GetDisplayDemangledName());
72
73 return nullptr;
74}
75
76const char *SBFunction::GetMangledName() const {
78
79 if (m_opaque_ptr)
81 m_opaque_ptr->GetMangled().GetMangledName());
82 return nullptr;
83}
84
85const char *SBFunction::GetBaseName() const {
87
88 if (!m_opaque_ptr)
89 return nullptr;
90
92 m_opaque_ptr->GetMangled().GetBaseName());
93}
94
95bool SBFunction::operator==(const SBFunction &rhs) const {
96 LLDB_INSTRUMENT_VA(this, rhs);
97
98 return m_opaque_ptr == rhs.m_opaque_ptr;
99}
100
101bool SBFunction::operator!=(const SBFunction &rhs) const {
102 LLDB_INSTRUMENT_VA(this, rhs);
103
104 return m_opaque_ptr != rhs.m_opaque_ptr;
105}
106
108 LLDB_INSTRUMENT_VA(this, s);
109
110 if (m_opaque_ptr) {
111 s.Printf("SBFunction: id = 0x%8.8" PRIx64 ", name = %s",
112 m_opaque_ptr->GetID(), m_opaque_ptr->GetName().AsCString(""));
113 Type *func_type = m_opaque_ptr->GetType();
114 if (func_type)
115 s.Printf(", type = %s", func_type->GetName().AsCString(""));
116 return true;
117 }
118 s.Printf("No value");
119 return false;
120}
121
123 LLDB_INSTRUMENT_VA(this, target);
124
125 return GetInstructions(target, nullptr);
126}
127
129 const char *flavor) {
130 LLDB_INSTRUMENT_VA(this, target, flavor);
131
132 SBInstructionList sb_instructions;
133 if (m_opaque_ptr) {
134 TargetSP target_sp(target.GetSP());
135 TargetAPIMutex api_lock;
136 std::unique_lock<TargetAPIMutex> guard;
137 ModuleSP module_sp(m_opaque_ptr->GetAddress().GetModule());
138 if (target_sp && module_sp) {
139 api_lock = TargetAPIMutex(target_sp->GetAPIMutex());
140 guard = std::unique_lock<TargetAPIMutex>(api_lock);
141 const bool force_live_memory = true;
143 module_sp->GetArchitecture(), nullptr, flavor,
144 target_sp->GetDisassemblyCPU(), target_sp->GetDisassemblyFeatures(),
145 *target_sp, m_opaque_ptr->GetAddressRanges(), force_live_memory));
146 }
147 }
148 return sb_instructions;
149}
150
152
154 m_opaque_ptr = lldb_object_ptr;
155}
156
158 LLDB_INSTRUMENT_VA(this);
159
160 SBAddress addr;
161 if (m_opaque_ptr)
162 addr.SetAddress(m_opaque_ptr->GetAddress());
163 return addr;
164}
165
166SBAddress SBFunction::GetEndAddress() {
167 LLDB_INSTRUMENT_VA(this);
168
169 SBAddress addr;
170 if (m_opaque_ptr) {
172 if (!ranges.empty()) {
173 // Return the end of the first range, use GetRanges to get all ranges.
174 addr.SetAddress(ranges.front().GetBaseAddress());
175 addr->Slide(ranges.front().GetByteSize());
176 }
177 }
178 return addr;
179}
180
182 LLDB_INSTRUMENT_VA(this);
183
185 if (m_opaque_ptr)
186 ranges.ref() = AddressRangeListImpl(m_opaque_ptr->GetAddressRanges());
187
188 return ranges;
189}
190
191const char *SBFunction::GetArgumentName(uint32_t arg_idx) {
192 LLDB_INSTRUMENT_VA(this, arg_idx);
193
194 if (!m_opaque_ptr)
195 return nullptr;
196
197 Block &block = m_opaque_ptr->GetBlock(true);
198 VariableListSP variable_list_sp = block.GetBlockVariableList(true);
199 if (!variable_list_sp)
200 return nullptr;
201
202 VariableList arguments;
203 variable_list_sp->AppendVariablesWithScope(eValueTypeVariableArgument,
204 arguments, true);
205 lldb::VariableSP variable_sp = arguments.GetVariableAtIndex(arg_idx);
206 if (!variable_sp)
207 return nullptr;
208
209 return StringPool::GetSystemPool().Intern(variable_sp->GetName());
210}
211
213 LLDB_INSTRUMENT_VA(this);
214
215 if (m_opaque_ptr)
216 return m_opaque_ptr->GetPrologueByteSize();
217 return 0;
218}
219
221 LLDB_INSTRUMENT_VA(this);
222
223 SBType sb_type;
224 if (m_opaque_ptr) {
225 Type *function_type = m_opaque_ptr->GetType();
226 if (function_type)
227 sb_type.ref().SetType(function_type->shared_from_this());
228 }
229 return sb_type;
230}
231
233 LLDB_INSTRUMENT_VA(this);
234
235 SBBlock sb_block;
236 if (m_opaque_ptr)
237 sb_block.SetPtr(&m_opaque_ptr->GetBlock(true));
238 return sb_block;
239}
240
242 LLDB_INSTRUMENT_VA(this);
243
244 if (m_opaque_ptr) {
245 if (m_opaque_ptr->GetCompileUnit())
246 return m_opaque_ptr->GetCompileUnit()->GetLanguage();
247 }
249}
250
252 LLDB_INSTRUMENT_VA(this);
253
254 if (m_opaque_ptr) {
255 if (m_opaque_ptr->GetCompileUnit())
256 return m_opaque_ptr->GetCompileUnit()->GetIsOptimized();
257 }
258 return false;
259}
#define LLDB_INSTRUMENT_VA(...)
lldb_private::AddressRangeListImpl & ref() const
void SetAddress(lldb::SBSection section, lldb::addr_t offset)
Definition SBAddress.cpp:90
void SetPtr(lldb_private::Block *lldb_object_ptr)
Definition SBBlock.cpp:180
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:600
lldb_private::TypeImpl & ref()
Definition SBType.cpp:100
bool Slide(int64_t offset)
Definition Address.h:446
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:382
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:386
AddressRanges GetAddressRanges()
Definition Function.h:434
const char * Intern(llvm::StringRef str) const
Definition StringPool.h:78
const char * InternNonEmpty(llvm::StringRef str) const
Like Intern, but an empty string yields nullptr.
Definition StringPool.h:81
static StringPoolRef GetSystemPool()
The system pool. Only valid between Initialize and Terminate.
A Lockable handle over a Target's API mutex, returned by Target::GetAPIMutex() and backing the public...
void SetType(const lldb::TypeSP &type_sp)
ConstString GetName()
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
@ eValueTypeVariableArgument
function argument variables
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::Module > ModuleSP