From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id D17E03858C2C for ; Wed, 6 Oct 2021 15:51:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D17E03858C2C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wr1-x42b.google.com with SMTP id k7so10119794wrd.13 for ; Wed, 06 Oct 2021 08:51:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=d5Yr+4ir80aONhtvhLbJSDYWnwOpSt52Jh0d4m1rSrw=; b=MaUPqs4FQ6Dwnpxo8/fwLHwUNUbuMXYt1+rOrjQ0QvqMNWU4K281+g23gc0n7qOvIh Df/opcClUXUF8xMYF+i2pty13kCbpdCRi7/Y+JuU8xKpuKbyGl7g7RY2gOkKcEvT1n1w jjm6p6mn47x0kgduGw2QCH372lZd11ajLXVznSWuXUxk4qatMkMwL+FIM4ufqEUejz92 la5xswosORsP7YxKTVFIOUkME/0hal0xFbqcxAZUxJp4PpGotmPThtxaCT6ksD1q+Rz8 7ZqOtfc0gSV+d1MKiBKgTsmQCrkzZ9rpbWf+8oChmoPQmoinMnd2i1VXNmj+FO02pDqO k2+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=d5Yr+4ir80aONhtvhLbJSDYWnwOpSt52Jh0d4m1rSrw=; b=PWcZtnlwGNtEQvAzLAQBu2tfTUjk9dYN/goTldL4xlKubVySfyDJJKg4jNGd+Xa74o GBHHMTipPIXOgE3Lb6kRts6MbbJT3XJBpTxT575k/6+BapstP2NuW+Run2bh4pJ+gdqY Tayqk0FE0YwJ4WspmnrBhoCdtjHqbPM8adF7ZeEzSzHyuZOnECxy3mSg3MlnCwwcv9lA J+gG28r7C6pefTvz1Kll/She4fOylXqyPv9v/FEjAaYas7uxVTKE+m690FSxkkO2bidD jj0jBBN5YuMAEkpjsknzh9jFSeVjE29caF2vD8va9oWVF4DW/M8mCNUEVfmC2fSe/T3Y gJtA== X-Gm-Message-State: AOAM533e2qWZzCVoYYd5SW5YWEZeFiY/VrGziS4i1yLs0MyT++lSeR1i HcA+SjGGdv2qA4Ofr6y5ijmP/A== X-Google-Smtp-Source: ABdhPJyrqet2BzVYYNgNhUtxNm07+iXWeUEusALP1NMEraehkS/8E3OECNjEXre2DjEs58IDRGFNTQ== X-Received: by 2002:a5d:4cca:: with SMTP id c10mr26569241wrt.188.1633535497502; Wed, 06 Oct 2021 08:51:37 -0700 (PDT) Received: from localhost (host86-169-137-11.range86-169.btcentralplus.com. [86.169.137.11]) by smtp.gmail.com with ESMTPSA id l2sm5928137wmi.1.2021.10.06.08.51.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Oct 2021 08:51:37 -0700 (PDT) Date: Wed, 6 Oct 2021 16:51:35 +0100 From: Andrew Burgess 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) Message-ID: <20211006155135.GS1900093@embecosm.com> References: <20210920094122.GB4950@embecosm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: Linux/5.8.18-100.fc31.x86_64 (x86_64) X-Uptime: 16:45:36 up 17 days, 6:54, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] X-Spam-Status: No, score=-9.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_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, 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: Wed, 06 Oct 2021 15:51:42 -0000 * Kumar N, Bhuvanendra [2021-09-22 12:38:20 +0000]: > [AMD Official Use Only] > > Hi Andrew, > > Thanks a lot for your review comments, I have addressed all the review comments and tested. Updated patch is attached and also inlined with this email. > > >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 specific field like this? > >Wouldn't adding a TYPE_CODE_NAMELIST be more in keeping with how GDB currently does things, though I understand this is likely to make the patch slightly bigger. Did you consider this approach? > > Regarding your major comment, I did considered introducing a new > type specific field for namelist earlier, instead of using any of > those existing. Reason I did not included in my earlier patch was, > type_specific_kind is declared with 3 bits in struct main_type and > already there were 8 values, hence deferred expanding > type_specific_kind etc.... But now I have done that, thanks for the > suggestion. Except that wasn't quite what I suggested; I actually asked whether namelist's should become their own type altogether, notice I suggested TYPE_CODE_NAMELIST. 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: =?UTF-8?q?=E2=80=9Cbhkumarn=E2=80=9D?= > Date: Wed, 22 Sep 2021 17:52:15 +0530 > Subject: [PATCH] Fix ptype and print commands for namelist variables(a fortran > feature). > > 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 > support 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 > variables and its items. Sample output of these commands is shared below, > with fixed gdb. > (gdb) ptype nml > type = Type nml > integer(kind=4) :: a > integer(kind=4) :: b > End Type nml > (gdb) print nml > $1 = ( a = 10, b = 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, struct die_info *die, > > fp = &new_field->field; > > - if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) > - { > + if ((die->tag == DW_TAG_member || die->tag == DW_TAG_namelist_item) > + && ! die_is_declaration (die, cu)) > + { > + /* For the DW_TAG_namelist_item die, use the referenced die. */ > + if (die->tag == DW_TAG_namelist_item) > + { > + struct attribute *attr1 = dwarf2_attr (die, DW_AT_namelist_item, cu); > + struct die_info *item_die = nullptr; > + struct dwarf2_cu *item_cu = cu; > + if (attr1->form_is_ref ()) > + item_die = follow_die_ref (die, attr1, &item_cu); > + if (item_die != nullptr) > + die = 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, struct dwarf2_cu *cu) > } > > type = alloc_type (objfile); > - INIT_CPLUS_SPECIFIC (type); > + if (die->tag == DW_TAG_namelist) > + TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_NAMELIST; > + else > + INIT_CPLUS_SPECIFIC (type); > > name = dwarf2_name (die, cu); > if (name != 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 == DW_TAG_member > - || child_die->tag == DW_TAG_variable) > + || child_die->tag == DW_TAG_variable > + || child_die->tag == 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 *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) > @@ -21807,8 +21826,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) = LOC_TYPEDEF; > - SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; > + case DW_TAG_namelist: > + if (die->tag == DW_TAG_namelist) > + { > + SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC; > + SYMBOL_DOMAIN (sym) = VAR_DOMAIN; > + } > + else > + { > + SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF; > + SYMBOL_DOMAIN (sym) = 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 != DW_TAG_class_type > && die->tag != DW_TAG_interface_type > && die->tag != DW_TAG_structure_type > + && die->tag != DW_TAG_namelist > && die->tag != 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 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-valprint.c b/gdb/f-valprint.c > index 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, struct ui_file *stream, > fputs_filtered (" = ", stream); > } > > + /* While printing namelist items, fetch the appropriate value > + field before printing its value. */ > + if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_NAMELIST) > + { > + struct block_symbol symni = lookup_symbol (field_name, > + get_selected_block (0), VAR_DOMAIN, nullptr); > + if (symni.symbol != nullptr) > + field = 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 a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog > index 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 > 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 > +# it under the terms of the GNU General Public License as published by > +# 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 WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU 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 . > + > +# This file is part of the gdb testsuite. It contains tests for 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"] > +gdb_continue_to_breakpoint "Display namelist" > + > +if {[test_compiler_info {gcc-*}]} { > + gdb_test "ptype nml" \ > + "type = Type nml\r\n *$int :: a\r\n *$int :: b\r\n *End Type nml" > + gdb_test "print nml" \ > + "\\$\[0-9\]+ = \\( a = 10, b = 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 modify > +! it under the terms of the GNU General Public License as published by > +! 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 WITHOUT ANY WARRANTY; without even the implied warranty of > +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +! GNU 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 . > +! > +! This file is the Fortran source file for namelist.exp. > + > +program main > + > + integer :: a, b > + namelist /nml/ a, b > + > + a = 10 > + b = 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 (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: Andrew Burgess > Sent: Monday, September 20, 2021 3:11 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 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 and also inlined below with this email. > > > > Problem description/summary: > > > > 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 support 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. > > > > Fix details: > > > > This fix 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 = Type nml > > integer(kind=4) :: a > > integer(kind=4) :: b > > End Type nml > > (gdb) print nml > > $1 = ( a = 10, b = 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.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fgcc-mirror%2Fgcc&data=04%7C01%7CBhuvanendra.KumarN%40amd.com%7Cf615fb689a504a4c006508d97c1ad0b5%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637677276883645649%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=yZro%2BZ5l9UWD0epPKzPI21qCx0KmAKZJslWb6bgkanE%3D&reserved=0) will be handled in separate PATCH. I will raise separate patch for this. > > > > regards, > > bhuvan > > > > Patch inlined: > > > > From 0775cbf3716bae9480c3f1f1d9d8860ac561929e Mon Sep 17 00:00:00 2001 > > From: =?UTF-8?q?=E2=80=9Cbhkumarn=E2=80=9D?= > > Bhuvanendra.KumarN@amd.com > > Date: Mon, 24 Aug 2021 11:49:14 +0530 > > Subject: [PATCH] Fix ptype and print commands for namelist variables(a > > fortran feature). > > > > 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 support 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 > > variables and its items. Sample output of these commands is shared > > below, with fixed gdb. > > (gdb) ptype nml > > type = Type nml > > integer(kind=4) :: a > > integer(kind=4) :: b > > End Type nml > > (gdb) print nml > > $1 = ( a = 10, b = 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, struct die_info *die, > > fp = &new_field->field; > > - if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) > > - { > > + if ((die->tag == DW_TAG_member || die->tag == DW_TAG_namelist_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 == DW_TAG_namelist_item) > > + { > > + struct attribute *attr1 = dwarf2_attr (die, DW_AT_namelist_item, cu); > > + struct die_info *item_die = NULL; > > Throughout this patch, please use nullptr instead of NULL. > > > + struct dwarf2_cu *item_cu = cu; > > + if (attr1->form_is_ref ()) > > + item_die = follow_die_ref (die, attr1, &item_cu); > > + if (item_die != NULL) > > + die = 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, struct dwarf2_cu *cu) > > type = alloc_type (objfile); > > INIT_CPLUS_SPECIFIC (type); > > + if (die->tag == 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 = dwarf2_name (die, cu); > > if (name != NULL) > > @@ -15684,7 +15699,8 @@ handle_struct_member_die (struct die_info *child_die, struct type *type, > > struct dwarf2_cu *cu) { > > if (child_die->tag == DW_TAG_member > > - || child_die->tag == DW_TAG_variable) > > + || child_die->tag == DW_TAG_variable > > + || child_die->tag == 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) > > @@ -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) = LOC_TYPEDEF; > > - SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; > > + case DW_TAG_namelist: > > + if (die->tag == DW_TAG_namelist) > > + { > > + SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC; > > + SYMBOL_DOMAIN (sym) = VAR_DOMAIN; > > + } > > + else > > + { > > + SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF; > > + SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; > > + } > > { > > /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't @@ > > -22744,6 +22771,7 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) > > && die->tag != DW_TAG_class_type > > && die->tag != DW_TAG_interface_type > > && die->tag != DW_TAG_structure_type > > + && die->tag != DW_TAG_namelist > > && die->tag != DW_TAG_union_type) > > return NULL; > > @@ -22768,6 +22796,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-valprint.c b/gdb/f-valprint.c index > > 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 (" = ", stream); > > } > > + /* While printing namelist items, fetch the appropriate value > > + field before printing its value. */ > > + if (TYPE_SPECIFIC_FIELD (type) == 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 specific field like this? > > Wouldn't adding a TYPE_CODE_NAMELIST be more in keeping with how GDB currently does things, though I understand this is likely to make the patch slightly bigger. Did you consider this approach? > > > > > > + { > > + struct block_symbol symni = 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 != NULL) > > + field = value_of_variable(symni.symbol, symni.block); > > + } > > + > > common_val_print (field, stream, recurse + 1, > > options, current_language); diff --git > > a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index > > 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 > > 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 copyright 2020+. > > > + > > +# This program is free software; you can redistribute it and/or > > +modify # it under the terms of the GNU General Public License as > > +published by # 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 WITHOUT ANY WARRANTY; without even the implied warranty of # > > +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU > > +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.protection.outlook.com/?url=http%3A%2F%2Fwww.gnu.org%2Flicenses%2F&data=04%7C01%7CBhuvanendra.KumarN%40amd.com%7Cf615fb689a504a4c006508d97c1ad0b5%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637677276883645649%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=QG%2FRj3ZZSfOdcgEEhs5GUDAwOK5RCeBiSJdPVN1DfsY%3D&reserved=0. > > + > > +# This file is part of the gdb testsuite. It contains tests for > > +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"] > > +gdb_continue_to_breakpoint "Display namelist" > > + > > +if {[test_compiler_info {gcc-*}]} { > > + gdb_test "ptype nml" "type = Type nml\r\n *$int :: a\r\n *$int :: b\r\n *End Type nml" > > + gdb_test "print nml" \\$\[0-9\]+ = \\( a = 10, b = 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 > > +modify ! it under the terms of the GNU General Public License as > > +published by ! 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 WITHOUT ANY WARRANTY; without even the implied warranty of ! > > +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU > > +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.protection.outlook.com/?url=http%3A%2F%2Fwww.gnu.org%2Flicenses%2F&data=04%7C01%7CBhuvanendra.KumarN%40amd.com%7Cf615fb689a504a4c006508d97c1ad0b5%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637677276883645649%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=QG%2FRj3ZZSfOdcgEEhs5GUDAwOK5RCeBiSJdPVN1DfsY%3D&reserved=0. > > +! > > +! This file is the Fortran source file for namelist.exp. > > + > > +program main > > + > > + integer :: a, b > > + namelist /nml/ a, b > > + > > + a = 10 > > + b = 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 > > (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 > > > > > > >