This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch/rfc] Add reggroup type (cagney_sysregs-20020825-branch)


Hello,

The attached adds a type attribute to each register. Vis:

(gdb) maint print reggroups
Group name Type
sse user
mmx user
general user
float user
all user
save internal
restore internal
vector user
system user

I'm thinking that GUI's will need a way of asking GDB for a list of groups that the user (rather than the internals) are interested in.

In the above the save and restore reggroups are ``internal'' and the user shouldn't need to know about them (unless the user is wondering why a register wasn't saved/restored across an inferior function call).

Thoughts? Other ways of doing this? ...

If this is ok, I'll start pulling reggroups into the mainline.

Committing to my branch,
Andrew
2002-09-19  Andrew Cagney  <cagney@redhat.com>

	* reggroups.h (enum reggroup_type): Declare.
	(reggroup_type): Declare.
	(reggroup_new): Add ``type'' parameter.
	* reggroups.c: Include "command.h" and "gdbcmd.h".
	 (reggroups_dump): New function.
	(maintenance_print_reggroups): New function.
	(_initialize_reggroup): Add ``maint print reggroups'' command.
	(save_group, restore_group): Set type to INTERNAL_REGGROUP.
	(reggroup_new): Update.
	(struct reggroup): Add ``type'' field.
	(reggroup_type): New function.
	* i386-tdep.c (i386_init_reggroups): Update.

Index: doc/ChangeLog
2002-09-19  Andrew Cagney  <cagney@redhat.com>

	* gdb.texinfo (Maintenance Commands): Document ``maint print
	reggroups''.

Index: i386-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-tdep.c,v
retrieving revision 1.84.4.5
diff -u -r1.84.4.5 i386-tdep.c
--- i386-tdep.c	19 Sep 2002 16:55:51 -0000	1.84.4.5
+++ i386-tdep.c	19 Sep 2002 18:02:22 -0000
@@ -1423,8 +1423,8 @@
 static void
 i386_init_reggroups (void)
 {
-  i386_sse_reggroup = reggroup_new ("sse");
-  i386_mmx_reggroup = reggroup_new ("mmx");
+  i386_sse_reggroup = reggroup_new ("sse", USER_REGGROUP);
+  i386_mmx_reggroup = reggroup_new ("mmx", USER_REGGROUP);
 }
 
 static void
Index: reggroups.c
===================================================================
RCS file: /cvs/src/src/gdb/Attic/reggroups.c,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 reggroups.c
--- reggroups.c	19 Sep 2002 16:49:55 -0000	1.1.2.2
+++ reggroups.c	19 Sep 2002 18:02:22 -0000
@@ -26,19 +26,23 @@
 #include "gdbtypes.h"
 #include "gdb_assert.h"
 #include "regcache.h"
+#include "command.h"
+#include "gdbcmd.h"		/* For maintenanceprintlist.  */
 
 /* Individual register groups.  */
 
 struct reggroup
 {
   const char *name;
+  enum reggroup_type type;
 };
 
 struct reggroup *
-reggroup_new (const char *name)
+reggroup_new (const char *name, enum reggroup_type type)
 {
   struct reggroup *group = XMALLOC (struct reggroup);
   group->name = name;
+  group->type = type;
   return group;
 }
 
@@ -50,6 +54,12 @@
   return group->name;
 }
 
+enum reggroup_type
+reggroup_type (struct reggroup *group)
+{
+  return group->type;
+}
+
 /* All the groups for a given architecture.  */
 
 struct reggroups
@@ -151,8 +161,109 @@
   return 0;   
 }
 
