From: "Ulrich Weigand" <uweigand@de.ibm.com>
To: gdb-patches@sourceware.org
Subject: [9/9] Support __float128 format on Intel and Power
Date: Thu, 25 Aug 2016 15:08:00 -0000 [thread overview]
Message-ID: <20160825150829.9A434C9FB@oc7340732750.ibm.com> (raw)
Hello,
now that all the prerequisites are in place, this patch finally adds support
for handling the __float128 type on Intel and Power, by providing appropriate
platform-specific versions of the floatformat_for_type callback.
Since at this point we do not yet have any indication in the debug info to
distinguish different floating-point formats of the same length, we simply
use the type name as hint. Types named "__float128" get the IEEE format.
A new test case does some simple verification that the format is decoded
correctly, using both __float128 and "long double" to make sure using both
in the same file still works.
Note that this still only supports basic format decoding and encoding.
We do not yet support the GNU extension 'g' suffix for __float128 constants.
In addition, since all *arithmetic* on floating-point values is still
performed in native host "long double" arithmetic, if that format is not
able to encode all target __float128 values, we may get incorrect results.
(To fix this would require implementing fully synthetic target floating-
point arithmetic along the lines of GCC's real.c, presumably using MPFR.)
Tested on x64_64-linux and powerpc64le-linux.
Bye,
Ulrich
ChangeLog:
* i386-tdep.c (i386_floatformat_for_type): New function.
(i386_gdbarch_init): Install it.
* ppc-linux-tdep.c (ppc_floatformat_for_type): New function.
(ppc_linux_init_abi): Install it.
testsuite/ChangeLog:
* gdb.base/float128.c: New file.
* gdb.base/float128.exp: Likewise.
Index: binutils-gdb/gdb/i386-tdep.c
===================================================================
--- binutils-gdb.orig/gdb/i386-tdep.c 2016-08-25 13:11:36.711781338 +0200
+++ binutils-gdb/gdb/i386-tdep.c 2016-08-25 13:11:53.562855148 +0200
@@ -8161,6 +8161,20 @@ i386_fast_tracepoint_valid_at (struct gd
}
}
+/* Return a floating-point format for a floating-point variable of
+ length LEN in bits. If non-NULL, NAME is the name of its type.
+ If no suitable type is found, return NULL. */
+
+const struct floatformat **
+i386_floatformat_for_type (struct gdbarch *gdbarch,
+ const char *name, int len)
+{
+ if (len == 128 && name && strcmp (name, "__float128") == 0)
+ return floatformats_ia64_quad;
+
+ return default_floatformat_for_type (gdbarch, name, len);
+}
+
static int
i386_validate_tdesc_p (struct gdbarch_tdep *tdep,
struct tdesc_arch_data *tdesc_data)
@@ -8370,6 +8384,9 @@ i386_gdbarch_init (struct gdbarch_info i
alignment. */
set_gdbarch_long_double_bit (gdbarch, 96);
+ /* Support for floating-point data type variants. */
+ set_gdbarch_floatformat_for_type (gdbarch, i386_floatformat_for_type);
+
/* Register numbers of various important registers. */
set_gdbarch_sp_regnum (gdbarch, I386_ESP_REGNUM); /* %esp */
set_gdbarch_pc_regnum (gdbarch, I386_EIP_REGNUM); /* %eip */
Index: binutils-gdb/gdb/ppc-linux-tdep.c
===================================================================
--- binutils-gdb.orig/gdb/ppc-linux-tdep.c 2016-08-25 13:11:36.711781338 +0200
+++ binutils-gdb/gdb/ppc-linux-tdep.c 2016-08-25 13:11:53.566855164 +0200
@@ -1628,6 +1628,20 @@ ppc_init_linux_record_tdep (struct linux
record_tdep->ioctl_FIOQSIZE = 0x40086680;
}
+/* Return a floating-point format for a floating-point variable of
+ length LEN in bits. If non-NULL, NAME is the name of its type.
+ If no suitable type is found, return NULL. */
+
+const struct floatformat **
+ppc_floatformat_for_type (struct gdbarch *gdbarch,
+ const char *name, int len)
+{
+ if (len == 128 && name && strcmp (name, "__float128") == 0)
+ return floatformats_ia64_quad;
+
+ return default_floatformat_for_type (gdbarch, name, len);
+}
+
static void
ppc_linux_init_abi (struct gdbarch_info info,
struct gdbarch *gdbarch)
@@ -1651,6 +1665,9 @@ ppc_linux_init_abi (struct gdbarch_info
set_gdbarch_long_double_bit (gdbarch, 16 * TARGET_CHAR_BIT);
set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double);
+ /* Support for floating-point data type variants. */
+ set_gdbarch_floatformat_for_type (gdbarch, ppc_floatformat_for_type);
+
/* Handle inferior calls during interrupted system calls. */
set_gdbarch_write_pc (gdbarch, ppc_linux_write_pc);
Index: binutils-gdb/gdb/testsuite/gdb.base/float128.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-gdb/gdb/testsuite/gdb.base/float128.c 2016-08-25 13:11:53.569855177 +0200
@@ -0,0 +1,30 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2016 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/>. */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+long double ld;
+__float128 f128;
+
+int main()
+{
+ ld = 1.375l;
+ f128 = 2.375q;
+
+ return 0;
+}
Index: binutils-gdb/gdb/testsuite/gdb.base/float128.exp
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils-gdb/gdb/testsuite/gdb.base/float128.exp 2016-08-25 13:11:53.573855195 +0200
@@ -0,0 +1,69 @@
+# Copyright 2005-2016 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/>.
+
+# This file is part of the gdb testsuite. It is intended to test that
+# gdb could correctly handle floating point constant with a suffix.
+
+standard_testfile .c
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+ untested "Couldn't compile ${srcfile}"
+ return -1
+}
+
+clean_restart ${binfile}
+
+if ![runto_main] then {
+ perror "couldn't run to breakpoint"
+ continue
+}
+
+# Run to the breakpoint at return.
+gdb_breakpoint [gdb_get_line_number "return"]
+gdb_continue_to_breakpoint "return"
+
+# Print the original value of ld and f128
+gdb_test "print ld" ".* = 1\.375.*" "The original value of ld is 1.375"
+gdb_test "print f128" ".* = 2\.375.*" "The original value of f128 is 2.375"
+
+# Test that gdb could correctly recognize float constant expression with a suffix.
+# FIXME: gdb does not yet recognize the GNU extension 'q' suffix for __float128 constants.
+gdb_test "print ld=-1.375l" ".* = -1\.375.*" "Try to change ld to -1.375 with 'print ld=-1.375l'"
+gdb_test "print f128=-2.375l" ".* = -2\.375.*" "Try to change f128 to -2.375 with 'print f128=-2.375l'"
+
+# Test that gdb could handle the above correctly with "set var" command.
+set test "set variable ld=10.375l"
+gdb_test_multiple "set var ld=10.375l" "$test" {
+ -re "$gdb_prompt $" {
+ pass "$test"
+ }
+ -re "Invalid number.*$gdb_prompt $" {
+ fail "$test (do not recognize 10.375l)"
+ }
+}
+
+set test "set variable f128=20.375l"
+gdb_test_multiple "set var f128=20.375l" "$test" {
+ -re "$gdb_prompt $" {
+ pass "$test"
+ }
+ -re "Invalid number.*$gdb_prompt $" {
+ fail "$test (do not recognize 20.375l)"
+ }
+}
+
+gdb_test "print ld" ".* = 10\.375.*" "The value of ld is changed to 10.375"
+gdb_test "print f128" ".* = 20\.375.*" "The value of f128 is changed to 20.375"
+
--
Dr. Ulrich Weigand
GNU/Linux compilers and toolchain
Ulrich.Weigand@de.ibm.com
next reply other threads:[~2016-08-25 15:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-25 15:08 Ulrich Weigand [this message]
2016-08-25 23:28 ` Joseph Myers
2016-08-26 18:18 ` [9/9 v2] Support 128-bit IEEE floating-point types " Ulrich Weigand
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=20160825150829.9A434C9FB@oc7340732750.ibm.com \
--to=uweigand@de.ibm.com \
--cc=gdb-patches@sourceware.org \
/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