1 # Copyright 2008, 2009 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 ![target_info exists gdb,can_reverse] {
27 set testfile "step-reverse"
28 set srcfile ${testfile}.c
30 if { [prepare_for_testing $testfile.exp $testfile $srcfile] } {
36 if [target_info exists gdb,use_precord] {
37 # Activate process record/replay
38 gdb_test "record" "" "Turn on process record"
39 # FIXME: command ought to acknowledge, so we can test if it succeeded.
42 # plain vanilla step/next (no count)
44 gdb_test "next" ".*NEXT TEST 1.*" "next test 1"
45 gdb_test "step" ".*STEP TEST 1.*" "step test 1"
47 # step/next with count
49 gdb_test "next 2" ".*NEXT TEST 2.*" "next test 2"
50 gdb_test "step 3" ".*STEP TEST 2.*" "step test 2"
54 gdb_test "step" ".*NEXT OVER THIS CALL.*" "step up to call"
55 gdb_test "next" ".*STEP INTO THIS CALL.*" "next over call"
59 gdb_test "step" ".*ARRIVED IN CALLEE.*" "step into call"
63 set test_message "finish out of fn call"
64 gdb_test_multiple "finish" "$test_message" {
65 -re "FINISH TEST.*$gdb_prompt $" {
68 -re "STEP INTO THIS CALL.*$gdb_prompt $" {
74 # stepi over flat code (no calls)
76 set test_message "simple stepi"
77 gdb_test_multiple "stepi" "$test_message" {
78 -re "STEPI TEST.*$gdb_prompt $" {
81 -re "FINISH TEST.*$gdb_prompt $" {
85 -re "NEXTI TEST.*$gdb_prompt $" {
86 fail "$test_message (too far)"
90 # stepi into a function call
92 set test_message "stepi into function call"
93 gdb_test_multiple "stepi" "$test_message" {
94 -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
97 -re "NEXTI TEST.*$gdb_prompt $" {
98 fail "$test_message (too far)"
100 -re "RETURN FROM CALLEE.*$gdb_prompt $" {
101 fail "$test_message (too far)"
103 -re "ENTER CALLEE.*$gdb_prompt $" {
107 -re "STEPI TEST.*$gdb_prompt $" {
113 # stepi thru return of a function call
115 set test_message "stepi back from function call"
116 gdb_test_multiple "stepi" "$test_message" {
117 -re "NEXTI TEST.*$gdb_prompt $" {
120 -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
124 -re "RETURN FROM CALLEE.*$gdb_prompt $" {
128 -re "STEPI TEST.*$gdb_prompt $" {
132 -re "ENTER CALLEE.*$gdb_prompt $" {
133 fail "$test_message (too far)"
141 # Set reverse execution direction
142 # FIXME: command needs to acknowledge, so we can test if it succeeded.
144 gdb_test "set exec-dir reverse" "" "set reverse execution"
146 # stepi backward thru return and into a function
148 set stepi_location [gdb_get_line_number "ARRIVED IN CALLEE" "$srcfile"]
149 set test_message "reverse stepi thru function return"
150 gdb_test_multiple "stepi" "$test_message" {
151 -re "NEXTI TEST.*$gdb_prompt $" {
152 fail "$test_message (start statement)"
154 -re "RETURN FROM CALLEE.*$gdb_prompt $" {
158 -re "$hex\[ \t\]*$stepi_location.*ARRIVED IN CALLEE.*$gdb_prompt $" {
162 -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
165 -re "ENTER CALLEE.*$gdb_prompt $" {
166 fail "$test_message (too far)"
168 -re "STEPI TEST.*$gdb_prompt $" {
169 fail "$test_message (too far)"
173 # stepi backward out of a function call
175 set stepi_location [gdb_get_line_number "STEPI TEST" "$srcfile"]
176 set test_message "reverse stepi from a function call"
177 gdb_test_multiple "stepi" "$test_message" {
178 -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
179 fail "$test_message (start statement)"
181 -re "ENTER CALLEE.*$gdb_prompt $" {
185 -re "${hex} in main .*:$stepi_location.*STEPI TEST.*$gdb_prompt $" {
189 -re "STEPI TEST.*$gdb_prompt $" {
192 -re "STEP INTO THIS CALL.*$gdb_prompt $" {
193 fail "$test_message (too far)"
197 # stepi backward over flat code (no calls)
199 set stepi_location [gdb_get_line_number "FINISH TEST" "$srcfile"]
200 set test_message "simple reverse stepi"
201 gdb_test_multiple "stepi" "$test_message" {
202 -re "STEPI TEST.*$gdb_prompt $" {
203 fail "$test_message (start statement)"
205 -re "$hex\[ \t\]*$stepi_location.* FINISH TEST.*$gdb_prompt $" {
209 -re "$stepi_location.* FINISH TEST.*$gdb_prompt $" {
212 -re "STEP INTO THIS CALL.*$gdb_prompt $" {
213 fail "$test_message (too far)"
217 # step backward into function (thru return)
219 set test_message "reverse step into fn call"
220 gdb_test_multiple "step" "$test_message" {
221 -re "RETURN FROM CALLEE.*$gdb_prompt $" {
225 -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
230 # step backward out of called function (thru call)
232 gdb_test "step" ".*STEP INTO THIS CALL.*" "reverse step out of called fn"
234 # next backward over call
236 gdb_test "next" ".*NEXT OVER THIS CALL.*" "reverse next over call"
238 # step/next backward with count
240 gdb_test "step 3" ".*REVERSE STEP TEST 1.*" "reverse step test 1"
241 gdb_test "next 2" ".*REVERSE NEXT TEST 1.*" "reverse next test 1"
243 # step/next backward without count
245 gdb_test "step" ".*STEP TEST 1.*" "reverse step test 2"
246 gdb_test "next" ".*NEXT TEST 1.*" "reverse next test 2"
250 # Finish test by running forward to the end.
251 # FIXME return to this later...
252 # gdb_test "set exec-dir forward" "" "set forward execution"
253 # gdb_continue_to_end "step-reverse.exp"