Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright (C) 2016-2020 Free Software Foundation, Inc. |
a2077e25 PA |
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 { | |
bc6c7af4 | 39 | fail "can't run to main" |
a2077e25 PA |
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 | ||
14897d65 PA |
73 | # If we're detaching from the parent (or child), then tell it to |
74 | # exit itself when its child (or parent) exits. If we stay | |
75 | # attached, we take care of killing it. | |
76 | if {$detach_on_fork == "on"} { | |
77 | gdb_test "print exit_if_relative_exits = 1" " = 1" | |
78 | } | |
79 | ||
a2077e25 PA |
80 | set test "continue &" |
81 | gdb_test_multiple $test $test { | |
82 | -re "$gdb_prompt " { | |
83 | pass $test | |
84 | } | |
85 | } | |
86 | ||
87 | if {$detach_on_fork == "off" || $follow_fork == "child"} { | |
88 | set test "fork child appears" | |
89 | gdb_test_multiple "" $test { | |
90 | -re "\\\[New inferior " { | |
91 | pass $test | |
92 | } | |
93 | } | |
94 | } else { | |
95 | # All we can do is wait a little bit for the parent to fork. | |
96 | sleep 1 | |
97 | } | |
98 | ||
99 | set not_nl "\[^\r\n\]*" | |
100 | ||
873657b9 | 101 | if {$detach_on_fork == "on" && $follow_fork == "child"} { |
a2077e25 PA |
102 | gdb_test "info threads" \ |
103 | " 2.1 ${not_nl}\\\(running\\\).*No selected thread.*" | |
a2077e25 PA |
104 | } elseif {$detach_on_fork == "on"} { |
105 | gdb_test "info threads" \ | |
106 | "\\\* 1 ${not_nl}\\\(running\\\)" | |
873657b9 | 107 | } elseif {$non_stop == "on" || $schedule_multiple == "on"} { |
a2077e25 PA |
108 | # Both parent and child should be marked running, and the |
109 | # parent should be selected. | |
110 | gdb_test "info threads" \ | |
111 | [multi_line \ | |
112 | "\\\* 1.1 ${not_nl} \\\(running\\\)${not_nl}" \ | |
113 | " 2.1 ${not_nl} \\\(running\\\)"] | |
a2077e25 PA |
114 | } else { |
115 | set test "only $follow_fork marked running" | |
116 | gdb_test_multiple "info threads" $test { | |
117 | -re "\\\(running\\\)${not_nl}\\\(running\\\)\r\n$gdb_prompt $" { | |
118 | fail $test | |
119 | } | |
120 | -re "\\\* 1.1 ${not_nl}\\\(running\\\)\r\n 2.1 ${not_nl}\r\n$gdb_prompt $" { | |
121 | gdb_assert [string eq $follow_fork "parent"] $test | |
122 | } | |
873657b9 | 123 | -re "\\\* 1.1 ${not_nl}\r\n 2.1 ${not_nl}\\\(running\\\)\r\n$gdb_prompt $" { |
a2077e25 PA |
124 | gdb_assert [string eq $follow_fork "child"] $test |
125 | } | |
126 | } | |
127 | } | |
128 | ||
129 | # We don't want to see "Inferior exited" in reaction to the kills. | |
130 | gdb_test_no_output "set print inferior-events off" | |
131 | ||
132 | # Kill both parent and child. | |
133 | if {$detach_on_fork == "off" || $follow_fork == "parent"} { | |
134 | gdb_test_no_output "kill inferior 1" "kill parent" | |
135 | } | |
136 | if {$detach_on_fork == "off" || $follow_fork == "child"} { | |
137 | gdb_test_no_output "kill inferior 2" "kill child" | |
138 | } | |
139 | } | |
140 | ||
141 | # Exercise all permutations of: | |
142 | # | |
143 | # set detach-on-fork off|on | |
144 | # set follow-fork parent|child | |
145 | # set non-stop on|off | |
146 | # set schedule-multiple on|off | |
147 | ||
148 | foreach_with_prefix detach-on-fork {"off" "on"} { | |
149 | foreach_with_prefix follow-fork {"parent" "child"} { | |
150 | with_test_prefix "non-stop" { | |
151 | do_test ${detach-on-fork} ${follow-fork} "on" "-" | |
152 | } | |
153 | with_test_prefix "all-stop" { | |
154 | foreach_with_prefix schedule-multiple {"on" "off"} { | |
155 | do_test ${detach-on-fork} ${follow-fork} "off" ${schedule-multiple} | |
156 | } | |
157 | } | |
158 | } | |
159 | } |