* 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.
This commit is contained in:
Pedro Alves 2011-01-25 17:59:00 +00:00
parent 66d61a4cab
commit ab2188aa2a
11 changed files with 160 additions and 101 deletions

View File

@ -1,3 +1,20 @@
2011-01-25 Pedro Alves <pedro@codesourcery.com>
* 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.
2011-01-25 Pedro Alves <pedro@codesourcery.com>
* m2-valprint.c (print_unbounded_array): Pass

View File

@ -788,8 +788,8 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr,
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, const gdb_byte *valaddr,
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, const gdb_byte *valaddr,
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;

View File

@ -248,8 +248,8 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
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 gdb_byte *valaddr,
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 gdb_byte *valaddr,
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 gdb_byte *valaddr,
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 gdb_byte *valaddr,
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 gdb_byte *valaddr,
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 gdb_byte *valaddr,
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 gdb_byte *valaddr,
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 gdb_byte *valaddr,
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 gdb_byte *valaddr,
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 gdb_byte *valaddr,
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)),

View File

@ -283,8 +283,8 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
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 gdb_byte *valaddr, int embedded_offset,
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 gdb_byte *valaddr, int embedded_offset,
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 gdb_byte *valaddr, int embedded_offset,
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 gdb_byte *valaddr, int embedded_offset,
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
{

View File

@ -2110,9 +2110,11 @@ registers_info (char *addr_exp, int fpregs)
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

View File

@ -499,8 +499,8 @@ java_val_print (struct type *type, const gdb_byte *valaddr,
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 gdb_byte *valaddr,
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

View File

@ -388,8 +388,8 @@ m2_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
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 gdb_byte *valaddr, int embedded_offset,
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 gdb_byte *valaddr, int embedded_offset,
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 gdb_byte *valaddr, int embedded_offset,
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 gdb_byte *valaddr, int embedded_offset,
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 gdb_byte *valaddr, int embedded_offset,
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 gdb_byte *valaddr, int embedded_offset,
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;

View File

@ -139,8 +139,8 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
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, const gdb_byte *valaddr,
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, const gdb_byte *valaddr,
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, const gdb_byte *valaddr,
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, const gdb_byte *valaddr,
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, const gdb_byte *valaddr,
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, const gdb_byte *valaddr,
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, const gdb_byte *valaddr,
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
{

View File

@ -329,8 +329,11 @@ print_formatted (struct value *val, int size,
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 *type)
}
/* 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 *valaddr, struct type *type,
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

View File

@ -514,6 +514,47 @@ val_print_type_code_flags (struct type *type, const gdb_byte *valaddr,
}
}
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.

View File

@ -126,6 +126,13 @@ extern void val_print_type_code_flags (struct type *type,
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);