From patchwork Thu Jun 6 12:23:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 33039 Received: (qmail 104479 invoked by alias); 6 Jun 2019 12:23:32 -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 104405 invoked by uid 89); 6 Jun 2019 12:23:31 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, MIME_BASE64_BLANKS, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: EUR02-VE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr20074.outbound.protection.outlook.com (HELO EUR02-VE1-obe.outbound.protection.outlook.com) (40.107.2.74) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 06 Jun 2019 12:23:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YBnOxv1SPJe1Gmg+1agmDzGqHptyOuMT4OObHJoqXDk=; b=8gBW7BH9oHK8ZQ3sIGtZCQpNV2X2eigK4mFMaeZEKnAxF9fccAWJaTb5NepDK/HMPGODL9I44aFbfVFuWDuC0Drin+O6oKtCQGNfOcz8AiqtsqmVs/PvYvSxcaZkGm1yuYWcLpWWqd34bkeXMkhklNHPaqhWDt51vJzRRG2a4rw= Received: from DB6PR0802MB2133.eurprd08.prod.outlook.com (10.172.227.22) by DB6PR0802MB2405.eurprd08.prod.outlook.com (10.172.250.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1943.22; Thu, 6 Jun 2019 12:23:25 +0000 Received: from DB6PR0802MB2133.eurprd08.prod.outlook.com ([fe80::8c26:bb4b:6c93:9d40]) by DB6PR0802MB2133.eurprd08.prod.outlook.com ([fe80::8c26:bb4b:6c93:9d40%2]) with mapi id 15.20.1965.011; Thu, 6 Jun 2019 12:23:25 +0000 From: Alan Hayward To: "gdb-patches@sourceware.org" CC: nd , Alan Hayward Subject: [PATCH 2/2] Suppress printing of empty bitfields when printing flags Date: Thu, 6 Jun 2019 12:23:24 +0000 Message-ID: <20190606122240.10406-2-alan.hayward@arm.com> References: <20190606122240.10406-1-alan.hayward@arm.com> In-Reply-To: <20190606122240.10406-1-alan.hayward@arm.com> authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alan.Hayward@arm.com; x-ms-oob-tlc-oobclassifiers: OLM:2958; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 MIME-Version: 1.0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Alan.Hayward@arm.com X-IsSubscribed: yes Consider a variable containing: flags A=1 and B=0, 2 bit ranges X=3 and Y=0 When printing, empty flags are suppressed, giving: $1 = [ A X=3 Y=0 ] For consistency, it makes sense to also suppress any bit ranges which are also 0. This now gives us: $2 = [ A X=3 ] Consider the CPSR register on AArch64 made up of many flags and bitfields. DIT is a single bit flag, only used on Armv8.4-A, and TCO is a 2 bit field only used on Armv8.5-A. Printing this in the existing code on Armv8.1-A gives: $3 = [C Z TCO=0] This is confusing for the Armv8.1-A user as TCO does not exist, and would be better shown as: $4 = [C Z] gdb/ChangeLog: 2019-06-06 Alan Hayward * valprint.c (val_print_type_code_flags): Suppress printing of empty bitfields. --- gdb/valprint.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) -- 2.20.1 (Apple Git-117) diff --git a/gdb/valprint.c b/gdb/valprint.c index 4c3d67a9ff..1e05eb0270 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -1225,7 +1225,15 @@ val_print_type_code_flags (struct type *type, const gdb_byte *valaddr, fputs_filtered ("[", stream); for (field = 0; field < nfields; field++) { - if (TYPE_FIELD_NAME (type, field)[0] != '\0') + unsigned field_len = TYPE_FIELD_BITSIZE (type, field); + ULONGEST field_val + = val >> (TYPE_FIELD_BITPOS (type, field) - field_len + 1); + const char *field_name = TYPE_FIELD_NAME (type, field); + + if (field_len < sizeof (ULONGEST) * TARGET_CHAR_BIT) + field_val &= ((ULONGEST) 1 << field_len) - 1; + + if (field_name[0] != '\0' && field_val != 0) { struct type *field_type = TYPE_FIELD_TYPE (type, field); @@ -1234,22 +1242,11 @@ val_print_type_code_flags (struct type *type, const gdb_byte *valaddr, problematic place to notify the user of an internal error though. Instead just fall through and print the field as an int. */ - && TYPE_FIELD_BITSIZE (type, field) == 1) - { - if (val & ((ULONGEST)1 << TYPE_FIELD_BITPOS (type, field))) - fprintf_filtered (stream, " %s", - TYPE_FIELD_NAME (type, field)); - } + && field_len == 1) + fprintf_filtered (stream, " %s", field_name); else { - unsigned field_len = TYPE_FIELD_BITSIZE (type, field); - ULONGEST field_val - = val >> (TYPE_FIELD_BITPOS (type, field) - field_len + 1); - - if (field_len < sizeof (ULONGEST) * TARGET_CHAR_BIT) - field_val &= ((ULONGEST) 1 << field_len) - 1; - fprintf_filtered (stream, " %s=", - TYPE_FIELD_NAME (type, field)); + fprintf_filtered (stream, " %s=", field_name); if (TYPE_CODE (field_type) == TYPE_CODE_ENUM) generic_val_print_enum_1 (field_type, field_val, stream); else