public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCHv2 14/16] gdb: convert reggroup to a C++ class with constructor, etc
Date: Wed,  6 Apr 2022 13:04:47 +0100	[thread overview]
Message-ID: <4af22c5f3aca2b182165691aff8a1dafb7e5995d.1649246539.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1649246538.git.aburgess@redhat.com>

Convert the 'struct reggroup' into a real class, with a constructor
and getter methods.

There should be no user visible changes after this commit.
---
 gdb/reggroups.c | 48 ++++++++++++++++++++++++++++++------------------
 1 file changed, 30 insertions(+), 18 deletions(-)

diff --git a/gdb/reggroups.c b/gdb/reggroups.c
index 2888704f2d2..dfae60773bb 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";
-- 
2.25.4


  parent reply	other threads:[~2022-04-06 12:05 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-31 21:04 [PATCH 00/16] Default register groups, and general related cleanup Andrew Burgess
2022-03-31 21:04 ` [PATCH 01/16] gdb: don't try to use readline before it's initialized Andrew Burgess
2022-03-31 21:04 ` [PATCH 02/16] gdb: add some const in gdb/reggroups.c Andrew Burgess
2022-03-31 21:04 ` [PATCH 03/16] gdb: make gdbarch_register_reggroup_p take a const reggroup * Andrew Burgess
2022-04-04 22:35   ` Lancelot SIX
2022-04-05  8:24     ` Andrew Burgess
2022-03-31 21:04 ` [PATCH 04/16] gdb: switch to using 'const reggroup *' in tui-regs.{c, h} Andrew Burgess
2022-03-31 21:04 ` [PATCH 05/16] gdb: use 'const reggroup *' in python/py-registers.c file Andrew Burgess
2022-03-31 21:04 ` [PATCH 06/16] gdb: have reggroup_find return a const Andrew Burgess
2022-03-31 21:04 ` [PATCH 07/16] gdb/tui: avoid theoretical bug with 'tui reg' command Andrew Burgess
2022-03-31 21:04 ` [PATCH 08/16] gdb/tui: fix 'tui reg next/prev' command when data window is hidden Andrew Burgess
2022-03-31 21:04 ` [PATCH 09/16] gdb: always add the default register groups Andrew Burgess
2022-03-31 21:04 ` [PATCH 10/16] gdb: convert reggroups to use a std::vector Andrew Burgess
2022-03-31 21:04 ` [PATCH 11/16] gdb: remove reggroup_next and reggroup_prev Andrew Burgess
2022-04-05 23:11   ` Lancelot SIX
2022-04-06 12:06     ` Andrew Burgess
2022-03-31 21:04 ` [PATCH 12/16] gdb: more 'const' in gdb/reggroups.{c,h} Andrew Burgess
2022-03-31 21:04 ` [PATCH 13/16] gdb: make the pre-defined register groups const Andrew Burgess
2022-03-31 21:04 ` [PATCH 14/16] gdb: convert reggroup to a C++ class with constructor, etc Andrew Burgess
2022-03-31 21:04 ` [PATCH 15/16] gdb: move struct reggroup into reggroups.h header Andrew Burgess
2022-03-31 21:04 ` [PATCH 16/16] gdb: update comments throughout reggroups.{c,h} files Andrew Burgess
2022-04-06 14:28   ` Simon Marchi
2022-04-06 12:04 ` [PATCHv2 00/16] Default register groups, and general related cleanup Andrew Burgess
2022-04-06 12:04   ` [PATCHv2 01/16] gdb: don't try to use readline before it's initialized Andrew Burgess
2022-04-06 12:57     ` Simon Marchi
2022-04-06 12:04   ` [PATCHv2 02/16] gdb: add some const in gdb/reggroups.c Andrew Burgess
2022-04-06 12:58     ` Simon Marchi
2022-04-06 12:04   ` [PATCHv2 03/16] gdb: make gdbarch_register_reggroup_p take a const reggroup * Andrew Burgess
2022-04-06 12:04   ` [PATCHv2 04/16] gdb: switch to using 'const reggroup *' in tui-regs.{c, h} Andrew Burgess
2022-04-06 12:04   ` [PATCHv2 05/16] gdb: use 'const reggroup *' in python/py-registers.c file Andrew Burgess
2022-04-06 12:04   ` [PATCHv2 06/16] gdb: have reggroup_find return a const Andrew Burgess
2022-04-06 12:04   ` [PATCHv2 07/16] gdb/tui: avoid theoretical bug with 'tui reg' command Andrew Burgess
2022-04-06 13:02     ` Simon Marchi
2022-04-06 12:04   ` [PATCHv2 08/16] gdb/tui: fix 'tui reg next/prev' command when data window is hidden Andrew Burgess
2022-04-06 13:13     ` Simon Marchi
2022-04-06 12:04   ` [PATCHv2 09/16] gdb: always add the default register groups Andrew Burgess
2022-04-06 13:22     ` Simon Marchi
2022-04-06 12:04   ` [PATCHv2 10/16] gdb: convert reggroups to use a std::vector Andrew Burgess
2022-04-06 12:04   ` [PATCHv2 11/16] gdb: remove reggroup_next and reggroup_prev Andrew Burgess
2022-04-06 14:22     ` Simon Marchi
2022-04-06 14:23       ` Simon Marchi
2022-04-06 12:04   ` [PATCHv2 12/16] gdb: more 'const' in gdb/reggroups.{c,h} Andrew Burgess
2022-04-06 12:04   ` [PATCHv2 13/16] gdb: make the pre-defined register groups const Andrew Burgess
2022-04-06 12:04   ` Andrew Burgess [this message]
2022-04-06 12:04   ` [PATCHv2 15/16] gdb: move struct reggroup into reggroups.h header Andrew Burgess
2022-04-06 12:04   ` [PATCHv2 16/16] gdb: update comments throughout reggroups.{c, h} files Andrew Burgess
2022-04-06 14:34   ` [PATCHv2 00/16] Default register groups, and general related cleanup Simon Marchi
2022-04-07 15:16     ` Andrew Burgess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4af22c5f3aca2b182165691aff8a1dafb7e5995d.1649246539.git.aburgess@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).