gdb: always add the default register groups

There's a set of 7 default register groups.  If we don't add any
gdbarch specific register groups during gdbarch initialisation, then
when we iterate over the register groups using reggroup_next and
reggroup_prev we will make use of these 7 default groups.  See the use
of default_groups in gdb/reggroups.c for details on this.

However, if the gdbarch adds its own groups during gdbarch
initialisation, then these groups will be used in preference to the
default groups.

A problem arises though if the particular architecture makes use of
the target description mechanism.  If the default target
description(s) (i.e. those internal to GDB that are used when the user
doesn't provide their own) don't mention any additional register
groups then the default register groups will be used.

But if the target description does mention additional groups then the
default groups are not used, and instead, the groups from the target
description are used.

The problem with this is that what usually happens is that the target
description will mention additional groups, e.g. groups for special
registers.  Most architectures that use target descriptions work
around this by adding all (or most) of the default register groups in
all cases.  See i386_add_reggroups, aarch64_add_reggroups,
riscv_add_reggroups, xtensa_add_reggroups, and others.

In this patch, my suggestion is that we should just add the default
register groups for every architecture, always.  This change is in
gdb/reggroups.c.

All the remaining changes are me updating the various architectures to
not add the default groups themselves.

So, where will this change be visible to the user?  I think the
following commands will possibly change:

* info registers / info all-registers:

  The user can provide a register group to these commands.  For example,
  on csky, we previously never added the 'vector' group.  Now, as a
  default group, this will be available, but (presumably) will not
  contain any registers.  I don't think this is necessarily a bad
  thing, there's something to be said for having some consistent
  defaults available.  There are other architectures that didn't add
  all 7 of the defaults, which will now have gained additional groups.

* maint print reggroups

  This prints the set of all available groups.  As a maintenance
  command I'm less concerned with the output changing here.
  Obviously, for the architectures that didn't previously add all the
  defaults, this list just got bigger.

* maint print register-groups

  This prints all the registers, and the groups they are in.  If the
  defaults were not previously being added then a register (obviously)
  can't appear in one of the default groups.  Now the groups are
  available then registers might be in more groups than previously.
  However, this is again a maintenance command, so I'm less concerned
  about this changing.
This commit is contained in:
Andrew Burgess 2022-03-31 10:10:54 +01:00
parent 07c316ecaa
commit e7d69e72bf
13 changed files with 36 additions and 138 deletions

View File

@ -3367,20 +3367,6 @@ aarch64_get_tdesc_vq (const struct target_desc *tdesc)
return sve_vq_from_vl (vl);
}
/* Add all the expected register sets into GDBARCH. */
static void
aarch64_add_reggroups (struct gdbarch *gdbarch)
{
reggroup_add (gdbarch, general_reggroup);
reggroup_add (gdbarch, float_reggroup);
reggroup_add (gdbarch, system_reggroup);
reggroup_add (gdbarch, vector_reggroup);
reggroup_add (gdbarch, all_reggroup);
reggroup_add (gdbarch, save_reggroup);
reggroup_add (gdbarch, restore_reggroup);
}
/* Implement the "cannot_store_register" gdbarch method. */
static int
@ -3636,9 +3622,6 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
/* Virtual tables. */
set_gdbarch_vbit_in_delta (gdbarch, 1);
/* Register architecture. */
aarch64_add_reggroups (gdbarch);
/* Hook in the ABI-specific overrides, if they have been registered. */
info.target_desc = tdesc;
info.tdesc_data = tdesc_data.get ();

View File

