1 # Copyright 2011-2022 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 standard_testfile linux-dp.c
20 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != ""} {
24 clean_restart ${binfile}
25 gdb_test_no_output "set print sevenbit-strings"
28 # Run until there are some threads.
29 gdb_breakpoint [gdb_get_line_number "linuxthreads.exp: info threads 2"]
30 gdb_continue_to_breakpoint "main thread's sleep"
32 # Create thread names.
33 gdb_test "thread apply 1 thread name threadname_1" \
37 gdb_test "thread apply 2 thread name threadname_2" \
41 gdb_test "thread apply 3 thread name threadname_3" \
45 gdb_test "thread apply 4 thread name threadname_4" \
49 gdb_test "thread apply 5 thread name threadname_5" \
53 gdb_test "thread apply 6 thread name threadname_6" \
57 # Collect thread ids, if any.
59 gdb_test_multiple "info threads" "collect thread id" {
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)
65 -re ".*$gdb_prompt $" {
66 pass "collect thread id"
70 if { [info exists thread6] } then {
71 gdb_test "echo $thread6\\n" "$thread6" "got thread ids"
74 # Collect process ids, if any.
76 gdb_test_multiple "info threads" "collect thread id" {
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)
82 -re ".*$gdb_prompt $" {
83 pass "collect process id"
87 if { [info exists process6] } then {
88 gdb_test "echo $process6\\n" "$process6" "got process ids"
91 # Collect lwp ids, if any.
93 gdb_test_multiple "info threads" "collect thread id" {
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)
99 -re ".*$gdb_prompt $" {
100 pass "collect lwp id"
104 if { [info exists lwp6] } then {
105 gdb_test "echo $lwp6\\n" "$lwp6" "got lwp ids"
109 # Now: test 'thread find' with names.
112 gdb_test "thread find threadname_6" \
113 "Thread 6 has name 'threadname_6'" "find thread name 6"
114 gdb_test "thread find threadname_5" \
115 "Thread 5 has name 'threadname_5'" "find thread name 5"
116 gdb_test "thread find threadname_4" \
117 "Thread 4 has name 'threadname_4'" "find thread name 4"
118 gdb_test "thread find threadname_3" \
119 "Thread 3 has name 'threadname_3'" "find thread name 3"
120 gdb_test "thread find threadname_2" \
121 "Thread 2 has name 'threadname_2'" "find thread name 2"
122 gdb_test "thread find threadname_1" \
123 "Thread 1 has name 'threadname_1'" "find thread name 1"
126 # Test 'thread find' with thread ids, if any.
129 if { [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"
145 # Test 'thread find' with process ids, if any.
148 if { [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"
164 # Test 'thread find' with lwp ids, if any.
167 if { [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"
184 gdb_test "thread find foobarbaz" "No threads match .*" "no thread"
187 # Test regular expression
190 for {set i 1} {$i <= 6} {incr i} {
193 gdb_test_multiple "thread find threadname_\[345\]" "test regular exp" {
194 -re "Thread (\[0-9\]+) has name \[^\r\n\]*" {
195 set thr_num $expect_out(1,string)
199 -re ".*$gdb_prompt $" {
200 if { $see3 && $see4 && $see5 && !$see1 && !$see2 && !$see6 } then {
201 pass "test regular exp"
203 fail "test regular exp"
209 # Test info threads on a subset of threads
212 for {set i 1} {$i <= 6} {incr i} {
215 gdb_test_multiple "info threads 2 4 6" "info threads 2 4 6" {
216 -re ". (\[0-9\]+) \[^\r\n\]*\"threadname_\[0-9\]+\" \[^\r\n\]*" {
217 set thr_num $expect_out(1,string)
221 -re "$gdb_prompt $" {
222 if { $see2 && $see4 && $see6 && !$see1 && !$see3 && !$see5 } then {
223 pass "info threads 2 4 6"
225 fail "info threads 2 4 6"
231 # Test info threads on a range
234 for {set i 1} {$i <= 6} {incr i} {
237 gdb_test_multiple "info threads 3-5" "info threads 3-5" {
238 -re ". (\[0-9\]+) \[^\r\n\]*\"threadname_\[0-9\]+\" \[^\r\n\]*" {
239 set thr_num $expect_out(1,string)
243 -re "$gdb_prompt $" {
244 if { $see3 && $see4 && $see5 && !$see1 && !$see2 && !$see6 } then {
245 pass "info threads 3-5"
247 fail "info threads 3-5"
252 # Test inverted range
254 gdb_test "info threads 5-3" "inverted range" "test inverted range"
256 # Test degenerate range
258 for {set i 1} {$i <= 6} {incr i} {
261 gdb_test_multiple "info threads 3-3" "info threads 3-3" {
262 -re ". (\[0-9\]+) .*\"threadname_\[0-9\]+\" \[^\r\n\]*" {
263 set thr_num $expect_out(1,string)
267 -re ".*$gdb_prompt $" {
268 if { $see3 && !$see1 && !$see2 && !$see4 && !$see5 && !$see6 } then {
269 pass "info threads 3-3"
271 fail "info threads 3-3"
278 gdb_test "info thread foo" \
279 "Invalid thread ID: foo"
281 gdb_test "info thread foo -1" \
282 "Invalid thread ID: foo -1"