From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 91C1C3858C53 for ; Sat, 26 Aug 2023 10:07:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 91C1C3858C53 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 A7C931F8D9 for ; Sat, 26 Aug 2023 10:07:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1693044424; 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=MFnXt1XUuMHubg2YpZjc7tWDFzY5o0UGJhNHeyKVNxU=; b=lXwh9gJXnsCPusx6pEAxWDEUn/Ik9jOTbNbWWqxIfzoiCiTbi7MxYX3TrW7Wc3haHjIexf O/tAuYjPdbQpDfoxfcsDim+6T1QuOIJL++0IEK1UL7fLzssWtLqMltU7irS8UvIsfSwfeJ TZ/DCkBGdiN+5yTnQhSqSXvbYXArM1Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1693044424; 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=MFnXt1XUuMHubg2YpZjc7tWDFzY5o0UGJhNHeyKVNxU=; b=sRck6b7FZwD+W7VUGc/amCtDA6uWn2e4+TtbilzRx1qqWX5y1ezorBzMdmndVtx25srgEl t8NSyL9E+2dECQBg== 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 88B6413585 for ; Sat, 26 Aug 2023 10:07:04 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id LfIUIMjO6WQAUQAAMHmgww (envelope-from ) for ; Sat, 26 Aug 2023 10:07:04 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH] [gdb/symtab] Fix too many symbols in gdbpy_lookup_static_symbols Date: Sat, 26 Aug 2023 12:07:23 +0200 Message-Id: <20230826100723.19454-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.9 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: When running test-case gdb.python/py-symbol.exp with target board cc-with-dwz-m, we run into: ... (gdb) python print (len (gdb.lookup_static_symbols ('rr')))^M 4^M (gdb) FAIL: gdb.python/py-symbol.exp: \ print (len (gdb.lookup_static_symbols ('rr'))) ... while with target board unix we have instead: ... (gdb) python print (len (gdb.lookup_static_symbols ('rr')))^M 2^M (gdb) PASS: gdb.python/py-symbol.exp: \ print (len (gdb.lookup_static_symbols ('rr'))) ... The problem is that the loop in gdbpy_lookup_static_symbols loops over compunits representing both CUs and PUs: ... for (compunit_symtab *cust : objfile->compunits ()) ... When doing a lookup on a PU, the user link is followed until we end up at a CU, and the lookup is done in that CU. In other words, when doing a lookup in the loop for a PU we duplicate the lookup for a CU that is already handled by the loop. Fix this by skipping PUs in the loop in gdb.lookup_static_symbols. Tested on x86_64-linux. PR symtab/25261 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=25261 --- gdb/python/py-symbol.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c index ee863aa4df4..43a20c7a366 100644 --- a/gdb/python/py-symbol.c +++ b/gdb/python/py-symbol.c @@ -602,9 +602,12 @@ gdbpy_lookup_static_symbols (PyObject *self, PyObject *args, PyObject *kw) { for (compunit_symtab *cust : objfile->compunits ()) { - const struct blockvector *bv; + /* Skip included compunits to prevent including compunits from + being searched twice. */ + if (cust->user != nullptr) + continue; - bv = cust->blockvector (); + const struct blockvector *bv = cust->blockvector (); const struct block *block = bv->static_block (); if (block != nullptr) base-commit: d2ac569f7b443aef7b2be2f0c80d8ab0d67b4292 -- 2.35.3