From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2049.outbound.protection.outlook.com [40.107.93.49]) by sourceware.org (Postfix) with ESMTPS id E60513858D28 for ; Fri, 3 Dec 2021 18:56:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E60513858D28 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OEDRfJOPh/Tj/OH5dudvjU++6nj/vaYMWssXNwbHjAcYVNBQgMRmnrAhd0tRUw5eI4kn3KLp1U6fbAl115BeYq52ZGF+ADNQCcM68Yf0i9ZaEd5RB7E5/0I0bMnDZp6fWT56PDc2FKdEZFQGkMju2Jx2ybOGkvqx1YmQkSJ4fFyM4Noh9w2/qTMw0LM5+B3xAQWj9bSKlgeXs/RXjkw+XScu8yw/PTZzap/LXNoT5hK84TwgUSLJuRp1ousA0t5j5snaJmNSwpwiPaXKWK7KjkziH5gkB//59M3M7OrSzA2KNNpCiyGx2WFGURqXxdBOLhk0+b8+fmmxNW3Yfl7MCw== 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=f0cISEl8/ehq6fCb5HQV5M1ghqbRdAEvAwE5D/OVTNc=; b=eQb3FMnQcFJ4MVntE/4uETATWsqNp/O03KA6rreMOc6Oq5KDIIJZEGikVDzT+E8axXQ+ndqYxViMCwygg/jV5aUCTY/TUleQJbvl8haXQkakw76hcyx7fnzT12ywVqnToQ/EaPpSFIPthCL1LT/byQ1XzWUWLIJ8kAde6kCnkxw0deL5s5qOzmROQtPC5E6hCEiS6+nSqZWHplpaW5llrvetlISzGCZ+Nl2B+iOozWKcTPUdvTlBvx30tqN3cTaSEtqcKEPSR8PQ73ZfpjNzgSq8O7xWBlekUS9yGqy9i93sAc4KZiBlJWAS9FXipQ8PCkZvtGcB+4AJwFD5uR5Qnw== 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 MW2PR12MB2346.namprd12.prod.outlook.com (2603:10b6:907:4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23; Fri, 3 Dec 2021 18:56:41 +0000 Received: from MW2PR12MB4684.namprd12.prod.outlook.com ([fe80::604e:c4ba:b448:1b40]) by MW2PR12MB4684.namprd12.prod.outlook.com ([fe80::604e:c4ba:b448:1b40%5]) with mapi id 15.20.4755.019; Fri, 3 Dec 2021 18:56:41 +0000 From: "Kumar N, Bhuvanendra" To: "brobecker@adacore.com" CC: "gdb-patches@sourceware.org" , "George, Jini Susan" , "Achra, Nitika" , "Sharma, Alok Kumar" , "E, Nagajyothi" , Andrew Burgess Subject: RE: [PATCH] Fix ptype and print commands for namelist variables(a fortran feature) Thread-Topic: [PATCH] Fix ptype and print commands for namelist variables(a fortran feature) Thread-Index: AdeYyESNFilxiCvkSRWjYmJPezxZtgVO2csAAGpd/AACxzmqgAA84QAgCGPfWdAAAOU2MALESQhw Date: Fri, 3 Dec 2021 18:56:41 +0000 Message-ID: References: <20210920094122.GB4950@embecosm.com> <20211006155135.GS1900093@embecosm.com> In-Reply-To: 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-19T14:32:25Z; 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 msip_label_88914ebd-7e6c-4e12-a031-a9906be2db14_enabled: true msip_label_88914ebd-7e6c-4e12-a031-a9906be2db14_setdate: 2021-12-03T18:56:33Z 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: 5e1c094d-2029-4fc0-9dba-59c02fc45258 msip_label_88914ebd-7e6c-4e12-a031-a9906be2db14_contentbits: 0 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: f7227423-3565-4d67-c203-08d9b68ea4e2 x-ms-traffictypediagnostic: MW2PR12MB2346: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:151; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 3WqIQbdYW1NdYgD0Y5wj8rdl8UGhEdSVgPOjUhXtSUAUTmjXjIlOmA01kp4JbW3MJLZ6689+V9XXNzmZVLDjmYCPyE3Aqf+aFWzrnGRrs7zKZmZdcUIwtyT7khXdcwEUNBUhTiFYTstq+jIW5kpKHaaS2Idh4vVR9FztK8Cy4NNFgbZ2ojxJInGfaG8XzBR8ROWA/m9sjvQIPmBC8E48Y0o3m6ElSTOIQPTsJHVU12Ampqc6ccnfK5MLV74E2VPg/m59CiHw3ANVvm/R7L1QyvnIHEYna/Bzo0Ez0pDrGoxnQyj7JNrRFrGtCsqzb2qvjPxYaXFTmbUza2cCA34uV8+FNmvBdRfG/iA737pcUig7jdadNqLp0EjfbkRlnkqF5kypMiUv5ZSHgqRhSqmBFg8OfL+RjN/tDddZZBaaqkQ2eYRBRqpwTvO5zLHwR21xZtufYk7wz60stk+kopKrmESVLxkGEVnqi5YpWoxprpYrPIr/fXIxa3i1YxRCOFB3tcLmPG2ugox2/JEMxTLGIgXjjeemXjt5LDmveTR8QRYlfQqPWaqUvtyyjCatPMAuV6eXNZCzSxkK7GZfp3T8pLr/mu6o717u9ZfjKTWh9XnohZ0kCJezZk0sjuNTjfksq+sQoXnHYii6quPo9dX2DvbXPI0oCB05MiAGi1Nn0a5rXiEF1ZKmxwWOU5PWlPHGgUWEyMzCtYV5GQXCqbnCWgT5h0MbLbYiwA/FZfiUdcHRbSkYvJD/gyuanQXBrqy0Rl6Q7+fj0RUxpzY+S/AS03wPxp5vF1gg8wggGmTtCovpcEkWjirwgFO0mZ2bKuFV31/ekTvkK3iBGeODnmzYYkCQ+wJYm0NUHWeMoPv5yIw= 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)(45080400002)(6916009)(66556008)(66476007)(66446008)(64756008)(76116006)(26005)(38070700005)(9686003)(122000001)(55236004)(53546011)(66946007)(186003)(5660300002)(4326008)(54906003)(8936002)(8676002)(86362001)(6506007)(316002)(52536014)(966005)(84970400001)(55016003)(30864003)(83380400001)(7696005)(508600001)(33656002)(2906002)(71200400001)(38100700002)(2004002)(579004)(559001); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?iMrChPGRlxZrH0iXzqrE7CyYvawqll8if/MiqlKCgozsBpyBNi0gidVVXyU7?= =?us-ascii?Q?S21gjmvX9FpvdWN9xUHVlzqwZNP61n03nD7HRNKNXNrT3vFxjM7Izoh8gzCM?= =?us-ascii?Q?QTJOYlTImWsN1IlfZ7GqjQSnWQE/K75uZeAun+Gs5poNS86fAelIbEj94uU2?= =?us-ascii?Q?J85WnwNf/KRcsGA4Ot/qHFltcqa4Rbo1tAwYSQu7gz2zzpPoTnZp9vevX3Jf?= =?us-ascii?Q?dwEVSEXMLgPFFFAWHe4jO1tklk6UqiVeQZ4LlkPYSK8CDLnYeBweoaNXjPxo?= =?us-ascii?Q?uyG1opZOUDO8/PmawNdQy8VvoC5MIYYzF2Kf2gDqtrreXmWng2suKrOxtRPo?= =?us-ascii?Q?iSDU/8d5fmcCn8ZkTwHiFFpCZRSZ+0RYK+jTHtdNnqpas9QTdn4LEyyw9JI+?= =?us-ascii?Q?okOQG2Zc/qQqHC/DmQcLtlpBseRYOOcC/4RoVgs8mLcHANuIxX++qzFmS9Ht?= =?us-ascii?Q?LpjYSkpAifk5Oo3FXhJ8vz5++QcU+3F1qgeCtHkBhJD+Q49Ubq2A53NfDSJM?= =?us-ascii?Q?QqJvm7Dp18trI2nBxBTGnXW68TrqAOouYTMZjjLxkDWxNcpqax3bhycjklzH?= =?us-ascii?Q?e075PuXcU52ww9gd3yEstm9lWj4OimBs8x2iO8aaKM6L4wYds+BLAoZPH4xA?= =?us-ascii?Q?/Mwqwrwngx5STDDzxavHq3IQQwWEBwyy//8cbZKgRit35m7FzDrDP2KK4yC8?= =?us-ascii?Q?yNAT7c8Ls/HSrfN9QV5g+H9hZ4f2TUMDVE8OoayUMdUVZxBitBIETMG0uIvH?= =?us-ascii?Q?PBnQaNaFiGzkXNoD9Kp+gp4tvNq7pmeJ/gDSr4TDHyVhRXDtO1kpLUOlCOF7?= =?us-ascii?Q?r394+kK8M4hP80dAVTuxH0VP28bPfs4Fd1tb79pxOplgV6taYy0+D/qGCfhX?= =?us-ascii?Q?Vgj+lGfQgHyMBHWqKUWlFVxKxE/bOG87andNU+LVb95i4k/qvCsiRm+NysBR?= =?us-ascii?Q?MfJoLGbWKH63NtrOL8JtpD3TimzyRHB/qW0lQz5pLCqS/adHUHbZ/KT8MDbr?= =?us-ascii?Q?cTJRHC02yZ/VbkbrEQsJBi9xMIXqDw1ktf7u62CTg3V3rbJvJWLf0QGNyI9u?= =?us-ascii?Q?0gzsn5+YCnMKcbHUbS+nbebV0yMqElzigOT9zz2+cCGti3f720i4Ugts/Ly+?= =?us-ascii?Q?9JNkB3vWda37M1Wjpg6/633gbuv7EU5COP6/qrtBmTM6Vbce6m7LeVTnXRi3?= =?us-ascii?Q?h3pdgwOWSN0e0RfpoK3NIO4lmRWDU6onbwH1mtWs7LteCbJh0vHw4FoDvBfn?= =?us-ascii?Q?hwNJPkpz7BDXhemcTpgZUnhqEnFYkBI0KI/cltAqVTzzuFtv/S+9GOLgg1mL?= =?us-ascii?Q?7/UnqgdMqvZHCLmlN0MjrVwfGfzx9umtFRAziyAg3b3xWBM+T4kQ6tPRJ4Ow?= =?us-ascii?Q?yC8wb6YTvX13KmzyEGUOErGOR+3N+NN3oUiwyttUH8Y+PM5FZDv/WwiIOQps?= =?us-ascii?Q?LXxlhO0mKkobLPjnHv6zeI9Eeml69ifkwF6r3fDAPYX5gTwdhWfAdb/XUVhj?= =?us-ascii?Q?DC5yW8X/lUSnXySbX4wjYwCbEU+YUUrSPtDifxZNMcCVOx5cVQavOd2V4GaC?= =?us-ascii?Q?Jp/S3rA4SFyBa0U9XHUGELxNjwq1ZomBWW8qGyf9a9dGOD9f5DOdn7rsUCim?= =?us-ascii?Q?YDX19Ncao+tyJ0+8Jl7Cth0=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: f7227423-3565-4d67-c203-08d9b68ea4e2 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Dec 2021 18:56:41.5252 (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: llmZ8gm95RYeJhlLvJyzJRfUdOHZ8PHvF/y/sMT9fZS4NagNKAu7nlSzHIkgBpbRHFULoMwRCLo+4TtpAZve5g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR12MB2346 X-Spam-Status: No, score=-11.6 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: Fri, 03 Dec 2021 18:56:58 -0000 [AMD Official Use Only] Hi, Thanks a lot for your reply on this thread. I have observed your reply in t= he below GDB patches email archive. I did not get any email in my email cli= ent(Microsoft outlook) for your email reply, hence I have copy and pasted y= our reply here and my replies are inlined below. Thanks a lot for your time= . My replies are inlined below with Bhuvan start> and Bhuvan end>. Please bea= r with me for following such notation only for this time, since I had to co= py and paste your reply and reply on top of that, I could not find better m= ethod. Also majority of the indentation comments are mostly due to email cl= ient related, but I will address all of them. I tried to answer most of you= r queries and also giving brief introduction to namelist feature. Please le= t me know if you have more questions about these.=20 https://sourceware.org/pipermail/gdb-patches/2021-November/183907.html Joel Brobecker brobecker@adacore.com Sat Nov 27 07:56:51 GMT 2021 Hi Bhuvan, > Gentle PING*4 for the revised patch. Requesting some of you from the > community to review the updated code patch please, i had addressed all > the previous review comments. I'm very sorry for the lack of feedback for this patch. I'll attempt to help you push this patch through, knowing that I have no knowledge of Fortran. I only have time to do code reviews in the weekend, at the moment, so hopefully others might be able to join in and help. But otherwise, please bear with me. > 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 = variables. >=20 > GCC/gfortran support namelist(a fortran feature), it emits DW_TAG_namelis= t and DW_TAG_namelist_item dies. But gdb does not process these dies and su= pport namelist variables during print and ptype commands. When tried to pri= nt, 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 var= iables 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 ) This is a small detail, but typically, for text which is not a copy/paste of other things like GDB sessions, etc, we try to keep the length of each line down to something that fits within an 80-characters terminal. Adding the 4 characters that commands like "git log" or "git show" indents the commit message with, would you mind reformatting your explanations to fit within those 76-characters per line, please? Also, for those who are not familiar with Fortran, I think it would be useful to have a small introduction to that feature that goes beyond a bit of Fortran code in a testcase, and how GDB is proposed to show it. I'd like to understand what they mean semantically, how those are typically used, and how they are stored in memory (to understand how they work). This will help me better review this change. Can you provide that kind of info? Bhuvan start> Sample program: 1 program main 2 3 integer :: a, b 4 namelist /nml/ a, b 5 6 a =3D 10 7 b =3D 20 8 Write(*,nml) 9 10 end program main Output of this program: $ ./out &NML A =3D 10, B =3D 20 / Namelist is a group of variables or arrays that can be read or written.=20 Namelist syntax: NAMELIST / groupname / namelist_items ... NAMELIST statement assign a group name to a collection of variables. Here i= n this example namelist is a group of 2 integer variables a and b, these ar= e called namelist items. The group name is nml. The namelist items can be o= f any data type and can be variables or arrays. More details are shared bel= ow. dwarfdump of an gfortran emitted binary : compilers emit DW_TAG_namelist fo= r group name and DW_TAG_namelist_item for namelist items as shown below for= the above sample program. GDB needs to process these namelist dies and sup= port namelist variables printing with print and ptype commands.=20 . . . 0x000000b4: DW_TAG_variable [10] DW_AT_name [DW_FORM_string] ("a") DW_AT_decl_file [DW_FORM_data1] ("/home/bhuvan/work= /fortran/test/3180/n2.f90") DW_AT_decl_line [DW_FORM_data1] (20) DW_AT_type [DW_FORM_ref4] (cu + 0x006d =3D> {0x000000= 6d} "integer(kind=3D4)") DW_AT_declaration [DW_FORM_flag_present] (true) DW_AT_location [DW_FORM_exprloc] (DW_OP_fbreg -20) =20 0x000000c0: DW_TAG_variable [10] DW_AT_name [DW_FORM_string] ("b") DW_AT_decl_file [DW_FORM_data1] ("/home/bhuvan/work= /fortran/test/3180/n2.f90") DW_AT_decl_line [DW_FORM_data1] (20) DW_AT_type [DW_FORM_ref4] (cu + 0x006d =3D> {0x000000= 6d} "integer(kind=3D4)") DW_AT_declaration [DW_FORM_flag_present] (true) DW_AT_location [DW_FORM_exprloc] (DW_OP_fbreg -24) . . . 0x000000dd: DW_TAG_namelist [12] * DW_AT_name [DW_FORM_string] ("nml") =20 0x000000e2: DW_TAG_namelist_item [9] DW_AT_namelist_item [DW_FORM_ref4] (cu + 0x00b4 =3D> {= 0x000000b4}) =20 0x000000e7: DW_TAG_namelist_item [9] DW_AT_namelist_item [DW_FORM_ref4] (cu + 0x00c0 =3D> {= 0x000000c0}) =20 0x000000ec: NULL Bhuvan end> > --- > 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 g= db/testsuite/gdb.fortran/namelist.exp > create mode 100644 gdb/testsuite/gdb.fortran/namelist.f90 >=20 > diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index cbd9a3012eb..e6c= d8ed48f0 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= die_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_= item) > + && ! die_is_declaration (die, cu)) The indentation is incorrect. The "&&" opeator should line up with the indentation of the condition expression. Thus: > + 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. */ Can you explain why, and put that information in the comment? Bhuvan start> As shown in the above sample dwarf dump, DW_TAG_namelist_item points or ref= ers to actual variable die thru DW_FORM_ref4, hence we need to use the refe= renced die. Bhuvan end> Also, this is only a minor comment that you don't have to agree with, but FWIW, when I read your comment, I intuitively thought that namelist items were always references. On the other hand, reading the code itself, it doesn't appear to be so. > + 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. */ I think it would be better if you kept that comment at the start of the if block, so above your special handling of DW_TAG_namelist_item. > /* Get type of field. */ > @@ -15621,6 +15634,10 @@ read_structure_type (struct die_info *die, struc= t 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_= 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 @@ -15867,7 +1588= 5,9 @@ handle_struct_member_die (struct die_info *child_die, struct type *t= ype, } > =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) @@ = -21971,8 +21991,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; > + } I have to say, I'm a little uncomfortable with this part of the change -- perhaps simply because I don't understand it. Does it make sense to handle DW_TAG_namelist here? This second handles a group of *types*, wheres the change suggests that namelist are more like *variables*. Should the two be handled at the same place? What made you pick this part of the code to insert support for DW_TAG_namelist? Or am I misunderstanding the concept of namelists (which brings me back to the question at the beginning)? Bhuvan start> DW_TAG_namelist are similar to DW_TAG_structure_type or DW_TAG_union_type, = hence I have placed them here. Basically namelist variable nml (in the abov= e sample program) is a group of items a and b. please note a and b are decl= ared before only and storage is allocated as part of that. For namelist ite= ms (a and b), there is no separate storage gets created or allocated, same = storage is used/referenced. DW_TAG_namelist_item points to the original var= iable die. Hence namelist is just a group of such items. Main advantage of = these namelist is that they can be used for I/O and they cannot be categori= zed strictly as type only, hence namelists are handled at the same place as= that of DW_TAG_structure_type, but since they can be used with I/O stateme= nts (which is the main advantage of using namelist in fortran), I have cate= gorized them as VAR_DOMAIN, so that I can use it during print command as we= ll inside GDB.=20 Hence namelist cannot be categorized as type only feature, it's a combinati= on of type and variable, if we want to put it this way.=20 I have used a separate type (TYPE_CODE_NAMELIST) for namelist after Andrew = suggestion. Bhuvan end> > { > /* 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 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-typeprint.c b/gdb/f-typeprint.c index 1791cb29451..5b34622dac= b 100644 > --- a/gdb/f-typeprint.c > +++ b/gdb/f-typeprint.c > @@ -121,6 +121,7 @@ f_language::f_type_print_varspec_prefix (struct type = *type, > 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 = *type, > 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, str= uct 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, str= uct 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..6f80b= 5a12ff 100644 > --- a/gdb/f-valprint.c > +++ b/gdb/f-valprint.c > @@ -295,6 +295,7 @@ f_language::value_print_inner (struct value *val, str= uct 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, st= ruct 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); Can you fix the indentation here, please? On the second line, the start of the parameters should be aligned with the start of the parameters on the lines above. Also, remember that indentation is 2 characters, not 4. You could have... struct block_symbol symni =3D lookup_symbol (field_name, get_selected_block (0), VAR_DOMAIN, nullptr); ... or (one parameter per line) ... struct block_symbol symni =3D lookup_symbol (field_name, get_selected_block (0), VAR_DOMAIN, nullptr); ... or move all the parameters on the next line, with: 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..ba8a61987= db 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. */ In terms of documenting the enumerate, can you use the same style as the other enums? This is actually important, because I believe this is to allow us to use Doxygen to generate documentation (something we may not have done for a while, but I'd rather we don't make it worse). > =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/= 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 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. I think there are trailing spaces at the end of several lines above. While at it, would you mind please removing them all? Or, actually, given the above, I'm wondering if this wasn't caused by your mailer making some reformatting changes.. > + > +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. Same request as in the commit message: It would be nice if we could keep the code and comments without 80-characters whenever reasonable. > +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.f= ortran/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..6= b8be1f6a16 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, = 0x41) DW_AT (DW_AT_identifier_case, 0x42) DW_AT (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: Kumar N, Bhuvanendra=20 Sent: Friday, November 19, 2021 8:03 PM To: aburgess@redhat.com Cc: gdb-patches@sourceware.org; George, Jini Susan ; Achra, Nitika ; Sharma, Alok Kumar ; E, Nagajyothi ; Joseph, Ancel Subject: RE: [PATCH] Fix ptype and print commands for namelist variables(a = fortran feature) [AMD Official Use Only] Hi Andrew, Looks like gfortran is emitting DW_TAG_namelist for "nml" twice, hence you = are seeing it twice with "info local" command. But clang/flang emits only o= nce, hence I am getting only once with "info local" command. my GDB command outputs are with clang/flang compiler. Please let me know if= you want to try with clang/flang, I can share the details, thanks a lot ag= ain regards, bhuvan -----Original Message----- From: Kumar N, Bhuvanendra Sent: Friday, November 19, 2021 7:39 PM To: 'aburgess@redhat.com' Cc: 'gdb-patches@sourceware.org' ; George, Jini= Susan ; Achra, Nitika ; Sh= arma, Alok Kumar ; E, Nagajyothi ; Joseph, Ancel Subject: FW: [PATCH] Fix ptype and print commands for namelist variables(a = fortran feature) [AMD Official Use Only] Hi Andrew, Thanks again for the review. Could you please use this revised patch for th= e review, thanks I am resending the revised patch now and details are shared just below in t= his email chain. I am getting the proper outputs with "info local" as shown below. Regards, bhuvan (gdb) i local a =3D 10 b =3D 20 nml =3D ( a =3D 10, b =3D 20 ) (gdb) pt nml type =3D Type nml integer :: a integer :: b End Type nml (gdb) whatis nml type =3D Type nml -----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 > > > > > > >=