2006-04-26 Michael Snyder <msnyder@redhat.com>
[deliverable/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 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
41 }
42
43 # Start with a fresh gdb
44
45 gdb_exit
46 gdb_start
47 gdb_reinitialize_dir $srcdir/$subdir
48 gdb_load ${binfile}
49
50 global gdb_prompt
51
52 # This is a test of gdb's ability to follow the parent, child or both
53 # parent and child of multiple Unix fork() system calls.
54 #
55
56 # Inferior program calls fork 4 times. Since each fork
57 # calls fork 4 times, there will be 16 forks. Each fork
58 # saves the return values of its own 4 fork calls.
59
60 # First set gdb to follow the child.
61 # The result should be that each of the 4 forks returns zero.
62
63 runto_main
64 set exit_bp_loc [gdb_get_line_number "Set exit breakpoint here."]
65 gdb_test "break $exit_bp_loc" "Breakpoint.* at .*" "Break at exit"
66 gdb_test "set follow child" "" ""
67
68 send_gdb "continue\n"
69 gdb_expect {
70 -re ".*Break.* main .*$gdb_prompt.*$" {}
71 -re ".*$gdb_prompt $" {fail "run to exit 1"}
72 default {fail "run to exit 1 (timeout)"}
73 }
74
75 gdb_test "print pids" "\\$.* = \\{0, 0, 0, 0\\}.*" "follow child, print pids"
76
77 # Now set gdb to follow the parent.
78 # Result should be that none of the 4 forks returns zero.
79
80 delete_breakpoints
81 runto_main
82 gdb_test "break $exit_bp_loc" "Breakpoint.* at .*" "Break at exit"
83 gdb_test "set follow parent" "" ""
84
85 send_gdb "continue\n"
86 gdb_expect {
87 -re ".*Break.* main .*$gdb_prompt.*$" {}
88 -re ".*$gdb_prompt $" {fail "run to exit 2"}
89 default {fail "run to exit 2 (timeout)"}
90 }
91
92 gdb_test "print pids\[0\]==0 || pids\[1\]==0 || pids\[2\]==0 || pids\[3\]==0" \
93 " = 0" "follow parent, print pids"
94
95 #
96 # Now test with detach-on-fork off.
97 #
98
99 runto_main
100 gdb_test "break $exit_bp_loc" "Breakpoint.* at .*" ""
101
102 gdb_test "help set detach-on-fork" "whether gdb will detach the child.*" \
103 "help set detach"
104
105 gdb_test "show detach-on-fork" "on." "show detach default on"
106
107 gdb_test "set detach off" "" "set detach off"
108
109 #
110 # We will now run every fork up to the exit bp,
111 # eventually winding up with 16 forks.
112 #
113
114 for {set i 1} {$i <= 15} {incr i} {
115 gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit $i"
116 gdb_test "info fork" " 4 .* 3 .* 2 .* 1 .*" "info fork $i"
117 gdb_test "restart $i" "(_dl_sysinfo_int80|fork).*" "restart $i"
118 }
119
120 gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit 16"
121 gdb_test "info fork" " 4 .* 3 .* 2 .* 1 .*" "info fork 16"
122 gdb_test "restart 0" " main .*" "restart final"
123
124 #
125 # Now we should examine all the pids.
126 #
127
128 #
129 # Test detach-fork
130 #
131
132 # [assumes we're at #0]
133 gdb_test "detach-fork 1" "Detached .*" "Detach 1"
134 gdb_test "detach-fork 2" "Detached .*" "Detach 2"
135 gdb_test "detach-fork 3" "Detached .*" "Detach 3"
136 gdb_test "detach-fork 4" "Detached .*" "Detach 4"
137
138 #
139 # Test delete fork
140 #
141
142 gdb_test "delete fork 5" "" "Delete 5"
143 gdb_test "info fork 5" "No fork number 5." "Did delete 5"
144 gdb_test "delete fork 6" "" "Delete 6"
145 gdb_test "info fork 6" "No fork number 6." "Did delete 6"
146 gdb_test "delete fork 7" "" "Delete 7"
147 gdb_test "info fork 7" "No fork number 7." "Did delete 7"
148 gdb_test "delete fork 8" "" "Delete 8"
149 gdb_test "info fork 8" "No fork number 8." "Did delete 8"
150 gdb_test "delete fork 9" "" "Delete 9"
151 gdb_test "info fork 9" "No fork number 9." "Did delete 9"
152 gdb_test "delete fork 10" "" "Delete 10"
153 gdb_test "info fork 10" "No fork number 10." "Did delete 10"
154 gdb_test "delete fork 11" "" "Delete 11"
155 gdb_test "info fork 11" "No fork number 11." "Did delete 11"
156 gdb_test "delete fork 12" "" "Delete 12"
157 gdb_test "info fork 12" "No fork number 12." "Did delete 12"
158 gdb_test "delete fork 13" "" "Delete 13"
159 gdb_test "info fork 13" "No fork number 13." "Did delete 13"
160 gdb_test "delete fork 14" "" "Delete 14"
161 gdb_test "info fork 14" "No fork number 14." "Did delete 14"
162 gdb_test "delete fork 15" "" "Delete 15"
163 gdb_test "info fork 15" "No fork number 15." "Did delete 15"
164
165 return 0
166
This page took 0.049702 seconds and 4 git commands to generate.