From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 0E41A385841A for ; Thu, 7 Sep 2023 14:42:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0E41A385841A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id BE4431F8B5 for ; Thu, 7 Sep 2023 14:42:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1694097756; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MG3jadZPdhvMLfyJq7ipjrveIUrhZUU9oruBn5G9lzc=; b=niLPNuvtGbx2WlpUCTg9yu65zecTAZxe60RiH9NY08EfJvqWZFhvQdvqYuwIem793zaqat 2duNuZzAGEcH7qkQTqFfHgsLoQEQxHp30wp9O8aW0zBet3W8ZhWpqKkiVs71ADfrfTTKXj SBS6w3Vs1dPDQFkXlUpH15bg3g+dV1Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1694097756; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MG3jadZPdhvMLfyJq7ipjrveIUrhZUU9oruBn5G9lzc=; b=gvgUi8aL7U8cBvyOI/QvscRx0V3JhwJ8Z+w02a3OHZ+QGE0jsJZDIkkZM58fqkBlGth4c3 ALShdlTkaCjnApDQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id ACA6A13ADD for ; Thu, 7 Sep 2023 14:42:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id CF0XKVzh+WSRZAAAMHmgww (envelope-from ) for ; Thu, 07 Sep 2023 14:42:36 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH] [gdb/symtab] Fix gdb-index writing for .debug_types Date: Thu, 7 Sep 2023 16:42:33 +0200 Message-Id: <20230907144233.14505-2-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230907144233.14505-1-tdevries@suse.de> References: <20230907144233.14505-1-tdevries@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,TXREP 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: With test-case gdb.ada/same_enum.exp and target board dwarf4-gdb-index we run into: ... (gdb) print red^M No definition of "red" in current context.^M (gdb) FAIL: gdb.ada/same_enum.exp: print red ... [ This is a regression since commit 844a72efbce ("Simplify gdb_index writing"), so this is broken in gdb 12 and 13. ] The easiest way to see what's going wrong is with readelf. We have in section .gdb_index: ... [7194] pck__red: 2 [static, variable] 3 [static, variable] ... which points to the CUs 2 and 3 in the CU list (shown using "2" and "3"), but should be pointing to the TUs 2 and 3 in the TU list (shown using "T2" and "T3"). Fix this by removing the counter / types_counter distinction in write_gdbindex, such that we get the expected: ... [7194] pck__red: T2 [static, variable] T3 [static, variable] ... [ While reading write_gdbindex I noticed a few oddities related to dwz handling, I've filed PR30829 about this. ] Tested on x86_64-linux. PR symtab/30827 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30827 --- gdb/dwarf2/index-write.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index e178bb067a9..11f254e263a 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -1201,18 +1201,14 @@ write_gdbindex (dwarf2_per_bfd *per_bfd, cooked_index *table, data_buf types_cu_list; /* The CU list is already sorted, so we don't need to do additional - work here. Also, the debug_types entries do not appear in - all_units, but only in their own hash table. */ + work here. */ int counter = 0; - int types_counter = 0; for (int i = 0; i < per_bfd->all_units.size (); ++i) { dwarf2_per_cu_data *per_cu = per_bfd->all_units[i].get (); - int &this_counter = per_cu->is_debug_types ? types_counter : counter; - - const auto insertpair = cu_index_htab.emplace (per_cu, this_counter); + const auto insertpair = cu_index_htab.emplace (per_cu, counter); gdb_assert (insertpair.second); /* The all_units list contains CUs read from the objfile as well as @@ -1234,7 +1230,7 @@ write_gdbindex (dwarf2_per_bfd *per_bfd, cooked_index *table, else cu_list.append_uint (8, BFD_ENDIAN_LITTLE, per_cu->length ()); - ++this_counter; + ++counter; } write_cooked_index (table, cu_index_htab, &symtab); -- 2.35.3