diff mbox

[PR,18702] Fix wrong output of x87 registers due to truncation to double on amd64

Message ID 5661BACA.50909@gmail.com
State New
Headers show

Commit Message

Ruslan Kabatsayev Dec. 4, 2015, 4:09 p.m. UTC
When `info float` is used on an AMD64 system, GDB prints floating-point
values of x87 registers with raw contents like 0x361a867a8e0527397ce0 or
0xc4f988454a1ddd3cfdab wrongly. This happens due to truncation to double,
after which the former becomes 0.0, and the latter becomes negative infinity.
This is caused by failed detection of x86-64 host, which results in setting
gdb_host_{float,double,long_double}_format to zeros.
This commit fixes this misdetection, and adds a test to make sure future
commits don't introduce a regression here.

gdb/ChangeLog:

	* configure.host: Fix detection of x86_64 host when setting
	floatformats.
	* testsuite/gdb.arch/i386-float.S: Add a regression test for the fix.
	* testsuite/gdb.arch/i386-float.exp: Add checking of the test results.
---
 gdb/configure.host                    | 2 +-
 gdb/testsuite/gdb.arch/i386-float.S   | 4 ++++
 gdb/testsuite/gdb.arch/i386-float.exp | 6 +++++-
 3 files changed, 10 insertions(+), 2 deletions(-)

Comments

Andrew Burgess Dec. 5, 2015, 10:41 p.m. UTC | #1
* Ruslan Kabatsayev <b7.10110111@gmail.com> [2015-12-04 19:09:46 +0300]:

> When `info float` is used on an AMD64 system, GDB prints floating-point
> values of x87 registers with raw contents like 0x361a867a8e0527397ce0 or
> 0xc4f988454a1ddd3cfdab wrongly. This happens due to truncation to double,
> after which the former becomes 0.0, and the latter becomes negative infinity.
> This is caused by failed detection of x86-64 host, which results in setting
> gdb_host_{float,double,long_double}_format to zeros.
> This commit fixes this misdetection, and adds a test to make sure future
> commits don't introduce a regression here.
> 
> gdb/ChangeLog:
> 
> 	* configure.host: Fix detection of x86_64 host when setting
> 	floatformats.
> 	* testsuite/gdb.arch/i386-float.S: Add a regression test for the fix.
> 	* testsuite/gdb.arch/i386-float.exp: Add checking of the test results.

There's a separate ChangeLog in the gdb/testsuite directory, so you
need to split your entry over these two files.  And remember files
names in the testsuite ChangeLog don't need to have the testsuite/
prefix.

Thanks,
Andrew
Ruslan Kabatsayev Dec. 6, 2015, 6:29 a.m. UTC | #2
On 12/06/2015 01:41 AM, Andrew Burgess wrote:
> * Ruslan Kabatsayev <b7.10110111@gmail.com> [2015-12-04 19:09:46 +0300]:
> 
>> When `info float` is used on an AMD64 system, GDB prints floating-point
>> values of x87 registers with raw contents like 0x361a867a8e0527397ce0 or
>> 0xc4f988454a1ddd3cfdab wrongly. This happens due to truncation to double,
>> after which the former becomes 0.0, and the latter becomes negative infinity.
>> This is caused by failed detection of x86-64 host, which results in setting
>> gdb_host_{float,double,long_double}_format to zeros.
>> This commit fixes this misdetection, and adds a test to make sure future
>> commits don't introduce a regression here.
>>
>> gdb/ChangeLog:
>>
>> 	* configure.host: Fix detection of x86_64 host when setting
>> 	floatformats.
>> 	* testsuite/gdb.arch/i386-float.S: Add a regression test for the fix.
>> 	* testsuite/gdb.arch/i386-float.exp: Add checking of the test results.
> 
> There's a separate ChangeLog in the gdb/testsuite directory, so you
> need to split your entry over these two files.  And remember files
> names in the testsuite ChangeLog don't need to have the testsuite/
> prefix.

gdb/ChangeLog:

	* configure.host: Fix detection of x86_64 host when setting
	floatformats.

gdb/testsuite/ChangeLog:

	* gdb.arch/i386-float.S: Add a regression test for the fix of
	floatformats setup on x86_64 hosts.
	* gdb.arch/i386-float.exp: Add checking of the test results for
	floatformats setup on x86_64 hosts.

> 
> Thanks,
> Andrew
> 
>
diff mbox

Patch

diff --git a/gdb/configure.host b/gdb/configure.host
index 48714f4..ef265eb 100644
--- a/gdb/configure.host
+++ b/gdb/configure.host
@@ -195,7 +195,7 @@  esac
 # "double" and "long double" types.
 
 case "${host}" in
-i[34567]86-*-*)
+i[34567]86-*-*|x86_64-*-*)
 	gdb_host_float_format="&floatformat_ieee_single_little"
 	gdb_host_double_format="&floatformat_ieee_double_little"
 	gdb_host_long_double_format="&floatformat_i387_ext"
diff --git a/gdb/testsuite/gdb.arch/i386-float.S b/gdb/testsuite/gdb.arch/i386-float.S
index 76126c4..f5de8c2 100644
--- a/gdb/testsuite/gdb.arch/i386-float.S
+++ b/gdb/testsuite/gdb.arch/i386-float.S
@@ -29,6 +29,10 @@ 
 SYMBOL(main):
 	fninit
 	fldt    val
+	fldt    bigval
+	fldt    smallval
 	ret
 .data
 	val: .byte 0x00,0x00,0x45,0x07,0x11,0x19,0x22,0xe9,0xfe,0xbf
+	smallval: .byte 0xe9,0xd0,0xd7,0x65,0x81,0xb7,0x43,0xc6,0x5c,0x6a
+	bigval:   .byte 0x6a,0x45,0x90,0xdc,0x03,0xc1,0xf8,0xc6,0xe5,0x03
diff --git a/gdb/testsuite/gdb.arch/i386-float.exp b/gdb/testsuite/gdb.arch/i386-float.exp
index e638ceb..4260f29 100644
--- a/gdb/testsuite/gdb.arch/i386-float.exp
+++ b/gdb/testsuite/gdb.arch/i386-float.exp
@@ -39,5 +39,9 @@  if ![runto_main] then {
 
 gdb_test "stepi" ".*fldt.*" "first stepi"
 gdb_test "info float" ".*R7: Empty   0x00000000000000000000\r\n.*"
-gdb_test "stepi" ".*ret.*" "second stepi"
+gdb_test "stepi" ".*fldt.*" "second stepi"
 gdb_test "info float" ".*=>R7: Valid   0xbffee922191107450000 .*"
+gdb_test "stepi" ".*fldt.*" "third stepi"
+gdb_test "info float" ".*=>R6: Valid   0x03e5c6f8c103dc90456a \\+3.500000000000000007e-4632\r\n.*"
+gdb_test "stepi" ".*ret.*" "fourth stepi"
+gdb_test "info float" ".*=>R5: Valid   0x6a5cc643b78165d7d0e9 \\+7.250000000000000005e\\+3264\r\n.*"