Commit | Line | Data |
---|---|---|
ecd75fc8 | 1 | # Copyright (C) 1996-2014 Free Software Foundation, Inc. |
c906108c SS |
2 | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
c906108c | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
c906108c SS |
8 | # This program is distributed in the hope that it will be useful, |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
e22f8b7c | 12 | # |
c906108c | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c906108c | 15 | |
c906108c SS |
16 | # This file was written by Fred Fish. (fnf@cygnus.com) |
17 | ||
c906108c | 18 | |
0efbbabc | 19 | standard_testfile |
c906108c SS |
20 | |
21 | # regexp for "horizontal" text (i.e. doesn't include newline or | |
22 | # carriage return) | |
23 | set horiz "\[^\n\r\]*" | |
24 | ||
c906108c SS |
25 | if [istarget "*-*-linux"] then { |
26 | set target_cflags "-D_MIT_POSIX_THREADS" | |
27 | } else { | |
28 | set target_cflags "" | |
29 | } | |
b6ff0e81 | 30 | |
0efbbabc | 31 | if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable debug] != "" } { |
b5ab8ff3 | 32 | return -1 |
c906108c SS |
33 | } |
34 | ||
0efbbabc | 35 | clean_restart ${binfile} |
c906108c | 36 | |
12b5d08a MS |
37 | gdb_test_no_output "set print sevenbit-strings" |
38 | #gdb_test_no_output "set print address off" | |
39 | gdb_test_no_output "set width 0" | |
c906108c SS |
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'" ".*" |
c906108c SS |
44 | |
45 | proc all_threads_running {} { | |
46 | global gdb_prompt | |
47 | global srcfile | |
48 | ||
49 | # Reset all the counters to zero. | |
12b5d08a MS |
50 | gdb_test_no_output "set var common_routine::hits=0" |
51 | gdb_test_no_output "set var common_routine::from_thread1=0" | |
52 | gdb_test_no_output "set var common_routine::from_thread2=0" | |
53 | gdb_test_no_output "set var common_routine::from_main=0" | |
54 | gdb_test_no_output "set var common_routine::full_coverage=0" | |
c906108c SS |
55 | |
56 | # Disable all breakpoints. | |
12b5d08a | 57 | gdb_test_no_output "disable" |
c906108c SS |
58 | |
59 | # Set up a breakpoint that will cause us to stop when we have | |
60 | # been called 15 times. This should be plenty of time to allow | |
61 | # every thread to run at least once, since each thread sleeps for | |
62 | # one second between calls to common_routine. | |
f6978de9 | 63 | gdb_test "tbreak common_routine if hits >= 15" ".*" |
c906108c SS |
64 | |
65 | # Start all the threads running again and wait for the inferior | |
66 | # to stop. Since no other breakpoints are set at this time | |
67 | # we should stop only when we have been previously called 15 times. | |
68 | ||
9db70545 MS |
69 | set return_me 1 |
70 | ||
71 | gdb_test_multiple "continue" "continue until common routine run 15 times" { | |
72 | -re "Continuing.*common_routine.*at.*$srcfile.*$gdb_prompt $" { | |
73 | set return_me 0 | |
c906108c SS |
74 | } |
75 | } | |
76 | ||
9db70545 | 77 | if { $return_me == 1 } then { |
ae59b1da | 78 | return 0 |
9db70545 MS |
79 | } |
80 | ||
c906108c SS |
81 | # Check that we stopped when we actually expected to stop, by |
82 | # verifying that there have been 15 previous hits. | |
83 | ||
2f09097b ND |
84 | # NOTE: Because of synchronization behavior, it is possible for |
85 | # more than one thread to increment "hits" between one breakpoint | |
86 | # trap and the next. So stopping after 16 or 17 hits should be | |
87 | # considered acceptable. | |
88 | ||
9db70545 MS |
89 | gdb_test_multiple "p common_routine::hits" \ |
90 | "stopped before calling common_routine 15 times" { | |
91 | -re ".*= 15\r\n$gdb_prompt $" { | |
92 | pass "stopped before calling common_routine 15 times" | |
93 | } | |
94 | -re ".*= 16\r\n$gdb_prompt $" { | |
95 | pass "stopped before calling common_routine 15 times (16 times)" | |
96 | } | |
97 | -re ".*= 17\r\n$gdb_prompt $" { | |
98 | pass "stopped before calling common_routine 15 times (17 times)" | |
99 | } | |
c906108c | 100 | } |
c906108c SS |
101 | |
102 | # Also check that all of the threads have run, which will only be true | |
103 | # if the full_coverage variable is set. | |
104 | ||
9db70545 MS |
105 | set return_me 1 |
106 | gdb_test_multiple "p common_routine::full_coverage" \ | |
107 | "some threads didn't run" { | |
108 | -re ".* = 1.*$gdb_prompt $" { | |
109 | } | |
110 | -re ".* = 0.*$gdb_prompt $" { | |
111 | fail "some threads didn't run" | |
112 | set return_me 0 | |
113 | } | |
c906108c | 114 | } |
c906108c SS |
115 | |
116 | # Looks fine, return success. | |
9db70545 | 117 | return $return_me |
c906108c SS |
118 | } |
119 | ||
120 | proc test_startup {} { | |
121 | global srcdir srcfile gdb_prompt expect_out | |
122 | global horiz | |
123 | global main_id thread1_id thread2_id | |
124 | ||
125 | # We should be able to do an info threads before starting any others. | |
9db70545 MS |
126 | set return_me 1 |
127 | gdb_test_multiple "info threads" "info threads" { | |
ae23c492 | 128 | -re ".*Thread.*main.*$gdb_prompt $" { |
c906108c | 129 | pass "info threads" |
9db70545 | 130 | set return_me 0 |
c906108c SS |
131 | } |
132 | -re "\r\n$gdb_prompt $" { | |
ae23c492 | 133 | unsupported "gdb does not support pthreads for this machine" |
c906108c SS |
134 | } |
135 | } | |
136 | ||
9db70545 | 137 | if { $return_me == 1 } then { |
ae59b1da | 138 | return 0 |
9db70545 MS |
139 | } |
140 | ||
c906108c | 141 | # Extract the thread id number of main thread from "info threads" output. |
9db70545 MS |
142 | gdb_test_multiple "info threads" "get main thread id" { |
143 | -re "(\[0-9\]+)(${horiz}Thread${horiz}main.*)($gdb_prompt $)" { | |
144 | } | |
145 | } | |
146 | ||
c906108c SS |
147 | set main_id $expect_out(1,string) |
148 | ||
149 | # Check that we can continue and create the first thread. | |
2a11c64d | 150 | gdb_test "break thread1" "Breakpoint .* file .*$srcfile.*" |
c906108c SS |
151 | gdb_test "continue" \ |
152 | "Continuing.*Breakpoint .*, thread1 \\(arg=0xfeedface\\).*at.*$srcfile.*" \ | |
153 | "Continue to creation of first thread" | |
12b5d08a | 154 | gdb_test_no_output "disable" |
c906108c SS |
155 | |
156 | # Extract the thread id number of thread 1 from "info threads" output. | |
9db70545 MS |
157 | gdb_test_multiple "info threads" "get thread 1 id" { |
158 | -re "(\[0-9\]+)(${horiz}Thread${horiz}thread1.*)($gdb_prompt $)" { | |
159 | } | |
160 | } | |
161 | ||
c906108c SS |
162 | set thread1_id $expect_out(1,string) |
163 | ||
164 | # Check that we can continue and create the second thread, | |
165 | # ignoring the first thread for the moment. | |
2a11c64d | 166 | gdb_test "break thread2" "Breakpoint .* file .*$srcfile.*" |
c906108c SS |
167 | gdb_test "continue" \ |
168 | "Continuing.*Breakpoint .*, thread2 \\(arg=0xdeadbeef\\).*at.*$srcfile.*" \ | |
169 | "Continue to creation of second thread" | |
170 | ||
171 | # Extract the thread id number of thread 2 from "info threads" output. | |
9db70545 MS |
172 | gdb_test_multiple "info threads" "get thread 2 id" { |
173 | -re "(\[0-9\]+)(${horiz}Thread${horiz}thread2.*)($gdb_prompt $)" { | |
174 | } | |
175 | } | |
176 | ||
c906108c SS |
177 | set thread2_id $expect_out(1,string) |
178 | ||
179 | return 1 | |
180 | } | |
181 | ||
182 | proc check_control_c {} { | |
183 | global gdb_prompt | |
184 | ||
185 | # Verify that all threads are running. | |
186 | if [all_threads_running] then { | |
187 | pass "All threads running after startup" | |
188 | } | |
189 | ||
190 | # Send a continue followed by ^C to the process to stop it. | |
9db70545 | 191 | gdb_test_multiple "continue" "continue with all threads running" { |
8f0cbc1c DJ |
192 | -re "Continuing." { |
193 | pass "Continue with all threads running" | |
194 | } | |
8f0cbc1c | 195 | } |
51d01eda MC |
196 | after 2000 |
197 | send_gdb "\003" | |
c906108c | 198 | set description "Stopped with a ^C" |
c906108c SS |
199 | gdb_expect { |
200 | -re "Program received signal SIGINT.*$gdb_prompt $" { | |
201 | pass $description | |
202 | } | |
203 | -re "Quit.*$gdb_prompt $" { | |
204 | pass $description | |
205 | } | |
206 | timeout { | |
207 | fail "$description (timeout)" | |
ae59b1da | 208 | return 1 |
c906108c SS |
209 | } |
210 | } | |
f6978de9 | 211 | gdb_test "bt" ".*" |
c906108c SS |
212 | |
213 | # Verify that all threads can be run again after a ^C stop. | |
214 | if [all_threads_running] then { | |
215 | pass "All threads running after continuing from ^C stop" | |
216 | } | |
ae59b1da | 217 | return 0 |
c906108c SS |
218 | } |
219 | ||
220 | proc check_backtraces {} { | |
221 | global gdb_prompt main_id thread1_id thread2_id | |
222 | ||
223 | # Check that the "thread apply N backtrace" command works | |
224 | ||
225 | gdb_test "thread apply $main_id backtrace" \ | |
226 | ".* in main \\(argc=.*, argv=.*\\).*" \ | |
227 | "check backtrace from main thread" | |
228 | gdb_test "thread apply $thread1_id backtrace" \ | |
229 | ".* in thread1 \\(arg=0xfeedface\\).*" \ | |
230 | "check backtrace from thread 1" | |
231 | gdb_test "thread apply $thread2_id backtrace" \ | |
232 | ".* in thread2 \\(arg=0xdeadbeef\\).*" \ | |
233 | "check backtrace from thread 2" | |
234 | ||
235 | # Check that we can apply the backtrace command to all | |
236 | # three threads with a single gdb command | |
237 | ||
238 | gdb_test "thread apply $main_id $thread1_id $thread2_id bt" \ | |
239 | ".* in main .* in thread1 .* in thread2.*" \ | |
240 | "apply backtrace command to all three threads" | |
241 | ||
242 | # Check that we can do thread specific backtraces | |
243 | # This also tests that we can do thread specific breakpoints. | |
244 | ||
245 | gdb_test "break common_routine thread $thread2_id" \ | |
246 | "Breakpoint .* at 0x.* file .* line .*" \ | |
247 | "set break at common_routine in thread 2" | |
248 | ||
9db70545 | 249 | gdb_test_multiple "continue" "continue to bkpt at common_routine in thread 2" { |
88caa9b9 | 250 | -re "Breakpoint .* common_routine \\(arg=2\\).*$gdb_prompt $" { |
cf74b8ca | 251 | pass "continue to bkpt at common_routine in thread 2" |
9db70545 MS |
252 | gdb_test "backtrace" \ |
253 | "#0.*common_routine \\(arg=2\\).*#1.*thread2.*" \ | |
254 | "backtrace from thread 2 bkpt in common_routine" | |
c906108c | 255 | } |
88caa9b9 | 256 | -re "Breakpoint .* common_routine \\(arg=0\\).*$gdb_prompt $" { |
cf74b8ca | 257 | fail "continue to bkpt at common_routine in thread 2 (arg=0)" |
c906108c | 258 | } |
88caa9b9 | 259 | -re "Breakpoint .* common_routine \\(arg=1\\).*$gdb_prompt $" { |
cf74b8ca | 260 | fail "continue to bkpt at common_routine in thread 2 (arg=1)" |
c906108c | 261 | } |
c906108c SS |
262 | } |
263 | } | |
264 | ||
c906108c | 265 | if [runto_main] then { |
c906108c | 266 | if [test_startup] then { |
da55addb MS |
267 | if [check_control_c] then { |
268 | warning "Could not stop child with ^C; skipping rest of tests.\n" | |
4ec70201 | 269 | return |
da55addb | 270 | } |
c906108c SS |
271 | check_backtraces |
272 | } | |
273 | } |