01917d
commit 00d5215ecec4fa0a78dcc37fec9425593753eb66
01917d
Author: Ulrich Weigand <ulrich.weigand@de.ibm.com>
01917d
Date:   Tue Sep 6 17:33:15 2016 +0200
01917d
01917d
    Support 128-bit IEEE floating-point types on Intel and Power
01917d
    
01917d
    Now that all the prerequisites are in place, this commit finally adds support
01917d
    for handling the __float128 type on Intel and Power, by providing appropriate
01917d
    platform-specific versions of the floatformat_for_type callback.
01917d
    
01917d
    Since at this point we do not yet have any indication in the debug info to
01917d
    distinguish different floating-point formats of the same length, we simply
01917d
    use the type name as hint.  Types named "__float128" get the IEEE format.
01917d
    In addition to handling "__float128" itself, we also recognize "_Float128"
01917d
    and (on Power) "_Float64x", as well as the complex versions of those.
01917d
    (As pointed out by Joseph Myers, starting with GCC 7, __float128 is just
01917d
    a typedef for _Float128 -- but it's good to handle this anyway.)
01917d
    
01917d
    A new test case does some simple verification that the format is decoded
01917d
    correctly, using both __float128 and "long double" to make sure using both
01917d
    in the same file still works.  Another new test verifies handling of the
01917d
    _FloatN and _FloatNx types supported by GCC 7, as well as the complex
01917d
    versions of those types.
01917d
    
01917d
    Note that this still only supports basic format decoding and encoding.
01917d
    We do not yet support the GNU extension 'g' suffix for __float128 constants.
01917d
    In addition, since all *arithmetic* on floating-point values is still
01917d
    performed in native host "long double" arithmetic, if that format is not
01917d
    able to encode all target __float128 values, we may get incorrect results.
01917d
    (To fix this would require implementing fully synthetic target floating-
01917d
    point arithmetic along the lines of GCC's real.c, presumably using MPFR.)
01917d
    
01917d
    gdb/ChangeLog:
01917d
    
01917d
            * i386-tdep.c (i386_floatformat_for_type): New function.
01917d
            (i386_gdbarch_init): Install it.
01917d
            * ppc-linux-tdep.c (ppc_floatformat_for_type): New function.
01917d
            (ppc_linux_init_abi): Install it.
01917d
    
01917d
    gdb/testsuite/ChangeLog:
01917d
    
01917d
            * gdb.base/float128.c: New file.
01917d
            * gdb.base/float128.exp: Likewise.
01917d
            * gdb.base/floatn.c: Likewise.
01917d
            * gdb.base/floatn.exp: Likewise.
01917d
    
01917d
    Signed-off-by: Ulrich Weigand <ulrich.weigand@de.ibm.com>
01917d
01917d
### a/gdb/ChangeLog
01917d
### b/gdb/ChangeLog
01917d
## -1,5 +1,12 @@
01917d
 2016-09-05  Ulrich Weigand  <uweigand@de.ibm.com>
01917d
 
01917d
+	* i386-tdep.c (i386_floatformat_for_type): New function.
01917d
+	(i386_gdbarch_init): Install it.
01917d
+	* ppc-linux-tdep.c (ppc_floatformat_for_type): New function.
01917d
+	(ppc_linux_init_abi): Install it.
01917d
+
01917d
+2016-09-05  Ulrich Weigand  <uweigand@de.ibm.com>
01917d
+
01917d
 	* gdbarch.sh (floatformat_for_type): New gdbarch callback.
01917d
 	* gdbarch.h, gdbarch.c: Re-generate.
01917d
 	* arch-utils.h (default_floatformat_for_type): New prototype.
01917d
Index: gdb-7.6.1/gdb/i386-tdep.c
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/gdb/i386-tdep.c	2017-03-11 22:05:54.267721188 +0100
01917d
+++ gdb-7.6.1/gdb/i386-tdep.c	2017-03-11 22:07:59.209585676 +0100
01917d
@@ -7495,6 +7495,23 @@
01917d
     }
01917d
 }
01917d
 
01917d
+/* Return a floating-point format for a floating-point variable of
01917d
+   length LEN in bits.  If non-NULL, NAME is the name of its type.
01917d
+   If no suitable type is found, return NULL.  */
01917d
+
01917d
+static const struct floatformat **
01917d
+i386_floatformat_for_type (struct gdbarch *gdbarch,
01917d
+			   const char *name, int len)
01917d
+{
01917d
+  if (len == 128 && name)
01917d
+    if (strcmp (name, "__float128") == 0
01917d
+	|| strcmp (name, "_Float128") == 0
01917d
+	|| strcmp (name, "complex _Float128") == 0)
01917d
+      return floatformats_ia64_quad;
01917d
+
01917d
+  return default_floatformat_for_type (gdbarch, name, len);
01917d
+}
01917d
+
01917d
 static int
