xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.threads/signal-command-handle-nopass.exp (revision 8b657b0747480f8989760d71343d6dd33f8d4cf9)
1# Copyright (C) 2014-2023 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 an explicit "signal FOO" delivers FOO even if "handle" for
17# that same signal is set to "nopass".  Also make sure the signal is
18# delivered to the right thread, even if GDB has to step over a
19# breakpoint in some other thread first.
20
21standard_testfile
22
23if [target_info exists gdb,nosignals] {
24    verbose "Skipping ${testfile}.exp because of nosignals."
25    return -1
26}
27
28if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
29	 executable { debug }] != "" } {
30    return -1
31}
32
33# Run the test proper.  STEP_OVER indicates whether we leave in place
34# a breakpoint that needs to be stepped over when we explicitly
35# request a signal be delivered with the "signal" command.
36
37proc test { step_over } {
38    global srcfile binfile
39
40    with_test_prefix "step-over $step_over" {
41	clean_restart ${binfile}
42
43	if {![runto_main]} {
44	    return 0
45	}
46
47	gdb_test "handle SIGUSR1 stop print nopass"
48
49	gdb_test "b thread_function" "Breakpoint .* at .*$srcfile.*"
50	gdb_test "continue" "thread_function.*" "stopped in thread"
51
52	# Thread 2 is stopped at a breakpoint.  If we leave the
53	# breakpoint in place, GDB needs to move thread 2 past the
54	# breakpoint before delivering the signal to thread 1.  We
55	# want to be sure that GDB doesn't mistakenly deliver the
56	# signal to thread 1 while doing that.
57	if { $step_over == "no" } {
58	    delete_breakpoints
59	}
60
61	gdb_test "break handler" "Breakpoint .* at .*$srcfile.*"
62
63	gdb_test "thread 1" "Switching to thread 1.*"
64
65	set pattern "\\\* 1\[ \t\]+Thread.*"
66
67	gdb_test "info threads" $pattern "thread 1 selected"
68
69	gdb_test "signal SIGUSR1" "handler .*"
70
71	# Make sure it was thread 1 that got the signal.  Note we list
72	# all threads instead of just thread 1, so that if something
73	# goes wrong and another thread ends up selected, we can
74	# easily see which in the logs.
75	gdb_test "info threads" $pattern "thread 1 got the signal"
76    }
77}
78
79foreach stepover {"yes" "no"} {
80    test $stepover
81}
82