aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog17
-rw-r--r--gdb/ada-valprint.c12
-rw-r--r--gdb/c-valprint.c56
-rw-r--r--gdb/f-valprint.c24
-rw-r--r--gdb/infcmd.c8
-rw-r--r--gdb/jv-valprint.c8
-rw-r--r--gdb/m2-valprint.c28
-rw-r--r--gdb/p-valprint.c32
-rw-r--r--gdb/printcmd.c28
-rw-r--r--gdb/valprint.c41
-rw-r--r--gdb/valprint.h7
11 files changed, 160 insertions, 101 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 3ad1b84..c56abe1 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,22 @@
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
value_contents_for_printing rather than value_contents, to
m2_print_array_contents. Also pass in the value.
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index d0810c7..bd297c6 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -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;
diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c
index bbe5588..3bd4db2 100644
--- a/gdb/c-valprint.c
+++ b/gdb/c-valprint.c
@@ -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)),
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index 94a70a1..a15e777 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -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
{
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index f589e3c..5efbf39 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -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
diff --git a/gdb/jv-valprint.c b/gdb/jv-valprint.c
index 8c29f37..b282da8 100644
--- a/gdb/jv-valprint.c
+++ b/gdb/jv-valprint.c
@@ -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
diff --git a/gdb/m2-valprint.c b/gdb/m2-valprint.c
index 192c71b..f22ee2f 100644
--- a/gdb/m2-valprint.c
+++ b/gdb/m2-valprint.c
@@ -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;
diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
index f803ddc..ca7606a 100644
--- a/gdb/p-valprint.c
+++ b/gdb/p-valprint.c
@@ -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
{
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index f435f6d..29ffbf5 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -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
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 6ddbed8..b6b96d4 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -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.
diff --git a/gdb/valprint.h b/gdb/valprint.h
index ee9830a..3ad3545 100644
--- a/gdb/valprint.h
+++ b/gdb/valprint.h
@@ -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);