This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[rfc][32/37] Eliminate builtin_type_ macros: Update value-printing code
- From: uweigand at de dot ibm dot com
- To: gdb-patches at sourceware dot org
- Date: Sun, 31 Aug 2008 19:51:17 +0200
- Subject: [rfc][32/37] Eliminate builtin_type_ macros: Update value-printing code
- References: <20080831175045.128504000@de.ibm.com>
Hello,
this removes a number of builtin_type_ uses remaining in value-printing code.
Note that the printcmd.c locations still access current_gdbarch after this
patch; making the print routines architecture-aware will require some
additional follow-on effort.
Bye,
Ulrich
ChangeLog:
* 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.
Index: gdb-head/gdb/expprint.c
===================================================================
--- gdb-head.orig/gdb/expprint.c
+++ gdb-head/gdb/expprint.c
@@ -237,7 +237,8 @@ print_subexp_standard (struct expression
nargs++;
tem = 0;
if (exp->elts[pc + 4].opcode == OP_LONG
- && exp->elts[pc + 5].type == builtin_type_char
+ && exp->elts[pc + 5].type
+ == builtin_type (exp->gdbarch)->builtin_char
&& exp->language_defn->la_language == language_c)
{
/* Attempt to print C character arrays using string syntax.
@@ -252,7 +253,8 @@ print_subexp_standard (struct expression
while (tem < nargs)
{
if (exp->elts[pc].opcode != OP_LONG
- || exp->elts[pc + 1].type != builtin_type_char)
+ || exp->elts[pc + 1].type
+ != builtin_type (exp->gdbarch)->builtin_char)
{
/* Not a simple array of char, use regular array printing. */
tem = 0;
Index: gdb-head/gdb/f-valprint.c
===================================================================
--- gdb-head.orig/gdb/f-valprint.c
+++ gdb-head/gdb/f-valprint.c
@@ -523,26 +523,7 @@ f_val_print (struct type *type, const gd
print_scalar_formatted (valaddr, type, format, 0, stream);
else
{
- val = 0;
- switch (TYPE_LENGTH (type))
- {
- case 1:
- val = unpack_long (builtin_type_f_logical_s1, valaddr);
- break;
-
- case 2:
- val = unpack_long (builtin_type_f_logical_s2, valaddr);
- break;
-
- case 4:
- val = unpack_long (builtin_type_f_logical, valaddr);
- break;
-
- default:
- error (_("Logicals of length %d bytes not supported"),
- TYPE_LENGTH (type));
-
- }
+ val = extract_unsigned_integer (valaddr, TYPE_LENGTH (type));
if (val == 0)
fprintf_filtered (stream, ".FALSE.");
@@ -562,20 +543,7 @@ f_val_print (struct type *type, const gd
break;
case TYPE_CODE_COMPLEX:
- switch (TYPE_LENGTH (type))
- {
- case 8:
- type = builtin_type_f_real;
- break;
- case 16:
- type = builtin_type_f_real_s8;
- break;
- case 32:
- type = builtin_type_f_real_s16;
- break;
- default:
- error (_("Cannot print out complex*%d variables"), TYPE_LENGTH (type));
- }
+ type = TYPE_TARGET_TYPE (type);
fputs_filtered ("(", stream);
print_floating (valaddr, type, stream);
fputs_filtered (",", stream);
Index: gdb-head/gdb/printcmd.c
===================================================================
--- gdb-head.orig/gdb/printcmd.c
+++ gdb-head/gdb/printcmd.c
@@ -309,6 +309,24 @@ print_formatted (struct value *val, int
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 *vala
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;
@@ -1994,17 +2007,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 == ',')
@@ -2048,15 +2050,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
--
Dr. Ulrich Weigand
GNU Toolchain for Linux on System z and Cell BE
Ulrich.Weigand@de.ibm.com