]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/bp-permanent.exp
fix skipping permanent breakpoints
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / bp-permanent.exp
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 # This file is part of the gdb testsuite.
17
18 # Test stepping over permanent breakpoints.
19
20 standard_testfile
21
22 set options { debug }
23 if { ![target_info exists gdb,nosignals] } {
24 lappend options "additional_flags=-DSIGNALS"
25 }
26
27 if {[build_executable "failed to prepare" $testfile $srcfile $options]} {
28 return -1
29 }
30
31 set line_bp [gdb_get_line_number "write permanent bp"]
32
33 # The test proper. ALWAYS_INSERTED indicates whether testing in
34 # "breakpoint always-inserted" mode. If SW_WATCHPOINT is true, set a
35 # software watchpoint, which forces constantly single-stepping, and
36 # exercises stepping the permanent breakpoint while delivering a
37 # signal at the same time.
38
39 proc test {always_inserted sw_watchpoint} {
40 global line_bp
41 global hex decimal
42 global gdb_prompt
43 global srcfile binfile
44
45 clean_restart $binfile
46
47 if ![runto_main] then {
48 return -1
49 }
50
51 gdb_test "set breakpoint always-inserted $always_inserted"
52
53 if {$sw_watchpoint} {
54 # Watching a convenience variable forces a software
55 # watchpoint.
56 gdb_test "watch \$dummy_convenience" "Watchpoint .*"
57 }
58
59 set address_bp ""
60 set address_after_bp ""
61
62 with_test_prefix "setup" {
63
64 # Set a breakpoint where we'll manually plant a permanent
65 # breakpoint.
66 set test "set probe breakpoint"
67 gdb_test_multiple "break $line_bp" $test {
68 -re "Breakpoint .* at ($hex).*$gdb_prompt $" {
69 set address_bp $expect_out(1,string)
70 pass $test
71 }
72 }
73 if {$address_bp == ""} {
74 return
75 }
76
77 # Get the size of the instruction where the breakpoint will
78 # manually inserted.
79 set test "get size of instruction"
80 gdb_test_multiple "x/2i $address_bp" $test {
81 -re ".*$hex <test\\+$decimal>:\[^\r\n\]+\r\n\[ \]+($hex).*\.\r\n$gdb_prompt $" {
82 set address_after_bp $expect_out(1,string)
83 pass $test
84 }
85 }
86 if {$address_after_bp == ""} {
87 return
88 }
89
90 # Write address range where the breakpoint is inserted to the
91 # corresponding variables in the inferior.
92 gdb_test "p /x addr_bp = $address_bp" " = $address_bp" \
93 "write addr_bp"
94 gdb_test "p /x addr_after_bp = $address_after_bp" " = $address_after_bp" \
95 "write addr_after_bp"
96
97 # Run the "setup" function in the inferior. This memcpy's the
98 # breakpoint instruction to a buffer in the inferior.
99 gdb_test "next" "test.*" "next over setup"
100
101 delete_breakpoints
102
103 # We now have the breakpoint instruction stored in 'buffer'. Poke it
104 # to memory manually.
105 set count [expr $address_after_bp - $address_bp]
106 for {set i 0} {$i < $count} {incr i} {
107 gdb_test "p /x addr_bp\[$i\] = buffer\[$i\]" " = .*"
108 }
109 }
110
111 with_test_prefix "basics" {
112 # Run to the permanent breakpoint, just to make sure we've inserted it
113 # correctly.
114 gdb_test "continue" "Program received signal SIGTRAP.*" \
115 "permanent breakpoint causes random signal"
116
117 # Now set a breakpoint on top, thus creating a permanent breakpoint.
118 gdb_breakpoint "$line_bp"
119
120 # Depending on whether this is a decr_pc_after_break arch, the PC will
121 # be either pointing at the permanent breakpoint address, or just
122 # after. Set the GDB breakpoint on top, and continue, twice. At
123 # least once, GDB will need to step-over the permanent breakpoint.
124
125 gdb_test "continue" "Breakpoint .*" "stop at permanent breakpoint"
126
127 gdb_test "p \$prev_counter = counter" " = $decimal"
128
129 gdb_test "continue" "Breakpoint .*" "stop at permanent breakpoint twice"
130
131 # Check that indeed the continue made progress, instead of re-trapping
132 # without advancing.
133 gdb_test "p counter - \$prev_counter" " = 1"
134
135 gdb_test "info breakpoints" \
136 "breakpoint.*keep.*y.*$hex.*in test at .*$srcfile:$line_bp.*already hit 2 times.*" \
137 "info breakpoints show enabled breakpoint"
138
139 gdb_test "disable \$bpnum"
140
141 gdb_test "commands\nset \$commands_ran = 1\nend" "" \
142 "set breakpoint commands"
143
144 gdb_test "info breakpoints" \
145 "breakpoint.*keep.*n.*$hex.*in test at .*$srcfile:$line_bp.*already hit 2 times.*" \
146 "info breakpoints shows disabled breakpoint"
147
148 # Run to the permanent breakpoint again. This time, since it's
149 # disabled, it should act as if we hadn't created it in the first
150 # place. IOW, we should get a random signal, and, the breakpoint's
151 # command should not run.
152 gdb_test "continue" "Program received signal SIGTRAP.*" \
153 "disabled permanent breakpoint doesn't explain stop"
154
155 gdb_test "info breakpoints" \
156 "breakpoint.*keep.*n.*$hex.*in test at .*$srcfile:$line_bp.*already hit 2 times.*" \
157 "info breakpoints still shows same number of hits"
158
159 gdb_test "print \$commands_ran" " = void" \
160 "breakpoint commands didn't run"
161
162 # Reenable the breakpoint, and check that it gets hit and accounted
163 # for this time.
164 gdb_test "enable \$bpnum" "" "reenable breakpoint"
165
166 gdb_test "continue" "Breakpoint .*" \
167 "stop at permanent breakpoint thrice"
168
169 gdb_test "info breakpoints" \
170 "breakpoint.*keep.*y.*$hex.*in test at .*$srcfile:$line_bp.*already hit 3 times.*" \
171 "info breakpoints shows one more hit"
172
173 gdb_test "print \$commands_ran" " = 1" "breakpoint commands ran"
174
175 # Check that stepi advances only past the permanent breakpoint, and
176 # not a single instruction more.
177 gdb_test "stepi" "after permanent bp .*" \
178 "single-step past permanent breakpoint"
179 }
180
181 with_test_prefix "next trips on permanent bp" {
182 delete_breakpoints
183
184 gdb_breakpoint "test_next"
185 gdb_continue_to_breakpoint "test_next"
186
187 gdb_breakpoint "$line_bp"
188 gdb_test "condition \$bpnum 0"
189
190 gdb_test "next" "after next .*"
191 }
192
193 if ![target_info exists gdb,nosignals] {
194
195 with_test_prefix "continue trips on nested permanent bp" {
196 delete_breakpoints
197
198 gdb_breakpoint "test_signal_nested"
199 gdb_continue_to_breakpoint "test_signal_nested"
200
201 gdb_breakpoint "$line_bp"
202 gdb_continue_to_breakpoint "permanent bp"
203 gdb_test "condition \$bpnum 0"
204
205 # Let SIGALRM trigger.
206 sleep 2
207
208 # We're now stopped at a permanent breakpoint, with a
209 # signal pending.
210 gdb_breakpoint "test_signal_nested_done"
211 gdb_continue_to_breakpoint "test_signal_nested_done"
212
213 # Ensure that the handler did run. There's one call to
214 # test in the mainline code, and another in the signal
215 # handler.
216 gdb_test "p counter" " = 2"
217 }
218
219 if [can_single_step_to_signal_handler] {
220
221 with_test_prefix "stepi signal with handler" {
222 delete_breakpoints
223
224 gdb_breakpoint "test_signal_with_handler"
225 gdb_continue_to_breakpoint "test_signal_with_handler"
226
227 gdb_breakpoint "$line_bp"
228
229 gdb_test "continue" "Breakpoint .*" "stop at permanent breakpoint"
230
231 gdb_test "queue-signal SIGUSR1"
232
233 set test "single-step to handler"
234 gdb_test_multiple "stepi" $test {
235 -re "Program received signal SIGTRAP.*$gdb_prompt $" {
236 fail $test
237 }
238 -re "handler .*$gdb_prompt $" {
239 pass $test
240 }
241 }
242
243 # Check that the mainline PC points at the permanent
244 # breakpoint.
245 gdb_test "up 2" "test .*" "up to mainline code"
246
247 gdb_test "p /x \$pc" " = $address_bp" \
248 "mainline pc points at permanent breakpoint"
249
250 gdb_test "continue" "Breakpoint .*" \
251 "stop at permanent breakpoint, out of handler"
252 }
253
254 with_test_prefix "stepi signal with no handler" {
255 gdb_breakpoint "test_signal_no_handler"
256 gdb_continue_to_breakpoint "test_signal_no_handler"
257
258 gdb_test "continue" "Breakpoint .*" "stop at permanent breakpoint"
259
260 gdb_test "queue-signal SIGUSR1"
261
262 gdb_test "stepi" "after permanent bp .*" \
263 "single-step past permanent breakpoint"
264 }
265 }
266 }
267 }
268
269 foreach always_inserted {off on} {
270 foreach sw_watchpoint {0 1} {
271 with_test_prefix "always_inserted=$always_inserted, sw_watchpoint=$sw_watchpoint" {
272 test $always_inserted $sw_watchpoint
273 }
274 }
275 }