Clarify "list" output when specified lines are ambiguous
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / checkpoint.exp
1 # Copyright 2005-2017 Free Software Foundation, Inc.
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
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
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.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>. */
15
16 if { [is_remote target] || ![isnative] } then {
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
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
31
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
39 if {[prepare_for_testing "failed to prepare" $testfile $srcfile \
40 [list debug "additional_flags=-DPI_TXT=\"$pi_txt\" -DCOPY1_TXT=\"$copy1_txt\""]]} {
41 return -1
42 }
43
44 global gdb_prompt
45
46 #
47 # This tests gdb checkpoint and restart.
48 #
49
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"
58
59 gdb_test "checkpoint" ".*" ""
60 gdb_test "continue 10" "breakpoint 1.*" "break1 two"
61
62 gdb_test "checkpoint" ".*" ""
63 gdb_test "continue 10" "breakpoint 1.*" "break1 three"
64
65 gdb_test "checkpoint" ".*" ""
66 gdb_test "continue 10" "breakpoint 1.*" "break1 four"
67
68 gdb_test "checkpoint" ".*" ""
69 gdb_test "continue 10" "breakpoint 1.*" "break1 five"
70
71 gdb_test "checkpoint" ".*" ""
72 gdb_test "continue 10" "breakpoint 1.*" "break1 six"
73
74 gdb_test "checkpoint" ".*" ""
75 gdb_test "continue 10" "breakpoint 1.*" "break1 seven"
76
77 gdb_test "checkpoint" ".*" ""
78 gdb_test "continue 10" "breakpoint 1.*" "break1 eight"
79
80 gdb_test "checkpoint" ".*" ""
81 gdb_test "continue 10" "breakpoint 1.*" "break1 nine"
82
83 gdb_test "checkpoint" ".*" ""
84 gdb_test "continue 10" "breakpoint 1.*" "break1 ten"
85
86 gdb_test "checkpoint" ".*" ""
87
88 gdb_test "info checkpoints" \
89 " 1 .* 2 .* 3 .* 4 .* 5 .* 6 .* 7 .* 8 .* 9 .* 10 .*" \
90 "info checkpoints one"
91
92 delete_breakpoints
93 gdb_breakpoint $break2_loc
94 gdb_test "continue" "breakpoint 2.*" "break2 one"
95
96 gdb_test "restart 1" "Switching to .*breakpoint 1.*" "restart 1 one"
97 gdb_test "print i" " = 78" "verify i 1 one"
98 gdb_test "step" "if .c == EOF.*" "step in 1 one"
99 gdb_test "print lines" " = 1.*" "verify lines 1 one"
100
101 gdb_test "restart 2" "Switching to .*breakpoint 1.*" "restart 2 one"
102 gdb_test "step" "if .c == EOF.*" "step in 2 one"
103 gdb_test "print i + 1 == lines * 79" " = 1" "verify i 2 one"
104 gdb_test "print lines" " = 11.*" "verify lines 2 one"
105
106 gdb_test "restart 3" "Switching to .*breakpoint 1.*" "restart 3 one"
107 gdb_test "step" "if .c == EOF.*" "step in 3 one"
108 gdb_test "print i + 1 == lines * 79" " = 1" "verify i 3 one"
109 gdb_test "print lines" " = 21.*" "verify lines 3 one"
110
111 gdb_test "restart 4" "Switching to .*breakpoint 1.*" "restart 4 one"
112 gdb_test "step" "if .c == EOF.*" "step in 4 one"
113 gdb_test "print i + 1 == lines * 79" " = 1" "verify i 4 one"
114 gdb_test "print lines" " = 31.*" "verify lines 4 one"
115
116 gdb_test "restart 5" "Switching to .*breakpoint 1.*" "restart 5 one"
117 gdb_test "step" "if .c == EOF.*" "step in 5 one"
118 gdb_test "print i + 1 == lines * 79" " = 1" "verify i 5 one"
119 gdb_test "print lines" " = 41.*" "verify lines 5 one"
120
121 gdb_test "restart 6" "Switching to .*breakpoint 1.*" "restart 6 one"
122 gdb_test "step" "if .c == EOF.*" "step in 6 one"
123 gdb_test "print i + 1 == lines * 79" " = 1" "verify i 6 one"
124 gdb_test "print lines" " = 51.*" "verify lines 6 one"
125
126 gdb_test "restart 7" "Switching to .*breakpoint 1.*" "restart 7 one"
127 gdb_test "step" "if .c == EOF.*" "step in 7 one"
128 gdb_test "print i + 1 == lines * 79" " = 1" "verify i 7 one"
129 gdb_test "print lines" " = 61.*" "verify lines 7 one"
130
131 gdb_test "restart 8" "Switching to .*breakpoint 1.*" "restart 8 one"
132 gdb_test "step" "if .c == EOF.*" "step in 8 one"
133 gdb_test "print i + 1 == lines * 79" " = 1" "verify i 8 one"
134 gdb_test "print lines" " = 71.*" "verify lines 8 one"
135
136 gdb_test "restart 9" "Switching to .*breakpoint 1.*" "restart 9 one"
137 gdb_test "step" "if .c == EOF.*" "step in 9 one"
138 gdb_test "print i + 1 == lines * 79" " = 1" "verify i 9 one"
139 gdb_test "print lines" " = 81.*" "verify lines 9 one"
140
141 gdb_test "restart 10" "Switching to .*breakpoint 1.*" "restart 10 one"
142 gdb_test "step" "if .c == EOF.*" "step in 10 one"
143 gdb_test "print i + 1 == lines * 79" " = 1" "verify i 10 one"
144 gdb_test "print lines" " = 91.*" "verify lines 10 one"
145
146 #
147 # Now let the files be closed by the original process,
148 # and diff them.
149
150 gdb_test "restart 0" "Switching to .*breakpoint 2.*" "restart 0 one"
151 gdb_breakpoint $break3_loc
152 gdb_test "continue" "breakpoint 3.*" "break3 one"
153
154 gdb_test "shell diff -s $pi_txt $copy1_txt" \
155 "Files .*pi.txt and .*copy1.txt are identical.*" \
156 "diff input and output one"
157
158 #
159 # And now run from various checkpoints, allowing
160 # various amounts of input and output.
161 #
162
163 gdb_breakpoint $break1_loc
164
165 gdb_test "restart 1" "Switching to .*c == EOF.*" "restart 1 two"
166 gdb_test "continue" ".*" ""
167 gdb_test "continue 100" "breakpoint 1.*" "breakpoint 1 1 one"
168 gdb_test "step" "if .c == EOF.*" "step in 1 two"
169 gdb_test "print lines" " = 102.*" "verify lines 1 two"
170
171 gdb_test "restart 2" "Switching to .*c == EOF.*" "restart 2 two"
172 gdb_test "continue" ".*" ""
173 gdb_test "continue 100" "breakpoint 1.*" "breakpoint 1 2 one"
174 gdb_test "step" "if .c == EOF.*" "step in 2 two"
175 gdb_test "print lines" " = 112.*" "verify lines 2 two"
176
177 gdb_test "restart 3" "Switching to .*c == EOF.*" "restart 3 two"
178 gdb_test "continue" ".*" ""
179 gdb_test "continue 500" "breakpoint 1.*" "breakpoint 1 3 one"
180 gdb_test "step" "if .c == EOF.*" "step in 3 two"
181 gdb_test "print lines" " = 522.*" "verify lines 3 two"
182
183 gdb_test "restart 4" "Switching to .*c == EOF.*" "restart 4 two"
184 gdb_test "continue" ".*" ""
185 gdb_test "continue 500" "breakpoint 1.*" "breakpoint 1 4 one"
186 gdb_test "step" "if .c == EOF.*" "step in 4 two"
187 gdb_test "print lines" " = 532.*" "verify lines 4 two"
188
189 gdb_test "restart 5" "Switching to .*c == EOF.*" "restart 5 two"
190 gdb_test "continue" ".*" ""
191 gdb_test "continue 1000" "breakpoint 1.*" "breakpoint 1 5 one"
192 gdb_test "step" "if .c == EOF.*" "step in 5 two"
193 gdb_test "print lines" " = 1042.*" "verify lines 5 two"
194
195 gdb_test "restart 6" "Switching to .*c == EOF.*" "restart 6 two"
196 gdb_test "continue" ".*" ""
197 gdb_test "continue 1000" "breakpoint 1.*" "breakpoint 1 6 one"
198 gdb_test "step" "if .c == EOF.*" "step in 6 two"
199 gdb_test "print lines" " = 1052.*" "verify lines 5 two"
200
201 gdb_test "restart 7" "Switching to .*c == EOF.*" "restart 7 two"
202 gdb_test "continue" ".*" ""
203 gdb_test "continue 1100" "breakpoint 1.*" "breakpoint 1 7 one"
204 gdb_test "step" "if .c == EOF.*" "step in 7 two"
205 gdb_test "print lines" " = 1162.*" "verify lines 7 two"
206
207 gdb_test "shell diff -s $pi_txt $copy1_txt" \
208 "Files .*pi.txt and .*copy1.txt are identical.*" \
209 "diff input and output two"
210
211 #
212 # OK, now allow the original program to delete the output file,
213 # and verify that the checkpoints can still write to it.
214 #
215
216 gdb_test "restart 0" "Switching to .*breakpoint 3.*" "restart 0 one"
217 gdb_breakpoint $break4_loc
218 gdb_test "continue" "breakpoint 4.*" "break4 one"
219
220 gdb_test "shell diff $pi_txt $copy1_txt" \
221 "diff: .*copy1.txt: No such file or directory" \
222 "delete copy1"
223
224 delete_breakpoints
225 gdb_breakpoint $break2_loc
226
227 gdb_test "restart 1" "if .c == EOF.*" "restart 1 three"
228 gdb_test "continue" "breakpoint 2.*" "break2 1 one"
229 gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 1"
230
231 gdb_test "restart 2" "if .c == EOF.*" "restart 2 three"
232 gdb_test "continue" "breakpoint 2.*" "break2 2 one"
233 gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 2"
234
235 gdb_test "restart 3" "if .c == EOF.*" "restart 3 three"
236 gdb_test "continue" "breakpoint 2.*" "break2 3 one"
237 gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 3"
238
239 gdb_test "restart 4" "if .c == EOF.*" "restart 4 three"
240 gdb_test "continue" "breakpoint 2.*" "break2 4 one"
241 gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 4"
242
243 gdb_test "restart 5" "if .c == EOF.*" "restart 5 three"
244 gdb_test "continue" "breakpoint 2.*" "break2 5 one"
245 gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 5"
246
247 gdb_test "restart 6" "if .c == EOF.*" "restart 6 three"
248 gdb_test "continue" "breakpoint 2.*" "break2 6 one"
249 gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 6"
250
251 gdb_test "restart 7" "if .c == EOF.*" "restart 7 three"
252 gdb_test "continue" "breakpoint 2.*" "break2 7 one"
253 gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 7"
254
255 gdb_test "restart 8" "if .c == EOF.*" "restart 8 three"
256 gdb_test "continue" "breakpoint 2.*" "break2 8 one"
257 gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 8"
258
259 gdb_test "restart 9" "if .c == EOF.*" "restart 9 three"
260 gdb_test "continue" "breakpoint 2.*" "break2 9 one"
261 gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 9"
262
263 gdb_test "restart 10" "if .c == EOF.*" "restart 10 three"
264 gdb_test "continue" "breakpoint 2.*" "break2 10 one"
265 gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 10"
266
267 #
268 # Now confirm that if one fork exits, we automatically switch to another one.
269 #
270
271 delete_breakpoints
272 gdb_test "continue" \
273 "Deleting copy.*$inferior_exited_re normally.*Switching to.*" \
274 "exit, dropped into next fork one"
275
276 gdb_test "continue" \
277 "Deleting copy.*$inferior_exited_re normally.*Switching to.*" \
278 "exit, dropped into next fork two"
279
280 gdb_test "continue" \
281 "Deleting copy.*$inferior_exited_re normally.*Switching to.*" \
282 "exit, dropped into next fork three"
283
284 gdb_test "continue" \
285 "Deleting copy.*$inferior_exited_re normally.*Switching to.*" \
286 "exit, dropped into next fork four"
287
288 gdb_test "continue" \
289 "Deleting copy.*$inferior_exited_re normally.*Switching to.*" \
290 "exit, dropped into next fork five"
291
292 #
293 # There should be still at least five forks left
294 #
295
296 gdb_test "info checkpoints" " 1 .* 2 .* 3 .* 4 .* 5 .*" \
297 "info checkpoints two"
298
299 #
300 # Kill should now terminate all of them.
301 #
302
303 gdb_test "kill" "" "kill all one" \
304 "Kill the program being debugged.*y or n. $" "y"
305
306 #
307 # and confirm that all are gone
308 #
309
310 gdb_test "restart 0" "Not found.*" "no more checkpoint 0"
311 gdb_test "restart 1" "Not found.*" "no more checkpoint 1"
312 gdb_test "restart 2" "Not found.*" "no more checkpoint 2"
313 gdb_test "restart 3" "Not found.*" "no more checkpoint 3"
314 gdb_test "restart 4" "Not found.*" "no more checkpoint 4"
315 gdb_test "restart 5" "Not found.*" "no more checkpoint 5"
316 gdb_test "restart 6" "Not found.*" "no more checkpoint 6"
317 gdb_test "restart 7" "Not found.*" "no more checkpoint 7"
318 gdb_test "restart 8" "Not found.*" "no more checkpoint 8"
319 gdb_test "restart 9" "Not found.*" "no more checkpoint 9"
320 gdb_test "restart 10" "Not found.*" "no more checkpoint 10"
321
322 #
323 # Now let's try setting a large number of checkpoints (>600)
324 #
325
326 gdb_exit
327 gdb_start
328 gdb_reinitialize_dir $srcdir/$subdir
329 gdb_load ${binfile}
330
331 runto_main
332 gdb_breakpoint $break1_loc
333
334 gdb_test "commands\nsilent\nif (lines % 2)\ncheckpoint\nend\n continue\nend" \
335 "" \
336 "set checkpoint breakpoint"
337
338 set prev_timeout $timeout
339 set timeout [expr $timeout + 120]
340 verbose "Timeout now $timeout sec."
341
342 gdb_breakpoint $break2_loc
343 gdb_test "continue" "breakpoint 2.*" "break2 with many checkpoints"
344
345 set count 0
346 set msg "info checkpoints with at least 600 checkpoints"
347 gdb_test_multiple "info checkpoints" $msg {
348 -re " $decimal process \[^\r\]*\r\n" {
349 incr count
350 exp_continue
351 }
352 -re "$gdb_prompt $" {
353 if { $count >= 600 } {
354 pass $msg
355 } else {
356 fail $msg
357 }
358 }
359 }
360
361 #
362 # OK, kill 'em all...
363 #
364
365 gdb_test "kill" "" "kill all one with many checkpoints" \
366 "Kill the program being debugged.*y or n. $" "y"
367
368 # Restore old timeout
369 set timeout $prev_timeout
370 verbose "Timeout now $timeout sec."
371
372 #
373 # Finished: cleanup
374 #
This page took 0.056239 seconds and 4 git commands to generate.