binutils-gdb/gdb/mi
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
..
mi-cmd-break.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
mi-cmd-break.h Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
mi-cmd-catch.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
mi-cmd-disas.c gdb, gdbserver, gdbsupport: replace many uses of strcmp with streq 2026-03-16 13:24:00 -04:00
mi-cmd-env.c Windows: Normalize backslashes to forward slashes 2026-07-06 22:13:07 +01:00
mi-cmd-file.c gdb: make symtab::compunit return a reference 2026-06-19 10:04:11 -04:00
mi-cmd-info.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
mi-cmd-stack.c gdb: add shadowed field in '-stack-list-locals/variables' mi commands 2026-07-17 19:36:18 +02:00
mi-cmd-target.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
mi-cmd-var.c thread_info::executing+resumed -> thread_info::internal_state 2026-04-06 18:50:19 +01:00
mi-cmds.c gdb: use gdb::unordered_string_map throughout 2026-02-13 14:04:14 -05:00
mi-cmds.h [gdb] Convert function typedefs to using 2026-07-13 15:06:35 +02:00
mi-common.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
mi-common.h Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
mi-console.c Rewrite output redirection and logging 2026-02-09 08:15:44 -07:00
mi-console.h Rewrite output redirection and logging 2026-02-09 08:15:44 -07:00
mi-getopt.c Use double quotes in some gdb output 2026-06-05 15:09:09 -06:00
mi-getopt.h Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
mi-interp.c [gdb] Drop nullptr in "get_selected_frame (nullptr)" 2026-06-05 23:06:48 +02:00
mi-interp.h Rewrite output redirection and logging 2026-02-09 08:15:44 -07:00
mi-main.c [gdb] Drop nullptr in "get_selected_frame (nullptr)" 2026-06-05 23:06:48 +02:00
mi-main.h Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
mi-out.c Remove m_applied_style from ui_file 2026-02-09 08:15:29 -07:00
mi-out.h Remove m_applied_style from ui_file 2026-02-09 08:15:29 -07:00
mi-parse.c [gdb] Add missing i18n support to error strings (part 1) 2026-06-09 22:14:06 +02:00
mi-parse.h Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
mi-symbol-cmds.c [gdb] Convert template typedefs to using 2026-07-13 15:06:35 +02:00