Add support for --start option in -exec-run GDB/MI command.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / checkpoint.exp
CommitLineData
28e7fd62 1# Copyright 2005-2013 Free Software Foundation, Inc.
099ac3dd
MS
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
099ac3dd 6# (at your option) any later version.
e22f8b7c 7#
099ac3dd
MS
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.
e22f8b7c 12#
099ac3dd 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>. */
099ac3dd 15
db9d7fc5 16if { [is_remote target] || ![isnative] } then {
099ac3dd
MS
17 continue
18}
19
20# Until "set follow-fork-mode" and "catch fork" are implemented on
21# other targets...
22#
23if {![istarget "*-*-linux*"]} then {
24 continue
25}
26
099ac3dd 27
f76495c8 28standard_testfile .c
099ac3dd
MS
29
30if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
b60f0898
JB
31 untested checkpoint.exp
32 return -1
099ac3dd
MS
33}
34
35# Start with a fresh gdb
36
f76495c8 37clean_restart ${binfile}
099ac3dd
MS
38
39global gdb_prompt
40
41#
42# This tests gdb checkpoint and restart.
43#
44
45remote_download host ${srcdir}/${subdir}/pi.txt pi.txt
46
47runto_main
48set break1_loc [gdb_get_line_number "breakpoint 1"]
49set break2_loc [gdb_get_line_number "breakpoint 2"]
50set break3_loc [gdb_get_line_number "breakpoint 3"]
51set break4_loc [gdb_get_line_number "breakpoint 4"]
52
53gdb_breakpoint $break1_loc
54gdb_test "continue" "breakpoint 1.*" "break1 start"
55
de7ff789 56gdb_test "checkpoint" ".*" ""
099ac3dd
MS
57gdb_test "continue 10" "breakpoint 1.*" "break1 two"
58
de7ff789 59gdb_test "checkpoint" ".*" ""
099ac3dd
MS
60gdb_test "continue 10" "breakpoint 1.*" "break1 three"
61
de7ff789 62gdb_test "checkpoint" ".*" ""
099ac3dd
MS
63gdb_test "continue 10" "breakpoint 1.*" "break1 four"
64
de7ff789 65gdb_test "checkpoint" ".*" ""
099ac3dd
MS
66gdb_test "continue 10" "breakpoint 1.*" "break1 five"
67
de7ff789 68gdb_test "checkpoint" ".*" ""
099ac3dd
MS
69gdb_test "continue 10" "breakpoint 1.*" "break1 six"
70
de7ff789 71gdb_test "checkpoint" ".*" ""
099ac3dd
MS
72gdb_test "continue 10" "breakpoint 1.*" "break1 seven"
73
de7ff789 74gdb_test "checkpoint" ".*" ""
099ac3dd
MS
75gdb_test "continue 10" "breakpoint 1.*" "break1 eight"
76
de7ff789 77gdb_test "checkpoint" ".*" ""
099ac3dd
MS
78gdb_test "continue 10" "breakpoint 1.*" "break1 nine"
79
de7ff789 80gdb_test "checkpoint" ".*" ""
099ac3dd
MS
81gdb_test "continue 10" "breakpoint 1.*" "break1 ten"
82
de7ff789 83gdb_test "checkpoint" ".*" ""
099ac3dd
MS
84
85gdb_test "info checkpoints" \
86 " 10 .* 9 .* 8 .* 7 .* 6 .* 5 .* 4 .* 3 .* 2 .* 1 .*" \
87 "info checkpoints one"
88
89delete_breakpoints
90gdb_breakpoint $break2_loc
91gdb_test "continue" "breakpoint 2.*" "break2 one"
92
93gdb_test "restart 1" "Switching to .*breakpoint 1.*" "restart 1 one"
94gdb_test "print i" " = 78" "verify i 1 one"
95gdb_test "step" "if .c == EOF.*" "step in 1 one"
96gdb_test "print lines" " = 1.*" "verify lines 1 one"
97
98gdb_test "restart 2" "Switching to .*breakpoint 1.*" "restart 2 one"
99gdb_test "step" "if .c == EOF.*" "step in 2 one"
100gdb_test "print i + 1 == lines * 79" " = 1" "verify i 2 one"
101gdb_test "print lines" " = 11.*" "verify lines 2 one"
102
103gdb_test "restart 3" "Switching to .*breakpoint 1.*" "restart 3 one"
104gdb_test "step" "if .c == EOF.*" "step in 3 one"
105gdb_test "print i + 1 == lines * 79" " = 1" "verify i 3 one"
106gdb_test "print lines" " = 21.*" "verify lines 3 one"
107
108gdb_test "restart 4" "Switching to .*breakpoint 1.*" "restart 4 one"
109gdb_test "step" "if .c == EOF.*" "step in 4 one"
110gdb_test "print i + 1 == lines * 79" " = 1" "verify i 4 one"
111gdb_test "print lines" " = 31.*" "verify lines 4 one"
112
113gdb_test "restart 5" "Switching to .*breakpoint 1.*" "restart 5 one"
114gdb_test "step" "if .c == EOF.*" "step in 5 one"
115gdb_test "print i + 1 == lines * 79" " = 1" "verify i 5 one"
116gdb_test "print lines" " = 41.*" "verify lines 5 one"
117
118gdb_test "restart 6" "Switching to .*breakpoint 1.*" "restart 6 one"
119gdb_test "step" "if .c == EOF.*" "step in 6 one"
120gdb_test "print i + 1 == lines * 79" " = 1" "verify i 6 one"
121gdb_test "print lines" " = 51.*" "verify lines 6 one"
122
123gdb_test "restart 7" "Switching to .*breakpoint 1.*" "restart 7 one"
124gdb_test "step" "if .c == EOF.*" "step in 7 one"
125gdb_test "print i + 1 == lines * 79" " = 1" "verify i 7 one"
126gdb_test "print lines" " = 61.*" "verify lines 7 one"
127
128gdb_test "restart 8" "Switching to .*breakpoint 1.*" "restart 8 one"
129gdb_test "step" "if .c == EOF.*" "step in 8 one"
130gdb_test "print i + 1 == lines * 79" " = 1" "verify i 8 one"
131gdb_test "print lines" " = 71.*" "verify lines 8 one"
132
133gdb_test "restart 9" "Switching to .*breakpoint 1.*" "restart 9 one"
134gdb_test "step" "if .c == EOF.*" "step in 9 one"
135gdb_test "print i + 1 == lines * 79" " = 1" "verify i 9 one"
136gdb_test "print lines" " = 81.*" "verify lines 9 one"
137
138gdb_test "restart 10" "Switching to .*breakpoint 1.*" "restart 10 one"
139gdb_test "step" "if .c == EOF.*" "step in 10 one"
140gdb_test "print i + 1 == lines * 79" " = 1" "verify i 10 one"
141gdb_test "print lines" " = 91.*" "verify lines 10 one"
142
143#
144# Now let the files be closed by the original process,
145# and diff them.
146
147gdb_test "restart 0" "Switching to .*breakpoint 2.*" "restart 0 one"
148gdb_breakpoint $break3_loc
149gdb_test "continue" "breakpoint 3.*" "break3 one"
150
151gdb_test "shell diff -s pi.txt copy1.txt" \
152 "Files pi.txt and copy1.txt are identical.*" \
153 "Diff input and output one"
154
155#
156# And now run from various checkpoints, allowing
157# various amounts of input and output.
158#
159
160gdb_breakpoint $break1_loc
161
162gdb_test "restart 1" "Switching to .*c == EOF.*" "restart 1 two"
de7ff789 163gdb_test "continue" ".*" ""
099ac3dd
MS
164gdb_test "continue 100" "breakpoint 1.*" "breakpoint 1 1 one"
165gdb_test "step" "if .c == EOF.*" "step in 1 two"
166gdb_test "print lines" " = 102.*" "verify lines 1 two"
167
168gdb_test "restart 2" "Switching to .*c == EOF.*" "restart 2 two"
de7ff789 169gdb_test "continue" ".*" ""
099ac3dd
MS
170gdb_test "continue 100" "breakpoint 1.*" "breakpoint 1 2 one"
171gdb_test "step" "if .c == EOF.*" "step in 2 two"
172gdb_test "print lines" " = 112.*" "verify lines 2 two"
173
174gdb_test "restart 3" "Switching to .*c == EOF.*" "restart 3 two"
de7ff789 175gdb_test "continue" ".*" ""
099ac3dd
MS
176gdb_test "continue 500" "breakpoint 1.*" "breakpoint 1 3 one"
177gdb_test "step" "if .c == EOF.*" "step in 3 two"
178gdb_test "print lines" " = 522.*" "verify lines 3 two"
179
180gdb_test "restart 4" "Switching to .*c == EOF.*" "restart 4 two"
de7ff789 181gdb_test "continue" ".*" ""
099ac3dd
MS
182gdb_test "continue 500" "breakpoint 1.*" "breakpoint 1 4 one"
183gdb_test "step" "if .c == EOF.*" "step in 4 two"
184gdb_test "print lines" " = 532.*" "verify lines 4 two"
185
186gdb_test "restart 5" "Switching to .*c == EOF.*" "restart 5 two"
de7ff789 187gdb_test "continue" ".*" ""
099ac3dd
MS
188gdb_test "continue 1000" "breakpoint 1.*" "breakpoint 1 5 one"
189gdb_test "step" "if .c == EOF.*" "step in 5 two"
190gdb_test "print lines" " = 1042.*" "verify lines 5 two"
191
192gdb_test "restart 6" "Switching to .*c == EOF.*" "restart 6 two"
de7ff789 193gdb_test "continue" ".*" ""
099ac3dd
MS
194gdb_test "continue 1000" "breakpoint 1.*" "breakpoint 1 6 one"
195gdb_test "step" "if .c == EOF.*" "step in 6 two"
196gdb_test "print lines" " = 1052.*" "verify lines 5 two"
197
198gdb_test "restart 7" "Switching to .*c == EOF.*" "restart 7 two"
de7ff789 199gdb_test "continue" ".*" ""
099ac3dd
MS
200gdb_test "continue 1100" "breakpoint 1.*" "breakpoint 1 7 one"
201gdb_test "step" "if .c == EOF.*" "step in 7 two"
202gdb_test "print lines" " = 1162.*" "verify lines 7 two"
203
204gdb_test "shell diff -s pi.txt copy1.txt" \
205 "Files pi.txt and copy1.txt are identical.*" \
206 "Diff input and output two"
207
208#
209# OK, now allow the original program to delete the output file,
210# and verify that the checkpoints can still write to it.
211#
212
213gdb_test "restart 0" "Switching to .*breakpoint 3.*" "restart 0 one"
214gdb_breakpoint $break4_loc
215gdb_test "continue" "breakpoint 4.*" "break4 one"
216
217gdb_test "shell diff pi.txt copy1.txt" \
218 "diff: copy1.txt: No such file or directory" \
219 "delete copy1"
220
221delete_breakpoints
222gdb_breakpoint $break2_loc
223
224gdb_test "restart 1" "if .c == EOF.*" "restart 1 three"
225gdb_test "continue" "breakpoint 2.*" "break2 1 one"
226gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 1"
227
5965d69d 228gdb_test "restart 2" "if .c == EOF.*" "restart 2 three"
099ac3dd
MS
229gdb_test "continue" "breakpoint 2.*" "break2 2 one"
230gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 2"
231
5965d69d 232gdb_test "restart 3" "if .c == EOF.*" "restart 3 three"
099ac3dd
MS
233gdb_test "continue" "breakpoint 2.*" "break2 3 one"
234gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 3"
235
5965d69d 236gdb_test "restart 4" "if .c == EOF.*" "restart 4 three"
099ac3dd
MS
237gdb_test "continue" "breakpoint 2.*" "break2 4 one"
238gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 4"
239
5965d69d 240gdb_test "restart 5" "if .c == EOF.*" "restart 5 three"
099ac3dd
MS
241gdb_test "continue" "breakpoint 2.*" "break2 5 one"
242gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 5"
243
5965d69d 244gdb_test "restart 6" "if .c == EOF.*" "restart 6 three"
099ac3dd
MS
245gdb_test "continue" "breakpoint 2.*" "break2 6 one"
246gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 6"
247
5965d69d 248gdb_test "restart 7" "if .c == EOF.*" "restart 7 three"
099ac3dd
MS
249gdb_test "continue" "breakpoint 2.*" "break2 7 one"
250gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 7"
251
5965d69d 252gdb_test "restart 8" "if .c == EOF.*" "restart 8 three"
099ac3dd
MS
253gdb_test "continue" "breakpoint 2.*" "break2 8 one"
254gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 8"
255
5965d69d 256gdb_test "restart 9" "if .c == EOF.*" "restart 9 three"
099ac3dd
MS
257gdb_test "continue" "breakpoint 2.*" "break2 9 one"
258gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 9"
259
5965d69d 260gdb_test "restart 10" "if .c == EOF.*" "restart 10 three"
099ac3dd
MS
261gdb_test "continue" "breakpoint 2.*" "break2 10 one"
262gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 10"
263
264#
265# Now confirm that if one fork exits, we automatically switch to another one.
266#
267
268delete_breakpoints
269gdb_test "continue" \
fda326dd 270 "Deleting copy.*$inferior_exited_re normally.*Switching to.*" \
099ac3dd
MS
271 "Exit, dropped into next fork one"
272
273gdb_test "continue" \
fda326dd 274 "Deleting copy.*$inferior_exited_re normally.*Switching to.*" \
099ac3dd
MS
275 "Exit, dropped into next fork two"
276
277gdb_test "continue" \
fda326dd 278 "Deleting copy.*$inferior_exited_re normally.*Switching to.*" \
099ac3dd
MS
279 "Exit, dropped into next fork three"
280
281gdb_test "continue" \
fda326dd 282 "Deleting copy.*$inferior_exited_re normally.*Switching to.*" \
099ac3dd
MS
283 "Exit, dropped into next fork four"
284
285gdb_test "continue" \
fda326dd 286 "Deleting copy.*$inferior_exited_re normally.*Switching to.*" \
099ac3dd
MS
287 "Exit, dropped into next fork five"
288
289#
290# There should be still at least five forks left
291#
292
293gdb_test "info checkpoints" " 5 .* 4 .* 3 .* 2 .* 1 .*" \
294 "info checkpoints two"
295
296#
297# Kill should now terminate all of them.
298#
299
300gdb_test "kill" "" "kill all one" \
301 "Kill the program being debugged.*y or n. $" "y"
302
303#
304# and confirm that all are gone
305#
306
307gdb_test "restart 0" "Not found.*" "no more checkpoint 0"
308gdb_test "restart 1" "Not found.*" "no more checkpoint 1"
309gdb_test "restart 2" "Not found.*" "no more checkpoint 2"
310gdb_test "restart 3" "Not found.*" "no more checkpoint 3"
311gdb_test "restart 4" "Not found.*" "no more checkpoint 4"
312gdb_test "restart 5" "Not found.*" "no more checkpoint 5"
313gdb_test "restart 6" "Not found.*" "no more checkpoint 6"
314gdb_test "restart 7" "Not found.*" "no more checkpoint 7"
315gdb_test "restart 8" "Not found.*" "no more checkpoint 8"
316gdb_test "restart 9" "Not found.*" "no more checkpoint 9"
317gdb_test "restart 10" "Not found.*" "no more checkpoint 10"
318
319#
e469c7fb 320# Now let's try setting a large number of checkpoints (>600)
099ac3dd
MS
321#
322
323gdb_exit
324gdb_start
325gdb_reinitialize_dir $srcdir/$subdir
326gdb_load ${binfile}
327
328runto_main
329gdb_breakpoint $break1_loc
330
ad3986f0
MS
331gdb_test "commands\nsilent\nif (lines % 2)\ncheckpoint\nend\n continue\nend" \
332 "" \
333 "set checkpoint breakpoint"
099ac3dd 334
e469c7fb
DE
335set prev_timeout $timeout
336set timeout [expr $timeout + 120]
337verbose "Timeout now $timeout sec."
338
099ac3dd
MS
339gdb_breakpoint $break2_loc
340gdb_test "continue" "breakpoint 2.*" "break2 with many checkpoints"
341
47b67b60
DJ
342set count 0
343set msg "info checkpoints with at least 600 checkpoints"
344gdb_test_multiple "info checkpoints" $msg {
345 -re " $decimal process \[^\r\]*\r\n" {
346 incr count
347 exp_continue
348 }
349 -re "$gdb_prompt $" {
350 if { $count >= 600 } {
351 pass $msg
352 } else {
353 fail $msg
354 }
355 }
356}
099ac3dd
MS
357
358#
359# OK, kill 'em all...
360#
361
e469c7fb 362gdb_test "kill" "" "kill all one with many checkpoints" \
099ac3dd
MS
363 "Kill the program being debugged.*y or n. $" "y"
364
e469c7fb
DE
365# Restore old timeout
366set timeout $prev_timeout
367verbose "Timeout now $timeout sec."
368
099ac3dd
MS
369#
370# Finished: cleanup
371#
372
373remote_exec build "rm -f pi.txt"
This page took 0.813044 seconds and 4 git commands to generate.