From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam08on2071.outbound.protection.outlook.com [40.107.101.71]) by sourceware.org (Postfix) with ESMTPS id 423FE3858D20 for ; Mon, 7 Feb 2022 14:41:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 423FE3858D20 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kC1nLJtYnf5WNP+hh1PckGClKVINhu8XMY/VnhoLnThFDX3qwHsndog1wmbXv5eVZfpMNsOb6okauf6URYStkTZhTIf4LFgeMtE+qs21JkmeqyX6lT2n8L9zW2qtdDE2F9w6TcFfQHChgCgnQ9tAq/tbMSaSsFHVTG1POu6cNuJBayJkFpyDMy7bIpbhCPmS7rG7l2ARzIl2OFcRBngMHWwBwEV55h4kd9hMqmgTtUzd3My43fDgJty7KoOgCr9i+C+ZwviKp8bgNP7Y2WBk4PneQjigCq6Pf0teLrFJiyiRpJ7FunJOsuteqwrtQ7oSwL7SKF8aHKmwgN/8OVhr8g== 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=0CRwxmwiBNlpEw6TjQKALAvQuc6gWwRNB0FPMNYKaOY=; b=SoB07VrN3X5LWIWsalUBsQ6OrLWlCK1NPKwpb/tEjiPu9UuPhrn1hJr2ijuTuECad5Nq6zRs+6ZShHcUPCwPNPAaRiKRjAX38QdQBH11SYD2ST6/fFVKQ5f80LbJM/uTCYAirJdfYfrrlA4/rvDUiWQeTFtVI5nLY1U2CbpdIIvY8jGx4EM7LvcRm8eKrweXqZJ0Ri0pFG9PziOZTbnqsCiWS4bpnecGcJxQK1r3BKOQeA2qwvvSEPMJV9+41jch4y5SLh5Ko1AQsrPm+d5km+cBsjDMaoDSRKcHs4WqFSBNMNlSDqqeDvITyNXem30CbKwSVusr0xuY9+cYDxG6zg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from MW2PR12MB4684.namprd12.prod.outlook.com (2603:10b6:302:13::29) by DM6PR12MB4403.namprd12.prod.outlook.com (2603:10b6:5:2ab::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.11; Mon, 7 Feb 2022 14:41:10 +0000 Received: from MW2PR12MB4684.namprd12.prod.outlook.com ([fe80::a56d:39af:d0ea:fdfd]) by MW2PR12MB4684.namprd12.prod.outlook.com ([fe80::a56d:39af:d0ea:fdfd%4]) with mapi id 15.20.4951.019; Mon, 7 Feb 2022 14:41:09 +0000 From: "Kumar N, Bhuvanendra" To: Andrew Burgess CC: Joel Brobecker , "George, Jini Susan" , "Achra, Nitika" , "Sharma, Alok Kumar" , "gdb-patches@sourceware.org" 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/AACxzmqgAA84QAgCGPfWdAAAOU2MALESQhwACv/V4ABM5CGMAHgE0kAAKyP/yAFgSX1oALFtceAAMBxxuA= Date: Mon, 7 Feb 2022 14:41:09 +0000 Message-ID: References: <20211006155135.GS1900093@embecosm.com> <20220203184357.GB1474789@redhat.com> In-Reply-To: <20220203184357.GB1474789@redhat.com> 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=2022-02-07T14:41:02Z; 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=cca85f2f-68e6-40da-9b60-db9165c73707; 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: 2022-02-07T14:41:02Z 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: 93625c8d-6e6b-4565-ac84-dc2637f5bd78 msip_label_88914ebd-7e6c-4e12-a031-a9906be2db14_contentbits: 0 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d2c910ec-7809-46dd-1a1c-08d9ea47e1a2 x-ms-traffictypediagnostic: DM6PR12MB4403:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:219; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: zH0Zzr4nzXoG1Oid2BHg2R5Firb3q+CNrJmftAJ12wi54tFQwhX6QHjNL4az16IfuVIGQA7g8TEGT70ktxScjR+t4YvlbfGixOBXDn2YDfA8xJoxPdshKXEbYKTalYFMDpBGUwgJ/Vb0Rl/Nk/pvvxcmSMUFIXshKAtSSvZmojnEtjvoOH7fMq3FwK2ji/752/snQf/N014nW5Fsfej/M0B1ddku8QItn3DnDM6nFpYvyWJ6HMIMG8AW8wjFRFzGDg1W9UHUMTYVtUk47uMStFUxLt38fBcQdM52ngLw9Bvc67vFevHOpoVAH8f30Zg56W20bXbIZb+mS/NZNyGt2KbCw6Po8iIztW2x/s1sjMDQO5WMl/4qzA7Tm++q91ELkZKr8JHm/9i0u42OgQMiBqR0BWq3Yy9tK8yeLfh1heuTcfGemYM+Xe2wWN8h3rKLrPHzfyHEGnM2Ju1UqT6Xpb5c/jOQDGxkpgICXrUhQKRFzIIjVvQaAUBEZMXaT/Uu3QvaZZ4NfcxBCS5x174Tztta61DJjbZk7FdhkGtLlbyzb5dZ4c3BMqUQjr492wmeBEWtQExLOW0Poo0FesoHS5dScrHCwPdrK1bqlUFmFaSMdtKHg2c7Qo91ndN3WNS2kBP3jysS+ZCE5KgYKnvj4efiMiZev/OE5N7cZBuZJz4YxUWNFvgfTADAMHs6ZwRCS7Twa0AC55uZuZtXFDbq13U2awa5WR3KIys1x6anzaDB9YZ0aDALxI2N70MULqGSo+9sjlCrYvrrw7i37Ay8nKrNpUzyvJGkizQTQGrwrcxODYvvcv+5l0MM79UxKd2V 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:(13230001)(4636009)(366004)(4326008)(186003)(5660300002)(26005)(38070700005)(55016003)(33656002)(71200400001)(83380400001)(86362001)(76116006)(66946007)(66476007)(64756008)(66556008)(66446008)(9686003)(8936002)(8676002)(2906002)(6506007)(38100700002)(53546011)(7696005)(30864003)(122000001)(52536014)(508600001)(316002)(54906003)(6916009)(2004002); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?5HOhxctZ/0Q7SvRpJltBe+J6pvMUpzidlDmCLPoQC4O3efq6FJtxZem4oRAG?= =?us-ascii?Q?GEjym50jrHNz3pCRr44R6bDKmg0+cTNflcyU/SuqA8rqqPqYHb6+glWnB2Nr?= =?us-ascii?Q?GiEwB92dI+LsyB0eT/OpBU876OfssLOprfs9DiCHFLQ4WXRy2fWX7jTYmA2s?= =?us-ascii?Q?FdfptURer1B7bo/RrZJKGj14A6ggIxgVfJdJFHdTph52ahSY/E5vxuW6pboS?= =?us-ascii?Q?gz6bYHtkXv1XwCBvN/8j0Q56EKRSEpwMjEvkGkJ0fATPWC/muwP/f7E4b6sC?= =?us-ascii?Q?lo7ezPkvTJAnmC3hXmcnTE/bKnx91yAcQcArSJqt32eoyRI21T2FFY77lTsS?= =?us-ascii?Q?HDdK8QfV0N4SCY8nGnjM6NiSceXmtGQBAT8COeTzxsc5uviBWcjrBzgDLOk5?= =?us-ascii?Q?D03bPdoNsoH2hyQAG3dVI/NUoEC91QmWfneIi3svAJYdCDAjl4qZwfBQuHA9?= =?us-ascii?Q?4PQU9vt5BTWASFoXh4R7U0TdYOMuzQcGd8ZznONFdgkCiQ8lo95cASb1gMnZ?= =?us-ascii?Q?HqTUixLgXiU51wP2G1Ynhq+hVrk3tvW2PbtmiTMWd9RaPp9FStYCX7c7Scty?= =?us-ascii?Q?+2kmYtn5+nM7YCesloKGLVhFMydt9bfqe5n49DRw9O9JKq9AYFiYTMUDJLSQ?= =?us-ascii?Q?/1GsTzIKmbsep2waiC/XGYgo9mbpdgI3Alx8i+RqjDfJnJbBNhYilDnkuENE?= =?us-ascii?Q?6RyKlx238b1Q+z1oPeHxR3r/4GHvcE+9gHPQvJwhLhQfa5MMP1XsTKINxZ/0?= =?us-ascii?Q?wrMSMKAuD5IR86y8zvoq3cka7pdoAEDr3W0DWtB70bKU0cvWxaaWuD0PpSNq?= =?us-ascii?Q?lRlq5Kwtt7PJi4Eq1BU3d/3TC0ZAegOlTTbVL7yZQWKDniFdlYcwcs24QXUn?= =?us-ascii?Q?LnA/vpkE1cNRGgnjvqxzmsowc0MJmwGiqkfm/tFssccSFcc9OxIPIaG+yRUw?= =?us-ascii?Q?caEtyN2wkyi02Sk1GnlBgYd/bV6SMiNuY9tG6Nmu4VECFHAl84Ae3JUX1R5x?= =?us-ascii?Q?ovaFU8uDw3z1IPGin1TLgJez28metz3IO+9mYEvVB0EfWvS4mNpd+bq3Ray5?= =?us-ascii?Q?2cY0pKxjswFJlhJdwkIpOc865flOX8atb237xgb8ONckQ31KJXQWxebuSf+M?= =?us-ascii?Q?H227lGJjwl560AkldNvSwrDtTPO1nJ/pt0Inhz7AkXkmbioCm8eJjyDrStdj?= =?us-ascii?Q?XMDkzsmbLTKzNmrnBc3AYANUCyUdCnkOyjYcfDnhDpUVCdfdhFMPn7l6G9rF?= =?us-ascii?Q?mPAajj+b+I7nRGP3ZjZYsffVEXd/ML8PxmbQo1PDa+VMf6fuvN/cRTS5J55o?= =?us-ascii?Q?zJINk3nGjfHOGa0M997eIc8xHtGBoCKBqZWKrn3dX+uyjOBFPHZypyrtXqtQ?= =?us-ascii?Q?wyT6fqrzZb7e9Aetgd0bIPx8BnLsSUQSK+9C0D6gF3fqsmBvKMu7/t54Xjzi?= =?us-ascii?Q?iLepBZgVfvJ0JMmbfAZ9BBnikBCrKL23m11FKG5ahksnfc24sLrnK4HwF4e2?= =?us-ascii?Q?9ZMEqYHr5gAIZbWCRTE7PbFlvaxZDKFV7y/ppoNoA3pnpgX25KCU20GhNM6+?= =?us-ascii?Q?j+Ze5AQP09nT6IVL2BkE1dDz0pGy0zBQAsQSQs7/eBGMZI8nqWqUqUJnptCt?= =?us-ascii?Q?uax4i3x0TP7BPhYXwnDH6DE=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: d2c910ec-7809-46dd-1a1c-08d9ea47e1a2 X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Feb 2022 14:41:09.7148 (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: 5pC7+T/QT5L15GZCZaMc3q2FM50e0sUb3aoDqF84GZP/kyZbxeggKL5zV7HBgPcrMj6eyMFZkmjiwGxo88OCUA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4403 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: Mon, 07 Feb 2022 14:41:18 -0000 [AMD Official Use Only] Hi Andrew, Thanks for the revised patch and suggestions, I looked at your code changes= (rearranging the code in f-valprint.c), the changes looks fine and also un= it and regression tested the changes. Also tested with -D_GLIBCXX_DEBUG=3D1= , even though we are not calling value_field() for namelist now. Please let me know how to proceed further, thanks again Regards, bhuvan -----Original Message----- From: Andrew Burgess =20 Sent: Friday, February 4, 2022 12:14 AM To: Kumar N, Bhuvanendra Cc: Joel Brobecker ; George, Jini Susan ; Achra, Nitika ; Sharma, Alok Kumar ; gdb-patches@sourceware.org; E, Nagajyothi Subject: Re: [PATCH] Fix ptype and print commands for namelist variables(a = fortran feature) [CAUTION: External Email] * Kumar N, Bhuvanendra via Gdb-patches [2022-0= 1-20 16:20:46 +0000]: > [AMD Official Use Only] > > Hi all, > > Sorry for the delay in sharing the revised patch, I was occupied with som= e other work. Please find the revised patch with all the details and also p= atch is inlined below. > > Reason for the assert failure when GDB is built with > -D_GLIBCXX_DEBUG=3D1 is, the size or length(TYPE_LENGTH) of the namelist= =20 > variable type was not populated, it was zero, hence assert was failing=20 > in gdbsupport/array-view.h. Now this is fixed and I could test with=20 > -D_GLIBCXX_DEBUG=3D1 > > Compiler is not emitting the size of the namelist variable type, hence=20 > GDB is calculating it. In similar types like DW_TAG_structure_type,=20 > DW_AT_byte_size attribute is emitted by compiler and GDB uses it with=20 > TYPE_LENGTH. It's not the case with DW_TAG_namelist. Hence size of the=20 > namelist variable type is calculated in GDB. Also unlike=20 > DW_TAG_structure_type, namelist items are not allocated in continuous=20 > memory, they are spread across, hence for each namelist item symbol=20 > table lookup is done before printing its value. This way making sure=20 > namelist items printing is intact. Hi Bhuvan, Thanks for continuing to work on this feature, and sorry for the slow turn = around on reviews. I took a look at the changes you made in the latest version, and I wasn't c= ompletely convinced. Setting the type length seems like a bad idea, given = that these namelists don't have a valid address, and don't actually live in= memory in a contiguous block. I assume this is why you ended up adding th= e change in value.c too. I think if we just reorder the code in f-valprint.c a little, then we can a= void the need to compute the type length. Could you test the patch below p= lease, and let me know if you see any problems. This is basically your work with some whitespace clean up in dwarf2/read.c,= the value.c change reverted, and f-valprint.c reworked a little. Oh, and = I updated the copyright year in the testsuite files. Let me know what you think. Thanks, Andrew --- commit 3b365631ef31051210b7ad26463aaccd3501cbfd Author: Bhuvanendra Kumar N Date: Wed Feb 2 17:52:27 2022 +0000 gdb/fortran: support ptype and print commands for namelist variables Gfortran supports namelists (a Fortran feature); it emits DW_TAG_namelist and DW_TAG_namelist_item dies. But gdb does not process these dies and does not support 'print' or 'ptype' commands on namelist variables. An attempt to print namelist variables results in gdb bailing 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 variables 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 ) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 1a749eac334..056ba= 97ee91 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -9694,6 +9694,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: @@ -14556,8 +14557,21 @@ dwarf2_add_field (struct field_info *fip, struct d= ie_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_it= em) + && !die_is_declaration (die, cu)) + { + if (die->tag =3D=3D DW_TAG_namelist_item) + { + /* Typically, DW_TAG_namelist_item are references to namelist ite= ms. + If so, follow that reference. */ + struct attribute *attr1 =3D dwarf2_attr (die, DW_AT_namelist_item= , 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. */ @@ -15615,6 +15629,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); @@ -15817,7 +15835,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 @@ -15860,8 += 15879,10 @@ handle_struct_member_die (struct die_info *child_die, struct ty= pe *type, handle_variant (child_die, type, fi, template_args, cu); } -/* Finish creating a structure or union type, including filling in - its members and creating a symbol for it. */ +/* Finish creating a structure or union type, including filling in its + members and creating a symbol for it. This function also handles Fortra= n + namelist variables, their items or members and creating a symbol for + them. */ static void process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) @@ -2= 1963,9 +21984,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; + } { /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't really ever be static objects: otherwise, if you try @@ -229= 02,6 +22931,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; @@ -22926,6 +22956,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 d= iff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c index 6fd3d519c86..3b26bf= 74b61 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, 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 3d13eb11fb0..10dfcaf= 7c41 100644 --- a/gdb/f-valprint.c +++ b/gdb/f-valprint.c @@ -512,24 +512,38 @@ f_language::value_print_inner (struct value *val, str= uct ui_file *stream, 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, "( "); for (index =3D 0; index < type->num_fields (); index++) { - struct value *field =3D value_field (val, index); - - struct type *field_type =3D check_typedef (type->field (index).ty= pe ()); - + struct type *field_type + =3D check_typedef (type->field (index).type ()); if (field_type->code () !=3D TYPE_CODE_FUNC) { - const char *field_name; + const char *field_name =3D type->field (index).name (); + struct value *field; + + if (type->code () =3D=3D TYPE_CODE_NAMELIST) + { + /* While printing namelist items, fetch the appropriate + value field before printing its value. */ + struct block_symbol sym + =3D lookup_symbol (field_name, get_selected_block (null= ptr), + VAR_DOMAIN, nullptr); + if (sym.symbol =3D=3D nullptr) + error (_("failed to find symbol for name list component= %s"), + field_name); + field =3D value_of_variable (sym.symbol, sym.block); + } + else + field =3D value_field (val, index); if (printed_field > 0) fputs_filtered (", ", stream); - field_name =3D type->field (index).name (); if (field_name !=3D NULL) { fputs_styled (field_name, variable_name_style.style (), d= iff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 7238873e4db..5072dc24bfa = 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -196,6 +196,19 @@ enum type_code /* * Fixed Point type. */ TYPE_CODE_FIXED_POINT, + + /* * Fortran namelist is a group of variables or arrays that can be + read or written. + + Namelist syntax: NAMELIST / groupname / namelist_items ... + NAMELIST statement assign a group name to a collection of variables + called as namelist items. The namelist items can be of any data typ= e + and can be variables or arrays. + + Compiler emit DW_TAG_namelist for group name and DW_TAG_namelist_it= em + for each of the namelist items. GDB process these namelist dies + and print namelist variables during print and ptype commands. */ + TYPE_CODE_NAMELIST, }; /* * 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..d6263e12fec --- /dev/null +++ b/gdb/testsuite/gdb.fortran/namelist.exp @@ -0,0 +1,50 @@ +# Copyright (C) 2021-2022 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 #=20 +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 \\)" +} 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..9e2ba0489d2 --- /dev/null +++ b/gdb/testsuite/gdb.fortran/namelist.f90 @@ -0,0 +1,27 @@ +! Copyright (C) 2021-2022 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 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 4214c80907a..530= c6f849f9 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)