03bf8449cf87694c0153e2bbb2ff476cccb1e342
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.multi / multi-kill.exp
1 # This testcase is part of GDB, the GNU debugger.
2
3 # Copyright 2020 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 if {[use_gdb_stub]} {
28 return 0
29 }
30
31 if {[build_executable "failed to prepare" $testfile $srcfile {debug}]} {
32 return -1
33 }
34
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}
40 }
41
42 # Wrap the entire test in a namespace to avoid contaminating other tests.
43 namespace eval $testfile {
44
45 # Start inferior NUM and record its PID in the TESTPID array.
46
47 proc start_inferior {num testpid} {
48 with_test_prefix "start_inferior $num" {
49 upvar $testpid tpid
50 global binfile srcfile
51
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"
57 }
58
59 gdb_load $binfile
60
61 gdb_breakpoint "initialized" {temporary}
62 gdb_run_cmd
63 gdb_test "" ".*reakpoint .*, initialized .*${srcfile}.*" "run"
64
65 set tpid($num) [get_integer_valueof "pid" -1]
66 if {$tpid($num) == -1} {
67 return -1
68 }
69
70 return 0
71 }
72 }
73
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
77
78 # The array holding each inferior's PID, indexed by inferior number.
79 array set testpid {}
80
81 for {set i 1} {$i <= $NUM_INFS} {incr i} {
82 if {[start_inferior $i testpid] < 0} {
83 return -1
84 }
85 }
86
87 # We want to continue all processes.
88 gdb_test_no_output "set schedule-multiple on"
89
90 # Resume, but then kill all from outside.
91 gdb_test_multiple "continue" "continue processes" {
92 -re "Continuing.\[\r\n\]+" {
93 # Kill all processes at once.
94
95 set kill_cmd "kill -9"
96 for {set i 1} {$i <= $NUM_INFS} {incr i} {
97 append kill_cmd " $testpid($i)"
98 }
99
100 remote_exec target $kill_cmd
101 exp_continue
102 }
103 -re "Program terminated with signal.*$gdb_prompt $" {
104 pass $gdb_test_name
105 }
106 }
107
108 # Check that "continue" collects the process kill event, as many times
109 # as we have inferiors left.
110
111 for {set i 2} {$i <= $NUM_INFS} {incr i} {
112 with_test_prefix "inf $i" {
113 set live_inferior ""
114
115 # Pick any live inferior.
116 gdb_test_multiple "info inferiors" "" {
117 -re "($decimal) *process.*$gdb_prompt $" {
118 set live_inferior $expect_out(1,string)
119 }
120 }
121
122 if {$live_inferior == ""} {
123 return -1
124 }
125
126 gdb_test "inferior $live_inferior" \
127 ".*Switching to inferior $live_inferior.*" \
128 "switch to inferior"
129
130 gdb_test "continue" \
131 "Program terminated with signal SIGKILL, .*" \
132 "continue to SIGKILL"
133 }
134 }
135
136 }
This page took 0.034971 seconds and 3 git commands to generate.