This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC v2][3/3] Target FP printing: Use floatformat_to_string in tdep code


Maciej W. Rozycki wrote:
> > A few tdep files use target-specific printing routines to output values in
> > the floating-point registers.  To get rid of host floating-point code,
> > this patch changes them to use floatformat_to_string instead.
> > 
> > No functional change intended, the resulting output should look the same.
> 
>  I have now quickly checked it with a single target only and unfortunately 
> the layout still has changed, e.g. in gdb.base/callfuncs.exp it used to 
> be:
> 
> [...]
>  f0:  0xd2f1a9fc flt: -5.18969491e+11   dbl: -0.001
>  f1:  0xbf50624d flt: -0.813999951
>  f2:  0x00000000 flt: 0                 dbl: 0
>  f3:  0x00000000 flt: 0
>  f4:  0xffffffff flt: -nan              dbl: -nan
>  f5:  0xffffffff flt: -nan
>  f6:  0xffffffff flt: -nan              dbl: -nan
>  f7:  0xffffffff flt: -nan
> [...]
> 
> while now it is:
> 
> [...]
>  f0:  0xd2f1a9fc flt: -5.18969491e+11   dbl: -0.001
>  f1:  0xbf50624d flt: -0.813999951
>  f2:  0x00000000 flt: 0                 dbl: 0
>  f3:  0x00000000 flt: 0
>  f4:  0xffffffff flt: -nan(0x7fffff) dbl: -nan(0xfffffffffffff)
>  f5:  0xffffffff flt: -nan(0x7fffff)
>  f6:  0xffffffff flt: -nan(0x7fffff) dbl: -nan(0xfffffffffffff)
>  f7:  0xffffffff flt: -nan(0x7fffff)
> [...]
> 
> so it looks to me that the NaN formatter gets the character count wrong.

I see.  I guess we shouldn't use the special output strings at all
when using formatted printing, but rely on the underlying printer
to handle all cases.  (This actually matches today's behavior of
printf_command, which my patches inadvertently changed.)

Can you verify using this additional patch on top of the series?

Thanks again,
Ulrich

Index: binutils-gdb/gdb/doublest.c
===================================================================
--- binutils-gdb.orig/gdb/doublest.c
+++ binutils-gdb/gdb/doublest.c
@@ -794,22 +794,27 @@ std::string
 floatformat_to_string (const struct floatformat *fmt,
 		       const gdb_byte *in, const char *format)
 {
-  /* Detect invalid representations.  */
-  if (!floatformat_is_valid (fmt, in))
-    return "<invalid float value>";
-
-  /* Handle NaN and Inf.  */
-  enum float_kind kind = floatformat_classify (fmt, in);
-  if (kind == float_nan)
-    {
-      const char *sign = floatformat_is_negative (fmt, in)? "-" : "";
-      const char *mantissa = floatformat_mantissa (fmt, in);
-      return string_printf ("%snan(0x%s)", sign, mantissa);
-    }
-  else if (kind == float_infinite)
+  /* Unless we need to adhere to a specific format, provide special
+     output for certain cases.  */
+  if (format == nullptr)
     {
-      const char *sign = floatformat_is_negative (fmt, in)? "-" : "";
-      return string_printf ("%sinf", sign);
+      /* Detect invalid representations.  */
+      if (!floatformat_is_valid (fmt, in))
+	return "<invalid float value>";
+
+      /* Handle NaN and Inf.  */
+      enum float_kind kind = floatformat_classify (fmt, in);
+      if (kind == float_nan)
+	{
+	  const char *sign = floatformat_is_negative (fmt, in)? "-" : "";
+	  const char *mantissa = floatformat_mantissa (fmt, in);
+	  return string_printf ("%snan(0x%s)", sign, mantissa);
+	}
+      else if (kind == float_infinite)
+	{
+	  const char *sign = floatformat_is_negative (fmt, in)? "-" : "";
+	  return string_printf ("%sinf", sign);
+	}
     }
 
   /* Determine the format string to use on the host side.  */



-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]