From patchwork Thu Oct 5 17:31:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulrich Weigand X-Patchwork-Id: 23362 Received: (qmail 129566 invoked by alias); 5 Oct 2017 17:31:44 -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 129249 invoked by uid 89); 5 Oct 2017 17:31:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.9 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 mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 05 Oct 2017 17:31:42 +0000 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v95HTXCN019206 for ; Thu, 5 Oct 2017 13:31:40 -0400 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0b-001b2d01.pphosted.com with ESMTP id 2ddqw6meut-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 05 Oct 2017 13:31:40 -0400 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 5 Oct 2017 18:31:39 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 5 Oct 2017 18:31:37 +0100 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v95HVb9L20119564 for ; Thu, 5 Oct 2017 17:31:37 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4639742047 for ; Thu, 5 Oct 2017 18:27:27 +0100 (BST) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 31FA54203F for ; Thu, 5 Oct 2017 18:27:27 +0100 (BST) Received: from oc3748833570.ibm.com (unknown [9.152.213.178]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Thu, 5 Oct 2017 18:27:27 +0100 (BST) Received: by oc3748833570.ibm.com (Postfix, from userid 1000) id BD040D835F0; Thu, 5 Oct 2017 19:31:36 +0200 (CEST) Subject: [RFC v2][3/3] Target FP printing: Use floatformat_to_string in tdep code To: gdb-patches@sourceware.org Date: Thu, 5 Oct 2017 19:31:36 +0200 (CEST) From: "Ulrich Weigand" MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17100517-0040-0000-0000-000003DFB0E3 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17100517-0041-0000-0000-000025E12095 Message-Id: <20171005173136.BD040D835F0@oc3748833570.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-05_08:, , 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-1710050240 [RFC v2][3/3] Target FP printing: Use floatformat_to_string in tdep code A few tdep files use target-specific printing routines to output values in the floating-point registers. To get rid of host floating-point code, this patch changes them to use floatformat_to_string instead. No functional change intended, the resulting output should look the same. Bye, Ulrich ChangeLog: * i387-tdep.c (print_i387_value): Use floatformat_to_string. * sh64-tdep.c (sh64_do_fp_register): Likewise. * mips-tdep.c (mips_print_fp_register): Likewise. Index: binutils-gdb/gdb/i387-tdep.c =================================================================== --- binutils-gdb.orig/gdb/i387-tdep.c +++ binutils-gdb/gdb/i387-tdep.c @@ -36,23 +36,14 @@ 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 + const struct floatformat *fmt + = floatformat_from_type (i387_ext_type (gdbarch)); + std::string str = floatformat_to_string (fmt, raw, " %-+27.19g"); + fprintf_filtered (file, "%s", str.c_str ()); } /* Print the classification for the register contents RAW. */ 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,16 @@ 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); + const struct floatformat *fmt + = floatformat_from_type (builtin_type (gdbarch)->builtin_float); + std::string str = floatformat_to_string (fmt, raw_buffer, "%-10.9g"); + fprintf_filtered (file, "%s", str.c_str ()); /* Print the fp register as hex. */ fprintf_filtered (file, "\t(raw "); Index: binutils-gdb/gdb/mips-tdep.c =================================================================== --- binutils-gdb.orig/gdb/mips-tdep.c +++ binutils-gdb/gdb/mips-tdep.c @@ -6256,8 +6256,12 @@ 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; + std::string flt_str, dbl_str; + + const struct floatformat *flt_fmt + = floatformat_from_type (builtin_type (gdbarch)->builtin_float); + const struct floatformat *dbl_fmt + = floatformat_from_type (builtin_type (gdbarch)->builtin_double); raw_buffer = ((gdb_byte *) @@ -6275,31 +6279,21 @@ 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); + flt_str = floatformat_to_string (flt_fmt, raw_buffer, "%-17.9g"); get_formatted_print_options (&opts, 'x'); print_scalar_formatted (raw_buffer, builtin_type (gdbarch)->builtin_uint32, &opts, 'w', file); - fprintf_filtered (file, " flt: "); - if (inv1) - fprintf_filtered (file, " "); - else - fprintf_filtered (file, "%-17.9g", flt1); + fprintf_filtered (file, " flt: %s", flt_str.c_str ()); 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); + dbl_str = floatformat_to_string (dbl_fmt, raw_buffer, "%-24.17g"); - fprintf_filtered (file, " dbl: "); - if (inv2) - fprintf_filtered (file, ""); - else - fprintf_filtered (file, "%-24.17g", doub); + fprintf_filtered (file, " dbl: %s", dbl_str.c_str ()); } } else @@ -6308,29 +6302,18 @@ mips_print_fp_register (struct ui_file * /* 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); + flt_str = floatformat_to_string (flt_fmt, raw_buffer, "%-17.9g"); mips_read_fp_register_double (frame, regnum, raw_buffer); - doub = unpack_double (builtin_type (gdbarch)->builtin_double, - raw_buffer, &inv2); + dbl_str = floatformat_to_string (dbl_fmt, raw_buffer, "%-24.17g"); get_formatted_print_options (&opts, 'x'); print_scalar_formatted (raw_buffer, builtin_type (gdbarch)->builtin_uint64, &opts, 'g', file); - fprintf_filtered (file, " flt: "); - if (inv1) - fprintf_filtered (file, ""); - else - fprintf_filtered (file, "%-17.9g", flt1); - - fprintf_filtered (file, " dbl: "); - if (inv2) - fprintf_filtered (file, ""); - else - fprintf_filtered (file, "%-24.17g", doub); + fprintf_filtered (file, " flt: %s", flt_str.c_str ()); + fprintf_filtered (file, " dbl: %s", dbl_str.c_str ()); } }