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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
|
# Copyright 2009-2025 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/>.
# This file tests various scenarios involving multiple inferiors
# and the checkpoint command.
# Checkpoint support works only on Linux.
require {istarget "*-*-linux*"}
# Checkpoint support is implemented for the (Linux) native target.
require gdb_protocol_is_native
set checkpoints_header_re " +Id +Active Target Id +Frame.*?"
set proc_re "(?:process $::decimal)"
set ckpt_re "Checkpoint"
set main_proc "\\(main process\\)"
set hello_c "hello\\.c"
set goodbye_c "goodbye\\.c"
set hangout_c "hangout\\.c"
set testfile "checkpoint-multi"
set exec1 "hello"
set srcfile1 ${exec1}.c
set binfile1 [standard_output_file ${exec1}]
set exec2 "goodbye"
set srcfile2 ${exec2}.c
set binfile2 [standard_output_file ${exec2}]
set exec3 "hangout"
set srcfile3 ${exec3}.c
set binfile3 [standard_output_file ${exec3}]
if { [build_executable ${testfile}.exp ${exec1} "${srcfile1}" {debug}] == -1 } {
return -1
}
if { [build_executable ${testfile}.exp ${exec2} "${srcfile2}" {debug}] == -1 } {
return -1
}
if { [build_executable ${testfile}.exp ${exec3} "${srcfile3}" {debug}] == -1 } {
return -1
}
# Start two inferiors, place a checkpoint on inferior 2, but switch
# back to inferior 1.
proc start_2_inferiors_checkpoint_on_inf_2 {} {
clean_restart $::exec1
# Start inferior 1.
if {[gdb_start_cmd] < 0} {
fail "start first inferior"
} else {
gdb_test "" "main.*" "start first inferior"
}
# Add a new inferior and exec into it.
gdb_test "add-inferior -exec $::binfile2" \
"Added inferior 2.*" \
"add inferior 2 with -exec $::exec2"
# Check that we have multiple inferiors.
gdb_test "info inferiors" \
"Executable.*$::exec1.*$::exec2.*"
# Switch to inferior 2.
gdb_test "inferior 2" \
"Switching to inferior 2.*$::exec2.*"
# Start inferior 2:
if {[gdb_start_cmd] < 0} {
fail "start second inferior"
} else {
gdb_test "" "main.*" "start second inferior"
}
# Set a checkpoint in inferior 2
gdb_test "checkpoint" "$::ckpt_re 2\\.1: fork returned pid $::decimal.*"
# Step one line in inferior 2.
gdb_test "step" "glob = 46;"
# Switch back to inferior 1.
gdb_test "inferior 1" "Switching to inferior 1.*$::exec1.*"
}
# Start two inferiors, place a checkpoint on inferior 2, but switch
# back to inferior 1. This is like the one above, except that it
# swaps the executables loaded into inferior 1 and inferior 2. This
# is important for being able to test "continue to exit". (Because...
# hello.c has an infinite loop, but goodbye.c doesn't. In order to
# test "continue to exit", we need to continue in an executable which
# will actually exit.)
proc start_2_inferiors_checkpoint_on_inf_2_alt {} {
clean_restart $::exec2
# Start inferior 1.
if {[gdb_start_cmd] < 0} {
fail "start first inferior"
} else {
gdb_test "" "main.*" "start first inferior"
}
# Add a new inferior and exec exec1 into it.
gdb_test "add-inferior -exec $::binfile1" \
"Added inferior 2.*" \
"add inferior 2 with -exec $::exec1"
# Check that we have two inferiors.
gdb_test "info inferiors" \
"Executable.*$::exec2.*$::exec1.*"
# Switch to inferior 2.
gdb_test "inferior 2" \
"Switching to inferior 2.*$::exec1.*"
# Start inferior 2:
if {[gdb_start_cmd] < 0} {
fail "start second inferior"
} else {
gdb_test "" "main.*" "start second inferior"
}
# Set a checkpoint in inferior 2
gdb_test "checkpoint" "$::ckpt_re 2\\.1: fork returned pid $::decimal.*"
# next one line in inferior 2.
gdb_test "next" "bar\\(\\).*"
# Switch back to inferior 1.
gdb_test "inferior 1" "Switching to inferior 1.*$::exec2.*"
}
with_test_prefix "check detach on non-checkpointed inferior" {
start_2_inferiors_checkpoint_on_inf_2
gdb_test "detach" "Detaching from program.*$::exec1.*Inferior 1.*detached.*"
}
with_test_prefix "check kill on non-checkpointed inferior" {
start_2_inferiors_checkpoint_on_inf_2
gdb_test "kill" "" "kill non-checkpointed inferior" \
"Kill the program being debugged.*y or n. $" "y"
}
with_test_prefix "check restart 0 on non-checkpointed inferior" {
start_2_inferiors_checkpoint_on_inf_2
gdb_test "restart 0" "Inferior 1 has no checkpoints"
gdb_test "restart 2.0" "Switching to inferior 2.*?goodbye.*?#0 +mailand .*?glob = 46;.*"
}
with_test_prefix "check restart 1 on non-checkpointed inferior" {
start_2_inferiors_checkpoint_on_inf_2
gdb_test "restart 1" "Inferior 1 has no checkpoints"
gdb_test "restart 2.1" "Switching to inferior 2.*?goodbye.*?#0 +main .*?mailand\\(\\);.*"
}
with_test_prefix "check continue to exit on non-checkpointed inferior" {
start_2_inferiors_checkpoint_on_inf_2_alt
gdb_test "continue" "Inferior 1.*? exited normally.*"
}
with_test_prefix "two inferiors with checkpoints" {
start_2_inferiors_checkpoint_on_inf_2
with_test_prefix "one checkpoint" {
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" +2\\.0 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" +2\\.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?"]
}
with_test_prefix "two checkpoints" {
gdb_test "checkpoint" "$ckpt_re 1\\.1: fork returned pid $::decimal.*" \
"checkpoint in inferior 1"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
"\\* 1\\.0 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.0 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?"]
}
# Note: No switching is done here since checkpoint 0 is the active one.
gdb_test "restart 0" "main.*?$hello_c.*?alarm \\(240\\);"
gdb_test "restart 2.0" \
"\\\[Switching to inferior 2.*?mailand.*?glob = 46;.*"
gdb_test "next" "\}"
with_test_prefix "restart 1" {
gdb_test "restart 1" "^Switching to $proc_re.*?#0 main \\(\\) at.*?$goodbye_c.*mailand\\(\\);"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.0 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
"\\* 2\\.1 y +$proc_re +at $::hex, file.*?$goodbye_c.*?"]
}
with_test_prefix "info checkpoints twice in a row" {
# Doing "info_checkpoints" twice in a row might seem pointless,
# but during work on making the checkpoint code inferior aware,
# there was a point at which doing it twice in a row did not
# produce the same output.
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.0 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
"\\* 2\\.1 y +$proc_re +at $::hex, file.*?$goodbye_c.*?"]
}
with_test_prefix "restart 0" {
# Switch back to checkpoint 0; again, there should be no
# "Switching to inferior" message.
gdb_test "restart 0" \
"^Switching to $proc_re.*?#0 mailand \\(\\) at.*?$goodbye_c.*\}"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
"\\* 2\\.0 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?"]
}
# Try switching to invalid checkpoints:
with_test_prefix "invalid checkpoints" {
gdb_test "restart 3" "Invalid checkpoint number 3 for inferior 2"
gdb_test "restart 2" "Invalid checkpoint number 2 for inferior 2"
gdb_test "restart -1" "Checkpoint number must be a non-negative integer"
gdb_test "restart 2.3" "Invalid checkpoint number 3 for inferior 2"
gdb_test "restart 3.0" "No inferior number '3'"
gdb_test "restart 1.2" "Invalid checkpoint number 2 for inferior 1"
gdb_test "restart 1.3" "Invalid checkpoint number 3 for inferior 1"
gdb_test "restart 1.-1" "Checkpoint number must be a non-negative integer"
gdb_test "restart -1.0" "Inferior number must be a positive integer"
}
with_test_prefix "restart 1.1" {
# Switch to checkpoint 1.1; this time, we should see a "Switching to
# inferior" message.
gdb_test "restart 1.1" \
"\\\[Switching to inferior 1.*?main.*?$hello_c.*?alarm \\(240\\);"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
"\\* 1\\.1 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.0 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?"]
}
with_test_prefix "restart 2.1" {
gdb_test "restart 2.1" \
"Switching to inferior 2.*?#0 main \\(\\) at.*?$goodbye_c.*mailand\\(\\);"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.0 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
"\\* 2\\.1 y +$proc_re +at $::hex, file.*?$goodbye_c.*?"]
}
with_test_prefix "second checkpoint in inferior 2" {
gdb_test "checkpoint" "$ckpt_re 2\\.2: fork returned pid $::decimal.*"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.0 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
"\\* 2\\.1 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.2 n +$proc_re +at $::hex, file.*?$goodbye_c.*?"]
}
with_test_prefix "third checkpoint in inferior 2" {
gdb_test "checkpoint" "$ckpt_re 2.3: fork returned pid $::decimal.*"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.0 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
"\\* 2\\.1 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.2 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.3 n +$proc_re +at $::hex, file.*?$goodbye_c.*?"]
}
with_test_prefix "continue to exit in checkpoint 2.1" {
gdb_test "continue" \
"Inferior 2 \\(process $decimal\\) exited normally.*?Switching to $proc_re.*?"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.0 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.2 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
"\\* 2\\.3 y +$proc_re +at $::hex, file.*?$goodbye_c.*?"]
}
with_test_prefix "continue to exit in checkpoint 2.3" {
gdb_test "continue" \
"Inferior 2 \\(process $decimal\\) exited normally.*?Switching to process $decimal.*?"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.0 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
"\\* 2\\.2 y +$proc_re +at $::hex, file.*?$goodbye_c.*?"]
}
with_test_prefix "continue to exit in checkpoint 2.2" {
gdb_test "continue" \
"Inferior 2 \\(process $decimal\\) exited normally.*?Switching to process $decimal.*?"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 y +$proc_re +at $::hex, file.*?$hello_c.*?"]
}
with_test_prefix "new checkpoints in inferior 2" {
gdb_test "checkpoint" "$ckpt_re 2.1: fork returned pid $::decimal.*" \
"checkpoint 2.1"
gdb_test "checkpoint" "$ckpt_re 2.2: fork returned pid $::decimal.*" \
"checkpoint 2.2"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
"\\* 2\\.0 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.2 n +$proc_re +at $::hex, file.*?$goodbye_c.*?"]
}
with_test_prefix "delete checkpoint 2.0" {
gdb_test "delete checkpoint 2.0" \
"Cannot delete active checkpoint" \
"failed attempt to delete active checkpoint 2.0"
gdb_test "restart 2.1" \
"^Switching to process.*?#0 mailand \\(\\) at.*?$goodbye_c.*\}"
gdb_test "delete checkpoint 2.0" \
"Killed process $::decimal"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
"\\* 2\\.1 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.2 n +$proc_re +at $::hex, file.*?$goodbye_c.*?"]
}
with_test_prefix "delete checkpoint 2.2" {
gdb_test "delete checkpoint 2.2" \
"Killed process $::decimal"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 y +$proc_re +at $::hex, file.*?$hello_c.*?"]
}
with_test_prefix "new checkpoint in inferior 2" {
gdb_test "checkpoint" "$ckpt_re 2.1: fork returned pid $::decimal.*"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
"\\* 2\\.0 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?"]
}
with_test_prefix "switch to inferior 1" {
gdb_test "inferior 1" "Switching to inferior 1.*?alarm \\(240\\);"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
"\\* 1\\.1 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.0 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?"]
}
with_test_prefix "kill inferior 1" {
gdb_test "kill" "\\\[Inferior 1 \\(process $::decimal\\) killed\\\]" \
"kill inferior 1" \
"Kill the program being debugged.*y or n. $" "y"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 2\\.0 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?"]
}
with_test_prefix "start inferior 1 again" {
gdb_test "checkpoint" "The program is not being run\\." \
"checkpoint in non-running inferior"
gdb_test "start" "Starting program.*?hello.*?alarm \\(240\\);"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 2\\.0 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?"]
}
with_test_prefix "checkpoint 1.1" {
gdb_test "checkpoint" "$ckpt_re 1.1: fork returned pid $::decimal.*" \
"second checkpoint in inferior 1"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
"\\* 1\\.0 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.0 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?"]
}
}
with_test_prefix "three inferiors with checkpoints" {
start_2_inferiors_checkpoint_on_inf_2
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 2\\.0 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?"]
with_test_prefix "add third inferior" {
# Add a third inferior and exec into it.
gdb_test "add-inferior -exec $::binfile3" \
"Added inferior 3.*" \
"add inferior 3 with -exec $::exec3"
# Check that we have three inferiors.
gdb_test "info inferiors" \
"Executable.*?\\* 1 .*?$::exec1.*? 2 .*?$::exec2.*? 3 .*?$::exec3.*?" \
"check for three inferiors"
# Switch to inferior 3.
gdb_test "inferior 3" \
"Switching to inferior 3.*$::exec3.*"
# Start inferior 2:
if {[gdb_start_cmd] < 0} {
fail "start third inferior"
} else {
gdb_test "" "main.*" "start third inferior"
}
gdb_test "checkpoint" "$ckpt_re 3\\.1: fork returned pid $::decimal.*"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 2\\.0 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
"\\* 3\\.0 y +$proc_re +at $::hex, file.*?$hangout_c.*?" \
" 3\\.1 n +$proc_re +at $::hex, file.*?$hangout_c.*?"]
}
with_test_prefix "make checkpoint in inferior 1" {
gdb_test "inferior 1" "Switching to inferior 1.*?alarm \\(240\\);"
gdb_test "checkpoint" "$ckpt_re 1\\.1: fork returned pid $::decimal.*"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
"\\* 1\\.0 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.0 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 3\\.0 y +$proc_re +at $::hex, file.*?$hangout_c.*?" \
" 3\\.1 n +$proc_re +at $::hex, file.*?$hangout_c.*?"]
}
with_test_prefix "restart 2.1" {
gdb_test "restart 2.1" \
"Switching to inferior 2.*?#0 main \\(\\) at.*?$goodbye_c.*mailand\\(\\);"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.0 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
"\\* 2\\.1 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 3\\.0 y +$proc_re +at $::hex, file.*?$hangout_c.*?" \
" 3\\.1 n +$proc_re +at $::hex, file.*?$hangout_c.*?"]
}
with_test_prefix "next and make new checkpoint" {
gdb_test "next" "foo\\(glob\\);"
gdb_test "checkpoint" "$ckpt_re 2\\.2: fork returned pid $::decimal.*"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.0 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
"\\* 2\\.1 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.2 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 3\\.0 y +$proc_re +at $::hex, file.*?$hangout_c.*?" \
" 3\\.1 n +$proc_re +at $::hex, file.*?$hangout_c.*?"]
}
with_test_prefix "switch to inferior 3 for upcoming kill" {
gdb_test "inferior 3" "Switching to inferior 3.*?alarm \\(30\\);"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.0 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.1 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.2 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
"\\* 3\\.0 y +$proc_re +at $::hex, file.*?$hangout_c.*?" \
" 3\\.1 n +$proc_re +at $::hex, file.*?$hangout_c.*?"]
}
with_test_prefix "kill inferior 3" {
gdb_test "kill" "\\\[Inferior 3 \\(process $::decimal\\) killed\\\]" \
"kill inferior 3" \
"Kill the program being debugged.*y or n. $" "y"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.0 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.1 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.2 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" ]
}
with_test_prefix "delete checkpoint 2.0" {
gdb_test "delete checkpoint 0" \
"Inferior 3 has no checkpoints"
gdb_test "delete checkpoint 2.0" \
"Killed process $::decimal"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.1 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.2 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" ]
}
with_test_prefix "restart 2.2" {
gdb_test "restart 2.2" \
"Switching to inferior 2.*?#0 main \\(\\) at.*?$goodbye_c.*foo\\(glob\\);"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
"\\* 2\\.2 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" ]
}
with_test_prefix "switch to non-running inferior 3" {
gdb_test "inferior 3" "\\\[Switching to inferior 3 \\\[<null>\\\] \\(.*?$::exec3\\)\\\]"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.2 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" ]
}
with_test_prefix "restart inferior 3 and make new checkpoints" {
gdb_test "start" "Starting program.*?hangout.*?alarm \\(30\\);"
gdb_test "checkpoint" \
"$ckpt_re 3\\.1: fork returned pid $::decimal.*" \
"checkpoint 3.1"
gdb_test "checkpoint" \
"$ckpt_re 3\\.2: fork returned pid $::decimal.*" \
"checkpoint 3.2"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.2 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
"\\* 3\\.0 y +$proc_re +at $::hex, file.*?$hangout_c.*?" \
" 3\\.1 n +$proc_re +at $::hex, file.*?$hangout_c.*?" \
" 3\\.2 n +$proc_re +at $::hex, file.*?$hangout_c.*?"]
}
with_test_prefix "delete checkpoint 3.1" {
gdb_test "delete checkpoint 1" \
"Killed process $::decimal"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.2 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
"\\* 3\\.0 y +$proc_re +at $::hex, file.*?$hangout_c.*?" \
" 3\\.2 n +$proc_re +at $::hex, file.*?$hangout_c.*?"]
}
with_test_prefix "attempt to delete active checkpoint in non-current inferior" {
# Switch to inferior 1, add another checkpoint - so that there
# are three of them in inferior 1 - then switch back to
# inferior 3 and delete active checkpoint in inferior 1.
# Then, switch to inferior 1 and attempt to add another
# checkpoint. During development, a "Cannot access memory at
# address ..." message was seen. This was a bug - there were
# several problems - but one of them was that the checkpoint in
# question was an "active" checkpoint. The fix was to
# disallow this case.
gdb_test "inferior 1" "Switching to inferior 1.*?alarm \\(240\\);"
gdb_test "checkpoint" "$ckpt_re 1\\.2: fork returned pid $::decimal.*"
gdb_test "inferior 3" "Switching to inferior 3.*?alarm \\(30\\);"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.2 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.2 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
"\\* 3\\.0 y +$proc_re +at $::hex, file.*?$hangout_c.*?" \
" 3\\.2 n +$proc_re +at $::hex, file.*?$hangout_c.*?"]
# Check that deleting active checkpoints in other (non-current)
# inferiors is disallowed.
gdb_test "delete checkpoint 1.0" \
"Cannot delete active checkpoint"
}
with_test_prefix "delete non-active checkpoint in non-current inferior" {
# But deleting non-active checkpoints, even in other inferiors,
# should work.
gdb_test "delete checkpoint 1.1" \
"Killed process $::decimal"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.2 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.2 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
"\\* 3\\.0 y +$proc_re +at $::hex, file.*?$hangout_c.*?" \
" 3\\.2 n +$proc_re +at $::hex, file.*?$hangout_c.*?"]
}
with_test_prefix "switch to inferior 1" {
gdb_test "inferior 1" "Switching to inferior 1.*?alarm \\(240\\);"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
"\\* 1\\.0 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.2 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.2 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 3\\.0 y +$proc_re +at $::hex, file.*?$hangout_c.*?" \
" 3\\.2 n +$proc_re +at $::hex, file.*?$hangout_c.*?"]
}
with_test_prefix "checkpoint 1.3" {
gdb_test "checkpoint" "$ckpt_re 1\\.3: fork returned pid $::decimal.*" \
"third checkpoint in inferior 1"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
"\\* 1\\.0 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.2 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.3 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.2 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 3\\.0 y +$proc_re +at $::hex, file.*?$hangout_c.*?" \
" 3\\.2 n +$proc_re +at $::hex, file.*?$hangout_c.*?"]
}
with_test_prefix "attempt to remove active but not current inferior" {
gdb_test "x/i \$pc" "=> $::hex <main.*"
gdb_test "remove-inferior 3" \
"warning: Can not remove active inferior 3\."
}
}
with_test_prefix "background execution" {
start_2_inferiors_checkpoint_on_inf_2
with_test_prefix "one checkpoint" {
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 2.0 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?"]
}
with_test_prefix "two checkpoints" {
gdb_test "checkpoint" "$ckpt_re 1\\.1: fork returned pid $::decimal.*" \
"checkpoint in inferior 1"
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
"\\* 1\\.0 y +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 1\\.1 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.0 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?"]
}
with_test_prefix "background continue hello" {
gdb_test "continue &" "Continuing\."
gdb_test "info checkpoints" \
[multi_line \
"\\* 1\\.0 y +$proc_re \\(running\\)" \
" 1\\.1 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.0 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?"]
}
with_test_prefix "fail to switch to inferior 2 w/ 1 in background" {
gdb_test "restart 2.1" "Cannot execute this command while the selected thread is running."
# Should be no change from earlier output.
gdb_test "info checkpoints" \
[multi_line \
"\\* 1\\.0 y +$proc_re \\(running\\)" \
" 1\\.1 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.0 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?"]
}
with_test_prefix "switch to inferior 2" {
set msg "stop thread"
gdb_test_multiple "interrupt" $msg {
-re "$gdb_prompt " {
gdb_test_multiple "" $msg {
-re "Thread 1\\.1 \"hello\" received signal SIGINT, Interrupt\\." {
pass $gdb_test_name
}
}
}
}
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
"\\* 1\\.0 y +$proc_re +at $::hex,.*" \
" 1\\.1 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.0 y +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
" 2\\.1 n +$proc_re +at $::hex, file.*?$goodbye_c.*?"]
gdb_test "restart 2.1" "Switching to inferior 2.*?goodbye.*?#0 +main .*?mailand\\(\\);.*"
}
with_test_prefix "after restart 2.1" {
gdb_test "info checkpoints" \
[multi_line \
"$checkpoints_header_re" \
" 1\\.0 y +$proc_re +at $::hex,.*" \
" 1\\.1 n +$proc_re +at $::hex, file.*?$hello_c.*?" \
" 2\\.0 n +$proc_re +at $::hex, file.*?$goodbye_c.*?" \
"\\* 2\\.1 y +$proc_re +at $::hex, file.*?$goodbye_c.*?"]
}
}
|