Test for PR18749: problems if whole process dies while (ptrace-) stopped
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / forking-threads-plus-breakpoint.exp
CommitLineData
863d01bd
PA
1# Copyright (C) 2015 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# This test verifies that several threads forking while another thread
17# is constantly stepping over a breakpoint is properly handled.
18
19standard_testfile
20
21set linenum [gdb_get_line_number "set break here"]
22
23if {[build_executable "failed to prepare" $testfile $srcfile {debug pthreads}] == -1} {
24 return -1
25}
26
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
32# child.
33proc do_test { cond_bp_target detach_on_fork } {
34 global GDBFLAGS
35 global srcfile testfile binfile
36 global decimal gdb_prompt
37 global linenum
38 global is_remote_target
39
40 set saved_gdbflags $GDBFLAGS
41 set GDBFLAGS [concat $GDBFLAGS " -ex \"set non-stop on\""]
4807d3f3 42 set GDBFLAGS [concat $GDBFLAGS " -ex \"set sysroot /\""]
863d01bd
PA
43 clean_restart $binfile
44 set GDBFLAGS $saved_gdbflags
45
46 if ![runto_main] then {
47 fail "Can't run to main"
48 return 0
49 }
50
51 gdb_test_no_output "set detach-on-fork $detach_on_fork"
52
53 gdb_test "break $linenum if zero == 1" \
54 "Breakpoint .*" \
55 "set breakpoint that evals false"
56
57 set test "continue &"
58 gdb_test_multiple $test $test {
59 -re "$gdb_prompt " {
60 pass $test
61 }
62 }
63
64 set fork_count 0
65 set ok 0
66
67 set test "inferior 1 exited"
68 gdb_test_multiple "" $test {
69 -re "Inferior 1 \(\[^\r\n\]+\) exited normally" {
70 set ok 1
71 pass $test
72 }
73 -re "Inferior $decimal \(\[^\r\n\]+\) exited normally" {
74 incr fork_count
4807d3f3 75 exp_continue
863d01bd
PA
76 if {$fork_count <= 100} {
77 exp_continue
78 } else {
79 fail "$test (too many forks)"
80 }
81 }
82 }
83
84 if {!$ok} {
85 # No use testing further.
86 return
87 }
88
89 gdb_test "info threads" "No threads\." \
90 "no threads left"
91
92 gdb_test "info inferiors" \
93 "Num\[ \t\]+Description\[ \t\]+Executable\[ \t\]+\r\n\\* 1 \[^\r\n\]+" \
94 "only inferior 1 left"
95}
96
97# Wrapper for foreach that calls with_test_prefix on each iteration,
98# including the iterator's current value in the prefix.
99
100proc foreach_with_prefix {var list body} {
101 upvar 1 $var myvar
102 foreach myvar $list {
103 with_test_prefix "$var=$myvar" {
104 uplevel 1 $body
105 }
106 }
107}
108
109foreach_with_prefix cond_bp_target {1 0} {
4807d3f3 110 foreach_with_prefix detach_on_fork {"off" "off"} {
863d01bd
PA
111 do_test $cond_bp_target $detach_on_fork
112
113 # Disable "off" for now. The test does pass with
114 # detach-on-fork off (at the time of writing), but gdb seems
115 # to slow down quadratically as inferiors are created, and
116 # then the test takes annoyingly long to complete...
117 break
118 }
119}
This page took 0.028063 seconds and 4 git commands to generate.