if ((targets & complete_reggroup_names) != 0)
{
- struct reggroup *group;
-
- for (group = reggroup_next (gdbarch, NULL);
- group != NULL;
- group = reggroup_next (gdbarch, group))
+ for (const struct reggroup *group : gdbarch_reggroups (gdbarch))
{
name = reggroup_name (group);
if (strncmp (word, name, len) == 0)
/* A register group? */
{
- struct reggroup *group;
-
- for (group = reggroup_next (gdbarch, NULL);
- group != NULL;
- group = reggroup_next (gdbarch, group))
+ const struct reggroup *group = nullptr;
+ for (const struct reggroup *g : gdbarch_reggroups (gdbarch))
{
/* Don't bother with a length check. Should the user
enter a short register group name, go with the first
group that matches. */
- if (strncmp (start, reggroup_name (group), end - start) == 0)
- break;
+ if (strncmp (start, reggroup_name (g), end - start) == 0)
+ {
+ group = g;
+ break;
+ }
}
if (group != NULL)
{
struct reggroup_iterator_object {
PyObject_HEAD
- /* The last register group returned. Initially this will be NULL. */
- const struct reggroup *reggroup;
+ /* The index into GROUPS for the next group to return. */
+ std::vector<const reggroup *>::size_type index;
/* Pointer back to the architecture we're finding registers for. */
struct gdbarch *gdbarch;
{
reggroup_iterator_object *iter_obj
= (reggroup_iterator_object *) self;
- struct gdbarch *gdbarch = iter_obj->gdbarch;
- const reggroup *next_group = reggroup_next (gdbarch, iter_obj->reggroup);
- if (next_group == NULL)
+ const std::vector<const reggroup *> &groups
+ = gdbarch_reggroups (iter_obj->gdbarch);
+ if (iter_obj->index >= groups.size ())
{
PyErr_SetString (PyExc_StopIteration, _("No more groups"));
return NULL;
}
- iter_obj->reggroup = next_group;
- return gdbpy_get_reggroup (iter_obj->reggroup).release ();
+ const reggroup *group = groups[iter_obj->index];
+ iter_obj->index++;
+ return gdbpy_get_reggroup (group).release ();
}
/* Return a new gdb.RegisterGroupsIterator over all the register groups in
®group_iterator_object_type);
if (iter == NULL)
return NULL;
- iter->reggroup = NULL;
+ iter->index = 0;
iter->gdbarch = gdbarch;
return (PyObject *) iter;
}
else
{
const char *sep = "";
- struct reggroup *group;
-
- for (group = reggroup_next (m_gdbarch, NULL);
- group != NULL;
- group = reggroup_next (m_gdbarch, group))
+ for (const struct reggroup *group : gdbarch_reggroups (m_gdbarch))
{
if (gdbarch_register_reggroup_p (m_gdbarch, regnum, group))
{
/* 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;
private:
/* The register groups. */
- std::vector<struct reggroup *> m_groups;
+ std::vector<const struct reggroup *> m_groups;
};
static struct gdbarch_data *reggroups_data;
return groups;
}
-/* A register group iterator. */
-
-struct reggroup *
-reggroup_next (struct gdbarch *gdbarch, const struct reggroup *last)
-{
- /* 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;
-}
-
/* See reggroups.h. */
-
-struct reggroup *
-reggroup_prev (struct gdbarch *gdbarch, const struct reggroup *curr)
+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 (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;
+ return groups->groups ();
}
/* Is REGNUM a member of REGGROUP? */
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)
return group;
static void
reggroups_dump (struct gdbarch *gdbarch, struct ui_file *file)
{
- struct reggroup *group = NULL;
+ static constexpr const char *fmt = " %-10s %-10s\n";
- do
+ gdb_printf (file, fmt, "Group", "Type");
+
+ 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 = reggroup_name (group);
/* 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 (reggroup_type (group))
+ {
+ 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);
}
static void
extern const char *reggroup_name (const struct reggroup *reggroup);
extern enum reggroup_type reggroup_type (const struct reggroup *reggroup);
-/* Iterators for the architecture's register groups. Pass in NULL, returns
- the first (for next), or last (for prev) group. Pass in a group,
- returns the next or previous group, or NULL when either the end or the
- beginning of the group list is reached. */
-extern struct reggroup *reggroup_next (struct gdbarch *gdbarch,
- const struct reggroup *last);
-extern struct reggroup *reggroup_prev (struct gdbarch *gdbarch,
- const struct reggroup *curr);
+/* Return the list of all register groups for GDBARCH. */
+extern const std::vector<const reggroup *> &
+ gdbarch_reggroups (struct gdbarch *gdbarch);
+
/* Find a reggroup by name. */
extern const reggroup *reggroup_find (struct gdbarch *gdbarch,
const char *name);
(void) wstandend (handle);
}
-/* Helper for "tui reg next", wraps a call to REGGROUP_NEXT, but adds wrap
- around behaviour. Will never return nullptr. If CURRENT_GROUP is
- nullptr (e.g. if the tui register window has only just been displayed
- and has no current group selected), then the first register group will
- be returned. */
+/* Helper for "tui reg next", returns the next register group after
+ CURRENT_GROUP in the register group list for GDBARCH, with wrap around
+ behaviour.
+
+ If CURRENT_GROUP is nullptr (e.g. if the tui register window has only
+ just been displayed and has no current group selected) or the currently
+ selected register group can't be found (e.g. if the architecture has
+ changed since the register window was last updated), then the first
+ register group will be returned. */
static const reggroup *
tui_reg_next (const reggroup *current_group, struct gdbarch *gdbarch)
{
- const reggroup *group = reggroup_next (gdbarch, current_group);
- if (group == NULL)
- group = reggroup_next (gdbarch, NULL);
- return group;
+ const std::vector<const reggroup *> &groups = gdbarch_reggroups (gdbarch);
+ auto it = std::find (groups.begin (), groups.end (), current_group);
+ if (it != groups.end ())
+ it++;
+ if (it == groups.end ())
+ return groups.front ();
+ return *it;
}
-/* Helper for "tui reg prev", wraps a call to REGGROUP_PREV, but adds wrap
- around behaviour. Will never return nullptr. If CURRENT_GROUP is
- nullptr (e.g. if the tui register window has only just been displayed
- and has no current group selected), then the last register group will
- be returned. */
+/* Helper for "tui reg prev", returns the register group previous to
+ CURRENT_GROUP in the register group list for GDBARCH, with wrap around
+ behaviour.
+
+ If CURRENT_GROUP is nullptr (e.g. if the tui register window has only
+ just been displayed and has no current group selected) or the currently
+ selected register group can't be found (e.g. if the architecture has
+ changed since the register window was last updated), then the last
+ register group will be returned. */
static const reggroup *
tui_reg_prev (const reggroup *current_group, struct gdbarch *gdbarch)
{
- const reggroup *group = reggroup_prev (gdbarch, current_group);
- if (group == NULL)
- group = reggroup_prev (gdbarch, NULL);
- return group;
+ const std::vector<const reggroup *> &groups = gdbarch_reggroups (gdbarch);
+ auto it = std::find (groups.rbegin (), groups.rend (), current_group);
+ if (it != groups.rend ())
+ it++;
+ if (it == groups.rend ())
+ return groups.back ();
+ return *it;
}
/* Implement the 'tui reg' command. Changes the register group displayed
if (args != NULL)
{
- const reggroup *group, *match = NULL;
size_t len = strlen (args);
/* Make sure the curses mode is enabled. */
if (TUI_DATA_WIN == NULL || !TUI_DATA_WIN->is_visible ())
tui_regs_layout ();
+ const reggroup *match = nullptr;
const reggroup *current_group = TUI_DATA_WIN->get_current_group ();
if (strncmp (args, "next", len) == 0)
match = tui_reg_next (current_group, gdbarch);
/* This loop matches on the initial part of a register group
name. If this initial part in ARGS matches only one register
group then the switch is made. */
- for (group = reggroup_next (gdbarch, NULL);
- group != NULL;
- group = reggroup_next (gdbarch, group))
+ for (const struct reggroup *group : gdbarch_reggroups (gdbarch))
{
if (strncmp (reggroup_name (group), args, len) == 0)
{
}
else
{
- const reggroup *group;
- int first;
-
gdb_printf (_("\"tui reg\" must be followed by the name of "
"either a register group,\nor one of 'next' "
"or 'prev'. Known register groups are:\n"));
- for (first = 1, group = reggroup_next (gdbarch, NULL);
- group != NULL;
- first = 0, group = reggroup_next (gdbarch, group))
+ bool first = true;
+ for (const struct reggroup *group : gdbarch_reggroups (gdbarch))
{
if (!first)
gdb_printf (", ");
+ first = false;
gdb_printf ("%s", reggroup_name (group));
}