LLDB mainline
SBBlock.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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
9#include "lldb/API/SBBlock.h"
10#include "lldb/API/SBAddress.h"
11#include "lldb/API/SBFileSpec.h"
12#include "lldb/API/SBFrame.h"
13#include "lldb/API/SBStream.h"
14#include "lldb/API/SBValue.h"
17#include "lldb/Symbol/Block.h"
24#include "lldb/lldb-types.h"
25
26using namespace lldb;
27using namespace lldb_private;
28
30
32 : m_opaque_ptr(lldb_object_ptr) {}
33
37
39 LLDB_INSTRUMENT_VA(this, rhs);
40
42 return *this;
43}
44
46
47bool SBBlock::IsValid() const {
49 return this->operator bool();
50}
51SBBlock::operator bool() const {
53
54 return m_opaque_ptr != nullptr;
55}
56
57bool SBBlock::operator==(const SBBlock &rhs) const {
58 LLDB_INSTRUMENT_VA(this, rhs);
59
60 return m_opaque_ptr != nullptr && rhs.m_opaque_ptr != nullptr &&
61 m_opaque_ptr->GetFunction() == rhs.m_opaque_ptr->GetFunction() &&
62 m_opaque_ptr->GetFunction().GetCompileUnit() ==
65}
66
67bool SBBlock::operator!=(const SBBlock &rhs) const {
68 LLDB_INSTRUMENT_VA(this, rhs);
69
70 return !(*this == rhs);
71}
72
73bool SBBlock::IsInlined() const {
75
76 if (m_opaque_ptr)
77 return m_opaque_ptr->GetInlinedFunctionInfo() != nullptr;
78 return false;
79}
80
81const char *SBBlock::GetInlinedName() const {
83
84 if (m_opaque_ptr) {
85 const InlineFunctionInfo *inlined_info =
86 m_opaque_ptr->GetInlinedFunctionInfo();
87 if (inlined_info) {
89 inlined_info->GetName());
90 }
91 }
92 return nullptr;
93}
94
97
98 SBFileSpec sb_file;
99 if (m_opaque_ptr) {
100 const InlineFunctionInfo *inlined_info =
101 m_opaque_ptr->GetInlinedFunctionInfo();
102 if (inlined_info)
103 sb_file.SetFileSpec(inlined_info->GetCallSite().GetFile());
104 }
105 return sb_file;
106}
107
109 LLDB_INSTRUMENT_VA(this);
110
111 if (m_opaque_ptr) {
112 const InlineFunctionInfo *inlined_info =
113 m_opaque_ptr->GetInlinedFunctionInfo();
114 if (inlined_info)
115 return inlined_info->GetCallSite().GetLine();
116 }
117 return 0;
118}
119
121 LLDB_INSTRUMENT_VA(this);
122
123 if (m_opaque_ptr) {
124 const InlineFunctionInfo *inlined_info =
125 m_opaque_ptr->GetInlinedFunctionInfo();
126 if (inlined_info)
127 return inlined_info->GetCallSite().GetColumn();
128 }
129 return 0;
130}
131
132void SBBlock::AppendVariables(bool can_create, bool get_parent_variables,
133 lldb_private::VariableList *var_list) {
134 if (IsValid()) {
135 bool show_inline = true;
136 m_opaque_ptr->AppendVariables(
137 can_create, get_parent_variables, show_inline,
138 [](Variable *) { return true; }, var_list);
139 }
140}
141
143 LLDB_INSTRUMENT_VA(this);
144
145 SBBlock sb_block;
146 if (m_opaque_ptr)
147 sb_block.m_opaque_ptr = m_opaque_ptr->GetParent();
148 return sb_block;
149}
150
152 LLDB_INSTRUMENT_VA(this);
153
154 SBBlock sb_block;
155 if (m_opaque_ptr)
156 sb_block.m_opaque_ptr = m_opaque_ptr->GetContainingInlinedBlock();
157 return sb_block;
158}
159
161 LLDB_INSTRUMENT_VA(this);
162
163 SBBlock sb_block;
164 if (m_opaque_ptr)
165 sb_block.m_opaque_ptr = m_opaque_ptr->GetSibling();
166 return sb_block;
167}
168
170 LLDB_INSTRUMENT_VA(this);
171
172 SBBlock sb_block;
173 if (m_opaque_ptr)
174 sb_block.m_opaque_ptr = m_opaque_ptr->GetFirstChild();
175 return sb_block;
176}
177
179
181
183 LLDB_INSTRUMENT_VA(this, description);
184
185 Stream &strm = description.ref();
186
187 if (m_opaque_ptr) {
188 lldb::user_id_t id = m_opaque_ptr->GetID();
189 strm.Printf("Block: {id: %" PRIu64 "} ", id);
190 if (IsInlined()) {
191 strm.Printf(" (inlined, '%s') ", GetInlinedName());
192 }
194 m_opaque_ptr->CalculateSymbolContext(&sc);
195 if (sc.function) {
196 m_opaque_ptr->DumpAddressRanges(
197 &strm, sc.function->GetAddress().GetFileAddress());
198 }
199 } else
200 strm.PutCString("No value");
201
202 return true;
203}
204
206 LLDB_INSTRUMENT_VA(this);
207
208 if (m_opaque_ptr)
209 return m_opaque_ptr->GetNumRanges();
210 return 0;
211}
212
214 LLDB_INSTRUMENT_VA(this, idx);
215
216 lldb::SBAddress sb_addr;
217 if (m_opaque_ptr) {
218 AddressRange range;
219 if (m_opaque_ptr->GetRangeAtIndex(idx, range)) {
220 sb_addr.ref() = range.GetBaseAddress();
221 }
222 }
223 return sb_addr;
224}
225
227 LLDB_INSTRUMENT_VA(this, idx);
228
229 lldb::SBAddress sb_addr;
230 if (m_opaque_ptr) {
231 AddressRange range;
232 if (m_opaque_ptr->GetRangeAtIndex(idx, range)) {
233 sb_addr.ref() = range.GetBaseAddress();
234 sb_addr.ref().Slide(range.GetByteSize());
235 }
236 }
237 return sb_addr;
238}
239
241 LLDB_INSTRUMENT_VA(this);
242
243 lldb::SBAddressRangeList sb_ranges;
244 if (m_opaque_ptr)
245 sb_ranges.m_opaque_up->ref() = m_opaque_ptr->GetRanges();
246 return sb_ranges;
247}
248
250 LLDB_INSTRUMENT_VA(this, block_addr);
251
252 if (m_opaque_ptr && block_addr.IsValid()) {
253 return m_opaque_ptr->GetRangeIndexContainingAddress(block_addr.ref());
254 }
255
256 return UINT32_MAX;
257}
258
260 bool locals, bool statics,
261 lldb::DynamicValueType use_dynamic) {
262 LLDB_INSTRUMENT_VA(this, frame, arguments, locals, statics, use_dynamic);
263
264 Block *block = GetPtr();
265 SBValueList value_list;
266 if (block) {
267 StackFrameSP frame_sp(frame.GetFrameSP());
268 VariableListSP variable_list_sp(block->GetBlockVariableList(true));
269
270 if (variable_list_sp) {
271 const size_t num_variables = variable_list_sp->GetSize();
272 if (num_variables) {
273 for (size_t i = 0; i < num_variables; ++i) {
274 VariableSP variable_sp(variable_list_sp->GetVariableAtIndex(i));
275 if (variable_sp) {
276 bool add_variable = false;
277 switch (variable_sp->GetScope()) {
281 add_variable = statics;
282 break;
283
285 add_variable = arguments;
286 break;
287
289 add_variable = locals;
290 break;
291
292 default:
293 break;
294 }
295 if (add_variable) {
296 if (frame_sp) {
297 lldb::ValueObjectSP valobj_sp(
298 frame_sp->GetValueObjectForFrameVariable(variable_sp,
300 SBValue value_sb;
301 value_sb.SetSP(valobj_sp, use_dynamic);
302 value_list.Append(value_sb);
303 }
304 }
305 }
306 }
307 }
308 }
309 }
310 return value_list;
311}
312
314 bool locals, bool statics) {
315 LLDB_INSTRUMENT_VA(this, target, arguments, locals, statics);
316
317 Block *block = GetPtr();
318
319 SBValueList value_list;
320 if (block) {
321 TargetSP target_sp(target.GetSP());
322
323 VariableListSP variable_list_sp(block->GetBlockVariableList(true));
324
325 if (variable_list_sp) {
326 const size_t num_variables = variable_list_sp->GetSize();
327 if (num_variables) {
328 for (size_t i = 0; i < num_variables; ++i) {
329 VariableSP variable_sp(variable_list_sp->GetVariableAtIndex(i));
330 if (variable_sp) {
331 bool add_variable = false;
332 switch (variable_sp->GetScope()) {
336 add_variable = statics;
337 break;
338
340 add_variable = arguments;
341 break;
342
344 add_variable = locals;
345 break;
346
347 default:
348 break;
349 }
350 if (add_variable) {
351 if (target_sp)
352 value_list.Append(
353 ValueObjectVariable::Create(target_sp.get(), variable_sp));
354 }
355 }
356 }
357 }
358 }
359 }
360 return value_list;
361}
#define LLDB_INSTRUMENT_VA(...)
std::unique_ptr< lldb_private::AddressRangeListImpl > m_opaque_up
lldb_private::Address & ref()
bool IsValid() const
Definition SBAddress.cpp:74
void AppendVariables(bool can_create, bool get_parent_variables, lldb_private::VariableList *var_list)
Definition SBBlock.cpp:132
lldb::SBAddress GetRangeEndAddress(uint32_t idx)
Definition SBBlock.cpp:226
lldb::SBAddressRangeList GetRanges()
Definition SBBlock.cpp:240
uint32_t GetNumRanges()
Definition SBBlock.cpp:205
const char * GetInlinedName() const
Definition SBBlock.cpp:81
uint32_t GetInlinedCallSiteLine() const
Definition SBBlock.cpp:108
lldb::SBAddress GetRangeStartAddress(uint32_t idx)
Definition SBBlock.cpp:213
bool IsValid() const
Definition SBBlock.cpp:47
const lldb::SBBlock & operator=(const lldb::SBBlock &rhs)
Definition SBBlock.cpp:38
lldb::SBBlock GetContainingInlinedBlock()
Get the inlined block that contains this block.
Definition SBBlock.cpp:151
uint32_t GetRangeIndexForBlockAddress(lldb::SBAddress block_addr)
Definition SBBlock.cpp:249
lldb::SBValueList GetVariables(lldb::SBFrame &frame, bool arguments, bool locals, bool statics, lldb::DynamicValueType use_dynamic)
Definition SBBlock.cpp:259
void SetPtr(lldb_private::Block *lldb_object_ptr)
Definition SBBlock.cpp:180
lldb::SBBlock GetParent()
Definition SBBlock.cpp:142
lldb::SBBlock GetFirstChild()
Definition SBBlock.cpp:169
bool IsInlined() const
Definition SBBlock.cpp:73
uint32_t GetInlinedCallSiteColumn() const
Definition SBBlock.cpp:120
bool operator==(const lldb::SBBlock &rhs) const
Definition SBBlock.cpp:57
lldb::SBBlock GetSibling()
Definition SBBlock.cpp:160
lldb::SBFileSpec GetInlinedCallSiteFile() const
Definition SBBlock.cpp:95
lldb_private::Block * m_opaque_ptr
Definition SBBlock.h:99
lldb_private::Block * GetPtr()
Definition SBBlock.cpp:178
bool operator!=(const lldb::SBBlock &rhs) const
Definition SBBlock.cpp:67
bool GetDescription(lldb::SBStream &description)
Definition SBBlock.cpp:182
void SetFileSpec(const lldb_private::FileSpec &fspec)
lldb::StackFrameSP GetFrameSP() const
Definition SBFrame.cpp:88
lldb_private::Stream & ref()
Definition SBStream.cpp:179
lldb::TargetSP GetSP() const
Definition SBTarget.cpp:600
void Append(const lldb::SBValue &val_obj)
void SetSP(const lldb::ValueObjectSP &sp)
Definition SBValue.cpp:1093
A section + offset based address range class.
Address & GetBaseAddress()
Get accessor for the base address of the range.
lldb::addr_t GetByteSize() const
Get accessor for the byte size of this range.
bool Slide(int64_t offset)
Definition Address.h:446
lldb::addr_t GetFileAddress() const
Get the file address.
Definition Address.cpp:283
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
Function & GetFunction()
Definition Block.cpp:156
uint32_t GetLine() const
Get accessor for the declaration line number.
uint16_t GetColumn() const
Get accessor for the declaration column number.
FileSpec & GetFile()
Get accessor for file specification.
const Address & GetAddress() const
Return the address of the function (its entry point).
Definition Function.h:439
CompileUnit * GetCompileUnit()
Get accessor for the compile unit that owns this function.
Definition Function.cpp:415
A class that describes information for an inlined function.
Definition Function.h:120
Declaration & GetCallSite()
Get accessor for the call site declaration information.
Definition Function.cpp:105
ConstString GetName() const
Definition Function.cpp:93
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:63
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.
Defines a symbol context baton that can be handed other debug core functions.
Function * function
The Function for a given query.
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, const lldb::VariableSP &var_sp)
#define UINT32_MAX
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::VariableList > VariableListSP
std::shared_ptr< lldb_private::Variable > VariableSP
@ eValueTypeVariableGlobal
globals variable
@ eValueTypeVariableLocal
function local variables
@ eValueTypeVariableArgument
function argument variables
@ eValueTypeVariableStatic
static variable
@ eValueTypeVariableThreadLocal
thread local storage variable
uint64_t user_id_t
Definition lldb-types.h:83
std::shared_ptr< lldb_private::Target > TargetSP