From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from omta039.useast.a.cloudfilter.net (omta039.useast.a.cloudfilter.net [44.202.169.38]) by sourceware.org (Postfix) with ESMTPS id 25B623858D28 for ; Tue, 29 Aug 2023 20:00:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 25B623858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from eig-obgw-6007a.ext.cloudfilter.net ([10.0.30.247]) by cmsmtp with ESMTP id amcqq7SqOyYOwb4t3qjDnt; Tue, 29 Aug 2023 20:00:29 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id b4t1q5B65uKhRb4t2qXHDc; Tue, 29 Aug 2023 20:00:28 +0000 X-Authority-Analysis: v=2.4 cv=AsT9YcxP c=1 sm=1 tr=0 ts=64ee4e5c a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=UttIx32zK-AA:10 a=Qbun_eYptAEA:10 a=PKA9ihm9Fqa3aWbRbzoA:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=TVig8l+d9oXvBUlhKcfTyJKBbIsj8I2PLtwYBM6Zrjs=; b=n8Ww/VZefOaD4eQ2exMqUPKh8c KGcY/+avODW1MEEJMwUdd6qo5LdvCzKZxeYQ4Dit2lJIbWsG4tNWCM8lXQThVRE7jGxis6JSgswxZ euaRTVx/lp0Bc/K46CTC+GufE; Received: from 75-166-150-212.hlrn.qwest.net ([75.166.150.212]:52644 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1qb4t1-000TUE-1x; Tue, 29 Aug 2023 14:00:27 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Add symbol::matches method Date: Tue, 29 Aug 2023 14:00:18 -0600 Message-ID: <20230829200018.2161784-1-tom@tromey.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: 75.166.150.212 X-Source-L: No X-Exim-ID: 1qb4t1-000TUE-1x X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-150-212.hlrn.qwest.net (localhost.localdomain) [75.166.150.212]:52644 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfMhX1iOQxeLaF7jpqSa7QeGJEjQl95FZgmi2LVLErk/uSHxSQx0rHuuc7AoTfcfnBJcksCTNmLaoL5ZZ31kMNprStAt8k1s29tSPELTLKxriKjLiK/Tl xx3v5+3I+eM1XXCcIdQX4YwodN+VDGaNNX8NdjgvgAmj0HRX1edLv/nSf+qr2FMP+DLMEXbNQlGu1qPX0/10Bhsx7P7lCa8kKcM= X-Spam-Status: No, score=-3025.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,JMQ_SPF_NEUTRAL,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP,T_FILL_THIS_FORM_SHORT 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: This adds symbol::matches, a wrapper for symbol_matches_domain. Most places calling symbol_matches_domain can call this method instead, which is a bit less wordy and also (IMO) clearer. --- gdb/ada-lang.c | 5 ++--- gdb/block.c | 12 +++++------- gdb/linespec.c | 3 +-- gdb/symtab.c | 5 ++--- gdb/symtab.h | 15 +++++++++++---- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 575568cffb5..6c6eaf203c0 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -6050,7 +6050,7 @@ ada_add_block_symbols (std::vector &result, found_sym = false; for (struct symbol *sym : block_iterator_range (block, &lookup_name)) { - if (symbol_matches_domain (sym->language (), sym->domain (), domain)) + if (sym->matches (domain)) { if (sym->aclass () != LOC_UNRESOLVED) { @@ -6085,8 +6085,7 @@ ada_add_block_symbols (std::vector &result, for (struct symbol *sym : block_iterator_range (block)) { - if (symbol_matches_domain (sym->language (), - sym->domain (), domain)) + if (sym->matches (domain)) { int cmp; diff --git a/gdb/block.c b/gdb/block.c index 4e40247b79c..8e1b6ec88d4 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -680,8 +680,7 @@ block_lookup_symbol (const struct block *block, const char *name, 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 (symbol_matches_domain (sym->language (), - sym->domain (), domain)) + if (sym->matches (domain)) other = better_symbol (other, sym, domain); } return other; @@ -701,8 +700,7 @@ block_lookup_symbol (const struct block *block, const char *name, for (struct symbol *sym : block_iterator_range (block, &lookup_name)) { - if (symbol_matches_domain (sym->language (), - sym->domain (), domain)) + if (sym->matches (domain)) { sym_found = sym; if (!sym->is_argument ()) @@ -766,11 +764,11 @@ block_lookup_symbol_primary (const struct block *block, const char *name, if (best_symbol (sym, domain)) return sym; - /* This is a bit of a hack, but symbol_matches_domain might ignore + /* 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 (symbol_matches_domain (sym->language (), sym->domain (), domain)) + if (sym->matches (domain)) other = better_symbol (other, sym, domain); } @@ -794,7 +792,7 @@ block_find_symbol (const struct block *block, const char *name, { /* MATCHER is deliberately called second here so that it never sees a non-domain-matching symbol. */ - if (symbol_matches_domain (sym->language (), sym->domain (), domain) + if (sym->matches (domain) && matcher (sym, data)) return sym; } diff --git a/gdb/linespec.c b/gdb/linespec.c index fd9f54d4afd..fa733d880e3 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -3908,8 +3908,7 @@ find_label_symbols_in_block (const struct block *block, for (struct symbol *sym : block_iterator_range (block)) { - if (symbol_matches_domain (sym->language (), - sym->domain (), LABEL_DOMAIN) + if (sym->matches (LABEL_DOMAIN) && cmp (sym->search_name (), name, name_len) == 0) { result->push_back ({sym, block}); diff --git a/gdb/symtab.c b/gdb/symtab.c index 0117a2a59d7..d055f594c8c 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2278,8 +2278,7 @@ lookup_symbol_in_objfile_symtabs (struct objfile *objfile, other = result; break; } - if (symbol_matches_domain (result.symbol->language (), - result.symbol->domain (), domain)) + if (result.symbol->matches (domain)) { struct symbol *better = better_symbol (other.symbol, result.symbol, domain); @@ -2767,7 +2766,7 @@ iterate_over_symbols (const struct block *block, { for (struct symbol *sym : block_iterator_range (block, &name)) { - if (symbol_matches_domain (sym->language (), sym->domain (), domain)) + if (sym->matches (domain)) { struct block_symbol block_sym = {sym, block}; diff --git a/gdb/symtab.h b/gdb/symtab.h index ee4729b14cd..95b9bfa016b 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -1225,6 +1225,10 @@ enum symbol_subclass_kind extern gdb::array_view symbol_impls; +bool symbol_matches_domain (enum language symbol_language, + domain_enum symbol_domain, + domain_enum domain); + /* This structure is space critical. See space comments at the top. */ struct symbol : public general_symbol_info, public allocate_on_obstack @@ -1271,6 +1275,13 @@ struct symbol : public general_symbol_info, public allocate_on_obstack return this->impl ().aclass; } + /* Call symbol_matches_domain on this symbol, using the symbol's + domain. */ + bool matches (domain_enum d) const + { + return symbol_matches_domain (language (), domain (), d); + } + domain_enum domain () const { return m_domain; @@ -2020,10 +2031,6 @@ extern const char multiple_symbols_cancel[]; const char *multiple_symbols_select_mode (void); -bool symbol_matches_domain (enum language symbol_language, - domain_enum symbol_domain, - domain_enum domain); - /* lookup a symbol table by source file name. */ extern struct symtab *lookup_symtab (const char *); -- 2.41.0