1# Copyright 2008-2020 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
23if ![supports_reverse] {
24    return
25}
26
27standard_testfile
28
29if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
30    return -1
31}
32
33runto main
34
35if [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
42gdb_test "next" ".*NEXT TEST 1.*" "next test 1"
43gdb_test "step" ".*STEP TEST 1.*" "step test 1"
44
45# step/next with count
46
47gdb_test "next 2" ".*NEXT TEST 2.*" "next test 2"
48gdb_test "step 3" ".*STEP TEST 2.*" "step test 2"
49
50# step over call
51
52gdb_test "step" ".*NEXT OVER THIS CALL.*" "step up to call"
53gdb_test "next" ".*STEP INTO THIS CALL.*" "next over call"
54
55# step into call
56
57gdb_test "step" ".*ARRIVED IN CALLEE.*" "step into call"
58
59# finish out of call
60
61set test_message "finish out of fn call"
62gdb_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
74set test_message "simple stepi"
75gdb_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
90set test_message "stepi into function call"
91gdb_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
113set test_message "stepi back from function call"
114gdb_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
141gdb_test_no_output "set exec-dir reverse" "set reverse execution"
142
143# stepi backward thru return and into a function
144
145set stepi_location  [gdb_get_line_number "ARRIVED IN CALLEE" "$srcfile"]
146set test_message "reverse stepi thru function return"
147gdb_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
172set stepi_location  [gdb_get_line_number "STEPI TEST" "$srcfile"]
173set test_message "reverse stepi from a function call"
174gdb_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
196set stepi_location  [gdb_get_line_number "FINISH TEST" "$srcfile"]
197set test_message "simple reverse stepi"
198gdb_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
216gdb_test "step" "(RETURN FROM CALLEE|ARRIVED IN CALLEE).*" \
217    "reverse step into fn call"
218
219# step backward out of called function (thru call)
220
221set test_message "reverse step out of called fn"
222gdb_test_multiple "step" "$test_message" {
223    -re "STEP INTO THIS CALL.*.*$gdb_prompt $" {
224	pass "$test_message"
225    }
226    -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
227	send_gdb "step\n"
228	exp_continue
229    }
230    -re "ENTER CALLEE.*$gdb_prompt $" {
231	send_gdb "step\n"
232	exp_continue
233    }
234}
235
236# next backward over call
237
238gdb_test "next" ".*NEXT OVER THIS CALL.*" "reverse next over call"
239
240# step/next backward with count
241
242gdb_test "step 3" ".*REVERSE STEP TEST 1.*" "reverse step test 1"
243gdb_test "next 2" ".*REVERSE NEXT TEST 1.*" "reverse next test 1"
244
245# step/next backward without count
246
247gdb_test "step" ".*STEP TEST 1.*" "reverse step test 2"
248gdb_test "next" ".*NEXT TEST 1.*" "reverse next test 2"
249
250
251
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"
256
257