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