summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/checkpoint.exp
blob: 23a0a3683020e96b1aa04d11f25aacf9f500fdb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
#   Copyright 2005, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

if $tracelevel then {
	strace $tracelevel
	}

if { [is_remote target] || ![isnative] } then {
    continue
}

# Until "set follow-fork-mode" and "catch fork" are implemented on
# other targets...
#
if {![istarget "*-*-linux*"]} then {
    continue
}


set testfile "checkpoint"
set srcfile ${testfile}.c
set binfile ${objdir}/${subdir}/${testfile}

if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
     untested checkpoint.exp
     return -1
}

# Start with a fresh gdb

gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}

global gdb_prompt

#
# This tests gdb checkpoint and restart.
#

remote_download host ${srcdir}/${subdir}/pi.txt pi.txt

runto_main
set break1_loc [gdb_get_line_number "breakpoint 1"]
set break2_loc [gdb_get_line_number "breakpoint 2"]
set break3_loc [gdb_get_line_number "breakpoint 3"]
set break4_loc [gdb_get_line_number "breakpoint 4"]

gdb_breakpoint $break1_loc
gdb_test "continue" "breakpoint 1.*" "break1 start"

gdb_test "checkpoint" ".*" ""
gdb_test "continue 10" "breakpoint 1.*" "break1 two"

gdb_test "checkpoint" ".*" ""
gdb_test "continue 10" "breakpoint 1.*" "break1 three"

gdb_test "checkpoint" ".*" ""
gdb_test "continue 10" "breakpoint 1.*" "break1 four" 

gdb_test "checkpoint" ".*" ""
gdb_test "continue 10" "breakpoint 1.*" "break1 five"

gdb_test "checkpoint" ".*" ""
gdb_test "continue 10" "breakpoint 1.*" "break1 six"

gdb_test "checkpoint" ".*" ""
gdb_test "continue 10" "breakpoint 1.*" "break1 seven"

gdb_test "checkpoint" ".*" ""
gdb_test "continue 10" "breakpoint 1.*" "break1 eight"

gdb_test "checkpoint" ".*" ""
gdb_test "continue 10" "breakpoint 1.*" "break1 nine"

gdb_test "checkpoint" ".*" ""
gdb_test "continue 10" "breakpoint 1.*" "break1 ten"

gdb_test "checkpoint" ".*" ""

gdb_test "info checkpoints" \
    " 10 .* 9 .* 8 .* 7 .* 6 .* 5 .* 4 .* 3 .* 2 .* 1 .*" \
    "info checkpoints one"

delete_breakpoints
gdb_breakpoint $break2_loc
gdb_test "continue" "breakpoint 2.*" "break2 one"

gdb_test "restart 1" "Switching to .*breakpoint 1.*" "restart 1 one"
gdb_test "print i" " = 78" "verify i 1 one"
gdb_test "step" "if .c == EOF.*" "step in 1 one"
gdb_test "print lines" " = 1.*" "verify lines 1 one"

gdb_test "restart 2" "Switching to .*breakpoint 1.*" "restart 2 one"
gdb_test "step" "if .c == EOF.*" "step in 2 one"
gdb_test "print i + 1 == lines * 79" " = 1" "verify i 2 one"
gdb_test "print lines" " = 11.*" "verify lines 2 one"

gdb_test "restart 3" "Switching to .*breakpoint 1.*" "restart 3 one"
gdb_test "step" "if .c == EOF.*" "step in 3 one"
gdb_test "print i + 1 == lines * 79" " = 1" "verify i 3 one"
gdb_test "print lines" " = 21.*" "verify lines 3 one"

gdb_test "restart 4" "Switching to .*breakpoint 1.*" "restart 4 one"
gdb_test "step" "if .c == EOF.*" "step in 4 one"
gdb_test "print i + 1 == lines * 79" " = 1" "verify i 4 one"
gdb_test "print lines" " = 31.*" "verify lines 4 one"

gdb_test "restart 5" "Switching to .*breakpoint 1.*" "restart 5 one"
gdb_test "step" "if .c == EOF.*" "step in 5 one"
gdb_test "print i + 1 == lines * 79" " = 1" "verify i 5 one"
gdb_test "print lines" " = 41.*" "verify lines 5 one"

gdb_test "restart 6" "Switching to .*breakpoint 1.*" "restart 6 one"
gdb_test "step" "if .c == EOF.*" "step in 6 one"
gdb_test "print i + 1 == lines * 79" " = 1" "verify i 6 one"
gdb_test "print lines" " = 51.*" "verify lines 6 one"

gdb_test "restart 7" "Switching to .*breakpoint 1.*" "restart 7 one"
gdb_test "step" "if .c == EOF.*" "step in 7 one"
gdb_test "print i + 1 == lines * 79" " = 1" "verify i 7 one"
gdb_test "print lines" " = 61.*" "verify lines 7 one"

