From 33d7655bb2b3cc12ac5401ae107a0aca33085d6e Mon Sep 17 00:00:00 2001 From: Joel Brobecker Date: Wed, 25 Jul 2012 18:27:21 +0000 Subject: [PATCH] convert_doublest_to_floatformat: handle off-range values. On x86_64-linux targetting AVR, we see the following issues: (gdb) print 1.6e+308 $1 = 0.89002949 (gdb) print 1.6e-308 $3 = 2.87630892 What happens is that GDB is trying to convert the value it read (as a host "long double") into a target "double" value. The routine performing the conversion does not realize that 1.6e+308 is just too large to fit in a double. Similarly, it does not notice that 1.6e-308 is too small to be represented. This patch enhances convert_doublest_to_floatformat to both handle floats that are too small and too large. gdb/ChangeLog: * doublest.c (convert_doublest_to_floatformat): If the exponent is too small, treat the value as zero. If the exponent is too large, treat the value as infinity. --- gdb/ChangeLog | 6 ++++++ gdb/doublest.c | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b5aa8716000..2c1520b5ddc 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2012-07-25 Joel Brobecker + + * doublest.c (convert_doublest_to_floatformat): If the exponent + is too small, treat the value as zero. If the exponent is too + large, treat the value as infinity. + 2012-07-25 Joel Brobecker * configure.ac: Add --enable-lmcheck configure option. diff --git a/gdb/doublest.c b/gdb/doublest.c index c8c9e05932c..f683002020f 100644 --- a/gdb/doublest.c +++ b/gdb/doublest.c @@ -472,6 +472,28 @@ convert_doublest_to_floatformat (CONST struct floatformat *fmt, mant = frexp (dfrom, &exponent); #endif + if (exponent + fmt->exp_bias <= 0) + { + /* The value is too small to be expressed in the destination + type (not enough bits in the exponent. Treat as 0. */ + put_field (uto, order, fmt->totalsize, fmt->exp_start, + fmt->exp_len, 0); + put_field (uto, order, fmt->totalsize, fmt->man_start, + fmt->man_len, 0); + goto finalize_byteorder; + } + + if (exponent + fmt->exp_bias >= (1 << fmt->exp_len) - 1) + { + /* The value is too large to fit into the destination. + Treat as infinity. */ + put_field (uto, order, fmt->totalsize, fmt->exp_start, + fmt->exp_len, fmt->exp_nan); + put_field (uto, order, fmt->totalsize, fmt->man_start, + fmt->man_len, 0); + goto finalize_byteorder; + } + put_field (uto, order, fmt->totalsize, fmt->exp_start, fmt->exp_len, exponent + fmt->exp_bias - 1); -- 2.30.2