Fix oversights in frame decorator code
authorTom Tromey <tromey@adacore.com>
Wed, 14 Jun 2023 14:31:21 +0000 (08:31 -0600)
committerTom Tromey <tromey@adacore.com>
Mon, 10 Jul 2023 19:17:30 +0000 (13:17 -0600)
The frame decorator "FrameVars" code misses a couple of cases,
discovered when working on related DAP changes.

First, fetch_frame_locals does not stop when reaching a function
boundary.  This means it would return locals from any enclosing
functions.

Second, fetch_frame_args assumes that all arguments are at the
outermost scope, but this doesn't seem to be required by gdb.

gdb/python/lib/gdb/FrameDecorator.py

index 6773780735b44a48cae30fa1b9c21f56ee6aa733..7293be86185ef843e6cd7e9f6ed8ba3e85eef354 100644 (file)
@@ -269,6 +269,11 @@ class FrameVars(object):
                 if self.fetch_b(sym):
                     lvars.append(SymValueWrapper(sym, None))
 
+            # Stop when the function itself is seen, to avoid showing
+            # variables from outer functions in a nested function.
+            if block.function is not None:
+                break
+
             block = block.superblock
 
         return lvars
@@ -286,14 +291,18 @@ class FrameVars(object):
             block = None
 
         while block is not None:
-            if block.function is not None:
+            if block.is_global or block.is_static:
                 break
-            block = block.superblock
-
-        if block is not None:
             for sym in block:
                 if not sym.is_argument:
                     continue
                 args.append(SymValueWrapper(sym, None))
 
+            # Stop when the function itself is seen, to avoid showing
+            # variables from outer functions in a nested function.
+            if block.function is not None:
+                break
+
+            block = block.superblock
+
         return args