diff --git a/lldb/source/Core/Address.cpp b/lldb/source/Core/Address.cpp --- a/lldb/source/Core/Address.cpp +++ b/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(); } }