aboutsummaryrefslogtreecommitdiff
path: root/gdb/reggroups.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2022-06-01 15:31:15 -0600
committerTom Tromey <tom@tromey.com>2022-08-04 13:28:04 -0600
commitcb275538dbddfbb3c2c372a665ac48e6f617ea33 (patch)
tree7bc54ff4fc92c9b1cee74c2d7b9ae452b5ffec8b /gdb/reggroups.c
parent8b1540430107b0752485ab9e6a841dbbacd45681 (diff)
downloadfsf-binutils-gdb-cb275538dbddfbb3c2c372a665ac48e6f617ea33.zip
fsf-binutils-gdb-cb275538dbddfbb3c2c372a665ac48e6f617ea33.tar.gz
fsf-binutils-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/reggroups.c')
-rw-r--r--gdb/reggroups.c54
1 files changed, 28 insertions, 26 deletions
diff --git a/gdb/reggroups.c b/gdb/reggroups.c
index 1a13cb2..b81031b 100644
--- a/gdb/reggroups.c
+++ b/gdb/reggroups.c
@@ -52,6 +52,20 @@ reggroup_gdbarch_new (struct gdbarch *gdbarch, const char *name,
struct reggroups
{
+ reggroups ()
+ {
+ /* Add the default groups. */
+ add (general_reggroup);
+ add (float_reggroup);
+ add (system_reggroup);
+ add (vector_reggroup);
+ add (all_reggroup);
+ add (save_reggroup);
+ add (restore_reggroup);
+ }
+
+ DISABLE_COPY_AND_ASSIGN (reggroups);
+
/* Add GROUP to the list of register groups. */
void add (const reggroup *group)
@@ -86,15 +100,25 @@ private:
/* Key used to lookup register group data from a gdbarch. */
-static struct gdbarch_data *reggroups_data;
+static const registry<gdbarch>::key<reggroups> reggroups_data;
+
+/* Get the reggroups for the architecture, creating if necessary. */
+
+static reggroups *
+get_reggroups (struct gdbarch *gdbarch)
+{
+ struct reggroups *groups = reggroups_data.get (gdbarch);
+ if (groups == nullptr)
+ groups = reggroups_data.emplace (gdbarch);
+ return groups;
+}
/* See reggroups.h. */
void
reggroup_add (struct gdbarch *gdbarch, const reggroup *group)
{
- struct reggroups *groups
- = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data);
+ struct reggroups *groups = get_reggroups (gdbarch);
gdb_assert (groups != nullptr);
gdb_assert (group != nullptr);
@@ -102,31 +126,11 @@ reggroup_add (struct gdbarch *gdbarch, const reggroup *group)
groups->add (group);
}
-/* Called to initialize the per-gdbarch register group information. */
-
-static void *
-reggroups_init (struct obstack *obstack)
-{
- struct reggroups *groups = obstack_new<struct reggroups> (obstack);
-
- /* Add the default groups. */
- groups->add (general_reggroup);
- groups->add (float_reggroup);
- groups->add (system_reggroup);
- groups->add (vector_reggroup);
- groups->add (all_reggroup);
- groups->add (save_reggroup);
- groups->add (restore_reggroup);
-
- return groups;
-}
-
/* See reggroups.h. */
const std::vector<const reggroup *> &
gdbarch_reggroups (struct gdbarch *gdbarch)
{
- struct reggroups *groups
- = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data);
+ struct reggroups *groups = get_reggroups (gdbarch);
gdb_assert (groups != nullptr);
gdb_assert (groups->size () > 0);
return groups->groups ();
@@ -252,8 +256,6 @@ void _initialize_reggroup ();
void
_initialize_reggroup ()
{
- reggroups_data = gdbarch_data_register_pre_init (reggroups_init);
-
add_cmd ("reggroups", class_maintenance,
maintenance_print_reggroups, _("\
Print the internal register group names.\n\