diff options
author | Tom Tromey <tom@tromey.com> | 2022-06-01 15:31:15 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2022-08-04 13:28:04 -0600 |
commit | cb275538dbddfbb3c2c372a665ac48e6f617ea33 (patch) | |
tree | 7bc54ff4fc92c9b1cee74c2d7b9ae452b5ffec8b /gdb/gdbtypes.c | |
parent | 8b1540430107b0752485ab9e6a841dbbacd45681 (diff) | |
download | binutils-gdb-cb275538dbddfbb3c2c372a665ac48e6f617ea33.tar.gz |
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/gdbtypes.c')
-rw-r--r-- | gdb/gdbtypes.c | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 8ab0a898ba6..8c2558dd7ac 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -6147,19 +6147,12 @@ type::fixed_point_scaling_factor () -static struct gdbarch_data *gdbtypes_data; +static const registry<gdbarch>::key<struct builtin_type> gdbtypes_data; -const struct builtin_type * -builtin_type (struct gdbarch *gdbarch) +static struct builtin_type * +create_gdbtypes_data (struct gdbarch *gdbarch) { - return (const struct builtin_type *) gdbarch_data (gdbarch, gdbtypes_data); -} - -static void * -gdbtypes_post_init (struct gdbarch *gdbarch) -{ - struct builtin_type *builtin_type - = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_type); + struct builtin_type *builtin_type = new struct builtin_type; /* Basic types. */ builtin_type->builtin_void @@ -6302,6 +6295,18 @@ gdbtypes_post_init (struct gdbarch *gdbarch) return builtin_type; } +const struct builtin_type * +builtin_type (struct gdbarch *gdbarch) +{ + struct builtin_type *result = gdbtypes_data.get (gdbarch); + if (result == nullptr) + { + result = create_gdbtypes_data (gdbarch); + gdbtypes_data.set (gdbarch, result); + } + return result; +} + /* This set of objfile-based types is intended to be used by symbol readers as basic types. */ @@ -6439,8 +6444,6 @@ void _initialize_gdbtypes (); void _initialize_gdbtypes () { - gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init); - add_setshow_zuinteger_cmd ("overload", no_class, &overload_debug, _("Set debugging of C++ overloading."), _("Show debugging of C++ overloading."), |