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 # Create thread names.
42 gdb_test "thread apply 1 thread name threadname_1" \
46 gdb_test "thread apply 2 thread name threadname_2" \
50 gdb_test "thread apply 3 thread name threadname_3" \
54 gdb_test "thread apply 4 thread name threadname_4" \
58 gdb_test "thread apply 5 thread name threadname_5" \
62 gdb_test "thread apply 6 thread name threadname_6" \
66 # Collect thread ids, if any.
67 gdb_test_multiple "info threads" "collect thread id" {
68 -re ". 6 .*\[Tt\]hread (\[0-9a-fA-Fx\]+).* \"threadname_6\" \[^\r\n\]*" {
69 set thread6 $expect_out(1,string)
72 -re ". 5 .*\[Tt\]hread (\[0-9a-fA-Fx\]+).* \"threadname_5\" \[^\r\n\]*" {
73 set thread5 $expect_out(1,string)
76 -re ". 4 .*\[Tt\]hread (\[0-9a-fA-Fx\]+).* \"threadname_4\" \[^\r\n\]*" {
77 set thread4 $expect_out(1,string)
80 -re ". 3 .*\[Tt\]hread (\[0-9a-fA-Fx\]+).* \"threadname_3\" \[^\r\n\]*" {
81 set thread3 $expect_out(1,string)
84 -re ". 2 .*\[Tt\]hread (\[0-9a-fA-Fx\]+).* \"threadname_2\" \[^\r\n\]*" {
85 set thread2 $expect_out(1,string)
88 -re ". 1 .*\[Tt\]hread (\[0-9a-fA-Fx\]+).* \"threadname_1\" \[^\r\n\]*" {
89 set thread1 $expect_out(1,string)
92 -re ".*$gdb_prompt $" {
93 pass "collect thread id"
97 if { [info exists thread6] } then {
98 gdb_test "echo $thread6\\n" "$thread6" "got thread ids"
101 # Collect process ids, if any.
102 gdb_test_multiple "info threads" "collect thread id" {
103 -re ". 6 .*\[Pp\]rocess (\[0-9a-fA-Fx\]+).* \"threadname_6\" \[^\r\n\]*" {
104 set process6 $expect_out(1,string)
107 -re ". 5 .*\[Pp\]rocess (\[0-9a-fA-Fx\]+).* \"threadname_5\" \[^\r\n\]*" {
108 set process5 $expect_out(1,string)
111 -re ". 4 .*\[Pp\]rocess (\[0-9a-fA-Fx\]+).* \"threadname_4\" \[^\r\n\]*" {
112 set process4 $expect_out(1,string)
115 -re ". 3 .*\[Pp\]rocess (\[0-9a-fA-Fx\]+).* \"threadname_3\" \[^\r\n\]*" {
116 set process3 $expect_out(1,string)
119 -re ". 2 .*\[Pp\]rocess (\[0-9a-fA-Fx\]+).* \"threadname_2\" \[^\r\n\]*" {
120 set process2 $expect_out(1,string)
123 -re ". 1 .*\[Pp\]rocess (\[0-9a-fA-Fx\]+).* \"threadname_1\" \[^\r\n\]*" {
124 set process1 $expect_out(1,string)
127 -re ".*$gdb_prompt $" {
128 pass "collect process id"
132 if { [info exists process6] } then {
133 gdb_test "echo $process6\\n" "$process6" "got process ids"
136 # Collect lwp ids, if any.
137 gdb_test_multiple "info threads" "collect thread id" {
138 -re ". 6 .*LWP (\[0-9a-fA-Fx\]+).* \"threadname_6\" \[^\r\n\]*" {
139 set lwp6 $expect_out(1,string)
142 -re ". 5 .*LWP (\[0-9a-fA-Fx\]+).* \"threadname_5\" \[^\r\n\]*" {
143 set lwp5 $expect_out(1,string)
146 -re ". 4 .*LWP (\[0-9a-fA-Fx\]+).* \"threadname_4\" \[^\r\n\]*" {
147 set lwp4 $expect_out(1,string)
150 -re ". 3 .*LWP (\[0-9a-fA-Fx\]+).* \"threadname_3\" \[^\r\n\]*" {
151 set lwp3 $expect_out(1,string)
154 -re ". 2 .*LWP (\[0-9a-fA-Fx\]+).* \"threadname_2\" \[^\r\n\]*" {
155 set lwp2 $expect_out(1,string)
158 -re ". 1 .*LWP (\[0-9a-fA-Fx\]+).* \"threadname_1\" \[^\r\n\]*" {
159 set lwp1 $expect_out(1,string)
162 -re ".*$gdb_prompt $" {
163 pass "collect lwp id"
167 if { [info exists lwp6] } then {
168 gdb_test "echo $lwp6\\n" "$lwp6" "got lwp ids"
172 # Now: test 'thread find' with names.
175 gdb_test "thread find threadname_6" \
176 "Thread 6 has name 'threadname_6'" "find thread name 6"
177 gdb_test "thread find threadname_5" \
178 "Thread 5 has name 'threadname_5'" "find thread name 5"
179 gdb_test "thread find threadname_4" \
180 "Thread 4 has name 'threadname_4'" "find thread name 4"
181 gdb_test "thread find threadname_3" \
182 "Thread 3 has name 'threadname_3'" "find thread name 3"
183 gdb_test "thread find threadname_2" \
184 "Thread 2 has name 'threadname_2'" "find thread name 2"
185 gdb_test "thread find threadname_1" \
186 "Thread 1 has name 'threadname_1'" "find thread name 1"
189 # Test 'thread find' with thread ids, if any.
192 if { [info exists thread6] } then {
193 gdb_test "thread find $thread6" \
194 "Thread 6 has .*$thread6.*" "find thread id 6"
195 gdb_test "thread find $thread5" \
196 "Thread 5 has .*$thread5.*" "find thread id 5"
197 gdb_test "thread find $thread4" \
198 "Thread 4 has .*$thread4.*" "find thread id 4"
199 gdb_test "thread find $thread3" \
200 "Thread 3 has .*$thread3.*" "find thread id 3"
201 gdb_test "thread find $thread2" \
202 "Thread 2 has .*$thread2.*" "find thread id 2"
203 gdb_test "thread find $thread1" \
204 "Thread 1 has .*$thread1.*" "find thread id 1"
208 # Test 'thread find' with process ids, if any.
211 if { [info exists process6] } then {
212 gdb_test "thread find $process6" \
213 "Thread 6 has .*$process6.*" "find process id 6"
214 gdb_test "thread find $process5" \
215 "Thread 5 has .*$process5.*" "find process id 5"
216 gdb_test "thread find $process4" \
217 "Thread 4 has .*$process4.*" "find process id 4"
218 gdb_test "thread find $process3" \
219 "Thread 3 has .*$process3.*" "find process id 3"
220 gdb_test "thread find $process2" \
221 "Thread 2 has .*$process2.*" "find process id 2"
222 gdb_test "thread find $process1" \
223 "Thread 1 has .*$process1.*" "find process id 1"
227 # Test 'thread find' with lwp ids, if any.
230 if { [info exists lwp6] } then {
231 gdb_test "thread find $lwp6" \
232 "Thread 6 has .*$lwp6.*" "find lwp id 6"
233 gdb_test "thread find $lwp5" \
234 "Thread 5 has .*$lwp5.*" "find lwp id 5"
235 gdb_test "thread find $lwp4" \
236 "Thread 4 has .*$lwp4.*" "find lwp id 4"
237 gdb_test "thread find $lwp3" \
238 "Thread 3 has .*$lwp3.*" "find lwp id 3"
239 gdb_test "thread find $lwp2" \
240 "Thread 2 has .*$lwp2.*" "find lwp id 2"
241 gdb_test "thread find $lwp1" \
242 "Thread 1 has .*$lwp1.*" "find lwp id 1"
247 gdb_test "thread find foobarbaz" "No threads match .*" "no thread"
250 # Test regular expression
260 gdb_test_multiple "thread find threadname_\[345\]" "test regular exp" {
261 -re "Thread 6 has name \[^\r\n\]*" {
265 -re "Thread 5 has name \[^\r\n\]*" {
269 -re "Thread 4 has name \[^\r\n\]*" {
273 -re "Thread 3 has name \[^\r\n\]*" {
277 -re "Thread 2 has name \[^\r\n\]*" {
281 -re "Thread 1 has name \[^\r\n\]*" {
285 -re ".*$gdb_prompt $" {
286 if { $see3 && $see4 && $see5 && !$see1 && !$see2 && !$see6 } then {
287 pass "test regular exp"
289 fail "test regular exp"
295 # Test info threads on a subset of threads
305 gdb_test_multiple "info threads 2 4 6" "info threads 2 4 6" {
306 -re ". 6 .*\"threadname_6.*\" \[\r\n\]*" {
310 -re ". 5 .*\"threadname_5.*\" \[\r\n\]*" {
314 -re ". 4 .*\"threadname_4.*\" \[\r\n\]*" {
318 -re ". 3 .*\"threadname_3.*\" \[\r\n\]*" {
322 -re ". 2 .*\"threadname_2.*\" \[\r\n\]*" {
326 -re ". 1 .*\"threadname_1.*\" \[\r\n\]*" {
330 -re ".*$gdb_prompt $" {
331 if { $see2 && $see4 && $see6 && !$see1 && !$see3 && !$see5 } then {
332 pass "info threads 2 4 6"
334 fail "info threads 2 4 6"
340 # Test info threads on a range
350 gdb_test_multiple "info threads 3-5" "info threads 3-5" {
351 -re ". 6 .*\"threadname_6.*\" \[\r\n\]*" {
355 -re ". 5 .*\"threadname_5.*\" \[\r\n\]*" {
359 -re ". 4 .*\"threadname_4.*\" \[\r\n\]*" {
363 -re ". 3 .*\"threadname_3.*\" \[\r\n\]*" {
367 -re ". 2 .*\"threadname_2.*\" \[\r\n\]*" {
371 -re ". 1 .*\"threadname_1.*\" \[\r\n\]*" {
375 -re ".*$gdb_prompt $" {
376 if { $see3 && $see4 && $see5 && !$see1 && !$see2 && !$see6 } then {
377 pass "info threads 3-5"
379 fail "info threads 3-5"
384 # Test inverted range
386 gdb_test "info threads 5-3" "inverted range" "test inverted range"
388 # Test degenerate range
397 gdb_test_multiple "info threads 3-3" "info threads 3-3" {
398 -re ". 6 .*\"threadname_6.*\" \[\r\n\]*" {
402 -re ". 5 .*\"threadname_5.*\" \[\r\n\]*" {
406 -re ". 4 .*\"threadname_4.*\" \[\r\n\]*" {
410 -re ". 3 .*\"threadname_3.*\" \[\r\n\]*" {
414 -re ". 2 .*\"threadname_2.*\" \[\r\n\]*" {
418 -re ". 1 .*\"threadname_1.*\" \[\r\n\]*" {
422 -re ".*$gdb_prompt $" {
423 if { $see3 && !$see1 && !$see2 && !$see4 && !$see5 && !$see6 } then {
424 pass "info threads 3-3"
426 fail "info threads 3-3"