1 # Copyright 2008-2024 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>. */
16 # This file is part of the GDB testsuite. It tests reverse stepping.
17 # Lots of code borrowed from "step-test.exp".
20 # Test step and next with a reloaded process record file.
23 # This test suitable only for process record-replay
24 require supports_process_record
26 standard_testfile step-reverse.c
27 set precsave [standard_output_file step.precsave]
29 if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
35 # Activate process record/replay
36 gdb_test_no_output "record" "turn on process record"
38 set end_of_main [gdb_get_line_number "end of main" ]
39 gdb_test "break $end_of_main" \
40 "Breakpoint $decimal at .*$srcfile, line $end_of_main\." \
41 "breakpoint at end of main"
43 # This can take awhile.
44 with_timeout_factor 20 {
45 gdb_test_multiple "continue" "run to end of main" {
46 -re -wrap "Breakpoint .* end of main .*" {
49 -re -wrap "Process record does not support instruction 0xc5 at.*" {
50 kfail "record/23188" $gdb_test_name
52 -re -wrap "Process record does not support instruction 0xfae64 at.*" {
53 kfail "record/25038" $gdb_test_name
55 -re -wrap "Process record does not support instruction 0x62 at.*" {
56 kfail "record/30807" $gdb_test_name
61 # So can this, against gdbserver, for example.
63 with_timeout_factor 10 {
64 gdb_test "record save $precsave" \
65 "Saved core file $precsave with execution log\." \
66 "save process recfile"
69 gdb_test "kill" "" "kill process, prepare to debug log file" \
70 "Kill the program being debugged\\? \\(y or n\\) " "y"
72 gdb_test "record restore $precsave" \
73 "Restored records from core file .*" \
76 # plain vanilla step/next (no count)
78 gdb_test "next" ".*NEXT TEST 1.*" "next test 1"
79 gdb_test "step" ".*STEP TEST 1.*" "step test 1"
81 # step/next with count
83 gdb_test "next 2" ".*NEXT TEST 2.*" "next test 2"
84 gdb_test "step 3" ".*STEP TEST 2.*" "step test 2"
88 gdb_test "step" ".*NEXT OVER THIS RECURSION.*" "step up to call"
89 gdb_test "next" ".*NEXT OVER THIS CALL.*" "skip recursive call"
90 gdb_test "next" ".*STEP INTO THIS CALL.*" "next over call"
94 gdb_test "step" ".*ARRIVED IN CALLEE.*" "step into call"
98 set test_message "finish out of fn call"
99 gdb_test_multiple "finish" "$test_message" {
100 -re "FINISH TEST.*$gdb_prompt $" {
103 -re "STEP INTO THIS CALL.*$gdb_prompt $" {
109 # stepi over flat code (no calls)
111 set test_message "simple stepi"
112 gdb_test_multiple "stepi" "$test_message" {
113 -re "STEPI TEST.*$gdb_prompt $" {
116 -re "FINISH TEST.*$gdb_prompt $" {
120 -re "NEXTI TEST.*$gdb_prompt $" {
121 fail "$test_message (too far)"
125 # stepi into a function call
127 set alphanum_re "\[a-zA-Z0-9\]"
128 set pic_thunk_re "__$alphanum_re*\\.get_pc_thunk\\.$alphanum_re* \\(\\)"
129 set test_message "stepi into function call"
130 gdb_test_multiple "stepi" "$test_message" {
131 -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
134 -re "NEXTI TEST.*$gdb_prompt $" {
135 fail "$test_message (too far)"
137 -re "RETURN FROM CALLEE.*$gdb_prompt $" {
138 fail "$test_message (too far)"
140 -re "ENTER CALLEE.*$gdb_prompt $" {
144 -re "STEPI TEST.*$gdb_prompt $" {
148 -re "$pic_thunk_re.*$gdb_prompt $" {
154 # stepi thru return of a function call
156 set test_message "stepi back from function call"
157 gdb_test_multiple "stepi" "$test_message" {
158 -re "NEXTI TEST.*$gdb_prompt $" {
161 -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
165 -re "RETURN FROM CALLEE.*$gdb_prompt $" {
169 -re "STEPI TEST.*$gdb_prompt $" {
173 -re "ENTER CALLEE.*$gdb_prompt $" {
174 fail "$test_message (too far)"
182 # Set reverse execution direction
184 gdb_test_no_output "set exec-dir reverse" "set reverse execution"
186 # stepi backward thru return and into a function
188 set stepi_location [gdb_get_line_number "ARRIVED IN CALLEE" "$srcfile"]
189 set test_message "reverse stepi thru function return"
190 gdb_test_multiple "stepi" "$test_message" {
191 -re "NEXTI TEST.*$gdb_prompt $" {
192 fail "$test_message (start statement)"
194 -re "RETURN FROM CALLEE.*$gdb_prompt $" {
198 -re "$hex\[ \t\]*$stepi_location.*ARRIVED IN CALLEE.*$gdb_prompt $" {
202 -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
205 -re "ENTER CALLEE.*$gdb_prompt $" {
206 fail "$test_message (too far)"
208 -re "STEPI TEST.*$gdb_prompt $" {
209 fail "$test_message (too far)"
213 # stepi backward out of a function call
215 set start_pc [get_hexadecimal_valueof "\$pc" 0 "getting PC at start of stepi backwards"]
217 set stepi_location [gdb_get_line_number "STEPI TEST" "$srcfile"]
218 set test_message "reverse stepi from a function call"
219 gdb_test_multiple "stepi" "$test_message" {
220 -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
222 if { [get_hexadecimal_valueof "\$pc" 0 "getting PC after $step_count steps"] == $start_pc } {
223 fail "$test_message (start statement)"
229 -re "ENTER CALLEE.*$gdb_prompt $" {
233 -re "$pic_thunk_re.*$gdb_prompt $" {
237 -re "${hex} in main .*:$stepi_location.*STEPI TEST.*$gdb_prompt $" {
241 -re "STEPI TEST.*$gdb_prompt $" {
244 -re "STEP INTO THIS CALL.*$gdb_prompt $" {
245 fail "$test_message (too far)"
249 # stepi backward over flat code (no calls)
251 set stepi_location [gdb_get_line_number "FINISH TEST" "$srcfile"]
252 set test_message "simple reverse stepi"
253 gdb_test_multiple "stepi" "$test_message" {
254 -re "STEPI TEST.*$gdb_prompt $" {
255 fail "$test_message (start statement)"
257 -re "$hex\[ \t\]*$stepi_location.* FINISH TEST.*$gdb_prompt $" {
261 -re "$stepi_location.* FINISH TEST.*$gdb_prompt $" {
264 -re "STEP INTO THIS CALL.*$gdb_prompt $" {
265 fail "$test_message (too far)"
269 # step backward into function (thru return)
271 gdb_test "step" "(RETURN FROM CALLEE|ARRIVED IN CALLEE).*" \
272 "reverse step into fn call"
274 # step backward out of called function (thru call)
276 set test_message "reverse step out of called fn"
277 gdb_test_multiple "step" "$test_message" {
278 -re "STEP INTO THIS CALL.*.*$gdb_prompt $" {
281 -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
285 -re "ENTER CALLEE.*$gdb_prompt $" {
291 # Next backward over calls.
293 gdb_test "next" ".*NEXT OVER THIS CALL.*" "reverse next over call"
294 gdb_test "next" ".*NEXT OVER THIS RECURSION.*" "reverse next over recursive call"
296 # step/next backward with count
298 gdb_test "step 3" ".*REVERSE STEP TEST 1.*" "reverse step test 1"
299 gdb_test "next 2" ".*REVERSE NEXT TEST 1.*" "reverse next test 1"
301 # step/next backward without count
303 gdb_test "step" ".*STEP TEST 1.*" "reverse step test 2"
304 gdb_test "next" ".*NEXT TEST 1.*" "reverse next test 2"
308 # Finish test by running forward to the end.
309 # FIXME return to this later...
310 # gdb_test_no_output "set exec-dir forward" "set forward execution"
311 # gdb_continue_to_end "step-reverse.exp"