]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright (C) 2016-2024 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 | ||
65a33d75 | 38 | if {![runto_main]} { |
a2077e25 PA |
39 | return 0 |
40 | } | |
41 | ||
42 | # If debugging with target remote, check whether the all-stop | |
43 | # variant of the RSP is being used. If so, we can't run the | |
44 | # all-stop tests. | |
45 | if { [target_info exists gdb_protocol] | |
46 | && ([target_info gdb_protocol] == "remote" | |
47 | || [target_info gdb_protocol] == "extended-remote")} { | |
48 | ||
47171eeb AB |
49 | if {![is_target_non_stop]} { |
50 | unsupported "can't issue info threads while target is running" | |
51 | return 0 | |
a2077e25 PA |
52 | } |
53 | } | |
54 | ||
55 | # We want to catch "[New inferior ...]" below, to avoid sleeping. | |
56 | if {$detach_on_fork == "off" || $follow_fork == "child"} { | |
57 | gdb_test_no_output "set print inferior-events on" | |
58 | } | |
59 | ||
60 | gdb_test_no_output "set detach-on-fork $detach_on_fork" | |
61 | ||
62 | gdb_test_no_output "set follow-fork $follow_fork" | |
63 | if {$non_stop == "off"} { | |
64 | gdb_test_no_output "set schedule-multiple $schedule_multiple" | |
65 | } | |
66 | ||
14897d65 PA |
67 | # If we're detaching from the parent (or child), then tell it to |
68 | # exit itself when its child (or parent) exits. If we stay | |
69 | # attached, we take care of killing it. | |
70 | if {$detach_on_fork == "on"} { | |
71 | gdb_test "print exit_if_relative_exits = 1" " = 1" | |
72 | } | |
73 | ||
a2077e25 PA |
74 | set test "continue &" |
75 | gdb_test_multiple $test $test { | |
76 | -re "$gdb_prompt " { | |
77 | pass $test | |
78 | } | |
79 | } | |
80 | ||
81 | if {$detach_on_fork == "off" || $follow_fork == "child"} { | |
82 | set test "fork child appears" | |
83 | gdb_test_multiple "" $test { | |
84 | -re "\\\[New inferior " { | |
85 | pass $test | |
86 | } | |
87 | } | |
88 | } else { | |
89 | # All we can do is wait a little bit for the parent to fork. | |
90 | sleep 1 | |
91 | } | |
92 | ||
93 | set not_nl "\[^\r\n\]*" | |
94 | ||
873657b9 | 95 | if {$detach_on_fork == "on" && $follow_fork == "child"} { |
a2077e25 PA |
96 | gdb_test "info threads" \ |
97 | " 2.1 ${not_nl}\\\(running\\\).*No selected thread.*" | |
a2077e25 PA |
98 | } elseif {$detach_on_fork == "on"} { |
99 | gdb_test "info threads" \ | |
100 | "\\\* 1 ${not_nl}\\\(running\\\)" | |
873657b9 | 101 | } elseif {$non_stop == "on" || $schedule_multiple == "on"} { |
a2077e25 PA |
102 | # Both parent and child should be marked running, and the |
103 | # parent should be selected. | |
104 | gdb_test "info threads" \ | |
105 | [multi_line \ | |
106 | "\\\* 1.1 ${not_nl} \\\(running\\\)${not_nl}" \ | |
107 | " 2.1 ${not_nl} \\\(running\\\)"] | |
a2077e25 PA |
108 | } else { |
109 | set test "only $follow_fork marked running" | |
110 | gdb_test_multiple "info threads" $test { | |
111 | -re "\\\(running\\\)${not_nl}\\\(running\\\)\r\n$gdb_prompt $" { | |
112 | fail $test | |
113 | } | |
114 | -re "\\\* 1.1 ${not_nl}\\\(running\\\)\r\n 2.1 ${not_nl}\r\n$gdb_prompt $" { | |
115 | gdb_assert [string eq $follow_fork "parent"] $test | |
116 | } | |
873657b9 | 117 | -re "\\\* 1.1 ${not_nl}\r\n 2.1 ${not_nl}\\\(running\\\)\r\n$gdb_prompt $" { |
a2077e25 PA |
118 | gdb_assert [string eq $follow_fork "child"] $test |
119 | } | |
120 | } | |
121 | } | |
122 | ||
123 | # We don't want to see "Inferior exited" in reaction to the kills. | |
124 | gdb_test_no_output "set print inferior-events off" | |
125 | ||
126 | # Kill both parent and child. | |
127 | if {$detach_on_fork == "off" || $follow_fork == "parent"} { | |
128 | gdb_test_no_output "kill inferior 1" "kill parent" | |
129 | } | |
130 | if {$detach_on_fork == "off" || $follow_fork == "child"} { | |
131 | gdb_test_no_output "kill inferior 2" "kill child" | |
132 | } | |
133 | } | |
134 | ||
135 | # Exercise all permutations of: | |
136 | # | |
137 | # set detach-on-fork off|on | |
138 | # set follow-fork parent|child | |
139 | # set non-stop on|off | |
140 | # set schedule-multiple on|off | |
141 | ||
142 | foreach_with_prefix detach-on-fork {"off" "on"} { | |
143 | foreach_with_prefix follow-fork {"parent" "child"} { | |
144 | with_test_prefix "non-stop" { | |
145 | do_test ${detach-on-fork} ${follow-fork} "on" "-" | |
146 | } | |
147 | with_test_prefix "all-stop" { | |
148 | foreach_with_prefix schedule-multiple {"on" "off"} { | |
149 | do_test ${detach-on-fork} ${follow-fork} "off" ${schedule-multiple} | |
150 | } | |
151 | } | |
152 | } | |
153 | } |