2 # Free Software Foundation, Inc.
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
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
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.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # Please email any bugs, comments, and/or additions to this file to:
24 set testfile "linux-dp"
25 set srcfile ${testfile}.c
26 set binfile ${objdir}/${subdir}/${testfile}
27 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != ""} {
32 gdb_reinitialize_dir $srcdir/$subdir
34 gdb_test_no_output "set print sevenbit-strings"
37 # Run until there are some threads.
38 gdb_breakpoint [gdb_get_line_number "linuxthreads.exp: info threads 2"]
39 gdb_continue_to_breakpoint "main thread's sleep"
41 # Make sure thread list is up-to-date (in case remote targets have not yet
42 # reported thread creation events)
43 gdb_test "info threads"
45 # Create thread names.
46 gdb_test "thread apply 1 thread name threadname_1" \
50 gdb_test "thread apply 2 thread name threadname_2" \
54 gdb_test "thread apply 3 thread name threadname_3" \
58 gdb_test "thread apply 4 thread name threadname_4" \
62 gdb_test "thread apply 5 thread name threadname_5" \
66 gdb_test "thread apply 6 thread name threadname_6" \
70 # Collect thread ids, if any.
71 gdb_test_multiple "info threads" "collect thread id" {
72 -re ". 6 .*\[Tt\]hread (\[0-9a-fA-Fx\]+).* \"threadname_6\" \[^\r\n\]*" {
73 set thread6 $expect_out(1,string)
76 -re ". 5 .*\[Tt\]hread (\[0-9a-fA-Fx\]+).* \"threadname_5\" \[^\r\n\]*" {
77 set thread5 $expect_out(1,string)
80 -re ". 4 .*\[Tt\]hread (\[0-9a-fA-Fx\]+).* \"threadname_4\" \[^\r\n\]*" {
81 set thread4 $expect_out(1,string)
84 -re ". 3 .*\[Tt\]hread (\[0-9a-fA-Fx\]+).* \"threadname_3\" \[^\r\n\]*" {
85 set thread3 $expect_out(1,string)
88 -re ". 2 .*\[Tt\]hread (\[0-9a-fA-Fx\]+).* \"threadname_2\" \[^\r\n\]*" {
89 set thread2 $expect_out(1,string)
92 -re ". 1 .*\[Tt\]hread (\[0-9a-fA-Fx\]+).* \"threadname_1\" \[^\r\n\]*" {
93 set thread1 $expect_out(1,string)
96 -re ".*$gdb_prompt $" {
97 pass "collect thread id"
101 if { [info exists thread6] } then {
102 gdb_test "echo $thread6\\n" "$thread6" "got thread ids"
105 # Collect process ids, if any.
106 gdb_test_multiple "info threads" "collect thread id" {
107 -re ". 6 .*\[Pp\]rocess (\[0-9a-fA-Fx\]+).* \"threadname_6\" \[^\r\n\]*" {
108 set process6 $expect_out(1,string)
111 -re ". 5 .*\[Pp\]rocess (\[0-9a-fA-Fx\]+).* \"threadname_5\" \[^\r\n\]*" {
112 set process5 $expect_out(1,string)
115 -re ". 4 .*\[Pp\]rocess (\[0-9a-fA-Fx\]+).* \"threadname_4\" \[^\r\n\]*" {
116 set process4 $expect_out(1,string)
119 -re ". 3 .*\[Pp\]rocess (\[0-9a-fA-Fx\]+).* \"threadname_3\" \[^\r\n\]*" {
120 set process3 $expect_out(1,string)
123 -re ". 2 .*\[Pp\]rocess (\[0-9a-fA-Fx\]+).* \"threadname_2\" \[^\r\n\]*" {
124 set process2 $expect_out(1,string)
127 -re ". 1 .*\[Pp\]rocess (\[0-9a-fA-Fx\]+).* \"threadname_1\" \[^\r\n\]*" {
128 set process1 $expect_out(1,string)
131 -re ".*$gdb_prompt $" {
132 pass "collect process id"
136 if { [info exists process6] } then {
137 gdb_test "echo $process6\\n" "$process6" "got process ids"
140 # Collect lwp ids, if any.
141 gdb_test_multiple "info threads" "collect thread id" {
142 -re ". 6 .*LWP (\[0-9a-fA-Fx\]+).* \"threadname_6\" \[^\r\n\]*" {
143 set lwp6 $expect_out(1,string)
146 -re ". 5 .*LWP (\[0-9a-fA-Fx\]+).* \"threadname_5\" \[^\r\n\]*" {
147 set lwp5 $expect_out(1,string)
150 -re ". 4 .*LWP (\[0-9a-fA-Fx\]+).* \"threadname_4\" \[^\r\n\]*" {
151 set lwp4 $expect_out(1,string)
154 -re ". 3 .*LWP (\[0-9a-fA-Fx\]+).* \"threadname_3\" \[^\r\n\]*" {
155 set lwp3 $expect_out(1,string)
158 -re ". 2 .*LWP (\[0-9a-fA-Fx\]+).* \"threadname_2\" \[^\r\n\]*" {
159 set lwp2 $expect_out(1,string)
162 -re ". 1 .*LWP (\[0-9a-fA-Fx\]+).* \"threadname_1\" \[^\r\n\]*" {
163 set lwp1 $expect_out(1,string)
166 -re ".*$gdb_prompt $" {
167 pass "collect lwp id"
171 if { [info exists lwp6] } then {
172 gdb_test "echo $lwp6\\n" "$lwp6" "got lwp ids"
176 # Now: test 'thread find' with names.
179 gdb_test "thread find threadname_6" \
180 "Thread 6 has name 'threadname_6'" "find thread name 6"
181 gdb_test "thread find threadname_5" \
182 "Thread 5 has name 'threadname_5'" "find thread name 5"
183 gdb_test "thread find threadname_4" \
184 "Thread 4 has name 'threadname_4'" "find thread name 4"
185 gdb_test "thread find threadname_3" \
186 "Thread 3 has name 'threadname_3'" "find thread name 3"
187 gdb_test "thread find threadname_2" \
188 "Thread 2 has name 'threadname_2'" "find thread name 2"
189 gdb_test "thread find threadname_1" \
190 "Thread 1 has name 'threadname_1'" "find thread name 1"
193 # Test 'thread find' with thread ids, if any.
196 if { [info exists thread6] } then {
197 gdb_test "thread find $thread6" \
198 "Thread 6 has .*$thread6.*" "find thread id 6"
199 gdb_test "thread find $thread5" \
200 "Thread 5 has .*$thread5.*" "find thread id 5"
201 gdb_test "thread find $thread4" \
202 "Thread 4 has .*$thread4.*" "find thread id 4"
203 gdb_test "thread find $thread3" \
204 "Thread 3 has .*$thread3.*" "find thread id 3"
205 gdb_test "thread find $thread2" \
206 "Thread 2 has .*$thread2.*" "find thread id 2"
207 gdb_test "thread find $thread1" \
208 "Thread 1 has .*$thread1.*" "find thread id 1"
212 # Test 'thread find' with process ids, if any.
215 if { [info exists process6] } then {
216 gdb_test "thread find $process6" \
217 "Thread 6 has .*$process6.*" "find process id 6"
218 gdb_test "thread find $process5" \
219 "Thread 5 has .*$process5.*" "find process id 5"
220 gdb_test "thread find $process4" \
221 "Thread 4 has .*$process4.*" "find process id 4"
222 gdb_test "thread find $process3" \
223 "Thread 3 has .*$process3.*" "find process id 3"
224 gdb_test "thread find $process2" \
225 "Thread 2 has .*$process2.*" "find process id 2"
226 gdb_test "thread find $process1" \
227 "Thread 1 has .*$process1.*" "find process id 1"
231 # Test 'thread find' with lwp ids, if any.
234 if { [info exists lwp6] } then {
235 gdb_test "thread find $lwp6" \
236 "Thread 6 has .*$lwp6.*" "find lwp id 6"
237 gdb_test "thread find $lwp5" \
238 "Thread 5 has .*$lwp5.*" "find lwp id 5"
239 gdb_test "thread find $lwp4" \
240 "Thread 4 has .*$lwp4.*" "find lwp id 4"
241 gdb_test "thread find $lwp3" \
242 "Thread 3 has .*$lwp3.*" "find lwp id 3"
243 gdb_test "thread find $lwp2" \
244 "Thread 2 has .*$lwp2.*" "find lwp id 2"
245 gdb_test "thread find $lwp1" \
246 "Thread 1 has .*$lwp1.*" "find lwp id 1"
251 gdb_test "thread find foobarbaz" "No threads match .*" "no thread"
254 # Test regular expression
264 gdb_test_multiple "thread find threadname_\[345\]" "test regular exp" {
265 -re "Thread 6 has name \[^\r\n\]*" {
269 -re "Thread 5 has name \[^\r\n\]*" {
273 -re "Thread 4 has name \[^\r\n\]*" {
277 -re "Thread 3 has name \[^\r\n\]*" {
281 -re "Thread 2 has name \[^\r\n\]*" {
285 -re "Thread 1 has name \[^\r\n\]*" {
289 -re ".*$gdb_prompt $" {
290 if { $see3 && $see4 && $see5 && !$see1 && !$see2 && !$see6 } then {
291 pass "test regular exp"
293 fail "test regular exp"
299 # Test info threads on a subset of threads
309 gdb_test_multiple "info threads 2 4 6" "info threads 2 4 6" {
310 -re ". 6 \[^\r\n\]*\"threadname_6\" \[^\r\n\]*" {
314 -re ". 5 \[^\r\n\]*\"threadname_5\" \[^\r\n\]*" {
318 -re ". 4 \[^\r\n\]*\"threadname_4\" \[^\r\n\]*" {
322 -re ". 3 \[^\r\n\]*\"threadname_3\" \[^\r\n\]*" {
326 -re ". 2 \[^\r\n\]*\"threadname_2\" \[^\r\n\]*" {
330 -re ". 1 \[^\r\n\]*\"threadname_1\" \[^\r\n\]*" {
334 -re "$gdb_prompt $" {
335 if { $see2 && $see4 && $see6 && !$see1 && !$see3 && !$see5 } then {
336 pass "info threads 2 4 6"
338 fail "info threads 2 4 6"
344 # Test info threads on a range
354 gdb_test_multiple "info threads 3-5" "info threads 3-5" {
355 -re ". 6 .*\"threadname_6\" \[^\r\n\]*" {
359 -re ". 5 .*\"threadname_5\" \[^\r\n\]*" {
363 -re ". 4 .*\"threadname_4\" \[^\r\n\]*" {
367 -re ". 3 .*\"threadname_3\" \[^\r\n\]*" {
371 -re ". 2 .*\"threadname_2\" \[^\r\n\]*" {
375 -re ". 1 .*\"threadname_1\" \[^\r\n\]*" {
379 -re "$gdb_prompt $" {
380 if { $see3 && $see4 && $see5 && !$see1 && !$see2 && !$see6 } then {
381 pass "info threads 3-5"
383 fail "info threads 3-5"
388 # Test inverted range
390 gdb_test "info threads 5-3" "inverted range" "test inverted range"
392 # Test degenerate range
401 gdb_test_multiple "info threads 3-3" "info threads 3-3" {
402 -re ". 6 .*\"threadname_6\" \[^\r\n\]*" {
406 -re ". 5 .*\"threadname_5\" \[^\r\n\]*" {
410 -re ". 4 .*\"threadname_4\" \[^\r\n\]*" {
414 -re ". 3 .*\"threadname_3\" \[^\r\n\]*" {
418 -re ". 2 .*\"threadname_2\" \[^\r\n\]*" {
422 -re ". 1 .*\"threadname_1\" \[^\r\n\]*" {
426 -re ".*$gdb_prompt $" {
427 if { $see3 && !$see1 && !$see2 && !$see4 && !$see5 && !$see6 } then {
428 pass "info threads 3-3"
430 fail "info threads 3-3"
437 gdb_test "info thread foo" \
438 "Args must be numbers or '.' variables." \
441 gdb_test "info thread foo -1" \
442 "Args must be numbers or '.' variables." \