Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Stephan Rohr <stephan.rohr@intel.com>
To: gdb-patches@sourceware.org
Cc: pedro@palves.net, eliz@gnu.org, jhb@FreeBSD.org, luis.machado@arm.com
Subject: [PATCH v2 3/5] gdb: support register groups for user registers
Date: Fri, 30 Oct 2026 11:50:14 +0000	[thread overview]
Message-ID: <20261030115016.45786-4-stephan.rohr@intel.com> (raw)
In-Reply-To: <20261030115016.45786-1-stephan.rohr@intel.com>

From: "Rohr, Stephan" <stephan.rohr@intel.com>

User registers are not part of any register group and user registers
are not listed with the "info registers <group>" command.  Neither do
"info registers" and "info all-registers".

Allow an optional set of register groups when adding a user register.
Update the "info registers" commands to print user registers, too.

This is in preparation for adding the Intel AMX tile registers as user
registers.
---
 gdb/NEWS            |  7 +++++++
 gdb/doc/gdb.texinfo |  7 +++++--
 gdb/infcmd.c        | 28 +++++++++++++++++++++++++++
 gdb/user-regs.c     | 46 +++++++++++++++++++++++++++++++++++++++------
 gdb/user-regs.h     | 17 +++++++++++++----
 5 files changed, 93 insertions(+), 12 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 2047e7376fb..4869f3595be 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -88,6 +88,13 @@ info locals
   The new "-shadowed on|off" option overrides the "set print shadowed"
   setting for a single invocation of the command.
 
+info registers
+info all-registers
+info registers REGGROUP
+  These commands now also print the user registers that are part of the
+  "general" register group, the "all" register group, or of REGGROUP,
+  respectively.
+
 *** Changes in GDB 18
 
 * Support for the Common Trace Format (CTF) has been removed.  GDB now
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 9e3b6fca669..72b87401c5c 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -13772,7 +13772,8 @@ and vector registers (in the selected stack frame).
 @item info registers @var{reggroup} @dots{}
 Print the name and value of the registers in each of the specified
 @var{reggroup}s.  The @var{reggroup} can be any of those returned by
-@code{maint print reggroups} (@pxref{Maintenance Commands}).
+@code{maint print reggroups} (@pxref{Maintenance Commands}).  This
+includes the user registers that are part of a @var{reggroup}.
 
 @item info registers @var{regname} @dots{}
 Print the @dfn{relativized} value of each specified register @var{regname}.
@@ -42832,7 +42833,9 @@ include the four ``standard'' registers @code{$fp}, @code{$pc},
 @code{$sp}, and @code{$ps}.  @xref{standard registers}.  User
 registers can be used in expressions in the same way as the canonical
 register names, but only the latter are listed by the @code{info
-registers} and @code{maint print registers} commands.
+registers} and @code{maint print registers} commands.  The exceptions are
+user registers that are part of a register group, which @code{info registers
+@var{reggroup}} lists (@pxref{info_registers_reggroup}).
 
 @kindex maint print section-scripts
 @cindex info for known .debug_gdb_scripts-loaded scripts
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index d7544168362..a1a31b65a07 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -2533,6 +2533,27 @@ default_print_registers_info (struct gdbarch *gdbarch,
     }
 }
 
+/* Print the user registers of GDBARCH in FRAME that are part of GROUP
+   to FILE.  */
+
+static void
+print_user_registers_in_group (gdbarch *gdbarch, ui_file *file,
+			       const frame_info_ptr &frame,
+			       const reggroup *group)
+{
+  /* User registers lie above the range of normal registers.  */
+  for (int regnum = gdbarch_num_cooked_regs (gdbarch);; regnum++)
+    {
+      const char *regname = user_reg_map_regnum_to_name (gdbarch, regnum);
+      if (regname == nullptr)
+	break;
+
+      if (user_reg_reggroup_p (gdbarch, regnum, group))
+	default_print_one_register_info (file, regname,
+					 value_of_user_reg (regnum, frame));
+    }
+}
+
 void
 registers_info (const char *addr_exp, bool fpregs)
 {
@@ -2548,6 +2569,11 @@ registers_info (const char *addr_exp, bool fpregs)
     {
       gdbarch_print_registers_info (gdbarch, gdb_stdout,
 				    frame, -1, fpregs);
+
+      /* Print all user registers that are in the all register group or the
+	 general register group, respectively.  */
+      print_user_registers_in_group (gdbarch, gdb_stdout, frame,
+				     fpregs ? all_reggroup : general_reggroup);
       return;
     }
 
@@ -2632,6 +2658,8 @@ registers_info (const char *addr_exp, bool fpregs)
 						gdb_stdout, frame,
 						regnum, fpregs);
 	      }
