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/regcache.c | |
parent | 8b1540430107b0752485ab9e6a841dbbacd45681 (diff) | |
download | fsf-binutils-gdb-cb275538dbddfbb3c2c372a665ac48e6f617ea33.zip fsf-binutils-gdb-cb275538dbddfbb3c2c372a665ac48e6f617ea33.tar.gz fsf-binutils-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/regcache.c')
-rw-r--r-- | gdb/regcache.c | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/gdb/regcache.c b/gdb/regcache.c index 6fd4f86..a22a839 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -41,19 +41,17 @@ /* Per-architecture object describing the layout of a register cache. Computed once when the architecture is created. */ -static struct gdbarch_data *regcache_descr_handle; - struct regcache_descr { /* The architecture this descriptor belongs to. */ - struct gdbarch *gdbarch; + struct gdbarch *gdbarch = nullptr; /* The raw register cache. Each raw (or hard) register is supplied by the target interface. The raw cache should not contain redundant information - if the PC is constructed from two registers then those registers and not the PC lives in the raw cache. */ - long sizeof_raw_registers; + long sizeof_raw_registers = 0; /* The cooked register space. Each cooked register in the range [0..NR_RAW_REGISTERS) is direct-mapped onto the corresponding raw @@ -61,21 +59,24 @@ struct regcache_descr .. NR_COOKED_REGISTERS) (a.k.a. pseudo registers) are mapped onto both raw registers and memory by the architecture methods gdbarch_pseudo_register_read and gdbarch_pseudo_register_write. */ - int nr_cooked_registers; - long sizeof_cooked_registers; + int nr_cooked_registers = 0; + long sizeof_cooked_registers = 0; /* Offset and size (in 8 bit bytes), of each register in the register cache. All registers (including those in the range [NR_RAW_REGISTERS .. NR_COOKED_REGISTERS) are given an offset. */ - long *register_offset; - long *sizeof_register; + long *register_offset = nullptr; + long *sizeof_register = nullptr; /* Cached table containing the type of each register. */ - struct type **register_type; + struct type **register_type = nullptr; }; -static void * +static const registry<gdbarch>::key<struct regcache_descr> + regcache_descr_handle; + +static struct regcache_descr * init_regcache_descr (struct gdbarch *gdbarch) { int i; @@ -83,7 +84,7 @@ init_regcache_descr (struct gdbarch *gdbarch) gdb_assert (gdbarch != NULL); /* Create an initial, zero filled, table. */ - descr = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct regcache_descr); + descr = new struct regcache_descr; descr->gdbarch = gdbarch; /* Total size of the register space. The raw registers are mapped @@ -140,8 +141,14 @@ init_regcache_descr (struct gdbarch *gdbarch) static struct regcache_descr * regcache_descr (struct gdbarch *gdbarch) { - return (struct regcache_descr *) gdbarch_data (gdbarch, - regcache_descr_handle); + struct regcache_descr *result = regcache_descr_handle.get (gdbarch); + if (result == nullptr) + { + result = init_regcache_descr (gdbarch); + regcache_descr_handle.set (gdbarch, result); + } + + return result; } /* Utility functions returning useful register attributes stored in @@ -2119,9 +2126,6 @@ _initialize_regcache () { struct cmd_list_element *c; - regcache_descr_handle - = gdbarch_data_register_post_init (init_regcache_descr); - gdb::observers::target_changed.attach (regcache_observer_target_changed, "regcache"); gdb::observers::thread_ptid_changed.attach (regcache_thread_ptid_changed, |