zequanwu created this revision. zequanwu added a reviewer: labath. zequanwu requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
This allows `image lookup -a ... -v` to print variables only if the given address is covered by the valid ranges of the variables. Since variables created in dwarf plugin always has empty scope range, print the variable if it has empty scope. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D119963 Files: lldb/source/Core/Address.cpp Index: lldb/source/Core/Address.cpp =================================================================== --- lldb/source/Core/Address.cpp +++ lldb/source/Core/Address.cpp @@ -720,10 +720,18 @@ bool get_parent_variables = true; bool stop_if_block_is_inlined_function = false; VariableList variable_list; - sc.block->AppendVariables(can_create, get_parent_variables, - stop_if_block_is_inlined_function, - [](Variable *) { return true; }, - &variable_list); + addr_t file_addr = GetFileAddress(); + sc.block->AppendVariables( + can_create, get_parent_variables, + stop_if_block_is_inlined_function, + [&file_addr](Variable *var) { + // Variables created from Dwarf always have empty scope range. + if (var->GetScopeRange().IsEmpty()) + return true; + return var->GetScopeRange().FindEntryThatContains(file_addr) != + nullptr; + }, + &variable_list); for (const VariableSP &var_sp : variable_list) { if (var_sp && var_sp->LocationIsValidForAddress(*this)) { @@ -739,6 +747,16 @@ var_sp->DumpLocationForAddress(s, *this); s->PutCString(", decl = "); var_sp->GetDeclaration().DumpStopContext(s, false); + s->PutCString(", valid ranges ="); + for (auto range : var_sp->GetScopeRange()) { + s->PutCString(" ["); + s->AsRawOstream() << llvm::format_hex(range.GetRangeBase(), + 2 + 2 * addr_size); + s->PutCString("-"); + s->AsRawOstream() + << llvm::format_hex(range.GetRangeEnd(), 2 + 2 * addr_size); + s->PutCString(")"); + } s->EOL(); } }
Index: lldb/source/Core/Address.cpp =================================================================== --- lldb/source/Core/Address.cpp +++ lldb/source/Core/Address.cpp @@ -720,10 +720,18 @@ bool get_parent_variables = true; bool stop_if_block_is_inlined_function = false; VariableList variable_list; - sc.block->AppendVariables(can_create, get_parent_variables, - stop_if_block_is_inlined_function, - [](Variable *) { return true; }, - &variable_list); + addr_t file_addr = GetFileAddress(); + sc.block->AppendVariables( + can_create, get_parent_variables, + stop_if_block_is_inlined_function, + [&file_addr](Variable *var) { + // Variables created from Dwarf always have empty scope range. + if (var->GetScopeRange().IsEmpty()) + return true; + return var->GetScopeRange().FindEntryThatContains(file_addr) != + nullptr; + }, + &variable_list); for (const VariableSP &var_sp : variable_list) { if (var_sp && var_sp->LocationIsValidForAddress(*this)) { @@ -739,6 +747,16 @@ var_sp->DumpLocationForAddress(s, *this); s->PutCString(", decl = "); var_sp->GetDeclaration().DumpStopContext(s, false); + s->PutCString(", valid ranges ="); + for (auto range : var_sp->GetScopeRange()) { + s->PutCString(" ["); + s->AsRawOstream() << llvm::format_hex(range.GetRangeBase(), + 2 + 2 * addr_size); + s->PutCString("-"); + s->AsRawOstream() + << llvm::format_hex(range.GetRangeEnd(), 2 + 2 * addr_size); + s->PutCString(")"); + } s->EOL(); } }
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits