1 # Copyright 2021-2023 Free Software Foundation, Inc.
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 3 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Test running into vfork while "detach-on-fork" is off and "follow-fork-mode"
17 # is parent. This shows a "Can not resume the parent process..." message. If
18 # the user wants to resume execution, they have to use either "set
19 # schedule-multiple on" or "set detach-on-fork on". Test these two resolution
24 if { [build_executable "failed to prepare" \
25 ${testfile} ${srcfile}] } {
29 # Test running to the "Can not resume the parent..." message. Then, resolve
30 # the situation using the method in RESOLUTION_METHOD, either "detach-on-fork"
31 # or "schedule-multiple" (the two alternatives the message suggests to the
34 proc do_test { resolution_method } {
35 clean_restart $::binfile
37 gdb_test_no_output "set detach-on-fork off"
39 if { ![runto_main] } {
43 gdb_test "break break_parent"
46 "Can not resume the parent process over vfork .*" \
49 # Try to continue again from there, expecting the same message. It
50 # exercises a different code path in GDB.
52 "Can not resume the parent process over vfork .*" \
53 "try to continue from vfork"
55 # Unblock the execution using the specified resolution method.
56 if { $resolution_method == "detach-on-fork" } {
57 # Make GDB detach the child.
58 gdb_test "set detach-on-fork on"
59 gdb_test "print unblock_parent = 1" " = 1"
60 } elseif { $resolution_method == "schedule-multiple" } {
61 # Make GDB resume both inferiors. The parent is blocked while the
62 # children executes, so the continue will make the child reach the
64 gdb_test "set schedule-multiple on"
65 gdb_test "continue" "$::inferior_exited_re normally.*" \
66 "continue to end of inferior 2"
67 gdb_test "inferior 1" ".*Switching to inferior 1.*"
68 gdb_test "print unblock_parent = 1" " = 1"
70 error "invalid resolution method: $resolution_method"
73 # Continue from the vfork call to the breakpoint.
74 gdb_test "continue" "Breakpoint $::decimal, break_parent .*" \
75 "continue to break_parent"
78 foreach_with_prefix resolution_method {detach-on-fork schedule-multiple} {
79 do_test $resolution_method