* [PATCH] gdb: test vfork + follow-fork-mode=parent + detach-on-fork=off
@ 2022-01-10 17:50 Simon Marchi
2022-03-31 11:47 ` Pedro Alves
0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2022-01-10 17:50 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
From: Simon Marchi <simon.marchi@efficios.com>
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"). Add a simple test for that.
Change-Id: Ib9454a615abba661b42f1b15056df73ed1bcd4c5
---
gdb/testsuite/gdb.base/vfork-follow-parent.c | 36 +++++++++
.../gdb.base/vfork-follow-parent.exp | 78 +++++++++++++++++++
2 files changed, 114 insertions(+)
create mode 100644 gdb/testsuite/gdb.base/vfork-follow-parent.c
create mode 100644 gdb/testsuite/gdb.base/vfork-follow-parent.exp
diff --git a/gdb/testsuite/gdb.base/vfork-follow-parent.c b/gdb/testsuite/gdb.base/vfork-follow-parent.c
new file mode 100644
index 000000000000..783ebe6494da
--- /dev/null
+++ b/gdb/testsuite/gdb.base/vfork-follow-parent.c
@@ -0,0 +1,36 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 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 void
+break_parent (void)
+{
+}
+
+int
+main (void)
+{
+ if (vfork () != 0)
+ {
+ 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
index 000000000000..0432a08e3449
--- /dev/null
+++ b/gdb/testsuite/gdb.base/vfork-follow-parent.exp
@@ -0,0 +1,78 @@
+# Copyright 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/>.
+
+# Test running into vfork while "detach-on-fork" is off and "follow-fork-mode"
+# is parent. This shows a "Can not resume the parent process..." message. If
+# the user wants to resume execution, they have to use either "set
+# schedule-multiple on" or "set detach-on-fork on". Test these two resolution
+# methods.
+
+standard_testfile
+
+if { [build_executable "failed to prepare" \
+ ${testfile} ${srcfile}] } {
+ return
+}
+
+# Test running to the "Can not resume the parent..." message. Then, resolve
+# the situation using the method in RESOLUTION_METHOD, either "detach-on-fork"
+# or "schedule-multiple" (the two alternatives the message suggests to the
+# user).
+
+proc do_test { resolution_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
+ # exercises a different code path in GDB.
+ gdb_test "continue" \
+ "Can not resume the parent process over vfork .*" \
+ "try to continue from vfork"
+
+ # Unblock the execution using the specified resolution method.
+ if { $resolution_method == "detach-on-fork" } {
+ # Make GDB detach the child.
+ gdb_test "set detach-on-fork on"
+ } elseif { $resolution_method == "schedule-multiple" } {
+ # Make GDB resume both inferiors. The parent is blocked while the
+ # children executes, so the continue will make the child reach the
+ # end.
+ 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 resolution method: $resolution_method"
+ }
+
+ # Continue from the vfork call to the breakpoint.
+ gdb_test "continue" "Breakpoint $::decimal, break_parent .*" \
+ "continue to break_parent"
+}
+
+foreach_with_prefix resolution_method {detach-on-fork schedule-multiple} {
+ do_test $resolution_method
+}
base-commit: 3c5038247c8a5fcff18fd81249b0801a95569939
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] gdb: test vfork + follow-fork-mode=parent + detach-on-fork=off
2022-01-10 17:50 [PATCH] gdb: test vfork + follow-fork-mode=parent + detach-on-fork=off Simon Marchi
@ 2022-03-31 11:47 ` Pedro Alves
2022-03-31 15:14 ` Simon Marchi
0 siblings, 1 reply; 3+ messages in thread
From: Pedro Alves @ 2022-03-31 11:47 UTC (permalink / raw)
To: Simon Marchi, gdb-patches; +Cc: Simon Marchi
On 2022-01-10 17:50, Simon Marchi via Gdb-patches wrote:
> From: Simon Marchi <simon.marchi@efficios.com>
>
> 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"). Add a simple test for that.
Huh, wow, guilty as charged.
LGTM.
Remember to update copyright years.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] gdb: test vfork + follow-fork-mode=parent + detach-on-fork=off
2022-03-31 11:47 ` Pedro Alves
@ 2022-03-31 15:14 ` Simon Marchi
0 siblings, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2022-03-31 15:14 UTC (permalink / raw)
To: Pedro Alves, gdb-patches; +Cc: Simon Marchi
On 2022-03-31 07:47, Pedro Alves wrote:
> On 2022-01-10 17:50, Simon Marchi via Gdb-patches wrote:
>> From: Simon Marchi <simon.marchi@efficios.com>
>>
>> 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"). Add a simple test for that.
>
> Huh, wow, guilty as charged.
>
> LGTM.
>
> Remember to update copyright years.
Done, thanks!
Simon
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-03-31 15:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-10 17:50 [PATCH] gdb: test vfork + follow-fork-mode=parent + detach-on-fork=off Simon Marchi
2022-03-31 11:47 ` Pedro Alves
2022-03-31 15:14 ` Simon Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).