1# This testcase is part of GDB, the GNU debugger. 2 3# Copyright 2007-2019 Free Software Foundation, Inc. 4 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. 9# 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. 14# 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/>. 17 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. 21 22# This test relies on "run", so it cannot run on target remote stubs. 23if { [use_gdb_stub] } { 24 untested "not supported on target remote stubs" 25 return 26} 27 28standard_testfile 29 30if { [prepare_for_testing "failed to prepare" $testfile $srcfile debug] } { 31 return -1 32} 33 34# This is the expected output for each of the test combinations 35# below. The order here is important: 36# 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 45 46set reading_re "(Reading.*from remote target\\.\\.\\.\r\n)*" 47set 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. 50set attach_child_re "${reading_re}\\\[Attaching after .* fork to child .*\\\]\r\n" 51set detach_child_re "${reading_re}\\\[Detaching after fork from child .*\\\]\r\n" 52set detach_parent_re "${reading_re}\\\[Detaching after fork from parent .*\\\]\r\n" 53set new_inf_re "${reading_re}\\\[New inferior $decimal \\(.*\\)\\\]\r\n" 54set inf_detached_re "${reading_re}\\\[Inferior $decimal \\(.*\\) detached\\\]\r\n" 55 56set 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}" \ 60 "${new_inf_re}" \ 61 "" \ 62 "" \ 63 "" \ 64 "" \ 65 ] 66 67set i 0 68 69foreach_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" 76 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}" 81 set i [expr $i + 1] 82 gdb_test "run" $output 83 } 84 } 85} 86