1 # Copyright 2008-2020 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_multiple "continue" "run to end of main" {
50 -re -wrap "Breakpoint .* end of main .*" {
53 -re -wrap "Process record does not support instruction 0xc5 at.*" {
54 kfail "record/23188" $gdb_test_name
56 -re -wrap "Process record does not support instruction 0xfae64 at.*" {
57 kfail "record/25038" $gdb_test_name
62 # So can this, against gdbserver, for example.
64 with_timeout_factor 10 {
65 gdb_test "record save $precsave" \
66 "Saved core file $precsave with execution log\." \
67 "save process recfile"
70 gdb_test "kill" "" "kill process, prepare to debug log file" \
71 "Kill the program being debugged\\? \\(y or n\\) " "y"
73 gdb_test "record restore $precsave" \
74 "Restored records from core file .*" \
77 # plain vanilla step/next (no count)
79 gdb_test "next" ".*NEXT TEST 1.*" "next test 1"
80 gdb_test "step" ".*STEP TEST 1.*" "step test 1"
82 # step/next with count
84 gdb_test "next 2" ".*NEXT TEST 2.*" "next test 2"
85 gdb_test "step 3" ".*STEP TEST 2.*" "step test 2"
89 gdb_test "step" ".*NEXT OVER THIS CALL.*" "step up to 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 test_message "stepi into function call"
128 gdb_test_multiple "stepi" "$test_message" {
129 -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
132 -re "NEXTI TEST.*$gdb_prompt $" {
133 fail "$test_message (too far)"
135 -re "RETURN FROM CALLEE.*$gdb_prompt $" {
136 fail "$test_message (too far)"
138 -re "ENTER CALLEE.*$gdb_prompt $" {
142 -re "STEPI TEST.*$gdb_prompt $" {
148 # stepi thru return of a function call
150 set test_message "stepi back from function call"
151 gdb_test_multiple "stepi" "$test_message" {
152 -re "NEXTI TEST.*$gdb_prompt $" {
155 -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
159 -re "RETURN FROM CALLEE.*$gdb_prompt $" {
163 -re "STEPI TEST.*$gdb_prompt $" {
167 -re "ENTER CALLEE.*$gdb_prompt $" {
168 fail "$test_message (too far)"
176 # Set reverse execution direction
178 gdb_test_no_output "set exec-dir reverse" "set reverse execution"
180 # stepi backward thru return and into a function
182 set stepi_location [gdb_get_line_number "ARRIVED IN CALLEE" "$srcfile"]
183 set test_message "reverse stepi thru function return"
184 gdb_test_multiple "stepi" "$test_message" {
185 -re "NEXTI TEST.*$gdb_prompt $" {
186 fail "$test_message (start statement)"
188 -re "RETURN FROM CALLEE.*$gdb_prompt $" {
192 -re "$hex\[ \t\]*$stepi_location.*ARRIVED IN CALLEE.*$gdb_prompt $" {
196 -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
199 -re "ENTER CALLEE.*$gdb_prompt $" {
200 fail "$test_message (too far)"
202 -re "STEPI TEST.*$gdb_prompt $" {
203 fail "$test_message (too far)"
207 # stepi backward out of a function call
209 set stepi_location [gdb_get_line_number "STEPI TEST" "$srcfile"]
210 set test_message "reverse stepi from a function call"
211 gdb_test_multiple "stepi" "$test_message" {
212 -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
213 fail "$test_message (start statement)"
215 -re "ENTER CALLEE.*$gdb_prompt $" {
219 -re "${hex} in main .*:$stepi_location.*STEPI TEST.*$gdb_prompt $" {
223 -re "STEPI TEST.*$gdb_prompt $" {
226 -re "STEP INTO THIS CALL.*$gdb_prompt $" {
227 fail "$test_message (too far)"
231 # stepi backward over flat code (no calls)
233 set stepi_location [gdb_get_line_number "FINISH TEST" "$srcfile"]
234 set test_message "simple reverse stepi"
235 gdb_test_multiple "stepi" "$test_message" {
236 -re "STEPI TEST.*$gdb_prompt $" {
237 fail "$test_message (start statement)"
239 -re "$hex\[ \t\]*$stepi_location.* FINISH TEST.*$gdb_prompt $" {
243 -re "$stepi_location.* FINISH TEST.*$gdb_prompt $" {
246 -re "STEP INTO THIS CALL.*$gdb_prompt $" {
247 fail "$test_message (too far)"
251 # step backward into function (thru return)
253 gdb_test "step" "(RETURN FROM CALLEE|ARRIVED IN CALLEE).*" \
254 "reverse step into fn call"
256 # step backward out of called function (thru call)
258 set test_message "reverse step out of called fn"
259 gdb_test_multiple "step" "$test_message" {
260 -re "STEP INTO THIS CALL.*.*$gdb_prompt $" {
263 -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
267 -re "ENTER CALLEE.*$gdb_prompt $" {
273 # next backward over call
275 gdb_test "next" ".*NEXT OVER THIS CALL.*" "reverse next over call"
277 # step/next backward with count
279 gdb_test "step 3" ".*REVERSE STEP TEST 1.*" "reverse step test 1"
280 gdb_test "next 2" ".*REVERSE NEXT TEST 1.*" "reverse next test 1"
282 # step/next backward without count
284 gdb_test "step" ".*STEP TEST 1.*" "reverse step test 2"
285 gdb_test "next" ".*NEXT TEST 1.*" "reverse next test 2"
289 # Finish test by running forward to the end.
290 # FIXME return to this later...
291 # gdb_test_no_output "set exec-dir forward" "set forward execution"
292 # gdb_continue_to_end "step-reverse.exp"