gdb: test vfork + follow parent + detach-on-fork off
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 12 Oct 2021 19:05:18 +0000 (15:05 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Thu, 28 Oct 2021 20:33:01 +0000 (16:33 -0400)
The particular behavior we have when using that combination of
settings doesn't seem tested at all (at least, I don't find it if I grep
for "Can not resume the parent process").  At a simple test for that.

Change-Id: Ib9454a615abba661b42f1b15056df73ed1bcd4c5

gdb/testsuite/gdb.base/vfork-follow-parent.c [new file with mode: 0644]
gdb/testsuite/gdb.base/vfork-follow-parent.exp [new file with mode: 0644]

diff --git a/gdb/testsuite/gdb.base/vfork-follow-parent.c b/gdb/testsuite/gdb.base/vfork-follow-parent.c
new file mode 100644 (file)
index 0000000..171b77b
--- /dev/null
@@ -0,0 +1,39 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2020-2021 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 3 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, see <http://www.gnu.org/licenses/>.  */
+
+#include <unistd.h>
+
+static volatile int release_parent = 0;
+
+static void
+break_parent (void)
+{
+}
+
+int
+main (void)
+{
+  if (vfork () != 0)
+    {
+      while (!release_parent);
+      break_parent ();
+    }
+  else
+    _exit (0);
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/vfork-follow-parent.exp b/gdb/testsuite/gdb.base/vfork-follow-parent.exp
new file mode 100644 (file)
index 0000000..d7be02c
--- /dev/null
@@ -0,0 +1,65 @@
+# Copyright 2020-2021 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 3 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, see <http://www.gnu.org/licenses/>.
+
+# This serves as a template for writing new test cases.  Replace this with
+# a description of what this test case tests.
+
+standard_testfile
+
+if { [build_executable "failed to prepare" \
+       ${testfile} ${srcfile}] } {
+    return
+}
+
+proc do_test { method } {
+    clean_restart $::binfile
+
+    gdb_test_no_output "set detach-on-fork off"
+
+    if { ![runto_main] } {
+       return
+    }
+
+    gdb_test "break break_parent"
+
+    gdb_test "continue" \
+       "Can not resume the parent process over vfork .*" \
+       "continue to vfork"
+
+    # Try to continue again from there, expecting the same message.  It takes a
+    # different code path in GDB.
+    gdb_test "continue" \
+       "Can not resume the parent process over vfork .*" \
+       "try to continue from vfork"
+
+    if { $method == "detach-on-fork" } {
+       gdb_test "set detach-on-fork on"
+    } elseif { $method == "schedule-multiple" } {
+       gdb_test "set schedule-multiple on"
+       gdb_test "continue" "$::inferior_exited_re normally.*" \
+           "continue to end of inferior 2"
+       gdb_test "inferior 1" ".*Switching to inferior 1.*"
+    } else {
+       error "invalid method: $method"
+    }
+
+    gdb_test "p release_parent = 1" " = 1"
+    gdb_test "continue" "Breakpoint $::decimal, break_parent .*" \
+       "continue to break_parent"
+}
+
+foreach_with_prefix method {detach-on-fork schedule-multiple} {
+    do_test $method
+}
This page took 0.025757 seconds and 4 git commands to generate.