]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.threads/manythreads.exp
GDB copyright headers update after running GDB's copyright.py script.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / manythreads.exp
CommitLineData
7339a42e 1# manythreads.exp -- Expect script to test stopping many threads
618f726f 2# Copyright (C) 2004-2016 Free Software Foundation, Inc.
7339a42e
JJ
3
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
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
7339a42e 7# (at your option) any later version.
e22f8b7c 8#
7339a42e
JJ
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.
e22f8b7c 13#
7339a42e 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
7339a42e 16
7339a42e
JJ
17# This file was written by Jeff Johnston. (jjohnstn@redhat.com)
18
87a3a92c
SL
19# This test requires sending ^C to interrupt the running target.
20if [target_info exists gdb,nointerrupts] {
21 verbose "Skipping manythreads.exp because of nointerrupts."
22 return
23}
7339a42e 24
0efbbabc 25standard_testfile
7339a42e 26
e5d98164
YQ
27set opts { debug }
28if [info exists DEBUG] {
29 # make check RUNTESTFLAGS='gdb.threads/manythreads.exp DEBUG=1'
30 lappend opts "additional_flags=-DDEBUG"
31}
32
33if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $opts] != "" } {
7339a42e
JJ
34 return -1
35}
36
0efbbabc 37clean_restart ${binfile}
12b5d08a 38gdb_test_no_output "set print sevenbit-strings"
7339a42e
JJ
39runto_main
40
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.
09dd9a69 43gdb_test "shell stty intr '^C'" ".*"
7339a42e
JJ
44
45set message "first continue"
46gdb_test_multiple "continue" "first continue" {
47 -re "error:.*$gdb_prompt $" {
48 fail "$message"
49 }
50 -re "Continuing" {
51 pass "$message"
52 }
53}
54
57380f4e
DJ
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.
57remote_expect host 1 { timeout { } }
58
2278c276
PA
59# Send a Ctrl-C and wait for the SIGINT.
60
61proc interrupt_and_wait { message } {
62 global gdb_prompt
63
64 send_gdb "\003"
65
66 gdb_test_multiple "" $message {
67 -re "\\\[New \[^\]\]*\\\]\r\n" {
68 exp_continue
69 }
70 -re "\\\[\[^\]\]* exited\\\]\r\n" {
71 exp_continue
72 }
73 -re "Program received signal SIGINT.*$gdb_prompt $" {
74 pass "$message"
75 }
76 -re "$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
81 # regression.
82 #
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.
86 #
87 # A BROKEN example would be:
88 #
89 # ... pages of new threads output ...
90 # [New Thread NNN]
91 # ^C
92 # ... more new threads output ...
93 # [New Thread NNN]
94 # [New Thread NNN]
95 # Program received signal SIGINT, Interrupt.
96 # [New Thread NNN]
97 # [New Thread NNN]
98 # ... pages of new threads output ...
99 # [Switching to Thread NNN]
100 # foo () at foo.c:31
101 # 31 bar ();
102 #
a1471180 103 fail $message
2278c276
PA
104 }
105 }
7339a42e
JJ
106}
107
2278c276
PA
108# Send a Ctrl-C and verify that we can do info threads and continue
109interrupt_and_wait "stop threads 1"
110
4339e69e
DJ
111set cmd "info threads"
112set ok 0
113gdb_test_multiple $cmd $cmd {
a7658b96 114 -re " 1 *Thread " {
4339e69e
DJ
115 set ok 1
116 exp_continue
117 }
118 -re ".*\r\n" {
119 # Eat this line and continue, to prevent the buffer overflowing.
120 exp_continue
121 }
122 -re "$gdb_prompt $" {
123 if { $ok } {
124 pass $cmd
125 } else {
126 fail $cmd
127 }
128 }
129}
7339a42e 130
4694da01
TT
131gdb_test_no_output "thread name zardoz" "give a name to the thread"
132gdb_test "info threads" ".*zardoz.*" "check thread name"
133
7339a42e
JJ
134set message "second continue"
135gdb_test_multiple "continue" "second continue" {
136 -re "error:.*$gdb_prompt $" {
137 fail "$message"
138 }
139 -re "Continuing" {
140 pass "$message"
141 }
142}
143
57380f4e
DJ
144# Wait another second. If the program stops on its own, GDB has failed
145# to handle duplicate SIGINTs sent to multiple threads.
146set failed 0
147remote_expect host 1 {
148 -re "\\\[New \[^\]\]*\\\]\r\n" {
149 exp_continue -continue_timer
150 }
151 -re "\\\[\[^\]\]* exited\\\]\r\n" {
152 exp_continue -continue_timer
153 }
57380f4e
DJ
154 -re "Program received signal SIGINT.*$gdb_prompt $" {
155 if { $failed == 0 } {
156 fail "check for duplicate SIGINT"
157 }
158 send_gdb "continue\n"
159 set failed 1
160 exp_continue
161 }
162 timeout {
163 if { $failed == 0 } {
164 pass "check for duplicate SIGINT"
165 }
166 }
167}
168
7339a42e 169# Send another Ctrl-C and verify that we can do info threads and quit
2278c276 170interrupt_and_wait "stop threads 2"
7339a42e
JJ
171
172gdb_test_multiple "quit" "GDB exits after stopping multithreaded program" {
b8fa0bfa 173 -re "Quit anyway\\? \\(y or n\\) $" {
7339a42e
JJ
174 send_gdb "y\n"
175 exp_continue
176 }
177 eof {
178 pass "GDB exits after stopping multithreaded program"
179 }
180 timeout {
181 fail "GDB exits after stopping multithreaded program (timeout)"
182 }
183}
184