public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "Kumar N, Bhuvanendra" <Bhuvanendra.KumarN@amd.com>
To: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Cc: "George, Jini Susan" <JiniSusan.George@amd.com>,
	"Sharma, Alok Kumar" <AlokKumar.Sharma@amd.com>,
	"Achra, Nitika" <Nitika.Achra@amd.com>,
	"E, Nagajyothi" <Nagajyothi.E@amd.com>
Subject: RE: [PATCH] Fix ptype and print commands for namelist variables(a fortran feature)
Date: Tue, 24 Aug 2021 09:21:46 +0000	[thread overview]
Message-ID: <MW2PR12MB46842980EA481EEA8A89E11987C59@MW2PR12MB4684.namprd12.prod.outlook.com> (raw)
In-Reply-To: <MW2PR12MB46844ECA167D82F5A91E158E87C59@MW2PR12MB4684.namprd12.prod.outlook.com>

[AMD Official Use Only]

One additional information.


Testing:

- NO regressions found in GDB testsuite after the fix.

- New test case is added for this fix.



regards,

bhuvan

From: Kumar N, Bhuvanendra
Sent: Tuesday, August 24, 2021 2:46 PM
To: 'gdb-patches@sourceware.org' <gdb-patches@sourceware.org>
Cc: George, Jini Susan <JiniSusan.George@amd.com>; Sharma, Alok Kumar <AlokKumar.Sharma@amd.com>; Achra, Nitika <Nitika.Achra@amd.com>; E, Nagajyothi <Nagajyothi.E@amd.com>
Subject: [PATCH] Fix ptype and print commands for namelist variables(a fortran feature)


[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 )

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://github.com/gcc-mirror/gcc) 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<mailto: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<mailto: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<mailto: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))
+    {
+      /* 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;
+          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);

   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 "<anonymous struct>" or "<anonymous union>" 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)
+             {
+               struct block_symbol symni = lookup_symbol(field_name,
+                get_selected_block (0), VAR_DOMAIN, nullptr);
+               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<mailto: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<mailto: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.
+
+# 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 http://www.gnu.org/licenses/.
+
+# 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 \\)<file://$/%5b0-9/%5d+%20=%20/(%20a%20=%2010,%20b%20=%2020%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..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 http://www.gnu.org/licenses/.
+!
+! 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




  reply	other threads:[~2021-08-24  9:21 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-24  9:16 Kumar N, Bhuvanendra
2021-08-24  9:21 ` Kumar N, Bhuvanendra [this message]
2021-09-20  9:41 ` Andrew Burgess
2021-09-22 12:38   ` Kumar N, Bhuvanendra
2021-10-06 15:51     ` Andrew Burgess
2021-10-07 21:05       ` Kumar N, Bhuvanendra
2021-10-18 17:02         ` Kumar N, Bhuvanendra
2021-11-04 15:50         ` Andrew Burgess
2021-11-19 14:09         ` FW: " Kumar N, Bhuvanendra
2021-11-19 14:32           ` Kumar N, Bhuvanendra
2021-12-03 18:56             ` Kumar N, Bhuvanendra
2021-12-04 13:20               ` Joel Brobecker
2021-12-10 16:18                 ` Kumar N, Bhuvanendra
2021-12-20  5:13                   ` Joel Brobecker
2021-12-23 15:51                     ` Kumar N, Bhuvanendra
2022-01-20 16:20                       ` Kumar N, Bhuvanendra
2022-02-03 18:43                         ` Andrew Burgess
2022-02-07 14:41                           ` Kumar N, Bhuvanendra
2022-02-11 16:20                             ` Andrew Burgess
2022-02-11 16:39                               ` Kumar N, Bhuvanendra
2021-12-09 13:16             ` Andrew Burgess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=MW2PR12MB46842980EA481EEA8A89E11987C59@MW2PR12MB4684.namprd12.prod.outlook.com \
    --to=bhuvanendra.kumarn@amd.com \
    --cc=AlokKumar.Sharma@amd.com \
    --cc=JiniSusan.George@amd.com \
    --cc=Nagajyothi.E@amd.com \
    --cc=Nitika.Achra@amd.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).