Commit | Line | Data |
---|---|---|
a25a5a45 PA |
1 | # Copyright (C) 2014 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 | # Test that: | |
17 | # | |
18 | # - setting a breakpoint while a thread is running results in the | |
19 | # breakpoint being inserted immediately. | |
20 | # | |
21 | # - if breakpoint always-inserted mode is off, GDB doesn't remove | |
22 | # breakpoints from the target when a thread stops, if there are | |
23 | # still threads running. | |
24 | ||
25 | standard_testfile | |
26 | ||
27 | if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug pthreads}] == -1} { | |
28 | return -1 | |
29 | } | |
30 | ||
31 | # The test proper. NON_STOP indicates whether we're testing in | |
32 | # non-stop, or all-stop mode. ALWAYS_INSERTED indicates whether | |
33 | # testing in "breakpoint always-inserted" mode. | |
34 | ||
35 | proc test { always_inserted non_stop } { | |
36 | global srcfile binfile | |
37 | global gdb_prompt | |
38 | global decimal | |
39 | ||
40 | clean_restart $binfile | |
41 | ||
42 | gdb_test_no_output "set non-stop $non_stop" | |
43 | gdb_test_no_output "set breakpoint always-inserted $always_inserted" | |
44 | ||
45 | if ![runto_main] { | |
46 | return -1 | |
47 | } | |
48 | ||
49 | # In all-stop, check whether we're testing with the remote or | |
50 | # extended-remote targets. If so, skip the tests, as with the | |
51 | # RSP, we can't issue commands until the target replies to vCont. | |
52 | # Not an issue with the non-stop RSP variant, which has a | |
53 | # non-blocking vCont. | |
54 | if {$non_stop=="off" && [gdb_is_target_remote]} { | |
55 | return -1 | |
56 | } | |
57 | ||
58 | gdb_breakpoint [gdb_get_line_number "set wait-thread breakpoint here"] | |
59 | gdb_continue_to_breakpoint "run to wait-thread breakpoint" | |
60 | ||
61 | delete_breakpoints | |
62 | ||
63 | # Leave the main thread stopped, so GDB can poke at memory freely. | |
64 | if {$non_stop == "off"} { | |
65 | gdb_test_no_output "set scheduler-locking on" | |
66 | gdb_test "thread 2" "Switching to .*" | |
67 | gdb_test "continue &" "Continuing\." "continuing thread 2" | |
68 | gdb_test "thread 3" "Switching to .*" | |
69 | gdb_test "continue &" "Continuing\." "continuing thread 3" | |
70 | gdb_test "thread 1" "Switching to .*" "switch back to main thread" | |
71 | } | |
72 | ||
73 | gdb_test "info threads" \ | |
74 | "\\\(running\\\).*\\\(running\\\).* main .*" \ | |
75 | "only main stopped" | |
76 | ||
77 | # Don't use gdb_test as it's racy in this case -- gdb_test matches | |
78 | # the prompt with an end anchor. Sometimes expect will manage to | |
79 | # read the breakpoint hit output while still processing this test, | |
80 | # defeating the anchor. | |
81 | set test "set breakpoint while a thread is running" | |
82 | gdb_test_multiple "break breakpoint_function" $test { | |
83 | -re "Breakpoint $decimal at .*: file .*$srcfile.*\r\n$gdb_prompt " { | |
84 | pass $test | |
85 | } | |
86 | -re "$gdb_prompt " { | |
87 | fail $test | |
88 | } | |
89 | } | |
90 | ||
91 | # Check that the breakpoint is hit. Can't use gdb_test here, as | |
92 | # no prompt is expected to come out. | |
93 | set test "breakpoint is hit" | |
94 | gdb_test_multiple "" $test { | |
95 | -re "Breakpoint .*, breakpoint_function \[^\r\n\]+" { | |
96 | pass $test | |
97 | } | |
98 | } | |
99 | ||
100 | if {$non_stop == "on"} { | |
101 | gdb_test "info threads" \ | |
102 | "\\\(running\\\).* breakpoint_function .* main .*" \ | |
103 | "one thread running" | |
104 | ||
105 | # Unblock the other thread, which should then trip on the same | |
106 | # breakpoint, unless GDB removed it by mistake. Can't use | |
107 | # gdb_test here for the same reasons as above. | |
108 | set test "unblock second thread" | |
109 | gdb_test_multiple "print second_child = 1" $test { | |
110 | -re " = 1\r\n$gdb_prompt " { | |
111 | pass $test | |
112 | } | |
113 | -re "$gdb_prompt " { | |
114 | fail $test | |
115 | } | |
116 | } | |
117 | ||
118 | set test "breakpoint on second child is hit" | |
119 | gdb_test_multiple "" $test { | |
120 | -re "Breakpoint .*, breakpoint_function \[^\r\n\]+" { | |
121 | pass $test | |
122 | } | |
123 | } | |
124 | ||
125 | gdb_test "info threads" \ | |
126 | " breakpoint_function .* breakpoint_function .* main .*" \ | |
127 | "all threads stopped" | |
128 | } else { | |
129 | # This test is not merged with the non-stop one because in | |
130 | # all-stop we don't know where the other thread stops (inside | |
131 | # usleep, for example). | |
132 | set test "all threads stopped" | |
133 | gdb_test_multiple "info threads" "$test" { | |
134 | -re "\\\(running\\\).*$gdb_prompt $" { | |
135 | fail $test | |
136 | } | |
137 | -re "breakpoint_function .* main .*$gdb_prompt $" { | |
138 | pass $test | |
139 | } | |
140 | } | |
141 | } | |
142 | } | |
143 | ||
144 | foreach always_inserted { "off" "on" } { | |
145 | foreach non_stop { "off" "on" } { | |
146 | set stop_mode [expr ($non_stop=="off")?"all-stop":"non-stop"] | |
147 | with_test_prefix "always-inserted $always_inserted: $stop_mode" { | |
148 | test $always_inserted $non_stop | |
149 | } | |
150 | } | |
151 | } |