[PATCH 1/2] gdb: add annotation in 'info locals' command for variables shadowing case
Ijaz, Abdul B
abdul.b.ijaz@intel.com
Mon Aug 23 09:03:54 GMT 2021
On Wed, 2021-07-28 at 19:43 +0200, abdul.b.ijaz via Gdb-patches wrote:
> (gdb) info locals
> x = 99
> x = 42
>
> So far this scenario is only known case for C/C++/Fortran language so
> to tackle in this case, when iterating over the stack frame variables
> keep the track of inner block variables and when same variable is
> found in the outer-block then print <shadowed> after its value.
> Iteration of stack frame variables always starts with inner block so
> gdb now print <shadowed> for super-block duplicate variables like this:
>
> (gdb) info locals
> x = 99
> x = 42 <shadowed>
Effectively, it is nice to better handle shadowed variables.
Note however that we can have several levels of inner blocks, and then the <shadowed> indication might not clearly indicate which variable it is.
E.g.:
(gdb) info locals
x = 111
x = 11
x = 1
(gdb)
Maybe "info locals" could rather output the location of the variables, either automatically when there is some shadowing and/or with an optional argument, e.g.
info locals [-q] [-location] [-t TYPEREGEXP] [NAMEREGEXP]
....
The location of a variable is output if -location is provided or when
a variable shadows another variable.
...
>> Thanks Philippe for the feedback. I understand your concern that adding shadowed to several level inner blocks will still not indicate clearly which variable but only for the intermediate blocks although it will still indicate the innermost block variable like below and also test is added for multiple inner levels.
(gdb) info locals
x = 111
x = 11 <shadowed>
x = 1 <shadowed>
So based on your feedback in my opinion adding variable location to output could be good option by default for variable shadowing case instead of optional argument. So please confirm shall I update it accordingly. It was updated like this based on the feedback on following request so adding Tom, Simon and Baris in case they have any further feedback on this:
https://sourceware.org/pipermail/gdb-patches/2021-June/180478.html
Best Regards
Abdul Basit
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
More information about the Gdb-patches
mailing list