]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.threads/thread-find.exp
GDB copyright headers update after running GDB's copyright.py script.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / thread-find.exp
CommitLineData
618f726f 1# Copyright 2011-2016 Free Software Foundation, Inc.
60f98dde
MS
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
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
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.
12#
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/>.
15
16# Please email any bugs, comments, and/or additions to this file to:
17# bug-gdb@gnu.org
18
0efbbabc 19standard_testfile linux-dp.c
60f98dde
MS
20if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != ""} {
21 return -1
22}
23
0efbbabc 24clean_restart ${binfile}
60f98dde
MS
25gdb_test_no_output "set print sevenbit-strings"
26runto_main
27
28# Run until there are some threads.
29gdb_breakpoint [gdb_get_line_number "linuxthreads.exp: info threads 2"]
30gdb_continue_to_breakpoint "main thread's sleep"
31
32# Create thread names.
33gdb_test "thread apply 1 thread name threadname_1" \
34 "Thread 1 .*" \
35 "name thread 1"
36
37gdb_test "thread apply 2 thread name threadname_2" \
38 "Thread 2 .*" \
39 "name thread 2"
40
41gdb_test "thread apply 3 thread name threadname_3" \
42 "Thread 3 .*" \
43 "name thread 3"
44
45gdb_test "thread apply 4 thread name threadname_4" \
46 "Thread 4 .*" \
47 "name thread 4"
48
49gdb_test "thread apply 5 thread name threadname_5" \
50 "Thread 5 .*" \
51 "name thread 5"
52
53gdb_test "thread apply 6 thread name threadname_6" \
54 "Thread 6 .*" \
55 "name thread 6"
56
57# Collect thread ids, if any.
7e0aa6aa 58
60f98dde 59gdb_test_multiple "info threads" "collect thread id" {
7e0aa6aa
PA
60 -re ". (\[0-9\]+) \[^\r\n\]*\[Tt\]hread (\[0-9a-fA-Fx\]+)\[^\r\n\]* \"threadname_\[0-9\]+\" \[^\r\n\]*" {
61 set thr_num $expect_out(1,string)
62 set thread$thr_num $expect_out(2,string)
60f98dde
MS
63 exp_continue
64 }
65 -re ".*$gdb_prompt $" {
66 pass "collect thread id"
67 }
68}
69
70if { [info exists thread6] } then {
71 gdb_test "echo $thread6\\n" "$thread6" "got thread ids"
72}
73
74# Collect process ids, if any.
7e0aa6aa 75
60f98dde 76gdb_test_multiple "info threads" "collect thread id" {
7e0aa6aa
PA
77 -re ". (\[0-9\]+) \[^\r\n\]*\[Pp\]rocess (\[0-9a-fA-Fx\]+)\[^\r\n\]* \"threadname_\[0-9\]+\" \[^\r\n\]*" {
78 set thr_num $expect_out(1,string)
79 set process$thr_num $expect_out(2,string)
60f98dde
MS
80 exp_continue
81 }
82 -re ".*$gdb_prompt $" {
83 pass "collect process id"
84 }
85}
86
87if { [info exists process6] } then {
88 gdb_test "echo $process6\\n" "$process6" "got process ids"
89}
90
91# Collect lwp ids, if any.
7e0aa6aa 92
60f98dde 93gdb_test_multiple "info threads" "collect thread id" {
7e0aa6aa
PA
94 -re ". (\[0-9\]+) \[^\r\n\]*LWP (\[0-9a-fA-Fx\]+)\[^\r\n\]* \"threadname_\[0-9\]+\" \[^\r\n\]*" {
95 set thr_num $expect_out(1,string)
96 set lwp$thr_num $expect_out(2,string)
60f98dde
MS
97 exp_continue
98 }
99 -re ".*$gdb_prompt $" {
100 pass "collect lwp id"
101 }
102}
103
104if { [info exists lwp6] } then {
105 gdb_test "echo $lwp6\\n" "$lwp6" "got lwp ids"
106}
107
108#
109# Now: test 'thread find' with names.
110#
111
112gdb_test "thread find threadname_6" \
113 "Thread 6 has name 'threadname_6'" "find thread name 6"
114gdb_test "thread find threadname_5" \
115 "Thread 5 has name 'threadname_5'" "find thread name 5"
116gdb_test "thread find threadname_4" \
117 "Thread 4 has name 'threadname_4'" "find thread name 4"
118gdb_test "thread find threadname_3" \
119 "Thread 3 has name 'threadname_3'" "find thread name 3"
120gdb_test "thread find threadname_2" \
121 "Thread 2 has name 'threadname_2'" "find thread name 2"
122gdb_test "thread find threadname_1" \
123 "Thread 1 has name 'threadname_1'" "find thread name 1"
124
125#
126# Test 'thread find' with thread ids, if any.
127#
128
129if { [info exists thread6] } then {
130 gdb_test "thread find $thread6" \
131 "Thread 6 has .*$thread6.*" "find thread id 6"
132 gdb_test "thread find $thread5" \
133 "Thread 5 has .*$thread5.*" "find thread id 5"
134 gdb_test "thread find $thread4" \
135 "Thread 4 has .*$thread4.*" "find thread id 4"
136 gdb_test "thread find $thread3" \
137 "Thread 3 has .*$thread3.*" "find thread id 3"
138 gdb_test "thread find $thread2" \
139 "Thread 2 has .*$thread2.*" "find thread id 2"
140 gdb_test "thread find $thread1" \
141 "Thread 1 has .*$thread1.*" "find thread id 1"
142}
143
144#
145# Test 'thread find' with process ids, if any.
146#
147
148if { [info exists process6] } then {
149 gdb_test "thread find $process6" \
150 "Thread 6 has .*$process6.*" "find process id 6"
151 gdb_test "thread find $process5" \
152 "Thread 5 has .*$process5.*" "find process id 5"
153 gdb_test "thread find $process4" \
154 "Thread 4 has .*$process4.*" "find process id 4"
155 gdb_test "thread find $process3" \
156 "Thread 3 has .*$process3.*" "find process id 3"
157 gdb_test "thread find $process2" \
158 "Thread 2 has .*$process2.*" "find process id 2"
159 gdb_test "thread find $process1" \
160 "Thread 1 has .*$process1.*" "find process id 1"
161}
162
163#
164# Test 'thread find' with lwp ids, if any.
165#
166
167if { [info exists lwp6] } then {
168 gdb_test "thread find $lwp6" \
169 "Thread 6 has .*$lwp6.*" "find lwp id 6"
170 gdb_test "thread find $lwp5" \
171 "Thread 5 has .*$lwp5.*" "find lwp id 5"
172 gdb_test "thread find $lwp4" \
173 "Thread 4 has .*$lwp4.*" "find lwp id 4"
174 gdb_test "thread find $lwp3" \
175 "Thread 3 has .*$lwp3.*" "find lwp id 3"
176 gdb_test "thread find $lwp2" \
177 "Thread 2 has .*$lwp2.*" "find lwp id 2"
178 gdb_test "thread find $lwp1" \
179 "Thread 1 has .*$lwp1.*" "find lwp id 1"
180}
181
182# Test no match.
183
184gdb_test "thread find foobarbaz" "No threads match .*" "no thread"
185
186#
187# Test regular expression
188#
189
7e0aa6aa
PA
190for {set i 1} {$i <= 6} {incr i} {
191 set see$i 0
192}
60f98dde 193gdb_test_multiple "thread find threadname_\[345\]" "test regular exp" {
7e0aa6aa
PA
194 -re "Thread (\[0-9\]+) has name \[^\r\n\]*" {
195 set thr_num $expect_out(1,string)
196 set see$thr_num 1
60f98dde
MS
197 exp_continue
198 }
199 -re ".*$gdb_prompt $" {
200 if { $see3 && $see4 && $see5 && !$see1 && !$see2 && !$see6 } then {
201 pass "test regular exp"
202 } else {
203 fail "test regular exp"
204 }
205 }
206}
207
208#
209# Test info threads on a subset of threads
210#
211
7e0aa6aa
PA
212for {set i 1} {$i <= 6} {incr i} {
213 set see$i 0
214}
60f98dde 215gdb_test_multiple "info threads 2 4 6" "info threads 2 4 6" {
7e0aa6aa
PA
216 -re ". (\[0-9\]+) \[^\r\n\]*\"threadname_\[0-9\]+\" \[^\r\n\]*" {
217 set thr_num $expect_out(1,string)
218 set see$thr_num 1
60f98dde
MS
219 exp_continue
220 }
e338d953 221 -re "$gdb_prompt $" {
60f98dde
MS
222 if { $see2 && $see4 && $see6 && !$see1 && !$see3 && !$see5 } then {
223 pass "info threads 2 4 6"
224 } else {
225 fail "info threads 2 4 6"
226 }
227 }
228}
229
230#
231# Test info threads on a range
232#
233
7e0aa6aa
PA
234for {set i 1} {$i <= 6} {incr i} {
235 set see$i 0
236}
60f98dde 237gdb_test_multiple "info threads 3-5" "info threads 3-5" {
7e0aa6aa
PA
238 -re ". (\[0-9\]+) \[^\r\n\]*\"threadname_\[0-9\]+\" \[^\r\n\]*" {
239 set thr_num $expect_out(1,string)
240 set see$thr_num 1
60f98dde
MS
241 exp_continue
242 }
e338d953 243 -re "$gdb_prompt $" {
60f98dde
MS
244 if { $see3 && $see4 && $see5 && !$see1 && !$see2 && !$see6 } then {
245 pass "info threads 3-5"
246 } else {
247 fail "info threads 3-5"
248 }
249 }
250}
251
252# Test inverted range
253
254gdb_test "info threads 5-3" "inverted range" "test inverted range"
255
256# Test degenerate range
257
7e0aa6aa
PA
258for {set i 1} {$i <= 6} {incr i} {
259 set see$i 0
260}
60f98dde 261gdb_test_multiple "info threads 3-3" "info threads 3-3" {
7e0aa6aa
PA
262 -re ". (\[0-9\]+) .*\"threadname_\[0-9\]+\" \[^\r\n\]*" {
263 set thr_num $expect_out(1,string)
264 set see$thr_num 1
60f98dde
MS
265 exp_continue
266 }
267 -re ".*$gdb_prompt $" {
268 if { $see3 && !$see1 && !$see2 && !$see4 && !$see5 && !$see6 } then {
269 pass "info threads 3-3"
270 } else {
271 fail "info threads 3-3"
272 }
273 }
274}
275
79ba84ca
MS
276# Test bad input
277
278gdb_test "info thread foo" \
279 "Args must be numbers or '.' variables." \
280 "info thread foo"
281
282gdb_test "info thread foo -1" \
283 "Args must be numbers or '.' variables." \
284 "info thread foo -1"