]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/fork-print-inferior-events.exp
Automatic Copyright Year update after running gdb/copyright.py
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / fork-print-inferior-events.exp
1 # This testcase is part of GDB, the GNU debugger.
2
3 # Copyright 2007-2022 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.
23 if { [use_gdb_stub] } {
24 untested "not supported on target remote stubs"
25 return
26 }
27
28 # Test relies on checking follow-fork output. Do not run if gdb debug is
29 # enabled as it will be redirected to the log.
30 if [gdb_debug_enabled] {
31 untested "debug is enabled"
32 return 0
33 }
34
35 standard_testfile
36
37 if { [build_executable "failed to prepare" $testfile $srcfile debug] } {
38 return -1
39 }
40
41 # This is the expected output for each of the test combinations
42 # below. The order here is important:
43 #
44 # inferior-events: on; follow-fork: child; detach-on-fork: on
45 # inferior-events: on; follow-fork: child; detach-on-fork: off
46 # inferior-events: on; follow-fork: parent; detach-on-fork: on
47 # inferior-events: on; follow-fork: parent; detach-on-fork: off
48 # inferior-events: off; follow-fork: child; detach-on-fork: on
49 # inferior-events: off; follow-fork: child; detach-on-fork: off
50 # inferior-events: off; follow-fork: parent; detach-on-fork: on
51 # inferior-events: off; follow-fork: parent; detach-on-fork: off
52
53 set reading_re "(Reading.*from remote target\\.\\.\\.\r\n)*"
54 set exited_normally_re "${reading_re}\\\[Inferior $decimal \\(.*\\) exited normally\\\]"
55 # gdbserver produces a slightly different message when attaching after
56 # a fork, so we have to tweak the regexp to accomodate that.
57 set attach_child_re "${reading_re}\\\[Attaching after .* fork to child .*\\\]\r\n"
58 set detach_child_re "${reading_re}\\\[Detaching after fork from child .*\\\]\r\n"
59 set detach_parent_re "${reading_re}\\\[Detaching after fork from parent .*\\\]\r\n"
60 set new_inf_re "${reading_re}\\\[New inferior $decimal \\(.*\\)\\\]\r\n"
61 set inf_detached_re "${reading_re}\\\[Inferior $decimal \\(.*\\) detached\\\]\r\n"
62 set thread_db_re "(?:\\\[Thread debugging using .*? enabled\\\]\r\nUsing .*? library .*?\\.\r\n)?"
63
64 set expected_output [list \
65 "${attach_child_re}${new_inf_re}${detach_parent_re}${inf_detached_re}" \
66 "${attach_child_re}${new_inf_re}" \
67 "${detach_child_re}" \
68 "${new_inf_re}" \
69 "" \
70 "" \
71 "" \
72 "" \
73 ]
74
75 set i 0
76
77 foreach_with_prefix print_inferior_events { "on" "off" } {
78 foreach_with_prefix follow_fork_mode { "child" "parent" } {
79 foreach_with_prefix detach_on_fork { "on" "off" } {
80 clean_restart $binfile
81 gdb_test_no_output "set print inferior-events $print_inferior_events"
82 gdb_test_no_output "set follow-fork-mode $follow_fork_mode"
83 gdb_test_no_output "set detach-on-fork $detach_on_fork"
84
85 set output [lindex $expected_output $i]
86 # Always add the "Starting program..." string so that we
87 # match exactly the lines we want.
88 set output "Starting program: $binfile\\s*\r\n${thread_db_re}${output}${thread_db_re}${exited_normally_re}"
89 set i [expr $i + 1]
90 gdb_test "run" $output
91 }
92 }
93 }