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 <tom@tromey.com>
This commit is contained in:
Guinevere Larsen 2023-07-21 11:10:42 +02:00
parent 890891f14d
commit 6e7db5d6bc
2 changed files with 20 additions and 2 deletions

View file

@ -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"

View file

@ -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"