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/guile/scm-symbol.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/guile/scm-symbol.c')
-rw-r--r-- | gdb/guile/scm-symbol.c | 34 |
1 files changed, 10 insertions, 24 deletions
diff --git a/gdb/guile/scm-symbol.c b/gdb/guile/scm-symbol.c index 78917bd..4344a63 100644 --- a/gdb/guile/scm-symbol.c +++ b/gdb/guile/scm-symbol.c @@ -78,13 +78,14 @@ struct syscm_deleter static const registry<objfile>::key<htab, syscm_deleter> syscm_objfile_data_key; -static struct gdbarch_data *syscm_gdbarch_data_key; struct syscm_gdbarch_data { /* Hash table to implement eqable gdbarch symbols. */ htab_t htab; }; + +static const registry<gdbarch>::key<syscm_gdbarch_data> syscm_gdbarch_data_key; /* Administrivia for symbol smobs. */ @@ -110,17 +111,6 @@ syscm_eq_symbol_smob (const void *ap, const void *bp) && a->symbol != NULL); } -static void * -syscm_init_arch_symbols (struct gdbarch *gdbarch) -{ - struct syscm_gdbarch_data *data - = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct syscm_gdbarch_data); - - data->htab = gdbscm_create_eqable_gsmob_ptr_map (syscm_hash_symbol_smob, - syscm_eq_symbol_smob); - return data; -} - /* Return the struct symbol pointer -> SCM mapping table. It is created if necessary. */ @@ -144,9 +134,14 @@ syscm_get_symbol_map (struct symbol *symbol) else { struct gdbarch *gdbarch = symbol->arch (); - struct syscm_gdbarch_data *data - = (struct syscm_gdbarch_data *) gdbarch_data (gdbarch, - syscm_gdbarch_data_key); + struct syscm_gdbarch_data *data = syscm_gdbarch_data_key.get (gdbarch); + if (data == nullptr) + { + data = syscm_gdbarch_data_key.emplace (gdbarch); + data->htab + = gdbscm_create_eqable_gsmob_ptr_map (syscm_hash_symbol_smob, + syscm_eq_symbol_smob); + } htab = data->htab; } @@ -817,12 +812,3 @@ gdbscm_initialize_symbols (void) domain_keyword = scm_from_latin1_keyword ("domain"); frame_keyword = scm_from_latin1_keyword ("frame"); } - -void _initialize_scm_symbol (); -void -_initialize_scm_symbol () -{ - /* Arch-specific symbol data. */ - syscm_gdbarch_data_key - = gdbarch_data_register_post_init (syscm_init_arch_symbols); -} |