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)
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 } {
66 gdb_test_multiple "" $message {
67 -re "\\\[New \[^\]\]*\\\]\r\n" {
70 -re "\\\[\[^\]\]* exited\\\]\r\n" {
73 -re "Program received signal SIGINT.*$gdb_prompt $" {
77 # Note that with this regex order, if GDB emits [New
78 # Thread ...] output between "Program received signal" and
79 # the prompt, the "Program received signal" regex won't
80 # match. That's good, as if we see that happening, it's a
83 # GDB makes sure to notify about signal stops, end of
84 # stepping ranges, etc., only after updating the thread
85 # list, otherwise that stop info would be easy to miss.
87 # A BROKEN example would be:
89 # ... pages of new threads output ...
92 # ... more new threads output ...
95 # Program received signal SIGINT, Interrupt.
98 # ... pages of new threads output ...
99 # [Switching to Thread NNN]
108 # Send a Ctrl-C and verify that we can do info threads and continue
109 interrupt_and_wait "stop threads 1"
111 set cmd "info threads"
113 gdb_test_multiple $cmd $cmd {
119 # Eat this line and continue, to prevent the buffer overflowing.
122 -re "$gdb_prompt $" {
131 gdb_test_no_output "thread name zardoz" "give a name to the thread"
132 gdb_test "info threads" ".*zardoz.*" "check thread name"
134 set message "second continue"
135 gdb_test_multiple "continue" "second continue" {
136 -re "error:.*$gdb_prompt $" {
144 # Wait another second. If the program stops on its own, GDB has failed
145 # to handle duplicate SIGINTs sent to multiple threads.
147 remote_expect host 1 {
148 -re "\\\[New \[^\]\]*\\\]\r\n" {
149 exp_continue -continue_timer
151 -re "\\\[\[^\]\]* exited\\\]\r\n" {
152 exp_continue -continue_timer
154 -re "Program received signal SIGINT.*$gdb_prompt $" {
155 if { $failed == 0 } {
156 fail "check for duplicate SIGINT"
158 send_gdb "continue\n"
163 if { $failed == 0 } {
164 pass "check for duplicate SIGINT"
169 # Send another Ctrl-C and verify that we can do info threads and quit
170 interrupt_and_wait "stop threads 2"
172 gdb_test_multiple "quit" "GDB exits after stopping multithreaded program" {
173 -re "Quit anyway\\? \\(y or n\\) $" {
178 pass "GDB exits after stopping multithreaded program"
181 fail "GDB exits after stopping multithreaded program (timeout)"