From patchwork Thu Jan 18 20:32:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 84374 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 D3863385801A for ; Thu, 18 Jan 2024 20:34:38 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta038.useast.a.cloudfilter.net (omta038.useast.a.cloudfilter.net [44.202.169.37]) by sourceware.org (Postfix) with ESMTPS id C401C385840D for ; Thu, 18 Jan 2024 20:32:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C401C385840D 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 C401C385840D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.37 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705609940; cv=none; b=e2/bootgolqZkX2WLokNyOxce7aRpVtx0GY467qN5X0hYATmGL8js5dl76NUgTSCNNtnay2XnU5uqSzVwDI/YOAnI3sMWNSYKHqvQypDBSEsTnYuvArpAD3+CFiYd0bQcmQjf2ZIC1bPARNUhEOzzitIjNJgEIKsVE7291+4F+4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705609940; c=relaxed/simple; bh=xnQLRDoE/MWVdIHjcDTGeOH5bjK0blwgHy/+IFGGQHo=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=mUDwfcJmgQ/sdy0qAt3AbWGPZO4K8a1eD1gQZdF4cPBQHdkRSp3gJ0V6mKhetAnEK+/dFcTE9JcjMHMxHIAAcZpT3UPB4uwBNK5dYCvoMXNOyi5LKcyhN5hRWA/74SIrKyGNGFsmsZ00atJPlpuigo62VwjJg49lJnSWiFcgbbk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5001a.ext.cloudfilter.net ([10.0.29.139]) by cmsmtp with ESMTPS id QXxyrQEer9gG6QZ3crf5xN; Thu, 18 Jan 2024 20:32:12 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id QZ3brH2g2RT1bQZ3br8FbE; Thu, 18 Jan 2024 20:32:11 +0000 X-Authority-Analysis: v=2.4 cv=MKVzJeVl c=1 sm=1 tr=0 ts=65a98acb a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10 a=dEuoMetlWLkA:10 a=Qbun_eYptAEA:10 a=6hCNZdMetuoarO1jANEA: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=hqmIYDaE2uV8q9D+mVUfeGQm9SUmDY3EjikNZRzO7G4=; b=Inm5tXjNZElmMS7STGocZjihwj 8T6l2hQa68UizYzWpwpg7jsnEYInqIvl4D93h35iAL1V+y9sJfMu8P7F/AvWYcAar6Au7hMPYouff 2kyeOwtHY23v2U6RqjXHmfQNK; Received: from 97-122-68-157.hlrn.qwest.net ([97.122.68.157]:50746 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 1rQZ3b-002DCj-00 for gdb-patches@sourceware.org; Thu, 18 Jan 2024 13:32:11 -0700 From: Tom Tromey Date: Thu, 18 Jan 2024 13:32:13 -0700 Subject: [PATCH v2 15/30] Introduce "scripting" domains MIME-Version: 1.0 Message-Id: <20240118-submit-domain-hacks-2-v2-15-aecab29fa104@tromey.com> References: <20240118-submit-domain-hacks-2-v2-0-aecab29fa104@tromey.com> In-Reply-To: <20240118-submit-domain-hacks-2-v2-0-aecab29fa104@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.68.157 X-Source-L: No X-Exim-ID: 1rQZ3b-002DCj-00 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-68-157.hlrn.qwest.net ([192.168.0.21]) [97.122.68.157]:50746 X-Source-Auth: tom+tromey.com X-Email-Count: 17 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfDSN/s8ucWcaXBqdP9YnXs+lTZP0T5StGIVJbJ1quevfBSj/FMgQkK1h2CPpaC83Rfkz95ur0db3otTwKdjlGRvio5MRDrSoOKzzYw0ApOYVCN53bBDg 2cjvxBoXbG7d9clGJ/+SWjnNz4M635zOwvo7sSBwt5AgI+Id1IUvafmXUeTdzdOfQEZ5xSjNvOh0yX9XZIdaa0V2YdmJ8t3feYA= X-Spam-Status: No, score=-3022.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, 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 The Python and Guile code exposed the internal domain constants both as attributes of symbols and as values to pass to lookup functions. Now, perfect backward compatibility here can't be achieved: some symbols are going to have domain changes by the end of this series. However, it seemed to me that we can preserve lookups using the basic domain values. This patch implements this by exporting the "or"-able search constants with an extra bit set. Then it introduces some functions to convert such constants to domain_search_flags. This will be used by the Python and Guile code, so that both old- and new-style lookups will work properly; and while preserving the idea that the domain constants can be compared to a symbol's domain. --- gdb/symtab.c | 42 ++++++++++++++++++++++++++++++++++++++++++ gdb/symtab.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/gdb/symtab.c b/gdb/symtab.c index 76a771b1166..6d24d2fe9ee 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -330,6 +330,48 @@ domain_name (domain_search_flags flags) /* See symtab.h. */ +domain_search_flags +from_scripting_domain (int val) +{ + if ((val & SCRIPTING_SEARCH_FLAG) == 0) + { + /* VAL should be one of the domain constants. Verify this and + convert it to a search constant. */ + switch (val) + { +#define DOMAIN(X) \ + case X ## _DOMAIN: break; +#include "sym-domains.def" +#undef DOMAIN + default: + error (_("unrecognized domain constant")); + } + domain_search_flags result = to_search_flags ((domain_enum) val); + if (val == VAR_DOMAIN) + { + /* This matches the historical practice. */ + result |= SEARCH_TYPE_DOMAIN | SEARCH_FUNCTION_DOMAIN; + } + return result; + } + else + { + /* VAL is several search constants or'd together. Verify + this. */ + val &= ~SCRIPTING_SEARCH_FLAG; + int check = val; +#define DOMAIN(X) \ + check &= ~ (int) SEARCH_ ## X ## _DOMAIN; +#include "sym-domains.def" +#undef DOMAIN + if (check != 0) + error (_("unrecognized domain constant")); + return (domain_search_flag) val; + } +} + +/* See symtab.h. */ + CORE_ADDR linetable_entry::pc (const struct objfile *objfile) const { diff --git a/gdb/symtab.h b/gdb/symtab.h index 2e55ad78039..b12c0541d6f 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -947,6 +947,37 @@ search_flags_matches (domain_search_flags flags, domain_enum domain) return (flags & to_search_flags (domain)) != 0; } +/* Some helpers for Python and Guile to account for backward + compatibility. Those exposed the domains for lookup as well as + checking attributes of a symbol, so special encoding and decoding + is needed to continue to support both uses. Domain constants must + remain unchanged, so that comparing a symbol's domain against a + constant yields the correct result, so search symbols are + distinguished by adding a flag bit. This way, either sort of + constant can be used for lookup. */ + +/* The flag bit. */ +constexpr int SCRIPTING_SEARCH_FLAG = 0x8000; +static_assert (SCRIPTING_SEARCH_FLAG > SEARCH_ALL); + +/* Convert a domain constant to a "scripting domain". */ +static constexpr inline int +to_scripting_domain (domain_enum val) +{ + return val; +} + +/* Convert a search constant to a "scripting domain". */ +static constexpr inline int +to_scripting_domain (domain_search_flags val) +{ + return SCRIPTING_SEARCH_FLAG | (int) val; +} + +/* Convert from a "scripting domain" constant back to search flags. + Throws an exception if VAL is not one of the allowable values. */ +extern domain_search_flags from_scripting_domain (int val); + /* An address-class says where to find the value of a symbol. */ enum address_class