public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* s/print_scalar_formatted/val_print_scalar_formatted/, mostly
@ 2011-01-25 18:19 Pedro Alves
  2011-01-25 19:38 ` TUI, always pass a value to val_print & co (Re: s/print_scalar_formatted/val_print_scalar_formatted/, mostly) Pedro Alves
  2011-01-28 16:01 ` [mips-tdep] Re: s/print_scalar_formatted/val_print_scalar_formatted/, mostly Pedro Alves
  0 siblings, 2 replies; 3+ messages in thread
From: Pedro Alves @ 2011-01-25 18:19 UTC (permalink / raw)
  To: gdb-patches

This addresses two problems:

 - When print_scalar_formatted sees a 's' format, it defers to val_print,
but since it has no value handy to match the contents buffer the
print_scalar_formatted wanted to print, it passes in a NULL value
to val_print, which is something that I want to forbid.
This patch adds a new val_print_scalar_formatted and adjusts all 
callers so that we do have a value handy.

- Fix this inconsistency:

(gdb) p arg1
$1 = <value optimized out>
(gdb) p /x arg1
$2 = value has been optimized out

The latter case is an error being thrown from within value_contents or
friends.

The fix is to check whether the value being printed is valid
before trying to get at its contents.  Instead of fixing most callers
of print_scalar_formatted to do that check, we centralize the 
check in the new val_print_scalar_formatted function.

