diff options
author | Bhuvanendra Kumar N <Bhuvanendra.KumarN@amd.com> | 2022-02-02 17:52:27 +0000 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2022-02-11 15:26:25 +0000 |
commit | e951225303b7d0565c985e2d562d3787983ff06f (patch) | |
tree | bb924f8f2e8cccb6afb95c0446ff42aa91a2f3e1 /gdb/dwarf2 | |
parent | 9ab50efc463ff723b8e9102f1f68a6983d320517 (diff) | |
download | gdb-e951225303b7d0565c985e2d562d3787983ff06f.zip gdb-e951225303b7d0565c985e2d562d3787983ff06f.tar.gz gdb-e951225303b7d0565c985e2d562d3787983ff06f.tar.bz2 |
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 = Type nml
integer(kind=4) :: a
integer(kind=4) :: b
End Type nml
(gdb) print nml
$1 = ( a = 10, b = 20 )
Diffstat (limited to 'gdb/dwarf2')
-rw-r--r-- | gdb/dwarf2/read.c | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index c063e7b..1055033 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 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)) + { + if (die->tag == DW_TAG_namelist_item) + { + /* Typically, DW_TAG_namelist_item are references to namelist items. + If so, follow that reference. */ + 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. */ @@ -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 == DW_TAG_namelist) + { + type->set_code (TYPE_CODE_NAMELIST); + } else { type->set_code (TYPE_CODE_STRUCT); @@ -15817,7 +15835,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 @@ -15860,8 +15879,10 @@ handle_struct_member_die (struct die_info *child_die, struct type *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 Fortran + 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) @@ -21963,9 +21984,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: - sym->set_aclass_index (LOC_TYPEDEF); - sym->set_domain (STRUCT_DOMAIN); - + case DW_TAG_namelist: + if (die->tag == DW_TAG_namelist) + { + sym->set_aclass_index (LOC_STATIC); + sym->set_domain (VAR_DOMAIN); + } + else + { + sym->set_aclass_index (LOC_TYPEDEF); + sym->set_domain (STRUCT_DOMAIN); + } { /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't really ever be static objects: otherwise, if you try @@ -22902,6 +22931,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; @@ -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 "<anonymous struct>" or "<anonymous union>" in GCC 4.3 |