Remove obsolete test from gdb.cp/var-tag.exp
[binutils-gdb.git] / gdb / testsuite / gdb.threads / signal-command-multiple-signals-pending.exp
blob5f47d75a981a1e79e76ccd83c39c14137ab7b507
1 # Copyright (C) 2014-2024 Free Software Foundation, Inc.
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.
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.
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/>.  */
16 # Test that "signal FOO" behaves correctly when we have multiple
17 # threads that have stopped for a signal.
19 standard_testfile
21 require {!target_info exists gdb,nosignals}
23 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
24          executable { debug }] != "" } {
25     return -1
28 # Run the test proper.  SCHEDLOCK indicates which variant (around
29 # scheduler-locking) of the test to perform.
31 proc test { schedlock } {
32     global srcfile binfile tdlabel_re
34     with_test_prefix "schedlock $schedlock" {
35         clean_restart ${binfile}
37         if {![runto_main]} {
38             return 0
39         }
41         gdb_test "handle SIGUSR1 stop print pass"
42         gdb_test "handle SIGUSR2 stop print pass"
44         gdb_test "break all_threads_started" "Breakpoint .* at .*$srcfile.*"
46         # Create threads one at a time, to insure stable thread
47         # numbers between runs and targets.
48         gdb_test "break thread_function" "Breakpoint .* at .*$srcfile.*"
49         gdb_test "continue" "thread_function.*" "thread 2 created"
50         gdb_test "continue" "thread_function.*" "thread 3 created"
52         gdb_test "continue" "all_threads_started.*" \
53             "continue to all_threads_started"
55         # Using schedlock, let the main thread queue a signal for each
56         # non-main thread.
57         gdb_test_no_output "set scheduler-locking on"
59         gdb_test "break all_threads_signalled" "Breakpoint .* at .*$srcfile.*"
60         gdb_test "continue" "all_threads_signalled.*" \
61             "continue to all_threads signalled"
63         gdb_test "info threads" "\\\* 1\[ \t\]+${tdlabel_re}.*" "thread 1 selected"
65         # With schedlock still enabled, let each thread report its
66         # signal.
68         gdb_test "thread 3" "Switching to thread 3.*"
69         gdb_test "continue" "Thread 3 .*received signal SIGUSR2.*" "stop with SIGUSR2"
70         gdb_test "thread 2" "Switching to thread 2.*"
71         gdb_test "continue" "Thread 2 .*received signal SIGUSR1.*" "stop with SIGUSR1"
73         gdb_test "break handler_sigusr1" "Breakpoint .* at .*$srcfile.*"
74         gdb_test "break handler_sigusr2" "Breakpoint .* at .*$srcfile.*"
76         set handler_re "Breakpoint .*, handler_sigusr. \\(sig=.*\\) at .*"
78         # Now test the "signal" command with either scheduler locking
79         # enabled or disabled.
81         if { $schedlock == "off" } {
82             # With scheduler locking off, switch to the main thread
83             # and issue "signal 0".  "signal 0" should then warn that
84             # two threads have signals that will be delivered.  When
85             # we let the command proceed, a signal should be
86             # delivered, and thus the corresponding breakpoint in the
87             # signal handler should trigger.
89             gdb_test_no_output "set scheduler-locking off"
90             gdb_test "thread 1" "Switching to thread 1.*"
92             set queried 0
93             set test "signal command queries"
94             gdb_test_multiple "signal 0" $test {
95                 -re "stopped with.*stopped with.*stopped with.*Continue anyway.*y or n. $" {
96                     fail "$test (too many threads noted)"
97                     set queried 1
98                 }
99                 -re "stopped with signal SIGUSR.*\r\nContinuing .*still deliver .*Continue anyway.*y or n. $" {
100                     pass $test
101                     set queried 1
102                 }
103                 -re "Continue anyway.*y or n. $" {
104                     fail "$test (no threads noted)"
105                     set queried 1
106                 }
107             }
109             # Continuing should stop in one of the signal handlers.
110             # Which thread runs first is not determinate.
111             if {$queried} {
112                 gdb_test "y" "$handler_re" "one signal delivered"
113             }
115             # Continuing a second time should stop in the other
116             # handler.
117             with_test_prefix "second signal" {
118                 gdb_test "continue" "$handler_re" "signal delivered"
119             }
120         } else {
121             # With scheduler locking on, stay with thread 2 selected,
122             # and try to deliver its signal explicitly.  The "signal"
123             # command should then warn that one other thread has a
124             # signal that will be delivered.  When we let the command
125             # proceed, the current thread's signal should be
126             # delivered, and thus the corresponding breakpoint in the
127             # signal handler should trigger.
128             gdb_test "signal SIGUSR1" \
129                 "Breakpoint .*, handler_sigusr1 \\(sig=.*\\) at .*" \
130                 "signal command does not query, signal delivered"
132             with_test_prefix "second signal" {
133                 # The other thread had stopped for a signal too, and
134                 # it wasn't resumed yet.  Disabling schedlock and
135                 # trying "signal 0" from the main thread should warn
136                 # again.
137                 gdb_test_no_output "set scheduler-locking off"
139                 set queried 0
140                 set test "signal command queries"
141                 gdb_test_multiple "signal 0" $test {
142                     -re "stopped with.*stopped with.*Continue anyway.*y or n. $" {
143                         fail "$test (too many threads noted)"
144                         set queried 1
145                     }
146                     -re "stopped with signal SIGUSR.*\r\nContinuing .*still deliver .*Continue anyway.*y or n. $" {
147                         pass $test
148                         set queried 1
149                     }
150                     -re "Continue anyway.*y or n. $" {
151                         fail "$test (no threads noted)"
152                         set queried 1
153                     }
154                 }
156                 if {$queried} {
157                     gdb_test "y" "Breakpoint .*, handler_sigusr2 \\(sig=.*\\) at .*" "signal delivered"
158                 }
159             }
160         }
162         # Both threads got their signal.  Continuing again should
163         # neither intercept nor deliver any other signal.
164         gdb_test "b end" "Breakpoint .* at .*$srcfile.*"
165         gdb_test "continue" "end .*" "no more signals"
166     }
169 foreach schedlock {"off" "on"} {
170     test $schedlock