]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.threads/queue-signal.exp
Automatic Copyright Year update after running gdb/copyright.py
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / queue-signal.exp
1 # Copyright (C) 2014-2022 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 standard_testfile
17
18 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
19 executable { debug }] != "" } {
20 return -1
21 }
22
23 clean_restart ${binfile}
24
25 if ![runto_main] {
26 return 0
27 }
28
29 gdb_test "handle SIGUSR1 stop print pass"
30 gdb_test "handle SIGUSR2 stop print pass"
31 gdb_test "handle SIGABRT stop print pass"
32
33 gdb_breakpoint "all_threads_running"
34 gdb_continue_to_breakpoint "all_threads_running"
35
36 # Find out which of threads 2,3 are for sigusr1,2.
37 set sigusr1_thread 0
38 set sigusr2_thread 0
39 gdb_test "thread 2"
40 gdb_test_multiple "bt" "determine thread functions" {
41 -re "sigusr1.*$gdb_prompt $" {
42 set sigusr1_thread 2
43 set sigusr2_thread 3
44 }
45 -re "sigusr2.*$gdb_prompt $" {
46 set sigusr1_thread 3
47 set sigusr2_thread 2
48 }
49 }
50
51 # No point in continuing if we couldn't figure out which thread is which.
52 if { $sigusr1_thread == 0 } {
53 # FAIL already recorded.
54 return 0
55 }
56
57 # Advance each thread to where we want them one at a time.
58 gdb_test_no_output "set scheduler-locking on"
59 gdb_test_no_output "set var ready = 1"
60
61 # Thread sigusr1_thread gets a SIGUSR1 which we leave alone.
62 gdb_test "thread $sigusr1_thread" "" \
63 "switch to SIGUSR1 thread"
64 gdb_test "continue" "SIGUSR1.*" \
65 "continue until we get SIGUSR1"
66
67 # Inject SIGUSR2 into thread sigusr2_thread.
68 gdb_test "thread $sigusr2_thread" "" \
69 "switch to SIGUSR2 thread"
70 gdb_test_no_output "queue-signal SIGUSR2"
71
72 # The main thread gets SIGABRT which we then throw away.
73 gdb_test "thread 1" ""
74 gdb_test "continue" "SIGABRT.*" \
75 "continue until we get SIGABRT"
76 gdb_test_no_output "queue-signal 0"
77
78 # Now let every thread run.
79 gdb_test_no_output "set scheduler-locking off"
80
81 gdb_breakpoint "all_threads_done"
82 gdb_continue_to_breakpoint "all_threads_done"
83
84 # Verify SIGUSR1, SIGUSR2 were received, and SIGABRT was discarded.
85 gdb_test "p sigusr1_received" "= 1"
86 gdb_test "p sigusr2_received" "= 1"
87 gdb_test "p sigabrt_received" "= 0"
88
89 # Before we finish up verify the queueing of nopass signals flags an error.
90 gdb_test "queue-signal SIGINT" \
91 "Signal handling set to not pass this signal to the program."
92
93 # Verify program is able to finish.
94 gdb_continue_to_end