Commit | Line | Data |
---|---|---|
7339a42e | 1 | # manythreads.exp -- Expect script to test stopping many threads |
e2882c85 | 2 | # Copyright (C) 2004-2018 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. |
20 | if [target_info exists gdb,nointerrupts] { | |
21 | verbose "Skipping manythreads.exp because of nointerrupts." | |
22 | return | |
23 | } | |
7339a42e | 24 | |
0efbbabc | 25 | standard_testfile |
7339a42e | 26 | |
e5d98164 YQ |
27 | set opts { debug } |
28 | if [info exists DEBUG] { | |
29 | # make check RUNTESTFLAGS='gdb.threads/manythreads.exp DEBUG=1' | |
30 | lappend opts "additional_flags=-DDEBUG" | |
31 | } | |
32 | ||
33 | if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $opts] != "" } { | |
7339a42e JJ |
34 | return -1 |
35 | } | |
36 | ||
0efbbabc | 37 | clean_restart ${binfile} |
12b5d08a | 38 | gdb_test_no_output "set print sevenbit-strings" |
7339a42e JJ |
39 | runto_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 | 43 | gdb_test "shell stty intr '^C'" ".*" |
7339a42e JJ |
44 | |
45 | set message "first continue" | |
46 | gdb_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. | |
57 | remote_expect host 1 { timeout { } } | |
58 | ||
2278c276 PA |
59 | # Send a Ctrl-C and wait for the SIGINT. |
60 | ||
61 | proc 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 | } | |
f303dbd6 | 73 | -re " received signal SIGINT.*$gdb_prompt $" { |
2278c276 PA |
74 | pass "$message" |
75 | } | |
76 | -re "$gdb_prompt $" { | |
77 | # Note that with this regex order, if GDB emits [New | |
00dbd492 PA |
78 | # Thread ...] output between "Thread NNN received signal" |
79 | # and the prompt, the "received signal" regex won't match. | |
f303dbd6 | 80 | # That's good, as if we see that happening, it's a |
2278c276 PA |
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] | |
f303dbd6 | 95 | # Thread NNN received signal SIGINT, Interrupt. |
2278c276 PA |
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 |
109 | interrupt_and_wait "stop threads 1" | |
110 | ||
4339e69e DJ |
111 | set cmd "info threads" |
112 | set ok 0 | |
113 | gdb_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 |
131 | gdb_test_no_output "thread name zardoz" "give a name to the thread" |
132 | gdb_test "info threads" ".*zardoz.*" "check thread name" | |
133 | ||
7339a42e JJ |
134 | set message "second continue" |
135 | gdb_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. | |
146 | set failed 0 | |
147 | remote_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 | } | |
00dbd492 | 154 | -re " received signal SIGINT.*$gdb_prompt $" { |
57380f4e DJ |
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 | 170 | interrupt_and_wait "stop threads 2" |
7339a42e JJ |
171 | |
172 | gdb_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 |