[3/4] gdb/testsuite: fix testing gdb.reverse/step-reverse.exp with clang
Checks
Context |
Check |
Description |
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_gdb_build--master-arm |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_gdb_check--master-arm |
success
|
Testing passed
|
Commit Message
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.
---
gdb/testsuite/gdb.reverse/step-precsave.exp | 18 +++++++++++++++++-
gdb/testsuite/gdb.reverse/step-reverse.exp | 20 +++++++++++++++++++-
2 files changed, 36 insertions(+), 2 deletions(-)
Comments
>>>>> "Bruno" == Bruno Larsen via Gdb-patches <gdb-patches@sourceware.org> writes:
Bruno> +proc get_current_pc {} {
I think this can probably use get_hexadecimal_valueof instead.
Tom
@@ -30,6 +30,16 @@ if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
return -1
}
+proc get_current_pc {} {
+ set pc 0
+ gdb_test_multiple "print \$pc" "" {
+ -re -wrap ".*0x(\[0-9a-f\]+).*" {
+ set pc $expect_out(1,string)
+ }
+ }
+ return $pc
+}
+
runto_main
# Activate process record/replay
@@ -209,11 +219,17 @@ gdb_test_multiple "stepi" "$test_message" {
# stepi backward out of a function call
+set start_pc [get_current_pc]
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)"
+ if { [get_current_pc] == $start_pc } {
+ fail "$test_message (start statement)"
+ } else {
+ send_gdb "stepi\n"
+ exp_continue
+ }
}
-re "ENTER CALLEE.*$gdb_prompt $" {
send_gdb "stepi\n"
@@ -28,6 +28,16 @@ if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
return -1
}
+proc get_current_pc {} {
+ set pc 0
+ gdb_test_multiple "print \$pc" "" {
+ -re -wrap ".*0x(\[0-9a-f\]+).*" {
+ set pc $expect_out(1,string)
+ }
+ }
+ return $pc
+}
+
runto_main
if [supports_process_record] {
@@ -174,11 +184,19 @@ 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_current_pc]
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)"
+ if { [get_current_pc] == $start_pc } {
+ fail "$test_message (start statement)"
+ } else {
+ send_gdb "stepi\n"
+ exp_continue
+ }
}
-re "ENTER CALLEE.*$gdb_prompt $" {
send_gdb "stepi\n"