This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Fix for crash printing NaN (PR gdb/13045)


Greetings,

Attached patch fixes gdb crash in PR 13045, which (AFAICT) has been broken
since forever.

Tested on Linux/x86_64 and Linux/i686 (CC_FOR_TARGET="gcc -m32"); no
regressions.

One thing I am not sure about is whether some platforms will cause inferior
to crash on divide-by-zero (the test will fail on such platforms).

Thanks,

--
Paul Pluzhnikov

2011-07-30  Paul Pluzhnikov  <ppluzhnikov@google.com>

	PR gdb/13045
	* doublest.c (convert_doublest_to_floatformat): Pass correct
	mantissa length to put_field.

testsuite/ChangeLog:

2011-07-30  Paul Pluzhnikov  <ppluzhnikov@google.com>

	PR gdb/13045
	* float.exp: Add new test case for PR gdb/13045
	* float.c: New file.


Index: doublest.c
===================================================================
RCS file: /cvs/src/src/gdb/doublest.c,v
retrieving revision 1.48
diff -u -p -r1.48 doublest.c
--- doublest.c	7 Jan 2011 19:36:16 -0000	1.48
+++ doublest.c	30 Jul 2011 22:04:54 -0000
@@ -274,10 +274,6 @@ convert_floatformat_to_doublest (const s
   *to = dto;
 }
 
-static void put_field (unsigned char *, enum floatformat_byteorders,
-		       unsigned int,
-		       unsigned int, unsigned int, unsigned long);
-
 /* Set a field which starts at START and is LEN bytes long.  DATA and
    TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER.  */
 static void
@@ -449,7 +445,7 @@ convert_doublest_to_floatformat (CONST s
 		 fmt->exp_len, fmt->exp_nan);
       /* Be sure it's not infinity, but NaN value is irrel.  */
       put_field (uto, order, fmt->totalsize, fmt->man_start,
-		 32, 1);
+		 fmt->man_len, 1);
       goto finalize_byteorder;
     }
 
Index: testsuite/gdb.base/float.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/float.exp,v
retrieving revision 1.24
diff -u -p -r1.24 float.exp
--- testsuite/gdb.base/float.exp	4 May 2011 19:28:15 -0000	1.24
+++ testsuite/gdb.base/float.exp	30 Jul 2011 22:04:54 -0000
@@ -27,7 +27,7 @@ if $tracelevel {
 #
 
 
-if { [prepare_for_testing float.exp float run.c] } {
+if { [prepare_for_testing float.exp float float.c] } {
     return -1
 }
 
@@ -99,3 +99,6 @@ if { [istarget "alpha*-*-*"] } then {
 } else {
     gdb_test "info float" "No floating.point info available for this processor." "info float (unknown target)"
 }
+
+gdb_test "step"
+gdb_test "finish" "Value returned is .* = (inf|nan).*"
Index: testsuite/gdb.base/float.c
===================================================================
RCS file: testsuite/gdb.base/float.c
diff -N testsuite/gdb.base/float.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.base/float.c	30 Jul 2011 22:04:54 -0000
@@ -0,0 +1,32 @@
+/* This test program is part of GDB, the GNU debugger.
+
+   Copyright 2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   */
+
+float
+foo ()
+{
+  float x = 0.0;
+  x = 1.0 / x;
+  return x;
+}
+
+int
+main ()
+{
+  foo ();
+  return 0;
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]