Update expected info threads error messages in gdb.multi/tids.exp
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.multi / tids.exp
1 # Copyright 2015-2019 Free Software Foundation, Inc.
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 # Test thread ID parsing and display.
17
18 load_lib gdb-python.exp
19
20 standard_testfile
21
22 # Multiple inferiors are needed, therefore both native and extended
23 # gdbserver modes are supported. Only non-extended gdbserver is not
24 # supported.
25 if [use_gdb_stub] {
26 untested "using gdb stub"
27 return
28 }
29
30 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} {pthreads debug}] } {
31 return -1
32 }
33
34 clean_restart ${testfile}
35
36 if { ![runto_main] } then {
37 return -1
38 }
39
40 # Issue "thread apply TID_LIST p 1234" and expect EXP_TID_LIST (a list
41 # of thread ids) to be displayed.
42 proc thread_apply {tid_list exp_tid_list {message ""}} {
43 global decimal
44 set any "\[^\r\n\]*"
45 set expected [string_to_regexp $exp_tid_list]
46
47 set r ""
48 foreach tid $expected {
49 append r "\[\r\n\]+"
50 append r "Thread $tid $any:\r\n"
51 append r "\\$$decimal = 1234"
52 }
53
54 set cmd "thread apply $tid_list"
55 if {$message == ""} {
56 set message $cmd
57 }
58 gdb_test "$cmd p 1234" $r $message
59 }
60
61 # Issue "info threads TID_LIST" and expect EXP_TID_LIST (a list of
62 # thread ids) to be displayed.
63 proc info_threads {tid_list exp_tid_list {message ""}} {
64 set any "\[^\r\n\]*"
65 set expected [string_to_regexp $exp_tid_list]
66 set r [join $expected " ${any}\r\n${any} "]
67 set r "${any} $r ${any}"
68 set cmd "info threads $tid_list"
69 if {$message == ""} {
70 set message $cmd
71 }
72 gdb_test $cmd $r $message
73 }
74
75 # Issue "info threads TID_LIST" and expect INFO_THR output. Then
76 # issue "thread apply TID_LIST" and expect THR_APPLY output. If
77 # THR_APPLY is omitted, INFO_THR is expected instead.
78 proc thr_apply_info_thr {tid_list info_thr {thr_apply ""}} {
79 if {$thr_apply == ""} {
80 set thr_apply $info_thr
81 }
82
83 info_threads $tid_list $info_thr
84 thread_apply $tid_list $thr_apply
85 }
86
87 # Issue both "thread apply TID_LIST" and "info threads TID_LIST" and
88 # expect commands to error out with EXP_ERROR_APPLY and EXP_ERROR_INFO.
89 # If EXP_ERROR_INFO is missing, default to EXP_ERROR_APPLY.
90 proc thr_apply_info_thr_error {tid_list exp_error_apply {exp_error_info ""}} {
91 if { "$exp_error_info" == "" } {
92 set exp_error_info "$exp_error_apply"
93 }
94
95 gdb_test "info threads $tid_list" \
96 $exp_error_info
97
98 gdb_test "thread apply $tid_list" \
99 $exp_error_apply \
100 "thread apply $tid_list"
101 }
102
103 # Issue both "info threads TID_LIST" and "thread apply TID_LIST" and
104 # expect the command to error out with "Invalid thread ID: $EXPECTED".
105 # EXPECTED is a literal string, not a regexp. If EXPECTED is omitted,
106 # TID_LIST is expected instead.
107 proc thr_apply_info_thr_invalid {tid_list {expected ""}} {
108 if {$expected == ""} {
109 set expected $tid_list
110 }
111 set expected [string_to_regexp $expected]
112 gdb_test "info threads $tid_list" \
113 "Invalid thread ID: $expected"
114
115 gdb_test "thread apply $tid_list p 1234" \
116 "Invalid thread ID: $expected p 1234" \
117 "thread apply $tid_list"
118 }
119
120 # "info threads" while there's only inferior 1 should show
121 # single-number thread IDs.
122 with_test_prefix "single inferior" {
123 info_threads "" "1"
124
125 gdb_test "thread" "Current thread is 1 .*"
126 }
127
128 # "info threads" while there are multiple inferiors should show
129 # qualified thread IDs.
130 with_test_prefix "two inferiors" {
131 # Add another inferior.
132 gdb_test "add-inferior" "Added inferior 2.*" "add empty inferior 2"
133
134 # Now that we've added another inferior, thread IDs now show the
135 # inferior number.
136 info_threads "" "1.1"
137
138 gdb_test "thread" "Current thread is 1\.1 .*"
139
140 gdb_test "inferior 2" "Switching to inferior 2 .*" "switch to inferior 2"
141 gdb_test "file ${binfile}" ".*" "load file in inferior 2"
142
143 runto_main
144
145 # Now that we've added another inferior, thread IDs now show the
146 # inferior number.
147 info_threads "" "1.1 2.1" \
148 "info threads show inferior numbers"
149
150 gdb_test "thread" "Current thread is 2\.1 .*" \
151 "switch to thread using extended thread ID"
152
153 gdb_breakpoint "thread_function1"
154
155 gdb_continue_to_breakpoint "once"
156 gdb_test "inferior 1" "Switching to inferior 1 .*"
157 gdb_continue_to_breakpoint "twice"
158
159 info_threads "" "1.1 1.2 2.1 2.2" \
160 "info threads again"
161
162 # Same, but show the global ID.
163 gdb_test "info threads -gid" \
164 [multi_line \
165 " 1\.1 +1 +.*" \
166 "\\* 1\.2 +4 +.* thread_function1 .* at .*$srcfile:.*" \
167 " 2\.1 +2 +.*" \
168 " 2\.2 +3 +.* thread_function1 .* at .*$srcfile:.*"]
169
170 # Confirm the convenience variables show the expected numbers.
171 gdb_test "p \$_thread == 2" " = 1"
172 gdb_test "p \$_gthread == 4" " = 1"
173
174 # Without an explicit inferior component, GDB defaults to the
175 # current inferior. Make sure we don't refer to a thread by
176 # global ID by mistake.
177 gdb_test "thread 4" "Unknown thread 1.4\\."
178
179 # Test thread ID list parsing. Test qualified and unqualified
180 # IDs; qualified and unqualified ranges; invalid IDs and invalid
181 # ranges.
182
183 # First spawn a couple more threads so ranges includes more than
184 # two threads.
185 with_test_prefix "more threads" {
186 gdb_breakpoint "thread_function2"
187
188 gdb_test "inferior 2" "Switching to inferior 2 .*"
189 gdb_continue_to_breakpoint "once"
190
191 gdb_test "inferior 1" "Switching to inferior 1 .*"
192 gdb_continue_to_breakpoint "twice"
193 }
194
195 thr_apply_info_thr "1" \
196 "1.1"
197
198 thr_apply_info_thr "1.1" \
199 "1.1"
200
201 thr_apply_info_thr "1 2 3" \
202 "1.1 1.2 1.3"
203
204 # Same, but with qualified thread IDs.
205 thr_apply_info_thr "1.1 1.2 1.3 2.1 2.2" \
206 "1.1 1.2 1.3 2.1 2.2"
207
208 # Test a thread number range.
209 thr_apply_info_thr "1-3" \
210 "1.1 1.2 1.3"
211
212 # Same, but using a qualified range.
213 thr_apply_info_thr "1.1-3" \
214 "1.1 1.2 1.3"
215
216 # A mix of qualified and unqualified thread IDs/ranges.
217 thr_apply_info_thr "1.1 2-3" \
218 "1.1 1.2 1.3"
219
220 thr_apply_info_thr "1 1.2-3" \
221 "1.1 1.2 1.3"
222
223 # Likewise, but mix inferiors too.
224 thr_apply_info_thr "2.1 2-3" \
225 "1.2 1.3 2.1" \
226 "2.1 1.2 1.3"
227
228 # Multiple ranges with mixed explicit inferiors.
229 thr_apply_info_thr "1.1-2 2.2-3" \
230 "1.1 1.2 2.2 2.3"
231
232 # All threads.
233 thread_apply "all" \
234 "2.3 2.2 2.1 1.3 1.2 1.1"
235 thread_apply "all -ascending" \
236 "1.1 1.2 1.3 2.1 2.2 2.3"
237
238 # Now test using GDB convenience variables.
239
240 gdb_test "p \$inf = 1" " = 1"
241 gdb_test "p \$thr_start = 2" " = 2"
242 gdb_test "p \$thr_end = 3" " = 3"
243
244 # Convenience variable for the inferior number, only.
245 thr_apply_info_thr "\$inf.2" \
246 "1.2"
247 thr_apply_info_thr "\$inf.2-3" \
248 "1.2 1.3"
249
250 # Convenience variables for thread numbers as well.
251 foreach prefix {"" "1." "\$inf."} {
252 thr_apply_info_thr "${prefix}\$thr_start" \
253 "1.2"
254 thr_apply_info_thr "${prefix}\$thr_start-\$thr_end" \
255 "1.2 1.3"
256 thr_apply_info_thr "${prefix}2-\$thr_end" \
257 "1.2 1.3"
258 thr_apply_info_thr "${prefix}\$thr_start-3" \
259 "1.2 1.3"
260
261 # Undefined convenience variable.
262 set prefix_re [string_to_regexp $prefix]
263 thr_apply_info_thr_error "${prefix}\$conv123" \
264 [multi_line \
265 "Convenience variable must have integer value\." \
266 "Invalid thread ID: ${prefix_re}\\\$conv123"]
267 }
268
269 # Convenience variables pointing at an inexisting thread and/or
270 # inferior.
271 gdb_test "p \$inf = 30" " = 30"
272 gdb_test "p \$thr = 20" " = 20"
273 # Try both the convenience variable and the literal number.
274 foreach thr {"\$thr" "20" "1.20" "\$inf.1" "30.1" } {
275 set expected [string_to_regexp $thr]
276 gdb_test "info threads $thr" "No threads match '${expected}'."
277 # "info threads" works like a filter. If there's any other
278 # valid thread in the list, there's no error.
279 info_threads "$thr 1.1" "1.1"
280 info_threads "1.1 $thr" "1.1"
281 }
282
283 gdb_test "thread apply \$thr p 1234" \
284 "warning: Unknown thread 1.20" \
285 "thread apply \$thr"
286
287 gdb_test "thread apply \$inf.1 p 1234" \
288 "warning: Unknown thread 30.1" \
289 "thread apply \$inf.1"
290
291 # Star ranges.
292
293 thr_apply_info_thr "1.*" \
294 "1.1 1.2 1.3"
295
296 thr_apply_info_thr "*" \
297 "1.1 1.2 1.3"
298
299 thr_apply_info_thr "1.* 2.1" \
300 "1.1 1.2 1.3 2.1"
301
302 thr_apply_info_thr "2.1 1.*" \
303 "1.1 1.2 1.3 2.1" \
304 "2.1 1.1 1.2 1.3"
305
306 thr_apply_info_thr "1.* 2.*" \
307 "1.1 1.2 1.3 2.1 2.2 2.3"
308
309 thr_apply_info_thr "2.* 1.*" \
310 "1.1 1.2 1.3 2.1 2.2 2.3" \
311 "2.1 2.2 2.3 1.1 1.2 1.3"
312
313 # There's no inferior 3, but "info threads" treats the thread list
314 # as a filter, so it's OK. "thread apply" complains about the
315 # unknown inferior through.
316 info_threads "1.1 3.*" \
317 "1.1"
318 gdb_test "thread apply 1.1 3.* p 1" \
319 "Thread 1.1.*warning: Unknown inferior 3"
320
321 # Now test a set of invalid thread IDs/ranges.
322
323 thr_apply_info_thr_invalid "1." \
324 "1."
325
326 thr_apply_info_thr_invalid "1-3 1." \
327 "1."
328
329 thr_apply_info_thr_invalid "1.1.1" \
330 "1.1.1"
331
332 thr_apply_info_thr_invalid "2 1.1.1" \
333 "1.1.1"
334
335 thr_apply_info_thr_invalid "1.1.1 2" \
336 "1.1.1 2"
337
338 thr_apply_info_thr_invalid "1-2.1" \
339 "1-2.1"
340
341 gdb_test "p \$zero = 0" " = 0"
342 gdb_test "p \$one = 1" " = 1"
343 gdb_test "p \$minus_one = -11" " = -11"
344 foreach prefix {"" "1." "$one."} {
345 set prefix_re [string_to_regexp $prefix]
346
347 thr_apply_info_thr_invalid "${prefix}foo"
348 thr_apply_info_thr_invalid "${prefix}1foo"
349 thr_apply_info_thr_invalid "${prefix}foo1"
350
351 thr_apply_info_thr_error "${prefix}1-0" "inverted range"
352 thr_apply_info_thr_error "${prefix}1-\$zero" "inverted range"
353 thr_apply_info_thr_error "${prefix}\$one-0" "inverted range"
354 thr_apply_info_thr_error "${prefix}\$one-\$zero" "inverted range"
355 thr_apply_info_thr_error "${prefix}1-" "inverted range"
356 thr_apply_info_thr_error "${prefix}2-1" "inverted range"
357 thr_apply_info_thr_error "${prefix}2-\$one" "inverted range"
358 if {$prefix == ""} {
359 thr_apply_info_thr_error "${prefix}-1" "Invalid thread ID: -1" \
360 "Unrecognized option at: -1"
361 thr_apply_info_thr_error "${prefix}-\$one" \
362 "Invalid thread ID: -\\\$one" "Unrecognized option at: -\\\$one"
363 } else {
364 thr_apply_info_thr_error "${prefix}-1" "negative value"
365 thr_apply_info_thr_error "${prefix}-\$one" "negative value"
366 }
367 thr_apply_info_thr_error "${prefix}\$minus_one" \
368 "negative value: ${prefix_re}\\\$minus_one"
369
370 thr_apply_info_thr_error "${prefix}1-*" "inverted range"
371 thr_apply_info_thr_invalid "${prefix}*1"
372 thr_apply_info_thr_invalid "${prefix}*foo"
373 thr_apply_info_thr_invalid "${prefix}foo*"
374 }
375
376 # Check that a valid thread ID list with a missing command errors
377 # out.
378 with_test_prefix "missing command" {
379 set output "Please specify a command following the thread ID list"
380 gdb_test "thread apply 1" $output
381 gdb_test "thread apply 1.1" $output
382 gdb_test "thread apply 1.1 1.2" $output
383 gdb_test "thread apply 1-2" $output
384 gdb_test "thread apply 1.1-2" $output
385 gdb_test "thread apply $thr" $output
386 gdb_test "thread apply 1.*" $output
387 }
388
389 # Check that thread ID list parsing stops at the non-number token
390 # "foo" in a corner case where the "foo" is followed by hyphens.
391 # In this corner case, GDB used to skip past "foo", and then parse
392 # "--1" as a tid range for the current inferior.
393 gdb_test "thread apply 1 foo --1" \
394 "Undefined command: \"foo\". Try \"help\"\\."
395
396 # Check that we do parse the inferior number and don't confuse it.
397 gdb_test "info threads 3.1" \
398 "No threads match '3.1'\."
399 }
400
401 if { ![skip_python_tests] } {
402 with_test_prefix "python" {
403 # Check that InferiorThread.num and InferiorThread.global_num
404 # return the expected numbers.
405 gdb_py_test_silent_cmd "python t0 = gdb.selected_thread ()" \
406 "test gdb.selected_thread" 1
407 gdb_test "python print ('result = %s' % t0.num)" " = 3" \
408 "test InferiorThread.num"
409 gdb_test "python print ('result = %s' % t0.global_num)" " = 6" \
410 "test InferiorThread.global_num"
411
412 # Breakpoint.thread expects global IDs. Confirm that that
413 # works as expected.
414 delete_breakpoints
415 gdb_breakpoint "thread_function1"
416
417 gdb_py_test_silent_cmd "python bp = gdb.breakpoints()\[0\]" \
418 "get python breakpoint" 0
419 gdb_test "python bp.thread = 6" "thread = 6" \
420 "make breakpoint thread-specific with python"
421 # Check that the inferior-qualified ID is correct.
422 gdb_test "info breakpoint" \
423 "stop only in thread 1.3\r\n.*" \
424 "thread specific breakpoint right thread"
425 }
426 }
427
428 # Remove the second inferior and confirm that GDB goes back to showing
429 # single-number thread IDs.
430 with_test_prefix "back to one inferior" {
431 gdb_test "kill inferior 2" "" "kill inferior 2" "Kill the program being debugged.*" "y"
432 gdb_test "thread 1.1" "Switching to thread 1\.1 .*"
433 gdb_test "remove-inferior 2" ".*" "remove inferior 2"
434
435 # "info threads" while there's only inferior 1 should show
436 # single-number thread IDs.
437 info_threads "" "1 2 3"
438
439 gdb_test "thread" "Current thread is 1 .*"
440 }
441
442 # Add another inferior and remove inferior 1. Since even though
443 # there's a single inferior, its number is not 1, GDB should show
444 # inferior-qualified thread IDs.
445 with_test_prefix "single-inferior but not initial" {
446 # Add another inferior.
447 gdb_test "add-inferior" "Added inferior 3.*" "add empty inferior"
448
449 # Now that we'd added another inferior, thread IDs should show the
450 # inferior number.
451 info_threads "" "1.1 1.2 1.3" \
452 "info threads with multiple inferiors"
453
454 gdb_test "thread" "Current thread is 1\.1 .*"
455
456 gdb_test "inferior 3" "Switching to inferior 3 .*" "switch to inferior 3"
457 gdb_test "file ${binfile}" ".*" "load file in inferior 3"
458
459 runto_main
460
461 gdb_test "remove-inferior 1" ".*" "remove inferior 1"
462
463 # Even though we have a single inferior, its number is > 1, so
464 # thread IDs should include the inferior number.
465 info_threads "" "3.1" \
466 "info threads with single inferior"
467
468 gdb_test "thread" "Current thread is 3\.1 .*" "thread again"
469 }
This page took 0.039897 seconds and 4 git commands to generate.