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"
17#include "lldb/Symbol/Block.h"
22#include "lldb/Target/Target.h"
24
25using namespace lldb;
26using namespace lldb_private;
27
29
31 : m_opaque_ptr(lldb_object_ptr) {}
32
33SBBlock::SBBlock(const SBBlock &rhs) : m_opaque_ptr(rhs.m_opaque_ptr) {
34 LLDB_INSTRUMENT_VA(this, rhs);
35}
36
38 LLDB_INSTRUMENT_VA(this, rhs);
39
41 return *this;
42}
43
45
46bool SBBlock::IsValid() const {
48 return this->operator bool();
49}
50SBBlock::operator bool() const {
52
53 return m_opaque_ptr != nullptr;
54}
55
56bool SBBlock::IsInlined() const {
58
59 if (m_opaque_ptr)
60 return m_opaque_ptr->GetInlinedFunctionInfo() != nullptr;
61 return false;
62}
63
64const char *SBBlock::GetInlinedName() const {
66
67 if (m_opaque_ptr) {
68 const InlineFunctionInfo *inlined_info =
70 if (inlined_info) {
71 return inlined_info->GetName().AsCString(nullptr);
72 }
73 }
74 return nullptr;
75}
76
79
80 SBFileSpec sb_file;
81 if (m_opaque_ptr) {
82 const InlineFunctionInfo *inlined_info =
84 if (inlined_info)
85 sb_file.SetFileSpec(inlined_info->GetCallSite().GetFile());
86 }
87 return sb_file;
88}
89
92
93 if (m_opaque_ptr) {
94 const InlineFunctionInfo *inlined_info =
96 if (inlined_info)
97 return inlined_info->GetCallSite().GetLine();
98 }
99 return 0;
100}
101
103 LLDB_INSTRUMENT_VA(this);
104
105 if (m_opaque_ptr) {
106 const InlineFunctionInfo *inlined_info =
108 if (inlined_info)
109 return inlined_info->GetCallSite().GetColumn();
110 }
111 return 0;
112}
113
114void SBBlock::AppendVariables(bool can_create, bool get_parent_variables,
115 lldb_private::VariableList *var_list) {
116 if (IsValid()) {
117 bool show_inline = true;
118 m_opaque_ptr->AppendVariables(can_create, get_parent_variables, show_inline,
119 [](Variable *) { return true; }, var_list);
120 }
121}
122
124 LLDB_INSTRUMENT_VA(this);
125
126 SBBlock sb_block;
127 if (m_opaque_ptr)
128 sb_block.m_opaque_ptr = m_opaque_ptr->GetParent();
129 return sb_block;
130}
131
133 LLDB_INSTRUMENT_VA(this);
134
135 SBBlock sb_block;
136 if (m_opaque_ptr)
138 return sb_block;
139}
140
142 LLDB_INSTRUMENT_VA(this);
143
144 SBBlock sb_block;
145 if (m_opaque_ptr)
147 return sb_block;
148}
149
151 LLDB_INSTRUMENT_VA(this);
152
153 SBBlock sb_block;
154 if (m_opaque_ptr)
156 return sb_block;
157}
158
160
162
164 LLDB_INSTRUMENT_VA(this, description);
165
166 Stream &strm = description.ref();
167
168 if (m_opaque_ptr) {
170 strm.Printf("Block: {id: %" PRIu64 "} ", id);
171 if (IsInlined()) {
172 strm.Printf(" (inlined, '%s') ", GetInlinedName());
173 }
176 if (sc.function) {
178 &strm,
180 }
181 } else
182 strm.PutCString("No value");
183
184 return true;
185}
186
188 LLDB_INSTRUMENT_VA(this);
189
190 if (m_opaque_ptr)
191 return m_opaque_ptr->GetNumRanges();
192 return 0;
193}
194
196 LLDB_INSTRUMENT_VA(this, idx);
197
198 lldb::SBAddress sb_addr;
199 if (m_opaque_ptr) {
200 AddressRange range;
201 if (m_opaque_ptr->GetRangeAtIndex(idx, range)) {
202 sb_addr.ref() = range.GetBaseAddress();
203 }
204 }
205 return sb_addr;
206}
207
209 LLDB_INSTRUMENT_VA(this, idx);
210
211 lldb::SBAddress sb_addr;
212 if (m_opaque_ptr) {
213 AddressRange range;
214 if (m_opaque_ptr->GetRangeAtIndex(idx, range)) {
215 sb_addr.ref() = range.GetBaseAddress();
216 sb_addr.ref().Slide(range.GetByteSize());
217 }
218 }
219 return sb_addr;
220}
221
223 LLDB_INSTRUMENT_VA(this, block_addr);
224
225 if (m_opaque_ptr && block_addr.IsValid()) {
226 return m_opaque_ptr->GetRangeIndexContainingAddress(block_addr.ref());
227 }
228
229 return UINT32_MAX;
230}
231
233 bool locals, bool statics,
234 lldb::DynamicValueType use_dynamic) {
235 LLDB_INSTRUMENT_VA(this, frame, arguments, locals, statics, use_dynamic);
236
237 Block *block = GetPtr();
238 SBValueList value_list;
239 if (block) {
240 StackFrameSP frame_sp(frame.GetFrameSP());
241 VariableListSP variable_list_sp(block->GetBlockVariableList(true));
242
243 if (variable_list_sp) {
244 const size_t num_variables = variable_list_sp->GetSize();
245 if (num_variables) {
246 for (size_t i = 0; i < num_variables; ++i) {
247 VariableSP variable_sp(variable_list_sp->GetVariableAtIndex(i));
248 if (variable_sp) {
249 bool add_variable = false;
250 switch (variable_sp->GetScope()) {
254 add_variable = statics;
255 break;
256
258 add_variable = arguments;
259 break;
260
262 add_variable = locals;
263 break;
264
265 default:
266 break;
267 }
268 if (add_variable) {
269 if (frame_sp) {
270 lldb::ValueObjectSP valobj_sp(
271 frame_sp->GetValueObjectForFrameVariable(variable_sp,
273 SBValue value_sb;
274 value_sb.SetSP(valobj_sp, use_dynamic);
275 value_list.Append(value_sb);
276 }
277 }
278 }
279 }
280 }
281 }
282 }
283 return value_list;
284}
285
287 bool locals, bool statics) {
288 LLDB_INSTRUMENT_VA(this, target, arguments, locals, statics);
289
290 Block *block = GetPtr();
291
292 SBValueList value_list;
293 if (block) {
294 TargetSP target_sp(target.GetSP());
295
296 VariableListSP variable_list_sp(block->GetBlockVariableList(true));
297
298 if (variable_list_sp) {
299 const size_t num_variables = variable_list_sp->GetSize();
300 if (num_variables) {
301 for (size_t i = 0; i < num_variables; ++i) {
302 VariableSP variable_sp(variable_list_sp->GetVariableAtIndex(i));
303 if (variable_sp) {
304 bool add_variable = false;
305 switch (variable_sp->GetScope()) {
309 add_variable = statics;
310 break;
311
313 add_variable = arguments;
314 break;
315
317 add_variable = locals;
318 break;
319
320 default:
321 break;
322 }
323 if (add_variable) {
324 if (target_sp)
325 value_list.Append(
326 ValueObjectVariable::Create(target_sp.get(), variable_sp));
327 }
328 }
329 }
330 }
331 }
332 }
333 return value_list;
334}
#define LLDB_INSTRUMENT_VA(...)
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:114
lldb::SBAddress GetRangeEndAddress(uint32_t idx)
Definition: SBBlock.cpp:208
uint32_t GetNumRanges()
Definition: SBBlock.cpp:187
const char * GetInlinedName() const
Definition: SBBlock.cpp:64
uint32_t GetInlinedCallSiteLine() const
Definition: SBBlock.cpp:90
lldb::SBAddress GetRangeStartAddress(uint32_t idx)
Definition: SBBlock.cpp:195
bool IsValid() const
Definition: SBBlock.cpp:46
const lldb::SBBlock & operator=(const lldb::SBBlock &rhs)
Definition: SBBlock.cpp:37
lldb::SBBlock GetContainingInlinedBlock()
Get the inlined block that contains this block.
Definition: SBBlock.cpp:132
uint32_t GetRangeIndexForBlockAddress(lldb::SBAddress block_addr)
Definition: SBBlock.cpp:222
lldb::SBValueList GetVariables(lldb::SBFrame &frame, bool arguments, bool locals, bool statics, lldb::DynamicValueType use_dynamic)
Definition: SBBlock.cpp:232
void SetPtr(lldb_private::Block *lldb_object_ptr)
Definition: SBBlock.cpp:161
lldb::SBBlock GetParent()
Definition: SBBlock.cpp:123
lldb::SBBlock GetFirstChild()
Definition: SBBlock.cpp:150
bool IsInlined() const
Definition: SBBlock.cpp:56
uint32_t GetInlinedCallSiteColumn() const
Definition: SBBlock.cpp:102
lldb::SBBlock GetSibling()
Definition: SBBlock.cpp:141
lldb::SBFileSpec GetInlinedCallSiteFile() const
Definition: SBBlock.cpp:77
lldb_private::Block * m_opaque_ptr
Definition: SBBlock.h:90
lldb_private::Block * GetPtr()
Definition: SBBlock.cpp:159
bool GetDescription(lldb::SBStream &description)
Definition: SBBlock.cpp:163
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:577
void Append(const lldb::SBValue &val_obj)
void SetSP(const lldb::ValueObjectSP &sp)
Definition: SBValue.cpp:1061
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: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:449
lldb::addr_t GetFileAddress() const
Get the file address.
Definition: Address.cpp:291
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:399
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
Block * GetSibling() const
Get the sibling block for this block.
Definition: Block.cpp:505
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:443
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:195
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:457
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:107
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:33
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: SBAttachInfo.h:14
Definition: SBAddress.h:15
uint64_t user_id_t
Definition: lldb-types.h:80
@ 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