01917d
 i386_validate_tdesc_p (struct gdbarch_tdep *tdep,
01917d
 		       struct tdesc_arch_data *tdesc_data)
01917d
@@ -7640,6 +7657,9 @@
01917d
      alignment.  */
01917d
   set_gdbarch_long_double_bit (gdbarch, 96);
01917d
 
01917d
+  /* Support for floating-point data type variants.  */
01917d
+  set_gdbarch_floatformat_for_type (gdbarch, i386_floatformat_for_type);
01917d
+
01917d
   /* Register numbers of various important registers.  */
01917d
   set_gdbarch_sp_regnum (gdbarch, I386_ESP_REGNUM); /* %esp */
01917d
   set_gdbarch_pc_regnum (gdbarch, I386_EIP_REGNUM); /* %eip */
01917d
Index: gdb-7.6.1/gdb/ppc-linux-tdep.c
01917d
===================================================================
01917d
--- gdb-7.6.1.orig/gdb/ppc-linux-tdep.c	2017-03-11 22:05:54.267721188 +0100
01917d
+++ gdb-7.6.1/gdb/ppc-linux-tdep.c	2017-03-11 22:08:14.080688571 +0100
01917d
@@ -1691,6 +1691,25 @@
01917d
   record_tdep->ioctl_FIOQSIZE = 0x40086680;
01917d
 }
01917d
 
01917d
+/* Return a floating-point format for a floating-point variable of
01917d
+   length LEN in bits.  If non-NULL, NAME is the name of its type.
01917d
+   If no suitable type is found, return NULL.  */
01917d
+
01917d
+static const struct floatformat **
01917d
+ppc_floatformat_for_type (struct gdbarch *gdbarch,
01917d
+                          const char *name, int len)
01917d
+{
01917d
+  if (len == 128 && name)
01917d
+    if (strcmp (name, "__float128") == 0
01917d
+        || strcmp (name, "_Float128") == 0
01917d
+        || strcmp (name, "_Float64x") == 0
01917d
+        || strcmp (name, "complex _Float128") == 0
01917d
+        || strcmp (name, "complex _Float64x") == 0)
01917d
+      return floatformats_ia64_quad;
01917d
+
01917d
+  return default_floatformat_for_type (gdbarch, name, len);
01917d
+}
01917d
+
01917d
 static void
01917d
 ppc_linux_init_abi (struct gdbarch_info info,
01917d
                     struct gdbarch *gdbarch)
01917d
@@ -1713,6 +1732,9 @@
01917d
   set_gdbarch_long_double_bit (gdbarch, 16 * TARGET_CHAR_BIT);
01917d
   set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double);
01917d
 
01917d
+  /* Support for floating-point data type variants.  */
01917d
+  set_gdbarch_floatformat_for_type (gdbarch, ppc_floatformat_for_type);
01917d
+
01917d
   /* Handle inferior calls during interrupted system calls.  */
01917d
   set_gdbarch_write_pc (gdbarch, ppc_linux_write_pc);
01917d
 
