Commit | Line | Data |
---|---|---|
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 |
16 | if $tracelevel then { |
17 | strace $tracelevel | |
18 | } | |
19 | ||
db9d7fc5 | 20 | if { [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 | # | |
27 | if {![istarget "*-*-linux*"]} then { | |
28 | continue | |
29 | } | |
30 | ||
099ac3dd MS |
31 | |
32 | set testfile "checkpoint" | |
33 | set srcfile ${testfile}.c | |
34 | set binfile ${objdir}/${subdir}/${testfile} | |
35 | ||
36 | if { [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 | ||
43 | gdb_exit | |
44 | gdb_start | |
45 | gdb_reinitialize_dir $srcdir/$subdir | |
46 | gdb_load ${binfile} | |
47 | ||
48 | global gdb_prompt | |
49 | ||
50 | # | |
51 | # This tests gdb checkpoint and restart. | |
52 | # | |
53 | ||
54 | remote_download host ${srcdir}/${subdir}/pi.txt pi.txt | |
55 | ||
56 | runto_main | |
57 | set break1_loc [gdb_get_line_number "breakpoint 1"] | |
58 | set break2_loc [gdb_get_line_number "breakpoint 2"] | |
59 | set break3_loc [gdb_get_line_number "breakpoint 3"] | |
60 | set break4_loc [gdb_get_line_number "breakpoint 4"] | |
61 | ||
62 | gdb_breakpoint $break1_loc | |
63 | gdb_test "continue" "breakpoint 1.*" "break1 start" | |
64 | ||
de7ff789 | 65 | gdb_test "checkpoint" ".*" "" |
099ac3dd MS |
66 | gdb_test "continue 10" "breakpoint 1.*" "break1 two" |
67 | ||
de7ff789 | 68 | gdb_test "checkpoint" ".*" "" |
099ac3dd MS |
69 | gdb_test "continue 10" "breakpoint 1.*" "break1 three" |
70 | ||
de7ff789 | 71 | gdb_test "checkpoint" ".*" "" |
099ac3dd MS |
72 | gdb_test "continue 10" "breakpoint 1.*" "break1 four" |
73 | ||
de7ff789 | 74 | gdb_test "checkpoint" ".*" "" |
099ac3dd MS |
75 | gdb_test "continue 10" "breakpoint 1.*" "break1 five" |
76 | ||
de7ff789 | 77 | gdb_test "checkpoint" ".*" "" |
099ac3dd MS |
78 | gdb_test "continue 10" "breakpoint 1.*" "break1 six" |
79 | ||
de7ff789 | 80 | gdb_test "checkpoint" ".*" "" |
099ac3dd MS |
81 | gdb_test "continue 10" "breakpoint 1.*" "break1 seven" |
82 | ||
de7ff789 | 83 | gdb_test "checkpoint" ".*" "" |
099ac3dd MS |
84 | gdb_test "continue 10" "breakpoint 1.*" "break1 eight" |
85 | ||
de7ff789 | 86 | gdb_test "checkpoint" ".*" "" |
099ac3dd MS |
87 | gdb_test "continue 10" "breakpoint 1.*" "break1 nine" |
88 | ||
de7ff789 | 89 | gdb_test "checkpoint" ".*" "" |
099ac3dd MS |
90 | gdb_test "continue 10" "breakpoint 1.*" "break1 ten" |
91 | ||
de7ff789 | 92 | gdb_test "checkpoint" ".*" "" |
099ac3dd MS |
93 | |
94 | gdb_test "info checkpoints" \ | |
95 | " 10 .* 9 .* 8 .* 7 .* 6 .* 5 .* 4 .* 3 .* 2 .* 1 .*" \ | |
96 | "info checkpoints one" | |
97 | ||
98 | delete_breakpoints | |
99 | gdb_breakpoint $break2_loc | |
100 | gdb_test "continue" "breakpoint 2.*" "break2 one" | |
101 | ||
102 | gdb_test "restart 1" "Switching to .*breakpoint 1.*" "restart 1 one" | |
103 | gdb_test "print i" " = 78" "verify i 1 one" | |
104 | gdb_test "step" "if .c == EOF.*" "step in 1 one" | |
105 | gdb_test "print lines" " = 1.*" "verify lines 1 one" | |
106 | ||
107 | gdb_test "restart 2" "Switching to .*breakpoint 1.*" "restart 2 one" | |
108 | gdb_test "step" "if .c == EOF.*" "step in 2 one" | |
109 | gdb_test "print i + 1 == lines * 79" " = 1" "verify i 2 one" | |
110 | gdb_test "print lines" " = 11.*" "verify lines 2 one" | |
111 | ||
112 | gdb_test "restart 3" "Switching to .*breakpoint 1.*" "restart 3 one" | |
113 | gdb_test "step" "if .c == EOF.*" "step in 3 one" | |
114 | gdb_test "print i + 1 == lines * 79" " = 1" "verify i 3 one" | |
115 | gdb_test "print lines" " = 21.*" "verify lines 3 one" | |
116 | ||
117 | gdb_test "restart 4" "Switching to .*breakpoint 1.*" "restart 4 one" | |
118 | gdb_test "step" "if .c == EOF.*" "step in 4 one" | |
119 | gdb_test "print i + 1 == lines * 79" " = 1" "verify i 4 one" | |
120 | gdb_test "print lines" " = 31.*" "verify lines 4 one" | |
121 | ||
122 | gdb_test "restart 5" "Switching to .*breakpoint 1.*" "restart 5 one" | |
123 | gdb_test "step" "if .c == EOF.*" "step in 5 one" | |
124 | gdb_test "print i + 1 == lines * 79" " = 1" "verify i 5 one" | |
125 | gdb_test "print lines" " = 41.*" "verify lines 5 one" | |
126 | ||
127 | gdb_test "restart 6" "Switching to .*breakpoint 1.*" "restart 6 one" | |
128 | gdb_test "step" "if .c == EOF.*" "step in 6 one" | |
129 | gdb_test "print i + 1 == lines * 79" " = 1" "verify i 6 one" | |
130 | gdb_test "print lines" " = 51.*" "verify lines 6 one" | |
131 | ||
132 | gdb_test "restart 7" "Switching to .*breakpoint 1.*" "restart 7 one" | |
133 | gdb_test "step" "if .c == EOF.*" "step in 7 one" | |
134 | gdb_test "print i + 1 == lines * 79" " = 1" "verify i 7 one" | |
135 | gdb_test "print lines" " = 61.*" "verify lines 7 one" | |
136 | ||
137 | gdb_test "restart 8" "Switching to .*breakpoint 1.*" "restart 8 one" | |
138 | gdb_test "step" "if .c == EOF.*" "step in 8 one" | |
139 | gdb_test "print i + 1 == lines * 79" " = 1" "verify i 8 one" | |
140 | gdb_test "print lines" " = 71.*" "verify lines 8 one" | |
141 | ||
142 | gdb_test "restart 9" "Switching to .*breakpoint 1.*" "restart 9 one" | |
143 | gdb_test "step" "if .c == EOF.*" "step in 9 one" | |
144 | gdb_test "print i + 1 == lines * 79" " = 1" "verify i 9 one" | |
145 | gdb_test "print lines" " = 81.*" "verify lines 9 one" | |
146 | ||
147 | gdb_test "restart 10" "Switching to .*breakpoint 1.*" "restart 10 one" | |
148 | gdb_test "step" "if .c == EOF.*" "step in 10 one" | |
149 | gdb_test "print i + 1 == lines * 79" " = 1" "verify i 10 one" | |
150 | gdb_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 | ||
156 | gdb_test "restart 0" "Switching to .*breakpoint 2.*" "restart 0 one" | |
157 | gdb_breakpoint $break3_loc | |
158 | gdb_test "continue" "breakpoint 3.*" "break3 one" | |
159 | ||
160 | gdb_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 | ||
169 | gdb_breakpoint $break1_loc | |
170 | ||
171 | gdb_test "restart 1" "Switching to .*c == EOF.*" "restart 1 two" | |
de7ff789 | 172 | gdb_test "continue" ".*" "" |
099ac3dd MS |
173 | gdb_test "continue 100" "breakpoint 1.*" "breakpoint 1 1 one" |
174 | gdb_test "step" "if .c == EOF.*" "step in 1 two" | |
175 | gdb_test "print lines" " = 102.*" "verify lines 1 two" | |
176 | ||
177 | gdb_test "restart 2" "Switching to .*c == EOF.*" "restart 2 two" | |
de7ff789 | 178 | gdb_test "continue" ".*" "" |
099ac3dd MS |
179 | gdb_test "continue 100" "breakpoint 1.*" "breakpoint 1 2 one" |
180 | gdb_test "step" "if .c == EOF.*" "step in 2 two" | |
181 | gdb_test "print lines" " = 112.*" "verify lines 2 two" | |
182 | ||
183 | gdb_test "restart 3" "Switching to .*c == EOF.*" "restart 3 two" | |
de7ff789 | 184 | gdb_test "continue" ".*" "" |
099ac3dd MS |
185 | gdb_test "continue 500" "breakpoint 1.*" "breakpoint 1 3 one" |
186 | gdb_test "step" "if .c == EOF.*" "step in 3 two" | |
187 | gdb_test "print lines" " = 522.*" "verify lines 3 two" | |
188 | ||
189 | gdb_test "restart 4" "Switching to .*c == EOF.*" "restart 4 two" | |
de7ff789 | 190 | gdb_test "continue" ".*" "" |
099ac3dd MS |
191 | gdb_test "continue 500" "breakpoint 1.*" "breakpoint 1 4 one" |
192 | gdb_test "step" "if .c == EOF.*" "step in 4 two" | |
193 | gdb_test "print lines" " = 532.*" "verify lines 4 two" | |
194 | ||
195 | gdb_test "restart 5" "Switching to .*c == EOF.*" "restart 5 two" | |
de7ff789 | 196 | gdb_test "continue" ".*" "" |
099ac3dd MS |
197 | gdb_test "continue 1000" "breakpoint 1.*" "breakpoint 1 5 one" |
198 | gdb_test "step" "if .c == EOF.*" "step in 5 two" | |
199 | gdb_test "print lines" " = 1042.*" "verify lines 5 two" | |
200 | ||
201 | gdb_test "restart 6" "Switching to .*c == EOF.*" "restart 6 two" | |
de7ff789 | 202 | gdb_test "continue" ".*" "" |
099ac3dd MS |
203 | gdb_test "continue 1000" "breakpoint 1.*" "breakpoint 1 6 one" |
204 | gdb_test "step" "if .c == EOF.*" "step in 6 two" | |
205 | gdb_test "print lines" " = 1052.*" "verify lines 5 two" | |
206 | ||
207 | gdb_test "restart 7" "Switching to .*c == EOF.*" "restart 7 two" | |
de7ff789 | 208 | gdb_test "continue" ".*" "" |
099ac3dd MS |
209 | gdb_test "continue 1100" "breakpoint 1.*" "breakpoint 1 7 one" |
210 | gdb_test "step" "if .c == EOF.*" "step in 7 two" | |
211 | gdb_test "print lines" " = 1162.*" "verify lines 7 two" | |
212 | ||
213 | gdb_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 | ||
222 | gdb_test "restart 0" "Switching to .*breakpoint 3.*" "restart 0 one" | |
223 | gdb_breakpoint $break4_loc | |
224 | gdb_test "continue" "breakpoint 4.*" "break4 one" | |
225 | ||
226 | gdb_test "shell diff pi.txt copy1.txt" \ | |
227 | "diff: copy1.txt: No such file or directory" \ | |
228 | "delete copy1" | |
229 | ||
230 | delete_breakpoints | |
231 | gdb_breakpoint $break2_loc | |
232 | ||
233 | gdb_test "restart 1" "if .c == EOF.*" "restart 1 three" | |
234 | gdb_test "continue" "breakpoint 2.*" "break2 1 one" | |
235 | gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 1" | |
236 | ||
237 | gdb_test "restart 2" "if .c == EOF.*" "restart 1 three" | |
238 | gdb_test "continue" "breakpoint 2.*" "break2 2 one" | |
239 | gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 2" | |
240 | ||
241 | gdb_test "restart 3" "if .c == EOF.*" "restart 1 three" | |
242 | gdb_test "continue" "breakpoint 2.*" "break2 3 one" | |
243 | gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 3" | |
244 | ||
245 | gdb_test "restart 4" "if .c == EOF.*" "restart 1 three" | |
246 | gdb_test "continue" "breakpoint 2.*" "break2 4 one" | |
247 | gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 4" | |
248 | ||
249 | gdb_test "restart 5" "if .c == EOF.*" "restart 1 three" | |
250 | gdb_test "continue" "breakpoint 2.*" "break2 5 one" | |
251 | gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 5" | |
252 | ||
253 | gdb_test "restart 6" "if .c == EOF.*" "restart 1 three" | |
254 | gdb_test "continue" "breakpoint 2.*" "break2 6 one" | |
255 | gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 6" | |
256 | ||
257 | gdb_test "restart 7" "if .c == EOF.*" "restart 1 three" | |
258 | gdb_test "continue" "breakpoint 2.*" "break2 7 one" | |
259 | gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 7" | |
260 | ||
261 | gdb_test "restart 8" "if .c == EOF.*" "restart 1 three" | |
262 | gdb_test "continue" "breakpoint 2.*" "break2 8 one" | |
263 | gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 8" | |
264 | ||
265 | gdb_test "restart 9" "if .c == EOF.*" "restart 1 three" | |
266 | gdb_test "continue" "breakpoint 2.*" "break2 9 one" | |
267 | gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 9" | |
268 | ||
269 | gdb_test "restart 10" "if .c == EOF.*" "restart 1 three" | |
270 | gdb_test "continue" "breakpoint 2.*" "break2 10 one" | |
271 | gdb_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 | ||
277 | delete_breakpoints | |
278 | gdb_test "continue" \ | |
279 | "Deleting copy.*Program exited normally.*Switching to.*" \ | |
280 | "Exit, dropped into next fork one" | |
281 | ||
282 | gdb_test "continue" \ | |
283 | "Deleting copy.*Program exited normally.*Switching to.*" \ | |
284 | "Exit, dropped into next fork two" | |
285 | ||
286 | gdb_test "continue" \ | |
287 | "Deleting copy.*Program exited normally.*Switching to.*" \ | |
288 | "Exit, dropped into next fork three" | |
289 | ||
290 | gdb_test "continue" \ | |
291 | "Deleting copy.*Program exited normally.*Switching to.*" \ | |
292 | "Exit, dropped into next fork four" | |
293 | ||
294 | gdb_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 | ||
302 | gdb_test "info checkpoints" " 5 .* 4 .* 3 .* 2 .* 1 .*" \ | |
303 | "info checkpoints two" | |
304 | ||
305 | # | |
306 | # Kill should now terminate all of them. | |
307 | # | |
308 | ||
309 | gdb_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 | ||
316 | gdb_test "restart 0" "Not found.*" "no more checkpoint 0" | |
317 | gdb_test "restart 1" "Not found.*" "no more checkpoint 1" | |
318 | gdb_test "restart 2" "Not found.*" "no more checkpoint 2" | |
319 | gdb_test "restart 3" "Not found.*" "no more checkpoint 3" | |
320 | gdb_test "restart 4" "Not found.*" "no more checkpoint 4" | |
321 | gdb_test "restart 5" "Not found.*" "no more checkpoint 5" | |
322 | gdb_test "restart 6" "Not found.*" "no more checkpoint 6" | |
323 | gdb_test "restart 7" "Not found.*" "no more checkpoint 7" | |
324 | gdb_test "restart 8" "Not found.*" "no more checkpoint 8" | |
325 | gdb_test "restart 9" "Not found.*" "no more checkpoint 9" | |
326 | gdb_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 | ||
332 | gdb_exit | |
333 | gdb_start | |
334 | gdb_reinitialize_dir $srcdir/$subdir | |
335 | gdb_load ${binfile} | |
336 | ||
337 | runto_main | |
338 | gdb_breakpoint $break1_loc | |
339 | ||
ad3986f0 MS |
340 | gdb_test "commands\nsilent\nif (lines % 2)\ncheckpoint\nend\n continue\nend" \ |
341 | "" \ | |
342 | "set checkpoint breakpoint" | |
099ac3dd | 343 | |
e469c7fb DE |
344 | set prev_timeout $timeout |
345 | set timeout [expr $timeout + 120] | |
346 | verbose "Timeout now $timeout sec." | |
347 | ||
099ac3dd MS |
348 | gdb_breakpoint $break2_loc |
349 | gdb_test "continue" "breakpoint 2.*" "break2 with many checkpoints" | |
350 | ||
47b67b60 DJ |
351 | set count 0 |
352 | set msg "info checkpoints with at least 600 checkpoints" | |
353 | gdb_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 | 371 | gdb_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 |
375 | set timeout $prev_timeout | |
376 | verbose "Timeout now $timeout sec." | |
377 | ||
099ac3dd MS |
378 | # |
379 | # Finished: cleanup | |
380 | # | |
381 | ||
382 | remote_exec build "rm -f pi.txt" |