[Lldb-commits] [PATCH] D119963: [LLDB] Dump valid ranges of variables

Zequan Wu via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Feb 16 11:23:26 PST 2022


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();
             }
           }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119963.409343.patch
Type: text/x-patch
Size: 2043 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220216/99d80f65/attachment.bin>


More information about the lldb-commits mailing list