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