summaryrefslogtreecommitdiff
path: root/gdb/go-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/go-lang.c
parent8b1540430107b0752485ab9e6a841dbbacd45681 (diff)
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/go-lang.c')
-rw-r--r--gdb/go-lang.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 844f743e83..c56db23852 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -481,11 +481,10 @@ go_language::language_arch_info (struct gdbarch *gdbarch,
static go_language go_language_defn;
-static void *
+static struct builtin_go_type *
build_go_types (struct gdbarch *gdbarch)
{
- struct builtin_go_type *builtin_go_type
- = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_go_type);
+ struct builtin_go_type *builtin_go_type = new struct builtin_go_type;
builtin_go_type->builtin_void
= arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
@@ -527,17 +526,17 @@ build_go_types (struct gdbarch *gdbarch)
return builtin_go_type;
}
-static struct gdbarch_data *go_type_data;
+static const registry<gdbarch>::key<struct builtin_go_type> go_type_data;
const struct builtin_go_type *
builtin_go_type (struct gdbarch *gdbarch)
{
- return (const struct builtin_go_type *) gdbarch_data (gdbarch, go_type_data);
-}
+ struct builtin_go_type *result = go_type_data.get (gdbarch);
+ if (result == nullptr)
+ {
+ result = build_go_types (gdbarch);
+ go_type_data.set (gdbarch, result);
+ }
-void _initialize_go_language ();
-void
-_initialize_go_language ()
-{
- go_type_data = gdbarch_data_register_post_init (build_go_types);
+ return result;
}