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 running a program that spawns enough threads that the tid of an 17# exited thread is reused. GDB should not crash when this happens. 18 19standard_testfile 20 21if {[prepare_for_testing "failed to prepare" $testfile $srcfile { debug pthreads }] == -1} { 22 return -1 23} 24 25clean_restart ${binfile} 26 27if ![runto main] { 28 fail "can't run to main" 29 return -1 30} 31 32delete_breakpoints 33 34# Avoid dumping a ton of thread create/exit info in the logs. 35gdb_test_no_output "set print thread-events off" 36 37gdb_breakpoint "after_count" 38gdb_continue_to_breakpoint "after_count" 39 40# Get value of VARIABLE in the inferior. 41 42proc getvar {variable} { 43 global decimal 44 global gdb_prompt 45 46 set value 0 47 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) 52 pass $msg 53 } 54 } 55 return $value 56} 57 58set reuse_time [getvar "reuse_time"] 59 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). 63gdb_breakpoint "do_nothing_thread_func" 64gdb_continue_to_breakpoint "do_nothing_thread_func" 65 66delete_breakpoints 67 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. 75gdb_breakpoint "after_reuse_time" 76 77# Higher than what the test program sleeps before exiting. 78set timeout [expr $reuse_time * 2] 79 80gdb_continue_to_breakpoint "after_reuse_time" 81