]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright 2015-2024 Free Software Foundation, Inc. |
4eec2deb PA |
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 | ||
19 | standard_testfile | |
20 | ||
21 | if {[prepare_for_testing "failed to prepare" $testfile $srcfile { debug pthreads }] == -1} { | |
22 | return -1 | |
23 | } | |
24 | ||
50441f0f | 25 | if ![runto_main] { |
4eec2deb PA |
26 | return -1 |
27 | } | |
28 | ||
29 | delete_breakpoints | |
30 | ||
31 | # Avoid dumping a ton of thread create/exit info in the logs. | |
32 | gdb_test_no_output "set print thread-events off" | |
33 | ||
34 | gdb_breakpoint "after_count" | |
35 | gdb_continue_to_breakpoint "after_count" | |
36 | ||
37 | # Get value of VARIABLE in the inferior. | |
38 | ||
39 | proc getvar {variable} { | |
40 | global decimal | |
41 | global gdb_prompt | |
42 | ||
43 | set value 0 | |
44 | ||
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 | |
50 | } | |
51 | } | |
52 | return $value | |
53 | } | |
54 | ||
55 | set reuse_time [getvar "reuse_time"] | |
56 | ||
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" | |
62 | ||
63 | delete_breakpoints | |
64 | ||
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" | |
73 | ||
74 | # Higher than what the test program sleeps before exiting. | |
75 | set timeout [expr $reuse_time * 2] | |
76 | ||
77 | gdb_continue_to_breakpoint "after_reuse_time" |