1 # manythreads.exp -- Expect script to test stopping many threads
2 # Copyright (C) 2004-2015 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)
23 if [info exists DEBUG] {
24 # make check RUNTESTFLAGS='gdb.threads/manythreads.exp DEBUG=1'
25 lappend opts "additional_flags=-DDEBUG"
28 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $opts] != "" } {
32 clean_restart ${binfile}
33 gdb_test_no_output "set print sevenbit-strings"
36 # We'll need this when we send_gdb a ^C to GDB. Need to do it before we
37 # run the program and gdb starts saving and restoring tty states.
38 gdb_test "shell stty intr '^C'" ".*"
40 set message "first continue"
41 gdb_test_multiple "continue" "first continue" {
42 -re "error:.*$gdb_prompt $" {
50 # Wait one second. This is better than the TCL "after" command, because
51 # we don't lose GDB's output while we do it.
52 remote_expect host 1 { timeout { } }
54 # Send a Ctrl-C and wait for the SIGINT.
56 proc interrupt_and_wait { message } {
61 gdb_test_multiple "" $message {
62 -re "\\\[New \[^\]\]*\\\]\r\n" {
65 -re "\\\[\[^\]\]* exited\\\]\r\n" {
68 -re "Program received signal SIGINT.*$gdb_prompt $" {
72 # Note that with this regex order, if GDB emits [New
73 # Thread ...] output between "Program received signal" and
74 # the prompt, the "Program received signal" regex won't
75 # match. That's good, as if we see that happening, it's a
78 # GDB makes sure to notify about signal stops, end of
79 # stepping ranges, etc., only after updating the thread
80 # list, otherwise that stop info would be easy to miss.
82 # A BROKEN example would be:
84 # ... pages of new threads output ...
87 # ... more new threads output ...
90 # Program received signal SIGINT, Interrupt.
93 # ... pages of new threads output ...
94 # [Switching to Thread NNN]
103 # Send a Ctrl-C and verify that we can do info threads and continue
104 interrupt_and_wait "stop threads 1"
106 set cmd "info threads"
108 gdb_test_multiple $cmd $cmd {
114 # Eat this line and continue, to prevent the buffer overflowing.
117 -re "$gdb_prompt $" {
126 gdb_test_no_output "thread name zardoz" "give a name to the thread"
127 gdb_test "info threads" ".*zardoz.*" "check thread name"
129 set message "second continue"
130 gdb_test_multiple "continue" "second continue" {
131 -re "error:.*$gdb_prompt $" {
139 # Wait another second. If the program stops on its own, GDB has failed
140 # to handle duplicate SIGINTs sent to multiple threads.
142 remote_expect host 1 {
143 -re "\\\[New \[^\]\]*\\\]\r\n" {
144 exp_continue -continue_timer
146 -re "\\\[\[^\]\]* exited\\\]\r\n" {
147 exp_continue -continue_timer
149 -re "Program received signal SIGINT.*$gdb_prompt $" {
150 if { $failed == 0 } {
151 fail "check for duplicate SIGINT"
153 send_gdb "continue\n"
158 if { $failed == 0 } {
159 pass "check for duplicate SIGINT"
164 # Send another Ctrl-C and verify that we can do info threads and quit
165 interrupt_and_wait "stop threads 2"
167 gdb_test_multiple "quit" "GDB exits after stopping multithreaded program" {
168 -re "Quit anyway\\? \\(y or n\\) $" {
173 pass "GDB exits after stopping multithreaded program"
176 fail "GDB exits after stopping multithreaded program (timeout)"