1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2020-2024 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.
29 if {[build_executable "failed to prepare" $testfile $srcfile {debug}]} {
33 # We are testing GDB's ability to stop all threads.
34 # Hence, go with the all-stop-on-top-of-non-stop mode.
35 save_vars { GDBFLAGS } {
36 append GDBFLAGS " -ex \"maint set target-non-stop on\""
37 clean_restart ${binfile}
40 # Wrap the entire test in a namespace to avoid contaminating other tests.
41 namespace eval $testfile {
43 # Start inferior NUM and record its PID in the TESTPID array.
45 proc start_inferior {num} {
46 with_test_prefix "start_inferior $num" {
48 global binfile srcfile
51 gdb_test "add-inferior" "Added inferior .*" \
53 gdb_test "inferior $num" "Switching to inferior .*" \
59 gdb_breakpoint "initialized" {temporary}
61 gdb_test "" ".*reakpoint .*, initialized .*${srcfile}.*" "run"
63 set testpid($num) [get_integer_valueof "pid" -1]
64 if {$testpid($num) == -1} {
72 # Sufficient inferiors to make sure that at least some other inferior
73 # is killed while we're handling a killed event.
76 # The array holding each inferior's PID, indexed by inferior number.
80 for {set i 1} {$i <= $NUM_INFS} {incr i} {
81 if {[start_inferior $i] < 0} {
86 # We want to continue all processes.
87 gdb_test_no_output "set schedule-multiple on"
89 # Resume, but then kill all from outside.
90 gdb_test_multiple "continue" "continue processes" {
91 -re "Continuing.\[\r\n\]+" {
92 # Kill all processes at once.
94 set kill_cmd "kill -9"
95 for {set i 1} {$i <= $NUM_INFS} {incr i} {
96 append kill_cmd " $testpid($i)"
99 remote_exec target $kill_cmd
102 -re "Program terminated with signal.*$gdb_prompt $" {
107 # Check that "continue" collects the process kill event, as many times
108 # as we have inferiors left.
110 for {set i 2} {$i <= $NUM_INFS} {incr i} {
111 with_test_prefix "inf $i" {
114 # Pick any live inferior.
115 gdb_test_multiple "info inferiors" "" {
116 -re "($decimal) *process.*$gdb_prompt $" {
117 set live_inferior $expect_out(1,string)
121 if {$live_inferior == ""} {
125 gdb_test "inferior $live_inferior" \
126 ".*Switching to inferior $live_inferior.*" \
129 gdb_test "continue" \
130 "Program terminated with signal SIGKILL, .*" \
131 "continue to SIGKILL"