Commit | Line | Data |
---|---|---|
32d0add0 | 1 | # Copyright 1988-2015 Free Software Foundation, Inc. |
320b6f49 MR |
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 | # Based on break.exp by Rob Savoye. (rob@cygnus.com) | |
17 | # Hardware breakpoint support by Maciej W. Rozycki and Daniel Jacobowitz. | |
18 | # Only one hardware breakpoint is set at a time as targets may limit | |
19 | # the number available. | |
20 | ||
21 | ||
22 | if { [prepare_for_testing hbreak2.exp "hbreak2" {break.c break1.c} {debug nowarnings}] } { | |
23 | return -1 | |
24 | } | |
25 | set srcfile break.c | |
26 | set srcfile1 break1.c | |
27 | ||
28 | if ![runto_main] then { fail "break tests suppressed" } | |
29 | delete_breakpoints | |
30 | ||
31 | # | |
32 | # Test whether the target supports hardware breakpoints at all. | |
33 | # | |
34 | gdb_test_multiple "hbreak main" "hardware breakpoint support" { | |
35 | -re "No hardware breakpoint support in the target.*$gdb_prompt $" { | |
36 | unsupported "hardware breakpoints" | |
37 | return | |
38 | } | |
39 | -re "Hardware breakpoints used exceeds limit.*$gdb_prompt $" { | |
40 | unsupported "hardware breakpoints" | |
41 | return | |
42 | } | |
43 | -re "Hardware assisted breakpoint.*at.* file .*$srcfile, line.*$gdb_prompt $" { | |
44 | pass "hardware breakpoint support" | |
45 | } | |
46 | } | |
47 | gdb_run_cmd | |
48 | gdb_test_multiple "" "hardware breakpoint insertion" { | |
49 | -re "Warning:\[\r\n\]+Cannot insert hardware breakpoint \[0-9\]+\.\[\r\n\]+Could not insert hardware breakpoints:\[\r\n\]+You may have requested too many hardware breakpoints/watchpoints\.\[\r\n\]+.*$gdb_prompt $" { | |
50 | unsupported "hardware breakpoint insertion" | |
51 | return | |
52 | } | |
53 | -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:.*\[\r\n\]+.*\[\t \]+if .argc.* \{.*$gdb_prompt $" { | |
54 | pass "hardware breakpoint insertion" | |
55 | } | |
56 | } | |
57 | delete_breakpoints | |
58 | ||
59 | # | |
60 | # Test simple hardware breakpoint setting commands. | |
61 | # | |
62 | ||
63 | # | |
64 | # Test break at function. | |
65 | # | |
66 | gdb_test "hbreak main" \ | |
67 | "Hardware assisted breakpoint.*at.* file .*$srcfile, line.*" \ | |
68 | "hardware breakpoint function" | |
69 | delete_breakpoints | |
70 | ||
71 | # | |
72 | # Test break at quoted function. | |
73 | # | |
74 | gdb_test "hbreak \"marker2\"" \ | |
75 | "Hardware assisted breakpoint.*at.* file .*$srcfile1, line.*" \ | |
76 | "hardware breakpoint quoted function" | |
77 | delete_breakpoints | |
78 | ||
79 | # | |
80 | # Test break at function in file. | |
81 | # | |
82 | gdb_test "hbreak $srcfile:factorial" \ | |
83 | "Hardware assisted breakpoint.*at.* file .*$srcfile, line.*" \ | |
84 | "hardware breakpoint function in file" | |
85 | delete_breakpoints | |
86 | ||
87 | set bp_location1 [gdb_get_line_number "set breakpoint 1 here"] | |
88 | ||
89 | # | |
90 | # Test break at line number. | |
91 | # | |
92 | # Note that the default source file is the last one whose source text | |
93 | # was printed. For native debugging, before we've executed the | |
94 | # program, this is the file containing main, but for remote debugging, | |
95 | # it's wherever the processor was stopped when we connected to the | |
96 | # board. So, to be sure, we do a list command. | |
97 | # | |
98 | gdb_test "list main" \ | |
dc7e1a77 | 99 | ".*main \\(int argc, char ..argv, char ..envp\\).*" \ |
320b6f49 MR |
100 | "use `list' to establish default source file" |
101 | gdb_test "hbreak $bp_location1" \ | |
102 | "Hardware assisted breakpoint.*at.* file .*$srcfile, line $bp_location1\\." \ | |
103 | "hardware breakpoint line number" | |
104 | delete_breakpoints | |
105 | ||
106 | set bp_location2 [gdb_get_line_number "set breakpoint 2 here"] | |
107 | ||
108 | # | |
109 | # Test break at line number in file. | |
110 | # | |
111 | gdb_test "hbreak $srcfile:$bp_location2" \ | |
112 | "Hardware assisted breakpoint.*at.* file .*$srcfile, line $bp_location2\\." \ | |
113 | "hardware breakpoint line number in file" | |
114 | delete_breakpoints | |
115 | ||
116 | set bp_location3 [gdb_get_line_number "set breakpoint 3 here"] | |
117 | set bp_location4 [gdb_get_line_number "set breakpoint 4 here"] | |
118 | ||
119 | # | |
120 | # Test putting a break at the start of a multi-line if conditional. | |
121 | # Verify the breakpoint was put at the start of the conditional. | |
122 | # | |
123 | gdb_test "hbreak multi_line_if_conditional" \ | |
124 | "Hardware assisted breakpoint.*at.* file .*$srcfile, line $bp_location3\\." \ | |
125 | "hardware breakpoint at start of multi line if conditional" | |
126 | delete_breakpoints | |
127 | ||
128 | gdb_test "hbreak multi_line_while_conditional" \ | |
129 | "Hardware assisted breakpoint.*at.* file .*$srcfile, line $bp_location4\\." \ | |
130 | "hardware breakpoint at start of multi line while conditional" | |
131 | ||
320b6f49 MR |
132 | set bp_location6 [gdb_get_line_number "set breakpoint 6 here"] |
133 | ||
134 | set main_line $bp_location6 | |
135 | ||
136 | if {$hp_aCC_compiler} { | |
137 | set proto "\\(int\\)" | |
138 | } else { | |
139 | set proto "" | |
140 | } | |
141 | ||
142 | set bp_location7 [gdb_get_line_number "set breakpoint 7 here"] | |
143 | set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile1] | |
320b6f49 MR |
144 | |
145 | gdb_test "info break" \ | |
146 | "Num Type\[ \]+Disp Enb Address\[ \]+What.* | |
147 | \[0-9\]+\[\t \]+hw breakpoint keep y.* in multi_line_while_conditional at .*$srcfile:$bp_location4" \ | |
148 | "hardware breakpoint info" | |
149 | delete_breakpoints | |
150 | ||
151 | # | |
152 | # Run until the breakpoint at main is hit. For non-stubs-using targets. | |
153 | # | |
154 | gdb_test "hbreak main" \ | |
155 | "Hardware assisted breakpoint.*at.* file .*$srcfile, line.*" \ | |
156 | "hardware breakpoint function (2)" | |
157 | gdb_run_cmd | |
158 | gdb_test "" \ | |
159 | "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*" \ | |
160 | "run until function breakpoint" | |
161 | delete_breakpoints | |
162 | ||
163 | # | |
164 | # Run until the breakpoint at a line number. | |
165 | # | |
166 | gdb_test "hbreak $bp_location1" \ | |
167 | "Hardware assisted breakpoint.*at.* file .*$srcfile, line $bp_location1\\." \ | |
168 | "hardware breakpoint line number (2)" | |
169 | gdb_test "continue" \ | |
170 | "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \ | |
171 | "run until breakpoint set at a line number" | |
172 | delete_breakpoints | |
173 | ||
174 | # | |
175 | # Run until the breakpoint set in a function in a file. | |
176 | # | |
177 | gdb_test "hbreak $srcfile:factorial" \ | |
178 | "Hardware assisted breakpoint.*at.* file .*$srcfile, line.*" \ | |
179 | "hardware breakpoint function in file (2)" | |
180 | for {set i 6} {$i >= 1} {incr i -1} { | |
181 | gdb_test "continue" \ | |
182 | "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:$bp_location7.*$bp_location7\[\t \]+.*if .value > 1. \{.*" \ | |
183 | "run until file:function($i) breakpoint" | |
184 | } | |
185 | delete_breakpoints | |
186 | ||
187 | # | |
188 | # Run until the breakpoint set at a quoted function. | |
189 | # | |
190 | gdb_test "hbreak \"marker2\"" \ | |
191 | "Hardware assisted breakpoint.*at.* file .*$srcfile1, line.*" \ | |
192 | "hardware breakpoint quoted function (2)" | |
193 | gdb_test "continue" \ | |
dc7e1a77 | 194 | "Continuing\\..*Breakpoint \[0-9\]+, (0x\[0-9a-f\]+ in )?marker2 \\(a=43\\) at .*$srcfile1:$bp_location8.*" \ |
320b6f49 MR |
195 | "run until quoted breakpoint" |
196 | delete_breakpoints | |
197 | # | |
198 | # Run until the file:function breakpoint at a line number in a file. | |
199 | # | |
200 | gdb_test "hbreak $srcfile:$bp_location2" \ | |
201 | "Hardware assisted breakpoint.*at.* file .*$srcfile, line $bp_location2\\." \ | |
202 | "hardware breakpoint line number in file (2)" | |
203 | gdb_test "continue" \ | |
204 | "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location2.*$bp_location2\[\t \]+argc = \\(argc == 12345\\);.*" \ | |
205 | "run until file:linenum breakpoint" | |
206 | delete_breakpoints | |
207 | ||
208 | # Test break at offset +1. | |
209 | set bp_location10 [gdb_get_line_number "set breakpoint 10 here"] | |
210 | ||
211 | gdb_test "hbreak +1" \ | |
212 | "Hardware assisted breakpoint.*at.* file .*$srcfile, line $bp_location10\\." \ | |
213 | "hardware breakpoint offset +1" | |
214 | ||
215 | # Check to see if breakpoint is hit when stepped onto. | |
216 | ||
217 | gdb_test "step" \ | |
218 | ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10.*$bp_location10\[\t \]+return argc;.*breakpoint 10 here.*" \ | |
219 | "step onto hardware breakpoint" | |
220 | delete_breakpoints | |
221 | ||
222 | # Check to see if breakpoint can be set on ending brace of function. | |
223 | set bp_location10a [gdb_get_line_number "set breakpoint 10a here"] | |
224 | ||
225 | gdb_test "hbreak $bp_location10a" \ | |
226 | "Hardware assisted breakpoint.*at.* file .*$srcfile, line $bp_location10a\\." \ | |
227 | "setting hardware breakpoint at }" | |
228 | ||
229 | gdb_test "continue" \ | |
230 | ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10a.*$bp_location10a\[\t \]+}.*breakpoint 10a here.*" \ | |
231 | "continue to hardware breakpoint at }" | |
232 | ||
233 | # | |
234 | # Delete all breakpoints so we can start over, course this can be a test too. | |
235 | # | |
236 | delete_breakpoints | |
237 | ||
238 | # | |
239 | # Test temporary breakpoint at function. | |
240 | # | |
241 | ||
242 | gdb_test "thbreak main" \ | |
243 | "Hardware assisted breakpoint.*at.* file .*$srcfile, line.*" \ | |
244 | "temporary hardware breakpoint function" | |
245 | delete_breakpoints | |
246 | ||
247 | # | |
248 | # Test break at function in file. | |
249 | # | |
250 | ||
251 | gdb_test "thbreak $srcfile:factorial" \ | |
252 | "Hardware assisted breakpoint.*at.* file .*$srcfile, line.*" \ | |
253 | "temporary hardware breakpoint function in file" | |
254 | delete_breakpoints | |
255 | ||
256 | # | |
257 | # Test break at line number. | |
258 | # | |
259 | gdb_test "thbreak $bp_location1" \ | |
260 | "Hardware assisted breakpoint.*at.* file .*$srcfile, line $bp_location1.*" \ | |
261 | "temporary hardware breakpoint line number #1" | |
262 | delete_breakpoints | |
263 | ||
264 | gdb_test "thbreak $bp_location6" \ | |
265 | "Hardware assisted breakpoint.*at.* file .*$srcfile, line $bp_location6.*" \ | |
266 | "temporary hardware breakpoint line number #2" | |
267 | delete_breakpoints | |
268 | ||
269 | # | |
270 | # Test break at line number in file. | |
271 | # | |
272 | gdb_test "thbreak $srcfile:$bp_location2" \ | |
273 | "Hardware assisted breakpoint.*at.* file .*$srcfile, line $bp_location2.*" \ | |
274 | "temporary hardware breakpoint line number in file #1" | |
275 | delete_breakpoints | |
276 | ||
277 | set bp_location11 [gdb_get_line_number "set breakpoint 11 here"] | |
278 | gdb_test "thbreak $srcfile:$bp_location11" \ | |
279 | "Hardware assisted breakpoint.*at.* file .*$srcfile, line $bp_location11.*" \ | |
280 | "temporary hardware breakpoint line number in file #2" | |
281 | ||
282 | # | |
283 | # Check to see what breakpoints are set (temporary this time). | |
284 | # | |
285 | gdb_test "info break" \ | |
286 | "Num Type.*Disp Enb Address.*What.*\[\r\n\] | |
287 | \[0-9\]+\[\t \]+hw breakpoint del.*y.*in main at .*$srcfile:$bp_location11.*" \ | |
288 | "temporary hardware breakpoint info" | |
289 | ||
290 | ||
291 | #*********** | |
292 | ||
293 | if ![runto_main] then { fail "break tests suppressed" } | |
294 | ||
295 | # Verify that GDB responds gracefully when asked to set a breakpoint | |
296 | # on a nonexistent source line. | |
297 | # | |
298 | gdb_test_no_output "set breakpoint pending off" | |
299 | gdb_test "hbreak 999" \ | |
300 | "No line 999 in the current file." \ | |
301 | "hardware break on non-existent source line" | |
302 | ||
303 | # Run to the desired default location. If not positioned here, the | |
304 | # tests below don't work. | |
305 | # | |
306 | gdb_test "until $bp_location1" "main .* at .*:$bp_location1.*" \ | |
307 | "until bp_location1" | |
308 | ||
309 | ||
310 | # Verify that GDB allows one to just say "hbreak", which is treated | |
311 | # as the "default" breakpoint. | |
312 | # | |
313 | gdb_test "hbreak" "Hardware assisted breakpoint \[0-9\]*.*" \ | |
314 | "hardware break on default location" | |
315 | ||
316 | # Verify that a "silent" breakpoint can be set, and that GDB is indeed | |
317 | # "silent" about its triggering. | |
318 | # | |
319 | if ![runto_main] then { fail "break tests suppressed" } | |
320 | ||
321 | gdb_test_multiple "hbreak $bp_location1" \ | |
322 | "set to-be-silent hardware break bp_location1" { | |
323 | -re "Hardware assisted breakpoint (\[0-9\]*) at .*, line $bp_location1.*$gdb_prompt $" { | |
324 | pass "set to-be-silent hardware break bp_location1" | |
325 | } | |
326 | } | |
327 | ||
328 | gdb_test "commands $expect_out(1,string)\nsilent\nend" ">end" "set silent break bp_location1" | |
329 | ||
330 | gdb_test "info break $expect_out(1,string)" \ | |
331 | "\[0-9\]*\[ \t\]*hw breakpoint.*:$bp_location1\r\n\[ \t\]*silent.*" \ | |
332 | "info silent hardware break bp_location1" | |
333 | ||
334 | gdb_test "continue" "Continuing." \ | |
335 | "hit silent hardware break bp_location1" | |
336 | ||
337 | gdb_test "bt" "#0 main .* at .*:$bp_location1.*" \ | |
338 | "stopped for silent hardware break bp_location1" | |
339 | ||
340 | # Verify that GDB can at least parse a breakpoint with the | |
341 | # "thread" keyword. (We won't attempt to test here that a | |
342 | # thread-specific breakpoint really triggers appropriately. | |
343 | # The gdb.threads subdirectory contains tests for that.) | |
344 | # | |
345 | set bp_location12 [gdb_get_line_number "set breakpoint 12 here"] | |
346 | gdb_test "hbreak $bp_location12 thread 999" "Unknown thread 999.*" \ | |
347 | "thread-specific hardware breakpoint on non-existent thread disallowed" | |
348 | ||
349 | gdb_test "hbreak $bp_location12 thread foo" \ | |
350 | "Junk after thread keyword.*" \ | |
351 | "thread-specific hardware breakpoint on bogus thread ID disallowed" | |
352 | ||
353 | # Verify that GDB responds gracefully to a breakpoint command with | |
354 | # trailing garbage. | |
355 | # | |
356 | gdb_test "hbreak $bp_location12 foo" \ | |
40e084e1 | 357 | "malformed linespec error: unexpected string, \"foo\".*" \ |
320b6f49 MR |
358 | "hardware breakpoint with trailing garbage disallowed" |
359 | ||
360 | # Verify that GDB responds gracefully to a "clear" command that has | |
361 | # no matching breakpoint. (First, get us off the current source line, | |
362 | # which we know has a breakpoint.) | |
363 | # | |
364 | gdb_test "next" "marker1.*" "step over hardware breakpoint" | |
365 | ||
366 | gdb_test "clear 81" "No breakpoint at 81.*" \ | |
367 | "clear line has no breakpoint disallowed" | |
368 | ||
369 | gdb_test "clear" "No breakpoint at this line.*" \ | |
370 | "clear current line has no breakpoint disallowed" | |
371 | delete_breakpoints | |
372 | ||
373 | # Verify that a breakpoint can be set via a convenience variable. | |
374 | # | |
375 | gdb_test_no_output "set \$foo=$bp_location11" \ | |
376 | "set convenience variable \$foo to bp_location11" | |
377 | ||
378 | gdb_test "hbreak \$foo" \ | |
379 | "Hardware assisted breakpoint (\[0-9\]*) at .*, line $bp_location11.*" \ | |
380 | "set hardware breakpoint via convenience variable" | |
381 | delete_breakpoints | |
382 | ||
383 | # Verify that GDB responds gracefully to an attempt to set a | |
384 | # breakpoint via a convenience variable whose type is not integer. | |
385 | # | |
386 | gdb_test_no_output "set \$foo=81.5" \ | |
387 | "set convenience variable \$foo to 81.5" | |
388 | ||
389 | gdb_test "hbreak \$foo" \ | |
390 | "Convenience variables used in line specs must have integer values.*" \ | |
391 | "set hardware breakpoint via non-integer convenience variable disallowed" | |
392 | ||
393 | # Verify that we can set and trigger a breakpoint in a user-called function. | |
394 | # | |
395 | gdb_test "hbreak marker2" \ | |
dc7e1a77 | 396 | "Hardware assisted breakpoint (\[0-9\]*) at .*, line $bp_location8.*" \ |
320b6f49 MR |
397 | "set hardware breakpoint on to-be-called function" |
398 | ||
399 | gdb_test "print marker2(99)" \ | |
400 | "The program being debugged stopped while in a function called from GDB.\r\nEvaluation of the expression containing the function\r\n.marker2$proto. will be abandoned.\r\nWhen the function is done executing, GDB will silently stop.*" \ | |
401 | "hit hardware breakpoint on called function" | |
402 | ||
403 | # As long as we're stopped (breakpointed) in a called function, | |
404 | # verify that we can successfully backtrace & such from here. | |
405 | # | |
406 | # In this and the following test, the _sr4export check apparently is needed | |
407 | # for hppa*-*-hpux. | |
408 | # | |
409 | gdb_test_multiple "bt" "backtrace while in called function" { | |
dc7e1a77 | 410 | -re "#0\[ \t\]*($hex in )?marker2.*:$bp_location8\r\n#1.*_sr4export.*$gdb_prompt $" { |
320b6f49 MR |
411 | pass "backtrace while in called function" |
412 | } | |
dc7e1a77 | 413 | -re "#0\[ \t\]*($hex in )?marker2.*:$bp_location8\r\n#1.*function called from gdb.*$gdb_prompt $" { |
320b6f49 MR |
414 | pass "backtrace while in called function" |
415 | } | |
416 | } | |
417 | ||
418 | # Return from the called function. For remote targets, it's important to do | |
419 | # this before runto_main, which otherwise may silently stop on the dummy | |
420 | # breakpoint inserted by GDB at the program's entry point. | |
421 | # | |
422 | gdb_test_multiple "finish" "finish from called function" { | |
dc7e1a77 | 423 | -re "Run till exit from .*marker2.* at .*$bp_location8\r\n.* in _sr4export.*$gdb_prompt $" { |
320b6f49 MR |
424 | pass "finish from called function" |
425 | } | |
dc7e1a77 | 426 | -re "Run till exit from .*marker2.* at .*$bp_location8\r\n.*function called from gdb.*$gdb_prompt $" { |
320b6f49 MR |
427 | pass "finish from called function" |
428 | } | |
dc7e1a77 | 429 | -re "Run till exit from .*marker2.* at .*$bp_location8\r\n.*Value returned.*$gdb_prompt $" { |
320b6f49 MR |
430 | pass "finish from called function" |
431 | } | |
432 | } | |
433 | ||
434 | #******** | |
435 | ||
436 | ||
437 | # | |
438 | # Test "next" over recursive function call. | |
439 | # | |
440 | ||
441 | proc test_next_with_recursion {} { | |
442 | global gdb_prompt | |
443 | global decimal | |
444 | global binfile | |
445 | ||
446 | delete_breakpoints | |
447 | ||
448 | # Can't set a hardware breakpoint without a live target, so do it now | |
449 | # before it's killed below. | |
450 | gdb_test "hbreak factorial" \ | |
451 | "Hardware assisted breakpoint $decimal at .*" \ | |
452 | "hardware break at factorial" | |
453 | ||
454 | gdb_test "kill" "" "kill program" \ | |
455 | "Kill the program being debugged.*y or n. $" "y" | |
456 | ||
457 | # Run until we call factorial with 6 | |
458 | ||
459 | gdb_run_cmd | |
460 | if [gdb_test "" \ | |
461 | "Break.* factorial .value=6. .*" \ | |
462 | "run to factorial(6)"] then { gdb_suppress_tests } | |
463 | ||
464 | # Continue until we call factorial recursively with 5. | |
465 | ||
466 | if [gdb_test "continue" \ | |
467 | "Continuing.*Break.* factorial .value=5. .*" \ | |
468 | "continue to factorial(5)"] then { gdb_suppress_tests } | |
469 | ||
470 | # Do a backtrace just to confirm how many levels deep we are. | |
471 | ||
472 | if [gdb_test "backtrace" \ | |
473 | "#0\[ \t\]+ factorial .value=5..*" \ | |
474 | "backtrace from factorial(5)"] then { gdb_suppress_tests } | |
475 | ||
476 | # Now a "next" should position us at the recursive call, which | |
477 | # we will be performing with 4. | |
478 | ||
479 | if [gdb_test "next" \ | |
480 | ".* factorial .value - 1.;.*" \ | |
481 | "next to recursive call"] then { gdb_suppress_tests } | |
482 | ||
483 | # Disable the breakpoint at the entry to factorial by deleting them all. | |
484 | # The "next" should run until we return to the next line from this | |
485 | # recursive call to factorial with 4. | |
486 | # Buggy versions of gdb will stop instead at the innermost frame on | |
487 | # the line where we are trying to "next" to. | |
488 | ||
489 | delete_breakpoints | |
490 | ||
491 | if [istarget "mips*tx39-*"] { | |
492 | set timeout 60 | |
493 | } | |
494 | # We used to set timeout here for all other targets as well. This | |
495 | # is almost certainly wrong. The proper timeout depends on the | |
496 | # target system in use, and how we communicate with it, so there | |
497 | # is no single value appropriate for all targets. The timeout | |
498 | # should be established by the Dejagnu config file(s) for the | |
499 | # board, and respected by the test suite. | |
500 | # | |
501 | # For example, if I'm running GDB over an SSH tunnel talking to a | |
502 | # portmaster in California talking to an ancient 68k board running | |
503 | # a crummy ROM monitor (a situation I can only wish were | |
504 | # hypothetical), then I need a large timeout. But that's not the | |
505 | # kind of knowledge that belongs in this file. | |
506 | ||
507 | gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \ | |
508 | "next over recursive call" | |
509 | ||
510 | # OK, we should be back in the same stack frame we started from. | |
511 | # Do a backtrace just to confirm. | |
512 | ||
513 | set result [gdb_test "backtrace" \ | |
514 | "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \ | |
515 | "backtrace from factorial(5.1)"] | |
516 | if { $result != 0 } { gdb_suppress_tests } | |
517 | ||
518 | if [target_info exists gdb,noresults] { gdb_suppress_tests } | |
519 | gdb_continue_to_end "recursive next test" | |
4ec70201 | 520 | gdb_stop_suppressing_tests |
320b6f49 MR |
521 | } |
522 | ||
523 | test_next_with_recursion | |
524 | ||
525 | ||
526 | #******** | |
527 | ||
528 | # Build a new file with optimization enabled so that we can try breakpoints | |
529 | # on targets with optimized prologues. | |
530 | ||
531 | if { [prepare_for_testing hbreak2.exp "hbreak2o2" {break.c break1.c} {debug nowarnings optimize=-O2}] } { | |
532 | return -1 | |
533 | } | |
534 | ||
535 | if ![runto_main] then { fail "break tests suppressed" } | |
536 | delete_breakpoints | |
537 | ||
538 | # | |
539 | # Test break at function. | |
540 | # | |
541 | gdb_test "hbreak main" \ | |
542 | "Hardware assisted breakpoint.*at.* file .*, line.*" \ | |
543 | "hardware breakpoint function, optimized file" | |
544 | ||
545 | # | |
546 | # Run until the breakpoint at main is hit. For non-stubs-using targets. | |
547 | # | |
548 | gdb_run_cmd | |
549 | gdb_test_multiple "" "run until hardware function breakpoint, optimized file" { | |
550 | -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $" { | |
551 | pass "run until hardware function breakpoint, optimized file" | |
552 | } | |
553 | -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$gdb_prompt $" { | |
554 | pass "run until hardware function breakpoint, optimized file (code motion)" | |
555 | } | |
556 | } | |
557 | delete_breakpoints | |
558 | ||
559 | # | |
560 | # Test break at function. | |
561 | # | |
562 | gdb_test "hbreak marker4" \ | |
563 | "Hardware assisted breakpoint.*at.* file .*$srcfile1, line.*" \ | |
564 | "hardware breakpoint small function, optimized file" | |
565 | ||
566 | # | |
567 | # Run until the breakpoint at a small function. | |
568 | # | |
569 | ||
570 | # | |
571 | # Add a second pass pattern. The behavior differs here between stabs | |
572 | # and dwarf for one-line functions. Stabs preserves two line symbols | |
573 | # (one before the prologue and one after) with the same line number, | |
574 | # but dwarf regards these as duplicates and discards one of them. | |
575 | # Therefore the address after the prologue (where the breakpoint is) | |
576 | # has no exactly matching line symbol, and GDB reports the breakpoint | |
577 | # as if it were in the middle of a line rather than at the beginning. | |
578 | ||
320b6f49 MR |
579 | set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile1] |
580 | ||
581 | gdb_test_multiple "continue" \ | |
582 | "run until hardware breakpoint set at small function, optimized file" { | |
320b6f49 | 583 | -re "Breakpoint $decimal, marker4 \\(d=(d@entry=)?177601976\\) at .*$srcfile1:$bp_location14\[\r\n\]+$bp_location14\[\t \]+void marker4.*" { |
320b6f49 MR |
584 | pass "run until hardware breakpoint set at small function, optimized file (line bp_location14)" |
585 | } | |
586 | -re "Breakpoint $decimal, factorial \\(.*\\) .*\{\r\n$gdb_prompt" { | |
587 | # GCC 4.3 emits bad line number information - see gcc/36748. | |
588 | if { [test_compiler_info "gcc-4-3-*"] } { | |
589 | setup_xfail *-*-* | |
590 | } | |
591 | fail "run until hardware breakpoint set at small function, optimized file" | |
592 | } | |
593 | } |