From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id EHo2Fxg3zWRqTzcAWB0awg (envelope-from ) for ; Fri, 04 Aug 2023 13:36:24 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=oC5OiUjq; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 54EF21E0BB; Fri, 4 Aug 2023 13:36:24 -0400 (EDT) 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 4393A1E028 for ; Fri, 4 Aug 2023 13:36:22 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B9DE63857722 for ; Fri, 4 Aug 2023 17:36:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B9DE63857722 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1691170581; bh=0lo6lyecZBhh4OEt6yiwn9h9BPtMN5+US4wrciPhYEo=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=oC5OiUjqOcJzaPuz+3JbVYxBPqo3usZ9dO/MZb0XbMhlWVtMCQ6k2MPHNl6Rkxfc3 aO3NbynqB7qo19yPX3fTNcje5OE2E82FpwmlXEanYbuFvK3tQqHshy5pSLjUhI1t00 HFnUTWHJSsppeg6NXmNMCFe6OmkTTjkQEdc2npKs= Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 5C6963858C5F for ; Fri, 4 Aug 2023 17:36:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5C6963858C5F 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-out1.suse.de (Postfix) with ESMTPS id 95AF521872; Fri, 4 Aug 2023 17:36:00 +0000 (UTC) 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 7C6C8133B5; Fri, 4 Aug 2023 17:36:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ljMrHQA3zWRwCwAAMHmgww (envelope-from ); Fri, 04 Aug 2023 17:36:00 +0000 To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] [gdb/symtab] Don't deduplicate variables in gdb-index Date: Fri, 4 Aug 2023 19:35:42 +0200 Message-Id: <20230804173542.3357-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_STOCKGEN, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Tom de Vries via Gdb-patches Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" When running test-case gdb.python/py-symbol.exp with target board cc-with-gdb-index, we run into: ... (gdb) python print (len (gdb.lookup_static_symbols ('rr')))^M 1^M (gdb) FAIL: gdb.python/py-symbol.exp: print (len (gdb.lookup_static_symbols ('rr'))) ... [ Note that the test-case contains rr in both py-symtab.c: ... static int __attribute__ ((used)) rr = 42; /* line of rr */ ... and py-symtab-2.c: ... static int __attribute__ ((used)) rr = 99; /* line of other rr */ ... ] This passes with gdb-12-branch, and fails with gdb-13-branch. AFAIU the current code in symtab_index_entry::minimize makes the assumption that it's fine to store only one copy of rr in the gdb-index, because "print rr" will only ever print one, and always the same. But that fails to recognize that gdb supports gdb.lookup_static_symbols, which returns a list of variables rather than the first one. In other words, the current approach break feature parity between cooked index and gdb-index. Note btw that also debug-names has both instances: ... [ 5] #00597969 rr: <4> DW_TAG_variable DW_IDX_compile_unit=3 DW_IDX_GNU_internal=1 <4> DW_TAG_variable DW_IDX_compile_unit=4 DW_IDX_GNU_internal=1 ... Fix this in symtab_index_entry::minimize, by not deduplicating variables. Tested on x86_64-linux, with target boards unix and cc-with-gdb-index. PR symtab/30720 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30720 --- gdb/dwarf2/index-write.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index 66c5378d677..c3bc537521e 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -294,7 +294,7 @@ symtab_index_entry::minimize () auto from = std::unique (cu_indices.begin (), cu_indices.end ()); cu_indices.erase (from, cu_indices.end ()); - /* We don't want to enter a variable or type more than once, so + /* We don't want to enter a variable more than once, so remove any such duplicates from the list as well. When doing this, we want to keep the entry from the first CU -- but this is implicit due to the sort. This choice is done because it's @@ -304,8 +304,7 @@ symtab_index_entry::minimize () [&] (offset_type val) { gdb_index_symbol_kind kind = GDB_INDEX_SYMBOL_KIND_VALUE (val); - if (kind != GDB_INDEX_SYMBOL_KIND_TYPE - && kind != GDB_INDEX_SYMBOL_KIND_VARIABLE) + if (kind != GDB_INDEX_SYMBOL_KIND_TYPE) return false; val &= ~GDB_INDEX_CU_MASK; base-commit: 0133072f87b7ac0791413870876a0769ca7d44e0 -- 2.35.3