From: Guinevere Larsen Date: Fri, 21 Jul 2023 09:10:42 +0000 (+0200) Subject: gdb/testsuite: fix testing gdb.reverse/step-reverse.exp with clang X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6e7db5d6bcc383766e10c2ea6f6bf01b629db1b0;p=binutils-gdb.git gdb/testsuite: fix testing gdb.reverse/step-reverse.exp with clang When testing using reverse-stepi to fully step through a function, the code checks for an infinite loop by seeing if we land on the line that contains the return statement multiple times. This assumption only works if there is only one instruction associated with that line, which is how GCC handles line information, but other compilers may handle it differently. Clang-15, for instance, associates 6. Because of this, the inferior used to get seriously out of sync with the test expectations, and result in 13 spurious failures. The same issue occurs with gdb.reverse/step-precsave.exp. This commit changes the test so that we check for PC instead of line number. The test still only happens when the same line is detected, to simplify the resulting log. With this change, no new failures are emitted when using clang. Approved-By: Tom Tromey --- diff --git a/gdb/testsuite/gdb.reverse/step-precsave.exp b/gdb/testsuite/gdb.reverse/step-precsave.exp index 19cd5d9930e..e2971621c57 100644 --- a/gdb/testsuite/gdb.reverse/step-precsave.exp +++ b/gdb/testsuite/gdb.reverse/step-precsave.exp @@ -209,11 +209,19 @@ gdb_test_multiple "stepi" "$test_message" { # stepi backward out of a function call +set start_pc [get_hexadecimal_valueof "\$pc" 0 "getting PC at start of stepi backwards"] +set step_count 0 set stepi_location [gdb_get_line_number "STEPI TEST" "$srcfile"] set test_message "reverse stepi from a function call" gdb_test_multiple "stepi" "$test_message" { -re "ARRIVED IN CALLEE.*$gdb_prompt $" { - fail "$test_message (start statement)" + incr step_count + if { [get_hexadecimal_valueof "\$pc" 0 "getting PC after $step_count steps"] == $start_pc } { + fail "$test_message (start statement)" + } else { + send_gdb "stepi\n" + exp_continue + } } -re "ENTER CALLEE.*$gdb_prompt $" { send_gdb "stepi\n" diff --git a/gdb/testsuite/gdb.reverse/step-reverse.exp b/gdb/testsuite/gdb.reverse/step-reverse.exp index 4b78a8f8fb7..b7d00fb4bd3 100644 --- a/gdb/testsuite/gdb.reverse/step-reverse.exp +++ b/gdb/testsuite/gdb.reverse/step-reverse.exp @@ -174,11 +174,21 @@ gdb_test_multiple "stepi" "$test_message" { # stepi backward out of a function call +# When testing stepi, we dont want to infinitely step if we're not moving +# so we store the starting PC, in case we land on the same line as above +set start_pc [get_hexadecimal_valueof "\$pc" 0 "get PC at start"] +set get_pc_count 0 set stepi_location [gdb_get_line_number "STEPI TEST" "$srcfile"] set test_message "reverse stepi from a function call" gdb_test_multiple "stepi" "$test_message" { -re "ARRIVED IN CALLEE.*$gdb_prompt $" { - fail "$test_message (start statement)" + incr get_pc_count + if { [get_hexadecimal_valueof "\$pc" 0 "get PC again $get_pc_count"] == $start_pc } { + fail "$test_message (start statement)" + } else { + send_gdb "stepi\n" + exp_continue + } } -re "ENTER CALLEE.*$gdb_prompt $" { send_gdb "stepi\n"