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