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