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/user-regs.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/user-regs.c')
-rw-r--r-- | gdb/user-regs.c | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/gdb/user-regs.c b/gdb/user-regs.c index 8f1c6e6..4bc4685 100644 --- a/gdb/user-regs.c +++ b/gdb/user-regs.c @@ -57,8 +57,8 @@ struct user_reg struct gdb_user_regs { - struct user_reg *first; - struct user_reg **last; + struct user_reg *first = nullptr; + struct user_reg **last = nullptr; }; static void @@ -95,18 +95,26 @@ user_reg_add_builtin (const char *name, user_reg_read_ftype *xread, /* Per-architecture user registers. Start with the builtin user registers and then, again, append. */ -static struct gdbarch_data *user_regs_data; +static const registry<gdbarch>::key<gdb_user_regs> user_regs_data; -static void * -user_regs_init (struct obstack *obstack) +static gdb_user_regs * +get_user_regs (struct gdbarch *gdbarch) { - struct user_reg *reg; - struct gdb_user_regs *regs = OBSTACK_ZALLOC (obstack, struct gdb_user_regs); + struct gdb_user_regs *regs = user_regs_data.get (gdbarch); + if (regs == nullptr) + { + regs = new struct gdb_user_regs; + + struct obstack *obstack = gdbarch_obstack (gdbarch); + regs->last = ®s->first; + for (user_reg *reg = builtin_user_regs.first; + reg != NULL; + reg = reg->next) + append_user_reg (regs, reg->name, reg->xread, reg->baton, + OBSTACK_ZALLOC (obstack, struct user_reg)); + user_regs_data.set (gdbarch, regs); + } - regs->last = ®s->first; - for (reg = builtin_user_regs.first; reg != NULL; reg = reg->next) - append_user_reg (regs, reg->name, reg->xread, reg->baton, - OBSTACK_ZALLOC (obstack, struct user_reg)); return regs; } @@ -114,8 +122,7 @@ void user_reg_add (struct gdbarch *gdbarch, const char *name, user_reg_read_ftype *xread, const void *baton) { - struct gdb_user_regs *regs - = (struct gdb_user_regs *) gdbarch_data (gdbarch, user_regs_data); + struct gdb_user_regs *regs = get_user_regs (gdbarch); gdb_assert (regs != NULL); append_user_reg (regs, name, xread, baton, GDBARCH_OBSTACK_ZALLOC (gdbarch, struct user_reg)); @@ -149,8 +156,7 @@ user_reg_map_name_to_regnum (struct gdbarch *gdbarch, const char *name, /* Search the user name space. */ { - struct gdb_user_regs *regs - = (struct gdb_user_regs *) gdbarch_data (gdbarch, user_regs_data); + struct gdb_user_regs *regs = get_user_regs (gdbarch); struct user_reg *reg; int nr; @@ -169,8 +175,7 @@ user_reg_map_name_to_regnum (struct gdbarch *gdbarch, const char *name, static struct user_reg * usernum_to_user_reg (struct gdbarch *gdbarch, int usernum) { - struct gdb_user_regs *regs - = (struct gdb_user_regs *) gdbarch_data (gdbarch, user_regs_data); + struct gdb_user_regs *regs = get_user_regs (gdbarch); struct user_reg *reg; for (reg = regs->first; reg != NULL; reg = reg->next) @@ -216,11 +221,10 @@ static void maintenance_print_user_registers (const char *args, int from_tty) { struct gdbarch *gdbarch = get_current_arch (); - struct gdb_user_regs *regs; struct user_reg *reg; int regnum; - regs = (struct gdb_user_regs *) gdbarch_data (gdbarch, user_regs_data); + struct gdb_user_regs *regs = get_user_regs (gdbarch); regnum = gdbarch_num_cooked_regs (gdbarch); gdb_printf (" %-11s %3s\n", "Name", "Nr"); @@ -232,8 +236,6 @@ void _initialize_user_regs (); void _initialize_user_regs () { - user_regs_data = gdbarch_data_register_pre_init (user_regs_init); - add_cmd ("user-registers", class_maintenance, maintenance_print_user_registers, _("List the names of the current user registers."), |