01917d
Index: gdb-7.6.1/gdb/testsuite/gdb.base/float128.c
01917d
===================================================================
01917d
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
01917d
+++ gdb-7.6.1/gdb/testsuite/gdb.base/float128.c	2017-03-11 22:07:59.210585683 +0100
01917d
@@ -0,0 +1,30 @@
01917d
+/* This testcase is part of GDB, the GNU debugger.
01917d
+
01917d
+   Copyright 2016 Free Software Foundation, Inc.
01917d
+
01917d
+   This program is free software; you can redistribute it and/or modify
01917d
+   it under the terms of the GNU General Public License as published by
01917d
+   the Free Software Foundation; either version 3 of the License, or
01917d
+   (at your option) any later version.
01917d
+
01917d
+   This program is distributed in the hope that it will be useful,
01917d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
01917d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
01917d
+   GNU General Public License for more details.
01917d
+
01917d
+   You should have received a copy of the GNU General Public License
01917d
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
01917d
+
01917d
+#include <stdio.h>
01917d
+#include <stdlib.h>
01917d
+
01917d
+long double ld;
01917d
+__float128 f128;
01917d
+
01917d
+int main()
01917d
+{
01917d
+  ld = 1.375l;
01917d
+  f128 = 2.375q;
01917d
+
01917d
+  return 0;
01917d
+}
01917d
Index: gdb-7.6.1/gdb/testsuite/gdb.base/float128.exp
01917d
===================================================================
01917d
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
01917d
+++ gdb-7.6.1/gdb/testsuite/gdb.base/float128.exp	2017-03-11 22:07:59.211585690 +0100
01917d
@@ -0,0 +1,76 @@
01917d
+# Copyright 2016 Free Software Foundation, Inc.
01917d
+
01917d
+# This program is free software; you can redistribute it and/or modify
01917d
+# it under the terms of the GNU General Public License as published by
01917d
+# the Free Software Foundation; either version 3 of the License, or
01917d
+# (at your option) any later version.
01917d
+#
01917d
+# This program is distributed in the hope that it will be useful,
01917d
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
01917d
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
01917d
+# GNU General Public License for more details.
01917d
+#
01917d
+# You should have received a copy of the GNU General Public License
01917d
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
01917d
+
01917d
+# This file is part of the gdb testsuite.  It is intended to test that
01917d
+# gdb could correctly handle floating point constant with a suffix.
01917d
+
01917d
+standard_testfile .c
01917d
+
01917d
+proc do_compile { {opts {}} } {
01917d
+    global srcdir subdir srcfile binfile
01917d
+    set ccopts {debug quiet}
01917d
+    foreach opt $opts {lappend ccopts "additional_flags=$opt"}
01917d
+    gdb_compile "${srcdir}/${subdir}/${srcfile}" "$binfile" executable $ccopts
01917d
+}
01917d
+
01917d
+if { [do_compile] != "" && [do_compile {-mfloat128}] != "" } {
01917d
+    untested "compiler can't handle __float128 type?"
01917d
+    return -1
01917d
+}
01917d
+
01917d
+clean_restart ${binfile}
01917d
+
01917d
+if ![runto_main] then {
01917d
+    perror "couldn't run to breakpoint"
01917d
+    continue
01917d
+}
01917d
+
01917d
+# Run to the breakpoint at return.
01917d
+gdb_breakpoint [gdb_get_line_number "return"]
01917d
+gdb_continue_to_breakpoint "return"
01917d
+
01917d
+# Print the original value of ld and f128
01917d
+gdb_test "print ld" ".* = 1\\.375.*" "The original value of ld is 1.375"
01917d
+gdb_test "print f128" ".* = 2\\.375.*" "The original value of f128 is 2.375"
01917d
+
01917d
+# Test that gdb could correctly recognize float constant expression with a suffix.
01917d
+# FIXME: gdb does not yet recognize the GNU extension 'q' suffix for __float128 constants.
01917d
+gdb_test "print ld=-1.375l" ".* = -1\\.375.*" "Try to change ld to -1.375 with 'print ld=-1.375l'"
01917d
+gdb_test "print f128=-2.375l" ".* = -2\\.375.*" "Try to change f128 to -2.375 with 'print f128=-2.375l'"
01917d
+
01917d
+# Test that gdb could handle the above correctly with "set var" command.
01917d
+set test "set variable ld=10.375l"
01917d
+gdb_test_multiple "set var ld=10.375l" "$test" {
01917d
+    -re "$gdb_prompt $" {
01917d
+	pass "$test"
01917d
+    }
01917d
+    -re "Invalid number.*$gdb_prompt $" {
01917d
+	fail "$test (do not recognize 10.375l)"
01917d
+    }
01917d
+}
01917d
+
01917d
+set test "set variable f128=20.375l"
01917d
+gdb_test_multiple "set var f128=20.375l" "$test" {
01917d
+    -re "$gdb_prompt $" {
01917d
+	pass "$test"
01917d
+    }
01917d
+    -re "Invalid number.*$gdb_prompt $" {
01917d
+	fail "$test (do not recognize 20.375l)"
01917d
+    }
01917d
+}
01917d
+
01917d
+gdb_test "print ld" ".* = 10\\.375.*" "The value of ld is changed to 10.375"
01917d
+gdb_test "print f128" ".* = 20\\.375.*" "The value of f128 is changed to 20.375"
01917d
+
01917d
Index: gdb-7.6.1/gdb/testsuite/gdb.base/floatn.c
01917d
===================================================================
01917d
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
01917d
+++ gdb-7.6.1/gdb/testsuite/gdb.base/floatn.c	2017-03-11 22:07:59.211585690 +0100
01917d
@@ -0,0 +1,48 @@
01917d
+/* This testcase is part of GDB, the GNU debugger.
01917d
+
01917d
+   Copyright 2016 Free Software Foundation, Inc.
01917d
+
01917d
+   This program is free software; you can redistribute it and/or modify
01917d
+   it under the terms of the GNU General Public License as published by
01917d
+   the Free Software Foundation; either version 3 of the License, or
01917d
+   (at your option) any later version.
01917d
+
01917d
+   This program is distributed in the hope that it will be useful,
01917d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
01917d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
01917d
+   GNU General Public License for more details.
01917d
+
01917d
+   You should have received a copy of the GNU General Public License
01917d
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
01917d
+
01917d
+#include <stdio.h>
01917d
+#include <stdlib.h>
01917d
+
01917d
+_Float32 f32;
01917d
+_Float64 f64;
01917d
+_Float128 f128;
01917d
+_Float32x f32x;
01917d
+_Float64x f64x;
01917d
+
01917d
+_Complex _Float32 c32;
01917d
+_Complex _Float64 c64;
01917d
+_Complex _Float128 c128;
01917d
+_Complex _Float32x c32x;
01917d
+_Complex _Float64x c64x;
01917d
+
01917d
+int main()
01917d
+{
01917d
+  f32 = 1.5f32;
01917d
+  f64 = 2.25f64;
01917d
+  f128 = 3.375f128;
01917d
+  f32x = 10.5f32x;
01917d
+  f64x = 20.25f64x;
01917d
+
01917d
+  c32 = 1.5f32 + 1.0if;
01917d
+  c64 = 2.25f64 + 1.0if;
01917d
+  c128 = 3.375f128 + 1.0if;
01917d
+  c32x = 10.5f32x + 1.0if;
01917d
+  c64x = 20.25f64x + 1.0if;
01917d
+
01917d
+  return 0;
01917d
+}
01917d
Index: gdb-7.6.1/gdb/testsuite/gdb.base/floatn.exp
01917d
===================================================================
01917d
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
01917d
+++ gdb-7.6.1/gdb/testsuite/gdb.base/floatn.exp	2017-03-11 22:07:59.211585690 +0100
01917d
@@ -0,0 +1,124 @@
01917d
+# Copyright 2016 Free Software Foundation, Inc.
01917d
+
01917d
+# This program is free software; you can redistribute it and/or modify
01917d
+# it under the terms of the GNU General Public License as published by
01917d
+# the Free Software Foundation; either version 3 of the License, or
01917d
+# (at your option) any later version.
01917d
+#
01917d
+# This program is distributed in the hope that it will be useful,
01917d
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
01917d
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
01917d
+# GNU General Public License for more details.
01917d
+#
01917d
+# You should have received a copy of the GNU General Public License
01917d
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
01917d
+
01917d
+# This file is part of the gdb testsuite.  It is intended to test that
01917d
+# gdb could correctly handle floating point constant with a suffix.
01917d
+
01917d
+standard_testfile .c
01917d
+
01917d
+proc do_compile { {opts {}} } {
01917d
+    global srcdir subdir srcfile binfile
01917d
+    set ccopts {debug quiet}
01917d
+    foreach opt $opts {lappend ccopts "additional_flags=$opt"}
01917d
+    gdb_compile "${srcdir}/${subdir}/${srcfile}" "$binfile" executable $ccopts
01917d
+}
01917d
+
01917d
+if { [do_compile] != "" && [do_compile {-mfloat128}] != "" } {
01917d
+    untested "compiler can't handle _FloatN/_FloatNx types?"
01917d
+    return -1
01917d
+}
01917d
+
01917d
+clean_restart ${binfile}
01917d
+
01917d
+if ![runto_main] then {
01917d
+    perror "couldn't run to breakpoint"
01917d
+    continue
01917d
+}
01917d
+
01917d
+# Run to the breakpoint at return.
01917d
+gdb_breakpoint [gdb_get_line_number "return"]
01917d
+gdb_continue_to_breakpoint "return"
01917d
+
01917d
+# Print the original values of f32, f64, f128, f32x, f64x.
01917d
+gdb_test "print f32" ".* = 1\\.5.*" "The original value of f32 is 1.5"
01917d
+gdb_test "print f64" ".* = 2\\.25.*" "The original value of f64 is 2.25"
01917d
+gdb_test "print f128" ".* = 3\\.375.*" "The original value of f128 is 3.375"
01917d
+gdb_test "print f32x" ".* = 10\\.5.*" "The original value of f32x is 10.5"
01917d
+gdb_test "print f64x" ".* = 20\\.25.*" "The original value of f64x is 20.25"
01917d
+
01917d
+# Test that gdb could correctly recognize float constant expression with a suffix.
01917d
+# FIXME: gdb does not yet recognize the suffix for _FloatN/_FloatNx types.
01917d
+gdb_test "print f32=-1.5" ".* = -1\\.5.*" "Try to change f32 to -1.5 with 'print f32=-1.5'"
01917d
+gdb_test "print f64=-2.25" ".* = -2\\.25.*" "Try to change f64 to -2.25 with 'print f64=-2.25'"
01917d
+gdb_test "print f128=-3.375" ".* = -3\\.375.*" "Try to change f128 to -3.375 with 'print f128=-3.375'"
01917d
+gdb_test "print f32x=-10.5" ".* = -10\\.5.*" "Try to change f32x to -10.5 with 'print f32=-1.5x'"
01917d
+gdb_test "print f64x=-20.25" ".* = -20\\.25.*" "Try to change f64x to -20.25 with 'print f64=-2.25x'"
01917d
+
01917d
+# Test that gdb could handle the above correctly with "set var" command.
01917d
+set test "set variable f32 = 10.5"
01917d
+gdb_test_multiple "set var f32=10.5" "$test" {
01917d
+    -re "$gdb_prompt $" {
01917d
+	pass "$test"
01917d
+    }
01917d
+    -re "Invalid number.*$gdb_prompt $" {
01917d
+	fail "$test (do not recognize 10.5)"
01917d
+    }
01917d
+}
01917d
+
01917d
+set test "set variable f64 = 20.25"
01917d
+gdb_test_multiple "set var f64=20.25" "$test" {
01917d
+    -re "$gdb_prompt $" {
01917d
+	pass "$test"
01917d
+    }
01917d
+    -re "Invalid number.*$gdb_prompt $" {
01917d
+	fail "$test (do not recognize 20.25)"
01917d
+    }
01917d
+}
01917d
+
01917d
+set test "set variable f128 = 30.375"
01917d
+gdb_test_multiple "set var f128=30.375" "$test" {
01917d
+    -re "$gdb_prompt $" {
01917d
+	pass "$test"
01917d
+    }
01917d
+    -re "Invalid number.*$gdb_prompt $" {
01917d
+	fail "$test (do not recognize 30.375)"
01917d
+    }
01917d
+}
01917d
+
01917d
+set test "set variable f32x = 100.5"
01917d
+gdb_test_multiple "set var f32x=100.5" "$test" {
01917d
+    -re "$gdb_prompt $" {
01917d
+	pass "$test"
01917d
+    }
01917d
+    -re "Invalid number.*$gdb_prompt $" {
01917d
+	fail "$test (do not recognize 100.5)"
01917d
+    }
01917d
+}
01917d
+
01917d
+set test "set variable f64x = 200.25"
01917d
+gdb_test_multiple "set var f64x=200.25" "$test" {
01917d
+    -re "$gdb_prompt $" {
01917d
+	pass "$test"
01917d
+    }
01917d
+    -re "Invalid number.*$gdb_prompt $" {
01917d
+	fail "$test (do not recognize 200.25)"
01917d
+    }
01917d
+}
01917d
+
01917d
+gdb_test "print f32" ".* = 10\\.5.*" "The value of f32 is changed to 10.5"
01917d
+gdb_test "print f64" ".* = 20\\.25.*" "The value of f64 is changed to 20.25"
01917d
+gdb_test "print f128" ".* = 30\\.375.*" "The value of f128 is changed to 30.375"
01917d
+gdb_test "print f32x" ".* = 100\\.5.*" "The value of f32x is changed to 100.5"
01917d
+gdb_test "print f64x" ".* = 200\\.25.*" "The value of f64x is changed to 200.25"
01917d
+
01917d
+# Print the original values of c32, c64, c128, c32x, c64x.
01917d
+gdb_test "print c32" ".* = 1\\.5 \\+ 1 \\* I.*" "The original value of c32 is 1.5 + 1 * I"
01917d
+gdb_test "print c64" ".* = 2\\.25 \\+ 1 \\* I.*" "The original value of c64 is 2.25 + 1 * I"
01917d
+gdb_test "print c128" ".* = 3\\.375 \\+ 1 \\* I.*" "The original value of c128 is 3.375 + 1 * I"
01917d
+gdb_test "print c32x" ".* = 10\\.5 \\+ 1 \\* I.*" "The original value of c32x is 10.5 + 1 * I"
01917d
+gdb_test "print c64x" ".* = 20\\.25 \\+ 1 \\* I.*" "The original value of c64x is 20.25 + 1 * I"
01917d
+
01917d
+# FIXME: GDB cannot parse non-trivial complex constants yet.
01917d
+