gdb_test "restart 8" "Switching to .*breakpoint 1.*" "restart 8 one"
gdb_test "step" "if .c == EOF.*" "step in 8 one"
gdb_test "print i + 1 == lines * 79" " = 1" "verify i 8 one"
gdb_test "print lines" " = 71.*" "verify lines 8 one"

gdb_test "restart 9" "Switching to .*breakpoint 1.*" "restart 9 one"
gdb_test "step" "if .c == EOF.*" "step in 9 one"
gdb_test "print i + 1 == lines * 79" " = 1" "verify i 9 one"
gdb_test "print lines" " = 81.*" "verify lines 9 one"

gdb_test "restart 10" "Switching to .*breakpoint 1.*" "restart 10 one"
gdb_test "step" "if .c == EOF.*" "step in 10 one"
gdb_test "print i + 1 == lines * 79" " = 1" "verify i 10 one"
gdb_test "print lines" " = 91.*" "verify lines 10 one"

#
# Now let the files be closed by the original process, 
# and diff them.

gdb_test "restart 0" "Switching to .*breakpoint 2.*" "restart 0 one"
gdb_breakpoint $break3_loc
gdb_test "continue" "breakpoint 3.*" "break3 one"

gdb_test "shell diff -s pi.txt copy1.txt" \
    "Files pi.txt and copy1.txt are identical.*" \
    "Diff input and output one"

#
# And now run from various checkpoints, allowing 
# various amounts of input and output.
#

gdb_breakpoint $break1_loc

gdb_test "restart 1" "Switching to .*c == EOF.*" "restart 1 two"
gdb_test "continue" ".*" ""
gdb_test "continue 100" "breakpoint 1.*" "breakpoint 1 1 one"
gdb_test "step" "if .c == EOF.*" "step in 1 two"
gdb_test "print lines" " = 102.*" "verify lines 1 two"

gdb_test "restart 2" "Switching to .*c == EOF.*" "restart 2 two"
gdb_test "continue" ".*" ""
gdb_test "continue 100" "breakpoint 1.*" "breakpoint 1 2 one"
gdb_test "step" "if .c == EOF.*" "step in 2 two"
gdb_test "print lines" " = 112.*" "verify lines 2 two"

gdb_test "restart 3" "Switching to .*c == EOF.*" "restart 3 two"
gdb_test "continue" ".*" ""
gdb_test "continue 500" "breakpoint 1.*" "breakpoint 1 3 one"
gdb_test "step" "if .c == EOF.*" "step in 3 two"
gdb_test "print lines" " = 522.*" "verify lines 3 two"

gdb_test "restart 4" "Switching to .*c == EOF.*" "restart 4 two"
gdb_test "continue" ".*" ""
gdb_test "continue 500" "breakpoint 1.*" "breakpoint 1 4 one"
gdb_test "step" "if .c == EOF.*" "step in 4 two"
gdb_test "print lines" " = 532.*" "verify lines 4 two"

gdb_test "restart 5" "Switching to .*c == EOF.*" "restart 5 two"
gdb_test "continue" ".*" ""
gdb_test "continue 1000" "breakpoint 1.*" "breakpoint 1 5 one"
gdb_test "step" "if .c == EOF.*" "step in 5 two"
gdb_test "print lines" " = 1042.*" "verify lines 5 two"

gdb_test "restart 6" "Switching to .*c == EOF.*" "restart 6 two"
gdb_test "continue" ".*" ""
gdb_test "continue 1000" "breakpoint 1.*" "breakpoint 1 6 one"
gdb_test "step" "if .c == EOF.*" "step in 6 two"
gdb_test "print lines" " = 1052.*" "verify lines 5 two"

gdb_test "restart 7" "Switching to .*c == EOF.*" "restart 7 two"
gdb_test "continue" ".*" ""
gdb_test "continue 1100" "breakpoint 1.*" "breakpoint 1 7 one"
gdb_test "step" "if .c == EOF.*" "step in 7 two"
gdb_test "print lines" " = 1162.*" "verify lines 7 two"

gdb_test "shell diff -s pi.txt copy1.txt" \
    "Files pi.txt and copy1.txt are identical.*" \
    "Diff input and output two"

# 
# OK, now allow the original program to delete the output file, 
# and verify that the checkpoints can still write to it.
# 

gdb_test "restart 0" "Switching to .*breakpoint 3.*" "restart 0 one"
gdb_breakpoint $break4_loc
gdb_test "continue" "breakpoint 4.*" "break4 one"

gdb_test "shell diff pi.txt copy1.txt" \
    "diff: copy1.txt: No such file or directory" \
    "delete copy1"

delete_breakpoints
gdb_breakpoint $break2_loc

gdb_test "restart 1" "if .c == EOF.*" "restart 1 three"
gdb_test "continue" "breakpoint 2.*" "break2 1 one"
gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 1"

