From cb275538dbddfbb3c2c372a665ac48e6f617ea33 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 1 Jun 2022 15:31:15 -0600 Subject: 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. --- gdb/windows-tdep.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'gdb/windows-tdep.c') diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c index 2516e4e..a34ac5e 100644 --- a/gdb/windows-tdep.c +++ b/gdb/windows-tdep.c @@ -175,29 +175,25 @@ static const int FULL_TIB_SIZE = 0x1000; static bool maint_display_all_tib = false; -static struct gdbarch_data *windows_gdbarch_data_handle; - struct windows_gdbarch_data { - struct type *siginfo_type; - struct type *tib_ptr_type; /* Type of thread information block */ + struct type *siginfo_type = nullptr; + /* Type of thread information block. */ + struct type *tib_ptr_type = nullptr; }; -/* Allocate windows_gdbarch_data for an arch. */ - -static void * -init_windows_gdbarch_data (struct gdbarch *gdbarch) -{ - return GDBARCH_OBSTACK_ZALLOC (gdbarch, struct windows_gdbarch_data); -} +static const registry::key + windows_gdbarch_data_handle; /* Get windows_gdbarch_data of an arch. */ static struct windows_gdbarch_data * get_windows_gdbarch_data (struct gdbarch *gdbarch) { - return ((struct windows_gdbarch_data *) - gdbarch_data (gdbarch, windows_gdbarch_data_handle)); + windows_gdbarch_data *result = windows_gdbarch_data_handle.get (gdbarch); + if (result == nullptr) + result = windows_gdbarch_data_handle.emplace (gdbarch); + return result; } /* Define Thread Local Base pointer type. */ @@ -1195,9 +1191,6 @@ void _initialize_windows_tdep (); void _initialize_windows_tdep () { - windows_gdbarch_data_handle - = gdbarch_data_register_post_init (init_windows_gdbarch_data); - init_w32_command_list (); cmd_list_element *info_w32_thread_information_block_cmd = add_cmd ("thread-information-block", class_info, display_tib, -- cgit v1.1