From patchwork Tue Sep 5 18:21:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulrich Weigand X-Patchwork-Id: 22636 Received: (qmail 54863 invoked by alias); 5 Sep 2017 18:21:14 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 54823 invoked by uid 89); 5 Sep 2017 18:21:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=Eight X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 05 Sep 2017 18:21:08 +0000 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v85IJCg9033363 for ; Tue, 5 Sep 2017 14:21:06 -0400 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 2csx6d8xdn-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 05 Sep 2017 14:21:06 -0400 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 5 Sep 2017 19:21:04 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 5 Sep 2017 19:21:01 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v85IL01j13697070 for ; Tue, 5 Sep 2017 18:21:00 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 415E2AE04D for ; Tue, 5 Sep 2017 19:16:17 +0100 (BST) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 23609AE045 for ; Tue, 5 Sep 2017 19:16:17 +0100 (BST) Received: from oc3748833570.ibm.com (unknown [9.164.150.234]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 5 Sep 2017 19:16:17 +0100 (BST) Received: by oc3748833570.ibm.com (Postfix, from userid 1000) id 37B12D8086F; Tue, 5 Sep 2017 20:21:00 +0200 (CEST) Subject: [RFC][06/19] Target FP: Use print_floating in tdep code To: gdb-patches@sourceware.org Date: Tue, 5 Sep 2017 20:21:00 +0200 (CEST) From: "Ulrich Weigand" MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17090518-0040-0000-0000-000003F5CC36 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17090518-0041-0000-0000-00002096442A Message-Id: <20170905182100.37B12D8086F@oc3748833570.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-09-05_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1709050267 [RFC][06/19] Target FP: Use print_floating in tdep code A few tdep files use target-specific printing routines to output values in the floating-point registers. Now that print_floating should do the right thing for all target FP formats, this shouldn't be necesssary any more (also, this get rid of more host-FP code). Specifically, the i387-tdep file uses a special routine to print the 80-bit extended format using 19 digits. The common print_floating now uses the correct DECIMAL_DIG value of 21 digits. This is two digits more, but those may in some cases make a difference when converting back to the original value, so it seems better to just use the default. In addition, both mips-tdep and sh64-tdep use host FP to print floating-point values. This patch changes them to print_floating as well. Again, this may change the output format a bit, but in general it would appear preferable to use the default print_floating now (this will also now match how all other FP values are printed). Bye, Ulrich ChangeLog: * i387-tdep.c: Do not include "doublest.h". (print_i387_value): Remove. (print_i387_ext): Use print_floating instead of print_i387_value. * mips-tdep.c (mips_print_fp_register): Use print_floating. * sh64-tdep.c (sh64_do_fp_register): Likewise. testsuite/ChangeLog: * gdb.arch/i386-float.exp: Update for larger number of digits printed. Index: binutils-gdb/gdb/i387-tdep.c =================================================================== --- binutils-gdb.orig/gdb/i387-tdep.c +++ binutils-gdb/gdb/i387-tdep.c @@ -18,7 +18,6 @@ along with this program. If not, see . */ #include "defs.h" -#include "doublest.h" #include "frame.h" #include "gdbcore.h" #include "inferior.h" @@ -30,31 +29,6 @@ #include "i387-tdep.h" #include "x86-xstate.h" -/* Print the floating point number specified by RAW. */ - -static void -print_i387_value (struct gdbarch *gdbarch, - const gdb_byte *raw, struct ui_file *file) -{ - DOUBLEST value; - - /* Using extract_typed_floating here might affect the representation - of certain numbers such as NaNs, even if GDB is running natively. - This is fine since our caller already detects such special - numbers and we print the hexadecimal representation anyway. */ - value = extract_typed_floating (raw, i387_ext_type (gdbarch)); - - /* We try to print 19 digits. The last digit may or may not contain - garbage, but we'd better print one too many. We need enough room - to print the value, 1 position for the sign, 1 for the decimal - point, 19 for the digits and 6 for the exponent adds up to 27. */ -#ifdef PRINTF_HAS_LONG_DOUBLE - fprintf_filtered (file, " %-+27.19Lg", (long double) value); -#else - fprintf_filtered (file, " %-+27.19g", (double) value); -#endif -} - /* Print the classification for the register contents RAW. */ static void @@ -89,12 +63,16 @@ print_i387_ext (struct gdbarch *gdbarch, fputs_filtered (" SNaN", file); } else if (exponent < 0x7fff && exponent > 0x0000 && integer) - /* Normal. */ - print_i387_value (gdbarch, raw, file); + { + /* Normal. */ + fputs_filtered (" ", file); + print_floating (raw, i387_ext_type (gdbarch), file); + } else if (exponent == 0x0000) { /* Denormal or zero. */ - print_i387_value (gdbarch, raw, file); + fputs_filtered (" ", file); + print_floating (raw, i387_ext_type (gdbarch), file); if (integer) /* Pseudo-denormal. */ Index: binutils-gdb/gdb/testsuite/gdb.arch/i386-float.exp =================================================================== --- binutils-gdb.orig/gdb/testsuite/gdb.arch/i386-float.exp +++ binutils-gdb/gdb/testsuite/gdb.arch/i386-float.exp @@ -47,9 +47,9 @@ with_test_prefix "val" { } with_test_prefix "smallval" { gdb_test "stepi" ".*fldt.*" - gdb_test "info float" "=>R6: Valid 0x03e5c6f8c103dc90456a \\+3.500000000000000007e-4632\r\n.*" + gdb_test "info float" "=>R6: Valid 0x03e5c6f8c103dc90456a 3.50000000000000000\[0-9\]*e-4632\r\n.*" } with_test_prefix "bigval" { gdb_test "stepi" ".*ret.*" - gdb_test "info float" "=>R5: Valid 0x6a5cc643b78165d7d0e9 \\+7.250000000000000005e\\+3264\r\n.*" + gdb_test "info float" "=>R5: Valid 0x6a5cc643b78165d7d0e9 7.25000000000000000\[0-9\]*e\\+3264\r\n.*" } Index: binutils-gdb/gdb/mips-tdep.c =================================================================== --- binutils-gdb.orig/gdb/mips-tdep.c +++ binutils-gdb/gdb/mips-tdep.c @@ -6256,8 +6256,6 @@ mips_print_fp_register (struct ui_file * { /* Do values for FP (float) regs. */ struct gdbarch *gdbarch = get_frame_arch (frame); gdb_byte *raw_buffer; - double doub, flt1; /* Doubles extracted from raw hex data. */ - int inv1, inv2; raw_buffer = ((gdb_byte *) @@ -6275,8 +6273,6 @@ mips_print_fp_register (struct ui_file * /* 4-byte registers: Print hex and floating. Also print even numbered registers as doubles. */ mips_read_fp_register_single (frame, regnum, raw_buffer); - flt1 = unpack_double (builtin_type (gdbarch)->builtin_float, - raw_buffer, &inv1); get_formatted_print_options (&opts, 'x'); print_scalar_formatted (raw_buffer, @@ -6284,22 +6280,16 @@ mips_print_fp_register (struct ui_file * &opts, 'w', file); fprintf_filtered (file, " flt: "); - if (inv1) - fprintf_filtered (file, " "); - else - fprintf_filtered (file, "%-17.9g", flt1); + print_floating (raw_buffer, + builtin_type (gdbarch)->builtin_float, file); if ((regnum - gdbarch_num_regs (gdbarch)) % 2 == 0) { mips_read_fp_register_double (frame, regnum, raw_buffer); - doub = unpack_double (builtin_type (gdbarch)->builtin_double, - raw_buffer, &inv2); fprintf_filtered (file, " dbl: "); - if (inv2) - fprintf_filtered (file, ""); - else - fprintf_filtered (file, "%-24.17g", doub); + print_floating (raw_buffer, + builtin_type (gdbarch)->builtin_double, file); } } else @@ -6307,30 +6297,24 @@ mips_print_fp_register (struct ui_file * struct value_print_options opts; /* Eight byte registers: print each one as hex, float and double. */ - mips_read_fp_register_single (frame, regnum, raw_buffer); - flt1 = unpack_double (builtin_type (gdbarch)->builtin_float, - raw_buffer, &inv1); - mips_read_fp_register_double (frame, regnum, raw_buffer); - doub = unpack_double (builtin_type (gdbarch)->builtin_double, - raw_buffer, &inv2); get_formatted_print_options (&opts, 'x'); print_scalar_formatted (raw_buffer, builtin_type (gdbarch)->builtin_uint64, &opts, 'g', file); + mips_read_fp_register_single (frame, regnum, raw_buffer); + fprintf_filtered (file, " flt: "); - if (inv1) - fprintf_filtered (file, ""); - else - fprintf_filtered (file, "%-17.9g", flt1); + print_floating (raw_buffer, + builtin_type (gdbarch)->builtin_float, file); + + mips_read_fp_register_double (frame, regnum, raw_buffer); fprintf_filtered (file, " dbl: "); - if (inv2) - fprintf_filtered (file, ""); - else - fprintf_filtered (file, "%-24.17g", doub); + print_floating (raw_buffer, + builtin_type (gdbarch)->builtin_double, file); } } Index: binutils-gdb/gdb/sh64-tdep.c =================================================================== --- binutils-gdb.orig/gdb/sh64-tdep.c +++ binutils-gdb/gdb/sh64-tdep.c @@ -1915,8 +1915,6 @@ sh64_do_fp_register (struct gdbarch *gdb struct frame_info *frame, int regnum) { /* Do values for FP (float) regs. */ unsigned char *raw_buffer; - double flt; /* Double extracted from raw hex data. */ - int inv; /* Allocate space for the float. */ raw_buffer = (unsigned char *) @@ -1927,20 +1925,13 @@ sh64_do_fp_register (struct gdbarch *gdb error (_("can't read register %d (%s)"), regnum, gdbarch_register_name (gdbarch, regnum)); - /* Get the register as a number. */ - flt = unpack_double (builtin_type (gdbarch)->builtin_float, - raw_buffer, &inv); - /* Print the name and some spaces. */ fputs_filtered (gdbarch_register_name (gdbarch, regnum), file); print_spaces_filtered (15 - strlen (gdbarch_register_name (gdbarch, regnum)), file); /* Print the value. */ - if (inv) - fprintf_filtered (file, ""); - else - fprintf_filtered (file, "%-10.9g", flt); + print_floating (raw_buffer, builtin_type (gdbarch)->builtin_float, file); /* Print the fp register as hex. */ fprintf_filtered (file, "\t(raw ");