public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 15/30] Introduce "scripting" domains
Date: Thu, 18 Jan 2024 13:32:13 -0700	[thread overview]
Message-ID: <20240118-submit-domain-hacks-2-v2-15-aecab29fa104@tromey.com> (raw)
In-Reply-To: <20240118-submit-domain-hacks-2-v2-0-aecab29fa104@tromey.com>

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

-- 
2.43.0


  parent reply	other threads:[~2024-01-18 20:32 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 ` [PATCH v2 10/30] Use a .def file for domain_enum Tom Tromey
2024-01-29 17:57   ` 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 ` Tom Tromey [this message]
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-15-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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).