From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id rA8nIvpbN2d/9DIAWB0awg (envelope-from ) for ; Fri, 15 Nov 2024 09:34:34 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=DN3IRWQa; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=szl3EqcQ; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=DN3IRWQa; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=szl3EqcQ; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 751DF1E1A8; Fri, 15 Nov 2024 09:34:34 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.0 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (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 ABE811E197 for ; Fri, 15 Nov 2024 09:34:32 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 423EF385840B for ; Fri, 15 Nov 2024 14:34:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 423EF385840B Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=DN3IRWQa; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=szl3EqcQ; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=DN3IRWQa; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=szl3EqcQ Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id 673853858D3C for ; Fri, 15 Nov 2024 14:33:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 673853858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 673853858D3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1731681233; cv=none; b=rYaBXsuxsrHxpmZervEXQ4nGomYBAXtrCxgCiPBBjRNX8LEJxtJO/SD9DJr/8HjQLNKMnIitzsgBAkKtOHbRf4BB8wkz7xA8oZwafT/Xxv8Cl986TciyrF6oOy1eztnZZI4JmzRes/nucz2ZWoqIfhKFLmj/fYvMJjqnrZK1ur0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1731681233; c=relaxed/simple; bh=vXxk4Ca5uoeBHyQeO4u5qem2B1p17frXrLxgesk/poo=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature: Message-ID:Date:MIME-Version:Subject:From:To; b=x7moFTN/DrKswNjZ6T/u1pozdjyUhZOLHXHUJYHB59IFtYsApDz84n0l19cPQ2PefCjEbNmRugUiXJQdrAN7jpKl3a1slm+XoKFhXnV+oRWM3KDYkINBLieGjravOleV36boeT9q45BLyzG2mHwdC87+CG1VGmeVRmjm7jyYnMw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 673853858D3C Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 55BCA21270 for ; Fri, 15 Nov 2024 14:33:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1731681232; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=go5PSk2/GgTsd97nCn7v3lwydG30NdWVr/KqT7l0L6A=; b=DN3IRWQavEI98mXZ4sFunN8HYMiT2HkQ5YGkdinJlZr4Q9bPA24UOl0XmrcUwi49XaTcg0 gvWn3gMctzQtrpJgG5DbgxulZaqyjrmWLZigWGZFTYf0KNu5Sfn588n1qbznCXDlm2iGvW jY5m1vdlo24/iPEc9X2ZJWu9FnuAJj0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1731681232; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=go5PSk2/GgTsd97nCn7v3lwydG30NdWVr/KqT7l0L6A=; b=szl3EqcQlfFQYk/JO9s2XNIcOe0lqky22op9CErAsIVCXs09CtxAkhSrUL4ym0hxMa3W/1 3+YZsQd64EHfVMCQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1731681232; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=go5PSk2/GgTsd97nCn7v3lwydG30NdWVr/KqT7l0L6A=; b=DN3IRWQavEI98mXZ4sFunN8HYMiT2HkQ5YGkdinJlZr4Q9bPA24UOl0XmrcUwi49XaTcg0 gvWn3gMctzQtrpJgG5DbgxulZaqyjrmWLZigWGZFTYf0KNu5Sfn588n1qbznCXDlm2iGvW jY5m1vdlo24/iPEc9X2ZJWu9FnuAJj0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1731681232; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=go5PSk2/GgTsd97nCn7v3lwydG30NdWVr/KqT7l0L6A=; b=szl3EqcQlfFQYk/JO9s2XNIcOe0lqky22op9CErAsIVCXs09CtxAkhSrUL4ym0hxMa3W/1 3+YZsQd64EHfVMCQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 4572113485 for ; Fri, 15 Nov 2024 14:33:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id w6ixD9BbN2coKwAAD6G6ig (envelope-from ) for ; Fri, 15 Nov 2024 14:33:52 +0000 Message-ID: Date: Fri, 15 Nov 2024 15:34:21 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PING][PATCH] [gdb/symtab] Keep track of all parents for cooked index From: Tom de Vries To: gdb-patches@sourceware.org References: <20241024112325.868-1-tdevries@suse.de> Content-Language: en-US In-Reply-To: <20241024112325.868-1-tdevries@suse.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[sourceware.org:url,suse.de:mid] 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 On 10/24/24 13:23, Tom de Vries wrote: > [ This is a resubmission of v2 of "[gdb/symtab] Keep track of all parents for > cooked index" [1], this time with a DWARF assembly test-case. > > The test-case is based on the DWARF info generated for test-case > gdb.cp/breakpoint-locs.exp with target board cc-with-dwz. > > The difference is that the test-case does not contain > DW_TAG_inlined_subroutine, which makes it possible to submit this patch > independently from the patch series. > > A consequence of this difference is that the relevant DIEs in the PU are not > named, and consequently have no entries in the cooked index, which meant that > the original fix didn't work, so the fix has been updated to handle this case > as well. ] > > Consider the new DWARF assembly test-case gdb.dwarf2/dwz-2.exp. > > With readnow, we have: > ... > $ gdb -q -batch -readnow outputs/gdb.dwarf2/dwz-2/dwz-2 \ > -ex "print ns::foo" \ > -ex "print ns::bar" > $1 = {int (void)} 0x4101ac > $2 = {int (void)} 0x4101b4 > ... > but with the cooked index we have either: > ... > $1 = {int (void)} 0x4101ac > No symbol "bar" in namespace "ns". > ... > or: > ... > No symbol "foo" in namespace "ns". > $1 = {int (void)} 0x4101b4 > ... > > The problem is that both the entries for foo and bar don't have the correct > parent: > ... > $ gdb -q -batch outputs/gdb.dwarf2/dwz-2/dwz-2 -ex "maint print objfiles" \ > | egrep "qualified:.*(foo|bar)$" > qualified: foo > qualified: bar > ... > so gdb ends up expanding the first CU that contains namespace ns, which is the > CU that won the import race for the PU, which is why we're getting either > ns::foo or ns::bar. > > So why are the foo and bar entries not getting the correct parent? > > The DWARF representation of ns::foo and ns::bar is as follows: we have the foo > DIE (in CU1): > ... > <1><42>: Abbrev Number: 3 (DW_TAG_subprogram) > <43> DW_AT_specification: <0x2a> > <47> DW_AT_name : foo > <4b> DW_AT_low_pc : 0x4101ac > <53> DW_AT_high_pc : 0x4101b4 > <5b> DW_AT_linkage_name: _ZN2ns3fooEv > ... > and the bar DIE (in CU2): > ... > <1><7b>: Abbrev Number: 3 (DW_TAG_subprogram) > <7c> DW_AT_specification: <0x2a> > <80> DW_AT_name : bar > <84> DW_AT_low_pc : 0x4101b4 > <8c> DW_AT_high_pc : 0x4101bc > <94> DW_AT_linkage_name: _ZN2ns3barEv > ... > both referring to this DIE (in the PU): > ... > <1><2a>: Abbrev Number: 5 (DW_TAG_subprogram) > <2b> DW_AT_specification: <0x23> > ... > which refers to this DIE (also in the PU): > ... > <1><1f>: Abbrev Number: 3 (DW_TAG_namespace) > <20> DW_AT_name : ns > <2><23>: Abbrev Number: 4 (DW_TAG_subprogram) > <24> DW_AT_type : <0x18> > <28> DW_AT_external : 1 > ... > > When processing both the foo and bar DIEs, finding the parent is deferred, but > when the deferred parents are resolved there is no entry at 0x2a in the parent > map: > ... > map start: > 0x0000000000000000 0x0 > 0x0000000000000020 0x31f497c0 (0x1f: ns) > 0x000000000000002a 0x0 > ... > > Fix this by adding an entry at 0x2a in the parent map, such that we have > instead: > ... > map start: > 0x0000000000000000 0x0 > 0x0000000000000020 0x321117c0 (0x1f: ns) > 0x000000000000002b 0x0 > 0x0000000000000042 0x321117c0 (0x1f: ns) > 0x0000000000000043 0x0 > 0x000000000000007b 0x321117c0 (0x1f: ns) > 0x000000000000007c 0x0 > ... > and: > ... > $ gdb -q -batch outputs/gdb.dwarf2/dwz-2/dwz-2 -ex "maint print objfiles" \ > | egrep "qualified:.*(foo|bar)$" > qualified: ns::foo > qualified: ns::bar > ... > and: > ... > $ gdb -q -batch outputs/gdb.dwarf2/dwz-2/dwz-2 \ > -ex "print ns::foo" \ > -ex "print ns::bar" > $1 = {int (void)} 0x4101ac > $2 = {int (void)} 0x4101b4 > ... > > Tested on aarch64-linux. > Ping. Thanks, - Tom > PR symtab/32299 > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32299 > > [1] https://sourceware.org/pipermail/gdb-patches/2023-December/205056.html > --- > gdb/dwarf2/read.c | 8 ++ > gdb/testsuite/gdb.dwarf2/dwz-2.c | 37 +++++++++ > gdb/testsuite/gdb.dwarf2/dwz-2.exp | 116 +++++++++++++++++++++++++++++ > 3 files changed, 161 insertions(+) > create mode 100644 gdb/testsuite/gdb.dwarf2/dwz-2.c > create mode 100644 gdb/testsuite/gdb.dwarf2/dwz-2.exp > > diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c > index 6ac6f7c6a39..cacfab7e6d5 100644 > --- a/gdb/dwarf2/read.c > +++ b/gdb/dwarf2/read.c > @@ -16601,6 +16601,14 @@ cooked_indexer::index_dies (cutu_reader *reader, > this_parent_entry, m_per_cu); > } > > + if (this_parent_entry != nullptr) > + { > + parent_map::addr_type addr > + = parent_map::form_addr (this_die, > + reader->cu->per_cu->is_dwz); > + m_die_range_map->add_entry (addr, addr, this_parent_entry); > + } > + > if (linkage_name != nullptr) > { > /* We only want this to be "main" if it has a linkage name > diff --git a/gdb/testsuite/gdb.dwarf2/dwz-2.c b/gdb/testsuite/gdb.dwarf2/dwz-2.c > new file mode 100644 > index 00000000000..7b3236e980a > --- /dev/null > +++ b/gdb/testsuite/gdb.dwarf2/dwz-2.c > @@ -0,0 +1,37 @@ > +/* This testcase is part of GDB, the GNU debugger. > + > + Copyright 2024 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 > +foo (void) > +{ > + asm ("foo_label: .globl foo_label"); > + return 1; > +} > + > +int > +bar (void) > +{ > + asm ("bar_label: .globl bar_label"); > + return 2; > +} > + > +int > +main() > +{ > + asm ("main_label: .globl main_label"); > + return 0; > +} > diff --git a/gdb/testsuite/gdb.dwarf2/dwz-2.exp b/gdb/testsuite/gdb.dwarf2/dwz-2.exp > new file mode 100644 > index 00000000000..17508926340 > --- /dev/null > +++ b/gdb/testsuite/gdb.dwarf2/dwz-2.exp > @@ -0,0 +1,116 @@ > +# Copyright 2024 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 . > + > +# Check that the cooked index gets the correct parents for some entries with > +# the parents in a partial unit. > +# > +# The structure is similar to what's generated for test-case > +# gdb.cp/breakpoint-locs.exp with gcc and target board cc-with-dwz, only in > +# that case we have: > +# DW_TAG_inlined_subroutine -ao-> decl DW_TAG_subprogram -s-> > +# (DW_TAG_namespace::DW_TAG_class_type::decl DW_TAG_subprogram) > +# and here we use: > +# DW_TAG_subprogram -s-> decl DW_TAG_subprogram -s-> > +# (DW_TAG_namespace::decl DW_TAG_subprogram) > + > +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 dwz.S > + > +# Create the DWARF. > +set asm_file [standard_output_file $srcfile2] > +Dwarf::assemble $asm_file { > + get_func_info foo > + get_func_info bar > + get_func_info main > + > + declare_labels partial_label int_label decl1 decl2 > + > + cu {} { > + partial_label: partial_unit {} { > + int_label: base_type { > + {name int} > + {byte_size 4 sdata} > + {encoding @DW_ATE_signed} > + } > + > + DW_TAG_namespace { > + {DW_AT_name ns} > + } { > + decl1: subprogram { > + {type :$int_label} > + {external 1 flag} > + } > + } > + > + decl2: subprogram { > + {DW_AT_specification %$decl1} > + } > + } > + } > + > + cu {} { > + compile_unit {{language @DW_LANG_C_plus_plus}} { > + imported_unit { > + {import $partial_label ref_addr} > + } > + > + subprogram { > + {DW_AT_specification %$decl2} > + {DW_AT_name foo} > + {DW_AT_low_pc $foo_start DW_FORM_addr} > + {DW_AT_high_pc $foo_end DW_FORM_addr} > + {DW_AT_linkage_name _ZN2ns3fooEv} > + } > + } > + } > + > + cu {} { > + compile_unit {{language @DW_LANG_C_plus_plus}} { > + imported_unit { > + {import $partial_label ref_addr} > + } > + > + subprogram { > + {DW_AT_specification %$decl2} > + {DW_AT_name bar} > + {DW_AT_low_pc $bar_start DW_FORM_addr} > + {DW_AT_high_pc $bar_end DW_FORM_addr} > + {DW_AT_linkage_name _ZN2ns3barEv} > + } > + > + subprogram { > + {DW_AT_name main} > + {DW_AT_low_pc $main_start DW_FORM_addr} > + {DW_AT_high_pc $main_end DW_FORM_addr} > + } > + } > + } > +} > + > +if { [prepare_for_testing "failed to prepare" $testfile \ > + [list $asm_file $srcfile] {nodebug}] } { > + return -1 > +} > + > +# Regression test for PR32299. These should both pass, but before the fix > +# only one of them passed. > +gdb_test "p ns::foo" \ > + [string_to_regexp " "] > +gdb_test "p ns::bar" \ > + [string_to_regexp " "] > > base-commit: 86b26b453f65404b29ce035a2eb3d62671aa0612