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/solib-svr4.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/solib-svr4.c')
-rw-r--r-- | gdb/solib-svr4.c | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index 6f8680f..95a1e1e 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -2995,24 +2995,23 @@ svr4_relocate_section_addresses (struct so_list *so, /* Architecture-specific operations. */ -/* Per-architecture data key. */ -static struct gdbarch_data *solib_svr4_data; - struct solib_svr4_ops { /* Return a description of the layout of `struct link_map'. */ - struct link_map_offsets *(*fetch_link_map_offsets)(void); + struct link_map_offsets *(*fetch_link_map_offsets)(void) = nullptr; }; +/* Per-architecture data key. */ +static const registry<gdbarch>::key<struct solib_svr4_ops> solib_svr4_data; + /* Return a default for the architecture-specific operations. */ -static void * -solib_svr4_init (struct obstack *obstack) +static struct solib_svr4_ops * +get_ops (struct gdbarch *gdbarch) { - struct solib_svr4_ops *ops; - - ops = OBSTACK_ZALLOC (obstack, struct solib_svr4_ops); - ops->fetch_link_map_offsets = NULL; + struct solib_svr4_ops *ops = solib_svr4_data.get (gdbarch); + if (ops == nullptr) + ops = solib_svr4_data.emplace (gdbarch); return ops; } @@ -3023,8 +3022,7 @@ void set_solib_svr4_fetch_link_map_offsets (struct gdbarch *gdbarch, struct link_map_offsets *(*flmo) (void)) { - struct solib_svr4_ops *ops - = (struct solib_svr4_ops *) gdbarch_data (gdbarch, solib_svr4_data); + struct solib_svr4_ops *ops = get_ops (gdbarch); ops->fetch_link_map_offsets = flmo; @@ -3039,9 +3037,7 @@ set_solib_svr4_fetch_link_map_offsets (struct gdbarch *gdbarch, static struct link_map_offsets * svr4_fetch_link_map_offsets (void) { - struct solib_svr4_ops *ops - = (struct solib_svr4_ops *) gdbarch_data (target_gdbarch (), - solib_svr4_data); + struct solib_svr4_ops *ops = get_ops (target_gdbarch ()); gdb_assert (ops->fetch_link_map_offsets); return ops->fetch_link_map_offsets (); @@ -3052,9 +3048,7 @@ svr4_fetch_link_map_offsets (void) static int svr4_have_link_map_offsets (void) { - struct solib_svr4_ops *ops - = (struct solib_svr4_ops *) gdbarch_data (target_gdbarch (), - solib_svr4_data); + struct solib_svr4_ops *ops = get_ops (target_gdbarch ()); return (ops->fetch_link_map_offsets != NULL); } @@ -3173,8 +3167,6 @@ void _initialize_svr4_solib (); void _initialize_svr4_solib () { - solib_svr4_data = gdbarch_data_register_pre_init (solib_svr4_init); - svr4_so_ops.relocate_section_addresses = svr4_relocate_section_addresses; svr4_so_ops.free_so = svr4_free_so; svr4_so_ops.clear_so = svr4_clear_so; |