1 # Copyright (C) 2015-2022 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 # This test exercises the case of stopping for a breakpoint hit of one
17 # thread, then switching to a thread that has a status pending and
20 if [target_info exists gdb,nointerrupts] {
21 verbose "Skipping continue-pending-status.exp because of nointerrupts."
27 if [prepare_for_testing "failed to prepare" $testfile $srcfile {debug pthreads}] {
35 set break_line [gdb_get_line_number "break here"]
37 # Return current thread's number.
39 proc get_current_thread {} {
43 set msg "get thread number"
44 gdb_test_multiple "print /x \$_thread" $msg {
45 -re "\\$\[0-9\]* = (0x\[0-9a-zA-Z\]+).*$gdb_prompt $" {
46 set thread $expect_out(1,string)
53 # There are two threads in the program that are running the same tight
54 # loop, where we place a breakpoint. Sometimes we'll get a breakpoint
55 # trigger for thread 2, with the breakpoint event of thread 3 pending,
56 # other times the opposite. The original bug that motivated this test
57 # depended on the event thread being the highest numbered thread. We
58 # try the same multiple times, which should cover both threads
59 # reporting the event.
63 # These track whether we saw events for both threads 2 and 3. If the
64 # backend always returns the breakpoint hit for the same thread, then
65 # it fails to make sure threads aren't starved, and we'll fail the
66 # assert after the loop.
70 for {set i 0} {$i < $attempts} {incr i} {
71 with_test_prefix "attempt $i" {
72 gdb_test "b $srcfile:$break_line" \
73 "Breakpoint .* at .*$srcfile, line $break_line.*" \
74 "set break in tight loop"
76 "$srcfile:$break_line.*" \
77 "continue to tight loop"
79 # Switch to the thread that did _not_ report the event (and
80 # thus may have a pending status). At the time this test was
81 # written this was necessary to make linux-nat.c short-circuit
82 # the resume and go straight to consuming the pending event.
83 set thread [get_current_thread]
91 gdb_test "thread $thread" \
92 "Switching to thread $thread .*" \
93 "switch to non-event thread"
95 # Delete all breakpoints so that continuing doesn't switch
96 # back to the event thread to do a step-over, which would mask
97 # away the original bug, which depended on the event thread
98 # still having TARGET_STOPPED_BY_SW_BREAKPOINT stop_reason.
101 # In the original bug, continuing would trigger an internal
102 # error in the linux-nat.c backend.
104 set msg "continue for ctrl-c"
105 gdb_test_multiple "continue" $msg {
111 # Wait a bit for GDB to give the terminal to the inferior,
112 # otherwise ctrl-c too soon can result in a "Quit".
116 set msg "caught interrupt"
117 gdb_test_multiple "" $msg {
118 -re "Thread .* received signal SIGINT.*$gdb_prompt $" {
125 verbose -log "saw_thread_2=$saw_thread_2"
126 verbose -log "saw_thread_3=$saw_thread_3"
128 gdb_assert {$saw_thread_2 > 0 && $saw_thread_3 > 0} "no thread starvation"