From patchwork Thu Jan 18 20:32:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 84373 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 A882838582B6 for ; Thu, 18 Jan 2024 20:34:36 +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 D751D3858CDB for ; Thu, 18 Jan 2024 20:32:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D751D3858CDB 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 D751D3858CDB 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=1705609937; cv=none; b=Sy8oIkNZBpOohV9I4qC3Gd53qDyL1kh8dgc//NGM0I+ua9wERvP3pbkGa78KMLEeRlRW03WKb8ssARVrNhDaOc9XTbHYiJR+nV1lU05rhAMZ5L8VELu9Rqkn2faDnniJa6lR00ojKqmYoIslN/x6u3WvYdocfLLP9h87JVp13kM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705609937; c=relaxed/simple; bh=SWF7r1jYfk2/mXX1PIBZxmONO4yny//if4uV5CeuqWY=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=o5DZiwerqS2iJ2FpvpdR+ZArPmvIK3NdyvB10DIXsdbuCgedxNmICBw8AX4G466P6rDa3NniAhKn9P/ullDjByCppLghLMN9Ti7xie2l9V2T/DaFGnjbk4hl6u4d53STWs91WDv6Y1II4W+6VGHzdgQzYiab73HJ3cmdJuIgho8= 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 QSw7rOXAB9gG6QZ3arf5w3; Thu, 18 Jan 2024 20:32:10 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id QZ3ZrsCGAD6lhQZ3arjjTy; Thu, 18 Jan 2024 20:32:10 +0000 X-Authority-Analysis: v=2.4 cv=LNR1/ba9 c=1 sm=1 tr=0 ts=65a98aca 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=mDV3o1hIAAAA:8 a=z3Xw3AbGaEhUEUh7u4IA:9 a=QEXdDO2ut3YA:10 a=_FVE-zBwftR9WsbkzFJk:22 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=NF7GBtqPlH7L/4Yzz5xFCMbjqQcscogCsZ7FxQwNxG8=; b=F1RCXE69tOOKh/tmKSdwYzJL/R oUCDErfqYcn2eyMVvjTj3NSKQUQrrjR5A80dpf3fg8RIRNNcOirQo7iS8lK90eePgDpCxkUn8gquT EveWBiGi5tea8sQaUmuo2bJfT; 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 1rQZ3Z-002DCj-2H for gdb-patches@sourceware.org; Thu, 18 Jan 2024 13:32:09 -0700 From: Tom Tromey Date: Thu, 18 Jan 2024 13:32:08 -0700 Subject: [PATCH v2 10/30] Use a .def file for domain_enum MIME-Version: 1.0 Message-Id: <20240118-submit-domain-hacks-2-v2-10-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: 1rQZ3Z-002DCj-2H 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: 12 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfJpIoupor8JiCxMSFniBC1UdgeA4n0kZjqlLeQFkgKPNFUnb+O8ifPgRGmFcapE8ILY2TN30pCWVkMoy58CPsDI60mjvxNP3cndg0G02qKYqnSQ0rNmp wRZUgkn1o6F6tLBmIUYxn4gAzcT2D4EiTQBQQCkgI1yUOcM4uxAiJ38X2cVGzS/bN6PAvHtWfOHOi13Mo1hsOvBNhymb5Zt2vGs= X-Spam-Status: No, score=-3022.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_SHORT, KAM_STOCKGEN, 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 Future patches will change and reuse the names from domain_enum. This patch makes this less error-prone by having a single point to define these names, using the typical gdb ".def" file. --- gdb/guile/scm-symbol.c | 18 ++++++++++-------- gdb/python/py-symbol.c | 21 ++++++++------------- gdb/sym-domains.def | 47 +++++++++++++++++++++++++++++++++++++++++++++++ gdb/symtab.c | 10 ++++------ gdb/symtab.h | 31 +++---------------------------- 5 files changed, 72 insertions(+), 55 deletions(-) diff --git a/gdb/guile/scm-symbol.c b/gdb/guile/scm-symbol.c index 801c3f13b96..bf5fe24f23d 100644 --- a/gdb/guile/scm-symbol.c +++ b/gdb/guile/scm-symbol.c @@ -693,16 +693,18 @@ static const scheme_integer_constant symbol_integer_constants[] = X (LOC_OPTIMIZED_OUT), X (LOC_COMPUTED), X (LOC_REGPARM_ADDR), - - X (UNDEF_DOMAIN), - X (VAR_DOMAIN), - X (STRUCT_DOMAIN), - X (LABEL_DOMAIN), - X (VARIABLES_DOMAIN), - X (FUNCTIONS_DOMAIN), - X (TYPES_DOMAIN), #undef X +#define DOMAIN(X) \ + { "SYMBOL_" #X "_DOMAIN", X ## _DOMAIN }, +#include "sym-domains.def" +#undef DOMAIN + + /* These were never correct. */ + { "SYMBOL_VARIABLES_DOMAIN", VAR_DOMAIN }, + { "SYMBOL_FUNCTIONS_DOMAIN", VAR_DOMAIN }, + { "SYMBOL_TYPES_DOMAIN", VAR_DOMAIN }, + END_INTEGER_CONSTANTS }; diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c index 82ea5c59c63..52a25b632e0 100644 --- a/gdb/python/py-symbol.c +++ b/gdb/python/py-symbol.c @@ -670,20 +670,15 @@ gdbpy_initialize_symbols (void) || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_COMMON_BLOCK", LOC_COMMON_BLOCK) < 0 || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGPARM_ADDR", - LOC_REGPARM_ADDR) < 0 - || PyModule_AddIntConstant (gdb_module, "SYMBOL_UNDEF_DOMAIN", - UNDEF_DOMAIN) < 0 - || PyModule_AddIntConstant (gdb_module, "SYMBOL_VAR_DOMAIN", - VAR_DOMAIN) < 0 - || PyModule_AddIntConstant (gdb_module, "SYMBOL_STRUCT_DOMAIN", - STRUCT_DOMAIN) < 0 - || PyModule_AddIntConstant (gdb_module, "SYMBOL_LABEL_DOMAIN", - LABEL_DOMAIN) < 0 - || PyModule_AddIntConstant (gdb_module, "SYMBOL_MODULE_DOMAIN", - MODULE_DOMAIN) < 0 - || PyModule_AddIntConstant (gdb_module, "SYMBOL_COMMON_BLOCK_DOMAIN", - COMMON_BLOCK_DOMAIN) < 0) + LOC_REGPARM_ADDR) < 0) + return -1; + +#define DOMAIN(X) \ + if (PyModule_AddIntConstant (gdb_module, "SYMBOL_" #X "_DOMAIN", \ + X ## _DOMAIN) < 0) \ return -1; +#include "sym-domains.def" +#undef DOMAIN /* These remain defined for compatibility, but as they were never correct, they are no longer documented. Eventually we can remove diff --git a/gdb/sym-domains.def b/gdb/sym-domains.def new file mode 100644 index 00000000000..251c66fa04b --- /dev/null +++ b/gdb/sym-domains.def @@ -0,0 +1,47 @@ +/* Symbol domains -*- c++ -*- + + Copyright (C) 2023 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* UNDEF_DOMAIN is used when a domain has not been discovered or + none of the following apply. This usually indicates an error either + in the symbol information or in gdb's handling of symbols. */ + +DOMAIN (UNDEF) + +/* VAR_DOMAIN is the usual domain. In C, this contains variables, + function names, typedef names and enum type values. */ + +DOMAIN (VAR) + +/* STRUCT_DOMAIN is used in C to hold struct, union and enum type names. + Thus, if `struct foo' is used in a C program, it produces a symbol named + `foo' in the STRUCT_DOMAIN. */ + +DOMAIN (STRUCT) + +/* MODULE_DOMAIN is used in Fortran to hold module type names. */ + +DOMAIN (MODULE) + +/* LABEL_DOMAIN may be used for names of labels (for gotos). */ + +DOMAIN (LABEL) + +/* Fortran common blocks. Their naming must be separate from VAR_DOMAIN. + They also always use LOC_COMMON_BLOCK. */ +DOMAIN (COMMON_BLOCK) diff --git a/gdb/symtab.c b/gdb/symtab.c index 2020210c5f4..b1deb9d6767 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -305,12 +305,10 @@ domain_name (domain_enum e) { switch (e) { - case UNDEF_DOMAIN: return "UNDEF_DOMAIN"; - case VAR_DOMAIN: return "VAR_DOMAIN"; - case STRUCT_DOMAIN: return "STRUCT_DOMAIN"; - case MODULE_DOMAIN: return "MODULE_DOMAIN"; - case LABEL_DOMAIN: return "LABEL_DOMAIN"; - case COMMON_BLOCK_DOMAIN: return "COMMON_BLOCK_DOMAIN"; +#define DOMAIN(X) \ + case X ## _DOMAIN: return #X "_DOMAIN"; +#include "sym-domains.def" +#undef DOMAIN default: gdb_assert_not_reached ("bad domain_enum"); } } diff --git a/gdb/symtab.h b/gdb/symtab.h index 0a5f2633fe8..7e841c4033f 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -894,34 +894,9 @@ struct minimal_symbol : public general_symbol_info enum domain_enum { - /* UNDEF_DOMAIN is used when a domain has not been discovered or - none of the following apply. This usually indicates an error either - in the symbol information or in gdb's handling of symbols. */ - - UNDEF_DOMAIN, - - /* VAR_DOMAIN is the usual domain. In C, this contains variables, - function names, typedef names and enum type values. */ - - VAR_DOMAIN, - - /* STRUCT_DOMAIN is used in C to hold struct, union and enum type names. - Thus, if `struct foo' is used in a C program, it produces a symbol named - `foo' in the STRUCT_DOMAIN. */ - - STRUCT_DOMAIN, - - /* MODULE_DOMAIN is used in Fortran to hold module type names. */ - - MODULE_DOMAIN, - - /* LABEL_DOMAIN may be used for names of labels (for gotos). */ - - LABEL_DOMAIN, - - /* Fortran common blocks. Their naming must be separate from VAR_DOMAIN. - They also always use LOC_COMMON_BLOCK. */ - COMMON_BLOCK_DOMAIN, +#define DOMAIN(X) X ## _DOMAIN, +#include "sym-domains.def" +#undef DOMAIN }; /* The number of bits in a symbol used to represent the domain. */