[2/5,gdb/testsuite] Add regression test for PR32158

Message ID 20240912115242.17062-2-tdevries@suse.de
State Committed
Headers
Series [1/5,gdb/testsuite] Add gdb.dwarf2/enum-type-c++.exp, regression test for PR31900. |

Checks

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

Commit Message

Tom de Vries Sept. 12, 2024, 11:52 a.m. UTC
  Consider test-case:
...
namespace ns {
  enum class ec {
    val2 = 2
  };
}

int main () {
  return (int)ns::ec::val2;
}
...
compiled with debug info:
...
$ g++ test.c -g
...

When looking at the cooked index entry for val2 using "maint print objfiles",
we get:
...
    [7] ((cooked_index_entry *) 0x7f8ecc002ef0)
    name:       val2
    canonical:  val2
    qualified:  ns::val2
    DWARF tag:  DW_TAG_enumerator
    flags:      0x0 []
    DIE offset: 0xe9
    parent:     ((cooked_index_entry *) 0x7f8ecc002e90) [ns]
...
which is wrong, there is no source level entity ns::val2.

This is PR symtab/32158.

This is a regression since commit 4e417d7bb1c ("Change handling of
DW_TAG_enumeration_type in DWARF scanner").

Reverting the commit on current trunk fixes the problem, and gets us instead:
...
    [7] ((cooked_index_entry *) 0x7fba70002ef0)
    name:       val2
    canonical:  val2
    qualified:  ns::ec::val2
    DWARF tag:  DW_TAG_enumerator
    flags:      0x0 []
    DIE offset: 0xe9
    parent:     ((cooked_index_entry *) 0x7fba70002ec0) [ec]
...

Add a regression test for this PR in test-case gdb.dwarf2/enum-type-c++.exp.

Tested on x86_64-linux.
---
 gdb/testsuite/gdb.dwarf2/enum-type-c++.cc  |  6 ++++++
 gdb/testsuite/gdb.dwarf2/enum-type-c++.exp | 12 ++++++++++++
 2 files changed, 18 insertions(+)
  

Comments

Tom Tromey Sept. 13, 2024, 7:03 p.m. UTC | #1
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

Tom> Add a regression test for this PR in test-case gdb.dwarf2/enum-type-c++.exp.

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

Tom
  

Patch

diff --git a/gdb/testsuite/gdb.dwarf2/enum-type-c++.cc b/gdb/testsuite/gdb.dwarf2/enum-type-c++.cc
index c0ffaad0316..691c7fc7d88 100644
--- a/gdb/testsuite/gdb.dwarf2/enum-type-c++.cc
+++ b/gdb/testsuite/gdb.dwarf2/enum-type-c++.cc
@@ -24,6 +24,12 @@  public:
   };
 };
 
+enum class ec
+{
+  val2 = 2,
+};
 }
 
 int u1 = ns::A::val1;
+
+int u2 = (int)ns::ec::val2;
diff --git a/gdb/testsuite/gdb.dwarf2/enum-type-c++.exp b/gdb/testsuite/gdb.dwarf2/enum-type-c++.exp
index 44ad225de02..a3dfb4d2f74 100644
--- a/gdb/testsuite/gdb.dwarf2/enum-type-c++.exp
+++ b/gdb/testsuite/gdb.dwarf2/enum-type-c++.exp
@@ -42,3 +42,15 @@  gdb_test_lines "maint print objfiles" \
 	 ".*"]
 
 gdb_test "print $val1" " = $val1"
+
+# Regression test for PR32158.
+setup_kfail "gdb/32158" *-*-*
+set val2 ns::ec::val2
+gdb_test_lines "maint print objfiles" \
+    "val2 has correct parent" \
+    [multi_line \
+	 "" \
+	 "$re_ws+qualified:$re_ws+$val2" \
+	 ".*"]
+
+gdb_test "print $val2" " = $val2"