gdb: remove BLOCK_FUNCTION macro
[binutils-gdb.git] / gdb / reggroups.c
index 262bf49cea8ac8a0447a39054c8338126803bb8c..1a13cb2fba0b9fbd39cc1de939d8d089dc9da451 100644 (file)
 #include "gdbcmd.h"            /* For maintenanceprintlist.  */
 #include "gdbsupport/gdb_obstack.h"
 
-/* Individual register groups.  */
-
-struct reggroup
-{
-  const char *name;
-  enum reggroup_type type;
-};
+/* See reggroups.h.  */
 
-struct reggroup *
+const reggroup *
 reggroup_new (const char *name, enum reggroup_type type)
 {
-  struct reggroup *group = XNEW (struct reggroup);
-
-  group->name = name;
-  group->type = type;
-  return group;
+  return new reggroup (name, type);
 }
 
 /* See reggroups.h.  */
 
-struct reggroup *
+const reggroup *
 reggroup_gdbarch_new (struct gdbarch *gdbarch, const char *name,
                      enum reggroup_type type)
 {
-  struct reggroup *group = GDBARCH_OBSTACK_ZALLOC (gdbarch,
-                                                  struct reggroup);
-
-  group->name = gdbarch_obstack_strdup (gdbarch, name);
-  group->type = type;
-  return group;
-}
-
-/* Register group attributes.  */
-
-const char *
-reggroup_name (const struct reggroup *group)
-{
-  return group->name;
-}
-
-enum reggroup_type
-reggroup_type (const struct reggroup *group)
-{
-  return group->type;
+  name = gdbarch_obstack_strdup (gdbarch, name);
+  return obstack_new<struct reggroup> (gdbarch_obstack (gdbarch),
+                                      name, type);
 }
 
 /* A container holding all the register groups for a particular
@@ -81,7 +54,7 @@ struct reggroups
 {
   /* Add GROUP to the list of register groups.  */
 
-  void add (struct reggroup *group)
+  void add (const reggroup *group)
   {
     gdb_assert (group != nullptr);
     gdb_assert (std::find (m_groups.begin(), m_groups.end(), group)
@@ -100,7 +73,7 @@ struct reggroups
 
   /* Return a reference to the list of all groups.  */
 
-  const std::vector<struct reggroup *> &
+  const std::vector<const struct reggroup *> &
   groups () const
   {
     return m_groups;
@@ -108,15 +81,17 @@ struct reggroups
 
 private:
   /* The register groups.  */
-  std::vector<struct reggroup *> m_groups;
+  std::vector<const struct reggroup *> m_groups;
 };
 
+/* Key used to lookup register group data from a gdbarch.  */
+
 static struct gdbarch_data *reggroups_data;
 
-/* Add GROUP to the list of register groups for GDBARCH.  */
+/* See reggroups.h.  */
 
 void
-reggroup_add (struct gdbarch *gdbarch, struct reggroup *group)
+reggroup_add (struct gdbarch *gdbarch, const reggroup *group)
 {
   struct reggroups *groups
     = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data);
@@ -146,65 +121,19 @@ reggroups_init (struct obstack *obstack)
   return groups;
 }
 
-/* A register group iterator.  */
-
-struct reggroup *
-reggroup_next (struct gdbarch *gdbarch, const struct reggroup *last)
+/* See reggroups.h.  */
+const std::vector<const reggroup *> &
+gdbarch_reggroups (struct gdbarch *gdbarch)
 {
-  /* Don't allow this function to be called during architecture
-     creation.  If there are no groups, use the default groups list.  */
   struct reggroups *groups
     = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data);
   gdb_assert (groups != nullptr);
   gdb_assert (groups->size () > 0);
-
-  /* Return the first/next reggroup.  */
-  if (last == nullptr)
-    return groups->groups ().front ();
-  for (int i = 0; i < groups->size (); ++i)
-    {
-      if (groups->groups ()[i] == last)
-       {
-         if (i + 1 < groups->size ())
-           return groups->groups ()[i + 1];
-         else
-           return nullptr;
-       }
-    }
-
-  return nullptr;
+  return groups->groups ();
 }
 
 /* See reggroups.h.  */
 
-struct reggroup *
-reggroup_prev (struct gdbarch *gdbarch, const struct reggroup *curr)
-{
-  /* Don't allow this function to be called during architecture
-     creation.  If there are no groups, use the default groups list.  */
-  struct reggroups *groups
-    = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data);
-  gdb_assert (groups != nullptr);
-  gdb_assert (groups->size () > 0);
-
-  /* Return the first/next reggroup.  */
-  if (curr == nullptr)
-    return groups->groups ().back ();
-  for (int i = groups->size () - 1; i >= 0; --i)
-    {
-      if (groups->groups ()[i] == curr)
-       {
-         if (i - 1 >= 0)
-           return groups->groups ()[i - 1];
-         else
-           return nullptr;
-       }
-    }
-
-  return nullptr;
-}
-
-/* Is REGNUM a member of REGGROUP?  */
 int
 default_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
                             const struct reggroup *group)
