OSDN Git Service

Initial revision
authorjsm <jsm>
Mon, 28 Jun 1999 23:03:03 +0000 (23:03 +0000)
committerjsm <jsm>
Mon, 28 Jun 1999 23:03:03 +0000 (23:03 +0000)
gdb/testsuite/gdb.base/dbx.exp [new file with mode: 0644]
gdb/testsuite/gdb.base/execd-prog.c [new file with mode: 0644]
gdb/testsuite/gdb.base/foll-exec.c [new file with mode: 0644]
gdb/testsuite/gdb.base/foll-exec.exp [new file with mode: 0644]
gdb/testsuite/gdb.base/foll-fork.c [new file with mode: 0644]
gdb/testsuite/gdb.base/foll-fork.exp [new file with mode: 0644]
gdb/testsuite/gdb.base/foll-vfork.c [new file with mode: 0644]
gdb/testsuite/gdb.base/foll-vfork.exp [new file with mode: 0644]

diff --git a/gdb/testsuite/gdb.base/dbx.exp b/gdb/testsuite/gdb.base/dbx.exp
new file mode 100644 (file)
index 0000000..05f3fe4
--- /dev/null
@@ -0,0 +1,319 @@
+# Copyright (C) 1998 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+# Please email any bugs, comments, and/or additions to this file to:
+# bug-gdb@prep.ai.mit.edu
+
+
+if $tracelevel then {
+        strace $tracelevel
+}
+
+set testfile1 "average"
+set testfile2 "sum"
+set testfile "dbx-test"
+set binfile1 ${objdir}/${subdir}/${testfile1}
+set binfile2 ${objdir}/${subdir}/${testfile2}
+set binfile ${objdir}/${subdir}/${testfile}
+
+
+
+if  { [gdb_compile "${srcdir}/${subdir}/average.c" "${binfile1}.o" object {debug}] != "" } {
+     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+}
+
+if  { [gdb_compile "${srcdir}/${subdir}/sum.c" "${binfile2}.o" object {debug}] != "" } {
+     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+}
+
+if  { [gdb_compile "${binfile1}.o ${binfile2}.o" ${binfile} executable {debug}] != "" } {
+     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+}
+
+#
+# start gdb -- start gdb running, default procedure
+#
+proc dbx_gdb_start { } {
+    global verbose
+    global GDB
+    global GDBFLAGS
+    global prompt
+    global spawn_id
+    global timeout
+    verbose "Spawning $GDB -nw $GDBFLAGS"
+
+    if { [which $GDB] == 0 } then {
+        perror "$GDB does not exist."
+        exit 1
+    }
+
+    set oldtimeout $timeout
+    set timeout [expr "$timeout + 60"]
+    eval "spawn $GDB -nw -dbx $GDBFLAGS"
+    gdb_expect {
+        -re ".*\r\n$gdb_prompt $" {
+            verbose "GDB initialized."
+        }
+        -re "$prompt $" {
+            perror "GDB never initialized."
+            return -1
+        }
+        timeout         {
+            perror "(timeout) GDB never initialized."
+            return -1
+        }
+    }
+    set timeout $oldtimeout
+    # force the height to "unlimited", so no pagers get used
+    send_gdb "set height 0\n"
+    gdb_expect {
+        -re ".*$prompt $" {
+            verbose "Setting height to 0." 2
+        }
+        timeout {
+            warning "Couldn't set the height to 0."
+        }
+    }
+    # force the width to "unlimited", so no wraparound occurs
+    send_gdb "set width 0\n"
+    gdb_expect {
+        -re ".*$prompt $" {
+            verbose "Setting width to 0." 2
+        }
+        timeout {
+            warning "Couldn't set the width to 0."
+        }
+    }
+}
+
+
+proc dbx_reinitialize_dir { subdir } {
+    global gdb_prompt
+
+   send_gdb "use\n"
+    gdb_expect {
+        -re "Reinitialize source path to empty.*y or n. " {
+            send_gdb "y\n"
+            gdb_expect {
+                -re "Source directories searched.*$gdb_prompt $" {
+                    send_gdb "use $subdir\n"
+                    gdb_expect {
+                        -re "Source directories searched.*$gdb_prompt $" {
+                            verbose "Dir set to $subdir"
+                        }
+                        -re ".*$gdb_prompt $" {
+                            perror "Dir \"$subdir\" failed."
+                        }
+                    }
+                }
+                -re ".*$gdb_prompt $" {
+                    perror "Dir \"$subdir\" failed."
+                }
+            }
+        }
+        -re ".*$gdb_prompt $" {
+            perror "Dir \"$subdir\" failed."
+        }
+    }
+}
+
+# In "testsuite/config/unix-gdb.exp", the routine "gdb_load"
+# is defined as "gdb_file_cmd".  The binding of "gdb_file_cmd"
+# is done at invocation time.  Before this file is processed,
+# it binds to the definition in "testsuite/lib/gdb.exp"; after
+# this file is processed, it binds to this definition.
+# TCL lets us overrides a previous routine definition without a
+# warning (isn't that special?).
+#
+# This means that tests before use "file" to load a target, and
+# tests afterwards use the pair "symbol-file" "exec-file".
+#
+# I'm leaving it as it is for now because at the moment it
+# is the only test we have of the use of the combination of
+# "symbol-file" and "exec-file" to load a debugging target (the
+# other definition uses "file". 
+#
+# Symbol-file and exec-file should be tested explicitly, not
+# as a side effect of running a particular test (in this case,
+# "testsuite/gdb.compat/dbx.exp").
+#
+# CM: Renamed the procedure so it does not override the orginal file name.
+#     Having the test suite change behavior depending on the tests run makes
+#     it extremely difficult to reproduce errors. I've also added a
+#     "dbx_gdb_load" procedure.  This and only this test will call these
+#     procedures now. I also added an "expect" to the "send exec-file" line.
+#     The "expect" waits for a prompt to appear. Otherwise, if the tests run
+#     too quickly, the caller could send another command before the prompt
+#     of this command returns, causing the test to get out of sync and fail
+#     seemingly randomly or only on a loaded system.
+#
+proc dbx_gdb_file_cmd {arg } {
+    global verbose
+    global loadpath
+    global loadfile
+    global GDB
+    global gdb_prompt
+    global spawn_id
+    upvar timeout timeout
+
+    send_gdb "symbol-file $arg\n"
+    gdb_expect {
+       -re "Detected 64-bit symbol file.\r\nInvoking.*gdb64.*$gdb_prompt $" {
+            verbose "\t\tLoaded $arg into the $GDB"
+            send_gdb "exec-file $arg\n" 
+            gdb_expect {
+                -re ".*$gdb_prompt $" {
+                    verbose "\t\tLoaded $arg with new symbol table into $GDB"
+                    return 0
+                }
+                timeout {
+                    perror "(timeout) Couldn't load $arg"
+                    return -1
+                }
+            }
+            return 0
+        }
+        -re "Reading symbols from.*done.*$gdb_prompt $" {
+            verbose "\t\tLoaded $arg into the $GDB"
+            send_gdb "exec-file $arg\n" 
+            gdb_expect {
+                -re ".*$gdb_prompt $" {
+                    verbose "\t\tLoaded $arg with new symbol table into $GDB"
+                    return 0
+                }
+                timeout {
+                    perror "(timeout) Couldn't load $arg"
+                    return -1
+                }
+            }
+            return 0
+        }
+        -re "has no symbol-table.*$gdb_prompt $" {
+            perror "$arg wasn't compiled with \"-g\""
+            return -1
+        }
+        -re "A program is being debugged already.*Kill it.*y or n. $" {
+            send_gdb "y\n"
+                verbose "\t\tKilling previous program being debugged"
+            exp_continue
+        }
+        -re "Load new symbol table from \".*\".*y or n. $" {
+            send_gdb "y\n"
+            gdb_expect {
+                -re "Reading symbols from.*done.*$gdb_prompt $" {
+                    verbose "\t\tLoaded $arg with new symbol table into $GDB"
+                    return 0
+                }
+                timeout {
+                    perror "(timeout) Couldn't load $arg, other program already loaded."
+                    return -1
+                }
+            }
+        }
+        -re ".*No such file or directory.*$gdb_prompt $" {
+            perror "($arg) No such file or directory\n"
+            return -1
+        }
+        -re "$gdb_prompt $" {
+            perror "couldn't load $arg into $GDB."
+            return -1
+            }
+        timeout {
+            perror "couldn't load $arg into $GDB (timed out)."
+            return -1
+        }
+        eof {
+            # This is an attempt to detect a core dump, but seems not to
+            # work.  Perhaps we need to match .* followed by eof, in which
+            # expect does not seem to have a way to do that.
+            perror "couldn't load $arg into $GDB (end of file)."
+            return -1
+        }
+    }
+}
+
+proc dbx_gdb_load { arg } {
+    global verbose
+    global loadpath
+    global loadfile
+    global GDB
+    global prompt
+    upvar timeout timeout
+
+    return [dbx_gdb_file_cmd $arg]
+}
+
+#
+#test_breakpoints
+#
+proc test_breakpoints { } {
+    gdb_test "stop in main" "Breakpoint.*at.*: file.*average\.c, line 38\."
+    gdb_test "status" "Num.*Type.*Disp.*Enb.*Address.*What\r\n1\[ \r\]+breakpoint\[ \r\]+keep y.*in main at.*average\.c:38.*"
+    gdb_test "stop at 43" "Breakpoint.*at.*: file.*average\.c, line 43.*"
+    gdb_test "stop in 43" "Usage: stop in <function . address>"
+    gdb_test "stop at main" "Usage: stop at <line>"
+}
+
+#
+#test_assign
+#
+proc test_assign { } {
+    gdb_test "run" ""
+    gdb_test "assign first=1" ""
+    gdb_test "print first" ".1 = 1"
+}
+
+#
+#test_whereis
+#
+proc test_whereis { } {
+    gdb_test "whereis my_list" "All variables matching regular expression \"my_list\":\r\n\r\nFile.*average\.c:\r\nstatic int my_list\\\[10\\\];"
+}
+
+#
+#test_func
+#
+proc test_func { } {
+    gdb_test "cont" ""
+    gdb_test "step" ""
+    gdb_test "func sum" "'sum' not within current stack frame\."
+    gdb_test "stop in sum" "Breakpoint.*at.*: file.*sum\.c, line 11\."
+    gdb_test "cont"
+    gdb_test "func print_average" ".*in print_average.*\\(list=.*, low=0, high=6\\).*at.*average\.c:24\r\n24\[ \t\]+total = sum\\(list, low, high\\);"
+}
+
+# Start with a fresh gdb.
+
+gdb_exit
+global GDBFLAGS
+set saved_gdbflags $GDBFLAGS
+
+set GDBFLAGS "$GDBFLAGS --dbx"
+gdb_start
+dbx_reinitialize_dir $srcdir/$subdir
+dbx_gdb_load ${binfile}
+
+test_breakpoints
+test_assign
+test_whereis
+gdb_test "file average.c:1" "1\[ \t\]+/. This is a sample program.*"
+test_func
+
+#exit and cleanup
+gdb_exit
+
+set GDBFLAGS $saved_gdbflags
+return 0
diff --git a/gdb/testsuite/gdb.base/execd-prog.c b/gdb/testsuite/gdb.base/execd-prog.c
new file mode 100644 (file)
index 0000000..5469f65
--- /dev/null
@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+/* There is a global_i in foll-exec, which exec's us.  We
+   should not be able to see that other definition of global_i
+   after we are exec'd.
+   */
+int  global_i = 0;
+
+#ifdef PROTOTYPES
+int main (int argc, char **argv)
+#else
+main (argc, argv)
+  int  argc;
+  char *  argv[];
+#endif
+{
+  /* There is a local_j in foll-exec, which exec's us.  We
+     should not be able to see that other definition of local_j
+     after we are exec'd.
+     */
+  int  local_j = argc;
+  char *  s;
+
+  printf ("Hello from execd-prog...\n");
+  if (argc != 2)
+    {
+      printf ("expected one string argument\n");
+      exit (-1);
+    }
+  s = argv[1];
+  printf ("argument received: %s\n", s);
+}
diff --git a/gdb/testsuite/gdb.base/foll-exec.c b/gdb/testsuite/gdb.base/foll-exec.c
new file mode 100644 (file)
index 0000000..1b76090
--- /dev/null
@@ -0,0 +1,43 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+
+int  global_i = 100;
+
+#ifdef PROTOTYPES
+int main (void)
+#else
+main ()
+#endif
+{
+  int  local_j = global_i+1;
+  int  local_k = local_j+1;
+
+  printf ("foll-exec is about to execlp(execd-prog)...\n");
+
+  execlp ("gdb.base/execd-prog",
+          "gdb.base/execd-prog",
+          "execlp arg1 from foll-exec",
+          (char *)0);
+
+  printf ("foll-exec is about to execl(execd-prog)...\n");
+
+  execl ("gdb.base/execd-prog",
+         "gdb.base/execd-prog",
+         "execl arg1 from foll-exec",
+         "execl arg2 from foll-exec",
+         (char *)0);
+
+  {
+    static char * argv[] = {
+      (char *)"gdb.base/execd-prog",
+      (char *)"execv arg1 from foll-exec",
+      (char *)0};
+
+    printf ("foll-exec is about to execv(execd-prog)...\n");
+
+    execv ("gdb.base/execd-prog", argv);
+  }
+}
diff --git a/gdb/testsuite/gdb.base/foll-exec.exp b/gdb/testsuite/gdb.base/foll-exec.exp
new file mode 100644 (file)
index 0000000..4342d5f
--- /dev/null
@@ -0,0 +1,396 @@
+#   Copyright (C) 1997 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+# Please email any bugs, comments, and/or additions to this file to:
+# bug-gdb@prep.ai.mit.edu
+
+if $tracelevel then {
+       strace $tracelevel
+       }
+
+set prms_id 0
+set bug_id 0
+
+set testfile "foll-exec"
+set testfile2 "execd-prog"
+set srcfile ${testfile}.c
+set srcfile2 ${testfile2}.c
+set binfile ${objdir}/${subdir}/${testfile}
+set binfile2 ${objdir}/${subdir}/${testfile2}
+
+# build the first test case
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
+     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+}
+
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+}
+
+
+# Until "catch exec" is implemented on other targets...
+#
+if ![istarget "hppa*-hp-hpux*"] then {
+    continue
+}
+
+proc zap_session {} {
+   global gdb_prompt
+   global binfile
+
+   send_gdb "kill\n"
+   gdb_expect {
+     -re ".*Kill the program being debugged.*y or n. $" {
+       send_gdb "y\n"
+       send_gdb "file $binfile\n"
+       gdb_expect {
+         -re ".*Load new symbol table from.*y or n. $" {
+           send_gdb "y\n"
+           gdb_expect {
+             -re "Reading symbols from.*$gdb_prompt $" {}
+             timeout { fail "loading symbols (timeout)"; return }
+           }
+         }
+         -re ".*gdb_prompt $" {}
+         timeout { fail "loading symbols (timeout)"; return }
+       }
+    }
+    -re ".*$gdb_prompt $" {}
+    timeout { fail "killing inferior (timeout)" ; return }
+   }
+}
+
+proc do_exec_tests {} {
+   global gdb_prompt
+   global binfile
+   global srcfile
+   global srcfile2
+   global testfile
+   global testfile2
+
+   # Start the program running, and stop at main.
+   #
+   if ![runto_main] then {
+     perror "Couldn't run ${testfile}"
+     return
+   }
+
+   # Verify that we can see various global and local variables
+   # in this program, and that they have expected values.  Some
+   # of these variables are also declared in the program we'll
+   # exec in a moment.
+   #
+   send_gdb "next 3\n"
+   gdb_expect {
+     -re "20.*execlp.*$gdb_prompt $"\
+                     {pass "step to exec call"}
+     -re "$gdb_prompt $" {fail "step to exec call"}
+     timeout         {fail "(timeout) step to exec call"}
+   }
+   send_gdb "print global_i\n"
+   gdb_expect {
+     -re ".* = 100.*$gdb_prompt $"\
+                     {pass "print follow-exec/global_i"}
+     -re "$gdb_prompt $" {fail "print follow-exec/global_i"}
+     timeout         {fail "(timeout) print follow-exec/global_i"}
+   }
+   send_gdb "print local_j\n"
+   gdb_expect {
+     -re ".* = 101.*$gdb_prompt $"\
+                     {pass "print follow-exec/local_j"}
+     -re "$gdb_prompt $" {fail "print follow-exec/local_j"}
+     timeout         {fail "(timeout) print follow-exec/local_j"}
+   }
+   send_gdb "print local_k\n"
+   gdb_expect {
+     -re ".* = 102.*$gdb_prompt $"\
+                     {pass "print follow-exec/local_k"}
+     -re "$gdb_prompt $" {fail "print follow-exec/local_k"}
+     timeout         {fail "(timeout) print follow-exec/local_k"}
+   }
+
+   # Try stepping through an execlp call, without catching it.
+   # We should stop in execd-program, at its first statement.
+   #
+   send_gdb "next\n"
+   gdb_expect {
+     -re "Executing new program: .*${testfile2}.*${srcfile2}:23.*int  local_j = argc;.*$gdb_prompt $"\
+                     {pass "step through execlp call"}
+     -re "$gdb_prompt $" {fail "step through execlp call"}
+     timeout         {fail "(timeout) step through execlp call"}
+   }
+
+   # Verify that we can see the variables defined in the newly-exec'd
+   # program, and CANNOT see those defined in the exec'ing program.
+   #
+   send_gdb "next\n"
+   gdb_expect {
+     -re "26.*printf.*$gdb_prompt $"\
+                     {pass "step after execlp call"}
+     -re "$gdb_prompt $" {fail "step after execlp call"}
+     timeout         {fail "(timeout) step after execlp call"}
+   }
+   send_gdb "print global_i\n"
+   gdb_expect {
+     -re ".* = 0.*$gdb_prompt $"\
+                     {pass "print execd-program/global_i (after execlp)"}
+     -re "$gdb_prompt $" {fail "print execd-program/global_i (after execlp)"}
+     timeout         {fail "(timeout) print execd-program/global_i (after execlp)"}
+   }
+   send_gdb "print local_j\n"
+   gdb_expect {
+     -re ".* = 2.*$gdb_prompt $"\
+                     {pass "print execd-program/local_j (after execlp)"}
+     -re "$gdb_prompt $" {fail "print execd-program/local_j (after execlp)"}
+     timeout         {fail "(timeout) print execd-program/local_j (after execlp)"}
+   }
+   send_gdb "print local_k\n"
+   gdb_expect {
+     -re "No symbol \"local_k\" in current context.*$gdb_prompt $"\
+                     {pass "print follow-exec/local_k (after execlp)"}
+     -re "$gdb_prompt $" {fail "print follow-exec/local_k (after execlp)"}
+     timeout         {fail "(timeout) print follow-exec/local_k (after execlp)"}
+   }
+
+   # Explicitly kill this program, or a subsequent rerun actually runs
+   # the exec'd program, not the original program...
+   zap_session
+
+   # Start the program running, and stop at main.
+   #
+   if ![runto_main] then {
+     perror "Couldn't run ${testfile} (2nd try)"
+     return
+   }
+
+   # Verify that we can catch an exec event, and then continue
+   # to follow through the exec.  (Since there's a breakpoint on
+   # "main", it'll also be transferred to the exec'd program,
+   # and we expect to stop there.)
+   #
+   send_gdb "catch exec\n"
+   gdb_expect {
+     -re "Catchpoint .*(exec).*$gdb_prompt $"\
+                     {pass "set catch exec"}
+     -re "$gdb_prompt $" {fail "set catch exec"}
+     timeout         {fail "(timeout) set catch exec"}
+   }
+
+   # Verify that the catchpoint is mentioned in an "info breakpoints",
+   # and further that the catchpoint mentions no program name.
+   #
+   send_gdb "info breakpoints\n"
+   gdb_expect {
+     -re ".*catch exec.*keep y.*$gdb_prompt $"\
+                     {pass "info shows catchpoint without exec pathname"}
+     -re ".*catch exec.*program \"\".*$gdb_prompt $"\
+                     {fail "info shows catchpoint without exec pathname"}
+     -re "$gdb_prompt $" {fail "info shows catchpoint without exec pathname"}
+     timeout         {fail "(timeout) info shows catchpoint without exec pathname"}
+   }
+
+   # DTS CLLbs16760
+   # PA64 doesn't know about $START$ in dld.sl at this point.  It should.
+   # - Michael Coulter
+   setup_xfail hppa2.0w-hp-hpux*
+   send_gdb "continue\n"
+   gdb_expect {
+     -re ".*Executing new program:.*${testfile2}.*Catchpoint .*(exec\'d .*${testfile2}).*in .START..*$gdb_prompt $"\
+                     {pass "hit catch exec"}
+     -re "$gdb_prompt $" {fail "hit catch exec"}
+     timeout         {fail "(timeout) hit catch exec"}
+   }
+
+   # DTS CLLbs16760
+   # test gets out of sync if previous test fails.
+   gdb_test "bt" ".*" "sync up after possible failure 1"
+   gdb_test "bt" "#0.*" "sync up after possible failure 2"
+
+   # Verify that the catchpoint is mentioned in an "info breakpoints",
+   # and further that the catchpoint managed to capture the exec'd
+   # program's name.
+   #
+   send_gdb "info breakpoints\n"
+   gdb_expect {
+     -re ".*catch exec .*program \".*${testfile2}\".*$gdb_prompt $"\
+                     {pass "info shows catchpoint exec pathname"}
+     -re "$gdb_prompt $" {fail "info shows catchpoint exec pathname"}
+     timeout         {fail "(timeout) info shows catchpoint exec pathname"}
+   }
+
+   # Verify that we can continue from the catchpoint, and land in the
+   # main of the newly-exec'd program.
+   #
+   send_gdb "continue\n"
+   gdb_expect {
+     -re ".*${srcfile2}:23.*$gdb_prompt $"\
+                     {pass "continue after hit catch exec"}
+     -re "$gdb_prompt $" {fail "continue after hit catch exec"}
+     timeout         {fail "(timeout) continue after hit catch exec"}
+   }
+
+   # Explicitly kill this program, or a subsequent rerun actually runs
+   # the exec'd program, not the original program...
+   zap_session
+
+   # Start the program running, and stop at main.
+   #
+   if ![runto_main] then {
+     perror "Couldn't run ${testfile} (3rd try)"
+     return
+   }
+
+   # Verify that we can follow through follow an execl()
+   # call.  (We must jump around earlier exec* calls.)
+   #
+   send_gdb "tbreak 27\n"
+   gdb_expect {
+     -re "Breakpoint .*file .*${srcfile}, line 27.*$gdb_prompt $"\
+                     {pass "prepare to jump to execl call"}
+     -re "$gdb_prompt $" {fail "prepare to jump to execl call"}
+     timeout         {fail "(timeout) prepare to jump to execl call"}
+   }
+   send_gdb "jump 27\n"
+   gdb_expect {
+     -re "main.* at .*${srcfile}:27.*$gdb_prompt $"\
+                     {pass "jump to execl call"}
+     -re "$gdb_prompt $" {fail "jump to execl call"}
+     timeout         {fail "(timeout) jump to execl call"}
+   }
+   # Note that stepping through an exec call causes the step-count
+   # to be reset to zero.  I.e.: you may specify "next 2" at the
+   # call, but you'll actually stop at the first breakpoint set in
+   # the newly-exec'd program, not after the remaining step-count
+   # reaches zero.
+   #
+   send_gdb "next 2\n"
+   gdb_expect {
+     -re "Executing new program: .*${testfile2}.*${srcfile2}:23.*int  local_j = argc;.*$gdb_prompt $"\
+                     {pass "step through execl call"}
+     -re "$gdb_prompt $" {fail "step through execl call"}
+     timeout         {fail "(timeout) step through execl call"}
+   }
+   send_gdb "next\n"
+   gdb_expect {
+     -re "26.*printf.*$gdb_prompt $"\
+                     {pass "step after execl call"}
+     -re "$gdb_prompt $" {fail "step after execl call"}
+     timeout         {fail "(timeout) step after execl call"}
+   }
+
+   # Verify that we can print a local variable (which happens to be
+   # assigned the value of main's argc).
+   #
+   send_gdb "print local_j\n"
+   gdb_expect {
+     -re ".* = 3.*$gdb_prompt $"\
+                     {pass "print execd-program/local_j (after execl)"}
+     -re "$gdb_prompt $" {fail "print execd-program/local_j (after execl)"}
+     timeout         {fail "(timeout) print execd-program/local_j (after execl)"}
+   }
+
+   # Explicitly kill this program, or a subsequent rerun actually runs
+   # the exec'd program, not the original program...
+   zap_session
+
+   # Start the program running, and stop at main.
+   #
+   if ![runto_main] then {
+     perror "Couldn't run ${testfile} (4th try)"
+     return
+   }
+
+   # Verify that we can follow through follow an execv()
+   # call.  (We must jump around earlier exec* calls.)
+   #
+   send_gdb "tbreak 41\n"
+   gdb_expect {
+     -re "Breakpoint .*file .*${srcfile}, line 41.*$gdb_prompt $"\
+                     {pass "prepare to jump to execv call"}
+     -re "$gdb_prompt $" {fail "prepare to jump to execv call"}
+     timeout         {fail "(timeout) prepare to jump to execv call"}
+   }
+   send_gdb "jump 41\n"
+   gdb_expect {
+     -re "main.* at .*${srcfile}:41.*$gdb_prompt $"\
+                     {pass "jump to execv call"}
+     -re "$gdb_prompt $" {fail "jump to execv call"}
+     timeout         {fail "(timeout) jump to execv call"}
+   }
+   send_gdb "next\n"
+   gdb_expect {
+     -re "Executing new program: .*${testfile2}.*${srcfile2}:23.*int  local_j = argc;.*$gdb_prompt $"\
+                     {pass "step through execv call"}
+     -re "$gdb_prompt $" {fail "step through execv call"}
+     timeout         {fail "(timeout) step through execv call"}
+   }
+   send_gdb "next\n"
+   gdb_expect {
+     -re "26.*printf.*$gdb_prompt $"\
+                     {pass "step after execv call"}
+     -re "$gdb_prompt $" {fail "step after execv call"}
+     timeout         {fail "(timeout) step after execv call"}
+   }
+
+   # Verify that we can print a local variable (which happens to be
+   # assigned the value of main's argc).
+   #
+   send_gdb "print local_j\n"
+   gdb_expect {
+     -re ".* = 2.*$gdb_prompt $"\
+                     {pass "print execd-program/local_j (after execv)"}
+     -re "$gdb_prompt $" {fail "print execd-program/local_j (after execv)"}
+     timeout         {fail "(timeout) print execd-program/local_j (after execv)"}
+   }
+
+   # Explicitly kill this program, or a subsequent rerun actually runs
+   # the exec'd program, not the original program...
+   zap_session
+
+   # Start the program running, and stop at main.
+   #
+   if ![runto_main] then {
+     perror "Couldn't run ${testfile} (5th try)"
+     return
+   }
+
+   # Verify that we can just continue and thereby follow through an
+   # exec call.  (Since the breakpoint on "main" is reset, we should
+   # just stop in main of the newly-exec'd program.)
+   #
+   send_gdb "continue\n"
+   gdb_expect {
+     -re "Executing new program: .*${testfile2}.*${srcfile2}:23.*int  local_j = argc;.*$gdb_prompt $"\
+                     {pass "continue through exec"}
+     -re "$gdb_prompt $" {fail "continue through exec"}
+     timeout         {fail "(timeout) continue through exec"}
+   }
+}
+
+# Start with a fresh gdb
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+
+# This is a test of gdb's ability to follow a process through a
+# Unix exec() system call.
+#
+do_exec_tests
+
+return 0
diff --git a/gdb/testsuite/gdb.base/foll-fork.c b/gdb/testsuite/gdb.base/foll-fork.c
new file mode 100644 (file)
index 0000000..841258f
--- /dev/null
@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include <unistd.h>
+
+#ifdef PROTOTYPES
+void callee (int i)
+#else
+void callee (i)
+  int  i;
+#endif
+{
+  printf("callee: %d\n", i);
+}
+
+#ifdef PROTOTYPES
+int main (void)
+#else
+main ()
+#endif
+{
+  int  pid;
+  int  v = 5;
+
+  pid = fork ();
+  if (pid == 0)
+    {
+      v++;
+      /* printf ("I'm the child!\n"); */
+    }
+  else
+    {
+      v--;
+      /* printf ("I'm the proud parent of child #%d!\n", pid); */
+    }
+}
diff --git a/gdb/testsuite/gdb.base/foll-fork.exp b/gdb/testsuite/gdb.base/foll-fork.exp
new file mode 100644 (file)
index 0000000..23afedd
--- /dev/null
@@ -0,0 +1,363 @@
+#   Copyright (C) 1997 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+# Please email any bugs, comments, and/or additions to this file to:
+# bug-gdb@prep.ai.mit.edu
+
+if $tracelevel then {
+       strace $tracelevel
+       }
+
+set prms_id 0
+set bug_id 0
+
+set testfile "foll-fork"
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+}
+
+
+
+# Until "set follow-fork-mode" and "catch fork" are implemented on
+# other targets...
+#
+if ![istarget "hppa*-hp-hpux*"] then {
+    continue
+}
+
+proc default_fork_parent_follow {} {
+   global gdb_prompt
+
+   send_gdb "show follow\n"
+   gdb_expect {
+      -re "Debugger response to a program call of fork or vfork is \"parent\"..*$gdb_prompt $"\
+                      {pass "default show parent follow, no catchpoints"}
+      -re "$gdb_prompt $" {fail "default show parent follow, no catchpoints"}
+      timeout         {fail "(timeout) default show parent follow, no catchpoints"}
+   }
+   send_gdb "next 2\n"
+   gdb_expect {
+      -re "Detaching after fork from.*$gdb_prompt $"\
+                      {pass "default parent follow, no catchpoints"}
+      -re "$gdb_prompt $" {fail "default parent follow, no catchpoints"}
+      timeout         {fail "(timeout) default parent follow, no catchpoints" }
+   }
+   # The child has been detached; allow time for any output it might
+   # generate to arrive, so that output doesn't get confused with
+   # any expected debugger output from a subsequent testpoint.
+   #
+   exec sleep 1
+}
+
+proc explicit_fork_parent_follow {} {
+   global gdb_prompt
+
+   send_gdb "set follow parent\n"
+   gdb_expect {
+      -re "$gdb_prompt $" {pass "set follow parent"}
+      timeout         {fail "(timeout) set follow parent"}
+   }
+   send_gdb "show follow\n"
+   gdb_expect {
+      -re "Debugger response to a program call of fork or vfork is \"parent\"..*$gdb_prompt $"\
+                      {pass "explicit show parent follow, no catchpoints"}
+      -re "$gdb_prompt $" {fail "explicit show parent follow, no catchpoints"}
+      timeout         {fail "(timeout) explicit show parent follow, no catchpoints"}
+   }
+   send_gdb "next 2\n"
+   gdb_expect {
+      -re "Detaching after fork from.*$gdb_prompt $"\
+                      {pass "explicit parent follow, no catchpoints"}
+      -re "$gdb_prompt $" {fail "explicit parent follow, no catchpoints"}
+      timeout         {fail "(timeout) explicit parent follow, no catchpoints"}
+   }
+   # The child has been detached; allow time for any output it might
+   # generate to arrive, so that output doesn't get confused with
+   # any expected debugger output from a subsequent testpoint.
+   #
+   exec sleep 1
+}
+
+proc explicit_fork_child_follow {} {
+   global gdb_prompt
+
+   send_gdb "set follow child\n"
+   gdb_expect {
+      -re "$gdb_prompt $" {pass "set follow child"}
+      timeout         {fail "(timeout) set follow child"}
+   }
+   send_gdb "show follow\n"
+   gdb_expect {
+      -re "Debugger response to a program call of fork or vfork is \"child\"..*$gdb_prompt $"\
+                      {pass "explicit show child follow, no catchpoints"}
+      -re "$gdb_prompt $" {fail "explicit show child follow, no catchpoints"}
+      timeout         {fail "(timeout) explicit show child follow, no catchpoints"}
+   }
+   send_gdb "next 2\n"
+   gdb_expect {
+      -re "Detaching from program:.*Attaching after fork to.*$gdb_prompt $"\
+                      {pass "explicit child follow, no catchpoints"}
+      -re "$gdb_prompt $" {fail "explicit child follow, no catchpoints"}
+      timeout         {fail "(timeout) explicit child follow, no catchpoints"}
+   }
+   # The child has been detached; allow time for any output it might
+   # generate to arrive, so that output doesn't get confused with
+   # any gdb_expected debugger output from a subsequent testpoint.
+   #
+   exec sleep 1
+}
+
+proc catch_fork_child_follow {} {
+   global gdb_prompt
+
+   send_gdb "catch fork\n"
+   gdb_expect {
+      -re "Catchpoint .*(fork).*$gdb_prompt $"\
+                      {pass "explicit child follow, set catch fork"}
+      -re "$gdb_prompt $" {fail "explicit child follow, set catch fork"}
+      timeout         {fail "(timeout) explicit child follow, set catch fork"}
+   }
+
+   # Verify that the catchpoint is mentioned in an "info breakpoints",
+   # and further that the catchpoint mentions no process id.
+   #
+   send_gdb "info breakpoints\n"
+   gdb_expect {
+     -re ".*catch fork.*keep y.*$gdb_prompt $"\
+                     {pass "info shows catchpoint without pid"}
+     -re ".*catch fork.*process .*$gdb_prompt $"\
+                     {fail "info shows catchpoint without pid"}
+     -re "$gdb_prompt $" {fail "info shows catchpoint without pid"}
+     timeout         {fail "(timeout) info shows catchpoint without pid"}
+   }
+
+   send_gdb "continue\n"
+   gdb_expect {
+      -re "Catchpoint.*(forked process.*),.*in _fork_sys.*$gdb_prompt $"\
+                      {pass "explicit child follow, catch fork"}
+      -re "$gdb_prompt $" {fail "explicit child follow, catch fork"}
+      timeout         {fail "(timeout) explicit child follow, catch fork"}
+   }
+
+   # Verify that the catchpoint is mentioned in an "info breakpoints",
+   # and further that the catchpoint managed to capture a process id.
+   #
+   send_gdb "info breakpoints\n"
+   gdb_expect {
+     -re ".*catch fork .*process \[0-9\]+.*$gdb_prompt $"\
+                     {pass "info shows catchpoint pid"}
+     -re "$gdb_prompt $" {fail "info shows catchpoint pid"}
+     timeout         {fail "(timeout) info shows catchpoint pid"}
+   }
+
+   send_gdb "set follow child\n"
+   gdb_expect {
+      -re "$gdb_prompt $" {pass "set follow child"}
+      timeout         {fail "(timeout) set follow child"}
+   }
+   send_gdb "tbreak 24\n"
+   gdb_expect {
+      -re "Breakpoint.*, line 24.*$gdb_prompt $"\
+                      {pass "set follow child, tbreak"}
+      -re "$gdb_prompt $" {fail "set follow child, tbreak"}
+      timeout         {fail "(timeout) set follow child, tbreak"}
+   }
+   send_gdb "continue\n"
+   gdb_expect {
+      -re ".*Detaching from program:.*Attaching after fork to.* at .*24.*$gdb_prompt $"\
+                      {pass "set follow child, hit tbreak"}
+      -re "$gdb_prompt $" {fail "set follow child, hit tbreak"}
+      timeout         {fail "(timeout) set follow child, hit tbreak"}
+   }
+   # The child has been detached; allow time for any output it might
+   # generate to arrive, so that output doesn't get confused with
+   # any expected debugger output from a subsequent testpoint.
+   #
+   exec sleep 1
+   send_gdb "delete breakpoints\n"
+   gdb_expect {
+      -re "Delete all breakpoints.*$" {
+         send_gdb "y\n"
+         gdb_expect {
+            -re "$gdb_prompt $"\
+                    {pass "set follow child, cleanup"}
+            timeout {fail "(timeout) set follow child, cleanup"}
+         }
+      }
+      -re "$gdb_prompt $" {fail "set follow child, cleanup"}
+      timeout         {fail "(timeout) set follow child, cleanup"}
+   }
+}
+
+proc tcatch_fork_parent_follow {} {
+   global gdb_prompt
+
+   send_gdb "catch fork\n"
+   gdb_expect {
+      -re "Catchpoint .*(fork).*$gdb_prompt $"\
+                      {pass "explicit parent follow, set tcatch fork"}
+      -re "$gdb_prompt $" {fail "explicit parent follow, set tcatch fork"}
+      timeout         {fail "(timeout) explicit parent follow, set tcatch fork"}
+   }
+# ??rehrauer: I don't yet know how to get the id of the tcatch
+# via this script, so that I can add a -do list to it.  For now,
+# do the follow stuff after the catch happens.
+
+   send_gdb "continue\n"
+   gdb_expect {
+      -re ".*in _fork_sys.*$gdb_prompt $"\
+                      {pass "explicit parent follow, tcatch fork"}
+      -re "$gdb_prompt $" {fail "explicit parent follow, tcatch fork"}
+      timeout         {fail "(timeout) explicit parent follow, tcatch fork"}
+   }
+   send_gdb "set follow parent\n"
+   gdb_expect {
+      -re "$gdb_prompt $" {pass "set follow parent"}
+      timeout         {fail "(timeout) set follow parent"}
+   }
+   send_gdb "tbreak 24\n"
+   gdb_expect {
+      -re "Breakpoint.*, line 24.*$gdb_prompt $"\
+                      {pass "set follow parent, tbreak"}
+      -re "$gdb_prompt $" {fail "set follow parent, tbreak"}
+      timeout         {fail "(timeout) set follow child, tbreak"}
+   }
+   send_gdb "continue\n"
+   gdb_expect {
+      -re ".*Detaching after fork from.* at .*24.*$gdb_prompt $"\
+                      {pass "set follow parent, hit tbreak"}
+      -re "$gdb_prompt $" {fail "set follow parent, hit tbreak"}
+      timeout         {fail "(timeout) set follow parent, hit tbreak"}
+   }
+   # The child has been detached; allow time for any output it might
+   # generate to arrive, so that output doesn't get confused with
+   # any expected debugger output from a subsequent testpoint.
+   #
+   exec sleep 1
+   send_gdb "delete breakpoints\n"
+   gdb_expect {
+      -re "Delete all breakpoints.*$" {
+         send_gdb "y\n"
+         gdb_expect {
+            -re "$gdb_prompt $"\
+                    {pass "set follow parent, cleanup"}
+            timeout {fail "(timeout) set follow parent, cleanup"}
+         }
+      }
+      -re "$gdb_prompt $" {fail "set follow parent, cleanup"}
+      timeout         {fail "(timeout) set follow parent, cleanup"}
+   }
+}
+
+proc do_fork_tests {} {
+   global gdb_prompt
+
+   # Verify that help is available for "set follow-fork-mode".
+   #
+   send_gdb "help set follow-fork-mode\n"
+   gdb_expect {
+      -re "Set debugger response to a program call of fork or vfork..*
+A fork or vfork creates a new process.  follow-fork-mode can be:.*
+.*parent  - the original process is debugged after a fork.*
+.*child   - the new process is debugged after a fork.*
+.*ask     - the debugger will ask for one of the above choices.*
+For \"parent\" or \"child\", the unfollowed process will run free..*
+By default, the debugger will follow the parent process..*$gdb_prompt $"\
+                      { pass "help set follow" }
+      -re "$gdb_prompt $" { fail "help set follow" }
+      timeout         { fail "(timeout) help set follow" }
+   }
+
+   # Verify that we can set follow-fork-mode, using an abbreviation
+   # for both the flag and its value.
+   #
+   send_gdb "set follow ch\n"
+   send_gdb "show fol\n"
+   gdb_expect {
+     -re "Debugger response to a program call of fork or vfork is \"child\".*$gdb_prompt $"\
+             {pass "set follow, using abbreviations"}
+     timeout {fail "(timeout) set follow, using abbreviations"}
+   }
+
+   # Verify that we cannot set follow-fork-mode to nonsense.
+   #
+   send_gdb "set follow chork\n"
+   gdb_expect {
+     -re "Undefined item: \"chork\".*$gdb_prompt $"\
+                     {pass "set follow to nonsense is prohibited"}
+     -re "$gdb_prompt $" {fail "set follow to nonsense is prohibited"}
+     timeout         {fail "(timeout) set follow to nonsense is prohibited"}
+   }
+   send_gdb "set follow parent\n"
+   gdb_expect {
+     -re "$gdb_prompt $" {pass "set follow to nonsense is prohibited (reset parent)"}
+     timeout         {fail "set follow to nonsense is prohibited (reset parent)"}
+   }
+
+   # Test the default behaviour, which is to follow the parent of a
+   # fork, and detach from the child.  Do this without catchpoints.
+   #
+   if [runto_main] then { default_fork_parent_follow }
+
+   # Test the ability to explicitly follow the parent of a fork, and
+   # detach from the child.  Do this without catchpoints.
+   #
+   if [runto_main] then { explicit_fork_parent_follow }
+
+   # Test the ability to follow the child of a fork, and detach from
+   # the parent.  Do this without catchpoints.
+   #
+   if [runto_main] then { explicit_fork_child_follow }
+
+   # Test the ability to follow both child and parent of a fork.  Do
+   # this without catchpoints.
+   # ??rehrauer: NYI.  Will add testpoints here when implemented.
+   #
+
+   # Test the ability to have the debugger ask the user at fork-time
+   # whether to follow the parent, child or both.  Do this without
+   # catchpoints.
+   # ??rehrauer: NYI.  Will add testpoints here when implemented.
+   #
+
+   # Test the ability to catch a fork, specify that the child be
+   # followed, and continue.  Make the catchpoint permanent.
+   #
+   if [runto_main] then { catch_fork_child_follow }
+
+   # Test the ability to catch a fork, specify via a -do clause that
+   # the parent be followed, and continue.  Make the catchpoint temporary.
+   #
+   if [runto_main] then { tcatch_fork_parent_follow }
+}
+
+# Start with a fresh gdb
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+
+# This is a test of gdb's ability to follow the parent, child or both
+# parent and child of a Unix fork() system call.
+#
+do_fork_tests
+
+return 0
diff --git a/gdb/testsuite/gdb.base/foll-vfork.c b/gdb/testsuite/gdb.base/foll-vfork.c
new file mode 100644 (file)
index 0000000..3c7fab5
--- /dev/null
@@ -0,0 +1,20 @@
+#include <stdio.h>
+#include <unistd.h>
+
+#ifdef PROTOTYPES
+int main (void)
+#else
+main ()
+#endif
+{
+  int  pid;
+
+  pid = vfork ();
+  if (pid == 0) {
+    printf ("I'm the child!\n");
+    execlp ("gdb.base/vforked-prog", "gdb.base/vforked-prog", (char *)0);
+  }
+  else {
+    printf ("I'm the proud parent of child #%d!\n", pid);
+  }
+}
diff --git a/gdb/testsuite/gdb.base/foll-vfork.exp b/gdb/testsuite/gdb.base/foll-vfork.exp
new file mode 100644 (file)
index 0000000..3a6f99f
--- /dev/null
@@ -0,0 +1,365 @@
+#   Copyright (C) 1997 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+# Please email any bugs, comments, and/or additions to this file to:
+# bug-gdb@prep.ai.mit.edu
+
+if $tracelevel then {
+       strace $tracelevel
+       }
+
+if [istarget "hppa2.0w-hp-hpux*"] {
+  warning "Don't run gdb.base/foll-vfork.exp until JAGaa43495 kernel problem is fixed."
+  return 0
+}
+
+set prms_id 0
+set bug_id 0
+
+set testfile "foll-vfork"
+set testfile2 "vforked-prog"
+set srcfile ${testfile}.c
+set srcfile2 ${testfile2}.c
+set binfile ${objdir}/${subdir}/${testfile}
+set binfile2 ${objdir}/${subdir}/${testfile2}
+
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+}
+
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
+     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+}
+
+
+# Until "set follow-fork-mode" and "catch vfork" are implemented on
+# other targets...
+#
+if ![istarget "hppa*-hp-hpux*"] then {
+    continue
+}
+
+# Test to see if we are on an HP-UX 10.20 and if so,
+# do not run these tests as catching vfork is disabled for
+# 10.20.
+
+if [istarget "hppa*-hp-hpux10.20"] then {
+    return 0
+}
+
+# A few of these tests require a little more time than the standard
+# timeout allows.
+set oldtimeout $timeout
+set timeout [expr "$timeout + 10"]
+
+proc vfork_parent_follow_through_step {} {
+   global gdb_prompt
+
+   send_gdb "set follow parent\n"
+   gdb_expect {
+      -re "$gdb_prompt $" {pass "set follow parent, vfork through step"}
+      timeout         {fail "set follow parent, vfork through step"}
+   }
+   send_gdb "next\n"
+   gdb_expect {
+      -re "Detaching after fork from.*13.*$gdb_prompt $"\
+                      {pass "vfork parent follow, through step"}
+      -re "$gdb_prompt $" {fail "vfork parent follow, through step"}
+      timeout         {fail "(timeout) vfork parent follow, through step" }
+   }
+   # The child has been detached; allow time for any output it might
+   # generate to arrive, so that output doesn't get confused with
+   # any gdb_expected debugger output from a subsequent testpoint.
+   #
+   exec sleep 1
+}
+
+proc vfork_parent_follow_to_bp {} {
+   global gdb_prompt
+
+   send_gdb "set follow parent\n"
+   gdb_expect {
+      -re "$gdb_prompt $" {pass "set follow parent, vfork to bp"}
+      timeout         {fail "set follow parent, vfork to bp"}
+   }
+   send_gdb "break 18\n"
+   gdb_expect {
+      -re "$gdb_prompt $" {pass "break, vfork to bp"}
+      timeout         {fail "break, vfork to bp"}
+   }
+   send_gdb "continue\n"
+   gdb_expect {
+      -re ".*Detaching after fork from process.*Breakpoint.*18.*$gdb_prompt $"\
+                      {pass "vfork parent follow, to bp"}
+      -re "$gdb_prompt $" {fail "vfork parent follow, to bp"}
+      timeout         {fail "(timeout) vfork parent follow, to bp" }
+   }
+   # The child has been detached; allow time for any output it might
+   # generate to arrive, so that output doesn't get confused with
+   # any expected debugger output from a subsequent testpoint.
+   #
+   exec sleep 1
+}
+
+proc vfork_and_exec_child_follow_to_main_bp {} {
+   global gdb_prompt
+   global binfile
+
+   send_gdb "set follow child\n"
+   gdb_expect {
+      -re "$gdb_prompt $" {pass "set follow child, vfork and exec to main bp"}
+      timeout         {fail "set follow child, vfork and exec to main bp"}
+   }
+   send_gdb "continue\n"
+   gdb_expect {
+      -re "Detaching from program.*Attaching after fork to.*Executing new program.*Breakpoint.*vforked-prog.c:9.*$gdb_prompt $"\
+                      {pass "vfork and exec child follow, to main bp"}
+      -re "$gdb_prompt $" {fail "vfork and exec child follow, to main bp"}
+      timeout         {fail "(timeout) vfork and exec child follow, to main bp" }
+   }
+   # The parent has been detached; allow time for any output it might
+   # generate to arrive, so that output doesn't get confused with
+   # any gdb_expected debugger output from a subsequent testpoint.
+   #
+   exec sleep 1
+
+   # Explicitly kill this child, or a subsequent rerun actually runs
+   # the exec'd child, not the original program...
+   send_gdb "kill\n"
+   gdb_expect {
+      -re ".*Kill the program being debugged.*y or n. $" {
+         send_gdb "y\n"
+         send_gdb "file $binfile\n"
+         gdb_expect {
+            -re ".*Load new symbol table from.*y or n. $" {
+               send_gdb "y\n"
+               gdb_expect {
+                  -re "Reading symbols from.*$gdb_prompt $" {}
+                  timeout { fail "loading symbols (timeout)"; return }
+               }
+            }
+            -re ".*gdb_prompt $" {}
+            timeout { fail "loading symbols (timeout)"; return }
+          }
+      }
+      -re ".*$gdb_prompt $" {}
+      timeout { fail "killing inferior (timeout)" ; return }
+    }
+}
+
+proc vfork_and_exec_child_follow_through_step {} {
+   global gdb_prompt
+   global binfile
+
+# This test cannot be performed prior to HP-UX 10.30, because ptrace-based
+# debugging of a vforking program basically doesn't allow the child to do
+# things like hit a breakpoint between a vfork and exec.  This means that
+# saying "set follow child; next" at a vfork() call won't work, because
+# the implementation of "next" sets a "step resume" breakpoint at the
+# return from the vfork(), which the child will hit on its way to exec'ing.
+#
+   if { ![istarget "hppa*-*-hpux10.30"] && ![istarget "hppa*-*-hpux11.*"] } {
+      verbose "vfork child-following next test ignored for non-hppa or pre-HP/UX-10.30 targets."
+      return 0
+   }
+
+   send_gdb "set follow child\n"
+   gdb_expect {
+      -re "$gdb_prompt $" {pass "set follow child, vfork and exec through step"}
+      timeout         {fail "set follow child, vfork and exec through step"}
+   }
+   send_gdb "next\n"
+   gdb_expect {
+      -re "Detaching from program.*Attaching after fork to.*Executing new program.*Breakpoint.*vforked-prog.c:9.*$gdb_prompt $"\
+                      {pass "vfork and exec child follow, through step"}
+      -re "$gdb_prompt $" {fail "vfork and exec child follow, through step"}
+      timeout         {fail "(timeout) vfork and exec child follow, through step" }
+   }
+   # The parent has been detached; allow time for any output it might
+   # generate to arrive, so that output doesn't get confused with
+   # any expected debugger output from a subsequent testpoint.
+   #
+   exec sleep 1
+
+   # Explicitly kill this child, or a subsequent rerun actually runs
+   # the exec'd child, not the original program...
+   send_gdb "kill\n"
+   gdb_expect {
+      -re ".*Kill the program being debugged.*y or n. $" {
+         send_gdb "y\n"
+         send_gdb "file $binfile\n"
+         gdb_expect {
+            -re ".*Load new symbol table from.*y or n. $" {
+               send_gdb "y\n"
+               gdb_expect {
+                  -re "Reading symbols from.*$gdb_prompt $" {}
+                  timeout { fail "loading symbols (timeout)"; return }
+               }
+            }
+            -re ".*gdb_prompt $" {}
+            timeout { fail "loading symbols (timeout)"; return }
+          }
+      }
+      -re ".*$gdb_prompt $" {}
+      timeout { fail "killing inferior (timeout)" ; return }
+    }
+}
+
+proc tcatch_vfork_then_parent_follow {} {
+   global gdb_prompt
+   global srcfile
+
+   send_gdb "set follow parent\n"
+   gdb_expect {
+      -re "$gdb_prompt $" {pass "set follow parent, tcatch vfork"}
+      timeout         {fail "set follow parent, tcatch vfork"}
+   }
+   send_gdb "tcatch vfork\n"
+   gdb_expect {
+      -re "Catchpoint .*(vfork).*$gdb_prompt $"\
+                      {pass "vfork parent follow, set tcatch vfork"}
+      -re "$gdb_prompt $" {fail "vfork parent follow, set tcatch vfork"}
+      timeout         {fail "(timeout) vfork parent follow, set tcatch vfork"}
+   }
+   send_gdb "continue\n"
+# HP-UX 10.20 seems to stop you in "vfork", while more recent HP-UXs
+# stop you in "_vfork".
+   gdb_expect {
+      -re "0x\[0-9a-fA-F\]*.*vfork.*$gdb_prompt $"\
+                      {pass "vfork parent follow, tcatch vfork"}
+      -re "0x\[0-9a-fA-F\]*.*_vfork.*$gdb_prompt $"\
+                      {pass "vfork parent follow, tcatch vfork"}
+      -re "$gdb_prompt $" {fail "vfork parent follow, tcatch vfork"}
+      timeout         {fail "(timeout) vfork parent follow, tcatch vfork"}
+   }
+   send_gdb "finish\n"
+   gdb_expect {
+      -re "Run till exit from.*vfork.*0x\[0-9a-fA-F\]* in main .* at .*${srcfile}:12.*$gdb_prompt $"\
+                      {pass "vfork parent follow, finish after tcatch vfork"}
+      -re "$gdb_prompt $" {fail "vfork parent follow, finish after tcatch vfork"}
+      timeout         {fail "(timeout) vfork parent follow, finish after tcatch vfork" }
+   }
+   # The child has been detached; allow time for any output it might
+   # generate to arrive, so that output doesn't get confused with
+   # any expected debugger output from a subsequent testpoint.
+   #
+   exec sleep 1
+}
+
+proc tcatch_vfork_then_child_follow {} {
+   global gdb_prompt
+   global srcfile2
+
+   send_gdb "set follow child\n"
+   gdb_expect {
+      -re "$gdb_prompt $" {pass "set follow child, tcatch vfork"}
+      timeout         {fail "set follow child, tcatch vfork"}
+   }
+   send_gdb "tcatch vfork\n"
+   gdb_expect {
+      -re "Catchpoint .*(vfork).*$gdb_prompt $"\
+                      {pass "vfork child follow, set tcatch vfork"}
+      -re "$gdb_prompt $" {fail "vfork child follow, set tcatch vfork"}
+      timeout         {fail "(timeout) vfork child follow, set tcatch vfork"}
+   }
+   send_gdb "continue\n"
+# HP-UX 10.20 seems to stop you in "vfork", while more recent HP-UXs
+# stop you in "_vfork".
+   gdb_expect {
+      -re "0x\[0-9a-fA-F\]*.*vfork.*$gdb_prompt $"\
+                      {pass "vfork child follow, tcatch vfork"}
+      -re "0x\[0-9a-fA-F\]*.*_vfork.*$gdb_prompt $"\
+                      {pass "vfork child follow, tcatch vfork"}
+      -re "$gdb_prompt $" {fail "vfork child follow, tcatch vfork"}
+      timeout         {fail "(timeout) vfork child follow, tcatch vfork"}
+   }
+   send_gdb "finish\n"
+   gdb_expect {
+      -re "Run till exit from.*vfork.*${srcfile2}:9.*$gdb_prompt $"\
+                      {pass "vfork child follow, finish after tcatch vfork"}
+      -re "$gdb_prompt $" {fail "vfork child follow, finish after tcatch vfork"}
+      timeout         {fail "(timeout) vfork child follow, finish after tcatch vfork" }
+   }
+   # The parent has been detached; allow time for any output it might
+   # generate to arrive, so that output doesn't get confused with
+   # any expected debugger output from a subsequent testpoint.
+   #
+   exec sleep 1
+}
+
+proc do_vfork_and_exec_tests {} {
+   global gdb_prompt
+
+   # Try following the parent process by stepping through a call to
+   # vfork.  Do this without catchpoints.
+   if [runto_main] then { vfork_parent_follow_through_step }
+
+   # Try following the parent process by setting a breakpoint on the
+   # other side of a vfork, and running to that point.  Do this
+   # without catchpoints.
+   if [runto_main] then { vfork_parent_follow_to_bp }
+
+   # Try following the child process by just continuing through the
+   # vfork, and letting the parent's breakpoint on "main" be auto-
+   # magically reset in the child.
+   #
+   if [runto_main] then { vfork_and_exec_child_follow_to_main_bp }
+
+   # Try following the child process by stepping through a call to
+   # vfork.  The child also executes an exec.  Since the child cannot
+   # be debugged until after it has exec'd, and since there's a bp on
+   # "main" in the parent, and since the bp's for the parent are
+   # recomputed in the exec'd child, the step through a vfork should
+   # land us in the "main" for the exec'd child, too.
+   #
+   if [runto_main] then { vfork_and_exec_child_follow_through_step }
+
+   # Try catching a vfork, and stepping out to the parent.
+   #
+   if [runto_main] then { tcatch_vfork_then_parent_follow }
+
+   # Try catching a vfork, and stepping out to the child.
+   #
+   if [runto_main] then { tcatch_vfork_then_child_follow }
+
+   # Test the ability to follow both child and parent of a vfork.  Do
+   # this without catchpoints.
+   # ??rehrauer: NYI.  Will add testpoints here when implemented.
+   #
+
+   # Test the ability to have the debugger ask the user at vfork-time
+   # whether to follow the parent, child or both.  Do this without
+   # catchpoints.
+   # ??rehrauer: NYI.  Will add testpoints here when implemented.
+   #
+}
+
+# Start with a fresh gdb
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+
+# This is a test of gdb's ability to follow the parent or child
+# of a Unix vfork() system call.  (The child will subsequently
+# call a variant of a Unix exec() system call.)
+#
+do_vfork_and_exec_tests
+
+set timeout $oldtimeout
+return 0