gdb/testsuite: fix gdb.trace/signal.exp on x86
[binutils-gdb/blckswan.git] / gdb / testsuite / gdb.threads / tid-reuse.exp
blobf28c7827d6532d27ef8ecea3a247cde701ee7a68
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.
19 standard_testfile
21 if {[prepare_for_testing "failed to prepare" $testfile $srcfile { debug pthreads }] == -1} {
22 return -1
25 if ![runto_main] {
26 return -1
29 delete_breakpoints
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} {
40 global decimal
41 global gdb_prompt
43 set value 0
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)
49 pass $msg
52 return $value
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"
63 delete_breakpoints
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"