1 # Copyright 2005, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 if { [is_remote target] || ![isnative] } then {
25 # Until "set follow-fork-mode" and "catch fork" are implemented on
28 if {![istarget "*-*-linux*"]} then {
33 set testfile "checkpoint"
34 set srcfile ${testfile}.c
35 set binfile ${objdir}/${subdir}/${testfile}
37 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
38 untested checkpoint.exp
42 # Start with a fresh gdb
46 gdb_reinitialize_dir $srcdir/$subdir
52 # This tests gdb checkpoint and restart.
55 remote_download host ${srcdir}/${subdir}/pi.txt pi.txt
58 set break1_loc [gdb_get_line_number "breakpoint 1"]
59 set break2_loc [gdb_get_line_number "breakpoint 2"]
60 set break3_loc [gdb_get_line_number "breakpoint 3"]
61 set break4_loc [gdb_get_line_number "breakpoint 4"]
63 gdb_breakpoint $break1_loc
64 gdb_test "continue" "breakpoint 1.*" "break1 start"
66 gdb_test "checkpoint" ".*" ""
67 gdb_test "continue 10" "breakpoint 1.*" "break1 two"
69 gdb_test "checkpoint" ".*" ""
70 gdb_test "continue 10" "breakpoint 1.*" "break1 three"
72 gdb_test "checkpoint" ".*" ""
73 gdb_test "continue 10" "breakpoint 1.*" "break1 four"
75 gdb_test "checkpoint" ".*" ""
76 gdb_test "continue 10" "breakpoint 1.*" "break1 five"
78 gdb_test "checkpoint" ".*" ""
79 gdb_test "continue 10" "breakpoint 1.*" "break1 six"
81 gdb_test "checkpoint" ".*" ""
82 gdb_test "continue 10" "breakpoint 1.*" "break1 seven"
84 gdb_test "checkpoint" ".*" ""
85 gdb_test "continue 10" "breakpoint 1.*" "break1 eight"
87 gdb_test "checkpoint" ".*" ""
88 gdb_test "continue 10" "breakpoint 1.*" "break1 nine"
90 gdb_test "checkpoint" ".*" ""
91 gdb_test "continue 10" "breakpoint 1.*" "break1 ten"
93 gdb_test "checkpoint" ".*" ""
95 gdb_test "info checkpoints" \
96 " 10 .* 9 .* 8 .* 7 .* 6 .* 5 .* 4 .* 3 .* 2 .* 1 .*" \
97 "info checkpoints one"
100 gdb_breakpoint $break2_loc
101 gdb_test "continue" "breakpoint 2.*" "break2 one"
103 gdb_test "restart 1" "Switching to .*breakpoint 1.*" "restart 1 one"
104 gdb_test "print i" " = 78" "verify i 1 one"
105 gdb_test "step" "if .c == EOF.*" "step in 1 one"
106 gdb_test "print lines" " = 1.*" "verify lines 1 one"
108 gdb_test "restart 2" "Switching to .*breakpoint 1.*" "restart 2 one"
109 gdb_test "step" "if .c == EOF.*" "step in 2 one"
110 gdb_test "print i + 1 == lines * 79" " = 1" "verify i 2 one"
111 gdb_test "print lines" " = 11.*" "verify lines 2 one"
113 gdb_test "restart 3" "Switching to .*breakpoint 1.*" "restart 3 one"
114 gdb_test "step" "if .c == EOF.*" "step in 3 one"
115 gdb_test "print i + 1 == lines * 79" " = 1" "verify i 3 one"
116 gdb_test "print lines" " = 21.*" "verify lines 3 one"
118 gdb_test "restart 4" "Switching to .*breakpoint 1.*" "restart 4 one"
119 gdb_test "step" "if .c == EOF.*" "step in 4 one"
120 gdb_test "print i + 1 == lines * 79" " = 1" "verify i 4 one"
121 gdb_test "print lines" " = 31.*" "verify lines 4 one"
123 gdb_test "restart 5" "Switching to .*breakpoint 1.*" "restart 5 one"
124 gdb_test "step" "if .c == EOF.*" "step in 5 one"
125 gdb_test "print i + 1 == lines * 79" " = 1" "verify i 5 one"
126 gdb_test "print lines" " = 41.*" "verify lines 5 one"
128 gdb_test "restart 6" "Switching to .*breakpoint 1.*" "restart 6 one"
129 gdb_test "step" "if .c == EOF.*" "step in 6 one"
130 gdb_test "print i + 1 == lines * 79" " = 1" "verify i 6 one"
131 gdb_test "print lines" " = 51.*" "verify lines 6 one"
133 gdb_test "restart 7" "Switching to .*breakpoint 1.*" "restart 7 one"
134 gdb_test "step" "if .c == EOF.*" "step in 7 one"
135 gdb_test "print i + 1 == lines * 79" " = 1" "verify i 7 one"
136 gdb_test "print lines" " = 61.*" "verify lines 7 one"
138 gdb_test "restart 8" "Switching to .*breakpoint 1.*" "restart 8 one"
139 gdb_test "step" "if .c == EOF.*" "step in 8 one"
140 gdb_test "print i + 1 == lines * 79" " = 1" "verify i 8 one"
141 gdb_test "print lines" " = 71.*" "verify lines 8 one"
143 gdb_test "restart 9" "Switching to .*breakpoint 1.*" "restart 9 one"
144 gdb_test "step" "if .c == EOF.*" "step in 9 one"
145 gdb_test "print i + 1 == lines * 79" " = 1" "verify i 9 one"
146 gdb_test "print lines" " = 81.*" "verify lines 9 one"
148 gdb_test "restart 10" "Switching to .*breakpoint 1.*" "restart 10 one"
149 gdb_test "step" "if .c == EOF.*" "step in 10 one"
150 gdb_test "print i + 1 == lines * 79" " = 1" "verify i 10 one"
151 gdb_test "print lines" " = 91.*" "verify lines 10 one"
154 # Now let the files be closed by the original process,
157 gdb_test "restart 0" "Switching to .*breakpoint 2.*" "restart 0 one"
158 gdb_breakpoint $break3_loc
159 gdb_test "continue" "breakpoint 3.*" "break3 one"
161 gdb_test "shell diff -s pi.txt copy1.txt" \
162 "Files pi.txt and copy1.txt are identical.*" \
163 "Diff input and output one"
166 # And now run from various checkpoints, allowing
167 # various amounts of input and output.
170 gdb_breakpoint $break1_loc
172 gdb_test "restart 1" "Switching to .*c == EOF.*" "restart 1 two"
173 gdb_test "continue" ".*" ""
174 gdb_test "continue 100" "breakpoint 1.*" "breakpoint 1 1 one"
175 gdb_test "step" "if .c == EOF.*" "step in 1 two"
176 gdb_test "print lines" " = 102.*" "verify lines 1 two"
178 gdb_test "restart 2" "Switching to .*c == EOF.*" "restart 2 two"
179 gdb_test "continue" ".*" ""
180 gdb_test "continue 100" "breakpoint 1.*" "breakpoint 1 2 one"
181 gdb_test "step" "if .c == EOF.*" "step in 2 two"
182 gdb_test "print lines" " = 112.*" "verify lines 2 two"
184 gdb_test "restart 3" "Switching to .*c == EOF.*" "restart 3 two"
185 gdb_test "continue" ".*" ""
186 gdb_test "continue 500" "breakpoint 1.*" "breakpoint 1 3 one"
187 gdb_test "step" "if .c == EOF.*" "step in 3 two"
188 gdb_test "print lines" " = 522.*" "verify lines 3 two"
190 gdb_test "restart 4" "Switching to .*c == EOF.*" "restart 4 two"
191 gdb_test "continue" ".*" ""
192 gdb_test "continue 500" "breakpoint 1.*" "breakpoint 1 4 one"
193 gdb_test "step" "if .c == EOF.*" "step in 4 two"
194 gdb_test "print lines" " = 532.*" "verify lines 4 two"
196 gdb_test "restart 5" "Switching to .*c == EOF.*" "restart 5 two"
197 gdb_test "continue" ".*" ""
198 gdb_test "continue 1000" "breakpoint 1.*" "breakpoint 1 5 one"
199 gdb_test "step" "if .c == EOF.*" "step in 5 two"
200 gdb_test "print lines" " = 1042.*" "verify lines 5 two"
202 gdb_test "restart 6" "Switching to .*c == EOF.*" "restart 6 two"
203 gdb_test "continue" ".*" ""
204 gdb_test "continue 1000" "breakpoint 1.*" "breakpoint 1 6 one"
205 gdb_test "step" "if .c == EOF.*" "step in 6 two"
206 gdb_test "print lines" " = 1052.*" "verify lines 5 two"
208 gdb_test "restart 7" "Switching to .*c == EOF.*" "restart 7 two"
209 gdb_test "continue" ".*" ""
210 gdb_test "continue 1100" "breakpoint 1.*" "breakpoint 1 7 one"
211 gdb_test "step" "if .c == EOF.*" "step in 7 two"
212 gdb_test "print lines" " = 1162.*" "verify lines 7 two"
214 gdb_test "shell diff -s pi.txt copy1.txt" \
215 "Files pi.txt and copy1.txt are identical.*" \
216 "Diff input and output two"
219 # OK, now allow the original program to delete the output file,
220 # and verify that the checkpoints can still write to it.
223 gdb_test "restart 0" "Switching to .*breakpoint 3.*" "restart 0 one"
224 gdb_breakpoint $break4_loc
225 gdb_test "continue" "breakpoint 4.*" "break4 one"
227 gdb_test "shell diff pi.txt copy1.txt" \
228 "diff: copy1.txt: No such file or directory" \
232 gdb_breakpoint $break2_loc
234 gdb_test "restart 1" "if .c == EOF.*" "restart 1 three"
235 gdb_test "continue" "breakpoint 2.*" "break2 1 one"
236 gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 1"
238 gdb_test "restart 2" "if .c == EOF.*" "restart 1 three"
239 gdb_test "continue" "breakpoint 2.*" "break2 2 one"
240 gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 2"
242 gdb_test "restart 3" "if .c == EOF.*" "restart 1 three"
243 gdb_test "continue" "breakpoint 2.*" "break2 3 one"
244 gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 3"
246 gdb_test "restart 4" "if .c == EOF.*" "restart 1 three"
247 gdb_test "continue" "breakpoint 2.*" "break2 4 one"
248 gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 4"
250 gdb_test "restart 5" "if .c == EOF.*" "restart 1 three"
251 gdb_test "continue" "breakpoint 2.*" "break2 5 one"
252 gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 5"
254 gdb_test "restart 6" "if .c == EOF.*" "restart 1 three"
255 gdb_test "continue" "breakpoint 2.*" "break2 6 one"
256 gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 6"
258 gdb_test "restart 7" "if .c == EOF.*" "restart 1 three"
259 gdb_test "continue" "breakpoint 2.*" "break2 7 one"
260 gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 7"
262 gdb_test "restart 8" "if .c == EOF.*" "restart 1 three"
263 gdb_test "continue" "breakpoint 2.*" "break2 8 one"
264 gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 8"
266 gdb_test "restart 9" "if .c == EOF.*" "restart 1 three"
267 gdb_test "continue" "breakpoint 2.*" "break2 9 one"
268 gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 9"
270 gdb_test "restart 10" "if .c == EOF.*" "restart 1 three"
271 gdb_test "continue" "breakpoint 2.*" "break2 10 one"
272 gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 10"
275 # Now confirm that if one fork exits, we automatically switch to another one.
279 gdb_test "continue" \
280 "Deleting copy.*$inferior_exited_re normally.*Switching to.*" \
281 "Exit, dropped into next fork one"
283 gdb_test "continue" \
284 "Deleting copy.*$inferior_exited_re normally.*Switching to.*" \
285 "Exit, dropped into next fork two"
287 gdb_test "continue" \
288 "Deleting copy.*$inferior_exited_re normally.*Switching to.*" \
289 "Exit, dropped into next fork three"
291 gdb_test "continue" \
292 "Deleting copy.*$inferior_exited_re normally.*Switching to.*" \
293 "Exit, dropped into next fork four"
295 gdb_test "continue" \
296 "Deleting copy.*$inferior_exited_re normally.*Switching to.*" \
297 "Exit, dropped into next fork five"
300 # There should be still at least five forks left
303 gdb_test "info checkpoints" " 5 .* 4 .* 3 .* 2 .* 1 .*" \
304 "info checkpoints two"
307 # Kill should now terminate all of them.
310 gdb_test "kill" "" "kill all one" \
311 "Kill the program being debugged.*y or n. $" "y"
314 # and confirm that all are gone
317 gdb_test "restart 0" "Not found.*" "no more checkpoint 0"
318 gdb_test "restart 1" "Not found.*" "no more checkpoint 1"
319 gdb_test "restart 2" "Not found.*" "no more checkpoint 2"
320 gdb_test "restart 3" "Not found.*" "no more checkpoint 3"
321 gdb_test "restart 4" "Not found.*" "no more checkpoint 4"
322 gdb_test "restart 5" "Not found.*" "no more checkpoint 5"
323 gdb_test "restart 6" "Not found.*" "no more checkpoint 6"
324 gdb_test "restart 7" "Not found.*" "no more checkpoint 7"
325 gdb_test "restart 8" "Not found.*" "no more checkpoint 8"
326 gdb_test "restart 9" "Not found.*" "no more checkpoint 9"
327 gdb_test "restart 10" "Not found.*" "no more checkpoint 10"
330 # Now let's try setting a large number of checkpoints (>600)
335 gdb_reinitialize_dir $srcdir/$subdir
339 gdb_breakpoint $break1_loc
341 gdb_test "commands\nsilent\nif (lines % 2)\ncheckpoint\nend\n continue\nend" \
343 "set checkpoint breakpoint"
345 set prev_timeout $timeout
346 set timeout [expr $timeout + 120]
347 verbose "Timeout now $timeout sec."
349 gdb_breakpoint $break2_loc
350 gdb_test "continue" "breakpoint 2.*" "break2 with many checkpoints"
353 set msg "info checkpoints with at least 600 checkpoints"
354 gdb_test_multiple "info checkpoints" $msg {
355 -re " $decimal process \[^\r\]*\r\n" {
359 -re "$gdb_prompt $" {
360 if { $count >= 600 } {
369 # OK, kill 'em all...
372 gdb_test "kill" "" "kill all one with many checkpoints" \
373 "Kill the program being debugged.*y or n. $" "y"
375 # Restore old timeout
376 set timeout $prev_timeout
377 verbose "Timeout now $timeout sec."
383 remote_exec build "rm -f pi.txt"