From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 11/29] Add domain_search_flags
Date: Mon, 20 Nov 2023 20:53:42 -0700 [thread overview]
Message-ID: <20231120-submit-domain-hacks-2-v1-11-29650d01b198@tromey.com> (raw)
In-Reply-To: <20231120-submit-domain-hacks-2-v1-0-29650d01b198@tromey.com>
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;
--
2.41.0
next prev parent reply other threads:[~2023-11-21 3:53 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-21 3:53 [PATCH 00/29] Restructure symbol domains Tom Tromey
2023-11-21 3:53 ` [PATCH 01/29] Fix bug in cooked index scanner Tom Tromey
2023-11-21 3:53 ` [PATCH 02/29] Small cleanup in DWARF reader Tom Tromey
2023-11-21 3:53 ` [PATCH 03/29] Make nsalias.exp more reliable Tom Tromey
2023-11-21 3:53 ` [PATCH 04/29] Fix latent bug in mdebugread.c Tom Tromey
2023-11-21 3:53 ` [PATCH 05/29] Give names to unspecified types Tom Tromey
2023-11-21 3:53 ` [PATCH 06/29] Remove NR_DOMAINS Tom Tromey
2023-11-21 3:53 ` [PATCH 07/29] Simplify symbol_to_info_string Tom Tromey
2023-11-21 3:53 ` [PATCH 08/29] Split up a big 'if' in symtab.c Tom Tromey
2023-11-21 3:53 ` [PATCH 09/29] Use a .def file for domain_enum Tom Tromey
2023-11-21 3:53 ` [PATCH 10/29] Add two new symbol domains Tom Tromey
2023-11-21 3:53 ` Tom Tromey [this message]
2023-11-21 3:53 ` [PATCH 12/29] Replace search_domain with domain_search_flags Tom Tromey
2023-11-21 3:53 ` [PATCH 13/29] Remove a check of VAR_DOMAIN Tom Tromey
2023-11-21 3:53 ` [PATCH 14/29] Introduce "scripting" domains Tom Tromey
2023-11-21 3:53 ` [PATCH 15/29] Use domain_search_flags in lookup_global_symbol_language Tom Tromey
2023-11-21 3:53 ` [PATCH 16/29] Use domain_search_flags in lookup_symbol et al Tom Tromey
2023-11-21 3:53 ` [PATCH 17/29] Remove some obsolete Python constants Tom Tromey
2023-11-21 3:53 ` [PATCH 18/29] Remove old symbol_matches_domain Tom Tromey
2023-11-21 3:53 ` [PATCH 19/29] Use the new symbol domains Tom Tromey
2023-11-21 3:53 ` [PATCH 20/29] Simplify some symbol searches in Ada code Tom Tromey
2023-11-21 3:53 ` [PATCH 21/29] Simplify some symbol searches in linespec.c Tom Tromey
2023-11-21 3:53 ` [PATCH 22/29] Only search for "main" as a function Tom Tromey
2023-11-21 3:53 ` [PATCH 23/29] Only look for functions in expand_symtabs_for_function Tom Tromey
2023-11-21 3:53 ` [PATCH 24/29] Use a function-domain search in inside_main_func Tom Tromey
2023-11-21 3:53 ` [PATCH 25/29] Only search types in cp_lookup_rtti_type Tom Tromey
2023-11-21 3:53 ` [PATCH 26/29] Only search types in lookup_typename Tom Tromey
2023-11-21 3:53 ` [PATCH 27/29] Only search for functions in rust_structop::evaluate_funcall Tom Tromey
2023-11-21 3:53 ` [PATCH 28/29] Refine search in cp_search_static_and_baseclasses Tom Tromey
2023-11-21 3:54 ` [PATCH 29/29] Document new Python and Guile constants Tom Tromey
2023-11-21 11:39 ` Eli Zaretskii
2024-01-23 0:34 ` Tom Tromey
2024-01-23 18:11 ` Eli Zaretskii
2023-11-21 18:37 ` [PATCH 00/29] Restructure symbol domains John Baldwin
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=20231120-submit-domain-hacks-2-v1-11-29650d01b198@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).