This is the mail archive of the gdb-patches@sourceware.org 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]

Re: info registers output


On 08/01/2012 09:49 PM, Ulrich Weigand wrote:
> Pedro Alves wrote:
>> Ah.  I wonder if that's been made on purpose.  You get this on amd64:
>>
>> (gdb) info registers rip pc
>> rip            0x390f407e68     0x390f407e68 <start_thread+552>
>> pc: 0x390f407e68
>>
>> GDB knows the type of "pc", and so should be able to print "pc" like "rip".
>>
>> Would that be a good idea?
> 
> Would make sense to me.  (In fact, there probably ought to be a single
> routine to print a register, called by both code paths, to avoid having
> the code diverge again in the future ...)

Here's a patch that does that.  If some arch wants to print user regs
differently, we'll either have to add a new gdbarch, or make
gdbarch_print_registers_info handle user regs.

We now get, for amd64:

(gdb) info registers pc rip sp rsp fp rbp
pc             0x45762b 0x45762b <main+15>
rip            0x45762b 0x45762b <main+15>
sp             0x7fffffffdbe0   0x7fffffffdbe0
rsp            0x7fffffffdbe0   0x7fffffffdbe0
fp             0x7fffffffdc10   0x7fffffffdc10
rbp            0x7fffffffdc10   0x7fffffffdc10

Before we'd get:

(gdb) info registers pc rip sp rsp fp rbp
pc: 0x45762b
rip            0x45762b 0x45762b <main+15>
sp: 0x7fffffffdbe0
rsp            0x7fffffffdbe0   0x7fffffffdbe0
fp: 0x7fffffffdc10
rbp            0x7fffffffdc10   0x7fffffffdc10

How does it look?

Tested on AMD64 Fedora 17.

2012-08-27  Pedro Alves  <palves@redhat.com>

	PR gdb/14428

	* infcmd.c (default_print_one_register_info): New, factored out
	from default_print_registers_info.
	(default_print_registers_info): Use it.  Mark value unavailable if
	necessary.
	(registers_info): Print user registers with
	default_print_one_register_info.
---

 gdb/infcmd.c                     |  167 +++++++++++++++++++++-----------------
 gdb/testsuite/gdb.base/pc-fp.exp |    2 
 2 files changed, 93 insertions(+), 76 deletions(-)

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 9d43193..2067948 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -2015,6 +2015,84 @@ path_command (char *dirname, int from_tty)
 }
 
 
+/* Print out the register NAME, of GDBARCH, with value VAL, to FILE,
+   in the default fashion.  */
+
+static void
+default_print_one_register_info (struct gdbarch *gdbarch,
+				 struct ui_file *file,
+				 const char *name,
+				 struct value *val)
+{
+  struct type *regtype = value_type (val);
+
+  fputs_filtered (name, file);
+  print_spaces_filtered (15 - strlen (name), file);
+
+  if (!value_entirely_available (val))
+    {
+      fprintf_filtered (file, "*value not available*\n");
+      return;
+    }
+
+  /* If virtual format is floating, print it that way, and in raw
+     hex.  */
+  if (TYPE_CODE (regtype) == TYPE_CODE_FLT
+      || TYPE_CODE (regtype) == TYPE_CODE_DECFLOAT)
+    {
+      int j;
+      struct value_print_options opts;
+      const gdb_byte *valaddr = value_contents_for_printing (val);
+
+      get_user_print_options (&opts);
+      opts.deref_ref = 1;
+
+      val_print (regtype,
+		 value_contents_for_printing (val),
+		 value_embedded_offset (val), 0,
+		 file, 0, val, &opts, current_language);
+
+      fprintf_filtered (file, "\t(raw 0x");
+      for (j = 0; j < TYPE_LENGTH (regtype); j++)
+	{
+	  int idx;
+
+	  if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
+	    idx = j;
+	  else
+	    idx = TYPE_LENGTH (regtype) - 1 - j;
+	  fprintf_filtered (file, "%02x", (unsigned char) valaddr[idx]);
+	}
+      fprintf_filtered (file, ")");
+    }
+  else
+    {
+      struct value_print_options opts;
+
+      /* Print the register in hex.  */
+      get_formatted_print_options (&opts, 'x');
+      opts.deref_ref = 1;
+      val_print (regtype,
+		 value_contents_for_printing (val),
+		 value_embedded_offset (val), 0,
+		 file, 0, val, &opts, current_language);
+      /* If not a vector register, print it also according to its
+	 natural format.  */
+      if (TYPE_VECTOR (regtype) == 0)
+	{
+	  get_user_print_options (&opts);
+	  opts.deref_ref = 1;
+	  fprintf_filtered (file, "\t");
+	  val_print (regtype,
+		     value_contents_for_printing (val),
+		     value_embedded_offset (val), 0,
+		     file, 0, val, &opts, current_language);
+	}
+    }
+
+  fprintf_filtered (file, "\n");
+}
+
 /* Print out the machine register regnum.  If regnum is -1, print all
    registers (print_all == 1) or all non-float and non-vector
    registers (print_all == 0).
@@ -2068,76 +2146,16 @@ default_print_registers_info (struct gdbarch *gdbarch,
 	  || *(gdbarch_register_name (gdbarch, i)) == '\0')
 	continue;
 
-      fputs_filtered (gdbarch_register_name (gdbarch, i), file);
-      print_spaces_filtered (15 - strlen (gdbarch_register_name
-					  (gdbarch, i)), file);
-
       regtype = register_type (gdbarch, i);
       val = allocate_value (regtype);
 
       /* Get the data in raw format.  */
       if (! frame_register_read (frame, i, value_contents_raw (val)))
