LLDB mainline
SBBlock.cpp
Go to the documentation of this file.
1//===-- SBBlock.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
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"
18#include "lldb/Symbol/Block.h"
23#include "lldb/Target/Target.h"
25
26using namespace lldb;
27using namespace lldb_private;
28
30
32 : m_opaque_ptr(lldb_object_ptr) {}
33
34SBBlock::SBBlock(const SBBlock &rhs) : m_opaque_ptr(rhs.m_opaque_ptr) {
35 LLDB_INSTRUMENT_VA(this, rhs);
36}
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::IsInlined() const {
59
60 if (m_opaque_ptr)
61 return m_opaque_ptr->GetInlinedFunctionInfo() != nullptr;
62 return false;
63}
64
65const char *SBBlock::GetInlinedName() const {
67
68 if (m_opaque_ptr) {
69 const InlineFunctionInfo *inlined_info =
71 if (inlined_info) {
72 return inlined_info->GetName().AsCString(nullptr);
73 }
74 }
75 return nullptr;
76}
77
80
81 SBFileSpec sb_file;
82 if (m_opaque_ptr) {
83 const InlineFunctionInfo *inlined_info =
85 if (inlined_info)
86 sb_file.SetFileSpec(inlined_info->GetCallSite().GetFile());
87 }
88 return sb_file;
89}
90
93
94 if (m_opaque_ptr) {
95 const InlineFunctionInfo *inlined_info =
97 if (inlined_info)
98 return inlined_info->GetCallSite().GetLine();
99 }
100 return 0;
101}
102
104 LLDB_INSTRUMENT_VA(this);
105
106 if (m_opaque_ptr) {
107 const InlineFunctionInfo *inlined_info =
109 if (inlined_info)
110 return inlined_info->GetCallSite().GetColumn();
111 }
112 return 0;
113}
114
115void SBBlock::AppendVariables(bool can_create, bool get_parent_variables,
116 lldb_private::VariableList *var_list) {
117 if (IsValid()) {
118 bool show_inline = true;
119 m_opaque_ptr->AppendVariables(can_create, get_parent_variables, show_inline,
120 [](Variable *) { return true; }, var_list);
121 }
122}
123
125 LLDB_INSTRUMENT_VA(this);
126
127 SBBlock sb_block;
128 if (m_opaque_ptr)
129 sb_block.m_opaque_ptr = m_opaque_ptr->GetParent();
130 return sb_block;
131}
132
134 LLDB_INSTRUMENT_VA(this);
135
136 SBBlock sb_block;
137 if (m_opaque_ptr)
139 return sb_block;
140}
141
143 LLDB_INSTRUMENT_VA(this);
144
145 SBBlock sb_block;
146 if (m_opaque_ptr)
148 return sb_block;
149}
150
152 LLDB_INSTRUMENT_VA(this);
153
154 SBBlock sb_block;
155 if (m_opaque_ptr)
157 return sb_block;
158}
159
161
163
165 LLDB_INSTRUMENT_VA(this, description);
166
167 Stream &strm = description.ref();
168
169 if (m_opaque_ptr) {
171 strm.Printf("Block: {id: %" PRIu64 "} ", id);
172 if (IsInlined()) {
173 strm.Printf(" (inlined, '%s') ", GetInlinedName());
174 }
177 if (sc.function) {
179 &strm,
181 }
182 } else
183 strm.PutCString("No value");
184
185 return true;
186}
187
189 LLDB_INSTRUMENT_VA(this);
190
191 if (m_opaque_ptr)
192 return m_opaque_ptr->GetNumRanges();
193 return 0;
194}
195
197 LLDB_INSTRUMENT_VA(this, idx);
198
199 lldb::SBAddress sb_addr;
200 if (m_opaque_ptr) {
201 AddressRange range;
202 if (m_opaque_ptr->GetRangeAtIndex(idx, range)) {
203 sb_addr.ref() = range.GetBaseAddress();
204 }
205 }
206 return sb_addr;
207}
208
210 LLDB_INSTRUMENT_VA(this, idx);
211
212 lldb::SBAddress sb_addr;
213 if (m_opaque_ptr) {
214 AddressRange range;
215 if (m_opaque_ptr->GetRangeAtIndex(idx, range)) {
216 sb_addr.ref() = range.GetBaseAddress();
217 sb_addr.ref().Slide(range.GetByteSize());
218 }
219 }
220 return sb_addr;
221}
222
224 LLDB_INSTRUMENT_VA(this);
225
226 lldb::SBAddressRangeList sb_ranges;
227 if (m_opaque_ptr)
228 sb_ranges.m_opaque_up->ref() = m_opaque_ptr->GetRanges();
229 return sb_ranges;
230}
231
233 LLDB_INSTRUMENT_VA(this, block_addr);
234
235 if (m_opaque_ptr && block_addr.IsValid()) {
236 return m_opaque_ptr->GetRangeIndexContainingAddress(block_addr.ref());
237 }
238
239 return UINT32_MAX;
240}
241
243 bool locals, bool statics,
244 lldb::DynamicValueType use_dynamic) {
245 LLDB_INSTRUMENT_VA(this, frame, arguments, locals, statics, use_dynamic);
246
247 Block *block = GetPtr();
248 SBValueList value_list;
249 if (block) {
250 StackFrameSP frame_sp(frame.GetFrameSP());
251 VariableListSP variable_list_sp(block->GetBlockVariableList(true));
252
253 if (variable_list_sp) {
254 const size_t num_variables = variable_list_sp->GetSize();
255 if (num_variables) {
256 for (size_t i = 0; i < num_variables; ++i) {
257 VariableSP variable_sp(variable_list_sp->GetVariableAtIndex(i));
258 if (variable_sp) {
259 bool add_variable = false;
260 switch (variable_sp->GetScope()) {
264 add_variable = statics;
265 break;
266
268 add_variable = arguments;
269 break;
270
272 add_variable = locals;
273 break;
274
275 default:
276 break;
277 }
278 if (add_variable) {
279 if (frame_sp) {
280 lldb::ValueObjectSP valobj_sp(
281 frame_sp->GetValueObjectForFrameVariable(variable_sp,
283 SBValue value_sb;
284 value_sb.SetSP(valobj_sp, use_dynamic);
285 value_list.Append(value_sb);
286 }
287 }
288 }
289 }
290 }
291 }
292 }
293 return value_list;
294}
295
297 bool locals, bool statics) {
298 LLDB_INSTRUMENT_VA(this, target, arguments, locals, statics);
299
300 Block *block = GetPtr();
301
302 SBValueList value_list;
303 if (block) {
304 TargetSP target_sp(target.GetSP());
305
306 VariableListSP variable_list_sp(block->GetBlockVariableList(true));
307
308 if (variable_list_sp) {
309 const size_t num_variables = variable_list_sp->GetSize();
310 if (num_variables) {
311 for (size_t i = 0; i < num_variables; ++i) {
312 VariableSP variable_sp(variable_list_sp->GetVariableAtIndex(i));
313 if (variable_sp) {
314 bool add_variable = false;
315 switch (variable_sp->GetScope()) {
319 add_variable = statics;
320 break;
321
323 add_variable = arguments;
324 break;
325
327 add_variable = locals;
328 break;
329
330 default:
331 break;
332 }
333 if (add_variable) {
334 if (target_sp)
335 value_list.Append(
336 ValueObjectVariable::Create(target_sp.get(), variable_sp));
337 }
338 }
339 }
340 }
341 }
342 }
343 return value_list;
344}
#define LLDB_INSTRUMENT_VA(...)
std::unique_ptr< lldb_private::AddressRangeListImpl > m_opaque_up
lldb_private::Address & ref()
Definition: SBAddress.cpp:173
bool IsValid() const
Definition: SBAddress.cpp:72
void AppendVariables(bool can_create, bool get_parent_variables, lldb_private::VariableList *var_list)
Definition: SBBlock.cpp:115
lldb::SBAddress GetRangeEndAddress(uint32_t idx)
Definition: SBBlock.cpp:209
lldb::SBAddressRangeList GetRanges()
Definition: SBBlock.cpp:223
uint32_t GetNumRanges()
Definition: SBBlock.cpp:188
const char * GetInlinedName() const
Definition: SBBlock.cpp:65
uint32_t GetInlinedCallSiteLine() const
Definition: SBBlock.cpp:91
lldb::SBAddress GetRangeStartAddress(uint32_t idx)
Definition: SBBlock.cpp:196
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:133
uint32_t GetRangeIndexForBlockAddress(lldb::SBAddress block_addr)
Definition: SBBlock.cpp:232
lldb::SBValueList GetVariables(lldb::SBFrame &frame, bool arguments, bool locals, bool statics, lldb::DynamicValueType use_dynamic)
Definition: SBBlock.cpp:242
void SetPtr(lldb_private::Block *lldb_object_ptr)
Definition: SBBlock.cpp:162
lldb::SBBlock GetParent()
Definition: SBBlock.cpp:124
lldb::SBBlock GetFirstChild()
Definition: SBBlock.cpp:151
bool IsInlined() const
Definition: SBBlock.cpp:57
uint32_t GetInlinedCallSiteColumn() const
Definition: SBBlock.cpp:103
lldb::SBBlock GetSibling()
Definition: SBBlock.cpp:142
lldb::SBFileSpec GetInlinedCallSiteFile() const
Definition: SBBlock.cpp:78
lldb_private::Block * m_opaque_ptr
Definition: SBBlock.h:94
lldb_private::Block * GetPtr()
Definition: SBBlock.cpp:160
bool GetDescription(lldb::SBStream &description)
Definition: SBBlock.cpp:164
void SetFileSpec(const lldb_private::FileSpec &fspec)
Definition: SBFileSpec.cpp:164
lldb::StackFrameSP GetFrameSP() const
Definition: SBFrame.cpp:85
lldb_private::Stream & ref()
Definition: SBStream.cpp:177
lldb::TargetSP GetSP() const
Definition: SBTarget.cpp:585
void Append(const lldb::SBValue &val_obj)
void SetSP(const lldb::ValueObjectSP &sp)
Definition: SBValue.cpp:1097
A section + offset based address range class.
Definition: AddressRange.h:25
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::addr_t GetFileAddress() const
Get the file address.
Definition: Address.cpp:293
A class that describes a single lexical block.
Definition: Block.h:41
Block * GetFirstChild() const
Get the first child block.
Definition: Block.h:202
lldb::VariableListSP GetBlockVariableList(bool can_create)
Get the variable list for this block only.
Definition: Block.cpp:415
void CalculateSymbolContext(SymbolContext *sc) override
Reconstruct the object's symbol context into sc.
Definition: Block.cpp:136
Block * GetContainingInlinedBlock()
Get the inlined block that contains this block.
Definition: Block.cpp:208
bool GetRangeAtIndex(uint32_t range_idx, AddressRange &range)
Definition: Block.cpp:303
const InlineFunctionInfo * GetInlinedFunctionInfo() const
Get const accessor for any inlined function information.
Definition: Block.h:276
AddressRanges GetRanges()
Definition: Block.cpp:317
Block * GetSibling() const
Get the sibling block for this block.
Definition: Block.cpp:521
Block * GetParent() const
Get the parent block.
Definition: Block.cpp:202
uint32_t AppendVariables(bool can_create, bool get_parent_variables, bool stop_if_block_is_inlined_function, const std::function< bool(Variable *)> &filter, VariableList *variable_list)
Appends the variables from this block, and optionally from all parent blocks, to variable_list.
Definition: Block.cpp:459
size_t GetNumRanges() const
Definition: Block.h:343
void DumpAddressRanges(Stream *s, lldb::addr_t base_addr)
Definition: Block.cpp:169
uint32_t GetRangeIndexContainingAddress(const Address &addr)
Definition: Block.cpp:286
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:188
uint32_t GetLine() const
Get accessor for the declaration line number.
Definition: Declaration.h:120
uint16_t GetColumn() const
Get accessor for the declaration column number.
Definition: Declaration.h:127
FileSpec & GetFile()
Get accessor for file specification.
Definition: Declaration.h:107
const AddressRange & GetAddressRange()
Definition: Function.h:447
A class that describes information for an inlined function.
Definition: Function.h:125
Declaration & GetCallSite()
Get accessor for the call site declaration information.
Definition: Function.cpp:108
ConstString GetName() const
Definition: Function.cpp:96
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:65
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:34
Function * function
The Function for a given query.
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, const lldb::VariableSP &var_sp)
#define UINT32_MAX
Definition: lldb-defines.h:19
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
Definition: lldb-forward.h:420
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Definition: lldb-forward.h:480
std::shared_ptr< lldb_private::VariableList > VariableListSP
Definition: lldb-forward.h:483
std::shared_ptr< lldb_private::Variable > VariableSP
Definition: lldb-forward.h:482
uint64_t user_id_t
Definition: lldb-types.h:82
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:444
@ eNoDynamicValues
@ eValueTypeVariableGlobal
globals variable
@ eValueTypeVariableLocal
function local variables
@ eValueTypeVariableArgument
function argument variables
@ eValueTypeVariableStatic
static variable
@ eValueTypeVariableThreadLocal
thread local storage variable
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:47