PR gdb/8704
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / foll-fork.exp
index 79a9a012b0b56a5b031457d350563886ab7b101e..c1eb1fca14be1e7191802c99e1fa20061c48ea6e 100644 (file)
@@ -1,4 +1,4 @@
-#   Copyright 1997, 1999, 2007, 2008 Free Software Foundation, Inc.
+#   Copyright 1997, 1999, 2007, 2008, 2009 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
@@ -64,7 +64,7 @@ proc check_fork_catchpoints {} {
 proc default_fork_parent_follow {} {
    global gdb_prompt
 
-   send_gdb "show follow\n"
+   send_gdb "show follow-fork\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"}
@@ -88,12 +88,12 @@ proc default_fork_parent_follow {} {
 proc explicit_fork_parent_follow {} {
    global gdb_prompt
 
-   send_gdb "set follow parent\n"
+   send_gdb "set follow-fork parent\n"
    gdb_expect {
-      -re "$gdb_prompt $" {pass "set follow parent"}
-      timeout         {fail "(timeout) set follow parent"}
+      -re "$gdb_prompt $" {pass "set follow-fork parent"}
+      timeout         {fail "(timeout) set follow-fork parent"}
    }
-   send_gdb "show follow\n"
+   send_gdb "show follow-fork\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"}
@@ -117,12 +117,12 @@ proc explicit_fork_parent_follow {} {
 proc explicit_fork_child_follow {} {
    global gdb_prompt
 
-   send_gdb "set follow child\n"
+   send_gdb "set follow-fork child\n"
    gdb_expect {
-      -re "$gdb_prompt $" {pass "set follow child"}
-      timeout         {fail "(timeout) set follow child"}
+      -re "$gdb_prompt $" {pass "set follow-fork child"}
+      timeout         {fail "(timeout) set follow-fork child"}
    }
-   send_gdb "show follow\n"
+   send_gdb "show follow-fork\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"}
@@ -131,7 +131,7 @@ proc explicit_fork_child_follow {} {
    }
    send_gdb "next 2\n"
    gdb_expect {
-      -re "Attaching after fork to.*$gdb_prompt $"\
+      -re "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"}
@@ -147,6 +147,8 @@ proc catch_fork_child_follow {} {
    global gdb_prompt
    global srcfile
 
+   set bp_after_fork [gdb_get_line_number "set breakpoint here"]
+
    send_gdb "catch fork\n"
    gdb_expect {
       -re "Catchpoint .*(fork).*$gdb_prompt $"\
@@ -167,7 +169,7 @@ proc catch_fork_child_follow {} {
 
    send_gdb "continue\n"
    gdb_expect {
-      -re "Catchpoint.*(forked process.*),.*in .*(fork|__kernel_vsyscall).*$gdb_prompt $"\
+      -re "Catchpoint.*(forked process.*),.*in .*(fork|__kernel_v?syscall).*$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"}
@@ -183,26 +185,26 @@ proc catch_fork_child_follow {} {
      }
    }
 
-   send_gdb "set follow child\n"
+   send_gdb "set follow-fork child\n"
    gdb_expect {
-      -re "$gdb_prompt $" {pass "set follow child"}
-      timeout         {fail "(timeout) set follow child"}
+      -re "$gdb_prompt $" {pass "set follow-fork child"}
+      timeout         {fail "(timeout) set follow-fork child"}
    }
-   send_gdb "tbreak ${srcfile}:24\n"
+   send_gdb "tbreak ${srcfile}:$bp_after_fork\n"
    gdb_expect {
-      -re "Temporary 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"}
+      -re "Temporary breakpoint.*, line $bp_after_fork.*$gdb_prompt $"\
+                      {pass "set follow-fork child, tbreak"}
+      -re "$gdb_prompt $" {fail "set follow-fork child, tbreak"}
+      timeout         {fail "(timeout) set follow-fork child, tbreak"}
    }
    send_gdb "continue\n"
    gdb_expect {
-      -re "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"}
+      -re "Attaching after.* fork to.* at .*$bp_after_fork.*$gdb_prompt $"\
+                      {pass "set follow-fork child, hit tbreak"}
+      -re "$gdb_prompt $" {fail "set follow-fork child, hit tbreak"}
+      timeout         {fail "(timeout) set follow-fork child, hit tbreak"}
    }
-   # The child has been detached; allow time for any output it might
+   # 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.
    #
@@ -213,12 +215,61 @@ proc catch_fork_child_follow {} {
          send_gdb "y\n"
          gdb_expect {
             -re "$gdb_prompt $"\
-                    {pass "set follow child, cleanup"}
-            timeout {fail "(timeout) set follow child, cleanup"}
+                    {pass "set follow-fork child, cleanup"}
+            timeout {fail "(timeout) set follow-fork child, cleanup"}
          }
       }
-      -re "$gdb_prompt $" {fail "set follow child, cleanup"}
-      timeout         {fail "(timeout) set follow child, cleanup"}
+      -re "$gdb_prompt $" {fail "set follow-fork child, cleanup"}
+      timeout         {fail "(timeout) set follow-fork child, cleanup"}
+   }
+}
+
+proc catch_fork_unpatch_child {} {
+   global gdb_prompt
+   global srcfile
+
+   set bp_exit [gdb_get_line_number "at exit"]
+
+   gdb_test "break callee" "file .*$srcfile, line .*" "unpatch child, break at callee"
+   gdb_test "catch fork" "Catchpoint \[0-9\]* \\(fork\\)" "unpatch child, set catch fork"
+
+   gdb_test "continue" \
+       "Catchpoint.*\\(forked process.*\\).*,.*in .*(fork|__kernel_v?syscall).*" \
+       "unpatch child, catch fork"
+
+   # Delete all breakpoints and catchpoints.
+   delete_breakpoints
+
+   gdb_test "break $bp_exit" \
+       "Breakpoint .*file .*$srcfile, line .*" \
+       "unpatch child, breakpoint at exit call"
+
+   gdb_test "set follow-fork child" "" "unpatch child, set follow-fork child"
+
+   set test "unpatch child, unpatched parent breakpoints from child"
+   gdb_test_multiple "continue" $test {
+      -re "at exit.*$gdb_prompt $" {
+         pass "$test"
+      }
+      -re "SIGTRAP.*$gdb_prompt $" {
+         fail "$test"
+
+         # Explicitly kill this child, so we can continue gracefully
+         # with further testing...
+         send_gdb "kill\n"
+         gdb_expect {
+             -re ".*Kill the program being debugged.*y or n. $" {
+                 send_gdb "y\n"
+                 gdb_expect -re "$gdb_prompt $" {}
+             }
+         }
+      }
+      -re ".*$gdb_prompt $" {
+         fail "$test (unknown output)"
+      }
+      timeout {
+         fail "$test (timeout)"
+      }
    }
 }
 
@@ -226,6 +277,8 @@ proc tcatch_fork_parent_follow {} {
    global gdb_prompt
    global srcfile
 
+   set bp_after_fork [gdb_get_line_number "set breakpoint here"]
+
    send_gdb "catch fork\n"
    gdb_expect {
       -re "Catchpoint .*(fork).*$gdb_prompt $"\
@@ -239,29 +292,29 @@ proc tcatch_fork_parent_follow {} {
 
    send_gdb "continue\n"
    gdb_expect {
-      -re ".*in .*(fork|__kernel_vsyscall).*$gdb_prompt $"\
+      -re ".*in .*(fork|__kernel_v?syscall).*$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"
+   send_gdb "set follow-fork parent\n"
    gdb_expect {
-      -re "$gdb_prompt $" {pass "set follow parent"}
-      timeout         {fail "(timeout) set follow parent"}
+      -re "$gdb_prompt $" {pass "set follow-fork parent"}
+      timeout         {fail "(timeout) set follow-fork parent"}
    }
-   send_gdb "tbreak ${srcfile}:24\n"
+   send_gdb "tbreak ${srcfile}:$bp_after_fork\n"
    gdb_expect {
-      -re "Temporary 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"}
+      -re "Temporary breakpoint.*, line $bp_after_fork.*$gdb_prompt $"\
+                      {pass "set follow-fork parent, tbreak"}
+      -re "$gdb_prompt $" {fail "set follow-fork parent, tbreak"}
+      timeout         {fail "(timeout) set follow-fork 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"}
+      -re ".*Detaching after fork from.* at .*$bp_after_fork.*$gdb_prompt $"\
+                      {pass "set follow-fork parent, hit tbreak"}
+      -re "$gdb_prompt $" {fail "set follow-fork parent, hit tbreak"}
+      timeout         {fail "(timeout) set follow-fork 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
@@ -274,12 +327,12 @@ proc tcatch_fork_parent_follow {} {
          send_gdb "y\n"
          gdb_expect {
             -re "$gdb_prompt $"\
-                    {pass "set follow parent, cleanup"}
-            timeout {fail "(timeout) set follow parent, cleanup"}
+                    {pass "set follow-fork parent, cleanup"}
+            timeout {fail "(timeout) set follow-fork parent, cleanup"}
          }
       }
-      -re "$gdb_prompt $" {fail "set follow parent, cleanup"}
-      timeout         {fail "(timeout) set follow parent, cleanup"}
+      -re "$gdb_prompt $" {fail "set follow-fork parent, cleanup"}
+      timeout         {fail "(timeout) set follow-fork parent, cleanup"}
    }
 }
 
@@ -296,35 +349,35 @@ A fork or vfork creates a new process.  follow-fork-mode can be:.*
 .*child   - the new process is debugged after a fork.*
 The unfollowed process will continue to run..*
 By default, the debugger will follow the parent process..*$gdb_prompt $"\
-                      { pass "help set follow" }
+                      { pass "help set follow-fork" }
       -re "$gdb_prompt $" { fail "help set follow" }
-      timeout         { fail "(timeout) help set follow" }
+      timeout         { fail "(timeout) help set follow-fork" }
    }
 
    # 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"
+   send_gdb "set follow-fork ch\n"
+   send_gdb "show follow-fork\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"}
+             {pass "set follow-fork, using abbreviations"}
+     timeout {fail "(timeout) set follow-fork, using abbreviations"}
    }
 
    # Verify that we cannot set follow-fork-mode to nonsense.
    #
-   send_gdb "set follow chork\n"
+   send_gdb "set follow-fork 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"}
+                     {pass "set follow-fork to nonsense is prohibited"}
+     -re "$gdb_prompt $" {fail "set follow-fork to nonsense is prohibited"}
+     timeout         {fail "(timeout) set follow-fork to nonsense is prohibited"}
    }
-   send_gdb "set follow parent\n"
+   send_gdb "set follow-fork 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)"}
+     -re "$gdb_prompt $" {pass "set follow-fork to nonsense is prohibited (reset parent)"}
+     timeout         {fail "set follow-fork to nonsense is prohibited (reset parent)"}
    }
 
    # Check that fork catchpoints are supported, as an indicator for whether
@@ -362,6 +415,11 @@ By default, the debugger will follow the parent process..*$gdb_prompt $"\
    #
    if [runto_main] then { catch_fork_child_follow }
 
+   # Test that parent breakpoints are successfully detached from the
+   # child at fork time, even if the user removes them from the
+   # breakpoints list after stopping at a fork catchpoint.
+   if [runto_main] then { catch_fork_unpatch_child }
+
    # Test the ability to catch a fork, specify via a -do clause that
    # the parent be followed, and continue.  Make the catchpoint temporary.
    #
This page took 0.028842 seconds and 4 git commands to generate.