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