[v2,2/2,gdb/symtab] Fix gdb.dwarf2/enum-type-c++.exp with cc-with-debug-types

Message ID 20240926130509.7960-2-tdevries@suse.de
State New
Headers
Series [v2,1/2,gdb/symtab] Fix parent of enumerator |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Tom de Vries Sept. 26, 2024, 1:05 p.m. UTC
  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.
---
 gdb/dwarf2/abbrev.c | 3 ++-
 gdb/dwarf2/read.c   | 5 +++--
 2 files changed, 5 insertions(+), 3 deletions(-)
  

Comments

Tom Tromey Sept. 27, 2024, 6:30 p.m. UTC | #1
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

Tom> There are two entries, which seems to be an inefficiency

Yeah, this seems bad.

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

Thank you.
Approved-By: Tom Tromey <tom@tromey.com>

Tom
  

Patch

diff --git a/gdb/dwarf2/abbrev.c b/gdb/dwarf2/abbrev.c
index bae8d8b3bed..c30db1ee31a 100644
--- a/gdb/dwarf2/abbrev.c
+++ b/gdb/dwarf2/abbrev.c
@@ -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
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 1a386b8d542..023f6677e31 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -16261,7 +16261,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
@@ -16585,7 +16586,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);
 	      }