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

Andrew Burgess aburgess@redhat.com
Wed Jan 5 16:26:47 GMT 2022


* Pedro Alves <pedro@palves.net> [2022-01-05 15:55:05 +0000]:

> 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>

Oh, I like this.  This one please.

Then in the MI output we'd have something like:

  ^done,locals=[{name="var",type="int",value="132",file="file.c",line="1"},
                {name="var",type="int",value="999",file="file.c",line="10",shadowed="True"}]

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

Agree this seems like a great addition.

Thanks,
Andrew



More information about the Gdb-patches mailing list