1 # Copyright 2008-2019 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 in reverse
23 if ![supports_reverse] {
29 if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
35 if [supports_process_record] {
36 # Activate process record/replay
37 gdb_test_no_output "record" "turn on process record"
40 # plain vanilla step/next (no count)
42 gdb_test "next" ".*NEXT TEST 1.*" "next test 1"
43 gdb_test "step" ".*STEP TEST 1.*" "step test 1"
45 # step/next with count
47 gdb_test "next 2" ".*NEXT TEST 2.*" "next test 2"
48 gdb_test "step 3" ".*STEP TEST 2.*" "step test 2"
52 gdb_test "step" ".*NEXT OVER THIS CALL.*" "step up to call"
53 gdb_test "next" ".*STEP INTO THIS CALL.*" "next over call"
57 gdb_test "step" ".*ARRIVED IN CALLEE.*" "step into call"
61 set test_message "finish out of fn call"
62 gdb_test_multiple "finish" "$test_message" {
63 -re "FINISH TEST.*$gdb_prompt $" {
66 -re "STEP INTO THIS CALL.*$gdb_prompt $" {
72 # stepi over flat code (no calls)
74 set test_message "simple stepi"
75 gdb_test_multiple "stepi" "$test_message" {
76 -re "STEPI TEST.*$gdb_prompt $" {
79 -re "FINISH TEST.*$gdb_prompt $" {
83 -re "NEXTI TEST.*$gdb_prompt $" {
84 fail "$test_message (too far)"
88 # stepi into a function call
90 set test_message "stepi into function call"
91 gdb_test_multiple "stepi" "$test_message" {
92 -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
95 -re "NEXTI TEST.*$gdb_prompt $" {
96 fail "$test_message (too far)"
98 -re "RETURN FROM CALLEE.*$gdb_prompt $" {
99 fail "$test_message (too far)"
101 -re "ENTER CALLEE.*$gdb_prompt $" {
105 -re "STEPI TEST.*$gdb_prompt $" {
111 # stepi thru return of a function call
113 set test_message "stepi back from function call"
114 gdb_test_multiple "stepi" "$test_message" {
115 -re "NEXTI TEST.*$gdb_prompt $" {
118 -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
122 -re "RETURN FROM CALLEE.*$gdb_prompt $" {
126 -re "STEPI TEST.*$gdb_prompt $" {
130 -re "ENTER CALLEE.*$gdb_prompt $" {
131 fail "$test_message (too far)"
139 # Set reverse execution direction
141 gdb_test_no_output "set exec-dir reverse" "set reverse execution"
143 # stepi backward thru return and into a function
145 set stepi_location [gdb_get_line_number "ARRIVED IN CALLEE" "$srcfile"]
146 set test_message "reverse stepi thru function return"
147 gdb_test_multiple "stepi" "$test_message" {
148 -re "NEXTI TEST.*$gdb_prompt $" {
149 fail "$test_message (start statement)"
151 -re "RETURN FROM CALLEE.*$gdb_prompt $" {
155 -re "$hex\[ \t\]*$stepi_location.*ARRIVED IN CALLEE.*$gdb_prompt $" {
159 -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
162 -re "ENTER CALLEE.*$gdb_prompt $" {
163 fail "$test_message (too far)"
165 -re "STEPI TEST.*$gdb_prompt $" {
166 fail "$test_message (too far)"
170 # stepi backward out of a function call
172 set stepi_location [gdb_get_line_number "STEPI TEST" "$srcfile"]
173 set test_message "reverse stepi from a function call"
174 gdb_test_multiple "stepi" "$test_message" {
175 -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
176 fail "$test_message (start statement)"
178 -re "ENTER CALLEE.*$gdb_prompt $" {
182 -re "${hex} in main .*:$stepi_location.*STEPI TEST.*$gdb_prompt $" {
186 -re "STEPI TEST.*$gdb_prompt $" {
189 -re "STEP INTO THIS CALL.*$gdb_prompt $" {
190 fail "$test_message (too far)"
194 # stepi backward over flat code (no calls)
196 set stepi_location [gdb_get_line_number "FINISH TEST" "$srcfile"]
197 set test_message "simple reverse stepi"
198 gdb_test_multiple "stepi" "$test_message" {
199 -re "STEPI TEST.*$gdb_prompt $" {
200 fail "$test_message (start statement)"
202 -re "$hex\[ \t\]*$stepi_location.* FINISH TEST.*$gdb_prompt $" {
206 -re "$stepi_location.* FINISH TEST.*$gdb_prompt $" {
209 -re "STEP INTO THIS CALL.*$gdb_prompt $" {
210 fail "$test_message (too far)"
214 # step backward into function (thru return)
216 gdb_test "step" "(RETURN FROM CALLEE|ARRIVED IN CALLEE).*" \
217 "reverse step into fn call"
219 # step backward out of called function (thru call)
221 set test_message "reverse step out of called fn"
222 gdb_test_multiple "step" "$test_message" {
223 -re "STEP INTO THIS CALL.*.*$gdb_prompt $" {
226 -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
230 -re "ENTER CALLEE.*$gdb_prompt $" {
236 # next backward over call
238 gdb_test "next" ".*NEXT OVER THIS CALL.*" "reverse next over call"
240 # step/next backward with count
242 gdb_test "step 3" ".*REVERSE STEP TEST 1.*" "reverse step test 1"
243 gdb_test "next 2" ".*REVERSE NEXT TEST 1.*" "reverse next test 1"
245 # step/next backward without count
247 gdb_test "step" ".*STEP TEST 1.*" "reverse step test 2"
248 gdb_test "next" ".*NEXT TEST 1.*" "reverse next test 2"
252 # Finish test by running forward to the end.
253 # FIXME return to this later...
254 # gdb_test_no_output "set exec-dir forward" "set forward execution"
255 # gdb_continue_to_end "step-reverse.exp"