1 # Copyright (C) 2015 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} {
27 # The test proper. If COND_BP_TARGET is true, then test with
28 # conditional breakpoints evaluated on the target side, if possible.
29 # DETACH_ON_FORK is used as value for the "set detach-on-fork"
30 # setting. If "on", this exercises GDB explicitly continuing the fork
31 # child until exit. If "off", this exercises GDB detaching the fork
33 proc do_test { cond_bp_target detach_on_fork } {
35 global srcfile testfile binfile
36 global decimal gdb_prompt
38 global is_remote_target
40 set saved_gdbflags $GDBFLAGS
41 set GDBFLAGS [concat $GDBFLAGS " -ex \"set non-stop on\""]
42 clean_restart $binfile
43 set GDBFLAGS $saved_gdbflags
45 if ![runto_main] then {
46 fail "Can't run to main"
50 gdb_test_no_output "set detach-on-fork $detach_on_fork"
52 gdb_test "break $linenum if zero == 1" \
54 "set breakpoint that evals false"
57 gdb_test_multiple $test $test {
66 set test "inferior 1 exited"
67 gdb_test_multiple "" $test {
68 -re "Inferior 1 \(\[^\r\n\]+\) exited normally" {
72 -re "Inferior $decimal \(\[^\r\n\]+\) exited normally" {
74 if {$fork_count <= 100} {
77 fail "$test (too many forks)"
83 # No use testing further.
87 gdb_test "info threads" "No threads\." \
90 gdb_test "info inferiors" \
91 "Num\[ \t\]+Description\[ \t\]+Executable\[ \t\]+\r\n\\* 1 \[^\r\n\]+" \
92 "only inferior 1 left"
95 # Wrapper for foreach that calls with_test_prefix on each iteration,
96 # including the iterator's current value in the prefix.
98 proc foreach_with_prefix {var list body} {
100 foreach myvar $list {
101 with_test_prefix "$var=$myvar" {
107 foreach_with_prefix cond_bp_target {1 0} {
108 foreach_with_prefix detach_on_fork {"on" "off"} {
109 do_test $cond_bp_target $detach_on_fork
111 # Disable "off" for now. The test does pass with
112 # detach-on-fork off (at the time of writing), but gdb seems
113 # to slow down quadratically as inferiors are created, and
114 # then the test takes annoyingly long to complete...