Only a handful of print_scalar_formatted calls are left in the
tree after this.  mips-tdep.c has 3 that could/should be converted
to val_print_scalar_formatted, but I didn't bother yet as I'd need to
make them construct a value too.  TUI has a use that needs fixing (and
needs similarly to be fixed for always-a-value-passed-to-val_print&co),
that I plan on fixing (I'm a TUI user!).  MI has one use that 
is unrelated to printing "struct values", so can stay as is.

Tested on x86_64-linux and checked in.

-- 
Pedro Alves
2011-01-25  Pedro Alves  <pedro@codesourcery.com>

	gdb/
	* printcmd.c (print_formatted): Use val_print_scalar_formatted
	instead of print_scalar_formatted.
	(print_scalar_formatted): Don't handle 's' format strings here,
	and add an assertion that we never see such format here.
	* valprint.h (val_print_scalar_formatted): Declare.
	* valprint.c (val_print_scalar_formatted): New.
	* c-valprint.c (c_val_print): Use val_print_scalar_formatted
	instead of print_scalar_formatted.
	* jv-valprint.c (java_val_print): Ditto.
	* p-valprint.c (pascal_val_print): Ditto.
	* ada-valprint.c (ada_val_print_1): Ditto.
	* f-valprint.c (f_val_print): Ditto.
	* infcmd.c (registers_info): Ditto.
	* m2-valprint.c (m2_val_print): Ditto.

---
 gdb/ada-valprint.c |   12 +++++------
 gdb/c-valprint.c   |   56 +++++++++++++++++++++++++++--------------------------
 gdb/f-valprint.c   |   24 +++++++++++-----------
 gdb/infcmd.c       |    8 ++++---
 gdb/jv-valprint.c  |    8 +++----
 gdb/m2-valprint.c  |   28 +++++++++++++-------------
 gdb/p-valprint.c   |   32 +++++++++++++++---------------
 gdb/printcmd.c     |   28 ++++++++------------------
 gdb/valprint.c     |   41 ++++++++++++++++++++++++++++++++++++++
 gdb/valprint.h     |    7 ++++++
 10 files changed, 143 insertions(+), 101 deletions(-)

Index: src/gdb/c-valprint.c
===================================================================
--- src.orig/gdb/c-valprint.c	2011-01-25 16:46:26.857639991 +0000
+++ src/gdb/c-valprint.c	2011-01-25 17:47:53.597639998 +0000
@@ -248,8 +248,8 @@ c_val_print (struct type *type, const gd
     case TYPE_CODE_MEMBERPTR:
       if (options->format)
 	{
-	  print_scalar_formatted (valaddr + embedded_offset, type,
-				  options, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      original_value, options, 0, stream);
 	  break;
 	}
       cp_print_class_member (valaddr + embedded_offset, type, stream, "&");
@@ -262,8 +262,8 @@ c_val_print (struct type *type, const gd
     case TYPE_CODE_PTR:
       if (options->format && options->format != 's')
 	{
-	  print_scalar_formatted (valaddr + embedded_offset, type,
-				  options, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      original_value, options, 0, stream);
 	  break;
 	}
       if (options->vtblprint && cp_is_vtbl_ptr_type (type))
@@ -432,8 +432,8 @@ c_val_print (struct type *type, const gd
     case TYPE_CODE_ENUM:
       if (options->format)
 	{
-	  print_scalar_formatted (valaddr + embedded_offset, type,
-				  options, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      original_value, options, 0, stream);
 	  break;
 	}
       len = TYPE_NFIELDS (type);
@@ -458,8 +458,8 @@ c_val_print (struct type *type, const gd
 
     case TYPE_CODE_FLAGS:
       if (options->format)
-	  print_scalar_formatted (valaddr + embedded_offset, type,
-				  options, 0, stream);
+	val_print_scalar_formatted (type, valaddr, embedded_offset,
+				    original_value, options, 0, stream);
       else
 	val_print_type_code_flags (type, valaddr + embedded_offset,
 				   stream);
@@ -469,8 +469,8 @@ c_val_print (struct type *type, const gd
     case TYPE_CODE_METHOD:
       if (options->format)
 	{
-	  print_scalar_formatted (valaddr + embedded_offset, type,
-				  options, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      original_value, options, 0, stream);
 	  break;
 	}
       /* FIXME, we should consider, at least for ANSI C language,
@@ -489,8 +489,8 @@ c_val_print (struct type *type, const gd
 	  struct value_print_options opts = *options;
 	  opts.format = (options->format ? options->format
 			 : options->output_format);
-	  print_scalar_formatted (valaddr + embedded_offset, type,
-				  &opts, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      original_value, &opts, 0, stream);
 	}
       else
 	{
@@ -521,8 +521,8 @@ c_val_print (struct type *type, const gd
 
 	  opts.format = (options->format ? options->format
 			 : options->output_format);
-	  print_scalar_formatted (valaddr + embedded_offset, type,
-				  &opts, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      original_value, &opts, 0, stream);
 	}
       else
 	{
@@ -547,8 +547,8 @@ c_val_print (struct type *type, const gd
 	  struct value_print_options opts = *options;
 	  opts.format = (options->format ? options->format
 			 : options->output_format);
-	  print_scalar_formatted (valaddr + embedded_offset, type,
-				  &opts, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      original_value, &opts, 0, stream);
 	}
       else
 	{
@@ -565,8 +565,8 @@ c_val_print (struct type *type, const gd
     case TYPE_CODE_FLT:
       if (options->format)
 	{
-	  print_scalar_formatted (valaddr + embedded_offset, type,
-				  options, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      original_value, options, 0, stream);
 	}
       else
 	{
@@ -576,8 +576,8 @@ c_val_print (struct type *type, const gd
 
     case TYPE_CODE_DECFLOAT:
       if (options->format)
-	print_scalar_formatted (valaddr + embedded_offset, type,
-				options, 0, stream);
+	val_print_scalar_formatted (type, valaddr, embedded_offset,
+				    original_value, options, 0, stream);
       else
 	print_decimal_floating (valaddr + embedded_offset,
 				type, stream);
@@ -601,19 +601,21 @@ c_val_print (struct type *type, const gd
 
     case TYPE_CODE_COMPLEX:
       if (options->format)
-	print_scalar_formatted (valaddr + embedded_offset,
-				TYPE_TARGET_TYPE (type),
-				options, 0, stream);
+	val_print_scalar_formatted (TYPE_TARGET_TYPE (type),
+				    valaddr, embedded_offset,
+				    original_value, options, 0, stream);
       else
 	print_floating (valaddr + embedded_offset,
 			TYPE_TARGET_TYPE (type),
 			stream);
       fprintf_filtered (stream, " + ");
       if (options->format)
-	print_scalar_formatted (valaddr + embedded_offset
-				+ TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
-				TYPE_TARGET_TYPE (type),
-				options, 0, stream);
+	val_print_scalar_formatted (TYPE_TARGET_TYPE (type),
+				    valaddr,
+				    embedded_offset
+				    + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
+				    original_value,
+				    options, 0, stream);
       else
 	print_floating (valaddr + embedded_offset
 			+ TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
Index: src/gdb/printcmd.c
===================================================================
--- src.orig/gdb/printcmd.c	2011-01-25 16:46:26.857639991 +0000
+++ src/gdb/printcmd.c	2011-01-25 17:47:53.597639998 +0000
@@ -329,8 +329,11 @@ print_formatted (struct value *val, int
   else
     /* User specified format, so don't look to the the type to
        tell us what to do.  */
-    print_scalar_formatted (value_contents (val), type,
-			    options, size, stream);
+    val_print_scalar_formatted (type,
+				value_contents_for_printing (val),
+				value_embedded_offset (val),
+				val,
+				options, size, stream);
 }
 
 /* Return builtin floating point type of same length as TYPE.
@@ -353,11 +356,8 @@ float_type_from_length (struct type *typ
 }
 
 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
-   according to OPTIONS and SIZE on STREAM.
-   Formats s and i are not supported at this level.
-
-   This is how the elements of an array or structure are printed
-   with a format.  */
+   according to OPTIONS and SIZE on STREAM.  Formats s and i are not
+   supported at this level.  */
 
 void
 print_scalar_formatted (const void *valaddr, struct type *type,
@@ -369,18 +369,8 @@ print_scalar_formatted (const void *vala
   unsigned int len = TYPE_LENGTH (type);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
-  /* If we get here with a string format, try again without it.  Go
-     all the way back to the language printers, which may call us
-     again.  */
-  if (options->format == 's')
-    {
-      struct value_print_options opts = *options;
-      opts.format = 0;
-      opts.deref_ref = 0;
-      val_print (type, valaddr, 0, 0, stream, 0, NULL, &opts,
-		 current_language);
-      return;
-    }
+  /* String printing should go through val_print_scalar_formatted.  */
+  gdb_assert (options->format != 's');
 
   if (len > sizeof(LONGEST) &&
       (TYPE_CODE (type) == TYPE_CODE_INT
Index: src/gdb/valprint.h
===================================================================
--- src.orig/gdb/valprint.h	2011-01-25 16:46:26.857639991 +0000
+++ src/gdb/valprint.h	2011-01-25 17:47:53.597639998 +0000
@@ -126,6 +126,13 @@ extern void val_print_type_code_flags (s
 				       const gdb_byte *valaddr,
 				       struct ui_file *stream);
 
+extern void val_print_scalar_formatted (struct type *,
+					const gdb_byte *, int,
+					const struct value *,
+					const struct value_print_options *,
+					int,
+					struct ui_file *);
+
 extern void print_binary_chars (struct ui_file *, const gdb_byte *,
 				unsigned int, enum bfd_endian);
 
Index: src/gdb/jv-valprint.c
===================================================================
--- src.orig/gdb/jv-valprint.c	2011-01-25 16:46:26.857639991 +0000
+++ src/gdb/jv-valprint.c	2011-01-25 17:47:53.597639998 +0000
@@ -499,8 +499,8 @@ java_val_print (struct type *type, const
     case TYPE_CODE_PTR:
       if (options->format && options->format != 's')
 	{
-	  print_scalar_formatted (valaddr + embedded_offset,
-				  type, options, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      val, options, 0, stream);
 	  break;
 	}
 #if 0
@@ -552,8 +552,8 @@ java_val_print (struct type *type, const
 
 	  opts.format = (options->format ? options->format
 			 : options->output_format);
-	  print_scalar_formatted (valaddr + embedded_offset,
-				  type, &opts, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      val, &opts, 0, stream);
 	}
       else if (TYPE_CODE (type) == TYPE_CODE_CHAR
 	       || (TYPE_CODE (type) == TYPE_CODE_INT
Index: src/gdb/p-valprint.c
===================================================================
--- src.orig/gdb/p-valprint.c	2011-01-25 16:46:26.847639998 +0000
+++ src/gdb/p-valprint.c	2011-01-25 17:47:53.597639998 +0000
@@ -139,8 +139,8 @@ pascal_val_print (struct type *type, con
     case TYPE_CODE_PTR:
       if (options->format && options->format != 's')
 	{
-	  print_scalar_formatted (valaddr + embedded_offset, type,
-				  options, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      original_value, options, 0, stream);
 	  break;
 	}
       if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type))
@@ -337,8 +337,8 @@ pascal_val_print (struct type *type, con
     case TYPE_CODE_ENUM:
       if (options->format)
 	{
-	  print_scalar_formatted (valaddr + embedded_offset, type,
-				  options, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      original_value, options, 0, stream);
 	  break;
 	}
       len = TYPE_NFIELDS (type);
@@ -363,8 +363,8 @@ pascal_val_print (struct type *type, con
 
     case TYPE_CODE_FLAGS:
       if (options->format)
-	  print_scalar_formatted (valaddr + embedded_offset, type,
-				  options, 0, stream);
+	val_print_scalar_formatted (type, valaddr, embedded_offset,
+				    original_value, options, 0, stream);
       else
 	val_print_type_code_flags (type, valaddr + embedded_offset, stream);
       break;
@@ -372,8 +372,8 @@ pascal_val_print (struct type *type, con
     case TYPE_CODE_FUNC:
       if (options->format)
 	{
-	  print_scalar_formatted (valaddr + embedded_offset, type,
-				  options, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      original_value, options, 0, stream);
 	  break;
 	}
       /* FIXME, we should consider, at least for ANSI C language, eliminating
@@ -392,8 +392,8 @@ pascal_val_print (struct type *type, con
 
 	  opts.format = (options->format ? options->format
 			 : options->output_format);
-	  print_scalar_formatted (valaddr + embedded_offset, type,
-				  &opts, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      original_value, &opts, 0, stream);
 	}
       else
 	{
@@ -427,8 +427,8 @@ pascal_val_print (struct type *type, con
 
 	  opts.format = (options->format ? options->format
 			 : options->output_format);
-	  print_scalar_formatted (valaddr + embedded_offset, type,
-				  &opts, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      original_value, &opts, 0, stream);
 	}
       else
 	{
@@ -443,8 +443,8 @@ pascal_val_print (struct type *type, con
 
 	  opts.format = (options->format ? options->format
 			 : options->output_format);
-	  print_scalar_formatted (valaddr + embedded_offset, type,
-				  &opts, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      original_value, &opts, 0, stream);
 	}
       else
 	{
@@ -461,8 +461,8 @@ pascal_val_print (struct type *type, con
     case TYPE_CODE_FLT:
       if (options->format)
 	{
-	  print_scalar_formatted (valaddr + embedded_offset, type,
-				  options, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      original_value, options, 0, stream);
 	}
       else
 	{
Index: src/gdb/ada-valprint.c
===================================================================
--- src.orig/gdb/ada-valprint.c	2011-01-25 16:46:26.857639991 +0000
+++ src/gdb/ada-valprint.c	2011-01-25 17:47:53.597639998 +0000
@@ -788,8 +788,8 @@ ada_val_print_1 (struct type *type, cons
 	      struct value_print_options opts = *options;
 
 	      opts.format = format;
-	      print_scalar_formatted (valaddr + offset_aligned,
-				      type, &opts, 0, stream);
+	      val_print_scalar_formatted (type, valaddr, offset_aligned,
+					  original_value, &opts, 0, stream);
 	    }
           else if (ada_is_system_address_type (type))
             {
@@ -827,8 +827,8 @@ ada_val_print_1 (struct type *type, cons
     case TYPE_CODE_ENUM:
       if (options->format)
 	{
-	  print_scalar_formatted (valaddr + offset_aligned,
-				  type, options, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, offset_aligned,
+				      original_value, options, 0, stream);
 	  break;
 	}
       len = TYPE_NFIELDS (type);
@@ -858,8 +858,8 @@ ada_val_print_1 (struct type *type, cons
 
     case TYPE_CODE_FLAGS:
       if (options->format)
-	print_scalar_formatted (valaddr + offset_aligned,
-				type, options, 0, stream);
+	val_print_scalar_formatted (type, valaddr, offset_aligned,
+				    original_value, options, 0, stream);
       else
 	val_print_type_code_flags (type, valaddr + offset_aligned, stream);
       break;
Index: src/gdb/f-valprint.c
===================================================================
--- src.orig/gdb/f-valprint.c	2011-01-25 16:46:26.857639991 +0000
+++ src/gdb/f-valprint.c	2011-01-25 17:47:53.597639998 +0000
@@ -283,8 +283,8 @@ f_val_print (struct type *type, const gd
     case TYPE_CODE_PTR:
       if (options->format && options->format != 's')
 	{
-	  print_scalar_formatted (valaddr + embedded_offset,
-				  type, options, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      original_value, options, 0, stream);
 	  break;
 	}
       else
@@ -352,8 +352,8 @@ f_val_print (struct type *type, const gd
     case TYPE_CODE_FUNC:
       if (options->format)
 	{
-	  print_scalar_formatted (valaddr + embedded_offset,
-				  type, options, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      original_value, options, 0, stream);
 	  break;
 	}
       /* FIXME, we should consider, at least for ANSI C language, eliminating
@@ -372,8 +372,8 @@ f_val_print (struct type *type, const gd
 
 	  opts.format = (options->format ? options->format
 			 : options->output_format);
-	  print_scalar_formatted (valaddr + embedded_offset,
-				  type, &opts, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      original_value, options, 0, stream);
 	}
       else
 	{
@@ -395,16 +395,16 @@ f_val_print (struct type *type, const gd
 
     case TYPE_CODE_FLAGS:
       if (options->format)
-	print_scalar_formatted (valaddr + embedded_offset,
-				type, options, 0, stream);
+	val_print_scalar_formatted (type, valaddr, embedded_offset,
+				    original_value, options, 0, stream);
       else
 	val_print_type_code_flags (type, valaddr + embedded_offset, stream);
       break;
 
     case TYPE_CODE_FLT:
       if (options->format)
-	print_scalar_formatted (valaddr + embedded_offset,
-				type, options, 0, stream);
+	val_print_scalar_formatted (type, valaddr, embedded_offset,
+				    original_value, options, 0, stream);
       else
 	print_floating (valaddr + embedded_offset, type, stream);
       break;
@@ -429,8 +429,8 @@ f_val_print (struct type *type, const gd
 
 	  opts.format = (options->format ? options->format
 			 : options->output_format);
-	  print_scalar_formatted (valaddr + embedded_offset,
-				  type, &opts, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      original_value, &opts, 0, stream);
 	}
       else
 	{
Index: src/gdb/infcmd.c
===================================================================
--- src.orig/gdb/infcmd.c	2011-01-25 16:46:26.857639991 +0000
+++ src/gdb/infcmd.c	2011-01-25 17:47:53.597639998 +0000
@@ -2110,9 +2110,11 @@ registers_info (char *addr_exp, int fpre
 
 		printf_filtered ("%s: ", start);
 		get_formatted_print_options (&opts, 'x');
-		print_scalar_formatted (value_contents (val),
-					check_typedef (value_type (val)),
-					&opts, 0, gdb_stdout);
+		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");
 	      }
 	    else
Index: src/gdb/m2-valprint.c
===================================================================
--- src.orig/gdb/m2-valprint.c	2011-01-25 17:42:56.617639989 +0000
+++ src/gdb/m2-valprint.c	2011-01-25 17:47:53.607639991 +0000
@@ -388,8 +388,8 @@ m2_val_print (struct type *type, const g
 	print_variable_at_address (type, valaddr + embedded_offset,
 				   stream, recurse, options);
       else if (options->format && options->format != 's')
-	print_scalar_formatted (valaddr + embedded_offset, type,
-				options, 0, stream);
+	val_print_scalar_formatted (type, valaddr, embedded_offset,
+				    original_value, options, 0, stream);
       else
 	{
 	  addr = unpack_pointer (type, valaddr + embedded_offset);
@@ -450,8 +450,8 @@ m2_val_print (struct type *type, const g
     case TYPE_CODE_ENUM:
       if (options->format)
 	{
-	  print_scalar_formatted (valaddr + embedded_offset, type,
-				  options, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      original_value, options, 0, stream);
 	  break;
 	}
       len = TYPE_NFIELDS (type);
@@ -477,8 +477,8 @@ m2_val_print (struct type *type, const g
     case TYPE_CODE_FUNC:
       if (options->format)
 	{
-	  print_scalar_formatted (valaddr + embedded_offset, type,
-				  options, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      original_value, options, 0, stream);
 	  break;
 	}
       /* FIXME, we should consider, at least for ANSI C language, eliminating
@@ -497,8 +497,8 @@ m2_val_print (struct type *type, const g
 
 	  opts.format = (options->format ? options->format
 			 : options->output_format);
-	  print_scalar_formatted (valaddr + embedded_offset, type,
-				  &opts, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      original_value, &opts, 0, stream);
 	}
       else
 	{
@@ -535,8 +535,8 @@ m2_val_print (struct type *type, const g
 
 	  opts.format = (options->format ? options->format
 			 : options->output_format);
-	  print_scalar_formatted (valaddr + embedded_offset, type,
-				  &opts, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      original_value, &opts, 0, stream);
 	}
       else
 	val_print_type_code_int (type, valaddr + embedded_offset, stream);
@@ -549,8 +549,8 @@ m2_val_print (struct type *type, const g
 
 	  opts.format = (options->format ? options->format
 			 : options->output_format);
-	  print_scalar_formatted (valaddr + embedded_offset, type,
-				  &opts, 0, stream);
+	  val_print_scalar_formatted (type, valaddr, embedded_offset,
+				      original_value, &opts, 0, stream);
 	}
       else
 	{
@@ -566,8 +566,8 @@ m2_val_print (struct type *type, const g
 
     case TYPE_CODE_FLT:
       if (options->format)
-	print_scalar_formatted (valaddr + embedded_offset, type,
-				options, 0, stream);
+	val_print_scalar_formatted (type, valaddr, embedded_offset,
+				    original_value, options, 0, stream);
       else
 	print_floating (valaddr + embedded_offset, type, stream);
       break;
Index: src/gdb/valprint.c
===================================================================
--- src.orig/gdb/valprint.c	2011-01-25 16:46:26.857639991 +0000
+++ src/gdb/valprint.c	2011-01-25 17:47:53.607639991 +0000
@@ -514,6 +514,47 @@ val_print_type_code_flags (struct type *
 	}
     }
   fputs_filtered ("]", stream);
+
+/* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
+   according to OPTIONS and SIZE on STREAM.  Format i is not supported
+   at this level.
+
+   This is how the elements of an array or structure are printed
+   with a format.  */
+}
+
+void
+val_print_scalar_formatted (struct type *type,
+			    const gdb_byte *valaddr, int embedded_offset,
+			    const struct value *val,
+			    const struct value_print_options *options,
+			    int size,
+			    struct ui_file *stream)
+{
+  gdb_assert (val != NULL);
+  gdb_assert (valaddr == value_contents_for_printing_const (val));
+
+  /* If we get here with a string format, try again without it.  Go
+     all the way back to the language printers, which may call us
+     again.  */
+  if (options->format == 's')
+    {
+      struct value_print_options opts = *options;
+      opts.format = 0;
+      opts.deref_ref = 0;
+      val_print (type, valaddr, embedded_offset, 0, stream, 0, val, &opts,
+		 current_language);
+      return;
+    }
+
+  /* A scalar object that does not have all bits available can't be
+     printed, because all bits contribute to its representation.  */
+  if (!value_bits_valid (val, TARGET_CHAR_BIT * embedded_offset,
+			      TARGET_CHAR_BIT * TYPE_LENGTH (type)))
+    val_print_optimized_out (stream);
+  else
+    print_scalar_formatted (valaddr + embedded_offset, type,
+			    options, size, stream);
 }
 
 /* Print a number according to FORMAT which is one of d,u,x,o,b,h,w,g.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* TUI, always pass a value to val_print & co (Re: s/print_scalar_formatted/val_print_scalar_formatted/, mostly)
  2011-01-25 18:19 s/print_scalar_formatted/val_print_scalar_formatted/, mostly Pedro Alves
@ 2011-01-25 19:38 ` Pedro Alves
  2011-01-28 16:01 ` [mips-tdep] Re: s/print_scalar_formatted/val_print_scalar_formatted/, mostly Pedro Alves
  1 sibling, 0 replies; 3+ messages in thread
From: Pedro Alves @ 2011-01-25 19:38 UTC (permalink / raw)
  To: gdb-patches

On Tuesday, 25 de January de 2011 18:01:42, Pedro Alves wrote:

> Only a handful of print_scalar_formatted calls are left in the
> tree after this.  mips-tdep.c has 3 that could/should be converted
> to val_print_scalar_formatted, but I didn't bother yet as I'd need to
> make them construct a value too.  TUI has a use that needs fixing (and
> needs similarly to be fixed for always-a-value-passed-to-val_print&co),
> that I plan on fixing (I'm a TUI user!).  MI has one use that
> is unrelated to printing "struct values", so can stay as is.

Ah, I forgot.  In the TUI case, it turns out it's dead code
and it was born that way:
 <http://sourceware.org/ml/gdb-patches/2004-03/msg00115.html>
...

Neither "info reg", neither MI register printing seem to 
do anything fancy with vectors, so I just removed it.

Applied.

-- 
Pedro Alves

2011-01-25  Pedro Alves  <pedro@codesourcery.com>

	gdb/
	* tui/tui-regs.c (tui_register_format): Remove dead code.

---
 gdb/tui/tui-regs.c |   18 +-----------------
 1 file changed, 1 insertion(+), 17 deletions(-)

Index: src/gdb/tui/tui-regs.c
===================================================================
--- src.orig/gdb/tui/tui-regs.c	2010-10-18 20:29:09.000000000 +0100
+++ src/gdb/tui/tui-regs.c	2010-10-18 20:29:41.000000000 +0100
@@ -697,23 +697,7 @@ tui_register_format (struct frame_info *
   stream = tui_sfileopen (256);
   gdb_stdout = stream;
   cleanups = make_cleanup (tui_restore_gdbout, (void*) old_stdout);
-  if (TYPE_VECTOR (type) != 0 && 0)
-    {
-      gdb_byte buf[MAX_REGISTER_SIZE];
-      int len;
-      struct value_print_options opts;
-
-      len = register_size (gdbarch, regnum);
-      fprintf_filtered (stream, "%-14s ", name);
-      get_frame_register (frame, regnum, buf);
-      get_formatted_print_options (&opts, 'f');
-      print_scalar_formatted (buf, type, &opts, len, stream);
-    }
-  else
-    {
-      gdbarch_print_registers_info (gdbarch, stream,
-                                    frame, regnum, 1);
-    }
+  gdbarch_print_registers_info (gdbarch, stream, frame, regnum, 1);
 
   /* Save formatted output in the buffer.  */
   p = tui_file_get_strbuf (stream);

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [mips-tdep] Re: s/print_scalar_formatted/val_print_scalar_formatted/, mostly
  2011-01-25 18:19 s/print_scalar_formatted/val_print_scalar_formatted/, mostly Pedro Alves
  2011-01-25 19:38 ` TUI, always pass a value to val_print & co (Re: s/print_scalar_formatted/val_print_scalar_formatted/, mostly) Pedro Alves
@ 2011-01-28 16:01 ` Pedro Alves
  1 sibling, 0 replies; 3+ messages in thread
From: Pedro Alves @ 2011-01-28 16:01 UTC (permalink / raw)
  To: gdb-patches

On Friday 28 January 2011 18:01:42, Pedro Alves wrote:
> Only a handful of print_scalar_formatted calls are left in the
> tree after this.  mips-tdep.c has 3 that could/should be converted
> to val_print_scalar_formatted, but I didn't bother yet as I'd need to
> make them construct a value too.  

I had actually started doing it for mips-tdep.c, but stopped
after the first conversion.  Might as well push it.  I've
applied the patch below.  The advantage is that
val_print_scalar_formatted will magically know to
print "<unavailable>" for register that haven't been
collected, when unavailable registers support is glued
with unavailable values support.

This suspicious bit,

  if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
    offset =
      register_size (gdbarch, regnum) - register_size (gdbarch, regnum);
  else
    offset = 0;

which always ends up with offset == 0,
had me go look through history, and find out that a long
sequence of cleanups and architecture changes over the years
ended up with equal register_size calls on both terms
of the subtraction, while they were different things originally.

I'm not planning on converting the other print_scalar_formatted
calls in mips-tdep.c myself.

-- 
Pedro Alves

2011-01-28  Pedro Alves  <pedro@codesourcery.com>

	gdb/
	* mips-tdep.c (mips_print_register): Use get_frame_register_value
	and val_print_scalar_formatted.

---
 gdb/mips-tdep.c |   20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

Index: src/gdb/mips-tdep.c
===================================================================
--- src.orig/gdb/mips-tdep.c	2011-01-13 15:07:28.726075000 +0000
+++ src/gdb/mips-tdep.c	2011-01-28 13:47:09.541415001 +0000
@@ -4683,9 +4683,9 @@ mips_print_register (struct ui_file *fil
 		     int regnum)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  gdb_byte raw_buffer[MAX_REGISTER_SIZE];
   int offset;
   struct value_print_options opts;
+  struct value *val;
 
   if (TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT)
     {
@@ -4693,8 +4693,8 @@ mips_print_register (struct ui_file *fil
       return;
     }
 
-  /* Get the data in raw format.  */
-  if (!frame_register_read (frame, regnum, raw_buffer))
+  val = get_frame_register_value (frame, regnum);
+  if (value_optimized_out (val))
     {
       fprintf_filtered (file, "%s: [Invalid]",
 			gdbarch_register_name (gdbarch, regnum));
@@ -4712,16 +4712,12 @@ mips_print_register (struct ui_file *fil
   else
     fprintf_filtered (file, ": ");
 
-  if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
-    offset =
-      register_size (gdbarch, regnum) - register_size (gdbarch, regnum);
-  else
-    offset = 0;
-
   get_formatted_print_options (&opts, 'x');
-  print_scalar_formatted (raw_buffer + offset,
-			  register_type (gdbarch, regnum), &opts, 0,
-			  file);
+  val_print_scalar_formatted (value_type (val),
+			      value_contents_for_printing (val),
+			      value_embedded_offset (val),
+			      val,
+			      &opts, 0, file);
 }
 
 /* Replacement for generic do_registers_info.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-01-28 15:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-25 18:19 s/print_scalar_formatted/val_print_scalar_formatted/, mostly Pedro Alves
2011-01-25 19:38 ` TUI, always pass a value to val_print & co (Re: s/print_scalar_formatted/val_print_scalar_formatted/, mostly) Pedro Alves
2011-01-28 16:01 ` [mips-tdep] Re: s/print_scalar_formatted/val_print_scalar_formatted/, mostly Pedro Alves

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).