xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.threads/signal-sigtrap.exp (revision 6881a4007f077b54e5f51159c52b9b25f57deb0d)
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# Check that GDB doesn't forget to pass SIGTRAP to the program when
17# the user explicitly passes it with the signal command.
18
19standard_testfile
20
21if [target_info exists gdb,nosignals] {
22    verbose "Skipping ${testfile}.exp because of nosignals."
23    return -1
24}
25
26if {[build_executable "failed to prepare" $testfile $srcfile \
27	 {debug pthreads}]} {
28    return -1
29}
30
31# Run test proper.  SIGTRAP_THREAD is the thread that should get the
32# SIGTRAP.
33
34proc test { sigtrap_thread } {
35    global srcfile binfile
36
37    with_test_prefix "sigtrap thread $sigtrap_thread" {
38	clean_restart ${binfile}
39
40	if {![runto "thread_function"]} {
41	    return 0
42	}
43
44	set pattern "\\\* 2\[ \t\]+Thread.*"
45	gdb_test "info threads" $pattern "thread 2 hit breakpoint"
46
47	gdb_test "break sigtrap_handler" "Breakpoint .* at .*$srcfile.*"
48
49	# Thread 2 is stopped at a breakpoint, which must be stepped
50	# over first.  Thus if this is thread 1, then GDB will first
51	# switch back to thread 2 to step it over the breakpoint.
52	gdb_test "thread $sigtrap_thread" \
53	    "Switching to thread $sigtrap_thread.*" \
54	    "switch to sigtrap thread"
55
56	gdb_test "signal SIGTRAP" \
57	    "Continuing with signal SIGTRAP.*Breakpoint .* sigtrap_handler .*" \
58	    "signal SIGTRAP reaches handler"
59
60	set pattern "\\\* $sigtrap_thread\[ \t\]+Thread.*"
61	gdb_test "info threads" $pattern "right thread got the signal"
62    }
63}
64
65foreach sigtrap_thread {1 2} {
66    test $sigtrap_thread
67}
68