1 # manythreads.exp -- Expect script to test stopping many threads
2 # Copyright (C) 2004-2024 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # This file was written by Jeff Johnston. (jjohnstn@redhat.com)
19 # This test requires sending ^C to interrupt the running target.
20 require {!target_info exists gdb,nointerrupts}
25 if [info exists DEBUG] {
26 # make check RUNTESTFLAGS='gdb.threads/manythreads.exp DEBUG=1'
27 lappend opts "additional_flags=-DDEBUG"
30 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $opts] != "" } {
34 clean_restart ${binfile}
35 gdb_test_no_output "set print sevenbit-strings"
38 # We'll need this when we send_gdb a ^C to GDB. Need to do it before we
39 # run the program and gdb starts saving and restoring tty states.
40 gdb_test "shell stty intr '^C'" ".*"
42 set message "first continue"
43 gdb_test_multiple "continue" "first continue" {
44 -re "error:.*$gdb_prompt $" {
52 # Wait one second. This is better than the TCL "after" command, because
53 # we don't lose GDB's output while we do it.
54 remote_expect host 1 { timeout { } }
56 # Send a Ctrl-C and wait for the SIGINT.
58 proc interrupt_and_wait { message } {
65 gdb_test_multiple "" $message {
66 -re "\r\n\\\[New \[^\r\n\]*(?=\r\n)" {
67 # Note if GDB emits [New Thread ...] output between
68 # "Thread NNN received signal" and the prompt, it's a
71 # GDB makes sure to notify about signal stops, end of
72 # stepping ranges, etc., only after updating the thread
73 # list, otherwise that stop info would be easy to miss.
75 # A BROKEN example would be:
77 # ... pages of new threads output ...
80 # ... more new threads output ...
83 # Thread NNN received signal SIGINT, Interrupt.
86 # ... pages of new threads output ...
87 # [Switching to Thread NNN]
96 -re "\r\n\\\[\[^\r\n]* exited\\\](?=\r\n)" {
99 -re "\r\n\[^\r\n]* received signal SIGINT\[^\r\n\]*(?=\r\n)" {
104 gdb_assert {$saw_signal && $order_ok} $gdb_test_name
109 # Send a Ctrl-C and verify that we can do info threads and continue
110 interrupt_and_wait "stop threads 1"
112 set cmd "info threads"
114 gdb_test_multiple $cmd $cmd {
115 -re " 1 *${tdlabel_re} " {
120 # Eat this line and continue, to prevent the buffer overflowing.
123 -re "$gdb_prompt $" {
132 gdb_test_no_output "thread name zardoz" "give a name to the thread"
133 gdb_test "info threads" ".*zardoz.*" "check thread name"
135 set message "second continue"
136 gdb_test_multiple "continue" "second continue" {
137 -re "error:.*$gdb_prompt $" {
145 # Wait another second. If the program stops on its own, GDB has failed
146 # to handle duplicate SIGINTs sent to multiple threads.
148 remote_expect host 1 {
149 -re "\\\[New \[^\]\]*\\\]\r\n" {
150 exp_continue -continue_timer
152 -re "\\\[\[^\]\]* exited\\\]\r\n" {
153 exp_continue -continue_timer
155 -re " received signal SIGINT.*$gdb_prompt $" {
156 if { $failed == 0 } {
157 fail "check for duplicate SIGINT"
159 send_gdb "continue\n"
164 if { $failed == 0 } {
165 pass "check for duplicate SIGINT"
170 # Send another Ctrl-C and verify that we can do info threads and quit
171 interrupt_and_wait "stop threads 2"
173 gdb_test_multiple "quit" "GDB exits after stopping multithreaded program" {
174 -re "Quit anyway\\? \\(y or n\\) $" {
179 pass "GDB exits after stopping multithreaded program"
182 fail "GDB exits after stopping multithreaded program (timeout)"