From: Andrew Burgess Date: Thu, 31 Mar 2022 09:10:54 +0000 (+0100) Subject: gdb: always add the default register groups X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e7d69e72bfd16113a6bbbebfb8a92126245a4106;p=binutils-gdb.git 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. --- diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index cdeeece83c0..98eaeaf8ca4 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -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 (); diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c index d6da2886c49..98bd1c4bc0a 100644 --- a/gdb/arc-tdep.c +++ b/gdb/arc-tdep.c @@ -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); diff --git a/gdb/csky-tdep.c b/gdb/csky-tdep.c index f1376730c87..feb416a2406 100644 --- a/gdb/csky-tdep.c +++ b/gdb/csky-tdep.c @@ -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); diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c index 400ccd6bebf..99a81b98da1 100644 --- a/gdb/i386-tdep.c +++ b/gdb/i386-tdep.c @@ -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 diff --git a/gdb/lm32-tdep.c b/gdb/lm32-tdep.c index f3f1f87d6bb..4a781c394e9 100644 --- a/gdb/lm32-tdep.c +++ b/gdb/lm32-tdep.c @@ -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; diff --git a/gdb/m32c-tdep.c b/gdb/m32c-tdep.c index 94087302892..5a767c9ed52 100644 --- a/gdb/m32c-tdep.c +++ b/gdb/m32c-tdep.c @@ -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); } diff --git a/gdb/m68hc11-tdep.c b/gdb/m68hc11-tdep.c index f1133fe6780..9d978d88018 100644 --- a/gdb/m68hc11-tdep.c +++ b/gdb/m68hc11-tdep.c @@ -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 diff --git a/gdb/mep-tdep.c b/gdb/mep-tdep.c index 8f2f0a3b30d..1ab01c6cbb3 100644 --- a/gdb/mep-tdep.c +++ b/gdb/mep-tdep.c @@ -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); diff --git a/gdb/nds32-tdep.c b/gdb/nds32-tdep.c index 425d7d90d64..a94a03ab2ab 100644 --- a/gdb/nds32-tdep.c +++ b/gdb/nds32-tdep.c @@ -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); diff --git a/gdb/or1k-tdep.c b/gdb/or1k-tdep.c index 9f7fa2f169f..2b906fa69d3 100644 --- a/gdb/or1k-tdep.c +++ b/gdb/or1k-tdep.c @@ -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)); - } + tdesc_use_registers (gdbarch, tdesc, std::move (tdesc_data)); /* Hook in ABI-specific overrides, if they have been registered. */ gdbarch_init_osabi (info, gdbarch); diff --git a/gdb/reggroups.c b/gdb/reggroups.c index 6c38ca743f4..74b981fb5e9 100644 --- a/gdb/reggroups.c +++ b/gdb/reggroups.c @@ -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\ diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c index 8713652b099..79b81351039 100644 --- a/gdb/riscv-tdep.c +++ b/gdb/riscv-tdep.c @@ -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); } diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c index 62be13643b2..6e478ee893d 100644 --- a/gdb/xtensa-tdep.c +++ b/gdb/xtensa-tdep.c @@ -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]); }