From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 58841 invoked by alias); 3 Mar 2020 04:47:26 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 58833 invoked by uid 89); 3 Mar 2020 04:47:25 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00,FORGED_SPF_HELO,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: NAM12-DM6-obe.outbound.protection.outlook.com Received: from mail-dm6nam12on2076.outbound.protection.outlook.com (HELO NAM12-DM6-obe.outbound.protection.outlook.com) (40.107.243.76) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Mar 2020 04:47:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ip07ffzCp3BZ4ms2W7+hh7RgX1IhfbLvlqNUd38IwDdecU9jaJGMBHvqV05K6WaIT2M7fFwy9V9rzQKFkPN0PeAThc2qkFhXUN1DEnMujt9rFE30+98VT14oyHul5lEnZTA/SYrhy4fCmlQD7uW8tvRnCFWGTUvCNQTQZXRUCQBP3nTCAd7s8tuMrTZP2xqWdkiwZYcN/tAgAkKj3a9uNJCKLYmhdjCWK7KhY2I6Vz+DHs5a4hlTaRBkYmxmxFtwtxuuAXIGQzGrspPqU44cyOUeEnROtYZpMBO+uhDDULlMx0sM3M+lMti+RY/8gMfl/ctk5yyYSWol9XC0+EEbYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rGrhmmsXrnhoRB720k3FtMxh11144B6kU9PnK66YEIk=; b=HcQYmcqq0xt2R88bd1bgZHET6AumqwQ0XS+q23SXXCLsmtN2crKx3IsDrR9JepO07x5Z/c81SHHpbQpcWjEsFKycJCPAapT99U9U9uOVKt7BhtOtmhLvns9Vl3LiamvSaKYuN8ErmvPZt7sAlG1Hrxq/PzrNKRxirYJ3JRO7EQgcj1on1d1v8DqgkuyUKPL13PeZW/SCkP1F52/02KgaZ5O9PQ88gU4GTFfIYFI0Vm2Lpyt24PhzbUSnh48CyMoBK3ywG9IiuNbcyjb/8Nt5eI7gyptBSOsswSS5evXw22tQi3VCn0bOESjiRstVhEVGkfE5e/TLumDm5h1dfDcz6Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rGrhmmsXrnhoRB720k3FtMxh11144B6kU9PnK66YEIk=; b=CG7URSUNAFzYxUojUK6RX9bx+ozBe4xd3zDpQ7Xci7YXnFs2ASPjjhjFPs89+Ndt0Opfa4JgLASVx+cTHgV6iXcSiKk1pQKqf3yZG6pyS8MsM+2DBBAJi4lOe/6TqrvWDUUB5w/DJJKnYV2GZ0n+XSDZnZtHJC8Oq0M2jM/VX5w= Received: from DM6PR12MB3129.namprd12.prod.outlook.com (2603:10b6:5:3b::26) by DM6PR12MB4009.namprd12.prod.outlook.com (2603:10b6:5:1cd::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2772.15; Tue, 3 Mar 2020 04:47:21 +0000 Received: from DM6PR12MB3129.namprd12.prod.outlook.com ([fe80::25b4:d90c:9db4:1aa1]) by DM6PR12MB3129.namprd12.prod.outlook.com ([fe80::25b4:d90c:9db4:1aa1%7]) with mapi id 15.20.2772.019; Tue, 3 Mar 2020 04:47:20 +0000 From: "Sharma, Alok Kumar" To: Andrew Burgess , "gdb-patches@sourceware.org" Subject: RE: [PATCHv2] gdb/fortran: Fix printing of logical true values for Flang Date: Tue, 03 Mar 2020 04:47:00 -0000 Message-ID: References: <20200302182152.12819-1-andrew.burgess@embecosm.com> In-Reply-To: <20200302182152.12819-1-andrew.burgess@embecosm.com> authentication-results: spf=none (sender IP is ) smtp.mailfrom=AlokKumar.Sharma@amd.com; x-ms-oob-tlc-oobclassifiers: OLM:9508; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-messagedata: shSC/7cvxEoQs9ROD0B7y+sNvtsU5IhGKK9esGdxBJHhzGd/JdS5t1q1g0SSPi9s1c9yxgMEI8ah/fy/S1Jtv2EvX2xAmRRhbUGHRrNk4zGDo9lTT9HzHi3Eau+aG/2l4CR/OjdUGO95RfLOuxRrHQ== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 0FEIH3tFFD/09HJfOAajE1fc9jSbhP5Jj996QMm+Tf/1FVnnzeITHrlB5LPg71slyrCGpHDVrwQgJzJL6a/59Q== X-SW-Source: 2020-03/txt/msg00045.txt Hi Andrew, I strongly agree and accept your comment. Please let me know if patch need = to be updated by me? In case you have already incorporated the comments, pl= ease push it. Regards, Alok -----Original Message----- From: Andrew Burgess =20 Sent: Monday, March 2, 2020 11:52 PM To: gdb-patches@sourceware.org Cc: Sharma, Alok Kumar ; Andrew Burgess Subject: [PATCHv2] gdb/fortran: Fix printing of logical true values for Fla= ng [CAUTION: External Email] Alok, Thanks for looking into this. I think that the best solution right now wil= l be to handle TYPE_CODE_BOOL in f_val_print rather than modifying generic_= val_print_bool. The other possibility would be, I think, to add a new field to 'struct lang= uage_defn' and use this in generic_val_print_bool instead of comparing the = value of current_lanuage directly, however, this isn't the common approach,= so I'd prefer to handle this case just like other TYPE_CODE_* are handled for now. I know that in places within GDB we do compare the value of current_lanuage= to the know language structures, but I'd like to move us away from doing t= his. I've gone ahead and added some tests too. Let me know what you think of this. If you're happy then I'll go ahead and= push this. Thanks Andrew --- GDB is not able to print logical true values for Flang compiler. Actual result: (gdb) p l $1 =3D 4294967295 Expected result: (gdb) p l $1 =3D .TRUE. This is due to GDB expecting representation of true value being 1. The Fortran standard doesnt specify how LOGICAL types are represented. Different compilers use different non-zero values to represent logical true= . The gfortran compiler uses 1 to represent logical true and the flang comp= iler uses -1. GDB should accept all the non-zero values as true. This is achieved by handling TYPE_CODE_BOOL in f_val_print and printing any= non-zero value as true. gdb/ChangeLog: * f-valprint.c (f_val_print): Handle TYPE_CODE_BOOL, any non-zero value should be printed as true. gdb/testsuite/ChangeLog: * gdb.fortran/logical.exp: Add tests that any non-zero value is printed as true. --- gdb/ChangeLog | 6 ++++++ gdb/f-valprint.c | 25 ++++++++++++++++++++++++- gdb/testsuite/ChangeLog | 5 +++++ gdb/testsuite/gdb.fortran/logical.exp | 18 ++++++++++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c index a25e6147322..0393ddf= a8ab 100644 --- a/gdb/f-valprint.c +++ b/gdb/f-valprint.c @@ -357,6 +357,30 @@ f_val_print (struct type *type, int embedded_offset, fprintf_filtered (stream, " )"); break; + case TYPE_CODE_BOOL: + if (options->format || options->output_format) + { + struct value_print_options opts =3D *options; + opts.format =3D (options->format ? options->format + : options->output_format); + val_print_scalar_formatted (type, embedded_offset, + original_value, &opts, 0, stream); + } + else + { + int unit_size =3D gdbarch_addressable_memory_unit_size (gdbarch); + LONGEST val + =3D unpack_long (type, valaddr + embedded_offset * unit_size); + /* The Fortran standard doesn't specify how logical types are + represented. Different compilers use different non zero + values to represent logical true. */ + if (val =3D=3D 0) + fputs_filtered (f_decorations.false_name, stream); + else + fputs_filtered (f_decorations.true_name, stream); + } + break; + case TYPE_CODE_REF: case TYPE_CODE_FUNC: case TYPE_CODE_FLAGS: @@ -366,7 +390,6 @@ f_val_print (struct type *type, int embedded_offset, case TYPE_CODE_RANGE: case TYPE_CODE_UNDEF: case TYPE_CODE_COMPLEX: - case TYPE_CODE_BOOL: case TYPE_CODE_CHAR: default: generic_val_print (type, embedded_offset, address, diff --git a/gdb/= testsuite/gdb.fortran/logical.exp b/gdb/testsuite/gdb.fortran/logical.exp index f0028159e59..96e6f8f9559 100644 --- a/gdb/testsuite/gdb.fortran/logical.exp +++ b/gdb/testsuite/gdb.fortran/logical.exp @@ -33,3 +33,21 @@ gdb_test "p l1" " =3D \\.TRUE\\." gdb_test "p l2" " =3D \\.TRUE\\." gdb_test "p l4" " =3D \\.TRUE\\." gdb_test "p l8" " =3D \\.TRUE\\." + +# Different Fortran compilers use different values for logical true. +# Check how GDB handles this by modifying the underlying value for our=20 +# logical variables and check they still print as true. +foreach_with_prefix var { l l1 l2 l4 l8 } { + set len [get_integer_valueof "sizeof (${var})" "get sizeof ${var}"] + set addr [get_hexadecimal_valueof "&l" "get address of ${var}"] + + for { set i 0 } { $i < $len } { incr i } { + with_test_prefix "byte $i" { + gdb_test_no_output "set *((uint8_t *) ${addr}) =3D 0xff" \ + "set contents of byte at offset $i" + gdb_test "p l" " =3D \\.TRUE\\." + incr addr + set addr [format "0x%x" $addr] + } + } +} -- 2.14.5