From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2067.outbound.protection.outlook.com [40.107.94.67]) by sourceware.org (Postfix) with ESMTPS id 24AF33858C3A for ; Thu, 4 Nov 2021 06:16:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 24AF33858C3A ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nGFjJwVYlNRFWze6mrRZOAXI8N6et+Nf4eOL/Xl0/0VHqs9xvwiEBGjWIdDfN1e+ADDCm1H9FRqDqlcXQPlofVmzPQcs2/BPVrXiUmsdG5je1XzvNnlF23fI5ceAMKtibv2nnD7RcOBpxHWzaBd/j7CTF3XfGdzVl8jaP5jmE+zVsIXTTh0L+oaV0j4/vMsqadfqv0ZBulmmnfne0+QUsvUr24VksVZw/MXPbnfXjPqyFkZ8f90MGj56S8WtTuGIZN3H02H8AazHmssAOT8KaJBpv6xaRaU1M9bK8GvBMJXjK1c9I80hPuN7uHB8zun3EKZaA8E1jitjF/0qfM35NA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=CKFZE60jOzn4WkEYuCFmZfOaffthsoV7oGdBo5sh9JM=; b=T0UnH4RZ0cBkYLEM2cFYGp0KXeiXbow79T9lSqwgMs+RDiFMw8JOEuAzAv1dLK6gd4fKi8rvAt2Lw/+wrDIEHUJFE6uo2m6kMvC6tMJD8lhWD3CNmfkIN3sEnOPaP0k1k/YnOAOmJrJb6mOydsL2IbMjMUXGOlGAj10NFQH1eCoR3r8ZK+oYjMykvB1uo5/E4Sh4wsteddheBn6xfTNjn/X+8kgcEImcaK5cxowE4c+ZEUKx0JrVfsLfV0ENiMcX3H8i4+nwYxPQxE0nD0gwJ9HmJ7Gh0GvUgRF6rLNq3hc5f3h/WeCTSdlgb7LbRxeXUV3yEPz3TApfTufRNGHVMA== 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 Received: from MW2PR12MB4684.namprd12.prod.outlook.com (2603:10b6:302:13::29) by MWHPR12MB1168.namprd12.prod.outlook.com (2603:10b6:300:e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.18; Thu, 4 Nov 2021 06:16:27 +0000 Received: from MW2PR12MB4684.namprd12.prod.outlook.com ([fe80::8c32:c276:90c3:5899]) by MW2PR12MB4684.namprd12.prod.outlook.com ([fe80::8c32:c276:90c3:5899%2]) with mapi id 15.20.4649.021; Thu, 4 Nov 2021 06:16:27 +0000 From: "Kumar N, Bhuvanendra" To: Andrew Burgess CC: "gdb-patches@sourceware.org" , "George, Jini Susan" , "Achra, Nitika" , "Sharma, Alok Kumar" , "E, Nagajyothi" Subject: RE: [PING*3] [PATCH] Fix ptype and print commands for namelist variables(a fortran feature) Thread-Topic: [PING*3] [PATCH] Fix ptype and print commands for namelist variables(a fortran feature) Thread-Index: AdfRQ1CLTZP3hb2/SS+2TOl52tFXDQ== Date: Thu, 4 Nov 2021 06:16:26 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_88914ebd-7e6c-4e12-a031-a9906be2db14_Enabled=true; MSIP_Label_88914ebd-7e6c-4e12-a031-a9906be2db14_SetDate=2021-11-04T06:16:16Z; MSIP_Label_88914ebd-7e6c-4e12-a031-a9906be2db14_Method=Standard; MSIP_Label_88914ebd-7e6c-4e12-a031-a9906be2db14_Name=AMD Official Use Only-AIP 2.0; MSIP_Label_88914ebd-7e6c-4e12-a031-a9906be2db14_SiteId=3dd8961f-e488-4e60-8e11-a82d994e183d; MSIP_Label_88914ebd-7e6c-4e12-a031-a9906be2db14_ActionId=c0026e34-6ff2-478e-a015-c2e154137452; MSIP_Label_88914ebd-7e6c-4e12-a031-a9906be2db14_ContentBits=1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 96210705-1e29-44cc-c9aa-08d99f5aa285 x-ms-traffictypediagnostic: MWHPR12MB1168: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:144; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: LmsUFQQ+2RIhEfd1DKISlxw55GHAtx+Lp6kiwMlRAhSFzoBrwH4FJsvJ1Fx+VNW/6qHh5pWb/E2AS+X9CMnJhirXUBXNDmB5dZIe42X0xLT1larpv8bnccMiRtbc1mI3gu3tv+sCoIxNNwP4hg8ICi6XlHEJmqvyOcEhv7V5hjs0vR9qP0OCMzfXVST/O2bGnRe1T3zjjcOSj3aVOmrLYINO/WyFFTmwkeR2FpBghuvJCpBLJaGBqaA+GUG8AOyhZaAoqCDJzUT4sB5J5+K7t2Zqn9g1iLhEOvUUGLkj/2v+33pcLMyO4KS5WHzhXjtyfbYfv6g3m3TDEHHm5ZOr3K2aYte5RbvA4nlUNQJ91o+YVNwruCNpqWQuH8E8LWrD3tB1EBgtoSW2w+KtJED9xP0NMgzWSxI1IZgug+KE5O3A6eDvdyjmjhd+bDgkpB0R9NsabYYPDF+44+2JYAl38rcWwvWhIFAytLrD7WOmmKzMxO5l6iUyc+vMefJ7frtNZDCEwqc1HdgKJ4qfQGjniQW589N1qFawUxgAKl9pA6A0obxQi9quRutlGN5uK01LaW3Ukrug+V0WzidtfD1t7QGwzqiQMmqGT5loUQsOudi6pVDDagpLJ0FlVHF+1TXJQAGFVUJ8gUsVNBoMcpsY/FLrFvVsFsSkSLcix4C1AU/CSUtSNFIXTRXbUSizLKabvytOdbk1xEjkrPdiD7kp+ALTenL2c1VgKdJl1MroPo4BGHj2quceNAMKdNd8YtBRJ6a2WhJ1QYWU9N3pBUq+4smOtDy49q80mQpyTVaT5mPHAhbq1+6n7XwNSwU7oxOTbw9AogNIsKJkTfbqRmVieB/7kf2smzfVss3vrAU6dIY= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MW2PR12MB4684.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(83380400001)(30864003)(5660300002)(4326008)(86362001)(38070700005)(6916009)(54906003)(53546011)(38100700002)(316002)(8936002)(76116006)(8676002)(2906002)(55016002)(45080400002)(33656002)(26005)(122000001)(9686003)(508600001)(71200400001)(7696005)(66476007)(66556008)(64756008)(66946007)(55236004)(66446008)(6506007)(52536014)(186003)(966005)(2004002)(559001)(579004); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?cTe87tT799RdhXPZ/sU9ax7bJ85dfIT5eMpWgHkF/kRQwdrS69QLtX4FZcDc?= =?us-ascii?Q?oEK6eWy23CNyGDbHTUMxxIV4Z28szbIKFJJYusemvtkP7N68irCUnm8uJpXz?= =?us-ascii?Q?3ZdzoAOQJ+l4BV6zvra7nh8W6P71NJ4fdNdPpOLri7/w+J7KWc9pm8ezAQIk?= =?us-ascii?Q?y1wU+VPIh0XrjQ/PtTc9XASw7VTlOZ8z+mCIVRnPiHvjz4cB0nvyo6r5hNvs?= =?us-ascii?Q?qAxRY1fpBnLtJUCEM8mTMwzrsL0PwLscO/XZpPtnRLlP9tXlDn6lqd9Xb+eG?= =?us-ascii?Q?PwESUmBTMr2MXNaaY37vU03q/SGuz1nEMITWrUyQSpl+u64PfHzfkdmmUBhi?= =?us-ascii?Q?lwAEJGSqHVY3bZriuZrRHh6tK3KlWrCBzss/KzBqzquHMUUV8CP47tesX42a?= =?us-ascii?Q?FAS7SYu+QWPiTT4tqEpvi3VVeWWWoF8URKfzodvvna7PbfWTbRpWLuFb6pvu?= =?us-ascii?Q?vkfNhi2H7mpT4pWJxUdfKubgCGrMlRo32yteQ4OpvX/3iQJkHHcvdPtstUOK?= =?us-ascii?Q?91t62jEVRIRfnKktxPbFvw1HTKdX5lvjICA3VZldDx9hdzrtOh/LkpK3BFWj?= =?us-ascii?Q?Q8OfiuGoKG8m9SOiAjkXskidi4IUSU73kAhWRkgQtc1QOiYXtzvIndID+B8i?= =?us-ascii?Q?Bcfj3X9PrjeY2InzJ2qFDDZLYSMfXpms/RJkCqxZ6H/8n6dopNxRn+C1d3E/?= =?us-ascii?Q?LUc3Lvhr5zsuTz2nWrCy9CPnEyCSwLk6upfCwADO6cB9yFuTFgmDrGzKWVE5?= =?us-ascii?Q?U8CxUwcW3zY7dO4r1Q6sqZT3LHa326hg3zyM1IIXElgrAlgafcpqZAz9aYOf?= =?us-ascii?Q?YQTUBYB2//YxxBMGmK+ljSkA0fbnp8Rl2SI2AxSeeYCl/Xn3GUdAPOTt/FRg?= =?us-ascii?Q?Rsg6T0FfF0CjQhKYhM5rhczLVZJL8jYiY+rbT3c8K0gUzf0DJs2tZbwmxPK7?= =?us-ascii?Q?8Ww1OPNUvk4sTA8EQMRKXVM0xRHPEdX3iv4Z3jHtF8VIOrOHMfcpkZrhS2ME?= =?us-ascii?Q?56dZE+dIJZV1kHiY+5gHwghVK4dIkUFThVVi4Qt0bZ+YOj4tY2tQyNhgB78Y?= =?us-ascii?Q?h7uf7Ry34RoT2OdVo1BGOT0IaWnIcBkSI5PbJv7qhE+To9zVehOqn966RvKx?= =?us-ascii?Q?7NTie1PPA4x8ZuH8v/HLS5NV/9l9QWs8IgDEOPrsWR9bws+K1BsYV5VBI/mo?= =?us-ascii?Q?5JtQ67JaJli9N2SRISh2iUPHJcBZqXIkNyqDDxMNlEfrhfl6IjP/o7dj5pYY?= =?us-ascii?Q?/m45nMHACNwT7Dxu+9QFHNG51wZyHE4eMY3qy7WQ3krg+anGCiQRdEjge8D3?= =?us-ascii?Q?l151QyU8Sne1RQfPf8CEJQupnkZNZcj7UBjQ0HDjMqLg4Rd4rRY4zyKz9XF/?= =?us-ascii?Q?eIGn5sGICkG/bXGQLVBhTqgyO7UlewHEVowwYfgiw0pe+kVYAxAj8NJ42zFP?= =?us-ascii?Q?mZ9+WSSDDJX7KNWsc6+q8IbWzS461u7zq2GM9Ntz5SHSj13pnrh6t+zQqJL9?= =?us-ascii?Q?OsIbt8JNBjV7plmB3NkEgV0TwN2hxJCqOv6t63unxQ0tdKJ91tzGORE4EKmV?= =?us-ascii?Q?jeK35eSBs2ycZoSCJiL4Yyk6F+a2C+9L5z/Yv2ov1bQJgHlMrQhdV/2MpsG8?= =?us-ascii?Q?+ndeYF3aajhtB8Gm5eUFdjo=3D?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW2PR12MB4684.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 96210705-1e29-44cc-c9aa-08d99f5aa285 X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Nov 2021 06:16:27.0027 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: zKlNoPNC3L7sSDX4UekwGHIViYHJhvRKy/2/i8pK4z0HO6EEm93jiJAaoQSI9dAOOPygoigpolgq24a/xWgvGg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1168 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_LOTSOFHASH, KAM_SHORT, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Nov 2021 06:16:36 -0000 [AMD Official Use Only] Hi Andrew and all, Gentle PING*3 for the revised patch Regards, bhuvan -----Original Message----- From: Kumar N, Bhuvanendra=20 Sent: Wednesday, October 27, 2021 6:46 PM To: Andrew Burgess Cc: gdb-patches@sourceware.org; George, Jini Susan ; Achra, Nitika ; Sharma, Alok Kumar ; E, Nagajyothi Subject: RE: {PING*2] [PATCH] Fix ptype and print commands for namelist var= iables(a fortran feature) [AMD Official Use Only] Hi Andrew and all, Gentle PING*2 for the revised patch regards, bhuvan -----Original Message----- From: Kumar N, Bhuvanendra Sent: Monday, October 18, 2021 10:32 PM To: 'Andrew Burgess' Cc: 'gdb-patches@sourceware.org' ; George, Jini= Susan ; Achra, Nitika ; Sh= arma, Alok Kumar ; E, Nagajyothi Subject: RE: [PATCH] Fix ptype and print commands for namelist variables(a = fortran feature) [AMD Official Use Only] Hi Andrew and all, Gentle ping for the revised patch regards, Bhuvan -----Original Message----- From: Kumar N, Bhuvanendra Sent: Friday, October 8, 2021 2:35 AM To: Andrew Burgess Cc: gdb-patches@sourceware.org; George, Jini Susan ; Achra, Nitika ; Sharma, Alok Kumar ; E, Nagajyothi Subject: RE: [PATCH] Fix ptype and print commands for namelist variables(a = fortran feature) [AMD Official Use Only] Hi Andrew, Thanks again for your review comments. I have now introduced a new type(TYP= E_CODE_NAMELIST) for namelist type as you suggested, could you please revie= w the revised changes. Updated patch is attached and also inlined with this= email. There are no regressions found during testing. thanks, bhuvan PATCH inlined: >From 89b7f847042ccea44633f714db07400fa6dd3617 Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?=3DE2=3D80=3D9Cbhkumarn=3DE2=3D80=3D9D?=3D Date: Fri, 8 Oct 2021 02:01:18 +0530 Subject: [PATCH] gdb/fortran: Fix ptype and print commands for namelist va= riables. GCC/gfortran support namelist(a fortran feature), it emits DW_TAG_namelist = and DW_TAG_namelist_item dies. But gdb does not process these dies and supp= ort namelist variables during print and ptype commands. When tried to print= , it bails out with the error message as shown below. (gdb) print nml No symbol "nml" in current context. This commit is to make the print and ptype commands work for namelist varia= bles and its items. Sample output of these commands is shared below, with f= ixed gdb. (gdb) ptype nml type =3D Type nml integer(kind=3D4) :: a integer(kind=3D4) :: b End Type nml (gdb) print nml $1 =3D ( a =3D 10, b =3D 20 ) --- gdb/dwarf2/read.c | 43 ++++++++++++++++++---- gdb/f-typeprint.c | 6 +++- gdb/f-valprint.c | 11 ++++++ gdb/gdbtypes.h | 2 ++ gdb/testsuite/gdb.fortran/namelist.exp | 49 ++++++++++++++++++++++++++ gdb/testsuite/gdb.fortran/namelist.f90 | 27 ++++++++++++++ include/dwarf2.def | 2 +- 7 files changed, 132 insertions(+), 8 deletions(-) create mode 100644 gdb= /testsuite/gdb.fortran/namelist.exp create mode 100644 gdb/testsuite/gdb.fortran/namelist.f90 diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index cbd9a3012eb..e6cd8= ed48f0 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -9705,6 +9705,7 @@ process_die (struct die_info *die, struct dwarf2_cu *= cu) case DW_TAG_interface_type: case DW_TAG_structure_type: case DW_TAG_union_type: + case DW_TAG_namelist: process_structure_scope (die, cu); break; case DW_TAG_enumeration_type: @@ -14562,8 +14563,20 @@ dwarf2_add_field (struct field_info *fip, struct d= ie_info *die, =20 fp =3D &new_field->field; =20 - if (die->tag =3D=3D DW_TAG_member && ! die_is_declaration (die, cu)) - { + if ((die->tag =3D=3D DW_TAG_member || die->tag =3D=3D DW_TAG_namelist_it= em) + && ! die_is_declaration (die, cu)) + { + /* For the DW_TAG_namelist_item die, use the referenced die. */ + if (die->tag =3D=3D DW_TAG_namelist_item) + { + struct attribute *attr1 =3D dwarf2_attr (die, DW_AT_namelist_ite= m, cu); + struct die_info *item_die =3D nullptr; + struct dwarf2_cu *item_cu =3D cu; + if (attr1->form_is_ref ()) + item_die =3D follow_die_ref (die, attr1, &item_cu); + if (item_die !=3D nullptr) + die =3D item_die; + } /* Data member other than a C++ static data member. */ =20 /* Get type of field. */ @@ -15621,6 +15634,10 @@ read_structure_type (struct die_info *die, struct = dwarf2_cu *cu) { type->set_code (TYPE_CODE_UNION); } + else if (die->tag =3D=3D DW_TAG_namelist) + { + type->set_code (TYPE_CODE_NAMELIST); + } else { type->set_code (TYPE_CODE_STRUCT); @@ -15823,7 +15840,8 @@ handle_st= ruct_member_die (struct die_info *child_die, struct type *type, struct dwarf2_cu *cu) { if (child_die->tag =3D=3D DW_TAG_member - || child_die->tag =3D=3D DW_TAG_variable) + || child_die->tag =3D=3D DW_TAG_variable + || child_die->tag =3D=3D DW_TAG_namelist_item) { /* NOTE: carlton/2002-11-05: A C++ static data member should be a DW_TAG_member that is a declaration, but @@ -15867,7 +15885,= 9 @@ handle_struct_member_die (struct die_info *child_die, struct type *typ= e, } =20 /* Finish creating a structure or union type, including filling in - its members and creating a symbol for it. */ + its members and creating a symbol for it. This function also + handles Fortran namelist variable, its items or members and + creating a symbol for it. */ =20 static void process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) @@ -2= 1971,8 +21991,17 @@ new_symbol (struct die_info *die, struct type *type, st= ruct dwarf2_cu *cu, case DW_TAG_union_type: case DW_TAG_set_type: case DW_TAG_enumeration_type: - SYMBOL_ACLASS_INDEX (sym) =3D LOC_TYPEDEF; - SYMBOL_DOMAIN (sym) =3D STRUCT_DOMAIN; + case DW_TAG_namelist: + if (die->tag =3D=3D DW_TAG_namelist) + { + SYMBOL_ACLASS_INDEX (sym) =3D LOC_STATIC; + SYMBOL_DOMAIN (sym) =3D VAR_DOMAIN; + } + else + { + SYMBOL_ACLASS_INDEX (sym) =3D LOC_TYPEDEF; + SYMBOL_DOMAIN (sym) =3D STRUCT_DOMAIN; + } =20 { /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't @@ -22909,6 = +22938,7 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) && die->tag !=3D DW_TAG_class_type && die->tag !=3D DW_TAG_interface_type && die->tag !=3D DW_TAG_structure_type + && die->tag !=3D DW_TAG_namelist && die->tag !=3D DW_TAG_union_type) return NULL; =20 @@ -22933,6 +22963,7 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu= *cu) case DW_TAG_interface_type: case DW_TAG_structure_type: case DW_TAG_union_type: + case DW_TAG_namelist: /* Some GCC versions emit spurious DW_AT_name attributes for unnamed structures or unions. These were of the form "._%d" in GCC 4.1, or simply "" or "" in GCC 4.3 diff --= git a/gdb/f-typeprint.c b/gdb/f-typeprint.c index 1791cb29451..5b34622dacb = 100644 --- a/gdb/f-typeprint.c +++ b/gdb/f-typeprint.c @@ -121,6 +121,7 @@ f_language::f_type_print_varspec_prefix (struct type *t= ype, case TYPE_CODE_UNDEF: case TYPE_CODE_STRUCT: case TYPE_CODE_UNION: + case TYPE_CODE_NAMELIST: case TYPE_CODE_ENUM: case TYPE_CODE_INT: case TYPE_CODE_FLT: @@ -261,6 +262,7 @@ f_language::f_type_print_varspec_suffix (struct type *t= ype, case TYPE_CODE_UNDEF: case TYPE_CODE_STRUCT: case TYPE_CODE_UNION: + case TYPE_CODE_NAMELIST: case TYPE_CODE_ENUM: case TYPE_CODE_INT: case TYPE_CODE_FLT: @@ -305,7 +307,8 @@ f_language::f_type_print_base (struct type *type, struc= t ui_file *stream, const char *prefix =3D ""; if (type->code () =3D=3D TYPE_CODE_UNION) prefix =3D "Type, C_Union :: "; - else if (type->code () =3D=3D TYPE_CODE_STRUCT) + else if (type->code () =3D=3D TYPE_CODE_STRUCT + || type->code () =3D=3D TYPE_CODE_NAMELIST) prefix =3D "Type "; fprintf_filtered (stream, "%*s%s%s", level, "", prefix, type->name (= )); return; @@ -391,6 +394,7 @@ f_language::f_type_print_base (struct type *type, struc= t ui_file *stream, =20 case TYPE_CODE_STRUCT: case TYPE_CODE_UNION: + case TYPE_CODE_NAMELIST: if (type->code () =3D=3D TYPE_CODE_UNION) fprintf_filtered (stream, "%*sType, C_Union :: ", level, ""); else diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c index 27d9a730978..6f80b5a= 12ff 100644 --- a/gdb/f-valprint.c +++ b/gdb/f-valprint.c @@ -295,6 +295,7 @@ f_language::value_print_inner (struct value *val, struc= t ui_file *stream, =20 case TYPE_CODE_STRUCT: case TYPE_CODE_UNION: + case TYPE_CODE_NAMELIST: /* Starting from the Fortran 90 standard, Fortran supports derived types. */ fprintf_filtered (stream, "( "); @@ -320,6 +321,16 @@ f_language::value_print_inner (struct value *val, stru= ct ui_file *stream, fputs_filtered (" =3D ", stream); } =20 + /* While printing namelist items, fetch the appropriate value + field before printing its value. */ + if (type->code () =3D=3D TYPE_CODE_NAMELIST) + { + struct block_symbol symni =3D lookup_symbol (field_name, + get_selected_block (0), VAR_DOMAIN, nullptr); + if (symni.symbol !=3D nullptr) + field =3D value_of_variable (symni.symbol, symni.block); + } + common_val_print (field, stream, recurse + 1, options, current_language); =20 diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index dc575c42996..ba8a61987db= 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -195,6 +195,8 @@ enum type_code =20 /* * Fixed Point type. */ TYPE_CODE_FIXED_POINT, + + TYPE_CODE_NAMELIST, /**< Fortran namelist. */ }; =20 /* * Some bits for the type's instance_flags word. See the macros diff --= git a/gdb/testsuite/gdb.fortran/namelist.exp b/gdb/testsuite/gdb.fortran/na= melist.exp new file mode 100644 index 00000000000..90762928455 --- /dev/null +++ b/gdb/testsuite/gdb.fortran/namelist.exp @@ -0,0 +1,49 @@ +# Copyright (C) 2021 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify=20 +# it under the terms of the GNU General Public License as published by=20 +# the Free Software Foundation; either version 3 of the License, or #=20 +(at your option) any later version. +# +# This program is distributed in the hope that it will be useful, # but=20 +WITHOUT ANY WARRANTY; without even the implied warranty of #=20 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU=20 +General Public License for more details. +# +# You should have received a copy of the GNU General Public License #=20 +along with this program. If not, see . + +# This file is part of the gdb testsuite. It contains tests for=20 +fortran # namelist. + +if { [skip_fortran_tests] } { return -1 } + +standard_testfile .f90 +load_lib "fortran.exp" + +if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug f90= }]} { + return -1 +} + +if ![fortran_runto_main] then { + perror "couldn't run to main" + continue +} + +# Depending on the compiler being used, the type names can be printed diff= erently. +set int [fortran_int4] + +gdb_breakpoint [gdb_get_line_number "Display namelist"]=20 +gdb_continue_to_breakpoint "Display namelist" + +if {[test_compiler_info {gcc-*}]} { + gdb_test "ptype nml" \ + "type =3D Type nml\r\n *$int :: a\r\n *$int :: b\r\n *End Type nml= " + gdb_test "print nml" \ + "\\$\[0-9\]+ =3D \\( a =3D 10, b =3D 20 \\)" +} else { + gdb_test "ptype nml" \ + "No symbol \"nml\" in current context\\." + gdb_test "print nml" \ + "No symbol \"nml\" in current context\\." +} diff --git a/gdb/testsuite/gdb.fortran/namelist.f90 b/gdb/testsuite/gdb.for= tran/namelist.f90 new file mode 100644 index 00000000000..fb36690d765 --- /dev/null +++ b/gdb/testsuite/gdb.fortran/namelist.f90 @@ -0,0 +1,27 @@ +! Copyright (C) 2021 Free Software Foundation, Inc. +! +! This program is free software; you can redistribute it and/or modify=20 +! it under the terms of the GNU General Public License as published by=20 +! the Free Software Foundation; either version 3 of the License, or ! +(at your option) any later version. +! +! This program is distributed in the hope that it will be useful, ! but=20 +WITHOUT ANY WARRANTY; without even the implied warranty of ! +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU=20 +General Public License for more details. +! +! You should have received a copy of the GNU General Public License !=20 +along with this program. If not, see . +! +! This file is the Fortran source file for namelist.exp. + +program main + + integer :: a, b + namelist /nml/ a, b + + a =3D 10 + b =3D 20 + Write(*,nml) ! Display namelist + +end program main diff --git a/include/dwarf2.def b/include/dwarf2.def index 1ae6e1df298..6b8= be1f6a16 100644 --- a/include/dwarf2.def +++ b/include/dwarf2.def @@ -289,7 +289,7 @@ DW_AT (DW_AT_frame_base, 0x40) DW_AT (DW_AT_friend, 0x= 41) DW_AT (DW_AT_identifier_case, 0x42) DW_AT (DW_AT_macro_info, 0x43) -D= W_AT (DW_AT_namelist_items, 0x44) +DW_AT (DW_AT_namelist_item, 0x44) DW_AT (DW_AT_priority, 0x45) DW_AT (DW_AT_segment, 0x46) DW_AT (DW_AT_specification, 0x47) -- 2.17.1 -----Original Message----- From: Andrew Burgess Sent: Wednesday, October 6, 2021 9:22 PM To: Kumar N, Bhuvanendra Cc: gdb-patches@sourceware.org; George, Jini Susan ; Achra, Nitika ; Sharma, Alok Kumar ; E, Nagajyothi Subject: Re: [PATCH] Fix ptype and print commands for namelist variables(a = fortran feature) [CAUTION: External Email] * Kumar N, Bhuvanendra [2021-09-22 12:38:20 +0= 000]: > [AMD Official Use Only] > > Hi Andrew, > > Thanks a lot for your review comments, I have addressed all the review co= mments and tested. Updated patch is attached and also inlined with this ema= il. > > >I'm a little uncomfortable with this if condition. This feels like a bi= t of a hack. Is there precedent anywhere else in GDB for using the type sp= ecific field like this? > >Wouldn't adding a TYPE_CODE_NAMELIST be more in keeping with how GDB cur= rently does things, though I understand this is likely to make the patch sl= ightly bigger. Did you consider this approach? > > Regarding your major comment, I did considered introducing a new type=20 > specific field for namelist earlier, instead of using any of those=20 > existing. Reason I did not included in my earlier patch was,=20 > type_specific_kind is declared with 3 bits in struct main_type and=20 > already there were 8 values, hence deferred expanding=20 > type_specific_kind etc.... But now I have done that, thanks for the=20 > suggestion. Except that wasn't quite what I suggested; I actually asked whether namelis= t's should become their own type altogether, notice I suggested TYPE_CODE_N= AMELIST. Though what you have here is nice in its simplicity, but I can't shake the = feeling that its not the right solution. I'll need to think about this some more - maybe others have an opinion? Thanks, Andrew > > Regards, > bhuvan > > PATH inlined: > > From 59053daf1018c3e4bcae8cd342d46b00f4f03648 Mon Sep 17 00:00:00 2001 > From: =3D?UTF-8?q?=3DE2=3D80=3D9Cbhkumarn=3DE2=3D80=3D9D?=3D > > Date: Wed, 22 Sep 2021 17:52:15 +0530 > Subject: [PATCH] Fix ptype and print commands for namelist variables(a=20 > fortran feature). > > GCC/gfortran support namelist(a fortran feature), it emits=20 > DW_TAG_namelist and DW_TAG_namelist_item dies. But gdb does not=20 > process these dies and support namelist variables during print and=20 > ptype commands. When tried to print, it bails out with the error message = as shown below. > (gdb) print nml > No symbol "nml" in current context. > This commit is to make the print and ptype commands work for namelist=20 > variables and its items. Sample output of these commands is shared=20 > below, with fixed gdb. > (gdb) ptype nml > type =3D Type nml > integer(kind=3D4) :: a > integer(kind=3D4) :: b > End Type nml > (gdb) print nml > $1 =3D ( a =3D 10, b =3D 20 ) > --- > gdb/ChangeLog | 11 ++++++ > gdb/dwarf2/read.c | 44 +++++++++++++++++++---- > gdb/f-valprint.c | 10 ++++++ > gdb/gdbtypes.h | 3 +- > gdb/testsuite/ChangeLog | 5 +++ > gdb/testsuite/gdb.fortran/namelist.exp | 49 > ++++++++++++++++++++++++++ > gdb/testsuite/gdb.fortran/namelist.f90 | 27 ++++++++++++++ > include/dwarf2.def | 2 +- > 8 files changed, 142 insertions(+), 9 deletions(-) create mode > 100644 gdb/testsuite/gdb.fortran/namelist.exp > create mode 100644 gdb/testsuite/gdb.fortran/namelist.f90 > > diff --git a/gdb/ChangeLog b/gdb/ChangeLog index > 36cb4c9e7e9..ec01c2957e9 100644 > --- a/gdb/ChangeLog > +++ b/gdb/ChangeLog > @@ -1,3 +1,14 @@ > +2021-08-23 Bhuvanendra Kumar N > + > + * dwarf2/read.c (process_die): Add new case for namelist. > + (dwarf2_add_field): Process DW_TAG_namelist_item die. > + (read_structure_type, handle_struct_member_die, new_symbol) > + (dwarf2_name): Update. > + * f-valprint.c (f_language::value_print_inner): Add support for > + printing namelist items. > + * include/dwarf2.def: (DW_AT_namelist_items): Renamed to ... > + (DW_AT_namelist_item): ... this. As per dwarf standard. > + > 2021-06-08 Lancelot Six > > * python/lib/gdb/FrameDecorator.py (FrameDecorator): Use 'is None' > diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index > 96009f1418f..88db06ec9e7 100644 > --- a/gdb/dwarf2/read.c > +++ b/gdb/dwarf2/read.c > @@ -9570,6 +9570,7 @@ process_die (struct die_info *die, struct dwarf2_cu= *cu) > case DW_TAG_interface_type: > case DW_TAG_structure_type: > case DW_TAG_union_type: > + case DW_TAG_namelist: > process_structure_scope (die, cu); > break; > case DW_TAG_enumeration_type: > @@ -14417,8 +14418,20 @@ dwarf2_add_field (struct field_info *fip,=20 > struct die_info *die, > > fp =3D &new_field->field; > > - if (die->tag =3D=3D DW_TAG_member && ! die_is_declaration (die, cu)) > - { > + if ((die->tag =3D=3D DW_TAG_member || die->tag =3D=3D DW_TAG_namelist_= item) > + && ! die_is_declaration (die, cu)) > + { > + /* For the DW_TAG_namelist_item die, use the referenced die. */ > + if (die->tag =3D=3D DW_TAG_namelist_item) > + { > + struct attribute *attr1 =3D dwarf2_attr (die, DW_AT_namelist_i= tem, cu); > + struct die_info *item_die =3D nullptr; > + struct dwarf2_cu *item_cu =3D cu; > + if (attr1->form_is_ref ()) > + item_die =3D follow_die_ref (die, attr1, &item_cu); > + if (item_die !=3D nullptr) > + die =3D item_die; > + } > /* Data member other than a C++ static data member. */ > > /* Get type of field. */ > @@ -15448,7 +15461,10 @@ read_structure_type (struct die_info *die, struc= t dwarf2_cu *cu) > } > > type =3D alloc_type (objfile); > - INIT_CPLUS_SPECIFIC (type); > + if (die->tag =3D=3D DW_TAG_namelist) > + TYPE_SPECIFIC_FIELD (type) =3D TYPE_SPECIFIC_NAMELIST; else > + INIT_CPLUS_SPECIFIC (type); > > name =3D dwarf2_name (die, cu); > if (name !=3D NULL) > @@ -15684,7 +15700,8 @@ handle_struct_member_die (struct die_info *child_= die, struct type *type, > struct dwarf2_cu *cu) { > if (child_die->tag =3D=3D DW_TAG_member > - || child_die->tag =3D=3D DW_TAG_variable) > + || child_die->tag =3D=3D DW_TAG_variable > + || child_die->tag =3D=3D DW_TAG_namelist_item) > { > /* NOTE: carlton/2002-11-05: A C++ static data member > should be a DW_TAG_member that is a declaration, but @@ > -15728,7 +15745,9 @@ handle_struct_member_die (struct die_info=20 > *child_die, struct type *type, } > > /* Finish creating a structure or union type, including filling in > - its members and creating a symbol for it. */ > + its members and creating a symbol for it. This function also > + handles Fortran namelist variable, its items or members and > + creating a symbol for it. */ > > static void > process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)=20 > @@ -21807,8 +21826,17 @@ new_symbol (struct die_info *die, struct type *t= ype, struct dwarf2_cu *cu, > case DW_TAG_union_type: > case DW_TAG_set_type: > case DW_TAG_enumeration_type: > - SYMBOL_ACLASS_INDEX (sym) =3D LOC_TYPEDEF; > - SYMBOL_DOMAIN (sym) =3D STRUCT_DOMAIN; > + case DW_TAG_namelist: > + if (die->tag =3D=3D DW_TAG_namelist) > + { > + SYMBOL_ACLASS_INDEX (sym) =3D LOC_STATIC; > + SYMBOL_DOMAIN (sym) =3D VAR_DOMAIN; > + } > + else > + { > + SYMBOL_ACLASS_INDEX (sym) =3D LOC_TYPEDEF; > + SYMBOL_DOMAIN (sym) =3D STRUCT_DOMAIN; > + } > > { > /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't @@ > -22744,6 +22772,7 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu = *cu) > && die->tag !=3D DW_TAG_class_type > && die->tag !=3D DW_TAG_interface_type > && die->tag !=3D DW_TAG_structure_type > + && die->tag !=3D DW_TAG_namelist > && die->tag !=3D DW_TAG_union_type) > return NULL; > > @@ -22768,6 +22797,7 @@ dwarf2_name (struct die_info *die, struct dwarf2_= cu *cu) > case DW_TAG_interface_type: > case DW_TAG_structure_type: > case DW_TAG_union_type: > + case DW_TAG_namelist: > /* Some GCC versions emit spurious DW_AT_name attributes for unnam= ed > structures or unions. These were of the form "._%d" in GCC 4.1, > or simply "" or "" in GCC > 4.3 diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c index=20 > 240daaf34f9..aa86fbc901e 100644 > --- a/gdb/f-valprint.c > +++ b/gdb/f-valprint.c > @@ -320,6 +320,16 @@ f_language::value_print_inner (struct value *val, st= ruct ui_file *stream, > fputs_filtered (" =3D ", stream); > } > > + /* While printing namelist items, fetch the appropriate value > + field before printing its value. */ > + if (TYPE_SPECIFIC_FIELD (type) =3D=3D TYPE_SPECIFIC_NAMELIST) > + { > + struct block_symbol symni =3D lookup_symbol (field_name, > + get_selected_block (0), VAR_DOMAIN, nullptr); > + if (symni.symbol !=3D nullptr) > + field =3D value_of_variable (symni.symbol, symni.block)= ; > + } > + > common_val_print (field, stream, recurse + 1, > options, current_language); > > diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index > 0cc00e74a20..124282c3d53 100644 > --- a/gdb/gdbtypes.h > +++ b/gdb/gdbtypes.h > @@ -607,6 +607,7 @@ enum type_specific_kind > TYPE_SPECIFIC_SELF_TYPE, > TYPE_SPECIFIC_INT, > TYPE_SPECIFIC_FIXED_POINT, > + TYPE_SPECIFIC_NAMELIST, > }; > > union type_owner > @@ -833,7 +834,7 @@ struct main_type > /* * A discriminant telling us which field of the type_specific > union is being used for this type, if any. */ > > - ENUM_BITFIELD(type_specific_kind) type_specific_field : 3; > + ENUM_BITFIELD(type_specific_kind) type_specific_field : 4; > > /* * Number of fields described for this type. This field appears > at this location because it packs nicely here. */ diff --git=20 > a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index=20 > 87cf3e2a061..33f60c29b3c 100644 > --- a/gdb/testsuite/ChangeLog > +++ b/gdb/testsuite/ChangeLog > @@ -1,3 +1,8 @@ > +2021-07-26 Bhuvanendra Kumar N > + > + * gdb.fortran/namelist.exp: New file. > + * gdb.fortran/namelist.f90: New file. > + > 2021-06-10 Bhuvanendra Kumar N > > * gdb.fortran/ptype-on-functions.exp: Add type info of formal=20 > diff --git a/gdb/testsuite/gdb.fortran/namelist.exp > b/gdb/testsuite/gdb.fortran/namelist.exp > new file mode 100644 > index 00000000000..90762928455 > --- /dev/null > +++ b/gdb/testsuite/gdb.fortran/namelist.exp > @@ -0,0 +1,49 @@ > +# Copyright (C) 2021 Free Software Foundation, Inc. > + > +# This program is free software; you can redistribute it and/or=20 > +modify # it under the terms of the GNU General Public License as=20 > +published by # the Free Software Foundation; either version 3 of the=20 > +License, or # (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, #=20 > +but WITHOUT ANY WARRANTY; without even the implied warranty of #=20 > +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU=20 > +General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License #=20 > +along with this program. If not, see . > + > +# This file is part of the gdb testsuite. It contains tests for=20 > +fortran # namelist. > + > +if { [skip_fortran_tests] } { return -1 } > + > +standard_testfile .f90 > +load_lib "fortran.exp" > + > +if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug f= 90}]} { > + return -1 > +} > + > +if ![fortran_runto_main] then { > + perror "couldn't run to main" > + continue > +} > + > +# Depending on the compiler being used, the type names can be printed di= fferently. > +set int [fortran_int4] > + > +gdb_breakpoint [gdb_get_line_number "Display namelist"]=20 > +gdb_continue_to_breakpoint "Display namelist" > + > +if {[test_compiler_info {gcc-*}]} { > + gdb_test "ptype nml" \ > + "type =3D Type nml\r\n *$int :: a\r\n *$int :: b\r\n *End Type n= ml" > + gdb_test "print nml" \ > + "\\$\[0-9\]+ =3D \\( a =3D 10, b =3D 20 \\)" > +} else { > + gdb_test "ptype nml" \ > + "No symbol \"nml\" in current context\\." > + gdb_test "print nml" \ > + "No symbol \"nml\" in current context\\." > +} > diff --git a/gdb/testsuite/gdb.fortran/namelist.f90 > b/gdb/testsuite/gdb.fortran/namelist.f90 > new file mode 100644 > index 00000000000..fb36690d765 > --- /dev/null > +++ b/gdb/testsuite/gdb.fortran/namelist.f90 > @@ -0,0 +1,27 @@ > +! Copyright (C) 2021 Free Software Foundation, Inc. > +! > +! This program is free software; you can redistribute it and/or=20 > +modify ! it under the terms of the GNU General Public License as=20 > +published by ! the Free Software Foundation; either version 3 of the=20 > +License, or ! (at your option) any later version. > +! > +! This program is distributed in the hope that it will be useful, !=20 > +but WITHOUT ANY WARRANTY; without even the implied warranty of !=20 > +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU=20 > +General Public License for more details. > +! > +! You should have received a copy of the GNU General Public License !=20 > +along with this program. If not, see . > +! > +! This file is the Fortran source file for namelist.exp. > + > +program main > + > + integer :: a, b > + namelist /nml/ a, b > + > + a =3D 10 > + b =3D 20 > + Write(*,nml) ! Display namelist > + > +end program main > diff --git a/include/dwarf2.def b/include/dwarf2.def index > 1ae6e1df298..6b8be1f6a16 100644 > --- a/include/dwarf2.def > +++ b/include/dwarf2.def > @@ -289,7 +289,7 @@ DW_AT (DW_AT_frame_base, 0x40) DW_AT=20 > (DW_AT_friend, 0x41) DW_AT (DW_AT_identifier_case, 0x42) DW_AT=20 > (DW_AT_macro_info, 0x43) -DW_AT (DW_AT_namelist_items, 0x44) > +DW_AT (DW_AT_namelist_item, 0x44) > DW_AT (DW_AT_priority, 0x45) > DW_AT (DW_AT_segment, 0x46) > DW_AT (DW_AT_specification, 0x47) > -- > 2.17.1 > > > -----Original Message----- > From: Andrew Burgess > Sent: Monday, September 20, 2021 3:11 PM > To: Kumar N, Bhuvanendra > Cc: gdb-patches@sourceware.org; George, Jini Susan=20 > ; Achra, Nitika ;=20 > Sharma, Alok Kumar ; E, Nagajyothi=20 > > Subject: Re: [PATCH] Fix ptype and print commands for namelist=20 > variables(a fortran feature) > > [CAUTION: External Email] > > * Kumar N, Bhuvanendra via Gdb-patches [2021= -08-24 09:16:19 +0000]: > > > [AMD Official Use Only] > > > > Hi all, > > > > Requesting code review for this GDB patch. Required patch is attached a= nd also inlined below with this email. > > > > Problem description/summary: > > > > GCC/gfortran support namelist(a fortran feature), it emits DW_TAG_namel= ist and DW_TAG_namelist_item dies. But gdb does not process these dies and = support namelist variables during print and ptype commands. When tried to p= rint, it bails out with the error message as shown below. > > (gdb) print nml > > No symbol "nml" in current context. > > > > Fix details: > > > > This fix is to make the print and ptype commands work for namelist vari= ables and its items. Sample output of these commands is shared below, with = fixed gdb. > > > > (gdb) ptype nml > > type =3D Type nml > > integer(kind=3D4) :: a > > integer(kind=3D4) :: b > > End Type nml > > (gdb) print nml > > $1 =3D ( a =3D 10, b =3D 20 ) > > bhuvan, > > Thanks for working on this. I have some small style issues, but I have a= bigger question which you'll find inline. > > Thanks, > Andrew > > > > > > gdb/ChangeLog: > > > > * dwarf2/read.c (process_die): Add new case for namelist. > > (dwarf2_add_field): Process DW_TAG_namelist_item die. > > (read_structure_type, handle_struct_member_die, new_symbol) > > (dwarf2_name): Update. > > * f-valprint.c (f_language::value_print_inner): Add support for > > printing namelist items. > > * include/dwarf2.def: (DW_AT_namelist_items): Renamed to ... > > (DW_AT_namelist_item): ... this. As per dwarf standard. > > > > gdb/testsuite/ChangeLog: > > > > * gdb.fortran/namelist.exp: New file. > > * gdb.fortran/namelist.f90: New file. > > > > NOTE: Similarly renaming DW_AT_namelist_items to DW_AT_namelist_item as= per DWARF standard naming convention in GCC/gfortran repo (https://nam11.s= afelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fgithub.com%2Fgcc-mirro= r%2Fgcc&data=3D04%7C01%7CBhuvanendra.KumarN%40amd.com%7C1b602ae2197248e= 5a9a008d988e12ef7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637691323019= 155507%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6= Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=3DK8mncjSuCt9BEaGJTnlJ9qp0%2FpFSVvf= kVxbe%2FNFrej0%3D&reserved=3D0) will be handled in separate PATCH. I wi= ll raise separate patch for this. > > > > regards, > > bhuvan > > > > Patch inlined: > > > > From 0775cbf3716bae9480c3f1f1d9d8860ac561929e Mon Sep 17 00:00:00 > > 2001 > > From: =3D?UTF-8?q?=3DE2=3D80=3D9Cbhkumarn=3DE2=3D80=3D9D?=3D > > Bhuvanendra.KumarN@amd.com > > Date: Mon, 24 Aug 2021 11:49:14 +0530 > > Subject: [PATCH] Fix ptype and print commands for namelist=20 > > variables(a fortran feature). > > > > GCC/gfortran support namelist(a fortran feature), it emits=20 > > DW_TAG_namelist and DW_TAG_namelist_item dies. But gdb does not=20 > > process these dies and support namelist variables during print and=20 > > ptype commands. When tried to print, it bails out with the error messag= e as shown below. > > (gdb) print nml > > No symbol "nml" in current context. > > This commit is to make the print and ptype commands work for=20 > > namelist variables and its items. Sample output of these commands is=20 > > shared below, with fixed gdb. > > (gdb) ptype nml > > type =3D Type nml > > integer(kind=3D4) :: a > > integer(kind=3D4) :: b > > End Type nml > > (gdb) print nml > > $1 =3D ( a =3D 10, b =3D 20 ) > > --- > > gdb/ChangeLog | 11 +++++++ > > gdb/dwarf2/read.c | 41 +++++++++++++++++++---- > > gdb/f-valprint.c | 10 ++++++ > > gdb/testsuite/ChangeLog | 5 +++ > > gdb/testsuite/gdb.fortran/namelist.exp | 45 > > ++++++++++++++++++++++++++ > > gdb/testsuite/gdb.fortran/namelist.f90 | 27 ++++++++++++++++ > > include/dwarf2.def | 2 +- > > 7 files changed, 134 insertions(+), 7 deletions(-) create mode > > 100644 gdb/testsuite/gdb.fortran/namelist.exp > > create mode 100644 gdb/testsuite/gdb.fortran/namelist.f90 > > > > diff --git a/gdb/ChangeLog b/gdb/ChangeLog index > > 36cb4c9e7e9..ec01c2957e9 100644 > > --- a/gdb/ChangeLog > > +++ b/gdb/ChangeLog > > @@ -1,3 +1,14 @@ > > +2021-08-23 Bhuvanendra Kumar N > > +Bhuvanendra.KumarN@amd.com > > + > > + * dwarf2/read.c (process_die): Add new case for namelist. > > + (dwarf2_add_field): Process DW_TAG_namelist_item die. > > + (read_structure_type, handle_struct_member_die, new_symbol) > > + (dwarf2_name): Update. > > + * f-valprint.c (f_language::value_print_inner): Add support for > > + printing namelist items. > > + * include/dwarf2.def: (DW_AT_namelist_items): Renamed to ... > > + (DW_AT_namelist_item): ... this. As per dwarf standard. > > + > > 2021-06-08 Lancelot Six lsix@lancelotsix.com > > * python/lib/gdb/FrameDecorator.py (FrameDecorator): Use 'is None= ' > > diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index > > 96009f1418f..54528d67498 100644 > > --- a/gdb/dwarf2/read.c > > +++ b/gdb/dwarf2/read.c > > @@ -9570,6 +9570,7 @@ process_die (struct die_info *die, struct dwarf2_= cu *cu) > > case DW_TAG_interface_type: > > case DW_TAG_structure_type: > > case DW_TAG_union_type: > > + case DW_TAG_namelist: > > process_structure_scope (die, cu); > > break; > > case DW_TAG_enumeration_type: > > @@ -14417,8 +14418,20 @@ dwarf2_add_field (struct field_info *fip, stru= ct die_info *die, > > fp =3D &new_field->field; > > - if (die->tag =3D=3D DW_TAG_member && ! die_is_declaration (die, cu)) > > - { > > + if ((die->tag =3D=3D DW_TAG_member || die->tag =3D=3D DW_TAG_namelis= t_item) && > > + ! die_is_declaration (die, cu)) > > The '&&' operator should start the line. > > > + { > > + /* For the DW_TAG_namelist_item die, use the referenced die. */ > > + if (die->tag =3D=3D DW_TAG_namelist_item) > > + { > > + struct attribute *attr1 =3D dwarf2_attr (die, DW_AT_namelist= _item, cu); > > + struct die_info *item_die =3D NULL; > > Throughout this patch, please use nullptr instead of NULL. > > > + struct dwarf2_cu *item_cu =3D cu; > > + if (attr1->form_is_ref ()) > > + item_die =3D follow_die_ref (die, attr1, &item_cu); > > + if (item_die !=3D NULL) > > + die =3D item_die; > > + } > > /* Data member other than a C++ static data member. */ > > /* Get type of field. */ > > @@ -15449,6 +15462,8 @@ read_structure_type (struct die_info *die, stru= ct dwarf2_cu *cu) > > type =3D alloc_type (objfile); > > INIT_CPLUS_SPECIFIC (type); > > + if (die->tag =3D=3D DW_TAG_namelist) > > + INIT_NONE_SPECIFIC (type); > > I think you should use if/then/else and place INIT_CPLUS_SPECIFIC in the = else block. > > > name =3D dwarf2_name (die, cu); > > if (name !=3D NULL) > > @@ -15684,7 +15699,8 @@ handle_struct_member_die (struct die_info *chil= d_die, struct type *type, > > struct dwarf2_cu *cu) { > > if (child_die->tag =3D=3D DW_TAG_member > > - || child_die->tag =3D=3D DW_TAG_variable) > > + || child_die->tag =3D=3D DW_TAG_variable > > + || child_die->tag =3D=3D DW_TAG_namelist_item) > > { > > /* NOTE: carlton/2002-11-05: A C++ static data member > > should be a DW_TAG_member that is a declaration, but @@ > > -15728,7 > > +15744,9 @@ handle_struct_member_die (struct die_info *child_die, > > struct type *type, } > > /* Finish creating a structure or union type, including filling in > > - its members and creating a symbol for it. */ > > + its members and creating a symbol for it. This function also > > + handles Fortran namelist variable, its items or members and > > + creating a symbol for it. */ > > static void > > process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)=20 > > @@ -21807,8 +21825,17 @@ new_symbol (struct die_info *die, struct type = *type, struct dwarf2_cu *cu, > > case DW_TAG_union_type: > > case DW_TAG_set_type: > > case DW_TAG_enumeration_type: > > - SYMBOL_ACLASS_INDEX (sym) =3D LOC_TYPEDEF; > > - SYMBOL_DOMAIN (sym) =3D STRUCT_DOMAIN; > > + case DW_TAG_namelist: > > + if (die->tag =3D=3D DW_TAG_namelist) > > + { > > + SYMBOL_ACLASS_INDEX (sym) =3D LOC_STATIC; > > + SYMBOL_DOMAIN (sym) =3D VAR_DOMAIN; > > + } > > + else > > + { > > + SYMBOL_ACLASS_INDEX (sym) =3D LOC_TYPEDEF; > > + SYMBOL_DOMAIN (sym) =3D STRUCT_DOMAIN; > > + } > > { > > /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't @@ > > -22744,6 +22771,7 @@ dwarf2_name (struct die_info *die, struct dwarf2_c= u *cu) > > && die->tag !=3D DW_TAG_class_type > > && die->tag !=3D DW_TAG_interface_type > > && die->tag !=3D DW_TAG_structure_type > > + && die->tag !=3D DW_TAG_namelist > > && die->tag !=3D DW_TAG_union_type) > > return NULL; > > @@ -22768,6 +22796,7 @@ dwarf2_name (struct die_info *die, struct dwarf= 2_cu *cu) > > case DW_TAG_interface_type: > > case DW_TAG_structure_type: > > case DW_TAG_union_type: > > + case DW_TAG_namelist: > > /* Some GCC versions emit spurious DW_AT_name attributes for unn= amed > > structures or unions. These were of the form "._%d" in GCC 4.1, > > or simply "" or "" in GCC > > 4.3 diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c index=20 > > 240daaf34f9..8ed35e2fb1f 100644 > > --- a/gdb/f-valprint.c > > +++ b/gdb/f-valprint.c > > @@ -320,6 +320,16 @@ f_language::value_print_inner (struct value *val, = struct ui_file *stream, > > fputs_filtered (" =3D ", stream); > > } > > + /* While printing namelist items, fetch the appropriate val= ue > > + field before printing its value. */ > > + if (TYPE_SPECIFIC_FIELD (type) =3D=3D TYPE_SPECIFIC_NONE) > > I'm a little uncomfortable with this if condition. This feels like a bit= of a hack. Is there precedent anywhere else in GDB for using the type spe= cific field like this? > > Wouldn't adding a TYPE_CODE_NAMELIST be more in keeping with how GDB curr= ently does things, though I understand this is likely to make the patch sli= ghtly bigger. Did you consider this approach? > > > > > > + { > > + struct block_symbol symni =3D lookup_symbol(field_name, > > + get_selected_block (0), VAR_DOMAIN, nullptr); > > There's a missing space before '(' here, and two lines below. > > > + if (symni.symbol !=3D NULL) > > + field =3D value_of_variable(symni.symbol, symni.block= ); > > + } > > + > > common_val_print (field, stream, recurse + 1, > > options, current_language); diff --git=20 > > a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index=20 > > 87cf3e2a061..33f60c29b3c 100644 > > --- a/gdb/testsuite/ChangeLog > > +++ b/gdb/testsuite/ChangeLog > > @@ -1,3 +1,8 @@ > > +2021-07-26 Bhuvanendra Kumar N > > +Bhuvanendra.KumarN@amd.com > > + > > + * gdb.fortran/namelist.exp: New file. > > + * gdb.fortran/namelist.f90: New file. > > + > > 2021-06-10 Bhuvanendra Kumar N Bhuvanendra.KumarN@amd.com > > * gdb.fortran/ptype-on-functions.exp: Add type info of formal=20 > > diff --git a/gdb/testsuite/gdb.fortran/namelist.exp > > b/gdb/testsuite/gdb.fortran/namelist.exp > > new file mode 100644 > > index 00000000000..e4df8c7debb > > --- /dev/null > > +++ b/gdb/testsuite/gdb.fortran/namelist.exp > > @@ -0,0 +1,45 @@ > > +# Copyright 2020-2021 Free Software Foundation, Inc. > > The '2020' date is only needed if the patch was original posted in 2020, = or if this file is copied/based on some other in-tree file that is copyrigh= t 2020+. > > > + > > +# This program is free software; you can redistribute it and/or=20 > > +modify # it under the terms of the GNU General Public License as=20 > > +published by # the Free Software Foundation; either version 3 of=20 > > +the License, or # (at your option) any later version. > > +# > > +# This program is distributed in the hope that it will be useful, #=20 > > +but WITHOUT ANY WARRANTY; without even the implied warranty of #=20 > > +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU=20 > > +General Public License for more details. > > +# > > +# You should have received a copy of the GNU General Public License=20 > > +# along with this program. If not, see https://nam11.safelinks.protec= tion.outlook.com/?url=3Dhttp%3A%2F%2Fwww.gnu.org%2Flicenses%2F&data=3D0= 4%7C01%7CBhuvanendra.KumarN%40amd.com%7C1b602ae2197248e5a9a008d988e12ef7%7C= 3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637691323019160499%7CUnknown%7CT= WFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%= 3D%7C1000&sdata=3DKoXo6%2BRQEYSwRQ6VV%2Batjx0FoVfnufps0RJnK88k2y0%3D&am= p;reserved=3D0. > > + > > +# This file is part of the gdb testsuite. It contains tests for=20 > > +fortran # namelist. > > + > > +if { [skip_fortran_tests] } { return -1 } > > + > > +standard_testfile .f90 > > +load_lib "fortran.exp" > > + > > +if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug= f90}]} { > > + return -1 > > +} > > + > > +if ![fortran_runto_main] then { > > + perror "couldn't run to main" > > + continue > > +} > > + > > +# Depending on the compiler being used, the type names can be printed = differently. > > +set int [fortran_int4] > > + > > +gdb_breakpoint [gdb_get_line_number "Display namelist"]=20 > > +gdb_continue_to_breakpoint "Display namelist" > > + > > +if {[test_compiler_info {gcc-*}]} { > > + gdb_test "ptype nml" "type =3D Type nml\r\n *$int :: a\r\n *$int := : b\r\n *End Type nml" > > + gdb_test "print nml" \\$\[0-9\]+ =3D \\( a =3D 10, b =3D 20=20 > > +\\) > > The pattern should be wrapped onto the newline. > > Thanks, > Andrew > > > +} else { > > + gdb_test "ptype nml" "No symbol \"nml\" in current context\\." > > + gdb_test "print nml" "No symbol \"nml\" in current context\\." > > +} > > diff --git a/gdb/testsuite/gdb.fortran/namelist.f90 > > b/gdb/testsuite/gdb.fortran/namelist.f90 > > new file mode 100644 > > index 00000000000..00704eddf27 > > --- /dev/null > > +++ b/gdb/testsuite/gdb.fortran/namelist.f90 > > @@ -0,0 +1,27 @@ > > +! Copyright 2020-2021 Free Software Foundation, Inc. > > +! > > +! This program is free software; you can redistribute it and/or=20 > > +modify ! it under the terms of the GNU General Public License as=20 > > +published by ! the Free Software Foundation; either version 3 of=20 > > +the License, or ! (at your option) any later version. > > +! > > +! This program is distributed in the hope that it will be useful, ! > > +but WITHOUT ANY WARRANTY; without even the implied warranty of ! > > +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU=20 > > +General Public License for more details. > > +! > > +! You should have received a copy of the GNU General Public License ! > > +along with this program. If not, see https://nam11.safelinks.protecti= on.outlook.com/?url=3Dhttp%3A%2F%2Fwww.gnu.org%2Flicenses%2F&data=3D04%= 7C01%7CBhuvanendra.KumarN%40amd.com%7C1b602ae2197248e5a9a008d988e12ef7%7C3d= d8961fe4884e608e11a82d994e183d%7C0%7C0%7C637691323019160499%7CUnknown%7CTWF= pbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D= %7C1000&sdata=3DKoXo6%2BRQEYSwRQ6VV%2Batjx0FoVfnufps0RJnK88k2y0%3D&= reserved=3D0. > > +! > > +! This file is the Fortran source file for namelist.exp. > > + > > +program main > > + > > + integer :: a, b > > + namelist /nml/ a, b > > + > > + a =3D 10 > > + b =3D 20 > > + Write(*,nml) ! Display namelist > > + > > +end program main > > diff --git a/include/dwarf2.def b/include/dwarf2.def index > > 1ae6e1df298..6b8be1f6a16 100644 > > --- a/include/dwarf2.def > > +++ b/include/dwarf2.def > > @@ -289,7 +289,7 @@ DW_AT (DW_AT_frame_base, 0x40) DW_AT=20 > > (DW_AT_friend, 0x41) DW_AT (DW_AT_identifier_case, 0x42) DW_AT=20 > > (DW_AT_macro_info, 0x43) -DW_AT (DW_AT_namelist_items, 0x44) > > +DW_AT (DW_AT_namelist_item, 0x44) > > DW_AT (DW_AT_priority, 0x45) > > DW_AT (DW_AT_segment, 0x46) > > DW_AT (DW_AT_specification, 0x47) > > -- > > 2.17.1 > > > > > > >