Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: uweigand@de.ibm.com
To: gdb-patches@sourceware.org
Subject: [rfc][32/37] Eliminate builtin_type_ macros: Update value-printing code
Date: Sun, 31 Aug 2008 17:52:00 -0000	[thread overview]
Message-ID: <20080831175138.190112000@de.ibm.com> (raw)
In-Reply-To: <20080831175045.128504000@de.ibm.com>

[-- Attachment #1: diff-type-printfixes --]
[-- Type: text/plain, Size: 6752 bytes --]

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


  parent reply	other threads:[~2008-08-31 17:52 UTC|newest]

Thread overview: 98+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-31 17:53 [rfc][00/37] Eliminate builtin_type_ macros uweigand
2008-08-31 17:52 ` [rfc][05/37] Eliminate builtin_type_ macros: Replace LA_BOOL_TYPE macro uweigand
2008-09-05 18:08   ` Joel Brobecker
2008-08-31 17:52 ` [rfc][19/37] Eliminate builtin_type_ macros: Ada range type handling uweigand
2008-09-06  0:24   ` Joel Brobecker
2008-09-07 15:43     ` Ulrich Weigand
2008-09-09 18:00       ` Joel Brobecker
2008-09-09 20:21         ` Ulrich Weigand
2008-09-09 22:08           ` Joel Brobecker
2008-09-09 22:32             ` Ulrich Weigand
2008-09-10  6:09               ` Joel Brobecker
2008-09-10  9:51                 ` Ulrich Weigand
2008-08-31 17:52 ` [rfc][26/37] Eliminate builtin_type_ macros: Use per-frame architecture uweigand
2008-08-31 17:52 ` [rfc][07/37] Eliminate builtin_type_ macros: Use expression arch for size_t type uweigand
2008-09-05 18:18   ` Joel Brobecker
2008-09-05 20:16     ` Ulrich Weigand
2008-08-31 17:52 ` [rfc][13/37] Eliminate builtin_type_ macros: Update EVAL_SKIP dummy return type uweigand
2008-09-05 22:56   ` Joel Brobecker
2008-09-07 15:40     ` Ulrich Weigand
2008-09-07 15:49       ` Joel Brobecker
2008-08-31 17:52 ` [rfc][15/37] Eliminate builtin_type_ macros: Dereferencing of integer types uweigand
2008-09-01  7:19   ` Tom Tromey
2008-09-02 23:34     ` Ulrich Weigand
2008-09-05 23:02   ` Joel Brobecker
2008-08-31 17:52 ` [rfc][29/37] Eliminate builtin_type_ macros: Update valarith.c routines uweigand
2008-08-31 17:52 ` [rfc][09/37] Eliminate builtin_type_ macros: Make argument promotion explicit uweigand
2008-08-31 17:52 ` [rfc][21/37] Eliminate builtin_type_ macros: Platform-neutral builtin_type_void uweigand
2008-09-06  0:38   ` Joel Brobecker
2008-09-06  4:12     ` Daniel Jacobowitz
2008-09-06 14:00       ` Joel Brobecker
2008-09-07 15:59       ` Ulrich Weigand
2008-09-13 15:23         ` Daniel Jacobowitz
2008-09-13 17:23         ` Joel Brobecker
2008-08-31 17:52 ` [rfc][23/37] Eliminate builtin_type_ macros: Platform-neutral types for internal variables uweigand
2008-09-02 12:43   ` Daniel Jacobowitz
2008-09-02 21:55     ` Ulrich Weigand
2008-09-02 22:00       ` Daniel Jacobowitz
2008-09-02 23:53       ` Ulrich Weigand
2008-08-31 17:52 ` [rfc][24/37] Eliminate builtin_type_ macros: Platform-neutral generic integers uweigand
2008-09-06  3:15   ` Joel Brobecker
2008-09-07 16:44     ` Ulrich Weigand
2008-08-31 17:52 ` [rfc][01/37] Eliminate builtin_type_ macros: Unused write_exp_msymbol parameters uweigand
2008-08-31 17:52 ` [rfc][02/37] Eliminate builtin_type_ macros: Introduce expression architecture uweigand
2008-08-31 17:52 ` [rfc][33/37] Eliminate builtin_type_ macros: Default target word size uweigand
2008-08-31 17:52 ` [rfc][11/37] Eliminate builtin_type_ macros: Update ax-gdb expression evaluator uweigand
2008-08-31 17:52 ` [rfc][30/37] Eliminate builtin_type_ macros: Remove gdbarch_name_of_malloc uweigand
2008-08-31 17:52 ` uweigand [this message]
2008-08-31 17:52 ` [rfc][16/37] Eliminate builtin_type_ macros: Ada fixed/double conversions uweigand
2008-09-05 23:13   ` Joel Brobecker
2008-08-31 17:53 ` [rfc][04/37] Eliminate builtin_type_ macros: Introduce java_language_arch_info uweigand
2008-08-31 17:53 ` [rfc][08/37] Eliminate builtin_type_ macros: Make pointer arithmetic explicit uweigand
2008-09-02 12:38   ` Daniel Jacobowitz
2008-09-02 21:48     ` Ulrich Weigand
2008-09-02 21:52       ` Daniel Jacobowitz
2008-09-04 22:32       ` Tom Tromey
2008-09-05 18:21         ` Joel Brobecker
2008-08-31 17:53 ` [rfc][20/37] Eliminate builtin_type_ macros: Objective-C expression evaluation uweigand
2008-08-31 17:53 ` [rfc][35/37] Eliminate builtin_type_ macros: Use target arch in bsd-uthread.c uweigand
2008-08-31 17:53 ` [rfc][22/37] Eliminate builtin_type_ macros: Platform-neutral "true char" types uweigand
2008-08-31 17:53 ` [rfc][17/37] Eliminate builtin_type_ macros: Ada pos_atr result type uweigand
2008-08-31 17:53 ` [rfc][12/37] Eliminate builtin_type_ macros: Remove redundant coerce_enum/coerce_number uweigand
2008-08-31 17:53 ` [rfc][36/37] Eliminate builtin_type_ macros: Use target arch in solib code uweigand
2008-08-31 17:53 ` [rfc][03/37] Eliminate builtin_type_ macros: Extract bitstring subscript handling uweigand
2008-09-05 18:16   ` Joel Brobecker
2008-09-05 20:17     ` Ulrich Weigand
2008-08-31 17:53 ` [rfc][14/37] Eliminate builtin_type_ macros: Implicit dereferencing of references uweigand
2008-08-31 17:53 ` [rfc][18/37] Eliminate builtin_type_ macros: Ada System.Address special handling uweigand
2008-08-31 17:53 ` [rfc][06/37] Eliminate builtin_type_ macros: Make OP_COMPLEX type explicit uweigand
2008-08-31 17:53 ` [rfc][37/37] Eliminate builtin_type_ macros: Delete the macros uweigand
2008-08-31 17:53 ` [rfc][10/37] Eliminate builtin_type_ macros: Use expression arch for argument promotion uweigand
2008-09-05 22:39   ` Joel Brobecker
2008-08-31 17:53 ` [rfc][27/37] Eliminate builtin_type_ macros: Update C++ ABI handling uweigand
2008-09-05 20:18   ` Ulrich Weigand
2008-08-31 18:12 ` [rfc][34/37] Eliminate builtin_type_ macros: Use target arch in procfs.c uweigand
2008-08-31 18:13 ` [rfc][31/37] Eliminate builtin_type_ macros: Inferior call argument types uweigand
2008-09-06  1:37   ` Joel Brobecker
2008-08-31 18:15 ` [rfc][28/37] Eliminate builtin_type_ macros: Update infcall.c routines uweigand
2008-09-02 12:48   ` Daniel Jacobowitz
2008-09-02 21:56     ` Ulrich Weigand
2008-08-31 18:16 ` [rfc][25/37] Eliminate builtin_type_ macros: Update *-tdep.c files uweigand
2008-08-31 22:20 ` [rfc][00/37] Eliminate builtin_type_ macros Mark Kettenis
2008-09-01  3:46   ` David Miller
2008-09-01 18:57   ` Ulrich Weigand
2008-09-02 10:22     ` Mark Kettenis
2008-09-02 12:30       ` Daniel Jacobowitz
2008-09-02 21:37       ` Ulrich Weigand
2008-09-02 12:50 ` Daniel Jacobowitz
2008-09-02 22:02   ` Ulrich Weigand
2008-09-02 22:12     ` Daniel Jacobowitz
2008-09-06  3:16 ` Joel Brobecker
2008-09-07 16:43   ` Ulrich Weigand
2008-09-09 18:05     ` Joel Brobecker
2008-09-09 20:21       ` Ulrich Weigand
2008-09-09 21:18       ` Joel Brobecker
2008-09-09 22:12         ` Ulrich Weigand
2008-09-10  6:18           ` Joel Brobecker
2008-09-10  9:43             ` Ulrich Weigand
2008-09-10 16:25               ` Joel Brobecker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080831175138.190112000@de.ibm.com \
    --to=uweigand@de.ibm.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox