From: Tom de Vries Date: Thu, 10 Oct 2024 06:19:26 +0000 (+0200) Subject: [gdb/testsuite] Fix gdb.dwarf2/enum-type-c++.exp with clang X-Git-Tag: gdb-16-branchpoint~693 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1001055e3552760015661dd9b081435051fe1340;p=thirdparty%2Fbinutils-gdb.git [gdb/testsuite] Fix gdb.dwarf2/enum-type-c++.exp with clang 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>: Abbrev Number: 2 (DW_TAG_variable) DW_AT_name : u1 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 Reviewed-By: Keith Seitz Tested-By: Guinevere Larsen --- diff --git a/gdb/testsuite/gdb.dwarf2/enum-type-c++.exp b/gdb/testsuite/gdb.dwarf2/enum-type-c++.exp index 8bf737ec506..4f9610c10c0 100644 --- a/gdb/testsuite/gdb.dwarf2/enum-type-c++.exp +++ b/gdb/testsuite/gdb.dwarf2/enum-type-c++.exp @@ -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 +} diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 738cd2fe9c6..f0a89394b87 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -1817,6 +1817,55 @@ proc gdb_test_sequence { args } { } +# 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 {