1 # Copyright 2011-2012 Free Software Foundation, Inc.
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
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Please email any bugs, comments, and/or additions to this file to:
19 set testfile "linux-dp"
20 set srcfile ${testfile}.c
21 set binfile ${objdir}/${subdir}/${testfile}
22 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != ""} {
27 gdb_reinitialize_dir $srcdir/$subdir
29 gdb_test_no_output "set print sevenbit-strings"
32 # Run until there are some threads.
33 gdb_breakpoint [gdb_get_line_number "linuxthreads.exp: info threads 2"]
34 gdb_continue_to_breakpoint "main thread's sleep"
36 # Make sure thread list is up-to-date (in case remote targets have not yet
37 # reported thread creation events)
38 gdb_test "info threads"
40 # Create thread names.
41 gdb_test "thread apply 1 thread name threadname_1" \
45 gdb_test "thread apply 2 thread name threadname_2" \
49 gdb_test "thread apply 3 thread name threadname_3" \
53 gdb_test "thread apply 4 thread name threadname_4" \
57 gdb_test "thread apply 5 thread name threadname_5" \
61 gdb_test "thread apply 6 thread name threadname_6" \
65 # Collect thread ids, if any.
66 gdb_test_multiple "info threads" "collect thread id" {
67 -re ". 6 .*\[Tt\]hread (\[0-9a-fA-Fx\]+).* \"threadname_6\" \[^\r\n\]*" {
68 set thread6 $expect_out(1,string)
71 -re ". 5 .*\[Tt\]hread (\[0-9a-fA-Fx\]+).* \"threadname_5\" \[^\r\n\]*" {
72 set thread5 $expect_out(1,string)
75 -re ". 4 .*\[Tt\]hread (\[0-9a-fA-Fx\]+).* \"threadname_4\" \[^\r\n\]*" {
76 set thread4 $expect_out(1,string)
79 -re ". 3 .*\[Tt\]hread (\[0-9a-fA-Fx\]+).* \"threadname_3\" \[^\r\n\]*" {
80 set thread3 $expect_out(1,string)
83 -re ". 2 .*\[Tt\]hread (\[0-9a-fA-Fx\]+).* \"threadname_2\" \[^\r\n\]*" {
84 set thread2 $expect_out(1,string)
87 -re ". 1 .*\[Tt\]hread (\[0-9a-fA-Fx\]+).* \"threadname_1\" \[^\r\n\]*" {
88 set thread1 $expect_out(1,string)
91 -re ".*$gdb_prompt $" {
92 pass "collect thread id"
96 if { [info exists thread6] } then {
97 gdb_test "echo $thread6\\n" "$thread6" "got thread ids"
100 # Collect process ids, if any.
101 gdb_test_multiple "info threads" "collect thread id" {
102 -re ". 6 .*\[Pp\]rocess (\[0-9a-fA-Fx\]+).* \"threadname_6\" \[^\r\n\]*" {
103 set process6 $expect_out(1,string)
106 -re ". 5 .*\[Pp\]rocess (\[0-9a-fA-Fx\]+).* \"threadname_5\" \[^\r\n\]*" {
107 set process5 $expect_out(1,string)
110 -re ". 4 .*\[Pp\]rocess (\[0-9a-fA-Fx\]+).* \"threadname_4\" \[^\r\n\]*" {
111 set process4 $expect_out(1,string)
114 -re ". 3 .*\[Pp\]rocess (\[0-9a-fA-Fx\]+).* \"threadname_3\" \[^\r\n\]*" {
115 set process3 $expect_out(1,string)
118 -re ". 2 .*\[Pp\]rocess (\[0-9a-fA-Fx\]+).* \"threadname_2\" \[^\r\n\]*" {
119 set process2 $expect_out(1,string)
122 -re ". 1 .*\[Pp\]rocess (\[0-9a-fA-Fx\]+).* \"threadname_1\" \[^\r\n\]*" {
123 set process1 $expect_out(1,string)
126 -re ".*$gdb_prompt $" {
127 pass "collect process id"
131 if { [info exists process6] } then {
132 gdb_test "echo $process6\\n" "$process6" "got process ids"
135 # Collect lwp ids, if any.
136 gdb_test_multiple "info threads" "collect thread id" {
137 -re ". 6 .*LWP (\[0-9a-fA-Fx\]+).* \"threadname_6\" \[^\r\n\]*" {
138 set lwp6 $expect_out(1,string)
141 -re ". 5 .*LWP (\[0-9a-fA-Fx\]+).* \"threadname_5\" \[^\r\n\]*" {
142 set lwp5 $expect_out(1,string)
145 -re ". 4 .*LWP (\[0-9a-fA-Fx\]+).* \"threadname_4\" \[^\r\n\]*" {
146 set lwp4 $expect_out(1,string)
149 -re ". 3 .*LWP (\[0-9a-fA-Fx\]+).* \"threadname_3\" \[^\r\n\]*" {
150 set lwp3 $expect_out(1,string)
153 -re ". 2 .*LWP (\[0-9a-fA-Fx\]+).* \"threadname_2\" \[^\r\n\]*" {
154 set lwp2 $expect_out(1,string)
157 -re ". 1 .*LWP (\[0-9a-fA-Fx\]+).* \"threadname_1\" \[^\r\n\]*" {
158 set lwp1 $expect_out(1,string)
161 -re ".*$gdb_prompt $" {
162 pass "collect lwp id"
166 if { [info exists lwp6] } then {
167 gdb_test "echo $lwp6\\n" "$lwp6" "got lwp ids"
171 # Now: test 'thread find' with names.
174 gdb_test "thread find threadname_6" \
175 "Thread 6 has name 'threadname_6'" "find thread name 6"
176 gdb_test "thread find threadname_5" \
177 "Thread 5 has name 'threadname_5'" "find thread name 5"
178 gdb_test "thread find threadname_4" \
179 "Thread 4 has name 'threadname_4'" "find thread name 4"
180 gdb_test "thread find threadname_3" \
181 "Thread 3 has name 'threadname_3'" "find thread name 3"
182 gdb_test "thread find threadname_2" \
183 "Thread 2 has name 'threadname_2'" "find thread name 2"
184 gdb_test "thread find threadname_1" \
185 "Thread 1 has name 'threadname_1'" "find thread name 1"
188 # Test 'thread find' with thread ids, if any.
191 if { [info exists thread6] } then {
192 gdb_test "thread find $thread6" \
193 "Thread 6 has .*$thread6.*" "find thread id 6"
194 gdb_test "thread find $thread5" \
195 "Thread 5 has .*$thread5.*" "find thread id 5"
196 gdb_test "thread find $thread4" \
197 "Thread 4 has .*$thread4.*" "find thread id 4"
198 gdb_test "thread find $thread3" \
199 "Thread 3 has .*$thread3.*" "find thread id 3"
200 gdb_test "thread find $thread2" \
201 "Thread 2 has .*$thread2.*" "find thread id 2"
202 gdb_test "thread find $thread1" \
203 "Thread 1 has .*$thread1.*" "find thread id 1"
207 # Test 'thread find' with process ids, if any.
210 if { [info exists process6] } then {
211 gdb_test "thread find $process6" \
212 "Thread 6 has .*$process6.*" "find process id 6"
213 gdb_test "thread find $process5" \
214 "Thread 5 has .*$process5.*" "find process id 5"
215 gdb_test "thread find $process4" \
216 "Thread 4 has .*$process4.*" "find process id 4"
217 gdb_test "thread find $process3" \
218 "Thread 3 has .*$process3.*" "find process id 3"
219 gdb_test "thread find $process2" \
220 "Thread 2 has .*$process2.*" "find process id 2"
221 gdb_test "thread find $process1" \
222 "Thread 1 has .*$process1.*" "find process id 1"
226 # Test 'thread find' with lwp ids, if any.
229 if { [info exists lwp6] } then {
230 gdb_test "thread find $lwp6" \
231 "Thread 6 has .*$lwp6.*" "find lwp id 6"
232 gdb_test "thread find $lwp5" \
233 "Thread 5 has .*$lwp5.*" "find lwp id 5"
234 gdb_test "thread find $lwp4" \
235 "Thread 4 has .*$lwp4.*" "find lwp id 4"
236 gdb_test "thread find $lwp3" \
237 "Thread 3 has .*$lwp3.*" "find lwp id 3"
238 gdb_test "thread find $lwp2" \
239 "Thread 2 has .*$lwp2.*" "find lwp id 2"
240 gdb_test "thread find $lwp1" \
241 "Thread 1 has .*$lwp1.*" "find lwp id 1"
246 gdb_test "thread find foobarbaz" "No threads match .*" "no thread"
249 # Test regular expression
259 gdb_test_multiple "thread find threadname_\[345\]" "test regular exp" {
260 -re "Thread 6 has name \[^\r\n\]*" {
264 -re "Thread 5 has name \[^\r\n\]*" {
268 -re "Thread 4 has name \[^\r\n\]*" {
272 -re "Thread 3 has name \[^\r\n\]*" {
276 -re "Thread 2 has name \[^\r\n\]*" {
280 -re "Thread 1 has name \[^\r\n\]*" {
284 -re ".*$gdb_prompt $" {
285 if { $see3 && $see4 && $see5 && !$see1 && !$see2 && !$see6 } then {
286 pass "test regular exp"
288 fail "test regular exp"
294 # Test info threads on a subset of threads
304 gdb_test_multiple "info threads 2 4 6" "info threads 2 4 6" {
305 -re ". 6 \[^\r\n\]*\"threadname_6\" \[^\r\n\]*" {
309 -re ". 5 \[^\r\n\]*\"threadname_5\" \[^\r\n\]*" {
313 -re ". 4 \[^\r\n\]*\"threadname_4\" \[^\r\n\]*" {
317 -re ". 3 \[^\r\n\]*\"threadname_3\" \[^\r\n\]*" {
321 -re ". 2 \[^\r\n\]*\"threadname_2\" \[^\r\n\]*" {
325 -re ". 1 \[^\r\n\]*\"threadname_1\" \[^\r\n\]*" {
329 -re "$gdb_prompt $" {
330 if { $see2 && $see4 && $see6 && !$see1 && !$see3 && !$see5 } then {
331 pass "info threads 2 4 6"
333 fail "info threads 2 4 6"
339 # Test info threads on a range
349 gdb_test_multiple "info threads 3-5" "info threads 3-5" {
350 -re ". 6 .*\"threadname_6\" \[^\r\n\]*" {
354 -re ". 5 .*\"threadname_5\" \[^\r\n\]*" {
358 -re ". 4 .*\"threadname_4\" \[^\r\n\]*" {
362 -re ". 3 .*\"threadname_3\" \[^\r\n\]*" {
366 -re ". 2 .*\"threadname_2\" \[^\r\n\]*" {
370 -re ". 1 .*\"threadname_1\" \[^\r\n\]*" {
374 -re "$gdb_prompt $" {
375 if { $see3 && $see4 && $see5 && !$see1 && !$see2 && !$see6 } then {
376 pass "info threads 3-5"
378 fail "info threads 3-5"
383 # Test inverted range
385 gdb_test "info threads 5-3" "inverted range" "test inverted range"
387 # Test degenerate range
396 gdb_test_multiple "info threads 3-3" "info threads 3-3" {
397 -re ". 6 .*\"threadname_6\" \[^\r\n\]*" {
401 -re ". 5 .*\"threadname_5\" \[^\r\n\]*" {
405 -re ". 4 .*\"threadname_4\" \[^\r\n\]*" {
409 -re ". 3 .*\"threadname_3\" \[^\r\n\]*" {
413 -re ". 2 .*\"threadname_2\" \[^\r\n\]*" {
417 -re ". 1 .*\"threadname_1\" \[^\r\n\]*" {
421 -re ".*$gdb_prompt $" {
422 if { $see3 && !$see1 && !$see2 && !$see4 && !$see5 && !$see6 } then {
423 pass "info threads 3-3"
425 fail "info threads 3-3"
432 gdb_test "info thread foo" \
433 "Args must be numbers or '.' variables." \
436 gdb_test "info thread foo -1" \
437 "Args must be numbers or '.' variables." \