fbf41e83f915dda0694bd71b7f65b5b69605bab1
[external/binutils.git] / gdb / testsuite / gdb.reverse / step-reverse.exp
1 # Copyright 2008-2016 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.  */
15
16 # This file is part of the GDB testsuite.  It tests reverse stepping.
17 # Lots of code borrowed from "step-test.exp".
18
19 #
20 # Test step and next in reverse
21 #
22
23 if ![supports_reverse] {
24     return
25 }
26
27 standard_testfile
28
29 if { [prepare_for_testing $testfile.exp $testfile $srcfile] } {
30     return -1
31 }
32
33 runto main
34
35 if [supports_process_record] {
36     # Activate process record/replay
37     gdb_test_no_output "record" "Turn on process record"
38 }
39
40 # plain vanilla step/next (no count)
41
42 gdb_test "next" ".*NEXT TEST 1.*" "next test 1"
43 gdb_test "step" ".*STEP TEST 1.*" "step test 1"
44
45 # step/next with count
46
47 gdb_test "next 2" ".*NEXT TEST 2.*" "next test 2"
48 gdb_test "step 3" ".*STEP TEST 2.*" "step test 2"
49
50 # step over call
51
52 gdb_test "step" ".*NEXT OVER THIS CALL.*" "step up to call"
53 gdb_test "next" ".*STEP INTO THIS CALL.*" "next over call"
54
55 # step into call
56
57 gdb_test "step" ".*ARRIVED IN CALLEE.*" "step into call"
58
59 # finish out of call
60
61 set test_message "finish out of fn call"
62 gdb_test_multiple "finish" "$test_message" {
63     -re "FINISH TEST.*$gdb_prompt $" {
64         pass "$test_message"
65     }
66     -re "STEP INTO THIS CALL.*$gdb_prompt $" {
67         send_gdb "step\n"
68         exp_continue
69     }
70 }
71
72 # stepi over flat code (no calls)
73
74 set test_message "simple stepi"
75 gdb_test_multiple "stepi" "$test_message" {
76     -re "STEPI TEST.*$gdb_prompt $" {
77         pass "$test_message"
78     }
79     -re "FINISH TEST.*$gdb_prompt $" {
80         send_gdb "stepi\n"
81         exp_continue
82     }
83     -re "NEXTI TEST.*$gdb_prompt $" {
84         fail "$test_message (too far)"
85     }
86 }
87
88 # stepi into a function call
89
90 set test_message "stepi into function call"
91 gdb_test_multiple "stepi" "$test_message" {
92     -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
93         pass "$test_message"
94     }
95     -re "NEXTI TEST.*$gdb_prompt $" {
96         fail "$test_message (too far)"
97     }
98     -re "RETURN FROM CALLEE.*$gdb_prompt $" {
99         fail "$test_message (too far)"
100     }
101     -re "ENTER CALLEE.*$gdb_prompt $" {
102         send_gdb "stepi\n"
103         exp_continue
104     }
105     -re "STEPI TEST.*$gdb_prompt $" {
106         send_gdb "stepi\n"
107         exp_continue
108     }
109 }
110
111 # stepi thru return of a function call
112
113 set test_message "stepi back from function call"
114 gdb_test_multiple "stepi" "$test_message" {
115     -re "NEXTI TEST.*$gdb_prompt $" {
116         pass "$test_message"
117     }
118     -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
119         send_gdb "stepi\n"
120         exp_continue
121     }
122     -re "RETURN FROM CALLEE.*$gdb_prompt $" {
123         send_gdb "stepi\n"
124         exp_continue
125     }
126     -re "STEPI TEST.*$gdb_prompt $" {
127         send_gdb "stepi\n"
128         exp_continue
129     }
130     -re "ENTER CALLEE.*$gdb_prompt $" {
131         fail "$test_message (too far)"
132     }
133 }
134
135 ###
136 ###
137 ###
138
139 # Set reverse execution direction
140
141 gdb_test_no_output "set exec-dir reverse" "set reverse execution"
142
143 # stepi backward thru return and into a function
144
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)"
150     }
151     -re "RETURN FROM CALLEE.*$gdb_prompt $" {
152         send_gdb "stepi\n"
153         exp_continue
154     }
155     -re "$hex\[ \t\]*$stepi_location.*ARRIVED IN CALLEE.*$gdb_prompt $" {
156         send_gdb "stepi\n"
157         exp_continue
158     }
159     -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
160         pass "$test_message"
161     }
162     -re "ENTER CALLEE.*$gdb_prompt $" {
163         fail "$test_message (too far)"
164     }
165     -re "STEPI TEST.*$gdb_prompt $" {
166         fail "$test_message (too far)"
167     }
168 }
169
170 # stepi backward out of a function call
171
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)"
177     }
178     -re "ENTER CALLEE.*$gdb_prompt $" {
179         send_gdb "stepi\n" 
180         exp_continue
181     }
182     -re "${hex} in main .*:$stepi_location.*STEPI TEST.*$gdb_prompt $" {
183         send_gdb "stepi\n"
184         exp_continue
185     }
186     -re "STEPI TEST.*$gdb_prompt $" {
187         pass "$test_message"
188     }
189     -re "STEP INTO THIS CALL.*$gdb_prompt $" {
190         fail "$test_message (too far)"
191     }
192 }
193
194 # stepi backward over flat code (no calls)
195
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)"
201     }
202     -re "$hex\[ \t\]*$stepi_location.* FINISH TEST.*$gdb_prompt $" {
203         send_gdb "stepi\n"
204         exp_continue
205     }
206     -re "$stepi_location.* FINISH TEST.*$gdb_prompt $" {
207         pass "$test_message"
208     }
209     -re "STEP INTO THIS CALL.*$gdb_prompt $" {
210         fail "$test_message (too far)"
211     }
212 }
213
214 # step backward into function (thru return)
215
216 set test_message "reverse step into fn call"
217 gdb_test_multiple "step" "$test_message" {
218     -re "RETURN FROM CALLEE.*$gdb_prompt $" {
219         send_gdb "step\n"
220         exp_continue
221     }
222     -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
223         pass "$test_message"
224     }
225 }
226
227 # step backward out of called function (thru call)
228
229 gdb_test "step" ".*STEP INTO THIS CALL.*" "reverse step out of called fn"
230
231 # next backward over call
232
233 gdb_test "next" ".*NEXT OVER THIS CALL.*" "reverse next over call"
234
235 # step/next backward with count
236
237 gdb_test "step 3" ".*REVERSE STEP TEST 1.*" "reverse step test 1"
238 gdb_test "next 2" ".*REVERSE NEXT TEST 1.*" "reverse next test 1"
239
240 # step/next backward without count
241
242 gdb_test "step" ".*STEP TEST 1.*" "reverse step test 2"
243 gdb_test "next" ".*NEXT TEST 1.*" "reverse next test 2"
244
245
246
247 # Finish test by running forward to the end.
248 # FIXME return to this later...
249 # gdb_test_no_output "set exec-dir forward" "set forward execution"
250 # gdb_continue_to_end "step-reverse.exp"
251