1 # Copyright (C) 2015-2023 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 # This test verifies that several threads forking while another thread
17 # is constantly stepping over a breakpoint is properly handled.
21 set linenum [gdb_get_line_number "set break here"]
23 if {[build_executable "failed to prepare" $testfile $srcfile {debug pthreads}] == -1} {
28 set displaced_stepping_supported 1
30 # "set displaced on" only tells gdb to use displaced stepping if
31 # possible. Probe for actual support.
33 proc probe_displaced_stepping_support {} {
34 global displaced_stepping_supported
35 global binfile gdb_prompt
37 with_test_prefix "probe displaced-stepping support" {
38 clean_restart $binfile
40 gdb_test_no_output "set displaced on"
45 # We're stopped at the main breakpoint. If displaced stepping is
46 # supported, we'll see related debug output while we step past
48 gdb_test_no_output "set debug displaced 1"
49 gdb_test_multiple "next" "probe" {
50 -re "prepared successfully .*$gdb_prompt $" {
53 -re ".*$gdb_prompt $" {
54 set displaced_stepping_supported 0
61 # The test proper. If COND_BP_TARGET is true, then test with
62 # conditional breakpoints evaluated on the target side, if possible.
63 # DETACH_ON_FORK is used as value for the "set detach-on-fork"
64 # setting. If "on", this exercises GDB explicitly continuing the fork
65 # child until exit. If "off", this exercises GDB detaching the fork
66 # child. DISPLACED indicates whether to use displaced stepping or
68 proc do_test { cond_bp_target detach_on_fork displaced } {
70 global srcfile testfile binfile
71 global decimal gdb_prompt
73 global is_remote_target
75 set saved_gdbflags $GDBFLAGS
76 set GDBFLAGS [concat $GDBFLAGS " -ex \"set non-stop on\""]
77 clean_restart $binfile
78 set GDBFLAGS $saved_gdbflags
84 if {$cond_bp_target} {
85 set test "set breakpoint condition-evaluation target"
86 gdb_test_multiple $test $test {
87 -re "warning: Target does not support breakpoint condition evaluation.\r\nUsing host evaluation mode instead.\r\n$gdb_prompt $" {
88 # Target doesn't support breakpoint condition
89 # evaluation on its side. Skip the test.
92 -re "^$test\r\n$gdb_prompt $" {
96 gdb_test_no_output "set breakpoint condition-evaluation host"
99 gdb_test_no_output "set detach-on-fork $detach_on_fork"
100 gdb_test_no_output "set displaced $displaced"
102 gdb_test "break $linenum if zero == 1" \
104 "set breakpoint that evals false"
106 set test "continue &"
107 gdb_test_multiple $test $test {
116 with_timeout_factor 10 {
117 set test "inferior 1 exited"
118 gdb_test_multiple "" $test {
119 -re "Inferior 1 \(\[^\r\n\]+\) exited normally" {
123 -re "Inferior $decimal \(\[^\r\n\]+\) exited normally" {
125 if {$fork_count <= 100} {
128 fail "$test (too many forks)"
135 # No use testing further.
139 gdb_test "info threads" "No threads\." \
142 gdb_test "info inferiors" \
143 "Num\[ \t\]+Description\[ \t\]+Connection\[ \t\]+Executable\[ \t\]+\r\n\\* 1 \[^\r\n\]+" \
144 "only inferior 1 left"
147 probe_displaced_stepping_support
149 foreach_with_prefix cond_bp_target {1 0} {
150 foreach_with_prefix detach_on_fork {"on" "off"} {
151 # Disable "off" for now. The test does pass with
152 # detach-on-fork off (at the time of writing), but gdb seems
153 # to slow down quadratically as inferiors are created, and
154 # then the test takes annoyingly long to complete...
155 if {$detach_on_fork == "off"} {
159 foreach_with_prefix displaced {"on" "off"} {
160 if {$displaced == "on" && !$displaced_stepping_supported} {
164 do_test $cond_bp_target $detach_on_fork $displaced