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.
This commit is contained in:
Tom Tromey
2022-06-01 15:31:15 -06:00
parent 8b15404301
commit cb275538db
41 changed files with 533 additions and 837 deletions

View File

@@ -41,7 +41,10 @@ static const char arch_smob_name[] = "gdb:arch";
/* The tag Guile knows the arch smob by. */
static scm_t_bits arch_smob_tag;
static struct gdbarch_data *arch_object_data = NULL;
/* Use a 'void *' here because it isn't guaranteed that SCM is a
pointer. */
static const registry<gdbarch>::key<void, gdb::noop_deleter<void>>
arch_object_data;
static int arscm_is_arch (SCM);
@@ -105,30 +108,28 @@ gdbscm_arch_p (SCM scm)
return scm_from_bool (arscm_is_arch (scm));
}
/* Associates an arch_object with GDBARCH as gdbarch_data via the gdbarch
post init registration mechanism (gdbarch_data_register_post_init). */
static void *
arscm_object_data_init (struct gdbarch *gdbarch)
{
SCM arch_scm = arscm_make_arch_smob (gdbarch);
/* This object lasts the duration of the GDB session, so there is no
call to scm_gc_unprotect_object for it. */
scm_gc_protect_object (arch_scm);
return (void *) arch_scm;
}
/* Return the <gdb:arch> object corresponding to GDBARCH.
The object is cached in GDBARCH so this is simple. */
SCM
arscm_scm_from_arch (struct gdbarch *gdbarch)
{
SCM a_scm = (SCM) gdbarch_data (gdbarch, arch_object_data);
SCM arch_scm;
void *data = arch_object_data.get (gdbarch);
if (data == nullptr)
{
arch_scm = arscm_make_arch_smob (gdbarch);
return a_scm;
/* This object lasts the duration of the GDB session, so there
is no call to scm_gc_unprotect_object for it. */
scm_gc_protect_object (arch_scm);
arch_object_data.set (gdbarch, (void *) arch_scm);
}
else
arch_scm = (SCM) data;
return arch_scm;
}
/* Return the <gdb:arch> smob in SELF.
@@ -651,11 +652,3 @@ gdbscm_initialize_arches (void)
gdbscm_define_functions (arch_functions, 1);
}
void _initialize_scm_arch ();
void
_initialize_scm_arch ()
{
arch_object_data
= gdbarch_data_register_post_init (arscm_object_data_init);
}

View File

@@ -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);
}