Don't resume new threads if scheduler-locking is in effect
[binutils-gdb.git] / gdb / testsuite / gdb.threads / schedlock-new-thread.exp
1 # Copyright 2021-2023 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 continuing over a thread spawn with scheduler-locking on.
17
18 standard_testfile .c
19
20 foreach_with_prefix schedlock {off on} {
21 set sl [expr $schedlock == "on" ? 1 : 0]
22 if { [build_executable "failed to prepare" $testfile-$sl \
23 $srcfile \
24 [list debug pthreads additional_flags=-DSCHEDLOCK=$sl]] \
25 == -1 } {
26 return
27 }
28 }
29
30 proc test {non-stop schedlock} {
31 save_vars ::GDBFLAGS {
32 append ::GDBFLAGS " -ex \"set non-stop ${non-stop}\""
33 set sl [expr $schedlock == "on" ? 1 : 0]
34 clean_restart $::binfile-$sl
35 }
36
37 set linenum1 [gdb_get_line_number "set break 1 here"]
38
39 if { ![runto $::srcfile:$linenum1] } {
40 return
41 }
42
43 delete_breakpoints
44
45 set linenum2 [gdb_get_line_number "set break 2 here"]
46 gdb_breakpoint $linenum2
47
48 gdb_breakpoint "thread_func"
49
50 gdb_test_no_output "set scheduler-locking $schedlock"
51
52 if {$schedlock} {
53 gdb_test "continue" \
54 "return 0.*set break 2 here .*" \
55 "continue does not stop in new thread"
56 } else {
57 gdb_test "continue" \
58 "thread_func .*" \
59 "continue stops in new thread"
60 }
61 }
62
63 foreach_with_prefix non-stop {off on} {
64 foreach_with_prefix schedlock {off on} {
65 test ${non-stop} ${schedlock}
66 }
67 }