1 # Copyright (C) 2011-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 GDB steps over all breakpoints of threads not the stepping
17 # thread, before actually proceeding with the stepped thread.
20 set executable ${testfile}
22 require {!target_info exists gdb,nosignals}
24 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
25 executable [list debug "incdir=${objdir}"]] != "" } {
29 # Prepare environment for test.
35 with_test_prefix "setup" {
36 clean_restart $executable
42 gdb_test_no_output "set displaced-stepping $displaced"
44 gdb_breakpoint [gdb_get_line_number "set wait-threads breakpoint here"]
45 gdb_continue_to_breakpoint "run to breakpoint"
46 gdb_test "info threads" "\\\* 1 .* 2 .* 3 .*" "info threads shows all threads"
48 gdb_test_no_output "set scheduler-locking on"
50 gdb_breakpoint [gdb_get_line_number "set breakpoint thread 3 here"]
51 gdb_breakpoint [gdb_get_line_number "set breakpoint thread 2 here"]
53 gdb_test "thread 3" "Switching.*"
54 gdb_continue_to_breakpoint "run to breakpoint in thread 3"
55 gdb_test "p *myp = 0" " = 0" "unbreak loop in thread 3"
57 gdb_test "thread 2" "Switching.*"
58 gdb_continue_to_breakpoint "run to breakpoint in thread 2"
59 gdb_test "p *myp = 0" " = 0" "unbreak loop in thread 2"
61 # Disable scheduler locking.
62 gdb_test_no_output "set scheduler-locking off"
64 # Now all 3 threads are stopped for a breakpoint that needs to
65 # be stepped over before thread 1 is resumed.
69 foreach displaced { "off" "on" } {
70 with_test_prefix "displaced=$displaced" {
71 with_test_prefix "step" {
73 gdb_test "thread 1" "Switching.*"
74 gdb_test "step" "in wait_threads .*"
77 with_test_prefix "next" {
79 gdb_test "thread 1" "Switching.*"
80 gdb_test "next" "pthread_join.*"
83 with_test_prefix "continue" {
85 gdb_breakpoint [gdb_get_line_number "EXIT_SUCCESS"]
86 gdb_test "thread 1" "Switching.*"
87 gdb_test "continue" "EXIT_SUCCESS.*"
90 # Try continuing with a queued signal in each of the threads
91 # (one at a time). Should stop at the signal handler, instead
92 # of re-trapping the breakpoint the threads were already
94 foreach thread {1 2 3} {
95 with_test_prefix "signal thr$thread" {
98 # Queue a signal in THREAD.
99 gdb_test "thread $thread" "Switching.*"
100 gdb_test_no_output "queue-signal SIGUSR1"
102 # Switch back to thread 1, and continue.
103 gdb_test "thread 1" "Switching.*" "switch back to thread 1"
104 gdb_breakpoint "sigusr1_handler" "set break at sigusr1_handler"
106 set msg "continue to sigusr1_handler"
107 gdb_test_multiple "continue" $msg {
108 -re "Breakpoint .* sigusr1_handler .*$gdb_prompt $" {
111 -re "Breakpoint .*$gdb_prompt $" {
112 if {![can_single_step_to_signal_handler]
113 && $thread != 1 && $displaced == "off"} {
114 setup_kfail "gdb/18214" "*-*-*"