aboutsummaryrefslogtreecommitdiff
path: root/gdb/printcmd.c
diff options
context:
space:
mode:
authorUlrich Weigand <uweigand@de.ibm.com>2008-09-11 14:28:47 +0000
committerUlrich Weigand <uweigand@de.ibm.com>2008-09-11 14:28:47 +0000
commitb806fb9a9bd4e0e47382c411d6e9321d1283445b (patch)
tree0b11c8ae8819ea9025164c82b62d0e109ebb35a4 /gdb/printcmd.c
parent3e3b026fee8cd62ac6c2cfc7f86cec972d8f5676 (diff)
downloadgdb-b806fb9a9bd4e0e47382c411d6e9321d1283445b.zip
gdb-b806fb9a9bd4e0e47382c411d6e9321d1283445b.tar.gz
gdb-b806fb9a9bd4e0e47382c411d6e9321d1283445b.tar.bz2
* expprint.c (print_subexp_standard): Compare against builtin type
associated with exp->gdbarch instead of builtin_type_char. * f-valprint.c (f_val_print): Use extract_unsigned_integer to extract values of arbitrary logical type. Handle arbitrary complex types. * printcmd.c (float_type_from_length): New function. (print_scalar_formatted, printf_command): Use it.
Diffstat (limited to 'gdb/printcmd.c')
-rw-r--r--gdb/printcmd.c64
1 files changed, 43 insertions, 21 deletions
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index fae39fe..021e191 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -309,6 +309,24 @@ print_formatted (struct value *val, int format, int size,
format, size, stream);
}
+/* Return builtin floating point type of same length as TYPE.
+ If no such type is found, return TYPE itself. */
+static struct type *
+float_type_from_length (struct gdbarch *gdbarch, struct type *type)
+{
+ const struct builtin_type *builtin = builtin_type (gdbarch);
+ unsigned int len = TYPE_LENGTH (type);
+
+ if (len == TYPE_LENGTH (builtin->builtin_float))
+ type = builtin->builtin_float;
+ else if (len == TYPE_LENGTH (builtin->builtin_double))
+ type = builtin->builtin_double;
+ else if (len == TYPE_LENGTH (builtin->builtin_long_double))
+ type = builtin->builtin_long_double;
+
+ return type;
+}
+
/* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
according to letters FORMAT and SIZE on STREAM.
FORMAT may not be zero. Formats s and i are not supported at this level.
@@ -434,12 +452,7 @@ print_scalar_formatted (const void *valaddr, struct type *type,
break;
case 'f':
- if (len == TYPE_LENGTH (builtin_type_float))
- type = builtin_type_float;
- else if (len == TYPE_LENGTH (builtin_type_double))
- type = builtin_type_double;
- else if (len == TYPE_LENGTH (builtin_type_long_double))
- type = builtin_type_long_double;
+ type = float_type_from_length (current_gdbarch, type);
print_floating (valaddr, type, stream);
break;
@@ -1999,17 +2012,6 @@ printf_command (char *arg, int from_tty)
s1 = s;
val_args[nargs] = parse_to_comma_and_eval (&s1);
- /* If format string wants a float, unchecked-convert the value to
- floating point of the same size */
-
- if (argclass[nargs] == double_arg)
- {
- struct type *type = value_type (val_args[nargs]);
- if (TYPE_LENGTH (type) == sizeof (float))
- deprecated_set_value_type (val_args[nargs], builtin_type_float);
- if (TYPE_LENGTH (type) == sizeof (double))
- deprecated_set_value_type (val_args[nargs], builtin_type_double);
- }
nargs++;
s = s1;
if (*s == ',')
@@ -2053,15 +2055,35 @@ printf_command (char *arg, int from_tty)
break;
case double_arg:
{
- double val = value_as_double (val_args[i]);
- printf_filtered (current_substring, val);
+ struct type *type = value_type (val_args[i]);
+ DOUBLEST val;
+ int inv;
+
+ /* If format string wants a float, unchecked-convert the value
+ to floating point of the same size. */
+ type = float_type_from_length (current_gdbarch, type);
+ val = unpack_double (type, value_contents (val_args[i]), &inv);
+ if (inv)
+ error (_("Invalid floating value found in program."));
+
+ printf_filtered (current_substring, (double) val);
break;
}
case long_double_arg:
#ifdef HAVE_LONG_DOUBLE
{
- long double val = value_as_double (val_args[i]);
- printf_filtered (current_substring, val);
+ struct type *type = value_type (val_args[i]);
+ DOUBLEST val;
+ int inv;
+
+ /* If format string wants a float, unchecked-convert the value
+ to floating point of the same size. */
+ type = float_type_from_length (current_gdbarch, type);
+ val = unpack_double (type, value_contents (val_args[i]), &inv);
+ if (inv)
+ error (_("Invalid floating value found in program."));
+
+ printf_filtered (current_substring, (long double) val);
break;
}
#else