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 | |
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/dwarf2')
-rw-r--r-- | gdb/dwarf2/expr.c | 32 | ||||
-rw-r--r-- | gdb/dwarf2/frame.c | 58 |
2 files changed, 33 insertions, 57 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); -} diff --git a/gdb/dwarf2/frame.c b/gdb/dwarf2/frame.c index 387a2bc..0e681f0 100644 --- a/gdb/dwarf2/frame.c +++ b/gdb/dwarf2/frame.c @@ -580,23 +580,39 @@ execute_cfa_program_test (struct gdbarch *gdbarch) /* Architecture-specific operations. */ -/* Per-architecture data key. */ -static struct gdbarch_data *dwarf2_frame_data; +static void dwarf2_frame_default_init_reg (struct gdbarch *gdbarch, + int regnum, + struct dwarf2_frame_state_reg *reg, + struct frame_info *this_frame); struct dwarf2_frame_ops { /* Pre-initialize the register state REG for register REGNUM. */ void (*init_reg) (struct gdbarch *, int, struct dwarf2_frame_state_reg *, - struct frame_info *); + struct frame_info *) + = dwarf2_frame_default_init_reg; /* Check whether the THIS_FRAME is a signal trampoline. */ - int (*signal_frame_p) (struct gdbarch *, struct frame_info *); + int (*signal_frame_p) (struct gdbarch *, struct frame_info *) = nullptr; /* Convert .eh_frame register number to DWARF register number, or adjust .debug_frame register number. */ - int (*adjust_regnum) (struct gdbarch *, int, int); + int (*adjust_regnum) (struct gdbarch *, int, int) = nullptr; }; +/* Per-architecture data key. */ +static const registry<gdbarch>::key<dwarf2_frame_ops> dwarf2_frame_data; + +/* Get or initialize the frame ops. */ +static dwarf2_frame_ops * +get_frame_ops (struct gdbarch *gdbarch) +{ + dwarf2_frame_ops *result = dwarf2_frame_data.get (gdbarch); + if (result == nullptr) + result = dwarf2_frame_data.emplace (gdbarch); + return result; +} + /* Default architecture-specific register state initialization function. */ @@ -637,18 +653,6 @@ dwarf2_frame_default_init_reg (struct gdbarch *gdbarch, int regnum, reg->how = DWARF2_FRAME_REG_CFA; } -/* Return a default for the architecture-specific operations. */ - -static void * -dwarf2_frame_init (struct obstack *obstack) -{ - struct dwarf2_frame_ops *ops; - - ops = OBSTACK_ZALLOC (obstack, struct dwarf2_frame_ops); - ops->init_reg = dwarf2_frame_default_init_reg; - return ops; -} - /* Set the architecture-specific register state initialization function for GDBARCH to INIT_REG. */ @@ -658,8 +662,7 @@ dwarf2_frame_set_init_reg (struct gdbarch *gdbarch, struct dwarf2_frame_state_reg *, struct frame_info *)) { - struct dwarf2_frame_ops *ops - = (struct dwarf2_frame_ops *) gdbarch_data (gdbarch, dwarf2_frame_data); + struct dwarf2_frame_ops *ops = get_frame_ops (gdbarch); ops->init_reg = init_reg; } @@ -671,8 +674,7 @@ dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum, struct dwarf2_frame_state_reg *reg, struct frame_info *this_frame) { - struct dwarf2_frame_ops *ops - = (struct dwarf2_frame_ops *) gdbarch_data (gdbarch, dwarf2_frame_data); + struct dwarf2_frame_ops *ops = get_frame_ops (gdbarch); ops->init_reg (gdbarch, regnum, reg, this_frame); } @@ -685,8 +687,7 @@ dwarf2_frame_set_signal_frame_p (struct gdbarch *gdbarch, int (*signal_frame_p) (struct gdbarch *, struct frame_info *)) { - struct dwarf2_frame_ops *ops - = (struct dwarf2_frame_ops *) gdbarch_data (gdbarch, dwarf2_frame_data); + struct dwarf2_frame_ops *ops = get_frame_ops (gdbarch); ops->signal_frame_p = signal_frame_p; } @@ -698,8 +699,7 @@ static int dwarf2_frame_signal_frame_p (struct gdbarch *gdbarch, struct frame_info *this_frame) { - struct dwarf2_frame_ops *ops - = (struct dwarf2_frame_ops *) gdbarch_data (gdbarch, dwarf2_frame_data); + struct dwarf2_frame_ops *ops = get_frame_ops (gdbarch); if (ops->signal_frame_p == NULL) return 0; @@ -714,8 +714,7 @@ dwarf2_frame_set_adjust_regnum (struct gdbarch *gdbarch, int (*adjust_regnum) (struct gdbarch *, int, int)) { - struct dwarf2_frame_ops *ops - = (struct dwarf2_frame_ops *) gdbarch_data (gdbarch, dwarf2_frame_data); + struct dwarf2_frame_ops *ops = get_frame_ops (gdbarch); ops->adjust_regnum = adjust_regnum; } @@ -727,8 +726,7 @@ static int dwarf2_frame_adjust_regnum (struct gdbarch *gdbarch, int regnum, int eh_frame_p) { - struct dwarf2_frame_ops *ops - = (struct dwarf2_frame_ops *) gdbarch_data (gdbarch, dwarf2_frame_data); + struct dwarf2_frame_ops *ops = get_frame_ops (gdbarch); if (ops->adjust_regnum == NULL) return regnum; @@ -2201,8 +2199,6 @@ void _initialize_dwarf2_frame (); void _initialize_dwarf2_frame () { - dwarf2_frame_data = gdbarch_data_register_pre_init (dwarf2_frame_init); - add_setshow_boolean_cmd ("unwinders", class_obscure, &dwarf2_frame_unwinders_enabled_p , _("\ Set whether the DWARF stack frame unwinders are used."), _("\ |