From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 10/30] Use a .def file for domain_enum
Date: Thu, 18 Jan 2024 13:32:08 -0700 [thread overview]
Message-ID: <20240118-submit-domain-hacks-2-v2-10-aecab29fa104@tromey.com> (raw)
In-Reply-To: <20240118-submit-domain-hacks-2-v2-0-aecab29fa104@tromey.com>
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 <http://www.gnu.org/licenses/>. */
+
+/* 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. */
--
2.43.0
next prev parent reply other threads:[~2024-01-18 20:34 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-18 20:31 [PATCH v2 00/30] Restructure symbol domains Tom Tromey
2024-01-18 20:31 ` [PATCH v2 01/30] Fix bug in cooked index scanner Tom Tromey
2024-01-18 20:32 ` [PATCH v2 02/30] Small cleanup in DWARF reader Tom Tromey
2024-01-18 20:32 ` [PATCH v2 03/30] Fix latent bug in DW_TAG_entry_point handling Tom Tromey
2024-01-18 20:32 ` [PATCH v2 04/30] Make nsalias.exp more reliable Tom Tromey
2024-01-18 20:32 ` [PATCH v2 05/30] Fix latent bug in mdebugread.c Tom Tromey
2024-01-18 20:32 ` [PATCH v2 06/30] Give names to unspecified types Tom Tromey
2024-01-18 20:32 ` [PATCH v2 07/30] Remove NR_DOMAINS Tom Tromey
2024-01-18 20:32 ` [PATCH v2 08/30] Simplify symbol_to_info_string Tom Tromey
2024-01-18 20:32 ` [PATCH v2 09/30] Split up a big 'if' in symtab.c Tom Tromey
2024-01-18 20:32 ` Tom Tromey [this message]
2024-01-29 17:57 ` [PATCH v2 10/30] Use a .def file for domain_enum Lancelot SIX
2024-01-29 18:20 ` Tom Tromey
2024-01-18 20:32 ` [PATCH v2 11/30] Add two new symbol domains Tom Tromey
2024-01-18 20:32 ` [PATCH v2 12/30] Add domain_search_flags Tom Tromey
2024-01-18 20:32 ` [PATCH v2 13/30] Replace search_domain with domain_search_flags Tom Tromey
2024-01-18 20:32 ` [PATCH v2 14/30] Remove a check of VAR_DOMAIN Tom Tromey
2024-01-18 20:32 ` [PATCH v2 15/30] Introduce "scripting" domains Tom Tromey
2024-01-18 20:32 ` [PATCH v2 16/30] Use domain_search_flags in lookup_global_symbol_language Tom Tromey
2024-01-18 20:32 ` [PATCH v2 17/30] Use domain_search_flags in lookup_symbol et al Tom Tromey
2024-01-18 20:32 ` [PATCH v2 18/30] Remove some obsolete Python constants Tom Tromey
2024-01-18 20:32 ` [PATCH v2 19/30] Remove old symbol_matches_domain Tom Tromey
2024-01-18 20:32 ` [PATCH v2 20/30] Use the new symbol domains Tom Tromey
2024-01-18 20:32 ` [PATCH v2 21/30] Simplify some symbol searches in Ada code Tom Tromey
2024-01-18 20:32 ` [PATCH v2 22/30] Simplify some symbol searches in linespec.c Tom Tromey
2024-01-18 20:32 ` [PATCH v2 23/30] Only search for "main" as a function Tom Tromey
2024-01-18 20:32 ` [PATCH v2 24/30] Only look for functions in expand_symtabs_for_function Tom Tromey
2024-01-18 20:32 ` [PATCH v2 25/30] Use a function-domain search in inside_main_func Tom Tromey
2024-01-18 20:32 ` [PATCH v2 26/30] Only search types in cp_lookup_rtti_type Tom Tromey
2024-01-18 20:32 ` [PATCH v2 27/30] Only search types in lookup_typename Tom Tromey
2024-01-18 20:32 ` [PATCH v2 28/30] Only search for functions in rust_structop::evaluate_funcall Tom Tromey
2024-01-18 20:32 ` [PATCH v2 29/30] Refine search in cp_search_static_and_baseclasses Tom Tromey
2024-01-18 20:32 ` [PATCH v2 30/30] Document new Python and Guile constants Tom Tromey
2024-01-28 23:42 ` [PATCH v2 00/30] Restructure symbol domains Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240118-submit-domain-hacks-2-v2-10-aecab29fa104@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox