]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/testsuite] Fix gdb.dwarf2/enum-type-c++.exp with clang
authorTom de Vries <tdevries@suse.de>
Thu, 10 Oct 2024 06:19:26 +0000 (08:19 +0200)
committerTom de Vries <tdevries@suse.de>
Thu, 10 Oct 2024 06:19:26 +0000 (08:19 +0200)
When running test-case gdb.dwarf2/enum-type-c++.exp with clang, we get:
...
FAIL: gdb.dwarf2/enum-type-c++.exp: val1 has a parent
FAIL: gdb.dwarf2/enum-type-c++.exp: print ns::A::val1
FAIL: gdb.dwarf2/enum-type-c++.exp: val2 has correct parent
FAIL: gdb.dwarf2/enum-type-c++.exp: print ns::ec::val2
...

The problem is that the debug info produced by clang does not contain any
references to enumerators val1 and val2, or the corresponding enumeration
types.

Instead, the variables u1 and u2 are considered to be simply of type int:
...
 <1><fb>: Abbrev Number: 2 (DW_TAG_variable)
    <fc>   DW_AT_name        : u1
    <fd>   DW_AT_type        : <0x106>
    <101>   DW_AT_external    : 1
    <103>   DW_AT_location    : (DW_OP_addrx <0>)
 <1><106>: Abbrev Number: 3 (DW_TAG_base_type)
    <107>   DW_AT_name        : int
    <108>   DW_AT_encoding    : 5       (signed)
    <109>   DW_AT_byte_size   : 4
 <1><10a>: Abbrev Number: 2 (DW_TAG_variable)
    <10b>   DW_AT_name        : u2
    <10c>   DW_AT_type        : <0x106>
    <110>   DW_AT_external    : 1
    <112>   DW_AT_location    : (DW_OP_addrx <0x1>)
...

Fix this by checking whether val1 and val2 are present in the cooked index
before checking whether they have the correct parent.

This cannot be expressed efficiently with gdb_test_lines, so factor out
gdb_get_lines and use that instead.

The test-case still calls "maint print objfiles" twice, but the first time is
for have_index.  We should probably use a gdb_caching_proc for this.

Tested on aarch64-linux.

Reported-By: Guinevere Larsen <guinevere@redhat.com>
Reviewed-By: Keith Seitz <keiths@redhat.com>
Tested-By: Guinevere Larsen <guinevere@redhat.com>
gdb/testsuite/gdb.dwarf2/enum-type-c++.exp
gdb/testsuite/lib/gdb.exp

index 8bf737ec506abca59d4c0f609ed92030b8398741..4f9610c10c0717185024b7212e467d2a8cc64179 100644 (file)
@@ -29,26 +29,39 @@ if { [prepare_for_testing "failed to prepare" $testfile \
 
 require {string equal [have_index $binfile] ""}
 
+set lines [gdb_get_lines "maint print objfiles"]
 set re_ws "\[ \t\]"
 
 # Regression test for PR31900.
 set val1 ns::A::val1
-gdb_test_lines "maint print objfiles" \
-    "val1 has a parent" \
-    [multi_line \
-        "" \
-        "$re_ws+qualified:$re_ws+$val1" \
-        ".*"]
+set test "val1 has a parent"
+if { [regexp val1 $lines] } {
+    set re \
+       [multi_line \
+            "" \
+            "$re_ws+qualified:$re_ws+$val1" \
+            ".*"]
+    gdb_assert {[regexp $re $lines]} $test
 
-gdb_test "print $val1" " = $val1"
+    gdb_test "print $val1" " = $val1"
+} else {
+    # Clang doesn't emit a DIE for val1.
+    unsupported $test
+}
 
 # Regression test for PR32158.
 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"
+set test "val2 has correct parent"
+if { [regexp val2 $lines] } {
+    set re \
+       [multi_line \
+            "" \
+            "$re_ws+qualified:$re_ws+$val2" \
+            ".*"]
+    gdb_assert {[regexp $re $lines]} $test
+
+    gdb_test "print $val2" " = $val2"
+} else {
+    # Clang doesn't emit a DIE for val2.
+    unsupported $test
+}
index 738cd2fe9c658b000f8ab9e3f7ad8a9a51cd0b60..f0a89394b879d8d890a241ccd6b4baac59598fad 100644 (file)
@@ -1817,6 +1817,55 @@ proc gdb_test_sequence { args } {
 }
 
 \f
+# Issue COMMAND, and return corresponding output lines.  Helper function for
+# gdb_get_lines_no_pass and gdb_get_lines.
+
+proc gdb_get_lines_1 { command message } {
+    set no_pass [string equal $message ""]
+    set lines ""
+    set ok 0
+    gdb_test_multiple $command $message {
+       -re "\r\n(\[^\r\n\]*)(?=\r\n)" {
+           set line $expect_out(1,string)
+           if { $lines eq "" } {
+               append lines "$line"
+           } else {
+               append lines "\r\n$line"
+           }
+           exp_continue
+       }
+       -re -wrap "" {
+           append lines "\r\n"
+           set ok 1
+           if { ! $no_pass } {
+               pass $gdb_test_name
+           }
+       }
+    }
+
+    if { ! $ok } {
+       return ""
+    }
+
+    return $lines
+}
+
+# Issue COMMAND, and return corresponding output lines.  Don't generate a pass.
+
+proc gdb_get_lines_no_pass { command } {
+    gdb_get_lines_1 $command ""
+}
+
+# Issue COMMAND, and return corresponding output lines.  Generate a pass.
+
+proc gdb_get_lines { command {message ""} } {
+    if { $message == "" } {
+       set message [command_to_message $command]
+    }
+
+    gdb_get_lines_1 $command $message
+}
+
 # Match output of COMMAND using RE.  Read output line-by-line.
 # Report pass/fail with MESSAGE.
 # For a command foo with output:
@@ -1856,22 +1905,7 @@ proc gdb_test_lines { command message re args } {
        set message [command_to_message $command]
     }
 
-    set lines ""
-    gdb_test_multiple $command $message {
-       -re "\r\n(\[^\r\n\]*)(?=\r\n)" {
-           set line $expect_out(1,string)
-           if { $lines eq "" } {
-               append lines "$line"
-           } else {
-               append lines "\r\n$line"
-           }
-           exp_continue
-       }
-       -re -wrap "" {
-           append lines "\r\n"
-       }
-    }
-
+    set lines [gdb_get_lines_no_pass $command]
     gdb_assert { [regexp $re $lines] } $message
 
     foreach re $re_not {