From: Andrew Burgess Date: Thu, 31 Mar 2022 15:44:15 +0000 (+0100) Subject: gdb: convert reggroup to a C++ class with constructor, etc X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c30c0f062e52b7a827d8571cdafcd04c9e71ab6b;p=binutils-gdb.git gdb: convert reggroup to a C++ class with constructor, etc Convert the 'struct reggroup' into a real class, with a constructor and getter methods. There should be no user visible changes after this commit. --- diff --git a/gdb/reggroups.c b/gdb/reggroups.c index 24c45257efc..643337e3aee 100644 --- a/gdb/reggroups.c +++ b/gdb/reggroups.c @@ -32,18 +32,33 @@ struct reggroup { - const char *name; - enum reggroup_type type; + /* Create a new register group object. The NAME is not owned by the new + reggroup object, so must outlive the object. */ + reggroup (const char *name, enum reggroup_type type) + : m_name (name), + m_type (type) + { /* Nothing. */ } + + /* Return the name for this register group. */ + const char *name () const + { return m_name; } + + /* Return the type of this register group. */ + enum reggroup_type type () const + { return m_type; } + +private: + /* The name of this register group. */ + const char *m_name; + + /* The type of this register group. */ + enum reggroup_type m_type; }; 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. */ @@ -52,12 +67,9 @@ 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; + name = gdbarch_obstack_strdup (gdbarch, name); + return obstack_new (gdbarch_obstack (gdbarch), + name, type); } /* Register group attributes. */ @@ -65,13 +77,13 @@ reggroup_gdbarch_new (struct gdbarch *gdbarch, const char *name, const char * reggroup_name (const struct reggroup *group) { - return group->name; + return group->name (); } enum reggroup_type reggroup_type (const struct reggroup *group) { - return group->type; + return group->type (); } /* A container holding all the register groups for a particular @@ -194,7 +206,7 @@ reggroup_find (struct gdbarch *gdbarch, const char *name) { 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; @@ -212,12 +224,12 @@ reggroups_dump (struct gdbarch *gdbarch, struct ui_file *file) for (const struct reggroup *group : gdbarch_reggroups (gdbarch)) { /* Group name. */ - const char *name = reggroup_name (group); + const char *name = group->name (); /* Group type. */ const char *type; - switch (reggroup_type (group)) + switch (group->type ()) { case USER_REGGROUP: type = "user";