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]

[PATCH] Have gdb display float infinity.


I noticed that gdb does display NaNs in a special way but not infinity. 
This patch changes that. I'm a bit new here so I have a few questions.

1. Should I submit a testcase to go along with the patch? as a separate 
patch? (I have no idea were to put it yet but I figured I would ask.)

2. I simply duplicated floatformat_is_nan() with one minor change to 
produce floatformat_is_inf(). I could have done this differently. Should I 
have changed float_format_is_nan() to float_format_is_nan_or_inf() and 
given the function a parameter for NaN v Inf? Something else?

I have tested this with both ppc and ppc64 but nothing else.

Thanks,
Dwayne

-- 
Dwayne Grant McConnell <dgm69@us.ibm.com>
Lotus Notes: Dwayne McConnell/Austin/IBM@IBMUS

2005-08-22  Dwayne Grant McConnell  <dgm69@us.ibm.com>

	* doublest.c (floatformat_is_inf): New function.
	* doublest.h (floatformat_is_inf): Likewise.
	* valprint.c (print_floating): Use floatformat_is_inf.

diff -urN src.orig/gdb/doublest.c src/gdb/doublest.c
--- src.orig/gdb/doublest.c	2005-08-21 11:53:05.000000000 -0500
+++ src/gdb/doublest.c	2005-08-22 13:26:13.460574187 -0500
@@ -544,6 +544,61 @@
   return 0;
 }
 
+/* Check if VAL is infinity for FMT.  */
+
+int
+floatformat_is_inf (const struct floatformat *fmt,
+		    const bfd_byte *uval)
+{
+  long exponent;
+  unsigned long mant;
+  unsigned int mant_bits, mant_off;
+  int mant_bits_left;
+  enum floatformat_byteorders order;
+  unsigned char newfrom[FLOATFORMAT_LARGEST_BYTES];
+  
+  gdb_assert (fmt != NULL);
+  gdb_assert (fmt->totalsize
+	      <= FLOATFORMAT_LARGEST_BYTES * FLOATFORMAT_CHAR_BIT);
+
+  order = floatformat_normalize_byteorder (fmt, uval, newfrom);
+
+  if (order != fmt->byteorder)
+    uval = newfrom;
+
+  if (! fmt->exp_nan)
+    return 0;
+
+  exponent = get_field (uval, order, fmt->totalsize, fmt->exp_start,
+			fmt->exp_len);
+
+  if (exponent != fmt->exp_nan)
+    return 0;
+
+  mant_bits_left = fmt->man_len;
+  mant_off = fmt->man_start;
+
+  while (mant_bits_left > 0)
+    {
+      mant_bits = min (mant_bits_left, 32);
+
+      mant = get_field (uval, order, fmt->totalsize, mant_off, mant_bits);
+
+      /* If there is an explicit integer bit, mask it off.  */
+      if (mant_off == fmt->man_start
+	  && fmt->intbit == floatformat_intbit_yes)
+	mant &= ~(1 << (mant_bits - 1));
+
+      if (!mant)
+	return 1;
+
+      mant_off += mant_bits;
+      mant_bits_left -= mant_bits;
+    }
+
+  return 0;
+}
+
 /* Convert the mantissa of VAL (which is assumed to be a floating
    point number whose format is described by FMT) into a hexadecimal
    and store it in a static string.  Return a pointer to that string.  */
diff -urN src.orig/gdb/doublest.h src/gdb/doublest.h
--- src.orig/gdb/doublest.h	2005-01-28 00:06:27.000000000 -0600
+++ src/gdb/doublest.h	2005-08-22 13:25:09.455002881 -0500
@@ -62,6 +62,7 @@
 extern int floatformat_is_negative (const struct floatformat *,
 				    const bfd_byte *);
 extern int floatformat_is_nan (const struct floatformat *, const bfd_byte *);
+extern int floatformat_is_inf (const struct floatformat *, const bfd_byte *);
 extern const char *floatformat_mantissa (const struct floatformat *,
 					 const bfd_byte *);
 
diff -urN src.orig/gdb/valprint.c src/gdb/valprint.c
--- src.orig/gdb/valprint.c	2005-06-10 01:07:32.000000000 -0500
+++ src/gdb/valprint.c	2005-08-22 13:24:53.969061247 -0500
@@ -413,6 +413,16 @@
       fprintf_filtered (stream, ")");
       return;
     }
+  if (fmt != NULL && floatformat_is_inf (fmt, valaddr))
+    {
+      if (floatformat_is_negative (fmt, valaddr))
+	fprintf_filtered (stream, "-");
+      fprintf_filtered (stream, "inf(");
+      fputs_filtered ("0x", stream);
+      fputs_filtered (floatformat_mantissa (fmt, valaddr), stream);
+      fprintf_filtered (stream, ")");
+      return;
+    }
 
   /* NOTE: cagney/2002-01-15: The TYPE passed into print_floating()
      isn't necessarily a TYPE_CODE_FLT.  Consequently, unpack_double


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