From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4142 invoked by alias); 7 Aug 2004 17:18:56 -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 4135 invoked from network); 7 Aug 2004 17:18:56 -0000 Received: from unknown (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org with SMTP; 7 Aug 2004 17:18:56 -0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.10/8.12.10) with ESMTP id i77HIpe3021191 for ; Sat, 7 Aug 2004 13:18:56 -0400 Received: from localhost.redhat.com (porkchop.devel.redhat.com [172.16.58.2]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id i77HIna09094; Sat, 7 Aug 2004 13:18:49 -0400 Received: from gnu.org (localhost [127.0.0.1]) by localhost.redhat.com (Postfix) with ESMTP id E65F92B9D; Sat, 7 Aug 2004 13:18:41 -0400 (EDT) Message-ID: <41150EF1.5060504@gnu.org> Date: Sat, 07 Aug 2004 17:18:00 -0000 From: Andrew Cagney User-Agent: Mozilla/5.0 (X11; U; NetBSD macppc; en-GB; rv:1.4.1) Gecko/20040801 MIME-Version: 1.0 To: Andrew Cagney , Joel Brobecker Cc: gdb-patches@sources.redhat.com Subject: Re: [RFA/mips] Fix crash trying to print long double float References: <20040806181603.GQ1203@gnat.com> <4113E8D6.3000506@gnu.org> <20040806203835.GW1192@gnat.com> <4113F1FB.1000902@gnu.org> In-Reply-To: <4113F1FB.1000902@gnu.org> Content-Type: multipart/mixed; boundary="------------010407080904070407020102" X-SW-Source: 2004-08/txt/msg00206.txt.bz2 This is a multi-part message in MIME format. --------------010407080904070407020102 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-length: 822 >>>> + format = NULL; >>>> + if (format == NULL) >>>> + error ("This GDB does not support %d-bit floating-point values.", >>>> + len & TARGET_CHAR_BIT); >>>> + return format; >>>> } >> >> >> >> Why do you use a variable? wouldn't have it been simpler to >> add one line at the end like this: >> >> error ("bla bla bla"); >> return NULL; /* Will never be reached. */ > > > And: > if (TARGET_FLOAT_FORMAT != NULL && len * TARGET_CHAR_BIT == TARGET_FLOAT_BIT) > return TARGET_FLOAT_FORMAT; > ... > else > error ("blah, blah"); > I don't trust *_FORMAT to be non-NULL. By deleting architecture methods of my PPC config I reproduced the crash (outch!). I've committed the attached to both the mainline and branch (the error message was tweaked slightly). Andrew --------------010407080904070407020102 Content-Type: text/plain; name="diffs" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="diffs" Content-length: 3150 2004-08-07 Andrew Cagney * doublest.c: Update copyright. (floatformat_from_length): Call error when floatformat is NULL. (extract_floating_by_length): Remove NULL fmt check. (store_floating_by_length): Ditto. Index: doublest.c =================================================================== RCS file: /cvs/src/src/gdb/doublest.c,v retrieving revision 1.18 diff -p -u -r1.18 doublest.c --- doublest.c 29 Jul 2004 19:33:22 -0000 1.18 +++ doublest.c 7 Aug 2004 17:09:17 -0000 @@ -1,8 +1,8 @@ /* Floating point routines for GDB, the GNU debugger. Copyright 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, - 1996, 1997, 1998, 1999, 2000, 2001, 2003 Free Software Foundation, - Inc. + 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004 Free Software + Foundation, Inc. This file is part of GDB. @@ -618,8 +618,8 @@ floatformat_from_doublest (const struct /* Return a floating-point format for a floating-point variable of - length LEN. Return NULL, if no suitable floating-point format - could be found. + length LEN. If no suitable floating-point format is found, an + error is thrown. We need this functionality since information about the floating-point format of a type is not always available to GDB; the @@ -633,12 +633,13 @@ floatformat_from_doublest (const struct static const struct floatformat * floatformat_from_length (int len) { + const struct floatformat *format; if (len * TARGET_CHAR_BIT == TARGET_FLOAT_BIT) - return TARGET_FLOAT_FORMAT; + format = TARGET_FLOAT_FORMAT; else if (len * TARGET_CHAR_BIT == TARGET_DOUBLE_BIT) - return TARGET_DOUBLE_FORMAT; + format = TARGET_DOUBLE_FORMAT; else if (len * TARGET_CHAR_BIT == TARGET_LONG_DOUBLE_BIT) - return TARGET_LONG_DOUBLE_FORMAT; + format = TARGET_LONG_DOUBLE_FORMAT; /* On i386 the 'long double' type takes 96 bits, while the real number of used bits is only 80, both in processor and in memory. @@ -646,9 +647,13 @@ floatformat_from_length (int len) else if ((TARGET_LONG_DOUBLE_FORMAT != NULL) && (len * TARGET_CHAR_BIT == TARGET_LONG_DOUBLE_FORMAT->totalsize)) - return TARGET_LONG_DOUBLE_FORMAT; - - return NULL; + format = TARGET_LONG_DOUBLE_FORMAT; + else + format = NULL; + if (format == NULL) + error ("Unrecognized %d-bit floating-point type.", + len & TARGET_CHAR_BIT); + return format; } const struct floatformat * @@ -675,12 +680,6 @@ extract_floating_by_length (const void * const struct floatformat *fmt = floatformat_from_length (len); DOUBLEST val; - if (fmt == NULL) - { - warning ("Can't extract a floating-point number of %d bytes.", len); - return NAN; - } - floatformat_to_doublest (fmt, addr, &val); return val; } @@ -699,13 +698,6 @@ store_floating_by_length (void *addr, in { const struct floatformat *fmt = floatformat_from_length (len); - if (fmt == NULL) - { - warning ("Can't store a floating-point number of %d bytes.", len); - memset (addr, 0, len); - return; - } - floatformat_from_doublest (fmt, &val, addr); } --------------010407080904070407020102--