From patchwork Tue Nov 21 03:53:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 80405 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B8171385843A for ; Tue, 21 Nov 2023 03:54:57 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta040.useast.a.cloudfilter.net (omta040.useast.a.cloudfilter.net [44.202.169.39]) by sourceware.org (Postfix) with ESMTPS id 9FCDA3858C54 for ; Tue, 21 Nov 2023 03:53:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9FCDA3858C54 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 9FCDA3858C54 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700538805; cv=none; b=qGkwMAY2WTGq8hct4N1Ao2UitTNoM5PM0ffiBE8hCPm7q+g7x82AvkpdpTbDQa/KPaouK4Opu6MZURy2Hg2YoS1qcvhHW3oSuZV0Ur4B+kBqaCf78hD1YP4G4YAcldX0zvt/+75tgjPdQ3NujbG+KNSRQgoXL3ZhJc0Qh9JZXV4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700538805; c=relaxed/simple; bh=yPaNGsvKDVX0+gN2vdRtD4MDBDDj+NNQnidS5Gql5v4=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=BAaAw/8fir6ZML12jlNyATfgbcVG7VqZjt8mWl0B6wITmSbtObTa0UC+FkgJK079l/bjIw+0ASDdVdHfWZ+7qUuByFdS81oXIDGVJQ3VbX44ycBJQnqYqg1TAEW3id01JKFKi78lApqZV5HErCU6nTjCh+B0z5P4zXBKiY4AN8M= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6002a.ext.cloudfilter.net ([10.0.30.222]) by cmsmtp with ESMTPS id 5AuCrpVIT6nOZ5HpBrzrPM; Tue, 21 Nov 2023 03:53:21 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id 5HpAr57t3M0U25HpArctLd; Tue, 21 Nov 2023 03:53:20 +0000 X-Authority-Analysis: v=2.4 cv=BuKOfKb5 c=1 sm=1 tr=0 ts=655c29b0 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10 a=BNY50KLci1gA:10 a=Qbun_eYptAEA:10 a=INT8-sjlIe3v6QsWUHQA:9 a=QEXdDO2ut3YA:10 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc: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=ERpUl8yTrucQMXt1kEFFjwZdxsQgi37vvaDaVaKhzvs=; b=JjYleOyySsUSZOT879mLEQL0Z2 rdD1uSvt0nCKaPYMB2jarGs39RXeGFTMZte5+w9mtNwVgiRIzGcynw3Y/z/V3fGseVO8txJ+/VOY2 N1uI690nO/eOjDwy1hP8PaVIJ; Received: from 97-122-77-73.hlrn.qwest.net ([97.122.77.73]:47856 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1r5Hp9-0040be-2q for gdb-patches@sourceware.org; Mon, 20 Nov 2023 20:53:19 -0700 From: Tom Tromey Date: Mon, 20 Nov 2023 20:53:42 -0700 Subject: [PATCH 11/29] Add domain_search_flags MIME-Version: 1.0 Message-Id: <20231120-submit-domain-hacks-2-v1-11-29650d01b198@tromey.com> References: <20231120-submit-domain-hacks-2-v1-0-29650d01b198@tromey.com> In-Reply-To: <20231120-submit-domain-hacks-2-v1-0-29650d01b198@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 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.77.73 X-Source-L: No X-Exim-ID: 1r5Hp9-0040be-2q X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-77-73.hlrn.qwest.net ([192.168.0.21]) [97.122.77.73]:47856 X-Source-Auth: tom+tromey.com X-Email-Count: 12 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfLaStsvCDNEP06Prf7RYbmWhlDCLOmUbQfN18Cv3AFp8SL8bMGMjorHkYp9+NnNVwm52Y0XR3hNpApZs4ra6y74KNR1RtRC086xBOw3+XBqlspGRCc1/ J6kSjzsPUlcB228TnsrVFWfk+ouZX9afcx/xtXYW/6XzC2z8GNYdmSigl2f2VRMFsMtgqYaMkbkLgrD/n8RbDpxnCNazRU5pkJU= X-Spam-Status: No, score=-3024.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This adds a new flag enum type, domain_search_flags, which is the flag version of domain_enum. Nothing uses this yet, but the goal here is to have all symbol searches and lookups use these flags. The new names are chosen to exactly parallel domain_enum. --- gdb/symtab.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ gdb/symtab.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/gdb/symtab.c b/gdb/symtab.c index 3bc158cec43..3c66cca1cab 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -330,6 +330,21 @@ search_domain_name (enum search_domain e) /* See symtab.h. */ +std::string +domain_name (domain_search_flags flags) +{ + static constexpr domain_search_flags::string_mapping mapping[] = { +#define DOMAIN(X) \ + MAP_ENUM_FLAG (SEARCH_ ## X ## _DOMAIN), +#include "sym-domains.def" +#undef DOMAIN + }; + + return flags.to_string (mapping); +} + +/* See symtab.h. */ + CORE_ADDR linetable_entry::pc (const struct objfile *objfile) const { @@ -2665,6 +2680,41 @@ symbol_matches_domain (enum language symbol_language, /* See symtab.h. */ +bool +symbol::matches (domain_search_flags flags) const +{ + if (language () != language_c + && language () != language_objc + && language () != language_opencl) + { + /* Only C languages distinguish tag and type namespaces. */ + if ((flags & SEARCH_TYPE_DOMAIN) != 0) + flags |= SEARCH_STRUCT_DOMAIN; + } + + if ((flags & SEARCH_FUNCTION_DOMAIN) != 0 + && domain () == VAR_DOMAIN + && aclass () == LOC_BLOCK) + return true; + + if ((flags & SEARCH_VAR_DOMAIN) != 0 + && domain () == VAR_DOMAIN) + return true; + + if ((flags & SEARCH_TYPE_DOMAIN) != 0 + && domain () == VAR_DOMAIN + && aclass () == LOC_TYPEDEF) + return true; + + if ((flags & SEARCH_STRUCT_DOMAIN) != 0 + && domain () == STRUCT_DOMAIN) + return true; + + return search_flags_matches (flags, m_domain); +} + +/* See symtab.h. */ + struct type * lookup_transparent_type (const char *name) { diff --git a/gdb/symtab.h b/gdb/symtab.h index 20cc0e90c14..0328a2024ad 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -899,6 +899,48 @@ enum domain_enum extern const char *domain_name (domain_enum); +/* Flags used for searching symbol tables. These can be combined to + let the search match multiple kinds of symbol. */ +enum domain_search_flag +{ +#define DOMAIN(X) \ + SEARCH_ ## X ## _DOMAIN = (1 << X ## _DOMAIN), +#include "sym-domains.def" +#undef DOMAIN +}; +DEF_ENUM_FLAGS_TYPE (enum domain_search_flag, domain_search_flags); + +/* A convenience constant to search for any symbol. */ +constexpr domain_search_flags SEARCH_ALL + = ((domain_search_flags) 0 +#define DOMAIN(X) | SEARCH_ ## X ## _DOMAIN +#include "sym-domains.def" +#undef DOMAIN + ); + +/* A convenience define for "C-like" name lookups, matching variables, + types, and functions. */ +#define SEARCH_VFT \ + (SEARCH_VAR_DOMAIN | SEARCH_FUNCTION_DOMAIN | SEARCH_TYPE_DOMAIN) + +/* Return a string representing the given flags. */ +extern std::string domain_name (domain_search_flags); + +/* Convert a symbol domain to search flags. */ +static inline domain_search_flags +to_search_flags (domain_enum domain) +{ + return domain_search_flags (domain_search_flag (1 << domain)); +} + +/* Return true if the given domain matches the given flags, false + otherwise. */ +static inline bool +search_flags_matches (domain_search_flags flags, domain_enum domain) +{ + return (flags & to_search_flags (domain)) != 0; +} + /* Searching domains, used when searching for symbols. Element numbers are hardcoded in GDB, check all enum uses before changing it. */ @@ -1244,6 +1286,9 @@ struct symbol : public general_symbol_info, public allocate_on_obstack return symbol_matches_domain (language (), domain (), d); } + /* Return true if this symbol's domain matches FLAGS. */ + bool matches (domain_search_flags flags) const; + domain_enum domain () const { return m_domain;