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/frame-unwind.c | |
parent | 8b1540430107b0752485ab9e6a841dbbacd45681 (diff) | |
download | gdb-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/frame-unwind.c')
-rw-r--r-- | gdb/frame-unwind.c | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/gdb/frame-unwind.c b/gdb/frame-unwind.c index 302ce1e..78fc8dd 100644 --- a/gdb/frame-unwind.c +++ b/gdb/frame-unwind.c @@ -29,8 +29,6 @@ #include "gdbarch.h" #include "dwarf2/frame-tailcall.h" -static struct gdbarch_data *frame_unwind_data; - struct frame_unwind_table_entry { const struct frame_unwind *unwinder; @@ -39,11 +37,14 @@ struct frame_unwind_table_entry struct frame_unwind_table { - struct frame_unwind_table_entry *list; + struct frame_unwind_table_entry *list = nullptr; /* The head of the OSABI part of the search list. */ - struct frame_unwind_table_entry **osabi_head; + struct frame_unwind_table_entry **osabi_head = nullptr; }; +static const registry<gdbarch>::key<struct frame_unwind_table> + frame_unwind_data; + /* A helper function to add an unwinder to a list. LINK says where to install the new unwinder. The new link is returned. */ @@ -56,16 +57,20 @@ add_unwinder (struct obstack *obstack, const struct frame_unwind *unwinder, return &(*link)->next; } -static void * -frame_unwind_init (struct obstack *obstack) +static struct frame_unwind_table * +get_frame_unwind_table (struct gdbarch *gdbarch) { - struct frame_unwind_table *table - = OBSTACK_ZALLOC (obstack, struct frame_unwind_table); + struct frame_unwind_table *table = frame_unwind_data.get (gdbarch); + if (table != nullptr) + return table; + + table = new frame_unwind_table; /* Start the table out with a few default sniffers. OSABI code can't override this. */ struct frame_unwind_table_entry **link = &table->list; + struct obstack *obstack = gdbarch_obstack (gdbarch); link = add_unwinder (obstack, &dummy_frame_unwind, link); /* The DWARF tailcall sniffer must come before the inline sniffer. Otherwise, we can end up in a situation where a DWARF frame finds @@ -79,6 +84,8 @@ frame_unwind_init (struct obstack *obstack) /* The insertion point for OSABI sniffers. */ table->osabi_head = link; + frame_unwind_data.set (gdbarch, table); + return table; } @@ -86,8 +93,7 @@ void frame_unwind_prepend_unwinder (struct gdbarch *gdbarch, const struct frame_unwind *unwinder) { - struct frame_unwind_table *table - = (struct frame_unwind_table *) gdbarch_data (gdbarch, frame_unwind_data); + struct frame_unwind_table *table = get_frame_unwind_table (gdbarch); struct frame_unwind_table_entry *entry; /* Insert the new entry at the start of the list. */ @@ -101,8 +107,7 @@ void frame_unwind_append_unwinder (struct gdbarch *gdbarch, const struct frame_unwind *unwinder) { - struct frame_unwind_table *table - = (struct frame_unwind_table *) gdbarch_data (gdbarch, frame_unwind_data); + struct frame_unwind_table *table = get_frame_unwind_table (gdbarch); struct frame_unwind_table_entry **ip; /* Find the end of the list and insert the new entry there. */ @@ -182,8 +187,7 @@ frame_unwind_find_by_frame (struct frame_info *this_frame, void **this_cache) frame_debug_printf ("this_frame=%d", frame_relative_level (this_frame)); struct gdbarch *gdbarch = get_frame_arch (this_frame); - struct frame_unwind_table *table - = (struct frame_unwind_table *) gdbarch_data (gdbarch, frame_unwind_data); + struct frame_unwind_table *table = get_frame_unwind_table (gdbarch); struct frame_unwind_table_entry *entry; const struct frame_unwind *unwinder_from_target; @@ -333,10 +337,3 @@ frame_unwind_got_address (struct frame_info *frame, int regnum, register_type (gdbarch, regnum), addr); return reg_val; } - -void _initialize_frame_unwind (); -void -_initialize_frame_unwind () -{ - frame_unwind_data = gdbarch_data_register_pre_init (frame_unwind_init); -} |