This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
s/print_scalar_formatted/val_print_scalar_formatted/, mostly
- From: Pedro Alves <pedro at codesourcery dot com>
- To: gdb-patches at sourceware dot org
- Date: Tue, 25 Jan 2011 18:01:42 +0000
- Subject: s/print_scalar_formatted/val_print_scalar_formatted/, mostly
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.