1 # manythreads.exp -- Expect script to test stopping many threads
2 # Copyright (C) 2004-2023 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 if [target_info exists gdb,nointerrupts] {
21 verbose "Skipping manythreads.exp because of nointerrupts."
28 if [info exists DEBUG] {
29 # make check RUNTESTFLAGS='gdb.threads/manythreads.exp DEBUG=1'
30 lappend opts "additional_flags=-DDEBUG"
33 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $opts] != "" } {
37 clean_restart ${binfile}
38 gdb_test_no_output "set print sevenbit-strings"
41 # We'll need this when we send_gdb a ^C to GDB. Need to do it before we
42 # run the program and gdb starts saving and restoring tty states.
43 gdb_test "shell stty intr '^C'" ".*"
45 set message "first continue"
46 gdb_test_multiple "continue" "first continue" {
47 -re "error:.*$gdb_prompt $" {
55 # Wait one second. This is better than the TCL "after" command, because
56 # we don't lose GDB's output while we do it.
57 remote_expect host 1 { timeout { } }
59 # Send a Ctrl-C and wait for the SIGINT.
61 proc interrupt_and_wait { message } {
68 gdb_test_multiple "" $message {
69 -re "\r\n\\\[New \[^\r\n\]*(?=\r\n)" {
70 # Note if GDB emits [New Thread ...] output between
71 # "Thread NNN received signal" and the prompt, it's a
74 # GDB makes sure to notify about signal stops, end of
75 # stepping ranges, etc., only after updating the thread
76 # list, otherwise that stop info would be easy to miss.
78 # A BROKEN example would be:
80 # ... pages of new threads output ...
83 # ... more new threads output ...
86 # Thread NNN received signal SIGINT, Interrupt.
89 # ... pages of new threads output ...
90 # [Switching to Thread NNN]
99 -re "\r\n\\\[\[^\r\n]* exited\\\](?=\r\n)" {
102 -re "\r\n\[^\r\n]* received signal SIGINT\[^\r\n\]*(?=\r\n)" {
107 gdb_assert {$saw_signal && $order_ok} $gdb_test_name
112 # Send a Ctrl-C and verify that we can do info threads and continue
113 interrupt_and_wait "stop threads 1"
115 set cmd "info threads"
117 gdb_test_multiple $cmd $cmd {
123 # Eat this line and continue, to prevent the buffer overflowing.
126 -re "$gdb_prompt $" {
135 gdb_test_no_output "thread name zardoz" "give a name to the thread"
136 gdb_test "info threads" ".*zardoz.*" "check thread name"
138 set message "second continue"
139 gdb_test_multiple "continue" "second continue" {
140 -re "error:.*$gdb_prompt $" {
148 # Wait another second. If the program stops on its own, GDB has failed
149 # to handle duplicate SIGINTs sent to multiple threads.
151 remote_expect host 1 {
152 -re "\\\[New \[^\]\]*\\\]\r\n" {
153 exp_continue -continue_timer
155 -re "\\\[\[^\]\]* exited\\\]\r\n" {
156 exp_continue -continue_timer
158 -re " received signal SIGINT.*$gdb_prompt $" {
159 if { $failed == 0 } {
160 fail "check for duplicate SIGINT"
162 send_gdb "continue\n"
167 if { $failed == 0 } {
168 pass "check for duplicate SIGINT"
173 # Send another Ctrl-C and verify that we can do info threads and quit
174 interrupt_and_wait "stop threads 2"
176 gdb_test_multiple "quit" "GDB exits after stopping multithreaded program" {
177 -re "Quit anyway\\? \\(y or n\\) $" {
182 pass "GDB exits after stopping multithreaded program"
185 fail "GDB exits after stopping multithreaded program (timeout)"