+
+	    print_user_registers_in_group (gdbarch, gdb_stdout, frame, group);
 	    continue;
 	  }
       }
diff --git a/gdb/user-regs.c b/gdb/user-regs.c
index f1c6c9a1b24..1e6280ef593 100644
--- a/gdb/user-regs.c
+++ b/gdb/user-regs.c
@@ -25,6 +25,8 @@
 #include "arch-utils.h"
 #include "command.h"
 #include "cli/cli-cmds.h"
+#include "reggroups.h"
+#include <algorithm>
 
 /* A table of user registers.
 
@@ -45,6 +47,10 @@ struct user_reg
      syscall.  */
   struct value *(*xread) (const frame_info_ptr &frame, const void *baton);
   const void *baton;
+  /* The register groups the register is part of.  The array is owned by
+     the caller of user_reg_add or user_reg_add_builtin.  */
+  const reggroup *const *groups;
+  size_t num_groups;
   struct user_reg *next;
 };
 
@@ -63,15 +69,26 @@ struct gdb_user_regs
 static void
 append_user_reg (struct gdb_user_regs *regs, const char *name,
 		 user_reg_read_ftype *xread, const void *baton,
+		 gdb::array_view<const reggroup *const> groups,
 		 struct user_reg *reg)
 {
   /* The caller is responsible for allocating memory needed to store
-     the register.  By doing this, the function can operate on a
-     register list stored in the common heap or a specific obstack.  */
+     the register and its GROUPS.  By doing this, the function can operate
+     on a register list stored in the common heap or a specific obstack.  */
   gdb_assert (reg != NULL);
+
+  /* User registers provide a different view of hardware registers.  They
+     shall not be added to the "save" or "restore" register groups.  */
+  for (const reggroup *group : groups)
+    gdb_assert (group != nullptr
+		&& group != save_reggroup
+		&& group != restore_reggroup);
+
   reg->name = name;
   reg->xread = xread;
   reg->baton = baton;
+  reg->groups = groups.data ();
+  reg->num_groups = groups.size ();
   reg->next = NULL;
   if (regs->last == nullptr)
     regs->last = &regs->first;
@@ -85,9 +102,10 @@ static struct gdb_user_regs builtin_user_regs;
 
 void
 user_reg_add_builtin (const char *name, user_reg_read_ftype *xread,
-		      const void *baton)
+		      const void *baton,
+		      gdb::array_view<const reggroup *const> groups)
 {
-  append_user_reg (&builtin_user_regs, name, xread, baton,
+  append_user_reg (&builtin_user_regs, name, xread, baton, groups,
 		   XNEW (struct user_reg));
 }
 
@@ -110,6 +128,7 @@ get_user_regs (struct gdbarch *gdbarch)
 	   reg != NULL;
 	   reg = reg->next)
 	append_user_reg (regs, reg->name, reg->xread, reg->baton,
+			 gdb::make_array_view (reg->groups, reg->num_groups),
 			 OBSTACK_ZALLOC (obstack, struct user_reg));
       user_regs_data.set (gdbarch, regs);
     }
@@ -119,11 +138,12 @@ get_user_regs (struct gdbarch *gdbarch)
 
 void
 user_reg_add (struct gdbarch *gdbarch, const char *name,
-	      user_reg_read_ftype *xread, const void *baton)
+	      user_reg_read_ftype *xread, const void *baton,
+	      gdb::array_view<const reggroup *const> groups)
 {
   struct gdb_user_regs *regs = get_user_regs (gdbarch);
   gdb_assert (regs != NULL);
-  append_user_reg (regs, name, xread, baton,
+  append_user_reg (regs, name, xread, baton, groups,
 		   GDBARCH_OBSTACK_ZALLOC (gdbarch, struct user_reg));
 }
 
@@ -194,6 +214,20 @@ user_reg_map_regnum_to_name (struct gdbarch *gdbarch, int regnum)
     }
 }
 
