]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/multi-forks.exp
* gdb.arch/altivec-abi.exp: Replace gdb_suppress_entire_file with
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / multi-forks.exp
1 # Copyright 2005, 2006 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17 if $tracelevel then {
18 strace $tracelevel
19 }
20
21 if { ![isnative] } then {
22 continue
23 }
24
25 # Until "set follow-fork-mode" and "catch fork" are implemented on
26 # other targets...
27 #
28 if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-*-linux*"]} then {
29 continue
30 }
31
32 set prms_id 0
33 set bug_id 0
34
35 set testfile "multi-forks"
36 set srcfile ${testfile}.c
37 set binfile ${objdir}/${subdir}/${testfile}
38
39 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
40 untested multi-forks.exp
41 return -1
42 }
43
44 # Start with a fresh gdb
45
46 gdb_exit
47 gdb_start
48 gdb_reinitialize_dir $srcdir/$subdir
49 gdb_load ${binfile}
50
51 global gdb_prompt
52
53 # This is a test of gdb's ability to follow the parent, child or both
54 # parent and child of multiple Unix fork() system calls.
55 #
56
57 # Inferior program calls fork 4 times. Since each fork
58 # calls fork 4 times, there will be 16 forks. Each fork
59 # saves the return values of its own 4 fork calls.
60
61 # First set gdb to follow the child.
62 # The result should be that each of the 4 forks returns zero.
63
64 runto_main
65 set exit_bp_loc [gdb_get_line_number "Set exit breakpoint here."]
66 gdb_test "break $exit_bp_loc" "Breakpoint.* at .*" "Break at exit"
67 gdb_test "set follow child" "" ""
68
69 send_gdb "continue\n"
70 gdb_expect {
71 -re ".*Break.* main .*$gdb_prompt.*$" {}
72 -re ".*$gdb_prompt $" {fail "run to exit 1"}
73 default {fail "run to exit 1 (timeout)"}
74 }
75
76 gdb_test "print pids" "\\$.* = \\{0, 0, 0, 0\\}.*" "follow child, print pids"
77
78 # Now set gdb to follow the parent.
79 # Result should be that none of the 4 forks returns zero.
80
81 delete_breakpoints
82 runto_main
83 gdb_test "break $exit_bp_loc" "Breakpoint.* at .*" "Break at exit"
84 gdb_test "set follow parent" "" ""
85
86 send_gdb "continue\n"
87 gdb_expect {
88 -re ".*Break.* main .*$gdb_prompt.*$" {}
89 -re ".*$gdb_prompt $" {fail "run to exit 2"}
90 default {fail "run to exit 2 (timeout)"}
91 }
92
93 gdb_test "print pids\[0\]==0 || pids\[1\]==0 || pids\[2\]==0 || pids\[3\]==0" \
94 " = 0" "follow parent, print pids"
95
96 #
97 # Now test with detach-on-fork off.
98 #
99
100 runto_main
101 gdb_test "break $exit_bp_loc" "Breakpoint.* at .*" ""
102
103 gdb_test "help set detach-on-fork" "whether gdb will detach the child.*" \
104 "help set detach"
105
106 gdb_test "show detach-on-fork" "on." "show detach default on"
107
108 gdb_test "set detach off" "" "set detach off"
109
110 #
111 # We will now run every fork up to the exit bp,
112 # eventually winding up with 16 forks.
113 #
114
115 for {set i 1} {$i <= 15} {incr i} {
116 gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit $i"
117 gdb_test "info fork" " 4 .* 3 .* 2 .* 1 .*" "info fork $i"
118 gdb_test "restart $i" "(_dl_sysinfo_int80|fork).*" "restart $i"
119 }
120
121 gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit 16"
122 gdb_test "info fork" " 4 .* 3 .* 2 .* 1 .*" "info fork 16"
123 gdb_test "restart 0" " main .*" "restart final"
124
125 #
126 # Now we should examine all the pids.
127 #
128
129 #
130 # Test detach-fork
131 #
132
133 # [assumes we're at #0]
134 gdb_test "detach-fork 1" "Detached .*" "Detach 1"
135 gdb_test "detach-fork 2" "Detached .*" "Detach 2"
136 gdb_test "detach-fork 3" "Detached .*" "Detach 3"
137 gdb_test "detach-fork 4" "Detached .*" "Detach 4"
138
139 #
140 # Test delete fork
141 #
142
143 gdb_test "delete fork 5" "" "Delete 5"
144 gdb_test "info fork 5" "No fork number 5." "Did delete 5"
145 gdb_test "delete fork 6" "" "Delete 6"
146 gdb_test "info fork 6" "No fork number 6." "Did delete 6"
147 gdb_test "delete fork 7" "" "Delete 7"
148 gdb_test "info fork 7" "No fork number 7." "Did delete 7"
149 gdb_test "delete fork 8" "" "Delete 8"
150 gdb_test "info fork 8" "No fork number 8." "Did delete 8"
151 gdb_test "delete fork 9" "" "Delete 9"
152 gdb_test "info fork 9" "No fork number 9." "Did delete 9"
153 gdb_test "delete fork 10" "" "Delete 10"
154 gdb_test "info fork 10" "No fork number 10." "Did delete 10"
155 gdb_test "delete fork 11" "" "Delete 11"
156 gdb_test "info fork 11" "No fork number 11." "Did delete 11"
157 gdb_test "delete fork 12" "" "Delete 12"
158 gdb_test "info fork 12" "No fork number 12." "Did delete 12"
159 gdb_test "delete fork 13" "" "Delete 13"
160 gdb_test "info fork 13" "No fork number 13." "Did delete 13"
161 gdb_test "delete fork 14" "" "Delete 14"
162 gdb_test "info fork 14" "No fork number 14." "Did delete 14"
163 gdb_test "delete fork 15" "" "Delete 15"
164 gdb_test "info fork 15" "No fork number 15." "Did delete 15"
165
166 return 0
167