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/linux-tdep.c | |
parent | 8b1540430107b0752485ab9e6a841dbbacd45681 (diff) | |
download | fsf-binutils-gdb-cb275538dbddfbb3c2c372a665ac48e6f617ea33.zip fsf-binutils-gdb-cb275538dbddfbb3c2c372a665ac48e6f617ea33.tar.gz fsf-binutils-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/linux-tdep.c')
-rw-r--r-- | gdb/linux-tdep.c | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index 4e6a48b..5fe6be1 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -193,25 +193,22 @@ enum LINUX_SIGRTMAX = 64, }; -static struct gdbarch_data *linux_gdbarch_data_handle; - struct linux_gdbarch_data { - struct type *siginfo_type; - int num_disp_step_buffers; + struct type *siginfo_type = nullptr; + int num_disp_step_buffers = 0; }; -static void * -init_linux_gdbarch_data (struct obstack *obstack) -{ - return obstack_zalloc<linux_gdbarch_data> (obstack); -} +static const registry<gdbarch>::key<linux_gdbarch_data> + linux_gdbarch_data_handle; static struct linux_gdbarch_data * get_linux_gdbarch_data (struct gdbarch *gdbarch) { - return ((struct linux_gdbarch_data *) - gdbarch_data (gdbarch, linux_gdbarch_data_handle)); + struct linux_gdbarch_data *result = linux_gdbarch_data_handle.get (gdbarch); + if (result == nullptr) + result = linux_gdbarch_data_handle.emplace (gdbarch); + return result; } /* Linux-specific cached data. This is used by GDB for caching @@ -2752,9 +2749,6 @@ void _initialize_linux_tdep (); void _initialize_linux_tdep () { - linux_gdbarch_data_handle = - gdbarch_data_register_pre_init (init_linux_gdbarch_data); - /* Observers used to invalidate the cache when needed. */ gdb::observers::inferior_exit.attach (invalidate_linux_cache_inf, "linux-tdep"); |