@@ -239,13 +168,9 @@ default_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 const reggroup *
 reggroup_find (struct gdbarch *gdbarch, const char *name)
 {
-  struct reggroup *group;
-
-  for (group = reggroup_next (gdbarch, NULL);
-       group != NULL;
-       group = reggroup_next (gdbarch, group))
+  for (const struct reggroup *group : gdbarch_reggroups (gdbarch))
     {
-      if (strcmp (name, reggroup_name (group)) == 0)
+      if (strcmp (name, group->name ()) == 0)
        return group;
     }
   return NULL;
@@ -256,54 +181,39 @@ reggroup_find (struct gdbarch *gdbarch, const char *name)
 static void
 reggroups_dump (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  struct reggroup *group = NULL;
+  static constexpr const char *fmt = " %-10s %-10s\n";
+
+  gdb_printf (file, fmt, "Group", "Type");
 
-  do
+  for (const struct reggroup *group : gdbarch_reggroups (gdbarch))
     {
       /* Group name.  */
-      {
-       const char *name;
-
-       if (group == NULL)
-         name = "Group";
-       else
-         name = reggroup_name (group);
-       gdb_printf (file, " %-10s", name);
-      }
+      const char *name = group->name ();
 
       /* Group type.  */
-      {
-       const char *type;
-
-       if (group == NULL)
-         type = "Type";
-       else
-         {
-           switch (reggroup_type (group))
-             {
-             case USER_REGGROUP:
-               type = "user";
-               break;
-             case INTERNAL_REGGROUP:
-               type = "internal";
-               break;
-             default:
-               internal_error (__FILE__, __LINE__, _("bad switch"));
-             }
-         }
-       gdb_printf (file, " %-10s", type);
-      }
+      const char *type;
+
+      switch (group->type ())
+       {
+       case USER_REGGROUP:
+         type = "user";
+         break;
+       case INTERNAL_REGGROUP:
+         type = "internal";
+         break;
+       default:
+         internal_error (__FILE__, __LINE__, _("bad switch"));
+       }
 
       /* Note: If you change this, be sure to also update the
         documentation.  */
-      
-      gdb_printf (file, "\n");
 
-      group = reggroup_next (gdbarch, group);
+      gdb_printf (file, fmt, name, type);
     }
-  while (group != NULL);
 }
 
+/* Implement 'maintenance print reggroups' command.  */
+
 static void
 maintenance_print_reggroups (const char *args, int from_tty)
 {
@@ -322,21 +232,21 @@ maintenance_print_reggroups (const char *args, int from_tty)
 }
 
 /* Pre-defined register groups.  */
-static struct reggroup general_group = { "general", USER_REGGROUP };
-static struct reggroup float_group = { "float", USER_REGGROUP };
-static struct reggroup system_group = { "system", USER_REGGROUP };
-static struct reggroup vector_group = { "vector", USER_REGGROUP };
-static struct reggroup all_group = { "all", USER_REGGROUP };
-static struct reggroup save_group = { "save", INTERNAL_REGGROUP };
-static struct reggroup restore_group = { "restore", INTERNAL_REGGROUP };
-
-struct reggroup *const general_reggroup = &general_group;
-struct reggroup *const float_reggroup = &float_group;
-struct reggroup *const system_reggroup = &system_group;
-struct reggroup *const vector_reggroup = &vector_group;
-struct reggroup *const all_reggroup = &all_group;
-struct reggroup *const save_reggroup = &save_group;
-struct reggroup *const restore_reggroup = &restore_group;
+static const reggroup general_group = { "general", USER_REGGROUP };
+static const reggroup float_group = { "float", USER_REGGROUP };
+static const reggroup system_group = { "system", USER_REGGROUP };
+static const reggroup vector_group = { "vector", USER_REGGROUP };
+static const reggroup all_group = { "all", USER_REGGROUP };
+static const reggroup save_group = { "save", INTERNAL_REGGROUP };
+static const reggroup restore_group = { "restore", INTERNAL_REGGROUP };
+
+const reggroup *const general_reggroup = &general_group;
+const reggroup *const float_reggroup = &float_group;
+const reggroup *const system_reggroup = &system_group;
+const reggroup *const vector_reggroup = &vector_group;
+const reggroup *const all_reggroup = &all_group;
+const reggroup *const save_reggroup = &save_group;
+const reggroup *const restore_reggroup = &restore_group;
 
 void _initialize_reggroup ();
 void