From: Dwayne Grant McConnell <dgm69@us.ibm.com>
To: gdb-patches@sources.redhat.com
Subject: [PATCH] Have gdb display float infinity.
Date: Mon, 22 Aug 2005 19:38:00 -0000 [thread overview]
Message-ID: <Pine.WNT.4.63.0508221353540.2128@dwayne> (raw)
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
next reply other threads:[~2005-08-22 19:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-22 19:38 Dwayne Grant McConnell [this message]
2005-08-22 20:28 ` Mark Kettenis
2005-08-22 21:42 ` Dwayne Grant McConnell
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=Pine.WNT.4.63.0508221353540.2128@dwayne \
--to=dgm69@us.ibm.com \
--cc=gdb-patches@sources.redhat.com \
/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