1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2007-2019 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Test that the event messages printed when using 'set print
19 # inferior-events [on,off]', 'set follow-fork-mode [child,parent]' and
20 # 'set detach-on-fork [on,off]' are the correct ones.
22 # This test relies on "run", so it cannot run on target remote stubs.
23 if { [use_gdb_stub] } {
24 untested "not supported on target remote stubs"
30 if { [prepare_for_testing "failed to prepare" $testfile $srcfile debug] } {
34 # This is the expected output for each of the test combinations
35 # below. The order here is important:
37 # inferior-events: on; follow-fork: child; detach-on-fork: on
38 # inferior-events: on; follow-fork: child; detach-on-fork: off
39 # inferior-events: on; follow-fork: parent; detach-on-fork: on
40 # inferior-events: on; follow-fork: parent; detach-on-fork: off
41 # inferior-events: off; follow-fork: child; detach-on-fork: on
42 # inferior-events: off; follow-fork: child; detach-on-fork: off
43 # inferior-events: off; follow-fork: parent; detach-on-fork: on
44 # inferior-events: off; follow-fork: parent; detach-on-fork: off
46 set reading_re "(Reading.*from remote target\\.\\.\\.\r\n)*"
47 set exited_normally_re "${reading_re}\\\[Inferior $decimal \\(.*\\) exited normally\\\]"
48 # gdbserver produces a slightly different message when attaching after
49 # a fork, so we have to tweak the regexp to accomodate that.
50 set attach_child_re "${reading_re}\\\[Attaching after .* fork to child .*\\\]\r\n"
51 set detach_child_re "${reading_re}\\\[Detaching after fork from child .*\\\]\r\n"
52 set detach_parent_re "${reading_re}\\\[Detaching after fork from parent .*\\\]\r\n"
53 set new_inf_re "${reading_re}\\\[New inferior $decimal \\(.*\\)\\\]\r\n"
54 set inf_detached_re "${reading_re}\\\[Inferior $decimal \\(.*\\) detached\\\]\r\n"
56 set expected_output [list \
57 "${attach_child_re}${new_inf_re}${detach_parent_re}${inf_detached_re}" \
58 "${attach_child_re}${new_inf_re}" \
59 "${detach_child_re}" \
69 foreach_with_prefix print_inferior_events { "on" "off" } {
70 foreach_with_prefix follow_fork_mode { "child" "parent" } {
71 foreach_with_prefix detach_on_fork { "on" "off" } {
72 clean_restart $binfile
73 gdb_test_no_output "set print inferior-events $print_inferior_events"
74 gdb_test_no_output "set follow-fork-mode $follow_fork_mode"
75 gdb_test_no_output "set detach-on-fork $detach_on_fork"
77 set output [lindex $expected_output $i]
78 # Always add the "Starting program..." string so that we
79 # match exactly the lines we want.
80 set output "Starting program: $binfile\\s*\r\n${output}${exited_normally_re}"
82 gdb_test "run" $output