+/* Dump out a table of register groups for the current architecture.  */
+
+static void
+reggroups_dump (struct gdbarch *gdbarch, struct ui_file *file)
+{
+  struct reggroup *const *groups = reggroups (gdbarch);
+  int i;
+  int regnum;
+
+  i = -1;
+  do
+    {
+      /* Group name.  */
+      {
+	const char *name;
+	if (i < 0)
+	  name = "Group name";
+	else
+	  name = reggroup_name (groups[i]);
+	fprintf_unfiltered (file, " %-10s", name);
+      }
+
+      /* Group type.  */
+      {
+	const char *type;
+	if (i < 0)
+	  type = "Type";
+	else
+	  {
+	    switch (reggroup_type (groups[i]))
+	      {
+	      case USER_REGGROUP:
+		type = "user";
+		break;
+	      case INTERNAL_REGGROUP:
+		type = "internal";
+		break;
+	      default:
+		internal_error (__FILE__, __LINE__, "bad switch");
+	      }
+	  }
+	fprintf_unfiltered (file, " %-10s", type);
+      }
+      fprintf_unfiltered (file, "\n");
+      i++;
+    }
+  while (groups[i] != NULL);
 
+#if 0
+  for (regnum = -1; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
+    {
+      {
+	const char *name;
+	if (regnum < 0)
+	  name = "Reg name";
+	else
+	  {
+	    name = REGISTER_NAME (regnum);
+	    if (name == NULL)
+	      name = "";
+	    else if (name[0] == '\0')
+	      name = "''";
+	  }
+	fprintf_unfiltered (file, " %-10s", name);
+      }
+
+      if (regnum < 0)
+	fprintf_unfiltered (file, " Groups");
+      else
+	{
+	  int i;
+	  const char *sep = " ";
+	  for (i = 0; groups[i] != NULL; i++)
+	    {
+	      if (gdbarch_register_reggroup_p (gdbarch, regnum, groups[i]))
+		{
+		  fprintf_unfiltered (file, "%s%s", sep,
+				      reggroup_name (groups[i]));
+		  sep = ",";
+		}
+	    }
+	}
 
+      fprintf_unfiltered (file, "\n");
+    }
+#endif
+
+}
+
+static void
+maintenance_print_reggroups (char *args, int from_tty)
+{
+  if (args == NULL)
+    reggroups_dump (current_gdbarch, gdb_stdout);
+  else
+    {
+      struct ui_file *file = gdb_fopen (args, "w");
+      if (file == NULL)
+	perror_with_name ("maintenance print reggroups");
+      reggroups_dump (current_gdbarch, file);    
+      ui_file_delete (file);
+    }
+}
 
 /* Pre-defined register groups.  */
 struct reggroup general_group = { "general" };
@@ -160,8 +271,8 @@
 struct reggroup system_group = { "system" };
 struct reggroup vector_group = { "vector" };
 struct reggroup all_group = { "all" };
-struct reggroup save_group = { "save" };
-struct reggroup restore_group = { "restore" };
+struct reggroup save_group = { "save", INTERNAL_REGGROUP };
+struct reggroup restore_group = { "restore", INTERNAL_REGGROUP };
 
 struct reggroup *const general_reggroup = &general_group;
 struct reggroup *const float_reggroup = &float_group;
@@ -185,4 +296,12 @@
   add_group (default_groups, all_reggroup);
   add_group (default_groups, save_reggroup);
   add_group (default_groups, restore_reggroup);
+
+
+  add_cmd ("reggroups", class_maintenance,
+	   maintenance_print_reggroups, "\
+Print the internal register group names.\n\
+Takes an optional file parameter.",
+	   &maintenanceprintlist);
+
 }
Index: reggroups.h
===================================================================
RCS file: /cvs/src/src/gdb/Attic/reggroups.h,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 reggroups.h
--- reggroups.h	19 Sep 2002 16:49:55 -0000	1.1.2.2
+++ reggroups.h	19 Sep 2002 18:02:22 -0000
@@ -27,6 +27,8 @@
 struct gdbarch;
 struct reggroup;
 
+enum reggroup_type { USER_REGGROUP, INTERNAL_REGGROUP };
+
 /* Pre-defined, user visible, register groups.  */
 extern struct reggroup *const general_reggroup;
 extern struct reggroup *const float_reggroup;
@@ -39,13 +41,15 @@
 extern struct reggroup *const restore_reggroup;
 
 /* Create a new local register group.  */
-extern struct reggroup *reggroup_new (const char *name);
+extern struct reggroup *reggroup_new (const char *name,
+				      enum reggroup_type type);
 
 /* Add a register group (with attribute values) to the pre-defined list.  */
 extern void reggroup_add (struct gdbarch *gdbarch, struct reggroup *group);
 
 /* Register group attributes.  */
 extern const char *reggroup_name (struct reggroup *reggroup);
+extern enum reggroup_type reggroup_type (struct reggroup *reggroup);
 
 /* The register groups for the current architecture.  */
 extern struct reggroup *const *reggroups (struct gdbarch *gdbarch);
Index: doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.115
diff -u -r1.115 gdb.texinfo
--- doc/gdb.texinfo	25 Aug 2002 19:10:15 -0000	1.115
+++ doc/gdb.texinfo	19 Sep 2002 18:02:32 -0000
@@ -14225,6 +14225,24 @@
 
 Takes an optional file parameter.
 
+@kindex maint print reggroups
+@item maint print reggroups
+Print @value{GDBN}'s internal register group data structures.
+
+Takes an optional file parameter.
+
+@smallexample
+(gdb) @kbd{maint print reggroups}
+ Group name Type      
+ general    user      
+ float      user      
+ all        user      
+ save       internal  
+ restore    internal  
+ vector     user      
+ system     user      
+@end smallexample
+
 @end table
 
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]