From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id qE21Ey7R7WcdkiQAWB0awg (envelope-from ) for ; Wed, 02 Apr 2025 20:07:10 -0400 Authentication-Results: simark.ca; dkim=fail reason="signature verification failed" (768-bit key; unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=soB4oO1S; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 4C7CB1E0C3; Wed, 2 Apr 2025 20:07:10 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.8 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 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 B3D201E0C0 for ; Wed, 2 Apr 2025 20:07:09 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 61234385AC3A for ; Thu, 3 Apr 2025 00:07:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 61234385AC3A Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=soB4oO1S Received: from omta40.uswest2.a.cloudfilter.net (omta40.uswest2.a.cloudfilter.net [35.89.44.39]) by sourceware.org (Postfix) with ESMTPS id 36BC2385AC3A for ; Wed, 2 Apr 2025 23:45:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 36BC2385AC3A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 36BC2385AC3A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1743637522; cv=none; b=W8vsFiZsSdITrWC/eQbwmWl+wN8a0Riy2LOpplswyd3iNe1I1Gtxy/7pehdgFbJRTE/CB53nguW66xb53pPSclcWljyPEAXSRGr+3S2m32GTESitpfo87mRqENztetRqh6QZF2aCNIEaIgsXVH50G1XTC6/ox75hz/NaVw9l8bI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1743637522; c=relaxed/simple; bh=11xu4keaDk4Pl3Ws7dDtcpi/ZG/ea4lYMTXfxccFoQA=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=KwkZFwHMPs41W7XPRelPdnP3UDz4C7EwAfKQXR9mtVSxKDGRUlj01855741Hyp5TZRG0Uwf6AicIk/dT1wOl75c9OTMiakib/RtQxrabbmv9dz/zSoDkF6xECuhDEQCDokEOVhkHjoMdj6NwBvTlgyYPsrLIfojoI/ezoyWt5zY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 36BC2385AC3A Received: from eig-obgw-5001a.ext.cloudfilter.net ([10.0.29.139]) by cmsmtp with ESMTPS id zwuDtaS8Zf1UX07lpuFImh; Wed, 02 Apr 2025 23:45:21 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id 07louz3gKRxIG07louztDy; Wed, 02 Apr 2025 23:45:21 +0000 X-Authority-Analysis: v=2.4 cv=N/viFH9B c=1 sm=1 tr=0 ts=67edcc11 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=XR8D0OoHHMoA:10 a=ItBw4LHWJt0A:10 a=GgbQac-mxtYejq7yYfIA:9 a=QEXdDO2ut3YA:10 a=6Ogn3jAGHLSNbaov7Orx:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=wix362sVjlYNApLWdJhEPc8eIwhV9xvmDhtCltg7dQM=; b=soB4oO1SHUeWBTALRppfkcr1iN AlojrS5vT9VmLLW/AFSSwHzHqM1Nzj1LHNBwQYSv18VCCTyS7c2ol48I/mS0Qt0OQFz4hpls7BUY5 aqxJwrub9ZPcz096O59Ud6yu1; Received: from 97-122-123-18.hlrn.qwest.net ([97.122.123.18]:56394 helo=prentzel.local) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.1) (envelope-from ) id 1u07lo-000000014hd-0f3l; Wed, 02 Apr 2025 17:45:20 -0600 From: Tom Tromey Date: Wed, 02 Apr 2025 17:45:23 -0600 Subject: [PATCH v2 24/28] Add best_symbol_tracker MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20250402-search-in-psyms-v2-24-ea91704487cb@tromey.com> References: <20250402-search-in-psyms-v2-0-ea91704487cb@tromey.com> In-Reply-To: <20250402-search-in-psyms-v2-0-ea91704487cb@tromey.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.2 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.123.18 X-Source-L: No X-Exim-ID: 1u07lo-000000014hd-0f3l X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-123-18.hlrn.qwest.net (prentzel.local) [97.122.123.18]:56394 X-Source-Auth: tom+tromey.com X-Email-Count: 25 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfLvnAHzQ6ccrXnUFN7eSa0hU/lAA0flZJjG5ujks+RaA/1Hv/JwjjwrTcFFHcoSjWeo7T3SnAnRKkHAN0L302eHNWkPT/Y0GMT0J9LVtGbPa9vHoNx2/ y47pFNA0toA6yiK5CdbtqHOlUk4V6IN3v1PDccrv/oK/FF8kDprwdInrIEFf4E1lyvVANaItVfr0NHxMVbTA1P7lodF/slb4EI0= 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 adds a new best_symbol_tracker struct. This is used to implement the "best symbol" logic that is used sometimes in symtab.c. This approach makes it simpler and more efficient to track the "best" symbol when searching across multiple blocks. --- gdb/block.c | 29 ++++++++++++++++++++++------- gdb/block.h | 27 ++++++++++++++++++++------- gdb/symtab.c | 33 +++++++-------------------------- 3 files changed, 49 insertions(+), 40 deletions(-) diff --git a/gdb/block.c b/gdb/block.c index d8f8bf56de7b1498ae3f89650a3c86c4eafe3bfe..27295168ba564334e5c50c98ad20c66bf2b21aa2 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -669,7 +669,11 @@ block_lookup_symbol (const struct block *block, const lookup_name_info &name, const domain_search_flags domain) { if (!block->function ()) - return block_lookup_symbol_primary (block, name, domain); + { + best_symbol_tracker tracker; + tracker.search (nullptr, block, name, domain); + return tracker.currently_best.symbol; + } else { /* Note that parameter symbols do not always show up last in the @@ -700,12 +704,12 @@ block_lookup_symbol (const struct block *block, const lookup_name_info &name, /* See block.h. */ -struct symbol * -block_lookup_symbol_primary (const struct block *block, +bool +best_symbol_tracker::search (compunit_symtab *symtab, + const struct block *block, const lookup_name_info &name, const domain_search_flags domain) { - symbol *other = nullptr; for (symbol *sym : block_iterator_range (block, &name)) { /* With the fix for PR gcc/debug/91507, we get for: @@ -736,17 +740,28 @@ block_lookup_symbol_primary (const struct block *block, the only option to make this work is improve the fallback to use the size of the minimal symbol. Filed as PR exp/24989. */ if (best_symbol (sym, domain)) - return sym; + { + best_symtab = symtab; + currently_best = { sym, block }; + return true; + } /* This is a bit of a hack, but 'matches' might ignore STRUCT vs VAR domain symbols. So if a matching symbol is found, make sure there is no "better" matching symbol, i.e., one with exactly the same domain. PR 16253. */ if (sym->matches (domain)) - other = better_symbol (other, sym, domain); + { + symbol *better = better_symbol (sym, currently_best.symbol, domain); + if (better != currently_best.symbol) + { + best_symtab = symtab; + currently_best = { better, block }; + } + } } - return other; + return false; } /* See block.h. */ diff --git a/gdb/block.h b/gdb/block.h index c348c7fdcc4088e7f5c912e49c387e2c650eda45..b1daed216c956043b63ee99d8418607b417593ae 100644 --- a/gdb/block.h +++ b/gdb/block.h @@ -630,14 +630,27 @@ extern struct symbol *block_lookup_symbol (const struct block *block, const lookup_name_info &name, const domain_search_flags domain); -/* Search BLOCK for symbol NAME in DOMAIN but only in primary symbol table of - BLOCK. BLOCK must be STATIC_BLOCK or GLOBAL_BLOCK. Function is useful if - one iterates all global/static blocks of an objfile. */ +/* When searching for a symbol, the "best" symbol is preferred over + one that is merely acceptable. See 'best_symbol'. This class + keeps track of this distinction while searching. */ -extern struct symbol *block_lookup_symbol_primary - (const struct block *block, - const lookup_name_info &name, - const domain_search_flags domain); +struct best_symbol_tracker +{ + /* The symtab in which the currently best symbol appears. */ + compunit_symtab *best_symtab = nullptr; + + /* The currently best (really "better") symbol. */ + block_symbol currently_best {}; + + /* Search BLOCK (which must have come from SYMTAB) for a symbol + matching NAME and DOMAIN. When a symbol is found, update + 'currently_best'. If a best symbol is found, return true. + Otherwise, return false. SYMTAB can be nullptr if the caller + does not care about this tracking. */ + bool search (compunit_symtab *symtab, + const block *block, const lookup_name_info &name, + domain_search_flags domain); +}; /* Find symbol NAME in BLOCK and in DOMAIN. This will return a matching symbol whose type is not a "opaque", see TYPE_IS_OPAQUE. diff --git a/gdb/symtab.c b/gdb/symtab.c index 4822b5681f8370394c9cb6ca6c38ac2214191a39..8961e117348b8fe2b2ebf6b73ad1ca0fe9edbe35 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2366,44 +2366,25 @@ lookup_symbol_in_objfile_symtabs (struct objfile *objfile, name, domain_name (domain).c_str ()); lookup_name_info lookup_name (name, symbol_name_match_type::FULL); - struct block_symbol other; - other.symbol = NULL; + best_symbol_tracker accum; for (compunit_symtab *cust : objfile->compunits ()) { const struct blockvector *bv; const struct block *block; - struct block_symbol result; bv = cust->blockvector (); block = bv->block (block_index); - result.symbol = block_lookup_symbol_primary (block, lookup_name, domain); - result.block = block; - if (result.symbol == NULL) - continue; - if (best_symbol (result.symbol, domain)) - { - other = result; - break; - } - if (result.symbol->matches (domain)) - { - struct symbol *better - = better_symbol (other.symbol, result.symbol, domain); - if (better != other.symbol) - { - other.symbol = better; - other.block = block; - } - } + if (accum.search (cust, block, lookup_name, domain)) + break; } - if (other.symbol != NULL) + if (accum.currently_best.symbol != nullptr) { symbol_lookup_debug_printf_v ("lookup_symbol_in_objfile_symtabs (...) = %s (block %s)", - host_address_to_string (other.symbol), - host_address_to_string (other.block)); - return other; + host_address_to_string (accum.currently_best.symbol), + host_address_to_string (accum.currently_best.block)); + return accum.currently_best; } symbol_lookup_debug_printf_v -- 2.46.1