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