From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1812 invoked by alias); 22 Aug 2005 19:00:41 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 1736 invoked by uid 22791); 22 Aug 2005 19:00:26 -0000 Received: from e31.co.us.ibm.com (HELO e31.co.us.ibm.com) (32.97.110.129) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Mon, 22 Aug 2005 19:00:26 +0000 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by e31.co.us.ibm.com (8.12.10/8.12.9) with ESMTP id j7MJ0FF3064660 for ; Mon, 22 Aug 2005 15:00:18 -0400 Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d03relay04.boulder.ibm.com (8.12.10/NCO/VERS6.7) with ESMTP id j7MJ0Mh5356580 for ; Mon, 22 Aug 2005 13:00:22 -0600 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.12.11/8.13.3) with ESMTP id j7MJ0Eao011331 for ; Mon, 22 Aug 2005 13:00:14 -0600 Received: from localhost (dyn94122390.austin.ibm.com [9.41.223.90]) by d03av02.boulder.ibm.com (8.12.11/8.12.11) with ESMTP id j7MJ0CEP011111 for ; Mon, 22 Aug 2005 13:00:14 -0600 Date: Mon, 22 Aug 2005 19:38:00 -0000 From: Dwayne Grant McConnell To: gdb-patches@sources.redhat.com Subject: [PATCH] Have gdb display float infinity. Message-ID: X-X-Sender: decimal1969@rushpost.com@mail.messagingengine.com MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-SW-Source: 2005-08/txt/msg00232.txt.bz2 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 Lotus Notes: Dwayne McConnell/Austin/IBM@IBMUS 2005-08-22 Dwayne Grant McConnell * 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