From: Guinevere Larsen Date: Fri, 21 Jul 2023 11:45:12 +0000 (+0200) Subject: gdb/testsuite: fix gdb.reverse/solib-*.exp tests when using clang X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=890891f14de5f08a5e5bfa4a6907fb6ec409dd45;p=binutils-gdb.git gdb/testsuite: fix gdb.reverse/solib-*.exp tests when using clang The tests gdb.reverse/solib-precsave.exp and solib-reverse.exp have the assumption that line tables will have an entry for the closing } in a function. Not all compiles do this, one example being clang. To fix this, this commit changes the function in shr2.c to have multiple lines, and the test to accept either line as a correct step location. To properly re-sync the inferiors, the function repeat_cmd_until had to be slightly changed to work with empty "current locations", so that we are able to step through multiple lines. This also changes the annotations used to determine the breakpoint locations in solib-reverse.c, adding a simple variable assignment right before the return statement. This way GDB will not set a breakpoint in the closing } line. Approved-By: Tom Tromey --- diff --git a/gdb/testsuite/gdb.reverse/shr2.c b/gdb/testsuite/gdb.reverse/shr2.c index 84a03de1b8c..16c3bf3bc6c 100644 --- a/gdb/testsuite/gdb.reverse/shr2.c +++ b/gdb/testsuite/gdb.reverse/shr2.c @@ -19,7 +19,8 @@ int shr2(int x) { - return 2*x; + int y = 2*x; + return y; } int shr2_local(int x) diff --git a/gdb/testsuite/gdb.reverse/solib-precsave.exp b/gdb/testsuite/gdb.reverse/solib-precsave.exp index 3ca73828063..f89969222c6 100644 --- a/gdb/testsuite/gdb.reverse/solib-precsave.exp +++ b/gdb/testsuite/gdb.reverse/solib-precsave.exp @@ -140,8 +140,17 @@ gdb_test_multiple "reverse-step" "reverse-step into solib function one" { pass $gdb_test_name } } -gdb_test "reverse-step" "return 2.x.*" "reverse-step within solib function one" -gdb_test "reverse-step" " middle part two.*" "reverse-step back to main one" +# Depending on wether the closing } has a line associated, we might have +# different acceptable results here +gdb_test_multiple "reverse-step" "reverse-step within solib function one" { + -re -wrap "return y;.*" { + pass $gdb_test_name + } + -re -wrap "int y =.*" { + pass $gdb_test_name + } +} +repeat_cmd_until "reverse-step" "" "main .. at" "reverse-step back to main one" gdb_test_multiple "reverse-step" "reverse-step into solib function two" { -re -wrap "begin part two.*" { @@ -152,8 +161,15 @@ gdb_test_multiple "reverse-step" "reverse-step into solib function two" { pass $gdb_test_name } } -gdb_test "reverse-step" "return 2.x.*" "reverse-step within solib function two" -gdb_test "reverse-step" " begin part two.*" "reverse-step back to main two" +gdb_test_multiple "reverse-step" "reverse-step within solib function two" { + -re -wrap "return y;.*" { + pass $gdb_test_name + } + -re -wrap "int y =.*" { + pass $gdb_test_name + } +} +repeat_cmd_until "reverse-step" "" "main .. at" "reverse-step back to main two" # # Test reverse-next over debuggable solib function diff --git a/gdb/testsuite/gdb.reverse/solib-reverse.c b/gdb/testsuite/gdb.reverse/solib-reverse.c index 7aa60089df3..20288e0bee8 100644 --- a/gdb/testsuite/gdb.reverse/solib-reverse.c +++ b/gdb/testsuite/gdb.reverse/solib-reverse.c @@ -43,6 +43,7 @@ int main () shr1 ("message 2\n"); /* shr1 two */ shr1 ("message 3\n"); /* shr1 three */ - return 0; /* end part one */ -} /* end of main */ + b[0] = 0; /* end part one */ + return 0; /* end of main */ +} diff --git a/gdb/testsuite/gdb.reverse/solib-reverse.exp b/gdb/testsuite/gdb.reverse/solib-reverse.exp index c061086a8d7..afc4659184a 100644 --- a/gdb/testsuite/gdb.reverse/solib-reverse.exp +++ b/gdb/testsuite/gdb.reverse/solib-reverse.exp @@ -116,8 +116,17 @@ gdb_test_multiple "reverse-step" "reverse-step into solib function one" { pass $gdb_test_name } } -gdb_test "reverse-step" "return 2.x.*" "reverse-step within solib function one" -gdb_test "reverse-step" " middle part two.*" "reverse-step back to main one" +# Depending on wether the closing } has a line associated, we might have +# different acceptable results here +gdb_test_multiple "reverse-step" "reverse-step within solib function one" { + -re -wrap "return y;.*" { + pass $gdb_test_name + } + -re -wrap "int y =.*" { + pass $gdb_test_name + } +} +repeat_cmd_until "reverse-step" "" "main .. at" "reverse-step back to main one" gdb_test_multiple "reverse-step" "reverse-step into solib function two" { -re -wrap "begin part two.*" { @@ -128,8 +137,15 @@ gdb_test_multiple "reverse-step" "reverse-step into solib function two" { pass $gdb_test_name } } -gdb_test "reverse-step" "return 2.x.*" "reverse-step within solib function two" -gdb_test "reverse-step" " begin part two.*" "reverse-step back to main two" +gdb_test_multiple "reverse-step" "reverse-step within solib function two" { + -re -wrap "return y;.*" { + pass $gdb_test_name + } + -re -wrap "int y =.*" { + pass $gdb_test_name + } +} +repeat_cmd_until "reverse-step" "" "main .. at" "reverse-step back to main two" # # Test reverse-next over debuggable solib function diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 36bf738c667..8432e636ecc 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -9716,6 +9716,9 @@ proc repeat_cmd_until { command current target \ set count 0 gdb_test_multiple "$command" "$test_name" { + -re "$target.*$gdb_prompt $" { + pass "$test_name" + } -re "$current.*$gdb_prompt $" { incr count if { $count < $max_steps } { @@ -9725,9 +9728,6 @@ proc repeat_cmd_until { command current target \ fail "$test_name" } } - -re "$target.*$gdb_prompt $" { - pass "$test_name" - } } }