]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/symtab] Fix gdb.dwarf2/enum-type-c++.exp with cc-with-debug-types
authorTom de Vries <tdevries@suse.de>
Tue, 8 Oct 2024 10:27:20 +0000 (12:27 +0200)
committerTom de Vries <tdevries@suse.de>
Tue, 8 Oct 2024 10:27:20 +0000 (12:27 +0200)
When running test-case gdb.dwarf2/enum-type-c++.exp with target board
cc-with-debug-types, we run into:
...
(gdb) FAIL: gdb.dwarf2/enum-type-c++.exp: val1 has a parent
...
because val1 has no parent:
...
    [31] ((cooked_index_entry *) 0x7efedc002e90)
    name:       val1
    canonical:  val1
    qualified:  val1
    DWARF tag:  DW_TAG_enumerator
    flags:      0x0 []
    DIE offset: 0xef
    parent:     ((cooked_index_entry *) 0)

  ...

    [37] ((cooked_index_entry *) 0x38ffd280)
    name:       val1
    canonical:  val1
    qualified:  val1
    DWARF tag:  DW_TAG_enumerator
    flags:      0x0 []
    DIE offset: 0xef
    parent:     ((cooked_index_entry *) 0)
...

There are two entries, which seems to be an inefficiency, but for now let's
focus on the correctness issue.

The debug info for val1 looks like this:
...
 <1><cb>: Abbrev Number: 2 (DW_TAG_namespace)
    <cc>   DW_AT_name        : ns
    <cf>   DW_AT_declaration : 1
 <2><d3>: Abbrev Number: 12 (DW_TAG_class_type)
    <d4>   DW_AT_name        : A
    <d6>   DW_AT_declaration : 1
 <3><d6>: Abbrev Number: 13 (DW_TAG_enumeration_type)
    <db>   DW_AT_declaration : 1
 <1><dd>: Abbrev Number: 14 (DW_TAG_enumeration_type)
    <e7>   DW_AT_specification: <0xd6>
 <2><ef>: Abbrev Number: 5 (DW_TAG_enumerator)
    <f0>   DW_AT_name        : val1
    <f4>   DW_AT_const_value : 1
...

Fix this by:
- adding a cooked index entry for DIE 0xcb (and consequently for child DIE
  0xd3), by marking it interesting,
- making sure that the entry for DIE 0xcb has a name, and
- using the entry for DIE 0xd3 as parent entry for DIE 0xdd.

Tested on aarch64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/dwarf2/abbrev.c
gdb/dwarf2/read.c

index bae8d8b3bed5dcff5af893cbc24a0a0d987ccac1..c30db1ee31ae36c09033604aec58bd4cb932f64c 100644 (file)
@@ -276,7 +276,8 @@ abbrev_table::read (struct dwarf2_section_info *section,
        }
       else if ((cur_abbrev->tag == DW_TAG_structure_type
                || cur_abbrev->tag == DW_TAG_class_type
-               || cur_abbrev->tag == DW_TAG_union_type)
+               || cur_abbrev->tag == DW_TAG_union_type
+               || cur_abbrev->tag == DW_TAG_namespace)
               && cur_abbrev->has_children)
        {
          /* We have to record this as interesting, regardless of how
index 95e7d6aee31a6bc288d738db335d0ae01cea2e65..ea31d8dd851b4ac717c3ef94041177859765ce97 100644 (file)
@@ -16310,7 +16310,8 @@ cooked_indexer::scan_attributes (dwarf2_per_cu_data *scanning_per_cu,
         want to treat them as definitions.  */
       if ((abbrev->tag == DW_TAG_class_type
           || abbrev->tag == DW_TAG_structure_type
-          || abbrev->tag == DW_TAG_union_type)
+          || abbrev->tag == DW_TAG_union_type
+          || abbrev->tag == DW_TAG_namespace)
          && abbrev->has_children)
        *flags |= IS_TYPE_DECLARATION;
       else
@@ -16635,7 +16636,7 @@ cooked_indexer::index_dies (cutu_reader *reader,
                else if (defer != 0)
                  recurse_parent = defer;
                else
-                 recurse_parent = parent_entry;
+                 recurse_parent = this_parent_entry;
 
                info_ptr = recurse (reader, info_ptr, recurse_parent, fully);
              }