Commit | Line | Data |
---|---|---|
88b9d363 | 1 | # Copyright (C) 2014-2022 Free Software Foundation, Inc. |
70509625 PA |
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 | ||
b61f7811 HAQ |
19 | standard_testfile |
20 | ||
70509625 PA |
21 | if [target_info exists gdb,nosignals] { |
22 | verbose "Skipping ${testfile}.exp because of nosignals." | |
23 | return -1 | |
24 | } | |
25 | ||
70509625 PA |
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 { | |
bc6c7af4 | 41 | fail "can't run to main" |
70509625 PA |
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.*" | |
c1a747c1 PA |
49 | |
50 | # Create threads one at a time, to insure stable thread | |
51 | # numbers between runs and targets. | |
52 | gdb_test "break thread_function" "Breakpoint .* at .*$srcfile.*" | |
53 | gdb_test "continue" "thread_function.*" "thread 2 created" | |
54 | gdb_test "continue" "thread_function.*" "thread 3 created" | |
55 | ||
f302f9e2 AB |
56 | gdb_test "continue" "all_threads_started.*" \ |
57 | "continue to all_threads_started" | |
70509625 PA |
58 | |
59 | # Using schedlock, let the main thread queue a signal for each | |
60 | # non-main thread. | |
61 | gdb_test_no_output "set scheduler-locking on" | |
62 | ||
63 | gdb_test "break all_threads_signalled" "Breakpoint .* at .*$srcfile.*" | |
f302f9e2 AB |
64 | gdb_test "continue" "all_threads_signalled.*" \ |
65 | "continue to all_threads signalled" | |
70509625 PA |
66 | |
67 | gdb_test "info threads" "\\\* 1\[ \t\]+Thread.*" "thread 1 selected" | |
68 | ||
69 | # With schedlock still enabled, let each thread report its | |
70 | # signal. | |
71 | ||
72 | gdb_test "thread 3" "Switching to thread 3.*" | |
f303dbd6 | 73 | gdb_test "continue" "Thread 3 .*received signal SIGUSR2.*" "stop with SIGUSR2" |
70509625 | 74 | gdb_test "thread 2" "Switching to thread 2.*" |
f303dbd6 | 75 | gdb_test "continue" "Thread 2 .*received signal SIGUSR1.*" "stop with SIGUSR1" |
70509625 PA |
76 | |
77 | gdb_test "break handler_sigusr1" "Breakpoint .* at .*$srcfile.*" | |
78 | gdb_test "break handler_sigusr2" "Breakpoint .* at .*$srcfile.*" | |
79 | ||
80 | set handler_re "Breakpoint .*, handler_sigusr. \\(sig=.*\\) at .*" | |
81 | ||
82 | # Now test the "signal" command with either scheduler locking | |
83 | # enabled or disabled. | |
84 | ||
85 | if { $schedlock == "off" } { | |
86 | # With scheduler locking off, switch to the main thread | |
87 | # and issue "signal 0". "signal 0" should then warn that | |
88 | # two threads have signals that will be delivered. When | |
89 | # we let the command proceed, a signal should be | |
90 | # delivered, and thus the corresponding breakpoint in the | |
91 | # signal handler should trigger. | |
92 | ||
93 | gdb_test_no_output "set scheduler-locking off" | |
94 | gdb_test "thread 1" "Switching to thread 1.*" | |
95 | ||
96 | set queried 0 | |
97 | set test "signal command queries" | |
98 | gdb_test_multiple "signal 0" $test { | |
99 | -re "stopped with.*stopped with.*stopped with.*Continue anyway.*y or n. $" { | |
100 | fail "$test (too many threads noted)" | |
101 | set queried 1 | |
102 | } | |
103 | -re "stopped with signal SIGUSR.*\r\nContinuing .*still deliver .*Continue anyway.*y or n. $" { | |
104 | pass $test | |
105 | set queried 1 | |
106 | } | |
107 | -re "Continue anyway.*y or n. $" { | |
108 | fail "$test (no threads noted)" | |
109 | set queried 1 | |
110 | } | |
111 | } | |
112 | ||
113 | # Continuing should stop in one of the signal handlers. | |
114 | # Which thread runs first is not determinate. | |
115 | if {$queried} { | |
116 | gdb_test "y" "$handler_re" "one signal delivered" | |
117 | } | |
118 | ||
119 | # Continuing a second time should stop in the other | |
120 | # handler. | |
121 | with_test_prefix "second signal" { | |
122 | gdb_test "continue" "$handler_re" "signal delivered" | |
123 | } | |
124 | } else { | |
125 | # With scheduler locking on, stay with thread 2 selected, | |
126 | # and try to deliver its signal explicitly. The "signal" | |
127 | # command should then warn that one other thread has a | |
128 | # signal that will be delivered. When we let the command | |
129 | # proceed, the current thread's signal should be | |
130 | # delivered, and thus the corresponding breakpoint in the | |
131 | # signal handler should trigger. | |
132 | gdb_test "signal SIGUSR1" \ | |
133 | "Breakpoint .*, handler_sigusr1 \\(sig=.*\\) at .*" \ | |
134 | "signal command does not query, signal delivered" | |
135 | ||
136 | with_test_prefix "second signal" { | |
137 | # The other thread had stopped for a signal too, and | |
138 | # it wasn't resumed yet. Disabling schedlock and | |
139 | # trying "signal 0" from the main thread should warn | |
140 | # again. | |
141 | gdb_test_no_output "set scheduler-locking off" | |
142 | ||
143 | set queried 0 | |
144 | set test "signal command queries" | |
145 | gdb_test_multiple "signal 0" $test { | |
146 | -re "stopped with.*stopped with.*Continue anyway.*y or n. $" { | |
147 | fail "$test (too many threads noted)" | |
148 | set queried 1 | |
149 | } | |
150 | -re "stopped with signal SIGUSR.*\r\nContinuing .*still deliver .*Continue anyway.*y or n. $" { | |
151 | pass $test | |
152 | set queried 1 | |
153 | } | |
154 | -re "Continue anyway.*y or n. $" { | |
155 | fail "$test (no threads noted)" | |
156 | set queried 1 | |
157 | } | |
158 | } | |
159 | ||
160 | if {$queried} { | |
161 | gdb_test "y" "Breakpoint .*, handler_sigusr2 \\(sig=.*\\) at .*" "signal delivered" | |
162 | } | |
163 | } | |
164 | } | |
165 | ||
166 | # Both threads got their signal. Continuing again should | |
167 | # neither intercept nor deliver any other signal. | |
168 | gdb_test "b end" "Breakpoint .* at .*$srcfile.*" | |
169 | gdb_test "continue" "end .*" "no more signals" | |
170 | } | |
171 | } | |
172 | ||
173 | foreach schedlock {"off" "on"} { | |
174 | test $schedlock | |
175 | } |