[PATCH v2 1/2] gdb: add annotation in 'info locals' command for variables shadowing case

Pedro Alves pedro@palves.net
Wed Jan 5 15:55:05 GMT 2022


On 2022-01-05 15:20, Andrew Burgess via Gdb-patches wrote:
>   (gdb) info locals
>   var = 123
>   foo = 456
>   var = 999	<shadowed: decl at line 1>
>   foo = 888	<shadowed: decl at line 10>
>   (gdb)
> 
> As you can see the information for var is not helpful.  I suspect we
> might want to print something like:
> 
>   var = 999	<shadowed: other-file.c:1>
>   foo = 888	<shadowed: test.c:10>

I just read this and my first impression from:

  shadowed: test.c:10

... without thinking much was that the ":" after "shadowed" meant "shadowed by".  It's a super
minor thing, but a colon or semicolon instead might drop that ambiguity, without reintroducing
the wordier "decl at":

   foo = 888	<shadowed, test.c:10>

Also, instead of printing extra info just for the shadowed ones, would it be useful to
print the disambiguation info for all variable names that are ambiguous?
In that case, maybe put "shadowed" at the end, as most frequently the variables are
shadowed in the same file, so you get better alignment.  Like:

   var = 123    <file.c:1>
   var = 999	<file.c:10, shadowed>

Just some 2c.  I think the feature is quite useful, whatever the finer details end up as.
Thanks for working on it.


More information about the Gdb-patches mailing list