From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id WlVYIVJx62moxzgAWB0awg (envelope-from ) for ; Fri, 24 Apr 2026 09:34:10 -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=hT9ovnME; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 78BE91E0BA; Fri, 24 Apr 2026 09:34:10 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.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,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED 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 609FA1E067 for ; Fri, 24 Apr 2026 09:34:09 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id D75F54BB5919 for ; Fri, 24 Apr 2026 13:34:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D75F54BB5919 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=hT9ovnME 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 C8E464BB5910 for ; Fri, 24 Apr 2026 13:33:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C8E464BB5910 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 C8E464BB5910 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777037616; cv=none; b=BDAco+vMyw6/KuqVzjN65jUlgk2WZ0AXxBcLmuTMo+ljDNWkDMyD3ufl1G/a9cx7OAQ2OJjgo+iET+vMuEGkP3UHj4G86uuYmjcARtMbqNrXDdHYfrJn9NpIsdmPUHvowvfRaAhPbQenSsJpoZWgCToTaVS0arm0BS9ys+TVf0o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777037616; c=relaxed/simple; bh=VkF4R3Uq7vnSQId0ZGS9a1Ew9kca/UL2uZ9BW85dRy0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Jm00XIfNQPWF/NO9udjtAlmV8IkDsLwTv7oghnnLSAUlauVGT6xRmJVA8yuYTFTaLh6UFPMB0ba2dN+4fITspvcQYXP9vCzZYnwxhO0W9Oo17MyFiJcHNJhjZ6+bn47oNB+n5dR0UtD4JpT68Dl0N9gf5O7u7EmEBIYrrxBwfgs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C8E464BB5910 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777037616; 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=WtLmdQ6py7y4Qd5Dr+jZAtMixhBGwLkOS7TpyGBzM/0=; b=hT9ovnME7u3J718979+th2jOErWCZEuON1SkklxjHECYnX23Mr4JQ7ky0sob6UJo5QuP6x ykDt5JrjAH7pL+cfKPZKlwGnOAZBAsSiSVZ2bxaEd5Rnam1pHWV/Q444Is/lx2gG661u5A /T3c9mno+PySHX+Ewq8y/3A3CvB4EzU= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-182-bIs-icf-P8OLX0LAMntaFA-1; Fri, 24 Apr 2026 09:33:30 -0400 X-MC-Unique: bIs-icf-P8OLX0LAMntaFA-1 X-Mimecast-MFC-AGG-ID: bIs-icf-P8OLX0LAMntaFA_1777037609 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-488e097a270so56213815e9.1 for ; Fri, 24 Apr 2026 06:33:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777037609; x=1777642409; h=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; bh=WtLmdQ6py7y4Qd5Dr+jZAtMixhBGwLkOS7TpyGBzM/0=; b=FGmSxIUdWXAFUdDJKLb34QZnouAjtGyk0hph+Oq5YKjiaplo+RHM4Ek4YP1mCImO9q xZ4RqNXZBgBfBDTmOqC2jfuV00nibMo3fRlI3QncCKXFCSD5AzPq8IWzHrUbjkDb4KA5 /6gX6wHqkl9xEyeDgAKoCL+Wqy4zRILVlOVVvFCLyy4vMTbQ9Fg6AVAfB++FFiC9Vvpv n4IL+hpoAhKr83393r1mQRDpRxbyEugsQhQ4EIl2y2v9JY8TnWRK0KL9RAH/UQheHRUU IO7q/4M758/T532us0NVJ/XKOVpCTvzf+XU+v3jmu1CSLP5snEEiW3nggPWP6EqM5bMf inCg== X-Forwarded-Encrypted: i=1; AFNElJ8njPinpwFPLNiIt8UFU5vqeAmKIF4ayzQy6SseVN4duJMS5xBoc3eOz3ydaQ+BgqJkAkwczKn2s3BK7A==@sourceware.org X-Gm-Message-State: AOJu0YxQk1DQ4/OjeXAwudZEeT+RN36zpcdEM3E5xZikek4t8fe7f13k xwE+uXEFnfrsH55EzcBMwbF+ZFqgMt77USiM/AXKWMEMw1p9r8cJ/ACLCAzGfLzJnHQHqkO39hq /SbjpaxH4I+MmUeBUOoVLUAhRHWLuK7HPUhmm/hXHKLNXmUjBzREYDqaHgvwY164= X-Gm-Gg: AeBDieskzzok3b10r/G6ZPqQdxXBviceGE4L5XMxA2CBGAUrSM5qUF81uckibiKXGTq k36lZsUcQN/sKvRGAedG4gkO31ErO98Ak7MCKL7lprZijCPD2XUkavzx3AsRHHedEiL6GQr/yqe O1p5C0lSn4GORtWuYGnvLeSnMQHG3+lneSZuHrHusS3Pt50ugpGiqkinCmpI7oI67yOrzez+YHO 0DmxJlsEGXFACsBjqJDhyi41G7vIeQldQrwsOVLUkoJTGnHKtucqhOQyneTH4pcvqKEZXkpXrCZ Q4fTH4QHnDMJthF+LRitilB+5SrwZycgYabDWC8u3X0+kHtG/MVJIK5JoKM+XEKCcQU3M8sl63D EOtgmns+BM+i24Egn2E9iNlP6vYc= X-Received: by 2002:a05:600c:3423:b0:488:fd7e:1063 with SMTP id 5b1f17b1804b1-488fd7e1253mr245653475e9.29.1777037608717; Fri, 24 Apr 2026 06:33:28 -0700 (PDT) X-Received: by 2002:a05:600c:3423:b0:488:fd7e:1063 with SMTP id 5b1f17b1804b1-488fd7e1253mr245653275e9.29.1777037608178; Fri, 24 Apr 2026 06:33:28 -0700 (PDT) Received: from localhost ([31.111.84.232]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4891f98728dsm109467115e9.23.2026.04.24.06.33.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2026 06:33:27 -0700 (PDT) From: Andrew Burgess To: Tom Tromey , gdb-patches@sourceware.org Cc: Tom Tromey Subject: Re: [PATCH] Use fully-qualified name in var_decl_name In-Reply-To: <20260423190109.1274057-1-tromey@adacore.com> References: <20260423190109.1274057-1-tromey@adacore.com> Date: Fri, 24 Apr 2026 14:33:26 +0100 Message-ID: <87wlxw1o0p.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: _U3dY8tfqLcQ4Xki2ob3lG6MAQarBAGFtbRbJwih96o_1777037609 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 Tom Tromey writes: > While testing gdb against a version of gnat-llvm that emits > unqualified names (in a hierarchical structure), I found that > gdb.ada/array_of_symbolic_length.exp would fail. > > The DWARF in question looks like this: > > <1><11a1>: Abbrev Number: 2 (DW_TAG_module) > <11a2> DW_AT_name : (indirect string, offset: 0xe65): pck > <2><11a6>: Abbrev Number: 3 (DW_TAG_variable) > <11a7> DW_AT_name : (indirect string, offset: 0xe69): my_length_LAST > [...] > <3><11df>: Abbrev Number: 5 (DW_TAG_subrange_type) > <11e0> DW_AT_type : <0x12ab> > <11e4> DW_AT_upper_bound : <0x11a6> > > That is, an array's upper bound refers to my_length_LAST. gdb > represents this as a PROP_VARIABLE_NAME -- but only the local name of > the variable was used in this case. > > This patch changes var_decl_name to use the correct full name for the > variable. > --- > gdb/dwarf2/read.c | 5 +---- > 1 file changed, 1 insertion(+), 4 deletions(-) > > diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c > index bc7b8b46d87..9fa8b704182 100644 > --- a/gdb/dwarf2/read.c > +++ b/gdb/dwarf2/read.c > @@ -13397,10 +13397,7 @@ var_decl_name (struct die_info *die, struct dwarf2_cu *cu) > if (attr == nullptr || !attr->as_boolean ()) > return nullptr; > > - attr = dwarf2_attr (die, DW_AT_name, cu); > - if (attr == nullptr) > - return nullptr; > - return attr->as_string (); > + return dwarf2_full_name (nullptr, die, cu); > } I took a crack at writing a DWARF assembler test for this, which I've included below. I think it would be a good idea if a test was included with this patch. Feel free to use what I've written, or change it as needed. Or write your own if this isn't suitable. If the test below is OK, then: Approved-By: Andrew Burgess Thanks, Andrew --- diff --git a/gdb/testsuite/gdb.dwarf2/ada-var-in-module.c b/gdb/testsuite/gdb.dwarf2/ada-var-in-module.c new file mode 100644 index 00000000000..cbc388b0346 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/ada-var-in-module.c @@ -0,0 +1,24 @@ +/* Copyright 2026 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +int the_length = 5; +int wrong_length = 9; +int global_array[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + +int +main (void) +{ + return 0; +} diff --git a/gdb/testsuite/gdb.dwarf2/ada-var-in-module.exp b/gdb/testsuite/gdb.dwarf2/ada-var-in-module.exp new file mode 100644 index 00000000000..b97e81b65c2 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/ada-var-in-module.exp @@ -0,0 +1,151 @@ +# Copyright 2026 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test that an array whose upper bound references a variable +# declaration inside a DW_TAG_module gets the correct fully qualified +# name. This tests that var_decl_name returns the fully qualified +# name. +# +# Without the var_decl_name fix, only the non-qualified name was being +# returned, GDB would then lookup based on this partial name, and +# could find the wrong variable. + +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF-2 and use gas. +require dwarf2_support + +standard_testfile .c -dw.S + +# Make some DWARF for the test. +set asm_file [standard_output_file $srcfile2] +Dwarf::assemble $asm_file { + cu {} { + DW_TAG_compile_unit { + DW_AT_language @DW_LANG_Ada95 + DW_AT_name foo.adb + DW_AT_comp_dir /tmp + } { + declare_labels integer_label array_label \ + length_label + + # Basic integer type. + integer_label: DW_TAG_base_type { + DW_AT_byte_size 4 DW_FORM_sdata + DW_AT_encoding @DW_ATE_signed + DW_AT_name integer + } + + # A module with a variable called 'my_length', this does + # not point at the array length though. This exists to + # confuse Ada's wild card variable lookup. + DW_TAG_module { + DW_AT_name aaa + } { + DW_TAG_variable { + DW_AT_name my_length + DW_AT_type :$integer_label + DW_AT_external 1 flag + DW_AT_location { + DW_OP_addr [gdb_target_symbol wrong_length] + } SPECIAL_expr + } + } + + # The 'bbb' module contains the variable that holds the + # array length (the array itself is defined below). There + # MUST be a separate declaration and definition for the + # variable, the bug we are testing for is when the array + # bound points at the declaration. + DW_TAG_module { + DW_AT_name bbb + } { + length_label: DW_TAG_variable { + DW_AT_name my_length + DW_AT_type :$integer_label + DW_AT_declaration 1 flag + } + + DW_TAG_variable { + DW_AT_name my_length + DW_AT_type :$integer_label + DW_AT_external 1 flag + DW_AT_location { + DW_OP_addr [gdb_target_symbol the_length] + } SPECIAL_expr + } + } + + # Another module with a variable called 'my_length', this + # also does not point at the array length. As with the + # 'aaa' module, this exists to confuse Ada's wild card + # variable lookup. + DW_TAG_module { + DW_AT_name ccc + } { + DW_TAG_variable { + DW_AT_name my_length + DW_AT_type :$integer_label + DW_AT_external 1 flag + DW_AT_location { + DW_OP_addr [gdb_target_symbol wrong_length] + } SPECIAL_expr + } + } + + # Global array type. The upper bound is held in the + # 'bbb.my_length' variable. The upper bound MUST + # reference the variable declaration in order to test the + # bug we are interested in. + array_label: DW_TAG_array_type { + DW_AT_name the_array_type + DW_AT_type :$integer_label + } { + DW_TAG_subrange_type { + DW_AT_type :$integer_label + DW_AT_lower_bound 1 DW_FORM_sdata + DW_AT_upper_bound :$length_label + } + } + + # Global array variable. + DW_TAG_variable { + DW_AT_name the_array + DW_AT_type :$array_label + DW_AT_location { + DW_OP_addr [gdb_target_symbol global_array] + } SPECIAL_expr + DW_AT_external 1 flag + } + } + } +} + +if {[prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] {nodebug}]} { + return +} + +# Print 'the_array'. To establish the upper bound GDB must lookup the +# correct variable by name. With the bug fix in place GDB should look +# for 'bbb.my_length' and find the correct variable. Without the fix +# GDB would look for just 'my_length' which is ambiguous. The hope of +# this test is that by having an 'aaa.my_length' and 'ccc.my_length' +# that, without the fix, GDB will find the wrong length and use that. +gdb_test_no_output "set language ada" +gdb_test "print aaa.my_length" " = 9" +gdb_test "print bbb.my_length" " = 5" +gdb_test "print ccc.my_length" " = 9" +gdb_test "print the_array" " = \\(1, 2, 3, 4, 5\\)"