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