Commit | Line | Data |
---|---|---|
7339a42e | 1 | # manythreads.exp -- Expect script to test stopping many threads |
ecd75fc8 | 2 | # Copyright (C) 2004-2014 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 | ||
7339a42e | 19 | |
0efbbabc | 20 | standard_testfile |
7339a42e | 21 | |
e5d98164 YQ |
22 | set opts { debug } |
23 | if [info exists DEBUG] { | |
24 | # make check RUNTESTFLAGS='gdb.threads/manythreads.exp DEBUG=1' | |
25 | lappend opts "additional_flags=-DDEBUG" | |
26 | } | |
27 | ||
28 | if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $opts] != "" } { | |
7339a42e JJ |
29 | return -1 |
30 | } | |
31 | ||
0efbbabc | 32 | clean_restart ${binfile} |
12b5d08a | 33 | gdb_test_no_output "set print sevenbit-strings" |
7339a42e JJ |
34 | runto_main |
35 | ||
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 | # On Ultrix, we don't need it and it is really slow (because shell_escape | |
39 | # doesn't use vfork). | |
40 | if ![istarget "*-*-ultrix*"] then { | |
f6978de9 | 41 | gdb_test "shell stty intr '^C'" ".*" |
7339a42e JJ |
42 | } |
43 | ||
44 | set message "first continue" | |
45 | gdb_test_multiple "continue" "first continue" { | |
46 | -re "error:.*$gdb_prompt $" { | |
47 | fail "$message" | |
48 | } | |
49 | -re "Continuing" { | |
50 | pass "$message" | |
51 | } | |
52 | } | |
53 | ||
57380f4e DJ |
54 | # Wait one second. This is better than the TCL "after" command, because |
55 | # we don't lose GDB's output while we do it. | |
56 | remote_expect host 1 { timeout { } } | |
57 | ||
2278c276 PA |
58 | # Send a Ctrl-C and wait for the SIGINT. |
59 | ||
60 | proc interrupt_and_wait { message } { | |
61 | global gdb_prompt | |
62 | ||
63 | send_gdb "\003" | |
64 | ||
65 | gdb_test_multiple "" $message { | |
66 | -re "\\\[New \[^\]\]*\\\]\r\n" { | |
67 | exp_continue | |
68 | } | |
69 | -re "\\\[\[^\]\]* exited\\\]\r\n" { | |
70 | exp_continue | |
71 | } | |
72 | -re "Program received signal SIGINT.*$gdb_prompt $" { | |
73 | pass "$message" | |
74 | } | |
75 | -re "$gdb_prompt $" { | |
76 | # Note that with this regex order, if GDB emits [New | |
77 | # Thread ...] output between "Program received signal" and | |
78 | # the prompt, the "Program received signal" regex won't | |
79 | # match. That's good, as if we see that happening, it's a | |
80 | # regression. | |
81 | # | |
82 | # GDB makes sure to notify about signal stops, end of | |
83 | # stepping ranges, etc., only after updating the thread | |
84 | # list, otherwise that stop info would be easy to miss. | |
85 | # | |
86 | # A BROKEN example would be: | |
87 | # | |
88 | # ... pages of new threads output ... | |
89 | # [New Thread NNN] | |
90 | # ^C | |
91 | # ... more new threads output ... | |
92 | # [New Thread NNN] | |
93 | # [New Thread NNN] | |
94 | # Program received signal SIGINT, Interrupt. | |
95 | # [New Thread NNN] | |
96 | # [New Thread NNN] | |
97 | # ... pages of new threads output ... | |
98 | # [Switching to Thread NNN] | |
99 | # foo () at foo.c:31 | |
100 | # 31 bar (); | |
101 | # | |
102 | fail $test | |
103 | } | |
104 | } | |
7339a42e JJ |
105 | } |
106 | ||
2278c276 PA |
107 | # Send a Ctrl-C and verify that we can do info threads and continue |
108 | interrupt_and_wait "stop threads 1" | |
109 | ||
4339e69e DJ |
110 | set cmd "info threads" |
111 | set ok 0 | |
112 | gdb_test_multiple $cmd $cmd { | |
a7658b96 | 113 | -re " 1 *Thread " { |
4339e69e DJ |
114 | set ok 1 |
115 | exp_continue | |
116 | } | |
117 | -re ".*\r\n" { | |
118 | # Eat this line and continue, to prevent the buffer overflowing. | |
119 | exp_continue | |
120 | } | |
121 | -re "$gdb_prompt $" { | |
122 | if { $ok } { | |
123 | pass $cmd | |
124 | } else { | |
125 | fail $cmd | |
126 | } | |
127 | } | |
128 | } | |
7339a42e | 129 | |
4694da01 TT |
130 | gdb_test_no_output "thread name zardoz" "give a name to the thread" |
131 | gdb_test "info threads" ".*zardoz.*" "check thread name" | |
132 | ||
7339a42e JJ |
133 | set message "second continue" |
134 | gdb_test_multiple "continue" "second continue" { | |
135 | -re "error:.*$gdb_prompt $" { | |
136 | fail "$message" | |
137 | } | |
138 | -re "Continuing" { | |
139 | pass "$message" | |
140 | } | |
141 | } | |
142 | ||
57380f4e DJ |
143 | # Wait another second. If the program stops on its own, GDB has failed |
144 | # to handle duplicate SIGINTs sent to multiple threads. | |
145 | set failed 0 | |
146 | remote_expect host 1 { | |
147 | -re "\\\[New \[^\]\]*\\\]\r\n" { | |
148 | exp_continue -continue_timer | |
149 | } | |
150 | -re "\\\[\[^\]\]* exited\\\]\r\n" { | |
151 | exp_continue -continue_timer | |
152 | } | |
57380f4e DJ |
153 | -re "Program received signal SIGINT.*$gdb_prompt $" { |
154 | if { $failed == 0 } { | |
155 | fail "check for duplicate SIGINT" | |
156 | } | |
157 | send_gdb "continue\n" | |
158 | set failed 1 | |
159 | exp_continue | |
160 | } | |
161 | timeout { | |
162 | if { $failed == 0 } { | |
163 | pass "check for duplicate SIGINT" | |
164 | } | |
165 | } | |
166 | } | |
167 | ||
7339a42e | 168 | # Send another Ctrl-C and verify that we can do info threads and quit |
2278c276 | 169 | interrupt_and_wait "stop threads 2" |
7339a42e JJ |
170 | |
171 | gdb_test_multiple "quit" "GDB exits after stopping multithreaded program" { | |
b8fa0bfa | 172 | -re "Quit anyway\\? \\(y or n\\) $" { |
7339a42e JJ |
173 | send_gdb "y\n" |
174 | exp_continue | |
175 | } | |
176 | eof { | |
177 | pass "GDB exits after stopping multithreaded program" | |
178 | } | |
179 | timeout { | |
180 | fail "GDB exits after stopping multithreaded program (timeout)" | |
181 | } | |
182 | } | |
183 |