@ -1952,20 +1952,6 @@ static const struct frame_base arc_normal_base = {
arc_frame_base_address
};
/* Add all the expected register sets into GDBARCH. */
static void
arc_add_reggroups (struct gdbarch *gdbarch)
{
reggroup_add (gdbarch, general_reggroup);
reggroup_add (gdbarch, float_reggroup);
reggroup_add (gdbarch, system_reggroup);
reggroup_add (gdbarch, vector_reggroup);
reggroup_add (gdbarch, all_reggroup);
reggroup_add (gdbarch, save_reggroup);
reggroup_add (gdbarch, restore_reggroup);
}
static enum arc_isa
mach_type_to_arc_isa (const unsigned long mach)
{
@ -2364,9 +2350,6 @@ arc_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
/* This doesn't include possible long-immediate value. */
set_gdbarch_max_insn_length (gdbarch, 4);
/* Add default register groups. */
arc_add_reggroups (gdbarch);
/* Frame unwinders and sniffers. */
dwarf2_frame_set_init_reg (gdbarch, arc_dwarf2_frame_init_reg);
dwarf2_append_unwinders (gdbarch);

View File

@ -2050,8 +2050,6 @@ csky_init_reggroup ()
static void
csky_add_reggroups (struct gdbarch *gdbarch)
{
reggroup_add (gdbarch, all_reggroup);
reggroup_add (gdbarch, general_reggroup);
reggroup_add (gdbarch, cr_reggroup);
reggroup_add (gdbarch, fr_reggroup);
reggroup_add (gdbarch, vr_reggroup);

View File

@ -4546,13 +4546,6 @@ i386_add_reggroups (struct gdbarch *gdbarch)
{
reggroup_add (gdbarch, i386_sse_reggroup);
reggroup_add (gdbarch, i386_mmx_reggroup);
reggroup_add (gdbarch, general_reggroup);
reggroup_add (gdbarch, float_reggroup);
reggroup_add (gdbarch, all_reggroup);
reggroup_add (gdbarch, save_reggroup);
reggroup_add (gdbarch, restore_reggroup);
reggroup_add (gdbarch, vector_reggroup);
reggroup_add (gdbarch, system_reggroup);
}
int

View File

@ -59,16 +59,6 @@ struct lm32_frame_cache
trad_frame_saved_reg *saved_regs;
};
/* Add the available register groups. */
static void
lm32_add_reggroups (struct gdbarch *gdbarch)
{
reggroup_add (gdbarch, general_reggroup);
reggroup_add (gdbarch, all_reggroup);
reggroup_add (gdbarch, system_reggroup);
}
/* Return whether a given register is in a given group. */
static int
@ -540,7 +530,6 @@ lm32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
set_gdbarch_push_dummy_call (gdbarch, lm32_push_dummy_call);
set_gdbarch_return_value (gdbarch, lm32_return_value);
lm32_add_reggroups (gdbarch);
set_gdbarch_register_reggroup_p (gdbarch, lm32_register_reggroup_p);
return gdbarch;

View File

@ -981,11 +981,6 @@ make_regs (struct gdbarch *arch)
set_gdbarch_dwarf2_reg_to_regnum (arch, m32c_debug_info_reg_to_regnum);
set_gdbarch_register_reggroup_p (arch, m32c_register_reggroup_p);
reggroup_add (arch, general_reggroup);
reggroup_add (arch, all_reggroup);
reggroup_add (arch, save_reggroup);
reggroup_add (arch, restore_reggroup);
reggroup_add (arch, system_reggroup);
reggroup_add (arch, m32c_dma_reggroup);
}

View File

@ -1361,13 +1361,6 @@ m68hc11_add_reggroups (struct gdbarch *gdbarch)
{
reggroup_add (gdbarch, m68hc11_hard_reggroup);
reggroup_add (gdbarch, m68hc11_soft_reggroup);
reggroup_add (gdbarch, general_reggroup);
reggroup_add (gdbarch, float_reggroup);
reggroup_add (gdbarch, all_reggroup);
reggroup_add (gdbarch, save_reggroup);
reggroup_add (gdbarch, restore_reggroup);
reggroup_add (gdbarch, vector_reggroup);
reggroup_add (gdbarch, system_reggroup);
}
static int

View File

