1 # Copyright 2008-2018 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 if ![supports_process_record] {
28 standard_testfile step-reverse.c
29 set precsave [standard_output_file step.precsave]
31 if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
37 if [supports_process_record] {
38 # Activate process record/replay
39 gdb_test_no_output "record" "turn on process record"
42 set end_of_main [gdb_get_line_number "end of main" ]
43 gdb_test "break $end_of_main" \
44 "Breakpoint $decimal at .*$srcfile, line $end_of_main\." \
45 "breakpoint at end of main"
47 # This can take awhile.
48 with_timeout_factor 20 {
49 gdb_test "continue" "Breakpoint .* end of main .*" "run to end of main"
52 # So can this, against gdbserver, for example.
54 with_timeout_factor 10 {
55 gdb_test "record save $precsave" \
56 "Saved core file $precsave with execution log\." \
57 "save process recfile"
60 gdb_test "kill" "" "kill process, prepare to debug log file" \
61 "Kill the program being debugged\\? \\(y or n\\) " "y"
63 gdb_test "record restore $precsave" \
64 "Restored records from core file .*" \
67 # plain vanilla step/next (no count)
69 gdb_test "next" ".*NEXT TEST 1.*" "next test 1"
70 gdb_test "step" ".*STEP TEST 1.*" "step test 1"
72 # step/next with count
74 gdb_test "next 2" ".*NEXT TEST 2.*" "next test 2"
75 gdb_test "step 3" ".*STEP TEST 2.*" "step test 2"
79 gdb_test "step" ".*NEXT OVER THIS CALL.*" "step up to call"
80 gdb_test "next" ".*STEP INTO THIS CALL.*" "next over call"
84 gdb_test "step" ".*ARRIVED IN CALLEE.*" "step into call"
88 set test_message "finish out of fn call"
89 gdb_test_multiple "finish" "$test_message" {
90 -re "FINISH TEST.*$gdb_prompt $" {
93 -re "STEP INTO THIS CALL.*$gdb_prompt $" {
99 # stepi over flat code (no calls)
101 set test_message "simple stepi"
102 gdb_test_multiple "stepi" "$test_message" {
103 -re "STEPI TEST.*$gdb_prompt $" {
106 -re "FINISH TEST.*$gdb_prompt $" {
110 -re "NEXTI TEST.*$gdb_prompt $" {
111 fail "$test_message (too far)"
115 # stepi into a function call
117 set test_message "stepi into function call"
118 gdb_test_multiple "stepi" "$test_message" {
119 -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
122 -re "NEXTI TEST.*$gdb_prompt $" {
123 fail "$test_message (too far)"
125 -re "RETURN FROM CALLEE.*$gdb_prompt $" {
126 fail "$test_message (too far)"
128 -re "ENTER CALLEE.*$gdb_prompt $" {
132 -re "STEPI TEST.*$gdb_prompt $" {
138 # stepi thru return of a function call
140 set test_message "stepi back from function call"
141 gdb_test_multiple "stepi" "$test_message" {
142 -re "NEXTI TEST.*$gdb_prompt $" {
145 -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
149 -re "RETURN FROM CALLEE.*$gdb_prompt $" {
153 -re "STEPI TEST.*$gdb_prompt $" {
157 -re "ENTER CALLEE.*$gdb_prompt $" {
158 fail "$test_message (too far)"
166 # Set reverse execution direction
168 gdb_test_no_output "set exec-dir reverse" "set reverse execution"
170 # stepi backward thru return and into a function
172 set stepi_location [gdb_get_line_number "ARRIVED IN CALLEE" "$srcfile"]
173 set test_message "reverse stepi thru function return"
174 gdb_test_multiple "stepi" "$test_message" {
175 -re "NEXTI TEST.*$gdb_prompt $" {
176 fail "$test_message (start statement)"
178 -re "RETURN FROM CALLEE.*$gdb_prompt $" {
182 -re "$hex\[ \t\]*$stepi_location.*ARRIVED IN CALLEE.*$gdb_prompt $" {
186 -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
189 -re "ENTER CALLEE.*$gdb_prompt $" {
190 fail "$test_message (too far)"
192 -re "STEPI TEST.*$gdb_prompt $" {
193 fail "$test_message (too far)"
197 # stepi backward out of a function call
199 set stepi_location [gdb_get_line_number "STEPI TEST" "$srcfile"]
200 set test_message "reverse stepi from a function call"
201 gdb_test_multiple "stepi" "$test_message" {
202 -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
203 fail "$test_message (start statement)"
205 -re "ENTER CALLEE.*$gdb_prompt $" {
209 -re "${hex} in main .*:$stepi_location.*STEPI TEST.*$gdb_prompt $" {
213 -re "STEPI TEST.*$gdb_prompt $" {
216 -re "STEP INTO THIS CALL.*$gdb_prompt $" {
217 fail "$test_message (too far)"
221 # stepi backward over flat code (no calls)
223 set stepi_location [gdb_get_line_number "FINISH TEST" "$srcfile"]
224 set test_message "simple reverse stepi"
225 gdb_test_multiple "stepi" "$test_message" {
226 -re "STEPI TEST.*$gdb_prompt $" {
227 fail "$test_message (start statement)"
229 -re "$hex\[ \t\]*$stepi_location.* FINISH TEST.*$gdb_prompt $" {
233 -re "$stepi_location.* FINISH TEST.*$gdb_prompt $" {
236 -re "STEP INTO THIS CALL.*$gdb_prompt $" {
237 fail "$test_message (too far)"
241 # step backward into function (thru return)
243 gdb_test "step" "(RETURN FROM CALLEE|ARRIVED IN CALLEE).*" \
244 "reverse step into fn call"
246 # step backward out of called function (thru call)
248 set test_message "reverse step out of called fn"
249 gdb_test_multiple "step" "$test_message" {
250 -re "STEP INTO THIS CALL.*.*$gdb_prompt $" {
253 -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
257 -re "ENTER CALLEE.*$gdb_prompt $" {
263 # next backward over call
265 gdb_test "next" ".*NEXT OVER THIS CALL.*" "reverse next over call"
267 # step/next backward with count
269 gdb_test "step 3" ".*REVERSE STEP TEST 1.*" "reverse step test 1"
270 gdb_test "next 2" ".*REVERSE NEXT TEST 1.*" "reverse next test 1"
272 # step/next backward without count
274 gdb_test "step" ".*STEP TEST 1.*" "reverse step test 2"
275 gdb_test "next" ".*NEXT TEST 1.*" "reverse next test 2"
279 # Finish test by running forward to the end.
280 # FIXME return to this later...
281 # gdb_test_no_output "set exec-dir forward" "set forward execution"
282 # gdb_continue_to_end "step-reverse.exp"