1 # Copyright (C) 2019-2023 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/>.
18 if {[build_executable "failed to prepare" $testfile $srcfile {debug pthreads}] == -1} {
22 # At this point GDB will be busy handling the breakpoint hits and
23 # re-resuming the program. Even if GDB internally switches thread
24 # context, the user should not notice it. The following part of the
25 # testcase ensures that.
27 # Switch to thread EXPECTED_THR, and then confirm that the thread
30 proc test_current_thread {expected_thr} {
35 clean_restart $binfile
37 if {![runto "all_started"]} {
41 # Set a breakpoint that continuously fires but doeesn't cause a stop.
42 gdb_breakpoint [concat [gdb_get_line_number "set breakpoint here"] " if 0"]
44 gdb_test "thread $expected_thr" "Switching to thread $expected_thr .*" \
45 "switch to thread $expected_thr"
47 # Continue the program in the background.
49 gdb_test_multiple "continue&" $test {
50 -re "Continuing\\.\r\n$gdb_prompt " {
55 set test "current thread is $expected_thr"
57 for {set i 0} {$i < 10} {incr i} {
61 gdb_test_multiple "thread" $test {
62 -re "Current thread is ($decimal) .*$gdb_prompt " {
63 set cur_thread $expect_out(1,string)
67 if {$cur_thread != $expected_thr} {
72 gdb_assert {$fails == 0} $test
74 # Explicitly interrupt the target, because in all-stop/remote,
75 # that's all we can do when the target is running. If we don't do
76 # this, we'd time out trying to kill the target, while bringing
77 # down gdb & gdbserver.
79 gdb_test_multiple $test $test {
80 -re "^interrupt\r\n$gdb_prompt " {
81 gdb_test_multiple "" $test {
82 -re "Thread .* received signal SIGINT, Interrupt\\." {
90 # Try once with each thread as current, to avoid missing a bug just
91 # because some part of GDB manages to switch to the right thread by
93 for {set thr 1} {$thr <= 3} {incr thr} {
94 with_test_prefix "thread $thr" {
95 test_current_thread $thr