@ -2427,10 +2427,6 @@ mep_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
set_gdbarch_stab_reg_to_regnum (gdbarch, mep_debug_reg_to_regnum);
set_gdbarch_register_reggroup_p (gdbarch, mep_register_reggroup_p);
reggroup_add (gdbarch, all_reggroup);
reggroup_add (gdbarch, general_reggroup);
reggroup_add (gdbarch, save_reggroup);
reggroup_add (gdbarch, restore_reggroup);
reggroup_add (gdbarch, mep_csr_reggroup);
reggroup_add (gdbarch, mep_cr_reggroup);
reggroup_add (gdbarch, mep_ccr_reggroup);

View File

@ -343,14 +343,6 @@ nds32_init_reggroups (void)
static void
nds32_add_reggroups (struct gdbarch *gdbarch)
{
/* Add pre-defined register groups. */
reggroup_add (gdbarch, general_reggroup);
reggroup_add (gdbarch, float_reggroup);
reggroup_add (gdbarch, system_reggroup);
reggroup_add (gdbarch, all_reggroup);
reggroup_add (gdbarch, save_reggroup);
reggroup_add (gdbarch, restore_reggroup);
/* Add NDS32 register groups. */
reggroup_add (gdbarch, nds32_cr_reggroup);
reggroup_add (gdbarch, nds32_ir_reggroup);

View File

@ -1260,19 +1260,7 @@ or1k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
}
if (tdesc_data != NULL)
{
/* If we are using tdesc, register our own reggroups, otherwise we
will used the defaults. */
reggroup_add (gdbarch, general_reggroup);
reggroup_add (gdbarch, system_reggroup);
reggroup_add (gdbarch, float_reggroup);
reggroup_add (gdbarch, vector_reggroup);
reggroup_add (gdbarch, all_reggroup);
reggroup_add (gdbarch, save_reggroup);
reggroup_add (gdbarch, restore_reggroup);
tdesc_use_registers (gdbarch, tdesc, std::move (tdesc_data));
}
/* Hook in ABI-specific overrides, if they have been registered. */
gdbarch_init_osabi (info, gdbarch);

View File

