From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id DrlCJCouGmfRBBkAWB0awg (envelope-from ) for ; Thu, 24 Oct 2024 07:23:22 -0400 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=SaG0KQNd; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=ikWTLigb; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=SaG0KQNd; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=ikWTLigb; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 6DF4B1E39B; Thu, 24 Oct 2024 07:23:22 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.8 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL, RCVD_IN_VALIDITY_SAFE,URIBL_BLOCKED,URIBL_DBL_BLOCKED_OPENDNS 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 DE2451E37A for ; Thu, 24 Oct 2024 07:23:20 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 763B03858C42 for ; Thu, 24 Oct 2024 11:23:20 +0000 (GMT) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id ACFFF3858D21 for ; Thu, 24 Oct 2024 11:22:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ACFFF3858D21 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 ACFFF3858D21 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729768977; cv=none; b=gLUjhqyZ+xiIFPBo6WTl9t1BHhqqQbFicuc42M3idU/mc4ryU9MIIHZp9zx/DSm/uirO+fTwnpSxViIrb5OcBPFv/H7FiRljDTg10AITuZhMSSb33RzYwEMfRtVmkI2bCldneUvCD2fdUCVwW+CkMvUp43zWw3DwbfLAfcMs73A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729768977; c=relaxed/simple; bh=CdKAc+nZIqR9Rd8mNxVCtyUNKGeIHH784dtDoWS+ky0=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=wrP2zmDA9+EhLvL3X9j75Zx88DxhbnaAgz0rD731irN31AWQMl5Vim7uW0U/kJEulsy8ToO0BgyurX36kuVGhTvhPDCIv0cOE+3ZFdOuSlzb6Zevc9Nvk5V4gITgyhCf1/vLqg9xEVE5YPzNTAPF/6ZsaP/QtiP10uZO2vjLHzE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 749E121B4D for ; Thu, 24 Oct 2024 11:22:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1729768969; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=X3Dfo7jbnGDwFfb19D2cBFGUFQBcTvaKx527613LjqY=; b=SaG0KQNdtlNn5uLB7Xo8cVek9oKPdOYEzUlg0q69yooAJmfJz0qv/D36wg/4lOsGdvHkEp fC++fre8ItYvZBpHcn8Z+jI3tn38WzxIN2SFOBg21FyzPNXuAc9nltyk52XbZyiXHUF51y 0DVwSNp2iZQvbUQIPEH7mgz08S07yCw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1729768969; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=X3Dfo7jbnGDwFfb19D2cBFGUFQBcTvaKx527613LjqY=; b=ikWTLigbWL2VdCAa1ijXfKdZtTwKrhcuI97ULnpHDARUohfC+BumP78y1WaspOGAzZlqzu foc5UxZFxLLl0XDQ== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=SaG0KQNd; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=ikWTLigb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1729768969; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=X3Dfo7jbnGDwFfb19D2cBFGUFQBcTvaKx527613LjqY=; b=SaG0KQNdtlNn5uLB7Xo8cVek9oKPdOYEzUlg0q69yooAJmfJz0qv/D36wg/4lOsGdvHkEp fC++fre8ItYvZBpHcn8Z+jI3tn38WzxIN2SFOBg21FyzPNXuAc9nltyk52XbZyiXHUF51y 0DVwSNp2iZQvbUQIPEH7mgz08S07yCw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1729768969; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=X3Dfo7jbnGDwFfb19D2cBFGUFQBcTvaKx527613LjqY=; b=ikWTLigbWL2VdCAa1ijXfKdZtTwKrhcuI97ULnpHDARUohfC+BumP78y1WaspOGAzZlqzu foc5UxZFxLLl0XDQ== 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 50CCD1368E for ; Thu, 24 Oct 2024 11:22:49 +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 7bf5EQkuGmcFcAAAD6G6ig (envelope-from ) for ; Thu, 24 Oct 2024 11:22:49 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH] [gdb/symtab] Keep track of all parents for cooked index Date: Thu, 24 Oct 2024 13:23:25 +0200 Message-Id: <20241024112325.868-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 749E121B4D X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_TLS_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:mid]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_DN_NONE(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action 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 [ 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. 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 -- 2.35.3