From patchwork Wed Sep 20 16:30:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulrich Weigand X-Patchwork-Id: 22978 Received: (qmail 124708 invoked by alias); 20 Sep 2017 16:30:40 -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 124677 invoked by uid 89); 20 Sep 2017 16:30:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.8 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=7706 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; Wed, 20 Sep 2017 16:30:31 +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 v8KGU6Un121666 for ; Wed, 20 Sep 2017 12:30:30 -0400 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0b-001b2d01.pphosted.com with ESMTP id 2d3t8uf29y-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 20 Sep 2017 12:30:28 -0400 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 20 Sep 2017 17:30:22 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 20 Sep 2017 17:30:20 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v8KGUJvn14155826; Wed, 20 Sep 2017 16:30:19 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AC90111C04C; Wed, 20 Sep 2017 17:26:21 +0100 (BST) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8D98311C04A; Wed, 20 Sep 2017 17:26:21 +0100 (BST) Received: from oc3748833570.ibm.com (unknown [9.152.213.178]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 20 Sep 2017 17:26:21 +0100 (BST) Received: by oc3748833570.ibm.com (Postfix, from userid 1000) id 628D5D83593; Wed, 20 Sep 2017 18:30:19 +0200 (CEST) Subject: Re: [RFC][02/19] Target FP: Simplify floatformat_from_type To: gdb-patches@sourceware.org Date: Wed, 20 Sep 2017 18:30:19 +0200 (CEST) From: "Ulrich Weigand" Cc: simon.marchi@polymtl.ca (Simon Marchi) In-Reply-To: <20170918190131.E5D12D835CB@oc3748833570.ibm.com> from "Ulrich Weigand" at Sep 18, 2017 09:01:31 PM MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17092016-0040-0000-0000-000003DBBCD4 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17092016-0041-0000-0000-000025DCF366 Message-Id: <20170920163019.628D5D83593@oc3748833570.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-09-20_04:, , 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-1709200222 Simon Marchi wrote: > Since this is where we do the division by > TARGET_CHAR_BIT, and therefore assume (implicitly) that bit is a > multiple of TARGET_CHAR_BIT, I think this is where the assert should be > added. To avoid adding them everywhere, we could make > arch_type/init_type take a size in bits, and do the division and assert > there. And here's the updated floatformat_from_type patch, assuming the above change is in. Bye, Ulrich ChangeLog: * doublest.h (floatformat_from_type): Move to gdbtypes.h. * doublest.c (floatformat_from_type): Move to gdbtypes.c. * gdbtypes.h (union type_specific): Make field floatformat hold just a single struct floatformat, not an array. (floatformat_from_type): Move here. * gdbtypes.c (floatformat_from_type): Move here. Update to changed TYPE_FLOATFORMAT definition. (verify_floatformat): Update to changed TYPE_FLOATFORMAT. (recursive_dump_type): Likewise. (init_float_type): Install correct floatformat for byte order. (arch_float_type): Likewise. Index: binutils-gdb/gdb/doublest.c =================================================================== --- binutils-gdb.orig/gdb/doublest.c +++ binutils-gdb/gdb/doublest.c @@ -770,22 +770,6 @@ floatformat_from_doublest (const struct } -/* Return the floating-point format for a floating-point variable of - type TYPE. */ - -const struct floatformat * -floatformat_from_type (const struct type *type) -{ - struct gdbarch *gdbarch = get_type_arch (type); - const struct floatformat *fmt; - - gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLT); - gdb_assert (TYPE_FLOATFORMAT (type)); - fmt = TYPE_FLOATFORMAT (type)[gdbarch_byte_order (gdbarch)]; - gdb_assert (TYPE_LENGTH (type) >= floatformat_totalsize_bytes (fmt)); - return fmt; -} - /* Extract a floating-point number of type TYPE from a target-order byte-stream at ADDR. Returns the value as type DOUBLEST. */ Index: binutils-gdb/gdb/doublest.h =================================================================== --- binutils-gdb.orig/gdb/doublest.h +++ binutils-gdb/gdb/doublest.h @@ -71,12 +71,6 @@ extern enum float_kind floatformat_class extern const char *floatformat_mantissa (const struct floatformat *, const bfd_byte *); -/* Given TYPE, return its floatformat. TYPE_FLOATFORMAT() may return - NULL. type_floatformat() detects that and returns a floatformat - based on the type size when FLOATFORMAT is NULL. */ - -const struct floatformat *floatformat_from_type (const struct type *type); - /* Return the floatformat's total size in host bytes. */ extern size_t floatformat_totalsize_bytes (const struct floatformat *fmt); Index: binutils-gdb/gdb/gdbtypes.c =================================================================== --- binutils-gdb.orig/gdb/gdbtypes.c +++ binutils-gdb/gdb/gdbtypes.c @@ -2735,22 +2735,30 @@ set_type_code (struct type *type, enum t determined by the floatformat. Returns size to be used. */ static int -verify_floatformat (int bit, const struct floatformat **floatformats) +verify_floatformat (int bit, const struct floatformat *floatformat) { - gdb_assert (floatformats != NULL); - gdb_assert (floatformats[0] != NULL && floatformats[1] != NULL); + gdb_assert (floatformat != NULL); if (bit == -1) - bit = floatformats[0]->totalsize; - gdb_assert (bit >= 0); + bit = floatformat->totalsize; - size_t len = bit / TARGET_CHAR_BIT; - gdb_assert (len >= floatformat_totalsize_bytes (floatformats[0])); - gdb_assert (len >= floatformat_totalsize_bytes (floatformats[1])); + gdb_assert (bit >= 0); + gdb_assert (bit >= floatformat->totalsize); return bit; } +/* Return the floating-point format for a floating-point variable of + type TYPE. */ + +const struct floatformat * +floatformat_from_type (const struct type *type) +{ + gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLT); + gdb_assert (TYPE_FLOATFORMAT (type)); + return TYPE_FLOATFORMAT (type); +} + /* Helper function to initialize the standard scalar types. If NAME is non-NULL, then it is used to initialize the type name. @@ -2843,11 +2851,13 @@ init_float_type (struct objfile *objfile int bit, const char *name, const struct floatformat **floatformats) { + struct gdbarch *gdbarch = get_objfile_arch (objfile); + const struct floatformat *fmt = floatformats[gdbarch_byte_order (gdbarch)]; struct type *t; - bit = verify_floatformat (bit, floatformats); + bit = verify_floatformat (bit, fmt); t = init_type (objfile, TYPE_CODE_FLT, bit, name); - TYPE_FLOATFORMAT (t) = floatformats; + TYPE_FLOATFORMAT (t) = fmt; return t; } @@ -4545,26 +4555,11 @@ recursive_dump_type (struct type *type, case TYPE_SPECIFIC_FLOATFORMAT: printfi_filtered (spaces, "floatformat "); - if (TYPE_FLOATFORMAT (type) == NULL) + if (TYPE_FLOATFORMAT (type) == NULL + || TYPE_FLOATFORMAT (type)->name == NULL) puts_filtered ("(null)"); else - { - puts_filtered ("{ "); - if (TYPE_FLOATFORMAT (type)[0] == NULL - || TYPE_FLOATFORMAT (type)[0]->name == NULL) - puts_filtered ("(null)"); - else - puts_filtered (TYPE_FLOATFORMAT (type)[0]->name); - - puts_filtered (", "); - if (TYPE_FLOATFORMAT (type)[1] == NULL - || TYPE_FLOATFORMAT (type)[1]->name == NULL) - puts_filtered ("(null)"); - else - puts_filtered (TYPE_FLOATFORMAT (type)[1]->name); - - puts_filtered (" }"); - } + puts_filtered (TYPE_FLOATFORMAT (type)->name); puts_filtered ("\n"); break; @@ -4909,11 +4904,12 @@ arch_float_type (struct gdbarch *gdbarch int bit, const char *name, const struct floatformat **floatformats) { + const struct floatformat *fmt = floatformats[gdbarch_byte_order (gdbarch)]; struct type *t; - bit = verify_floatformat (bit, floatformats); + bit = verify_floatformat (bit, fmt); t = arch_type (gdbarch, TYPE_CODE_FLT, bit, name); - TYPE_FLOATFORMAT (t) = floatformats; + TYPE_FLOATFORMAT (t) = fmt; return t; } Index: binutils-gdb/gdb/gdbtypes.h =================================================================== --- binutils-gdb.orig/gdb/gdbtypes.h +++ binutils-gdb/gdb/gdbtypes.h @@ -571,12 +571,11 @@ union type_specific struct gnat_aux_type *gnat_stuff; - /* * FLOATFORMAT is for TYPE_CODE_FLT. It is a pointer to two - floatformat objects that describe the floating-point value - that resides within the type. The first is for big endian - targets and the second is for little endian targets. */ + /* * FLOATFORMAT is for TYPE_CODE_FLT. It is a pointer to a + floatformat object that describes the floating-point value + that resides within the type. */ - const struct floatformat **floatformat; + const struct floatformat *floatformat; /* * For TYPE_CODE_FUNC and TYPE_CODE_METHOD types. */ @@ -1434,6 +1433,9 @@ extern void set_type_vptr_basetype (stru #define TYPE_ERROR_NAME(type) \ (TYPE_NAME (type) ? TYPE_NAME (type) : _("")) +/* Given TYPE, return its floatformat. */ +const struct floatformat *floatformat_from_type (const struct type *type); + struct builtin_type { /* Integral types. */