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/dwarf2/expr.c | |
parent | 8b1540430107b0752485ab9e6a841dbbacd45681 (diff) | |
download | binutils-cb275538dbddfbb3c2c372a665ac48e6f617ea33.zip binutils-cb275538dbddfbb3c2c372a665ac48e6f617ea33.tar.gz binutils-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/dwarf2/expr.c')
-rw-r--r-- | gdb/dwarf2/expr.c | 32 |
1 files changed, 6 insertions, 26 deletions
diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c index 9986258..3549745 100644 --- a/gdb/dwarf2/expr.c +++ b/gdb/dwarf2/expr.c @@ -34,30 +34,17 @@ #include "gdbarch.h" #include "objfiles.h" -/* Cookie for gdbarch data. */ - -static struct gdbarch_data *dwarf_arch_cookie; - /* This holds gdbarch-specific types used by the DWARF expression evaluator. See comments in execute_stack_op. */ struct dwarf_gdbarch_types { - struct type *dw_types[3]; + struct type *dw_types[3] {}; }; -/* Allocate and fill in dwarf_gdbarch_types for an arch. */ - -static void * -dwarf_gdbarch_types_init (struct gdbarch *gdbarch) -{ - struct dwarf_gdbarch_types *types - = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct dwarf_gdbarch_types); - - /* The types themselves are lazily initialized. */ +/* Cookie for gdbarch data. */ - return types; -} +static const registry<gdbarch>::key<dwarf_gdbarch_types> dwarf_arch_cookie; /* Ensure that a FRAME is defined, throw an exception otherwise. */ @@ -701,8 +688,9 @@ struct type * dwarf_expr_context::address_type () const { gdbarch *arch = this->m_per_objfile->objfile->arch (); - dwarf_gdbarch_types *types - = (dwarf_gdbarch_types *) gdbarch_data (arch, dwarf_arch_cookie); + dwarf_gdbarch_types *types = dwarf_arch_cookie.get (arch); + if (types == nullptr) + types = dwarf_arch_cookie.emplace (arch); int ndx; if (this->m_addr_size == 2) @@ -2398,11 +2386,3 @@ dwarf_expr_context::execute_stack_op (const gdb_byte *op_ptr, this->m_recursion_depth--; gdb_assert (this->m_recursion_depth >= 0); } - -void _initialize_dwarf2expr (); -void -_initialize_dwarf2expr () -{ - dwarf_arch_cookie - = gdbarch_data_register_post_init (dwarf_gdbarch_types_init); -} |