]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.threads/manythreads.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / manythreads.exp
CommitLineData
7339a42e 1# manythreads.exp -- Expect script to test stopping many threads
213516ef 2# Copyright (C) 2004-2023 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
de153775
TV
66 set saw_signal 0
67 set order_ok 1
2278c276 68 gdb_test_multiple "" $message {
de153775
TV
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
2278c276
PA
72 # regression.
73 #
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.
77 #
78 # A BROKEN example would be:
79 #
80 # ... pages of new threads output ...
81 # [New Thread NNN]
82 # ^C
83 # ... more new threads output ...
84 # [New Thread NNN]
85 # [New Thread NNN]
f303dbd6 86 # Thread NNN received signal SIGINT, Interrupt.
2278c276
PA
87 # [New Thread NNN]
88 # [New Thread NNN]
89 # ... pages of new threads output ...
90 # [Switching to Thread NNN]
91 # foo () at foo.c:31
92 # 31 bar ();
93 #
de153775
TV
94 if { $saw_signal } {
95 set order_ok 0
96 }
97 exp_continue
98 }
99 -re "\r\n\\\[\[^\r\n]* exited\\\](?=\r\n)" {
100 exp_continue
101 }
102 -re "\r\n\[^\r\n]* received signal SIGINT\[^\r\n\]*(?=\r\n)" {
103 set saw_signal 1
104 exp_continue
105 }
106 -re -wrap "" {
107 gdb_assert {$saw_signal && $order_ok} $gdb_test_name
2278c276
PA
108 }
109 }
7339a42e
JJ
110}
111
2278c276
PA
112# Send a Ctrl-C and verify that we can do info threads and continue
113interrupt_and_wait "stop threads 1"
114
4339e69e
DJ
115set cmd "info threads"
116set ok 0
117gdb_test_multiple $cmd $cmd {
a7658b96 118 -re " 1 *Thread " {
4339e69e
DJ
119 set ok 1
120 exp_continue
121 }
122 -re ".*\r\n" {
123 # Eat this line and continue, to prevent the buffer overflowing.
124 exp_continue
125 }
126 -re "$gdb_prompt $" {
127 if { $ok } {
128 pass $cmd
129 } else {
130 fail $cmd
131 }
132 }
133}
7339a42e 134
4694da01
TT
135gdb_test_no_output "thread name zardoz" "give a name to the thread"
136gdb_test "info threads" ".*zardoz.*" "check thread name"
137
7339a42e
JJ
138set message "second continue"
139gdb_test_multiple "continue" "second continue" {
140 -re "error:.*$gdb_prompt $" {
141 fail "$message"
142 }
143 -re "Continuing" {
144 pass "$message"
145 }
146}
147
57380f4e
DJ
148# Wait another second. If the program stops on its own, GDB has failed
149# to handle duplicate SIGINTs sent to multiple threads.
150set failed 0
151remote_expect host 1 {
152 -re "\\\[New \[^\]\]*\\\]\r\n" {
153 exp_continue -continue_timer
154 }
155 -re "\\\[\[^\]\]* exited\\\]\r\n" {
156 exp_continue -continue_timer
157 }
00dbd492 158 -re " received signal SIGINT.*$gdb_prompt $" {
57380f4e
DJ
159 if { $failed == 0 } {
160 fail "check for duplicate SIGINT"
161 }
162 send_gdb "continue\n"
163 set failed 1
164 exp_continue
165 }
166 timeout {
167 if { $failed == 0 } {
168 pass "check for duplicate SIGINT"
169 }
170 }
171}
172
7339a42e 173# Send another Ctrl-C and verify that we can do info threads and quit
2278c276 174interrupt_and_wait "stop threads 2"
7339a42e
JJ
175
176gdb_test_multiple "quit" "GDB exits after stopping multithreaded program" {
b8fa0bfa 177 -re "Quit anyway\\? \\(y or n\\) $" {
7339a42e
JJ
178 send_gdb "y\n"
179 exp_continue
180 }
181 eof {
182 pass "GDB exits after stopping multithreaded program"
183 }
184 timeout {
185 fail "GDB exits after stopping multithreaded program (timeout)"
186 }
187}
188