aboutsummaryrefslogtreecommitdiff
path: root/gdb/d-lang.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2022-06-01 15:31:15 -0600
committerTom Tromey <tom@tromey.com>2022-08-04 13:28:04 -0600
commitcb275538dbddfbb3c2c372a665ac48e6f617ea33 (patch)
tree7bc54ff4fc92c9b1cee74c2d7b9ae452b5ffec8b /gdb/d-lang.c
parent8b1540430107b0752485ab9e6a841dbbacd45681 (diff)
downloadgdb-cb275538dbddfbb3c2c372a665ac48e6f617ea33.zip
gdb-cb275538dbddfbb3c2c372a665ac48e6f617ea33.tar.gz
gdb-cb275538dbddfbb3c2c372a665ac48e6f617ea33.tar.bz2
Use registry in gdbarch
gdbarch implements its own registry-like approach. This patch changes it to instead use registry.h. It's a rather large patch but largely uninteresting -- it's mostly a straightforward conversion from the old approach to the new one. The main benefit of this change is that it introduces type safety to the gdbarch registry. It also removes a bunch of code. One possible drawback is that, previously, the gdbarch registry differentiated between pre- and post-initialization setup. This doesn't seem very important to me, though.
Diffstat (limited to 'gdb/d-lang.c')
-rw-r--r--gdb/d-lang.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index ce6dc05..d959199 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -188,11 +188,10 @@ static d_language d_language_defn;
/* Build all D language types for the specified architecture. */
-static void *
+static struct builtin_d_type *
build_d_types (struct gdbarch *gdbarch)
{
- struct builtin_d_type *builtin_d_type
- = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_d_type);
+ struct builtin_d_type *builtin_d_type = new struct builtin_d_type;
/* Basic types. */
builtin_d_type->builtin_void
@@ -265,19 +264,19 @@ build_d_types (struct gdbarch *gdbarch)
return builtin_d_type;
}
-static struct gdbarch_data *d_type_data;
+static const registry<gdbarch>::key<struct builtin_d_type> d_type_data;
/* Return the D type table for the specified architecture. */
const struct builtin_d_type *
builtin_d_type (struct gdbarch *gdbarch)
{
- return (const struct builtin_d_type *) gdbarch_data (gdbarch, d_type_data);
-}
+ struct builtin_d_type *result = d_type_data.get (gdbarch);
+ if (result == nullptr)
+ {
+ result = build_d_types (gdbarch);
+ d_type_data.set (gdbarch, result);
+ }
-void _initialize_d_language ();
-void
-_initialize_d_language ()
-{
- d_type_data = gdbarch_data_register_post_init (build_d_types);
+ return result;
}