From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ESdFM0YygmmDRCYAWB0awg (envelope-from ) for ; Tue, 03 Feb 2026 12:37:10 -0500 Received: by simark.ca (Postfix, from userid 112) id CE00F1E08D; Tue, 03 Feb 2026 12:37:10 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,RDNS_NONE autolearn=no autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (unknown [38.145.34.32]) (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 C2F671E08D for ; Tue, 03 Feb 2026 12:37:06 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 5DB064BA2E17 for ; Tue, 3 Feb 2026 17:37:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5DB064BA2E17 Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id CCF774BA2E0B for ; Tue, 3 Feb 2026 17:36:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CCF774BA2E0B Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CCF774BA2E0B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1770140201; cv=none; b=kQgkBzUorZ0bOi5txqlERFsQXPda0oIr7+xosd+GHN2AHwQItS1Vg/QBOoxdHw65lgxQsCC76uMtc0XeH+d/F89s4KT5CYn0Br5fjNpqpzMyxN4qvV8PUq2QDRpZ4LMmAoDK3s5x1mhbhKOmyqwkOPeExpbJd9pQEBLw3Ix/XKo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1770140201; c=relaxed/simple; bh=DYCgjug4MCx5iVZUjTeZV+r7BDwG7lv3zQzWb5qm6lA=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=sTZBEhPdifp0wbhCR8x6diwgi9OWUOybM6aHgA7dfdvm/+Sks4mPVYe9zlIcEJS87+FbUYs6/YUJjjixbSi7jbmp/X7mcSJuBWEabQbdV1Ft4joUFGWKl6BkcbMQ17EfFUdAjnqoBmKVdpRJT/ifz5eDgSPyKOIrpvVxvwTlU4I= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CCF774BA2E0B Received: by simark.ca (Postfix) id 2D0E71E08D; Tue, 03 Feb 2026 12:36:41 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH] gdb/dwarf2: don't search included symtabs recursively Date: Tue, 3 Feb 2026 12:36:27 -0500 Message-ID: <20260203173640.215967-1-simon.marchi@efficios.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260130025546.322629-3-simon.marchi@polymtl.ca> References: <20260130025546.322629-3-simon.marchi@polymtl.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 patch depends on this mini-series that converts compunit_symtab::includes to a vector: https://inbox.sourceware.org/gdb-patches/20260130025546.322629-1-simon.marchi@polymtl.ca/ The compunit_symtab::includes field says that it contains the flattened list of all recursively included symtabs: /* Vector of included compunit symtabs. When searching the static or global block of this compunit, the corresponding block of all included compunits will also be searched. Note that this list must be flattened -- the symbol reader is responsible for ensuring that this vector contains the transitive closure of all included compunits. */ std::vector includes; The DWARF reader appears to do exactly that, see recursively_compute_inclusions. It therefore seems unnecessary to do a recursive search, in recursively_find_pc_sect_compunit_symtab, it will search some symtabs multiple times. I confirmed this by hacking the function to print the searched CUs and to never find anything: diff --git i/gdb/dwarf2/read.c w/gdb/dwarf2/read.c index aeed0fa13a46..098fecb06cd9 100644 --- i/gdb/dwarf2/read.c +++ w/gdb/dwarf2/read.c @@ -2114,8 +2114,7 @@ static struct compunit_symtab * recursively_find_pc_sect_compunit_symtab (struct compunit_symtab *cust, CORE_ADDR pc) { - if (cust->blockvector () != nullptr && cust->blockvector ()->contains (pc)) - return cust; + printf ("\nSearch CU %p\n", cust); for (compunit_symtab *include : cust->includes) if (compunit_symtab *found And then: $ ./gdb -nx --data-directory=data-directory ~/build/babeltrace/src/lib/.libs/libbabeltrace2.so.0.0.0 -ex "p bt_common_assert_failed" -batch | grep 'Search CU' | sort | uniq -c 1 Search CU 0x7c83249e44b0 1 Search CU 0x7c83249e4690 1 Search CU 0x7c83249e4870 1 Search CU 0x7c83249e4960 1 Search CU 0x7c83249e4b40 1 Search CU 0x7c83249e4d20 1 Search CU 0x7c83249e4f00 2 Search CU 0x7c83249e4ff0 2 Search CU 0x7c83249e50e0 4 Search CU 0x7c83249e51d0 2 Search CU 0x7c83249e52c0 2 Search CU 0x7c83249e53b0 4 Search CU 0x7c83249e54a0 Change recursively_find_pc_sect_compunit_symtab to only search the flattened list, and rename it accordingly. With the patch, the same hack (putting the print in the "is_the_one" lambda) and command as above shows that all CUs are searched exactly once: 1 Search CU 0x7cc78ffe44b0 1 Search CU 0x7cc78ffe4690 1 Search CU 0x7cc78ffe4870 1 Search CU 0x7cc78ffe4960 1 Search CU 0x7cc78ffe4b40 1 Search CU 0x7cc78ffe4d20 1 Search CU 0x7cc78ffe4f00 1 Search CU 0x7cc78ffe4ff0 1 Search CU 0x7cc78ffe50e0 1 Search CU 0x7cc78ffe51d0 1 Search CU 0x7cc78ffe52c0 1 Search CU 0x7cc78ffe53b0 1 Search CU 0x7cc78ffe54a0 I am not sure how blockvectors work exactly, whether the blockvector of the includer CU is a superset of the blockvectors of the includees. I ask that because it seems like in practice, the requested PC always seems to be found in the first searched CU. I haven't investigated this point more than that though. Change-Id: I4064f9ddf6131226593ac864f0f804460201502e --- gdb/dwarf2/read.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index aeed0fa13a46..75fd737f6a66 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -2110,18 +2110,21 @@ dw_search_file_matcher /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific symtab. */ -static struct compunit_symtab * -recursively_find_pc_sect_compunit_symtab (struct compunit_symtab *cust, - CORE_ADDR pc) +static compunit_symtab * +find_pc_sect_compunit_symtab_includes (compunit_symtab *cust, CORE_ADDR pc) { - if (cust->blockvector () != nullptr && cust->blockvector ()->contains (pc)) + auto is_the_one = [pc] (compunit_symtab *one_cust) + { + return (one_cust->blockvector () != nullptr + && one_cust->blockvector ()->contains (pc)); + }; + + if (is_the_one (cust)) return cust; for (compunit_symtab *include : cust->includes) - if (compunit_symtab *found - = recursively_find_pc_sect_compunit_symtab (include, pc); - found != nullptr) - return found; + if (is_the_one (include)) + return include; return nullptr; } @@ -2134,8 +2137,6 @@ dwarf2_base_index_functions::find_pc_sect_compunit_symtab struct obj_section *section, int warn_if_readin) { - struct compunit_symtab *result; - dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); dwarf2_per_bfd *per_bfd = per_objfile->per_bfd; @@ -2152,7 +2153,7 @@ dwarf2_base_index_functions::find_pc_sect_compunit_symtab warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"), paddress (objfile->arch (), pc)); - result = recursively_find_pc_sect_compunit_symtab + compunit_symtab *result = find_pc_sect_compunit_symtab_includes (dw2_instantiate_symtab (data, per_objfile, false), pc); if (warn_if_readin && result == nullptr) base-commit: 637751817dd2e9a5dff9fc03b5917ecc4faeaf4a -- 2.53.0