From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id A4621385EC4E for ; Tue, 29 Jun 2021 14:50:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A4621385EC4E Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 15TEnrKb015192 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Jun 2021 10:49:58 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 15TEnrKb015192 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id C925A1E01F; Tue, 29 Jun 2021 10:49:53 -0400 (EDT) Subject: Re: Shadowed local variables in "info locals" To: "Aktemur, Tankut Baris" , "gdb-patches@sourceware.org" References: From: Simon Marchi Message-ID: <0f8b9c5a-c8d3-9dde-2a43-5f7b81fb5549@polymtl.ca> Date: Tue, 29 Jun 2021 10:49:53 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Tue, 29 Jun 2021 14:49:53 +0000 X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Jun 2021 14:50:05 -0000 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 > > 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