2006-04-26 Michael Snyder <msnyder@redhat.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / multi-forks.exp
CommitLineData
9078e690 1# Copyright 2005, 2006 Free Software Foundation, Inc.
099ac3dd
MS
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
9078e690 15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
099ac3dd
MS
16
17if $tracelevel then {
18 strace $tracelevel
19 }
20
21if { ![isnative] } then {
22 continue
23}
24
25# Until "set follow-fork-mode" and "catch fork" are implemented on
26# other targets...
27#
28if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-*-linux*"]} then {
29 continue
30}
31
32set prms_id 0
33set bug_id 0
34
35set testfile "multi-forks"
36set srcfile ${testfile}.c
37set binfile ${objdir}/${subdir}/${testfile}
38
39if { [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
45gdb_exit
46gdb_start
47gdb_reinitialize_dir $srcdir/$subdir
48gdb_load ${binfile}
49
50global 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
63runto_main
64set exit_bp_loc [gdb_get_line_number "Set exit breakpoint here."]
65gdb_test "break $exit_bp_loc" "Breakpoint.* at .*" "Break at exit"
66gdb_test "set follow child" "" ""
67
68send_gdb "continue\n"
69gdb_expect {
b8db102d 70 -re ".*Break.* main .*$gdb_prompt.*$" {}
099ac3dd
MS
71 -re ".*$gdb_prompt $" {fail "run to exit 1"}
72 default {fail "run to exit 1 (timeout)"}
73}
74
75gdb_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
80delete_breakpoints
81runto_main
82gdb_test "break $exit_bp_loc" "Breakpoint.* at .*" "Break at exit"
83gdb_test "set follow parent" "" ""
84
85send_gdb "continue\n"
86gdb_expect {
b8db102d 87 -re ".*Break.* main .*$gdb_prompt.*$" {}
099ac3dd
MS
88 -re ".*$gdb_prompt $" {fail "run to exit 2"}
89 default {fail "run to exit 2 (timeout)"}
90}
91
92gdb_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
99runto_main
100gdb_test "break $exit_bp_loc" "Breakpoint.* at .*" ""
101
102gdb_test "help set detach-on-fork" "whether gdb will detach the child.*" \
103 "help set detach"
104
105gdb_test "show detach-on-fork" "on." "show detach default on"
106
107gdb_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
9078e690
DJ
114for {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}
099ac3dd
MS
119
120gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit 16"
121gdb_test "info fork" " 4 .* 3 .* 2 .* 1 .*" "info fork 16"
122gdb_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]
133gdb_test "detach-fork 1" "Detached .*" "Detach 1"
134gdb_test "detach-fork 2" "Detached .*" "Detach 2"
135gdb_test "detach-fork 3" "Detached .*" "Detach 3"
136gdb_test "detach-fork 4" "Detached .*" "Detach 4"
137
138#
b8db102d 139# Test delete fork
099ac3dd
MS
140#
141
b8db102d
MS
142gdb_test "delete fork 5" "" "Delete 5"
143gdb_test "info fork 5" "No fork number 5." "Did delete 5"
144gdb_test "delete fork 6" "" "Delete 6"
145gdb_test "info fork 6" "No fork number 6." "Did delete 6"
146gdb_test "delete fork 7" "" "Delete 7"
147gdb_test "info fork 7" "No fork number 7." "Did delete 7"
148gdb_test "delete fork 8" "" "Delete 8"
149gdb_test "info fork 8" "No fork number 8." "Did delete 8"
150gdb_test "delete fork 9" "" "Delete 9"
151gdb_test "info fork 9" "No fork number 9." "Did delete 9"
152gdb_test "delete fork 10" "" "Delete 10"
153gdb_test "info fork 10" "No fork number 10." "Did delete 10"
154gdb_test "delete fork 11" "" "Delete 11"
155gdb_test "info fork 11" "No fork number 11." "Did delete 11"
156gdb_test "delete fork 12" "" "Delete 12"
157gdb_test "info fork 12" "No fork number 12." "Did delete 12"
158gdb_test "delete fork 13" "" "Delete 13"
159gdb_test "info fork 13" "No fork number 13." "Did delete 13"
160gdb_test "delete fork 14" "" "Delete 14"
161gdb_test "info fork 14" "No fork number 14." "Did delete 14"
162gdb_test "delete fork 15" "" "Delete 15"
163gdb_test "info fork 15" "No fork number 15." "Did delete 15"
099ac3dd
MS
164
165return 0
166
This page took 0.052991 seconds and 4 git commands to generate.