-	{
-	  fprintf_filtered (file, "*value not available*\n");
-	  continue;
-	}
-
-      /* If virtual format is floating, print it that way, and in raw
-         hex.  */
-      if (TYPE_CODE (regtype) == TYPE_CODE_FLT
-	  || TYPE_CODE (regtype) == TYPE_CODE_DECFLOAT)
-	{
-	  int j;
-	  struct value_print_options opts;
-	  const gdb_byte *valaddr = value_contents_for_printing (val);
-
-	  get_user_print_options (&opts);
-	  opts.deref_ref = 1;
-
-	  val_print (regtype,
-		     value_contents_for_printing (val),
-		     value_embedded_offset (val), 0,
-		     file, 0, val, &opts, current_language);
-
-	  fprintf_filtered (file, "\t(raw 0x");
-	  for (j = 0; j < register_size (gdbarch, i); j++)
-	    {
-	      int idx;
-
-	      if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
-		idx = j;
-	      else
-		idx = register_size (gdbarch, i) - 1 - j;
-	      fprintf_filtered (file, "%02x", (unsigned char) valaddr[idx]);
-	    }
-	  fprintf_filtered (file, ")");
-	}
-      else
-	{
-	  struct value_print_options opts;
-
-	  /* Print the register in hex.  */
-	  get_formatted_print_options (&opts, 'x');
-	  opts.deref_ref = 1;
-	  val_print (regtype,
-		     value_contents_for_printing (val),
-		     value_embedded_offset (val), 0,
-		     file, 0, val, &opts, current_language);
-          /* If not a vector register, print it also according to its
-             natural format.  */
-	  if (TYPE_VECTOR (regtype) == 0)
-	    {
-	      get_user_print_options (&opts);
-	      opts.deref_ref = 1;
-	      fprintf_filtered (file, "\t");
-	      val_print (regtype,
-			 value_contents_for_printing (val),
-			 value_embedded_offset (val), 0,
-			 file, 0, val, &opts, current_language);
-	    }
-	}
+	mark_value_bytes_unavailable (val, 0, TYPE_LENGTH (value_type (val)));
 
-      fprintf_filtered (file, "\n");
+      default_print_one_register_info (gdbarch, file,
+				       gdbarch_register_name (gdbarch, i),
+				       val);
     }
 }
 
@@ -2198,17 +2216,16 @@ registers_info (char *addr_exp, int fpregs)
 	    if (regnum >= gdbarch_num_regs (gdbarch)
 			  + gdbarch_num_pseudo_regs (gdbarch))
 	      {
-		struct value_print_options opts;
-		struct value *val = value_of_user_reg (regnum, frame);
-
-		printf_filtered ("%.*s: ", (int) (end - start), start);
-		get_formatted_print_options (&opts, 'x');
-		val_print_scalar_formatted (check_typedef (value_type (val)),
-					    value_contents_for_printing (val),
-					    value_embedded_offset (val),
-					    val,
-					    &opts, 0, gdb_stdout);
-		printf_filtered ("\n");
+		struct value *regval = value_of_user_reg (regnum, frame);
+		const char *regname = user_reg_map_regnum_to_name (gdbarch,
+								   regnum);
+
+		/* Print in the same fashion
+		   gdbarch_print_registers_info's default
+		   implementation prints.  */
+		default_print_one_register_info (gdbarch, gdb_stdout,
+						 regname,
+						 regval);
 	      }
 	    else
 	      gdbarch_print_registers_info (gdbarch, gdb_stdout,
diff --git a/gdb/testsuite/gdb.base/pc-fp.exp b/gdb/testsuite/gdb.base/pc-fp.exp
index beb5087..685e2d9 100644
--- a/gdb/testsuite/gdb.base/pc-fp.exp
+++ b/gdb/testsuite/gdb.base/pc-fp.exp
@@ -66,4 +66,4 @@ gdb_test "info register \$fp" "${valueof_fp}.*"
 # Regression test for
 # http://sourceware.org/bugzilla/show_bug.cgi?id=12659
 gdb_test "info register pc fp" \
-    "pc(:)?( |\t)+${valueof_pc}(( |\t)+${valueof_pc} <.*>)?\[\r\n\]+fp(:)?( |\t)+${valueof_fp}(( |\t)+${valueof_fp})?\[\r\n\]+"
+    "pc +${valueof_pc}\t${valueof_pc} <.*>\[\r\n\]+fp +${valueof_fp}\t${valueof_fp}\[\r\n\]+"


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