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