1# Copyright (C) 2014-2021 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] then {
44	    fail "can't run to main"
45	    return 0
46	}
47
48	gdb_test "handle SIGUSR1 stop print nopass"
49
50	gdb_test "b thread_function" "Breakpoint .* at .*$srcfile.*"
51	gdb_test "continue" "thread_function.*" "stopped in thread"
52
53	# Thread 2 is stopped at a breakpoint.  If we leave the
54	# breakpoint in place, GDB needs to move thread 2 past the
55	# breakpoint before delivering the signal to thread 1.  We
56	# want to be sure that GDB doesn't mistakenly deliver the
57	# signal to thread 1 while doing that.
58	if { $step_over == "no" } {
59	    delete_breakpoints
60	}
61
62	gdb_test "break handler" "Breakpoint .* at .*$srcfile.*"
63
64	gdb_test "thread 1" "Switching to thread 1.*"
65
66	set pattern "\\\* 1\[ \t\]+Thread.*"
67
68	gdb_test "info threads" $pattern "thread 1 selected"
69
70	gdb_test "signal SIGUSR1" "handler .*"
71
72	# Make sure it was thread 1 that got the signal.  Note we list
73	# all threads instead of just thread 1, so that if something
74	# goes wrong and another thread ends up selected, we can
75	# easily see which in the logs.
76	gdb_test "info threads" $pattern "thread 1 got the signal"
77    }
78}
79
80foreach stepover {"yes" "no"} {
81    test $stepover
82}
83