Always pass signals to the right thread
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / signal-command-multiple-signals-pending.exp
1 # Copyright (C) 2014 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>. */
15
16 # Test that "signal FOO" behaves correctly when we have multiple
17 # threads that have stopped for a signal.
18
19 if [target_info exists gdb,nosignals] {
20 verbose "Skipping ${testfile}.exp because of nosignals."
21 return -1
22 }
23
24 standard_testfile
25
26 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
27 executable { debug }] != "" } {
28 return -1
29 }
30
31 # Run the test proper. SCHEDLOCK indicates which variant (around
32 # scheduler-locking) of the test to perform.
33
34 proc test { schedlock } {
35 global srcfile binfile
36
37 with_test_prefix "schedlock $schedlock" {
38 clean_restart ${binfile}
39
40 if ![runto_main] then {
41 fail "Can't run to main"
42 return 0
43 }
44
45 gdb_test "handle SIGUSR1 stop print pass"
46 gdb_test "handle SIGUSR2 stop print pass"
47
48 gdb_test "break all_threads_started" "Breakpoint .* at .*$srcfile.*"
49 gdb_test "continue" "all_threads_started.*"
50
51 # Using schedlock, let the main thread queue a signal for each
52 # non-main thread.
53 gdb_test_no_output "set scheduler-locking on"
54
55 gdb_test "break all_threads_signalled" "Breakpoint .* at .*$srcfile.*"
56 gdb_test "continue" "all_threads_signalled.*"
57
58 gdb_test "info threads" "\\\* 1\[ \t\]+Thread.*" "thread 1 selected"
59
60 # With schedlock still enabled, let each thread report its
61 # signal.
62
63 gdb_test "thread 3" "Switching to thread 3.*"
64 gdb_test "continue" "Program received signal SIGUSR2.*" "stop with SIGUSR2"
65 gdb_test "thread 2" "Switching to thread 2.*"
66 gdb_test "continue" "Program received signal SIGUSR1.*" "stop with SIGUSR1"
67
68 gdb_test "break handler_sigusr1" "Breakpoint .* at .*$srcfile.*"
69 gdb_test "break handler_sigusr2" "Breakpoint .* at .*$srcfile.*"
70
71 set handler_re "Breakpoint .*, handler_sigusr. \\(sig=.*\\) at .*"
72
73 # Now test the "signal" command with either scheduler locking
74 # enabled or disabled.
75
76 if { $schedlock == "off" } {
77 # With scheduler locking off, switch to the main thread
78 # and issue "signal 0". "signal 0" should then warn that
79 # two threads have signals that will be delivered. When
80 # we let the command proceed, a signal should be
81 # delivered, and thus the corresponding breakpoint in the
82 # signal handler should trigger.
83
84 gdb_test_no_output "set scheduler-locking off"
85 gdb_test "thread 1" "Switching to thread 1.*"
86
87 set queried 0
88 set test "signal command queries"
89 gdb_test_multiple "signal 0" $test {
90 -re "stopped with.*stopped with.*stopped with.*Continue anyway.*y or n. $" {
91 fail "$test (too many threads noted)"
92 set queried 1
93 }
94 -re "stopped with signal SIGUSR.*\r\nContinuing .*still deliver .*Continue anyway.*y or n. $" {
95 pass $test
96 set queried 1
97 }
98 -re "Continue anyway.*y or n. $" {
99 fail "$test (no threads noted)"
100 set queried 1
101 }
102 }
103
104 # Continuing should stop in one of the signal handlers.
105 # Which thread runs first is not determinate.
106 if {$queried} {
107 gdb_test "y" "$handler_re" "one signal delivered"
108 }
109
110 # Continuing a second time should stop in the other
111 # handler.
112 with_test_prefix "second signal" {
113 gdb_test "continue" "$handler_re" "signal delivered"
114 }
115 } else {
116 # With scheduler locking on, stay with thread 2 selected,
117 # and try to deliver its signal explicitly. The "signal"
118 # command should then warn that one other thread has a
119 # signal that will be delivered. When we let the command
120 # proceed, the current thread's signal should be
121 # delivered, and thus the corresponding breakpoint in the
122 # signal handler should trigger.
123 gdb_test "signal SIGUSR1" \
124 "Breakpoint .*, handler_sigusr1 \\(sig=.*\\) at .*" \
125 "signal command does not query, signal delivered"
126
127 with_test_prefix "second signal" {
128 # The other thread had stopped for a signal too, and
129 # it wasn't resumed yet. Disabling schedlock and
130 # trying "signal 0" from the main thread should warn
131 # again.
132 gdb_test_no_output "set scheduler-locking off"
133
134 set queried 0
135 set test "signal command queries"
136 gdb_test_multiple "signal 0" $test {
137 -re "stopped with.*stopped with.*Continue anyway.*y or n. $" {
138 fail "$test (too many threads noted)"
139 set queried 1
140 }
141 -re "stopped with signal SIGUSR.*\r\nContinuing .*still deliver .*Continue anyway.*y or n. $" {
142 pass $test
143 set queried 1
144 }
145 -re "Continue anyway.*y or n. $" {
146 fail "$test (no threads noted)"
147 set queried 1
148 }
149 }
150
151 if {$queried} {
152 gdb_test "y" "Breakpoint .*, handler_sigusr2 \\(sig=.*\\) at .*" "signal delivered"
153 }
154 }
155 }
156
157 # Both threads got their signal. Continuing again should
158 # neither intercept nor deliver any other signal.
159 gdb_test "b end" "Breakpoint .* at .*$srcfile.*"
160 gdb_test "continue" "end .*" "no more signals"
161 }
162 }
163
164 foreach schedlock {"off" "on"} {
165 test $schedlock
166 }
This page took 0.033494 seconds and 4 git commands to generate.