binutils-gdb/gdb/doc
Ijaz, Abdul B 6972c12631 gdb: add shadowed field in '-stack-list-locals/variables' mi commands
For C/C++/Fortran languages GDB prints same name variable multiple times in
case of variable shadowing and it is confusing for user to identify which
variable belongs to the current scope.  So GDB now prints location information
for shadowed variables and add 'shadowed' field also in '-stack-list-locals'
and '-stack-list-variables' mi commands for super-block shadowed variable.

Suppose we have test.c file

1:int x = 3;
2:  {
3:    int x = 4;
4:    int y = 5;
5:    x = 99; /* break here */
6:  }

The "-stack-list-locals" and "-stack-list-variables" mi commands at the
"break here" line gives the following output:

Before the change:

~~~
(gdb)
-stack-list-locals 0
^done,locals=[name="x",name="y",name="x"]
(gdb)
-stack-list-locals 1
^done,locals=[{name="x",value="4"},{name="y",value="5"},{name="x",value="3"}]
(gdb)
-stack-list-locals 2
^done,locals=[{name="x",type="int",value="4"},{name="y",type="int",value="5"},{name="x",type="int",value="3"}]
(gdb)
-stack-list-variables 0
^done,variables=[{name="x"},{name="y"},{name="x"}]
(gdb)
-stack-list-variables 1
^done,variables=[{name="x",value="4"},{name="y",value="5"},{name="x",value="3"}]
(gdb)
-stack-list-variables 2
^done,variables=[{name="x",type="int",value="4"},{name="y",type="int",value="5"},{name="x",type="int",value="3"}]
~~~

With this patch we obtain:

~~~
(gdb)
-stack-list-locals 0
^done,locals=[name="x",name="y",name="x"]
(gdb)
-stack-list-locals 1
^done,locals=[{name="x",value="4",filename="../test.c",fullname="/home/src/test.c",line="3"},{name="y",value="5"},{name="x",value="3",filename="../test.c",fullname="/home/src/test.c",line="1",shadowed="true"}]
(gdb)
-stack-list-locals 2
^done,locals=[{name="x",type="int",value="4",filename="../test.c",fullname="/home/src/test.c",line="3"},{name="y",type="int",value="5"},{name="x",type="int",value="3",filename="../test.c",fullname="/home/src/test.c",line="1",shadowed="true"}]
(gdb)
-stack-list-variables 0
^done,variables=[{name="x",filename="../test.c",fullname="/home/src/test.c",line="3"},{name="y"},{name="x",filename="../test.c",fullname="/home/src/test.c",line="1",shadowed="true"}]
(gdb)
-stack-list-variables 1
^done,variables=[{name="x",value="4",filename="../test.c",fullname="/home/src/test.c",line="3"},{name="y",value="5"},{name="x",value="3",filename="../test.c",fullname="/home/src/test.c",line="1",shadowed="true"}]
(gdb)
-stack-list-variables 2
^done,variables=[{name="x",type="int",value="4",filename="../test.c",fullname="/home/src/test.c",line="3"},{name="y",type="int",value="5"},{name="x",type="int",value="3",filename="../test.c",fullname="/home/src/test.c",line="1",shadowed="true"}]
~~~

Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
2026-07-17 19:36:18 +02:00
..
.gitignore
a4rc.sed
agentexpr.texi Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
all-cfg.texi Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
annotate.texinfo [gdb] Fix trailing whitespace in annotate.texinfo 2026-06-18 22:06:50 +02:00
fdl.texi
gdb.texinfo gdb: add shadowed field in '-stack-list-locals/variables' mi commands 2026-07-17 19:36:18 +02:00
gpl.texi
guile.texi Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
lpsrc.sed
Makefile.in [gdb/doc] Remove doxygen support 2026-06-01 20:14:37 +02:00
makeinfo-wrapper.sh [gdb/build] Require makeinfo 5.0 2026-02-17 15:31:32 +01:00
psrc.sed
python.texi gdb/linux: handle missing NT_FILE note when opening core files 2026-05-01 19:56:56 +01:00
refcard.tex [gdb] Fix trailing whitespace in refcard.tex 2026-06-18 22:06:50 +02:00
stack_frame.eps
stack_frame.pdf
stack_frame.png
stack_frame.svg
stack_frame.txt [gdb] Fix trailing whitespace in some files 2026-06-18 22:06:50 +02:00