From 1bca9b1e6be9cb45684f38dba0d4d323447a653a Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Thu, 31 Mar 2022 11:43:13 +0100 Subject: gdb: remove reggroup_next and reggroup_prev Add a new function gdbarch_reggroups that returns a reference to a vector containing all the reggroups for an architecture. Make use of this function throughout GDB instead of the existing reggroup_next and reggroup_prev functions. Finally, delete the reggroup_next and reggroup_prev functions. Most of these changes are pretty straight forward, using range based for loops instead of the old style look using reggroup_next. There are two places where the changes are less straight forward. In gdb/python/py-registers.c, the register group iterator needed to change slightly. As the iterator is tightly coupled to the gdbarch, I just fetch the register group vector from the gdbarch when needed, and use an index counter to find the next item from the vector when needed. In gdb/tui/tui-regs.c the tui_reg_next and tui_reg_prev functions are just wrappers around reggroup_next and reggroup_prev respectively. I've just inlined the logic of the old functions into the tui functions. As the tui function had its own special twist (wrap around behaviour) I think this is OK. There should be no user visible changes after this commit. --- gdb/python/py-registers.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'gdb/python') diff --git a/gdb/python/py-registers.c b/gdb/python/py-registers.c index 41f6fea..6255dda 100644 --- a/gdb/python/py-registers.c +++ b/gdb/python/py-registers.c @@ -64,8 +64,8 @@ extern PyTypeObject register_descriptor_object_type 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::size_type index; /* Pointer back to the architecture we're finding registers for. */ struct gdbarch *gdbarch; @@ -224,17 +224,18 @@ gdbpy_reggroup_iter_next (PyObject *self) { 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 &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 @@ -251,7 +252,7 @@ gdbpy_new_reggroup_iterator (struct gdbarch *gdbarch) ®group_iterator_object_type); if (iter == NULL) return NULL; - iter->reggroup = NULL; + iter->index = 0; iter->gdbarch = gdbarch; return (PyObject *) iter; } -- cgit v1.1