gdb_test "restart 2" "if .c == EOF.*" "restart 1 three"
gdb_test "continue" "breakpoint 2.*" "break2 2 one"
gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 2"

gdb_test "restart 3" "if .c == EOF.*" "restart 1 three"
gdb_test "continue" "breakpoint 2.*" "break2 3 one"
gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 3"

gdb_test "restart 4" "if .c == EOF.*" "restart 1 three"
gdb_test "continue" "breakpoint 2.*" "break2 4 one"
gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 4"

gdb_test "restart 5" "if .c == EOF.*" "restart 1 three"
gdb_test "continue" "breakpoint 2.*" "break2 5 one"
gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 5"

gdb_test "restart 6" "if .c == EOF.*" "restart 1 three"
gdb_test "continue" "breakpoint 2.*" "break2 6 one"
gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 6"

gdb_test "restart 7" "if .c == EOF.*" "restart 1 three"
gdb_test "continue" "breakpoint 2.*" "break2 7 one"
gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 7"

gdb_test "restart 8" "if .c == EOF.*" "restart 1 three"
gdb_test "continue" "breakpoint 2.*" "break2 8 one"
gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 8"

gdb_test "restart 9" "if .c == EOF.*" "restart 1 three"
gdb_test "continue" "breakpoint 2.*" "break2 9 one"
gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 9"

gdb_test "restart 10" "if .c == EOF.*" "restart 1 three"
gdb_test "continue" "breakpoint 2.*" "break2 10 one"
gdb_test "print ftell (out) > 100000" " = 1.*" "outfile still open 10"

#
# Now confirm that if one fork exits, we automatically switch to another one.
#

delete_breakpoints
gdb_test "continue" \
    "Deleting copy.*Program exited normally.*Switching to.*" \
    "Exit, dropped into next fork one"

gdb_test "continue" \
    "Deleting copy.*Program exited normally.*Switching to.*" \
    "Exit, dropped into next fork two"

gdb_test "continue" \
    "Deleting copy.*Program exited normally.*Switching to.*" \
    "Exit, dropped into next fork three"

gdb_test "continue" \
    "Deleting copy.*Program exited normally.*Switching to.*" \
    "Exit, dropped into next fork four"

gdb_test "continue" \
    "Deleting copy.*Program exited normally.*Switching to.*" \
    "Exit, dropped into next fork five"

#
# There should be still at least five forks left
# 

gdb_test "info checkpoints" " 5 .* 4 .* 3 .* 2 .* 1 .*" \
    "info checkpoints two"

#
# Kill should now terminate all of them.
#

gdb_test "kill" "" "kill all one" \
    "Kill the program being debugged.*y or n. $" "y"

# 
# and confirm that all are gone
#

gdb_test "restart 0" "Not found.*" "no more checkpoint 0"
gdb_test "restart 1" "Not found.*" "no more checkpoint 1"
gdb_test "restart 2" "Not found.*" "no more checkpoint 2"
gdb_test "restart 3" "Not found.*" "no more checkpoint 3"
gdb_test "restart 4" "Not found.*" "no more checkpoint 4"
gdb_test "restart 5" "Not found.*" "no more checkpoint 5"
gdb_test "restart 6" "Not found.*" "no more checkpoint 6"
gdb_test "restart 7" "Not found.*" "no more checkpoint 7"
gdb_test "restart 8" "Not found.*" "no more checkpoint 8"
gdb_test "restart 9" "Not found.*" "no more checkpoint 9"
gdb_test "restart 10" "Not found.*" "no more checkpoint 10"

#
# Now let's try setting a large number of checkpoints (>600)
#

gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}

runto_main
gdb_breakpoint $break1_loc

gdb_test "commands\nsilent\nif (lines % 2)\ncheckpoint\nend\n  continue\nend" \
    "" \
    "set checkpoint breakpoint"

set prev_timeout $timeout
set timeout [expr $timeout + 120]
verbose "Timeout now $timeout sec."

gdb_breakpoint $break2_loc
gdb_test "continue" "breakpoint 2.*" "break2 with many checkpoints"

set count 0
set msg "info checkpoints with at least 600 checkpoints"
gdb_test_multiple "info checkpoints" $msg {
    -re "  $decimal process \[^\r\]*\r\n" {
	incr count
	exp_continue
    }
    -re "$gdb_prompt $" {
	if { $count >= 600 } {
	    pass $msg
	} else {
	    fail $msg
	}
    }
}    

#
# OK, kill 'em all...
#

gdb_test "kill" "" "kill all one with many checkpoints" \
    "Kill the program being debugged.*y or n. $" "y"

# Restore old timeout
set timeout $prev_timeout
verbose "Timeout now $timeout sec."

#
# Finished: cleanup
#

remote_exec build "rm -f pi.txt"