1 # Copyright
2015-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 # Test running a
program that spawns enough threads that the tid of an
17 # exited thread is reused. GDB should not crash when this happens.
21 if {[prepare_for_testing
"failed to prepare" $testfile $srcfile { debug pthreads }] == -1} {
31 # Avoid dumping a ton of thread create
/exit
info in the logs.
32 gdb_test_no_output
"set print thread-events off"
34 gdb_breakpoint
"after_count"
35 gdb_continue_to_breakpoint
"after_count"
37 #
Get value of
VARIABLE in the inferior.
39 proc getvar
{variable} {
45 set msg
"get $variable"
46 gdb_test_multiple
"print $variable" $msg {
47 -re
" = ($decimal)\r\n$gdb_prompt $" {
48 set value $expect_out
(1,string
)
55 set reuse_time
[getvar
"reuse_time"]
57 # Now the real test. Run to a breakpoint in a thread that exits
58 # immediately once resumed. The thread ends up left
on the thread
59 # list
, marked exited
(exactly because it
's the selected thread).
60 gdb_breakpoint "do_nothing_thread_func"
61 gdb_continue_to_breakpoint "do_nothing_thread_func"
65 # Let the program continue, constantly spawning short-lived threads
66 # (one at a time). On some targets, after a bit, a new thread reuses
67 # the tid of the old exited thread that we still have selected. GDB
68 # should not crash in this situation. Of course, if the tid number
69 # space is shared between all processes in the system (such as on
70 # Linux), there's a chance that some other process grabs the TID
, but
71 # that can never cause a spurious test fail.
72 gdb_breakpoint
"after_reuse_time"
74 # Higher than what the test
program sleeps before exiting.
75 set timeout
[expr $reuse_time
* 2]
77 gdb_continue_to_breakpoint
"after_reuse_time"