1 # Copyright 2015 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} {
25 clean_restart ${binfile}
28 fail "Can't run to main"
34 # Avoid dumping a ton of thread create/exit info in the logs.
35 gdb_test_no_output "set print thread-events off"
37 gdb_breakpoint "after_count"
38 gdb_continue_to_breakpoint "after_count"
40 # Get value of VARIABLE in the inferior.
42 proc getvar {variable} {
48 set msg "get $variable"
49 gdb_test_multiple "print $variable" $msg {
50 -re " = ($decimal)\r\n$gdb_prompt $" {
51 set value $expect_out(1,string)
58 set reuse_time [getvar "reuse_time"]
60 # Now the real test. Run to a breakpoint in a thread that exits
61 # immediately once resumed. The thread ends up left on the thread
62 # list, marked exited (exactly because it's the selected thread).
63 gdb_breakpoint "do_nothing_thread_func"
64 gdb_continue_to_breakpoint "do_nothing_thread_func"
68 # Let the program continue, constantly spawning short-lived threads
69 # (one at a time). On some targets, after a bit, a new thread reuses
70 # the tid of the old exited thread that we still have selected. GDB
71 # should not crash in this situation. Of course, if the tid number
72 # space is shared between all processes in the system (such as on
73 # Linux), there's a chance that some other process grabs the TID, but
74 # that can never cause a spurious test fail.
75 gdb_breakpoint "after_reuse_time"
77 # Higher than what the test program sleeps before exiting.
78 set timeout [expr $reuse_time * 2]
80 gdb_continue_to_breakpoint "after_reuse_time"