Lines Matching +full:block +full:- +full:offset

1 //===-- Block.cpp ---------------------------------------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Symbol/Block.h"
24 Block::Block(lldb::user_id_t uid)
29 Block::~Block() = default;
31 void Block::GetDescription(Stream *s, Function *function,
41 function->GetAddressRange().GetBaseAddress().GetLoadAddress(target);
43 base_addr = function->GetAddressRange().GetBaseAddress().GetFileAddress();
45 s->Printf(", range%s = ", num_ranges > 1 ? "s" : "");
48 DumpAddressRange(s->AsRawOstream(), base_addr + range.GetRangeBase(),
55 m_inlineInfoSP->Dump(s, show_fullpaths);
59 void Block::Dump(Stream *s, addr_t base_addr, int32_t depth,
62 Block *parent = GetParent();
65 parent->Dump(s, base_addr, depth + 1, show_context);
69 s->Printf("%p: ", static_cast<const void *>(this));
70 s->Indent();
71 *s << "Block" << static_cast<const UserID &>(*this);
72 const Block *parent_block = GetParent();
74 s->Printf(", parent = {0x%8.8" PRIx64 "}", parent_block->GetID());
78 m_inlineInfoSP->Dump(s, show_fullpaths);
87 if (parent_block != nullptr && !parent_block->Contains(range))
91 DumpAddressRange(s->AsRawOstream(), base_addr + range.GetRangeBase(),
95 s->EOL();
98 s->IndentMore();
101 m_variable_list_sp->Dump(s, show_context);
106 (*pos)->Dump(s, base_addr, depth - 1, show_context);
108 s->IndentLess();
112 Block *Block::FindBlockByID(user_id_t block_id) {
116 Block *matching_block = nullptr;
119 matching_block = (*pos)->FindBlockByID(block_id);
126 Block *Block::FindInnermostBlockByOffset(const lldb::addr_t offset) {
127 if (!Contains(offset))
130 if (Block *block = block_sp->FindInnermostBlockByOffset(offset))
131 return block;
136 void Block::CalculateSymbolContext(SymbolContext *sc) {
138 m_parent_scope->CalculateSymbolContext(sc);
139 sc->block = this;
142 lldb::ModuleSP Block::CalculateSymbolContextModule() {
144 return m_parent_scope->CalculateSymbolContextModule();
148 CompileUnit *Block::CalculateSymbolContextCompileUnit() {
150 return m_parent_scope->CalculateSymbolContextCompileUnit();
154 Function *Block::CalculateSymbolContextFunction() {
156 return m_parent_scope->CalculateSymbolContextFunction();
160 Block *Block::CalculateSymbolContextBlock() { return this; }
162 void Block::DumpSymbolContext(Stream *s) {
165 function->DumpSymbolContext(s);
166 s->Printf(", Block{0x%8.8" PRIx64 "}", GetID());
169 void Block::DumpAddressRanges(Stream *s, lldb::addr_t base_addr) {
174 DumpAddressRange(s->AsRawOstream(), base_addr + range.GetRangeBase(),
180 bool Block::Contains(addr_t range_offset) const {
184 bool Block::Contains(const Block *block) const {
185 if (this == block)
186 return false; // This block doesn't contain itself...
188 // Walk the parent chain for "block" and see if any if them match this block
189 const Block *block_parent;
190 for (block_parent = block->GetParent(); block_parent != nullptr;
191 block_parent = block_parent->GetParent()) {
193 return true; // One of the parents of "block" is this object!
198 bool Block::Contains(const Range &range) const {
202 Block *Block::GetParent() const {
204 return m_parent_scope->CalculateSymbolContextBlock();
208 Block *Block::GetContainingInlinedBlock() {
214 Block *Block::GetInlinedParent() {
215 Block *parent_block = GetParent();
217 if (parent_block->GetInlinedFunctionInfo())
220 return parent_block->GetInlinedParent();
225 Block *Block::GetContainingInlinedBlockWithCallSite(
227 Block *inlined_block = GetContainingInlinedBlock();
230 const auto *function_info = inlined_block->GetInlinedFunctionInfo();
233 function_info->GetCallSite().FileAndLineEqual(find_call_site))
235 inlined_block = inlined_block->GetInlinedParent();
240 bool Block::GetRangeContainingOffset(const addr_t offset, Range &range) {
241 const Range *range_ptr = m_ranges.FindEntryThatContains(offset);
250 bool Block::GetRangeContainingAddress(const Address &addr,
254 const AddressRange &func_range = function->GetAddressRange();
260 addr_t offset = addr_offset - func_offset;
262 const Range *range_ptr = m_ranges.FindEntryThatContains(offset);
267 range_ptr->GetRangeBase());
268 range.SetByteSize(range_ptr->GetByteSize());
278 bool Block::GetRangeContainingLoadAddress(lldb::addr_t load_addr,
286 uint32_t Block::GetRangeIndexContainingAddress(const Address &addr) {
289 const AddressRange &func_range = function->GetAddressRange();
295 addr_t offset = addr_offset - func_offset;
296 return m_ranges.FindEntryIndexThatContains(offset);
303 bool Block::GetRangeAtIndex(uint32_t range_idx, AddressRange &range) {
308 range.GetBaseAddress() = function->GetAddressRange().GetBaseAddress();
317 AddressRanges Block::GetRanges() {
326 range.GetBaseAddress() = function->GetAddressRange().GetBaseAddress();
333 bool Block::GetStartAddress(Address &addr) {
339 addr = function->GetAddressRange().GetBaseAddress();
346 void Block::FinalizeRanges() {
351 void Block::AddRange(const Range &range) {
352 Block *parent_block = GetParent();
353 if (parent_block && !parent_block->Contains(range)) {
356 ModuleSP module_sp(m_parent_scope->CalculateSymbolContextModule());
357 Function *function = m_parent_scope->CalculateSymbolContextFunction();
359 function->GetAddressRange().GetBaseAddress().GetFileAddress();
362 Type *func_type = function->GetType();
364 const Declaration &func_decl = func_type->GetDeclaration();
367 "warning: %s:%u block {0x%8.8" PRIx64
368 "} has range[%u] [0x%" PRIx64 " - 0x%" PRIx64
369 ") which is not contained in parent block {0x%8.8" PRIx64
373 block_end_addr, parent_block->GetID(), function->GetID(),
374 module_sp->GetFileSpec().GetPath().c_str());
377 "warning: block {0x%8.8" PRIx64 "} has range[%u] [0x%" PRIx64
378 " - 0x%" PRIx64
379 ") which is not contained in parent block {0x%8.8" PRIx64
382 block_end_addr, parent_block->GetID(), function->GetID(),
383 module_sp->GetFileSpec().GetPath().c_str());
386 parent_block->AddRange(range);
392 size_t Block::MemorySize() const {
393 size_t mem_size = sizeof(Block) + m_ranges.GetSize() * sizeof(Range);
395 mem_size += m_inlineInfoSP->MemorySize();
397 mem_size += m_variable_list_sp->MemorySize();
401 void Block::AddChild(const BlockSP &child_block_sp) {
403 child_block_sp->SetParentScope(this);
408 void Block::SetInlinedFunctionInfo(const char *name, const char *mangled,
415 VariableListSP Block::GetBlockVariableList(bool can_create) {
422 sc.module_sp->GetSymbolFile()->ParseVariablesForContext(sc);
429 Block::AppendBlockVariables(bool can_create, bool get_child_block_variables,
439 variable_list->AddVariable(var_sp);
447 Block *child_block = pos->get();
449 child_block->GetInlinedFunctionInfo() == nullptr) {
450 num_variables_added += child_block->AppendBlockVariables(
459 uint32_t Block::AppendVariables(bool can_create, bool get_parent_variables,
468 for (size_t i = 0; i < variable_list_sp->GetSize(); ++i) {
469 VariableSP variable = variable_list_sp->GetVariableAtIndex(i);
472 variable_list->AddVariable(variable);
481 Block *parent_block = GetParent();
483 num_variables_added += parent_block->AppendVariables(
490 SymbolFile *Block::GetSymbolFile() {
492 return module_sp->GetSymbolFile();
496 CompilerDeclContext Block::GetDeclContext() {
498 return sym_file->GetDeclContextForUID(GetID());
502 void Block::SetBlockInfoHasBeenParsed(bool b, bool set_children) {
508 (*pos)->SetBlockInfoHasBeenParsed(b, true);
512 void Block::SetDidParseVariables(bool b, bool set_children) {
517 (*pos)->SetDidParseVariables(b, true);
521 Block *Block::GetSibling() const {
523 Block *parent_block = GetParent();
525 return parent_block->GetSiblingForChild(this);
529 // A parent of child blocks can be asked to find a sibling block given
531 Block *Block::GetSiblingForChild(const Block *child_block) const {
535 if (pos->get() == child_block) {
537 return pos->get();