public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdb: convert reggroup to a C++ class with constructor, etc
@ 2022-04-07 15:08 Andrew Burgess
  0 siblings, 0 replies; only message in thread
From: Andrew Burgess @ 2022-04-07 15:08 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c30c0f062e52b7a827d8571cdafcd04c9e71ab6b

commit c30c0f062e52b7a827d8571cdafcd04c9e71ab6b
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Thu Mar 31 16:44:15 2022 +0100

    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:
---
 gdb/reggroups.c | 48 ++++++++++++++++++++++++++++++------------------
 1 file changed, 30 insertions(+), 18 deletions(-)

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<struct reggroup> (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";


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-07 15:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-07 15:08 [binutils-gdb] gdb: convert reggroup to a C++ class with constructor, etc Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).