* [PATCH] Have gdb display float infinity.
@ 2005-08-22 19:38 Dwayne Grant McConnell
2005-08-22 20:28 ` Mark Kettenis
0 siblings, 1 reply; 3+ messages in thread
From: Dwayne Grant McConnell @ 2005-08-22 19:38 UTC (permalink / raw)
To: gdb-patches
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Have gdb display float infinity.
2005-08-22 19:38 [PATCH] Have gdb display float infinity Dwayne Grant McConnell
@ 2005-08-22 20:28 ` Mark Kettenis
2005-08-22 21:42 ` Dwayne Grant McConnell
0 siblings, 1 reply; 3+ messages in thread
From: Mark Kettenis @ 2005-08-22 20:28 UTC (permalink / raw)
To: dgm69; +Cc: gdb-patches
> Date: Mon, 22 Aug 2005 14:00:11 -0500 (Central Daylight Time)
> From: Dwayne Grant McConnell <dgm69@us.ibm.com>
>
> 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.
Thanks! Since you're new, I'll have to ask whether you have a
copyright assignment for gdb?
> 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.)
Yes please! A seperate patch is fine, but make sure it gets in
shortly before or after the fix gets in.
> 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?
Hmm, this indeeds seems to duplicate a fair amount of code. Having
seperate functions for nan and inf is good I think, but do you see a
way to avoid code duplication?
> I have tested this with both ppc and ppc64 but nothing else.
It'd be great if you also could test this on another platform,
preferably amd64, i386 or m68k since those have extended double
formats.
Mark
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Have gdb display float infinity.
2005-08-22 20:28 ` Mark Kettenis
@ 2005-08-22 21:42 ` Dwayne Grant McConnell
0 siblings, 0 replies; 3+ messages in thread
From: Dwayne Grant McConnell @ 2005-08-22 21:42 UTC (permalink / raw)
To: Mark Kettenis; +Cc: gdb-patches
On Mon, 22 Aug 2005, Mark Kettenis wrote:
> > Date: Mon, 22 Aug 2005 14:00:11 -0500 (Central Daylight Time)
> > From: Dwayne Grant McConnell <dgm69@us.ibm.com>
> >
> > 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.
>
> Thanks! Since you're new, I'll have to ask whether you have a
> copyright assignment for gdb?
Yes. I have one for all the toolchain. I have contributed only to glibc up
to this point. Remind me, do I need to give you a reference number or
somesuch?
> > 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.)
>
> Yes please! A seperate patch is fine, but make sure it gets in
> shortly before or after the fix gets in.
Will do.
> > 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?
>
> Hmm, this indeeds seems to duplicate a fair amount of code. Having
> seperate functions for nan and inf is good I think, but do you see a
> way to avoid code duplication?
Let me think about it and I'll submit an alternate patch.
> > I have tested this with both ppc and ppc64 but nothing else.
>
> It'd be great if you also could test this on another platform,
> preferably amd64, i386 or m68k since those have extended double
> formats.
I'll see what I can do.
--
Dwayne Grant McConnell <dgm69@us.ibm.com>
Lotus Notes: Dwayne McConnell/Austin/IBM@IBMUS
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-08-22 20:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-22 19:38 [PATCH] Have gdb display float infinity Dwayne Grant McConnell
2005-08-22 20:28 ` Mark Kettenis
2005-08-22 21:42 ` Dwayne Grant McConnell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox