]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/fork-running-state.exp
Update copyright year range in all GDB files
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / fork-running-state.exp
1 # Copyright (C) 2016-2018 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
15
16 # Regression test for PR threads/19461 (strange "info thread" behavior
17 # in non-stop). GDB used to miss updating the parent/child running
18 # states after a fork.
19
20 standard_testfile
21
22 # The test proper.
23
24 proc do_test { detach_on_fork follow_fork non_stop schedule_multiple } {
25 global GDBFLAGS
26 global srcfile testfile
27 global gdb_prompt
28
29 save_vars { GDBFLAGS } {
30 append GDBFLAGS " -ex \"set non-stop $non_stop\""
31
32 if {[prepare_for_testing "failed to prepare" \
33 $testfile $srcfile {debug}] == -1} {
34 return -1
35 }
36 }
37
38 if ![runto_main] then {
39 fail "can't run to main"
40 return 0
41 }
42
43 # If debugging with target remote, check whether the all-stop
44 # variant of the RSP is being used. If so, we can't run the
45 # all-stop tests.
46 if { [target_info exists gdb_protocol]
47 && ([target_info gdb_protocol] == "remote"
48 || [target_info gdb_protocol] == "extended-remote")} {
49
50 set test "maint show target-non-stop"
51 gdb_test_multiple "maint show target-non-stop" $test {
52 -re "(is|currently) on.*$gdb_prompt $" {
53 }
54 -re "(is|currently) off.*$gdb_prompt $" {
55 unsupported "can't issue info threads while target is running"
56 return 0
57 }
58 }
59 }
60
61 # We want to catch "[New inferior ...]" below, to avoid sleeping.
62 if {$detach_on_fork == "off" || $follow_fork == "child"} {
63 gdb_test_no_output "set print inferior-events on"
64 }
65
66 gdb_test_no_output "set detach-on-fork $detach_on_fork"
67
68 gdb_test_no_output "set follow-fork $follow_fork"
69 if {$non_stop == "off"} {
70 gdb_test_no_output "set schedule-multiple $schedule_multiple"
71 }
72
73 set test "continue &"
74 gdb_test_multiple $test $test {
75 -re "$gdb_prompt " {
76 pass $test
77 }
78 }
79
80 if {$detach_on_fork == "off" || $follow_fork == "child"} {
81 set test "fork child appears"
82 gdb_test_multiple "" $test {
83 -re "\\\[New inferior " {
84 pass $test
85 }
86 }
87 } else {
88 # All we can do is wait a little bit for the parent to fork.
89 sleep 1
90 }
91
92 set not_nl "\[^\r\n\]*"
93
94 if {$detach_on_fork == "on" && $non_stop == "on" && $follow_fork == "child"} {
95 gdb_test "info threads" \
96 " 2.1 ${not_nl}\\\(running\\\).*No selected thread.*"
97 } elseif {$detach_on_fork == "on" && $follow_fork == "child"} {
98 gdb_test "info threads" \
99 "\\\* 2.1 ${not_nl}\\\(running\\\)"
100 } elseif {$detach_on_fork == "on"} {
101 gdb_test "info threads" \
102 "\\\* 1 ${not_nl}\\\(running\\\)"
103 } elseif {$non_stop == "on"
104 || ($schedule_multiple == "on" && $follow_fork == "parent")} {
105 # Both parent and child should be marked running, and the
106 # parent should be selected.
107 gdb_test "info threads" \
108 [multi_line \
109 "\\\* 1.1 ${not_nl} \\\(running\\\)${not_nl}" \
110 " 2.1 ${not_nl} \\\(running\\\)"]
111 } elseif {$schedule_multiple == "on" && $follow_fork == "child"} {
112 # Both parent and child should be marked running, and the
113 # child should be selected.
114 gdb_test "info threads" \
115 [multi_line \
116 " 1.1 ${not_nl} \\\(running\\\)${not_nl}" \
117 "\\\* 2.1 ${not_nl} \\\(running\\\)"]
118 } else {
119 set test "only $follow_fork marked running"
120 gdb_test_multiple "info threads" $test {
121 -re "\\\(running\\\)${not_nl}\\\(running\\\)\r\n$gdb_prompt $" {
122 fail $test
123 }
124 -re "\\\* 1.1 ${not_nl}\\\(running\\\)\r\n 2.1 ${not_nl}\r\n$gdb_prompt $" {
125 gdb_assert [string eq $follow_fork "parent"] $test
126 }
127 -re "1.1 ${not_nl}\r\n\\\* 2.1 ${not_nl}\\\(running\\\)\r\n$gdb_prompt $" {
128 gdb_assert [string eq $follow_fork "child"] $test
129 }
130 }
131 }
132
133 # We don't want to see "Inferior exited" in reaction to the kills.
134 gdb_test_no_output "set print inferior-events off"
135
136 # Kill both parent and child.
137 if {$detach_on_fork == "off" || $follow_fork == "parent"} {
138 gdb_test_no_output "kill inferior 1" "kill parent"
139 }
140 if {$detach_on_fork == "off" || $follow_fork == "child"} {
141 gdb_test_no_output "kill inferior 2" "kill child"
142 }
143 }
144
145 # Exercise all permutations of:
146 #
147 # set detach-on-fork off|on
148 # set follow-fork parent|child
149 # set non-stop on|off
150 # set schedule-multiple on|off
151
152 foreach_with_prefix detach-on-fork {"off" "on"} {
153 foreach_with_prefix follow-fork {"parent" "child"} {
154 with_test_prefix "non-stop" {
155 do_test ${detach-on-fork} ${follow-fork} "on" "-"
156 }
157 with_test_prefix "all-stop" {
158 foreach_with_prefix schedule-multiple {"on" "off"} {
159 do_test ${detach-on-fork} ${follow-fork} "off" ${schedule-multiple}
160 }
161 }
162 }
163 }