Add gdb.Type.optimized_out method.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / bp-permanent.exp
1 # Copyright (C) 2014-2015 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_basics \\(\\).*" "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 set test "p /x addr_bp\[$i\] = buffer\[$i\]"
108 gdb_test_multiple $test $test {
109 -re "Cannot access memory at address $hex.*$gdb_prompt $" {
110 # Some targets (QEMU for one) will disallow writes to the
111 # .text section under certain circumstances. It is no use
112 # continuing with the test at this point. Just return.
113 unsupported "Cannot modify memory"
114 return
115 }
116 -re " = .*$gdb_prompt $" {
117 pass $test
118 }
119 }
120 }
121 }
122
123 with_test_prefix "basics" {
124 # Run to the permanent breakpoint, just to make sure we've inserted it
125 # correctly.
126 gdb_test "continue" "Program received signal SIGTRAP.*" \
127 "permanent breakpoint causes random signal"
128
129 # Now set a breakpoint on top, thus creating a permanent breakpoint.
130 gdb_breakpoint "$line_bp"
131
132 # Depending on whether this is a decr_pc_after_break arch, the PC will
133 # be either pointing at the permanent breakpoint address, or just
134 # after. Set the GDB breakpoint on top, and continue, twice. At
135 # least once, GDB will need to step-over the permanent breakpoint.
136
137 gdb_test "continue" "Breakpoint .*" "stop at permanent breakpoint"
138
139 gdb_test "p \$prev_counter = counter" " = $decimal"
140
141 gdb_test "continue" "Breakpoint .*" "stop at permanent breakpoint twice"
142
143 # Check that indeed the continue made progress, instead of re-trapping
144 # without advancing.
145 gdb_test "p counter - \$prev_counter" " = 1"
146
147 gdb_test "info breakpoints" \
148 "breakpoint.*keep.*y.*$hex.*in test at .*$srcfile:$line_bp.*already hit 2 times.*" \
149 "info breakpoints show enabled breakpoint"
150
151 gdb_test "disable \$bpnum"
152
153 gdb_test "commands\nset \$commands_ran = 1\nend" "" \
154 "set breakpoint commands"
155
156 gdb_test "info breakpoints" \
157 "breakpoint.*keep.*n.*$hex.*in test at .*$srcfile:$line_bp.*already hit 2 times.*" \
158 "info breakpoints shows disabled breakpoint"
159
160 # Run to the permanent breakpoint again. This time, since it's
161 # disabled, it should act as if we hadn't created it in the first
162 # place. IOW, we should get a random signal, and, the breakpoint's
163 # command should not run.
164 gdb_test "continue" "Program received signal SIGTRAP.*" \
165 "disabled permanent breakpoint doesn't explain stop"
166
167 gdb_test "info breakpoints" \
168 "breakpoint.*keep.*n.*$hex.*in test at .*$srcfile:$line_bp.*already hit 2 times.*" \
169 "info breakpoints still shows same number of hits"
170
171 gdb_test "print \$commands_ran" " = void" \
172 "breakpoint commands didn't run"
173
174 # Reenable the breakpoint, and check that it gets hit and accounted
175 # for this time.
176 gdb_test "enable \$bpnum" "" "reenable breakpoint"
177
178 gdb_test "continue" "Breakpoint .*" \
179 "stop at permanent breakpoint thrice"
180
181 gdb_test "info breakpoints" \
182 "breakpoint.*keep.*y.*$hex.*in test at .*$srcfile:$line_bp.*already hit 3 times.*" \
183 "info breakpoints shows one more hit"
184
185 gdb_test "print \$commands_ran" " = 1" "breakpoint commands ran"
186
187 # Check that stepi advances only past the permanent breakpoint, and
188 # not a single instruction more.
189 gdb_test "stepi" "after permanent bp .*" \
190 "single-step past permanent breakpoint"
191 }
192
193 with_test_prefix "next trips on permanent bp" {
194 delete_breakpoints
195
196 gdb_breakpoint "test_next"
197 gdb_continue_to_breakpoint "test_next"
198
199 gdb_breakpoint "$line_bp"
200 gdb_test "condition \$bpnum 0"
201
202 gdb_test "next" "after next .*"
203 }
204
205 if ![target_info exists gdb,nosignals] {
206
207 with_test_prefix "continue trips on nested permanent bp" {
208 delete_breakpoints
209
210 gdb_breakpoint "test_signal_nested"
211 gdb_continue_to_breakpoint "test_signal_nested"
212
213 gdb_breakpoint "$line_bp"
214 gdb_continue_to_breakpoint "permanent bp"
215 gdb_test "condition \$bpnum 0"
216
217 # Let SIGALRM trigger.
218 sleep 2
219
220 # We're now stopped at a permanent breakpoint, with a
221 # signal pending.
222 gdb_breakpoint "test_signal_nested_done"
223 gdb_continue_to_breakpoint "test_signal_nested_done"
224
225 # Ensure that the handler did run. There's one call to
226 # test in the mainline code, and another in the signal
227 # handler.
228 gdb_test "p counter" " = 2"
229 }
230
231 if [can_single_step_to_signal_handler] {
232
233 with_test_prefix "stepi signal with handler" {
234 delete_breakpoints
235
236 gdb_breakpoint "test_signal_with_handler"
237 gdb_continue_to_breakpoint "test_signal_with_handler"
238
239 gdb_breakpoint "$line_bp"
240
241 gdb_test "continue" "Breakpoint .*" "stop at permanent breakpoint"
242
243 gdb_test "queue-signal SIGUSR1"
244
245 set test "single-step to handler"
246 gdb_test_multiple "stepi" $test {
247 -re "Program received signal SIGTRAP.*$gdb_prompt $" {
248 fail $test
249 }
250 -re "handler .*$gdb_prompt $" {
251 pass $test
252 }
253 }
254
255 # Check that the mainline PC points at the permanent
256 # breakpoint.
257 gdb_test "up 2" "test .*" "up to mainline code"
258
259 gdb_test "p /x \$pc" " = $address_bp" \
260 "mainline pc points at permanent breakpoint"
261
262 gdb_test "continue" "Breakpoint .*" \
263 "stop at permanent breakpoint, out of handler"
264 }
265
266 with_test_prefix "stepi signal with no handler" {
267 gdb_breakpoint "test_signal_no_handler"
268 gdb_continue_to_breakpoint "test_signal_no_handler"
269
270 gdb_test "continue" "Breakpoint .*" "stop at permanent breakpoint"
271
272 gdb_test "queue-signal SIGUSR1"
273
274 gdb_test "stepi" "after permanent bp .*" \
275 "single-step past permanent breakpoint"
276 }
277 }
278 }
279 }
280
281 foreach always_inserted {off on} {
282 foreach sw_watchpoint {0 1} {
283 with_test_prefix "always_inserted=$always_inserted, sw_watchpoint=$sw_watchpoint" {
284 test $always_inserted $sw_watchpoint
285 }
286 }
287 }
This page took 0.036955 seconds and 4 git commands to generate.