From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id CWF1NN8oWmrYpw4AWB0awg (envelope-from ) for ; Fri, 17 Jul 2026 09:06:39 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=fuY6JL5s; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id B4C1B1E033; Fri, 17 Jul 2026 09:06:39 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 980FC1E033 for ; Fri, 17 Jul 2026 09:06:38 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 235634BA23D6 for ; Fri, 17 Jul 2026 13:06:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 235634BA23D6 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=fuY6JL5s Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id EE2F24BA23E4 for ; Fri, 17 Jul 2026 12:56:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EE2F24BA23E4 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EE2F24BA23E4 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784293005; cv=none; b=cLMs24PVuCvEK5vuSnkbp2ivk0nJ9BS4HmphKGNh4Cjb8zlmNACMS47GzXZGdrGCNoFUPPubDBWoTT4Ea50JHI3L3iQOWmPJ9zTIfUgMSHmY5KhpTFxtNYqHgDNGwev2OBgDdON5SYk8zxJf/sR7D8fOLb5N7J2UPM4PsN9Acn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784293005; c=relaxed/simple; bh=EfP5FS5mHuf6ouBU7YUamse7WB4gwEIT9bmD7PQSvEw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=hlKY4hV2TDOyQSzeqnuUx3UhOYn7V15et6dfWIFrGxMHGrttqCTA2wr0VyTXfDb++tItL9tElgh8oM5VY2UCZwdhLlxnJYC/53kk/L8NZ49FKZb8aKhiw1mfsJTTDqOb5d8xAEopma/9su45GAiJTRaRTbHK7sBkrG21JIGWqTw= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=fuY6JL5s DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EE2F24BA23E4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784293004; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=eC9OdmOkpb56Xx9AlEDlsdxIS+MB440GhEG94lfEO2s=; b=fuY6JL5snmY3djYzkomeO6dEEf91ymvK3crlx2rSWW39Z58JRtI46GjmhOWJpAqCFOi5y4 Ar+U1Qwv3iCMd3W+ed4arTi8QlJxErWqAGS4PdqwV2IZsFWPvSWTvkyE2fZQIqAxf+yZE2 EPrNgIS2fjFRUGVGAArSLq/Ss+yRzFA= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-62-eCkRTvnJPAeUhs31u42ZPQ-1; Fri, 17 Jul 2026 08:56:43 -0400 X-MC-Unique: eCkRTvnJPAeUhs31u42ZPQ-1 X-Mimecast-MFC-AGG-ID: eCkRTvnJPAeUhs31u42ZPQ_1784293002 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-4729d2a64efso937396f8f.0 for ; Fri, 17 Jul 2026 05:56:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784293002; x=1784897802; h=content-type:mime-version:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=eC9OdmOkpb56Xx9AlEDlsdxIS+MB440GhEG94lfEO2s=; b=b8gs9cyErNAGh0CQh84DP+NNlRC09ir5xyrc1YWjyiXtUydehExVF46yqVqGPL/Kg7 ghBCroGJLmJxZcHDu2PattGXJeoi3x0bNYWp5YoXAcP//rmLWuzMPaGTWOrX+icr/Jfj Hdd2onIRjwlJBFvzJ3Um9P6tAlL+QXePhUflcxpx2W0XAe7ZvBbeTtxjzlLKKFIok+3Z HXeaU7TnziOJK22DLuifEYjuZUHPAc5a4K/BgUZ9+yrXL4GGLWjl+i4ks8geiNHMJlWY Oz8WRqySeqvU1CYUplh0X+eMtwJQ3zTL7BDnrAKToyijzyJcrgHM4w4N5CDrzU84v0/k rthQ== X-Forwarded-Encrypted: i=1; AHgh+RrBz2o+gno2s4emeLM6g4YJX22y2qLeEc+sMb589LTeq/KkaTRQgXggCwbVnT22cN8a3kLzv5h/GV863Q==@sourceware.org X-Gm-Message-State: AOJu0Yyc9U6+lpZF86wuqS/hih+1uofALsrrg99n/BSvNia4NxjdGBlB +91b4VFGV2H/RI0/gAg/7G6ujxw6PGTE6wzy8ssGomdtJI9lIAO3kpgL31gKjcRW2XABUpxxkD9 vcnVCjgGJbMUiZ0f+hAUjFH0SixJm5kPIRDDDlIw4Bxc/8FDhxxEKCXhDQz4GPjU= X-Gm-Gg: AfdE7cm8Z7eDij2BUEKJSxEUn9oSo1nOwj9rq7nMJF5tV48goR/cWYfPXbTgdUtDBO7 dnvSSYcxNl0uP5iL4DV9+HmmxBRHnKTdxgWRcelJ3j6TB1XNantJxFZdM3HqAWzW989KM1C0qNn UTsDrZk6qvDliuBfEcPFs5WUxLgSYYVIUTNtD54EC1S72xoeKEUvandNzEwyTefA+MuSqYlQZLq xBO6d3TYprj8Vf/58vd6Z0KdZgSEczGH3Sjvk86zckYmCSOjJubgG0LHvnyBkfc82jy+IvSi062 4u5Vh0+i4Noj+uD5mojTcU7nV5jsKMmjn5PiNF1I80G660BjOLO5O8177UMI8dzDeKDyViDi X-Received: by 2002:a05:6000:250e:b0:47f:4834:99cd with SMTP id ffacd0b85a97d-47f5a66292bmr9595579f8f.26.1784293002023; Fri, 17 Jul 2026 05:56:42 -0700 (PDT) X-Received: by 2002:a05:6000:250e:b0:47f:4834:99cd with SMTP id ffacd0b85a97d-47f5a66292bmr9595530f8f.26.1784293001442; Fri, 17 Jul 2026 05:56:41 -0700 (PDT) Received: from localhost ([31.111.209.233]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47f63edda29sm3912602f8f.32.2026.07.17.05.56.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2026 05:56:40 -0700 (PDT) From: Andrew Burgess To: Abdul Basit Ijaz , gdb-patches@sourceware.org Cc: pedro@palves.net, philippe.waroquiers@skynet.be, christina.schimpe@intel.com, lsix@lancelotsix.com, eliz@gnu.org, abdul.b.ijaz@intel.com, guinevere@redhat.com Subject: Re: [PATCH v14 1/2] gdb: add annotation in 'info locals' command for variables shadowing case In-Reply-To: <20260714124036.79545-2-abdul.b.ijaz@intel.com> References: <20260714124036.79545-1-abdul.b.ijaz@intel.com> <20260714124036.79545-2-abdul.b.ijaz@intel.com> Date: Fri, 17 Jul 2026 13:56:39 +0100 Message-ID: <87o6g5dbaw.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: sBBoMao9TQnuN4tSovBNLNQsQ-BWUmtuZX7nin8QrZE_1784293002 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Hi, I have a last couple of super minor nits, see inline below. If you're happy to fix these as I suggest then I don't think you need to post another version of the patch: Approved-By: Andrew Burgess But please wait for approval on patch #2 before merging both together. Thanks, Andrew Abdul Basit Ijaz writes: > From: "Ijaz, Abdul B" > > For C/C++/Fortran/Ada languages GDB prints same name variable multiple > times in case of variable shadowing and it is confusing for user to identify > which variable belongs to the current scope. So for such cases add location > info to the innermost listed variables and for super block variables add > "shadowed" annotation in the form of "". > > Suppose we have > > 1:int x = 3; > 2: { > 3: int x = 4; > 4: int y = 52; > 5: x = 99; /* break here */ > 6: } > > Currently: > > (gdb) info locals > x = 4 > y = 52 > x = 3 > > After applying this patch, we obtain: > > (gdb) info locals > x = 4 > y = 52 > x = 3 > > The patch adds the location annotations by keeping track of inner block > and already printed variables to identify shadowing. So, GDB now prints > "" for shadowed super-block variables and > "" for innermost declarations of such variables only. > > The location annotations are printed for shadowed variables in case of > C/C++/Fortran/Ada languages. In Rust, it is possible to declare a > variable with the same name many times. So in this case, just the first > instance of the variable is printed. RUST language test "var_reuse.exp" > fails with rustc compiler version >= 1.73 so XFAIL is added accordingly. > > Fix regex expression in the gdb.opt/inline-locals.exp test according to > this change. The test update is only required due to the existing gdb > known ticket gdb/25695 where this issue is seen with 7.5.0 version on > sles15sp6 but it is not seen anymore on the newer gcc versions e.g. > gcc-11.4.0. > > The symtab()/filename() nullptr check was added specifically to avoid > the crash seen in gdb.dwarf2/missing-type-name-for-templates.exp where > template symbols may have no associated source file. > > Reviewed-By: Guinevere Larsen > Reviewed-By: Eli Zaretskii > Co-Authored-By: Andrew Burgess > --- > gdb/NEWS | 5 + > gdb/c-typeprint.c | 3 +- > gdb/doc/gdb.texinfo | 26 ++++ > gdb/language.c | 20 +++ > gdb/language.h | 18 +++ > gdb/printcmd.c | 44 ++++++- > gdb/stack.c | 115 ++++++++++++++++-- > gdb/stack.h | 22 ++++ > gdb/testsuite/gdb.ada/var_shadowing.exp | 39 ++++++ > .../gdb.ada/var_shadowing/var_shadowing.adb | 30 +++++ > gdb/testsuite/gdb.base/var-shadowing.c | 51 ++++++++ > gdb/testsuite/gdb.base/var-shadowing.exp | 92 ++++++++++++++ > gdb/testsuite/gdb.base/var-shadowing2.c | 16 +++ > gdb/testsuite/gdb.opt/inline-locals.exp | 21 ++-- > gdb/testsuite/gdb.rust/var_reuse.exp | 36 ++++++ > gdb/testsuite/gdb.rust/var_reuse.rs | 20 +++ > gdb/value.h | 26 +++- > 17 files changed, 561 insertions(+), 23 deletions(-) > create mode 100644 gdb/testsuite/gdb.ada/var_shadowing.exp > create mode 100644 gdb/testsuite/gdb.ada/var_shadowing/var_shadowing.adb > create mode 100755 gdb/testsuite/gdb.base/var-shadowing.c > create mode 100755 gdb/testsuite/gdb.base/var-shadowing.exp > create mode 100644 gdb/testsuite/gdb.base/var-shadowing2.c > create mode 100755 gdb/testsuite/gdb.rust/var_reuse.exp > create mode 100755 gdb/testsuite/gdb.rust/var_reuse.rs > > diff --git a/gdb/NEWS b/gdb/NEWS > index ec9b5a33787..2c8adf05b43 100644 > --- a/gdb/NEWS > +++ b/gdb/NEWS > @@ -201,6 +201,11 @@ New command class for help > commands that we, as developers, believe would be close to a minimal > set of commands for a new user of GDB. > > +info locals > + GDB now shows the "shadowed" annotation and the location information > + for variables that are shadowed, or which are shadowing. > + > + Double blank line here, there should be only one. > * Removed commands > > target ctf > diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo > index a698b2b8451..ee33bfdba13 100644 > --- a/gdb/doc/gdb.texinfo > +++ b/gdb/doc/gdb.texinfo > @@ -9188,6 +9188,32 @@ The optional flag @samp{-q}, which stands for @samp{quiet}, disables > printing header information and messages explaining why no local variables > have been printed. > > +@smallexample > +@group > +1: int x = 3; > +2: @{ > +3: int x = 4; > +4: int y = 52; > +5: x = 99; // breakpoint-line > +6: @} > +@end group > +@group > +(gdb) info locals > +x = 4 > +y = 52 > +x = 3 > +@end group > +@end smallexample > + > +@anchor{shadowed variables} > +@cindex shadowed variables > +A variable is @dfn{shadowed} when there's another variable with the > +same name which is declared within an inner scope (decision block, > +method, or inner class). For such cases, its location for the > +outermost scope is followed by @samp{shadowed}. The location can > +help to locate the instances of shadowed variables. So, > +location information is only added for shadowed variables. I found the second sentence of this paragraph a little hard to parse. Also the justification for the location seems unnecessary (to me). How about this instead: A variable is @dfn{shadowed} when there's another variable with the same name which is declared within an inner scope (decision block, method, or inner class). When shadowing is detected, location information is added to all instances of the shadowed variable name. The outermost instances are additionally followed by @samp{shadowed} to indicate that they are not the active variable. > + > @item info locals [-q] [-t @var{type_regexp}] [@var{regexp}] > Like @kbd{info locals}, but only print the local variables selected > with the provided regexp(s). > diff --git a/gdb/stack.h b/gdb/stack.h > index ad2700b59a7..a03103b9847 100644 > --- a/gdb/stack.h > +++ b/gdb/stack.h > @@ -20,6 +20,8 @@ > #ifndef GDB_STACK_H > #define GDB_STACK_H > > +enum class var_shadowing; > + > gdb::unique_xmalloc_ptr find_frame_funname (const frame_info_ptr &frame, > enum language *funlang, > struct symbol **funcp); > @@ -27,12 +29,32 @@ gdb::unique_xmalloc_ptr find_frame_funname (const frame_info_ptr &frame, > typedef gdb::function_view > iterate_over_block_arg_local_vars_cb; > > +typedef gdb::function_view + var_shadowing shadow_status)> > + iterate_over_block_arg_local_vars_cb_printing; > + After the recent commit: commit ef5907287aec1dc7f5323c66042a4a26f275c5cf Date: Mon Jul 13 15:06:35 2026 +0200 [gdb] Convert template typedefs to using the previous 'typedef' has been updated to 'using'. Could you update this to match please. > void iterate_over_block_arg_vars (const struct block *block, > iterate_over_block_arg_local_vars_cb cb); > > void iterate_over_block_local_vars (const struct block *block, > iterate_over_block_arg_local_vars_cb cb); >