+/* See user-regs.h.  */
+
+bool
+user_reg_reggroup_p (struct gdbarch *gdbarch, int regnum,
+		     const reggroup *group)
+{
+  int maxregs = gdbarch_num_cooked_regs (gdbarch);
+  struct user_reg *reg = usernum_to_user_reg (gdbarch, regnum - maxregs);
+
+  gdb_assert (reg != nullptr);
+  return (std::find (reg->groups, reg->groups + reg->num_groups, group)
+	  != reg->groups + reg->num_groups);
+}
+
 struct value *
 value_of_user_reg (int regnum, const frame_info_ptr &frame)
 {
diff --git a/gdb/user-regs.h b/gdb/user-regs.h
index 7fdb05db4b1..8e08e677950 100644
--- a/gdb/user-regs.h
+++ b/gdb/user-regs.h
@@ -38,8 +38,11 @@
    of assumed to be read-only.  Should it, for instance, return a
    register descriptor that contains all the relevant access methods.  */
 
+#include "gdbsupport/array-view.h"
+
 class frame_info_ptr;
 struct gdbarch;
+struct reggroup;
 
 /* Given an architecture, map a user visible register name onto its
    index.  */
@@ -61,12 +64,18 @@ typedef struct value *(user_reg_read_ftype) (const frame_info_ptr &frame,
 extern struct value *value_of_user_reg (int regnum, const frame_info_ptr &frame);
 
 /* Add a builtin register (present in all architectures).  */
-extern void user_reg_add_builtin (const char *name,
-				  user_reg_read_ftype *read,
-				  const void *baton);
+extern void user_reg_add_builtin
+  (const char *name, user_reg_read_ftype *read, const void *baton,
+   gdb::array_view<const reggroup *const> groups = {});
 
 /* Add a per-architecture frame register.  */
 extern void user_reg_add (struct gdbarch *gdbarch, const char *name,
-			  user_reg_read_ftype *read, const void *baton);
+			  user_reg_read_ftype *read, const void *baton,
+			  gdb::array_view<const reggroup *const> groups = {});
+
+/* Return true if the user register REGNUM is a member of GROUP.  */
+
+extern bool user_reg_reggroup_p (struct gdbarch *gdbarch, int regnum,
+				 const reggroup *group);
 
 #endif /* GDB_USER_REGS_H */
-- 
2.43.0

________________________________________
Intel Deutschland GmbH 

Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany 

Tel: +49 (89) 99143-0 

www.intel.de 

Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman

Chairperson of the Supervisory Board: Sonja Pierer

Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.


  parent reply	other threads:[~2026-10-30 11:56 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30 11:50 [PATCH v2 0/5] Add Intel AMX support Stephan Rohr
2026-10-30 11:50 ` [PATCH v2 1/5] gdb: define additional integer built-in types Stephan Rohr
2026-10-30 12:45   ` Eli Zaretskii
2026-10-30 11:50 ` [PATCH v2 2/5] gdb, gdbserver: Add Intel AMX registers Stephan Rohr
2026-10-30 12:47   ` Eli Zaretskii
2026-11-03 10:44   ` Joos, Christina
2026-11-03 14:40   ` Joos, Christina
2026-10-30 11:50 ` Stephan Rohr [this message]
2026-10-30 12:48   ` [PATCH v2 3/5] gdb: support register groups for user registers Eli Zaretskii
2026-10-30 11:50 ` [PATCH v2 4/5] gdb: add a "matrix" register group Stephan Rohr
2026-10-30 12:49   ` Eli Zaretskii
2026-10-30 11:50 ` [PATCH v2 5/5] gdb: add Intel AMX tile registers as user registers Stephan Rohr
2026-10-30 12:50   ` Eli Zaretskii
2026-11-03 15:19   ` Joos, Christina
2026-11-04  9:00     ` Joos, Christina

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=20261030115016.45786-4-stephan.rohr@intel.com \
    --to=stephan.rohr@intel.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=jhb@FreeBSD.org \
    --cc=luis.machado@arm.com \
    --cc=pedro@palves.net \
    /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