From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 237EA3858D1E for ; Sat, 11 Nov 2023 22:53:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 237EA3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none 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 237EA3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699743192; cv=none; b=FWKeiZGZxMDWF6apZAVn2QlXrLAFVOjTXvvq+ODSCn09VTqb9/d+pMssLokmz8fGbitsg8+INIH8a7shr1oe7kK4kM3My/e4NmiCAFoAw4h/XuEqsKsaqrju1P4Q3QVA0HgxWHuCToEyhduVLil7KjvtFs1TyPvdyvk7mgQ0Vo4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699743192; c=relaxed/simple; bh=1IB1SKOb6GK7jTmOiS58M/vD/usYAZlv8dB81OJr6Nc=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=AftvIzx0e8MPMxi6Uptausy5o0WVdN6GBDB/nQtAZ/K5IfOWXroCwM0dCpENi3zPrkWZF+KejDlgJCEVSErW30O1j1RM4vE1YgHMt/JDEzeF0TSxOXiVyGTU48A2qnowv2tn6hyF//F3RL5kv4+rsXV/0KxGohQ+uuIIJiqKpCE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699743190; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=URmRytSjQ3cHMyLq+FoU3PP6sICy/7FqH4g8omOdJVU=; b=cK7lPsbaaTTHs2niPqVw462gmua3KLHLz8QwJxm6J6nB52Z/C2ycifhXtBLm3Uh6BI2Tjx UzagZVwfi3VR+2r63Zc8EP6jgZE0QXeMB7kjiDSS+sAxiLE5/LvsCvdV185B1yJf7mxmV2 zHoAZz56CQhMLljNPftAcyb8F9PTUbM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-19-TpfUUFsjNkCKlDxCHcp1ZA-1; Sat, 11 Nov 2023 17:53:07 -0500 X-MC-Unique: TpfUUFsjNkCKlDxCHcp1ZA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1D284185A780; Sat, 11 Nov 2023 22:53:07 +0000 (UTC) Received: from f38-zws-nv (unknown [10.22.16.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8B8037ACC; Sat, 11 Nov 2023 22:53:06 +0000 (UTC) Date: Sat, 11 Nov 2023 15:53:04 -0700 From: Kevin Buettner To: "Sargsyan, Eduard" Cc: gdb-patches@sourceware.org, "Aktemur, Tankut Baris" , "Metzger, Markus T" , "Schimpe, Christina" Subject: Re: Filtering shadowed variables in info local Message-ID: <20231111155304.1d4077bf@f38-zws-nv> In-Reply-To: References: Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Fri, 10 Nov 2023 17:54:53 +0000 "Sargsyan, Eduard" wrote: > After https://sourceware.org/pipermail/gdb-patches/2021-June/180478.html > and https://sourceware.org/pipermail/gdb-patches/2022-January/184819.html > GDB prints "" if variable has been marked as shadowed. > But user might not be interested in seeing any shadowed variables. > > For example, this code: > > 1 int num = 1; > 2 int > 3 main () > 4 { > 5 const char *str = "main"; > 6 int num = 3; > 7 { > 8 const char *str = "nested"; > 9 int num = 5; > 10 num = 0; // break here > 11 } > 12 return num; > 13 } > > Brings GDB to (when stopped at line 10): > > (gdb) info locals > str = 0x555555556009 "nested" > num = 5 > str = 0x555555556004 "main" > num = 3 > > Prints both shadowed and local variables "str" and "num", but does not print > global accessible variable "num". > > (gdb) print num > $1 = 5 > (gdb) print ::num > $2 = 1 > > Setting value to local variable "num" works as expected: > (gdb) set num = 7 > (gdb) info locals > str = 0x555555556009 "nested" > num = 7 > str = 0x555555556004 "main" > num = 3 > > In C++ shadowed variable is not accessible, to there is no way to change value > of variable "num" declared at line 5. So only local and global variables can > be modified: > > (gdb) set ::num = 9 > (gdb) print num > $3 = 7 > (gdb) print ::num > $4 = 9 > > I'm not sure if printing shadowed variables "num" and "str" are useful in the > use case described above. Maybe adding a setting to filter out shadowed > variables makes sense (by default the setting will be disabled). > > Example: > > (gdb) info locals > str = 0x555555556009 "nested" > num = 7 > str = 0x555555556004 "main" > num = 3 > (gdb) set print shadowed off > (gdb) info locals > str = 0x555555556009 "nested" > num = 7 > (gdb) set print shadowed on > (gdb) info locals > str = 0x555555556009 "nested" > num = 7 > str = 0x555555556004 "main" > num = 3 > > What are your thoughts? Nice write-up! I think it's useful to know the values of shadowed variables even if they're not settable. I think it might be useful to also know about the shadowed global, which is currently not displayed by "info locals". OTOH, the command suggests that only locals should be displayed, but the fact that a global is shadowed might be the source of a bug; IMO, it wouldn't hurt to tell the user about it. I have no objection to the addition of a "set print shadowed" command to control output of shadowed variables, but I'd prefer that the default be to preserve current behavior. Kevin