]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.multi/multi-kill.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.multi / multi-kill.exp
1 # This testcase is part of GDB, the GNU debugger.
2
3 # Copyright 2020-2024 Free Software Foundation, Inc.
4
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.
9 #
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.
14 #
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/>.
17
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.
24
25 standard_testfile
26
27 require !use_gdb_stub
28
29 if {[build_executable "failed to prepare" $testfile $srcfile {debug}]} {
30 return -1
31 }
32
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}
38 }
39
40 # Wrap the entire test in a namespace to avoid contaminating other tests.
41 namespace eval $testfile {
42
43 # Start inferior NUM and record its PID in the TESTPID array.
44
45 proc start_inferior {num} {
46 with_test_prefix "start_inferior $num" {
47 variable testpid
48 global binfile srcfile
49
50 if {$num != 1} {
51 gdb_test "add-inferior" "Added inferior .*" \
52 "add empty inferior"
53 gdb_test "inferior $num" "Switching to inferior .*" \
54 "switch to inferior"
55 }
56
57 gdb_load $binfile
58
59 gdb_breakpoint "initialized" {temporary}
60 gdb_run_cmd
61 gdb_test "" ".*reakpoint .*, initialized .*${srcfile}.*" "run"
62
63 set testpid($num) [get_integer_valueof "pid" -1]
64 if {$testpid($num) == -1} {
65 return -1
66 }
67
68 return 0
69 }
70 }
71
72 # Sufficient inferiors to make sure that at least some other inferior
73 # is killed while we're handling a killed event.
74 set NUM_INFS 10
75
76 # The array holding each inferior's PID, indexed by inferior number.
77 variable testpid
78 array set testpid {}
79
80 for {set i 1} {$i <= $NUM_INFS} {incr i} {
81 if {[start_inferior $i] < 0} {
82 return -1
83 }
84 }
85
86 # We want to continue all processes.
87 gdb_test_no_output "set schedule-multiple on"
88
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.
93
94 set kill_cmd "kill -9"
95 for {set i 1} {$i <= $NUM_INFS} {incr i} {
96 append kill_cmd " $testpid($i)"
97 }
98
99 remote_exec target $kill_cmd
100 exp_continue
101 }
102 -re "Program terminated with signal.*$gdb_prompt $" {
103 pass $gdb_test_name
104 }
105 }
106
107 # Check that "continue" collects the process kill event, as many times
108 # as we have inferiors left.
109
110 for {set i 2} {$i <= $NUM_INFS} {incr i} {
111 with_test_prefix "inf $i" {
112 set live_inferior ""
113
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)
118 }
119 }
120
121 if {$live_inferior == ""} {
122 return -1
123 }
124
125 gdb_test "inferior $live_inferior" \
126 ".*Switching to inferior $live_inferior.*" \
127 "switch to inferior"
128
129 gdb_test "continue" \
130 "Program terminated with signal SIGKILL, .*" \
131 "continue to SIGKILL"
132 }
133 }
134
135 }