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