Rename gdb/ChangeLog to gdb/ChangeLog-2021
[binutils-gdb.git] / gdb / testsuite / gdb.multi / multi-kill.exp
blob8882781c693e6dd6071201f6b460609b78bc511e
1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2020-2021 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Test receiving TARGET_WAITKIND_SIGNALLED events from multiple
19 # inferiors. In all stop-mode, upon receiving the exit event from one
20 # of the inferiors, GDB will try to stop the other inferior, too. So,
21 # a stop request will be sent. Receiving a TARGET_WAITKIND_SIGNALLED
22 # status kind as a response to that stop request instead of a
23 # TARGET_WAITKIND_STOPPED should be handled by GDB without problems.
25 standard_testfile
27 if {[use_gdb_stub]} {
28 return 0
31 if {[build_executable "failed to prepare" $testfile $srcfile {debug}]} {
32 return -1
35 # We are testing GDB's ability to stop all threads.
36 # Hence, go with the all-stop-on-top-of-non-stop mode.
37 save_vars { GDBFLAGS } {
38 append GDBFLAGS " -ex \"maint set target-non-stop on\""
39 clean_restart ${binfile}
42 # Wrap the entire test in a namespace to avoid contaminating other tests.
43 namespace eval $testfile {
45 # Start inferior NUM and record its PID in the TESTPID array.
47 proc start_inferior {num} {
48 with_test_prefix "start_inferior $num" {
49 variable testpid
50 global binfile srcfile
52 if {$num != 1} {
53 gdb_test "add-inferior" "Added inferior .*" \
54 "add empty inferior"
55 gdb_test "inferior $num" "Switching to inferior .*" \
56 "switch to inferior"
59 gdb_load $binfile
61 gdb_breakpoint "initialized" {temporary}
62 gdb_run_cmd
63 gdb_test "" ".*reakpoint .*, initialized .*${srcfile}.*" "run"
65 set testpid($num) [get_integer_valueof "pid" -1]
66 if {$testpid($num) == -1} {
67 return -1
70 return 0
74 # Sufficient inferiors to make sure that at least some other inferior
75 # is killed while we're handling a killed event.
76 set NUM_INFS 10
78 # The array holding each inferior's PID, indexed by inferior number.
79 variable testpid
80 array set testpid {}
82 for {set i 1} {$i <= $NUM_INFS} {incr i} {
83 if {[start_inferior $i] < 0} {
84 return -1
88 # We want to continue all processes.
89 gdb_test_no_output "set schedule-multiple on"
91 # Resume, but then kill all from outside.
92 gdb_test_multiple "continue" "continue processes" {
93 -re "Continuing.\[\r\n\]+" {
94 # Kill all processes at once.
96 set kill_cmd "kill -9"
97 for {set i 1} {$i <= $NUM_INFS} {incr i} {
98 append kill_cmd " $testpid($i)"
101 remote_exec target $kill_cmd
102 exp_continue
104 -re "Program terminated with signal.*$gdb_prompt $" {
105 pass $gdb_test_name
109 # Check that "continue" collects the process kill event, as many times
110 # as we have inferiors left.
112 for {set i 2} {$i <= $NUM_INFS} {incr i} {
113 with_test_prefix "inf $i" {
114 set live_inferior ""
116 # Pick any live inferior.
117 gdb_test_multiple "info inferiors" "" {
118 -re "($decimal) *process.*$gdb_prompt $" {
119 set live_inferior $expect_out(1,string)
123 if {$live_inferior == ""} {
124 return -1
127 gdb_test "inferior $live_inferior" \
128 ".*Switching to inferior $live_inferior.*" \
129 "switch to inferior"
131 gdb_test "continue" \
132 "Program terminated with signal SIGKILL, .*" \
133 "continue to SIGKILL"