From: Simon Marchi <simon.marchi@polymtl.ca>
To: "Aktemur, Tankut Baris" <tankut.baris.aktemur@intel.com>,
"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: Shadowed local variables in "info locals"
Date: Tue, 29 Jun 2021 10:49:53 -0400 [thread overview]
Message-ID: <0f8b9c5a-c8d3-9dde-2a43-5f7b81fb5549@polymtl.ca> (raw)
In-Reply-To: <SN6PR11MB289376763CB0070B01F2799CC4029@SN6PR11MB2893.namprd11.prod.outlook.com>
On 2021-06-29 10:21 a.m., Aktemur, Tankut Baris via Gdb-patches wrote:
> Hi,
>
> Suppose we have the following program:
>
> 1 int
> 2 main ()
> 3 {
> 4 int x = 42;
> 5 {
> 6 int x = 99;
> 7 x = 99;
> 8 }
> 9 return 0;
> 10 }
>
> The "info locals" command, when stopped at line 7, gives
>
> (gdb) info locals
> x = 99
> x = 42
>
> Is this a bug or an (un)intentional feature?
>
> From one perspective, only one "x" is available for use in our context, and
> thus only one "x" should be printed by "info locals". This is the "bug" view.
>
> From another perspective, the outer "x" and inner "x" are two different
> variables that are located in separate locations but they just happen to have
> the same name. Therefore, displaying both is giving valuable information.
> This is the "feature" view.
>
> Displaying both names could be confusing for the user in particular if the
> values of the variables come from complex execution flows and if the user cannot
> tell which "x" is which. A potential improvement to the current state is
> annotating the outer scope variable for clarity. E.g.
>
> (gdb) info locals
> x = 99
> x = 42 <shadowed>
>
> What are your thoughts?
I don't have a strong opinion. I maybe lean more towards the side of
showing all the information, but making it clearer which variable is
which (i.e. the example above).
But I just wanted to note that a change for MI's -stack-list-locals
command may also be desirable. It could be a new attribute in the
shadowed variable's record that says it is shadowed, that would not
break backwards compatibility.
Simon
next prev parent reply other threads:[~2021-06-29 14:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-29 14:21 Aktemur, Tankut Baris
2021-06-29 14:49 ` Simon Marchi [this message]
2021-06-30 16:54 ` Tom Tromey
2021-07-01 8:12 ` Aktemur, Tankut Baris
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0f8b9c5a-c8d3-9dde-2a43-5f7b81fb5549@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
--cc=tankut.baris.aktemur@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).