]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright 2005-2024 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 | # Until "set follow-fork-mode" and "catch fork" are implemented on |
17 | # other targets... | |
18 | # | |
24d59b55 | 19 | require {istarget "*-*-linux*"} |
099ac3dd | 20 | |
e48ef82d PA |
21 | # Checkpoint support is currently implemented in the Linux native |
22 | # target, so only works with "target native". | |
23 | if { [target_info gdb_protocol] != "" } { | |
cdd42066 | 24 | return |
e48ef82d PA |
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. | |
30 | standard_testfile checkpoint.c | |
099ac3dd | 31 | |
59b28c5d TT |
32 | set pi_txt [gdb_remote_download host ${srcdir}/${subdir}/pi.txt] |
33 | if {[is_remote host]} { | |
34 | set copy1_txt copy1.txt | |
35 | } else { | |
36 | set copy1_txt [standard_output_file copy1.txt] | |
37 | } | |
38 | ||
5b362f04 | 39 | if {[prepare_for_testing "failed to prepare" $testfile $srcfile \ |
59b28c5d | 40 | [list debug "additional_flags=-DPI_TXT=\"$pi_txt\" -DCOPY1_TXT=\"$copy1_txt\""]]} { |
b60f0898 | 41 | return -1 |
099ac3dd MS |
42 | } |
43 | ||
099ac3dd MS |
44 | global gdb_prompt |
45 | ||
46 | # | |
47 | # This tests gdb checkpoint and restart. | |
48 | # | |
49 | ||
099ac3dd MS |
50 | runto_main |
51 | set break1_loc [gdb_get_line_number "breakpoint 1"] | |
52 | set break2_loc [gdb_get_line_number "breakpoint 2"] | |
53 | set break3_loc [gdb_get_line_number "breakpoint 3"] | |
54 | set break4_loc [gdb_get_line_number "breakpoint 4"] | |
55 | ||
56 | gdb_breakpoint $break1_loc | |
57 | gdb_test "continue" "breakpoint 1.*" "break1 start" | |
cce0ae56 | 58 | gdb_test "checkpoint" "" "checkpoint one" |
099ac3dd | 59 | |
099ac3dd | 60 | gdb_test "continue 10" "breakpoint 1.*" "break1 two" |
cce0ae56 | 61 | gdb_test "checkpoint" "" "checkpoint two" |
099ac3dd | 62 | |
099ac3dd | 63 | gdb_test "continue 10" "breakpoint 1.*" "break1 three" |
cce0ae56 | 64 | gdb_test "checkpoint" "" "checkpoint three" |
099ac3dd | 65 | |
2bb68cff | 66 | gdb_test "continue 10" "breakpoint 1.*" "break1 four" |
cce0ae56 | 67 | gdb_test "checkpoint" "" "checkpoint four" |
099ac3dd | 68 | |
099ac3dd | 69 | gdb_test "continue 10" "breakpoint 1.*" "break1 five" |
cce0ae56 | 70 | gdb_test "checkpoint" "" "checkpoint five" |
099ac3dd | 71 | |
099ac3dd | 72 | gdb_test "continue 10" "breakpoint 1.*" "break1 six" |
cce0ae56 | 73 | gdb_test "checkpoint" "" "checkpoint six" |
099ac3dd | 74 | |
099ac3dd | 75 | gdb_test "continue 10" "breakpoint 1.*" "break1 seven" |
cce0ae56 | 76 | gdb_test "checkpoint" "" "checkpoint seven" |
099ac3dd | 77 | |
099ac3dd | 78 | gdb_test "continue 10" "breakpoint 1.*" "break1 eight" |
cce0ae56 | 79 | gdb_test "checkpoint" "" "checkpoint eight" |
099ac3dd | 80 | |
099ac3dd | 81 | gdb_test "continue 10" "breakpoint 1.*" "break1 nine" |
cce0ae56 | 82 | gdb_test "checkpoint" "" "checkpoint nine" |
099ac3dd | 83 | |
099ac3dd | 84 | gdb_test "continue 10" "breakpoint 1.*" "break1 ten" |
cce0ae56 | 85 | gdb_test "checkpoint" "" "checkpoint ten" |
099ac3dd | 86 | |
cdf2a0fe TV |
87 | set info_checkpoints_re "" |
88 | for { set i 0 } { $i <= 10 } { incr i } { | |
89 | append info_checkpoints_re " $i .* file .*" | |
90 | } | |
91 | gdb_test "info checkpoints" $info_checkpoints_re "info checkpoints one" | |
099ac3dd MS |
92 | |
93 | delete_breakpoints | |
94 | gdb_breakpoint $break2_loc | |
95 | gdb_test "continue" "breakpoint 2.*" "break2 one" | |
96 | ||
97 | gdb_test "restart 1" "Switching to .*breakpoint 1.*" "restart 1 one" | |
98 | gdb_test "print i" " = 78" "verify i 1 one" | |
99 | gdb_test "step" "if .c == EOF.*" "step in 1 one" | |
100 | gdb_test "print lines" " = 1.*" "verify lines 1 one" | |
101 | ||
102 | gdb_test "restart 2" "Switching to .*breakpoint 1.*" "restart 2 one" | |
103 | gdb_test "step" "if .c == EOF.*" "step in 2 one" | |
104 | gdb_test "print i + 1 == lines * 79" " = 1" "verify i 2 one" | |
105 | gdb_test "print lines" " = 11.*" "verify lines 2 one" | |
106 | ||
107 | gdb_test "restart 3" "Switching to .*breakpoint 1.*" "restart 3 one" | |
108 | gdb_test "step" "if .c == EOF.*" "step in 3 one" | |
109 | gdb_test "print i + 1 == lines * 79" " = 1" "verify i 3 one" | |
110 | gdb_test "print lines" " = 21.*" "verify lines 3 one" | |
111 | ||
112 | gdb_test "restart 4" "Switching to .*breakpoint 1.*" "restart 4 one" | |
113 | gdb_test "step" "if .c == EOF.*" "step in 4 one" | |
114 | gdb_test "print i + 1 == lines * 79" " = 1" "verify i 4 one" | |
115 | gdb_test "print lines" " = 31.*" "verify lines 4 one" | |
116 | ||
117 | gdb_test "restart 5" "Switching to .*breakpoint 1.*" "restart 5 one" | |
118 | gdb_test "step" "if .c == EOF.*" "step in 5 one" | |
119 | gdb_test "print i + 1 == lines * 79" " = 1" "verify i 5 one" | |
120 | gdb_test "print lines" " = 41.*" "verify lines 5 one" | |
121 | ||
122 | gdb_test "restart 6" "Switching to .*breakpoint 1.*" "restart 6 one" | |
123 | gdb_test "step" "if .c == EOF.*" "step in 6 one" | |
124 | gdb_test "print i + 1 == lines * 79" " = 1" "verify i 6 one" | |
125 | gdb_test "print lines" " = 51.*" "verify lines 6 one" | |
126 | ||
127 | gdb_test "restart 7" "Switching to .*breakpoint 1.*" "restart 7 one" | |
128 | gdb_test "step" "if .c == EOF.*" "step in 7 one" | |
129 | gdb_test "print i + 1 == lines * 79" " = 1" "verify i 7 one" | |
130 | gdb_test "print lines" " = 61.*" "verify lines 7 one" | |
131 | ||
132 | gdb_test "restart 8" "Switching to .*breakpoint 1.*" "restart 8 one" | |
133 | gdb_test "step" "if .c == EOF.*" "step in 8 one" | |
134 | gdb_test "print i + 1 == lines * 79" " = 1" "verify i 8 one" | |
135 | gdb_test "print lines" " = 71.*" "verify lines 8 one" | |
136 | ||
137 | gdb_test "restart 9" "Switching to .*breakpoint 1.*" "restart 9 one" | |
138 | gdb_test "step" "if .c == EOF.*" "step in 9 one" | |
139 | gdb_test "print i + 1 == lines * 79" " = 1" "verify i 9 one" | |
140 | gdb_test "print lines" " = 81.*" "verify lines 9 one" | |
141 | ||
142 | gdb_test "restart 10" "Switching to .*breakpoint 1.*" "restart 10 one" | |
143 | gdb_test "step" "if .c == EOF.*" "step in 10 one" | |
144 | gdb_test "print i + 1 == lines * 79" " = 1" "verify i 10 one" | |
145 | gdb_test "print lines" " = 91.*" "verify lines 10 one" | |
146 | ||
147 | # | |
2bb68cff | 148 | # Now let the files be closed by the original process, |
099ac3dd MS |
149 | # and diff them. |
150 | ||
151 | gdb_test "restart 0" "Switching to .*breakpoint 2.*" "restart 0 one" | |
152 | gdb_breakpoint $break3_loc | |
153 | gdb_test "continue" "breakpoint 3.*" "break3 one" | |
154 | ||
59b28c5d TT |
155 | gdb_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 | # | |
2bb68cff | 160 | # And now run from various checkpoints, allowing |
099ac3dd MS |
161 | # various amounts of input and output. |
162 | # | |
163 | ||
164 | gdb_breakpoint $break1_loc | |
165 | ||
166 | gdb_test "restart 1" "Switching to .*c == EOF.*" "restart 1 two" | |
cce0ae56 | 167 | gdb_test "continue" "" "continue, 1" |
099ac3dd MS |
168 | gdb_test "continue 100" "breakpoint 1.*" "breakpoint 1 1 one" |
169 | gdb_test "step" "if .c == EOF.*" "step in 1 two" | |
170 | gdb_test "print lines" " = 102.*" "verify lines 1 two" | |
171 | ||
172 | gdb_test "restart 2" "Switching to .*c == EOF.*" "restart 2 two" | |
cce0ae56 | 173 | gdb_test "continue" "" "continue, 2" |
099ac3dd MS |
174 | gdb_test "continue 100" "breakpoint 1.*" "breakpoint 1 2 one" |
175 | gdb_test "step" "if .c == EOF.*" "step in 2 two" | |
176 | gdb_test "print lines" " = 112.*" "verify lines 2 two" | |
177 | ||
178 | gdb_test "restart 3" "Switching to .*c == EOF.*" "restart 3 two" | |
cce0ae56 | 179 | gdb_test "continue" "" "continue, 3" |
099ac3dd MS |
180 | gdb_test "continue 500" "breakpoint 1.*" "breakpoint 1 3 one" |
181 | gdb_test "step" "if .c == EOF.*" "step in 3 two" | |
182 | gdb_test "print lines" " = 522.*" "verify lines 3 two" | |
183 | ||
184 | gdb_test "restart 4" "Switching to .*c == EOF.*" "restart 4 two" | |
cce0ae56 | 185 | gdb_test "continue" "" "continue, 4" |
099ac3dd MS |
186 | gdb_test "continue 500" "breakpoint 1.*" "breakpoint 1 4 one" |
187 | gdb_test "step" "if .c == EOF.*" "step in 4 two" | |
188 | gdb_test "print lines" " = 532.*" "verify lines 4 two" | |
189 | ||
190 | gdb_test "restart 5" "Switching to .*c == EOF.*" "restart 5 two" | |
cce0ae56 | 191 | gdb_test "continue" "" "continue, 5" |
099ac3dd MS |
192 | gdb_test "continue 1000" "breakpoint 1.*" "breakpoint 1 5 one" |
193 | gdb_test "step" "if .c == EOF.*" "step in 5 two" | |
194 | gdb_test "print lines" " = 1042.*" "verify lines 5 two" | |
195 | ||
196 | gdb_test "restart 6" "Switching to .*c == EOF.*" "restart 6 two" | |
cce0ae56 | 197 | gdb_test "continue" "" "continue, 6" |
099ac3dd MS |
198 | gdb_test "continue 1000" "breakpoint 1.*" "breakpoint 1 6 one" |
199 | gdb_test "step" "if .c == EOF.*" "step in 6 two" | |
2bb68cff | 200 | gdb_test "print lines" " = 1052.*" "verify lines 6 two" |
099ac3dd MS |
201 | |
202 | gdb_test "restart 7" "Switching to .*c == EOF.*" "restart 7 two" | |
cce0ae56 | 203 | gdb_test "continue" "" "continue, 7" |
099ac3dd MS |
204 | gdb_test "continue 1100" "breakpoint 1.*" "breakpoint 1 7 one" |
205 | gdb_test "step" "if .c == EOF.*" "step in 7 two" | |
206 | gdb_test "print lines" " = 1162.*" "verify lines 7 two" | |
207 | ||
59b28c5d TT |
208 | gdb_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 | 211 | |
2bb68cff LS |
212 | # |
213 | # OK, now allow the original program to delete the output file, | |
099ac3dd | 214 | # and verify that the checkpoints can still write to it. |
2bb68cff | 215 | # |
099ac3dd | 216 | |
2bb68cff | 217 | gdb_test "restart 0" "Switching to .*breakpoint 3.*" "restart 0 two" |
099ac3dd MS |
218 | gdb_breakpoint $break4_loc |
219 | gdb_test "continue" "breakpoint 4.*" "break4 one" | |
220 | ||
59b28c5d TT |
221 | gdb_test "shell diff $pi_txt $copy1_txt" \ |
222 | "diff: .*copy1.txt: No such file or directory" \ | |
099ac3dd MS |
223 | "delete copy1" |
224 | ||
225 | delete_breakpoints | |
226 | gdb_breakpoint $break2_loc | |
227 | ||
7022349d PA |
228 | for {set num 1} {$num <= 10} {incr num} { |
229 | gdb_test "restart $num" "if .c == EOF.*" "restart $num three" | |
230 | gdb_test "continue" "breakpoint 2.*" "break2 $num one" | |
231 | gdb_test "print (long) ftell (out) > 100000" " = 1.*" "outfile still open $num" | |
232 | } | |
099ac3dd MS |
233 | |
234 | # | |
235 | # Now confirm that if one fork exits, we automatically switch to another one. | |
236 | # | |
237 | ||
238 | delete_breakpoints | |
239 | gdb_test "continue" \ | |
fda326dd | 240 | "Deleting copy.*$inferior_exited_re normally.*Switching to.*" \ |
bb95117e | 241 | "exit, dropped into next fork one" |
099ac3dd MS |
242 | |
243 | gdb_test "continue" \ | |
fda326dd | 244 | "Deleting copy.*$inferior_exited_re normally.*Switching to.*" \ |
bb95117e | 245 | "exit, dropped into next fork two" |
099ac3dd MS |
246 | |
247 | gdb_test "continue" \ | |
fda326dd | 248 | "Deleting copy.*$inferior_exited_re normally.*Switching to.*" \ |
bb95117e | 249 | "exit, dropped into next fork three" |
099ac3dd MS |
250 | |
251 | gdb_test "continue" \ | |
fda326dd | 252 | "Deleting copy.*$inferior_exited_re normally.*Switching to.*" \ |
bb95117e | 253 | "exit, dropped into next fork four" |
099ac3dd MS |
254 | |
255 | gdb_test "continue" \ | |
fda326dd | 256 | "Deleting copy.*$inferior_exited_re normally.*Switching to.*" \ |
bb95117e | 257 | "exit, dropped into next fork five" |
099ac3dd MS |
258 | |
259 | # | |
260 | # There should be still at least five forks left | |
2bb68cff | 261 | # |
099ac3dd | 262 | |
2f341b6e | 263 | gdb_test "info checkpoints" " 1 .* 2 .* 3 .* 4 .* 5 .*" \ |
099ac3dd MS |
264 | "info checkpoints two" |
265 | ||
266 | # | |
267 | # Kill should now terminate all of them. | |
268 | # | |
269 | ||
270 | gdb_test "kill" "" "kill all one" \ | |
271 | "Kill the program being debugged.*y or n. $" "y" | |
272 | ||
2bb68cff | 273 | # |
099ac3dd MS |
274 | # and confirm that all are gone |
275 | # | |
276 | ||
277 | gdb_test "restart 0" "Not found.*" "no more checkpoint 0" | |
278 | gdb_test "restart 1" "Not found.*" "no more checkpoint 1" | |
279 | gdb_test "restart 2" "Not found.*" "no more checkpoint 2" | |
280 | gdb_test "restart 3" "Not found.*" "no more checkpoint 3" | |
281 | gdb_test "restart 4" "Not found.*" "no more checkpoint 4" | |
282 | gdb_test "restart 5" "Not found.*" "no more checkpoint 5" | |
283 | gdb_test "restart 6" "Not found.*" "no more checkpoint 6" | |
284 | gdb_test "restart 7" "Not found.*" "no more checkpoint 7" | |
285 | gdb_test "restart 8" "Not found.*" "no more checkpoint 8" | |
286 | gdb_test "restart 9" "Not found.*" "no more checkpoint 9" | |
287 | gdb_test "restart 10" "Not found.*" "no more checkpoint 10" | |
288 | ||
289 | # | |
e469c7fb | 290 | # Now let's try setting a large number of checkpoints (>600) |
099ac3dd MS |
291 | # |
292 | ||
c95d486d | 293 | clean_restart $binfile |
099ac3dd MS |
294 | |
295 | runto_main | |
296 | gdb_breakpoint $break1_loc | |
297 | ||
ad3986f0 MS |
298 | gdb_test "commands\nsilent\nif (lines % 2)\ncheckpoint\nend\n continue\nend" \ |
299 | "" \ | |
300 | "set checkpoint breakpoint" | |
099ac3dd | 301 | |
e469c7fb DE |
302 | set prev_timeout $timeout |
303 | set timeout [expr $timeout + 120] | |
304 | verbose "Timeout now $timeout sec." | |
305 | ||
099ac3dd MS |
306 | gdb_breakpoint $break2_loc |
307 | gdb_test "continue" "breakpoint 2.*" "break2 with many checkpoints" | |
308 | ||
47b67b60 DJ |
309 | set count 0 |
310 | set msg "info checkpoints with at least 600 checkpoints" | |
311 | gdb_test_multiple "info checkpoints" $msg { | |
312 | -re " $decimal process \[^\r\]*\r\n" { | |
313 | incr count | |
314 | exp_continue | |
315 | } | |
316 | -re "$gdb_prompt $" { | |
317 | if { $count >= 600 } { | |
318 | pass $msg | |
319 | } else { | |
320 | fail $msg | |
321 | } | |
322 | } | |
2bb68cff | 323 | } |
099ac3dd MS |
324 | |
325 | # | |
326 | # OK, kill 'em all... | |
327 | # | |
328 | ||
e469c7fb | 329 | gdb_test "kill" "" "kill all one with many checkpoints" \ |
099ac3dd MS |
330 | "Kill the program being debugged.*y or n. $" "y" |
331 | ||
e469c7fb DE |
332 | # Restore old timeout |
333 | set timeout $prev_timeout | |
334 | verbose "Timeout now $timeout sec." | |
335 | ||
099ac3dd MS |
336 | # |
337 | # Finished: cleanup | |
338 | # | |
83094d3d TV |
339 | |
340 | # | |
341 | # Now let's try to delete checkpoint 0. | |
342 | # | |
343 | ||
344 | with_test_prefix "delete checkpoint 0" { | |
345 | clean_restart $binfile | |
346 | runto_main | |
347 | ||
348 | gdb_test "checkpoint" "checkpoint 1: fork returned pid $decimal\\." | |
349 | gdb_test "restart 1" "Switching to .*" | |
350 | gdb_test "delete checkpoint 0" "Killed process $decimal" | |
351 | gdb_test "info checkpoints" [string_to_regexp "No checkpoints."] | |
352 | } |