@ -90,15 +90,6 @@ struct reggroups
static struct gdbarch_data *reggroups_data;
static void *
reggroups_init (struct obstack *obstack)
{
struct reggroups *groups = OBSTACK_ZALLOC (obstack, struct reggroups);
groups->last = &groups->first;
return groups;
}
/* Add a register group (with attribute values) to the pre-defined
list. */
@ -119,13 +110,42 @@ reggroup_add (struct gdbarch *gdbarch, struct reggroup *group)
struct reggroups *groups
= (struct reggroups *) gdbarch_data (gdbarch, reggroups_data);
/* The same reggroup should not be added multiple times. */
gdb_assert (groups != nullptr);
for (struct reggroup_el *el = groups->first; el != nullptr; el = el->next)
gdb_assert (group != el->group);
add_group (groups, group,
GDBARCH_OBSTACK_ZALLOC (gdbarch, struct reggroup_el));
}
/* The default register groups for an architecture. */
/* Called to initialize the per-gdbarch register group information. */
static struct reggroups default_groups = { NULL, &default_groups.first };
static void *
reggroups_init (struct obstack *obstack)
{
struct reggroups *groups = OBSTACK_ZALLOC (obstack, struct reggroups);
groups->last = &groups->first;
/* Add the default groups. */
add_group (groups, general_reggroup,
OBSTACK_ZALLOC (obstack, struct reggroup_el));
add_group (groups, float_reggroup,
OBSTACK_ZALLOC (obstack, struct reggroup_el));
add_group (groups, system_reggroup,
OBSTACK_ZALLOC (obstack, struct reggroup_el));
add_group (groups, vector_reggroup,
OBSTACK_ZALLOC (obstack, struct reggroup_el));
add_group (groups, all_reggroup,
OBSTACK_ZALLOC (obstack, struct reggroup_el));
add_group (groups, save_reggroup,
OBSTACK_ZALLOC (obstack, struct reggroup_el));
add_group (groups, restore_reggroup,
OBSTACK_ZALLOC (obstack, struct reggroup_el));
return groups;
}
/* A register group iterator. */
@ -139,8 +159,7 @@ reggroup_next (struct gdbarch *gdbarch, const struct reggroup *last)
creation. If there are no groups, use the default groups list. */
groups = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data);
gdb_assert (groups != NULL);
if (groups->first == NULL)
groups = &default_groups;
gdb_assert (groups->first != NULL);
/* Return the first/next reggroup. */
if (last == NULL)
@ -171,8 +190,7 @@ reggroup_prev (struct gdbarch *gdbarch, const struct reggroup *curr)
creation. If there are no groups, use the default groups list. */
groups = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data);
gdb_assert (groups != NULL);
if (groups->first == NULL)
groups = &default_groups;
gdb_assert (groups->first != NULL);
prev = NULL;
for (el = groups->first; el != NULL; el = el->next)
@ -327,15 +345,6 @@ _initialize_reggroup ()
{
reggroups_data = gdbarch_data_register_pre_init (reggroups_init);
/* The pre-defined list of groups. */
add_group (&default_groups, general_reggroup, XNEW (struct reggroup_el));
add_group (&default_groups, float_reggroup, XNEW (struct reggroup_el));
add_group (&default_groups, system_reggroup, XNEW (struct reggroup_el));
add_group (&default_groups, vector_reggroup, XNEW (struct reggroup_el));
add_group (&default_groups, all_reggroup, XNEW (struct reggroup_el));
add_group (&default_groups, save_reggroup, XNEW (struct reggroup_el));
add_group (&default_groups, restore_reggroup, XNEW (struct reggroup_el));
add_cmd ("reggroups", class_maintenance,
maintenance_print_reggroups, _("\
Print the internal register group names.\n\

View File

@ -3497,21 +3497,11 @@ riscv_find_default_target_description (const struct gdbarch_info info)
return riscv_lookup_target_description (features);
}
/* Add all the expected register sets into GDBARCH. */
/* Add all the RISC-V specific register groups into GDBARCH. */
static void
riscv_add_reggroups (struct gdbarch *gdbarch)
{
/* Add predefined register groups. */
reggroup_add (gdbarch, all_reggroup);
reggroup_add (gdbarch, save_reggroup);
reggroup_add (gdbarch, restore_reggroup);
reggroup_add (gdbarch, system_reggroup);
reggroup_add (gdbarch, vector_reggroup);
reggroup_add (gdbarch, general_reggroup);
reggroup_add (gdbarch, float_reggroup);
/* Add RISC-V specific register groups. */
reggroup_add (gdbarch, csr_reggroup);
}

View File

@ -734,23 +734,12 @@ xtensa_init_reggroups (void)
static void
xtensa_add_reggroups (struct gdbarch *gdbarch)
{
int i;
/* Predefined groups. */
reggroup_add (gdbarch, all_reggroup);
reggroup_add (gdbarch, save_reggroup);
reggroup_add (gdbarch, restore_reggroup);
reggroup_add (gdbarch, system_reggroup);
reggroup_add (gdbarch, vector_reggroup);
reggroup_add (gdbarch, general_reggroup);
reggroup_add (gdbarch, float_reggroup);
/* Xtensa-specific groups. */
reggroup_add (gdbarch, xtensa_ar_reggroup);
reggroup_add (gdbarch, xtensa_user_reggroup);
reggroup_add (gdbarch, xtensa_vectra_reggroup);
for (i = 0; i < XTENSA_MAX_COPROCESSOR; i++)
for (int i = 0; i < XTENSA_MAX_COPROCESSOR; i++)
reggroup_add (gdbarch, xtensa_cp[i]);
}