Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Cagney <cagney@gnu.org>
To: Joel Brobecker <brobecker@gnat.com>
Cc: gdb-patches@sources.redhat.com
Subject: Re: [RFA/mips] Fix crash trying to print long double float
Date: Fri, 06 Aug 2004 20:24:00 -0000	[thread overview]
Message-ID: <4113E8D6.3000506@gnu.org> (raw)
In-Reply-To: <20040806181603.GQ1203@gnat.com>

[-- Attachment #1: Type: text/plain, Size: 555 bytes --]

> Because the gdbarch vector tells GDB that TARGET_LONG_DOUBLE_BIT = 64bit,
> we end up returning a NULL floatformat. And unfortunately for us, we
> immediatly use that NULL floatformat to feed it to floatformat_is_valid(),
> which dereferences it without checking that it's not NULL before hand.
> This causes the SEGV.  See values.c:unpack_double():
> 
>         if (!floatformat_is_valid (floatformat_from_type (type), valaddr))
>           {
>             *invp = 1;
>             return 0.0;
>           }

Does the attached stop the crash?

Andrew


[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 3165 bytes --]

2004-08-06  Andrew Cagney  <cagney@gnu.org>

	* 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	6 Aug 2004 20:20:14 -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 
 
 \f
 /* 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 ("This GDB does not support %d-bit floating-point values.",
+	   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);
 }
 

  reply	other threads:[~2004-08-06 20:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-06 18:16 Joel Brobecker
2004-08-06 20:24 ` Andrew Cagney [this message]
2004-08-06 20:38   ` Joel Brobecker
2004-08-06 21:03     ` Andrew Cagney
2004-08-07 17:18       ` Andrew Cagney
2004-08-06 20:32 ` Joel Brobecker
2004-08-07 18:01   ` Andrew Cagney
2004-08-07 18:09     ` Joel Brobecker
2004-08-07 18:22       ` Andrew Cagney
2004-08-08  6:59         ` Joel Brobecker
2004-08-08 16:57           ` Andrew Cagney
2004-08-09  5:46             ` Joel Brobecker

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=4113E8D6.3000506@gnu.org \
    --to=cagney@gnu.org \
    --cc=brobecker@gnat.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