eb52047c9659e68df9fbb0315457ce1d38f8029b
[binutils-gdb.git] / gdb / testsuite / gdb.base / break.exp
1 # Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999,
2 # 2000, 2002, 2003
3 # Free Software Foundation, Inc.
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 # Please email any bugs, comments, and/or additions to this file to:
20 # bug-gdb@prep.ai.mit.edu
21
22 # This file was written by Rob Savoye. (rob@cygnus.com)
23
24 if $tracelevel then {
25 strace $tracelevel
26 }
27
28
29 #
30 # test running programs
31 #
32 set prms_id 0
33 set bug_id 0
34
35 set testfile "break"
36 set srcfile ${testfile}.c
37 set binfile ${objdir}/${subdir}/${testfile}
38
39 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-w}] != "" } {
40 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
41 }
42
43 if [get_compiler_info ${binfile}] {
44 return -1
45 }
46
47 gdb_exit
48 gdb_start
49 gdb_reinitialize_dir $srcdir/$subdir
50 gdb_load ${binfile}
51
52 if [target_info exists gdb_stub] {
53 gdb_step_for_stub;
54 }
55 #
56 # test simple breakpoint setting commands
57 #
58
59 # Test deleting all breakpoints when there are none installed,
60 # GDB should not prompt for confirmation.
61 # Note that gdb-init.exp provides a "delete_breakpoints" proc
62 # for general use elsewhere.
63
64 send_gdb "delete breakpoints\n"
65 gdb_expect {
66 -re "Delete all breakpoints.*$" {
67 send_gdb "y\n"
68 gdb_expect {
69 -re "$gdb_prompt $" {
70 fail "Delete all breakpoints when none (unexpected prompt)"
71 }
72 timeout { fail "Delete all breakpoints when none (timeout after unexpected prompt)" }
73 }
74 }
75 -re ".*$gdb_prompt $" { pass "Delete all breakpoints when none" }
76 timeout { fail "Delete all breakpoints when none (timeout)" }
77 }
78
79 #
80 # test break at function
81 #
82 gdb_test "break main" \
83 "Breakpoint.*at.* file .*$srcfile, line.*" \
84 "breakpoint function"
85
86 #
87 # test break at quoted function
88 #
89 gdb_test "break \"marker2\"" \
90 "Breakpoint.*at.* file .*$srcfile, line.*" \
91 "breakpoint quoted function"
92
93 #
94 # test break at function in file
95 #
96 gdb_test "break $srcfile:factorial" \
97 "Breakpoint.*at.* file .*$srcfile, line.*" \
98 "breakpoint function in file"
99
100 #
101 # test break at line number
102 #
103 # Note that the default source file is the last one whose source text
104 # was printed. For native debugging, before we've executed the
105 # program, this is the file containing main, but for remote debugging,
106 # it's wherever the processor was stopped when we connected to the
107 # board. So, to be sure, we do a list command.
108 #
109 gdb_test "list main" \
110 ".*main \\(argc, argv, envp\\).*" \
111 "use `list' to establish default source file"
112 gdb_test "break 79" \
113 "Breakpoint.*at.* file .*$srcfile, line 79\\." \
114 "breakpoint line number"
115
116 #
117 # test duplicate breakpoint
118 #
119 gdb_test "break 79" \
120 "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line 79\\." \
121 "breakpoint duplicate"
122
123 #
124 # test break at line number in file
125 #
126 gdb_test "break $srcfile:85" \
127 "Breakpoint.*at.* file .*$srcfile, line 85\\." \
128 "breakpoint line number in file"
129
130
131 #
132 # Test putting a break at the start of a multi-line if conditional.
133 # Verify the breakpoint was put at the start of the conditional.
134 #
135 gdb_test "break multi_line_if_conditional" \
136 "Breakpoint.*at.* file .*$srcfile, line 109\\." \
137 "breakpoint at start of multi line if conditional"
138
139 gdb_test "break multi_line_while_conditional" \
140 "Breakpoint.*at.* file .*$srcfile, line 124\\." \
141 "breakpoint at start of multi line while conditional"
142
143 #
144 # check to see what breakpoints are set
145 #
146 if [target_info exists gdb_stub] {
147 set main_line 72
148 } else {
149 set main_line 75
150 }
151
152 if {$hp_aCC_compiler} {
153 set proto "\\(int\\)"
154 } else {
155 set proto ""
156 }
157
158 gdb_test "info break" \
159 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
160 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$main_line.*
161 \[0-9\]+\[\t \]+breakpoint keep y.* in marker2 at .*$srcfile:4\[49\].*
162 \[0-9\]+\[\t \]+breakpoint keep y.* in factorial$proto at .*$srcfile:96.*
163 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:79.*
164 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:79.*
165 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:85.*
166 \[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_if_conditional at .*$srcfile:109.*
167 \[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_while_conditional at .*$srcfile:124" \
168 "breakpoint info"
169
170 # FIXME: The rest of this test doesn't work with anything that can't
171 # handle arguments.
172 # Huh? There doesn't *appear* to be anything that passes arguments
173 # below.
174 if [istarget "mips-idt-*"] then {
175 return
176 }
177
178 #
179 # run until the breakpoint at main is hit. For non-stubs-using targets.
180 #
181 if ![target_info exists use_gdb_stub] {
182 if [istarget "*-*-vxworks*"] then {
183 send_gdb "run vxmain \"2\"\n"
184 set timeout 120
185 verbose "Timeout is now $timeout seconds" 2
186 } else {
187 send_gdb "run\n"
188 }
189 gdb_expect {
190 -re "The program .* has been started already.*y or n. $" {
191 send_gdb "y\n"
192 exp_continue
193 }
194 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:75.*75\[\t \]+if .argc.* \{.*$gdb_prompt $"\
195 { pass "run until function breakpoint" }
196 -re ".*$gdb_prompt $" { fail "run until function breakpoint" }
197 timeout { fail "run until function breakpoint (timeout)" }
198 }
199 } else {
200 if ![target_info exists gdb_stub] {
201 gdb_test continue ".*Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:75.*75\[\t \]+if .argc.*\{.*" "stub continue"
202 }
203 }
204
205 #
206 # run until the breakpoint at a line number
207 #
208 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:79.*79\[\t \]+printf.*factorial.*" \
209 "run until breakpoint set at a line number"
210
211 #
212 # Run until the breakpoint set in a function in a file
213 #
214 for {set i 6} {$i >= 1} {incr i -1} {
215 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:96.*96\[\t \]+.*if .value > 1. \{.*" \
216 "run until file:function($i) breakpoint"
217 }
218
219 #
220 # Run until the breakpoint set at a quoted function
221 #
222 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, (0x\[0-9a-f\]+ in )?marker2 \\(a=43\\) at .*$srcfile:4\[49\].*" \
223 "run until quoted breakpoint"
224 #
225 # run until the file:function breakpoint at a line number in a file
226 #
227 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:85.*85\[\t \]+argc = \\(argc == 12345\\);.*" \
228 "run until file:linenum breakpoint"
229
230 # Test break at offset +1
231
232 gdb_test "break +1" \
233 "Breakpoint.*at.* file .*$srcfile, line 86\\." \
234 "breakpoint offset +1"
235
236 # Check to see if breakpoint is hit when stepped onto
237
238 gdb_test "step" \
239 ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:86.*86\[\t \]+return argc;" \
240 "step onto breakpoint"
241
242 #
243 # delete all breakpoints so we can start over, course this can be a test too
244 #
245 delete_breakpoints
246
247 #
248 # test temporary breakpoint at function
249 #
250
251 gdb_test "tbreak main" "Breakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function"
252
253 #
254 # test break at function in file
255 #
256
257 gdb_test "tbreak $srcfile:factorial" "Breakpoint.*at.* file .*$srcfile, line.*" \
258 "Temporary breakpoint function in file"
259
260 #
261 # test break at line number
262 #
263 send_gdb "tbreak 79\n"
264 gdb_expect {
265 -re "Breakpoint.*at.* file .*$srcfile, line 79.*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
266 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
267 timeout { fail "breakpoint line number #1 (timeout)" }
268 }
269
270 gdb_test "tbreak 75" "Breakpoint.*at.* file .*$srcfile, line 75.*" "Temporary breakpoint line number #2"
271
272 #
273 # test break at line number in file
274 #
275 send_gdb "tbreak $srcfile:85\n"
276 gdb_expect {
277 -re "Breakpoint.*at.* file .*$srcfile, line 85.*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
278 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
279 timeout { fail "Temporary breakpoint line number in file #1 (timeout)" }
280 }
281
282 gdb_test "tbreak $srcfile:81" "Breakpoint.*at.* file .*$srcfile, line 81.*" "Temporary breakpoint line number in file #2"
283
284 #
285 # check to see what breakpoints are set (temporary this time)
286 #
287 gdb_test "info break" "Num Type.*Disp Enb Address.*What.*\[\r\n\]
288 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$main_line.*\[\r\n\]
289 \[0-9\]+\[\t \]+breakpoint del.*y.*in factorial$proto at .*$srcfile:96.*\[\r\n\]
290 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:79.*\[\r\n\]
291 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:75.*\[\r\n\]
292 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:85.*\[\r\n\]
293 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:81.*" \
294 "Temporary breakpoint info"
295
296
297 #***********
298
299 # Verify that catchpoints for fork, vfork and exec don't trigger
300 # inappropriately. (There are no calls to those system functions
301 # in this test program.)
302 #
303 if ![runto_main] then { fail "break tests suppressed" }
304
305 send_gdb "catch\n"
306 gdb_expect {
307 -re "Catch requires an event name.*$gdb_prompt $"\
308 {pass "catch requires an event name"}
309 -re "$gdb_prompt $"\
310 {fail "catch requires an event name"}
311 timeout {fail "(timeout) catch requires an event name"}
312 }
313
314
315 set name "set catch fork, never expected to trigger"
316 send_gdb "catch fork\n"
317 gdb_expect {
318 -re "Catchpoint \[0-9\]* .fork..*$gdb_prompt $"
319 {pass $name}
320 -re "Catch of fork not yet implemented.*$gdb_prompt $"
321 {pass $name}
322 -re "$gdb_prompt $"
323 {fail $name}
324 timeout {fail "(timeout) $name"}
325 }
326
327
328 set name "set catch vfork, never expected to trigger"
329 send_gdb "catch vfork\n"
330
331 # If we are on HP-UX 10.20, we expect an error message to be
332 # printed if we type "catch vfork" at the gdb gdb_prompt. This is
333 # because on HP-UX 10.20, we cannot catch vfork events.
334
335 if [istarget "hppa*-hp-hpux10.20"] then {
336 gdb_expect {
337 -re "Catch of vfork events not supported on HP-UX 10.20..*$gdb_prompt $"
338 {pass $name}
339 -re "$gdb_prompt $"
340 {fail $name}
341 timeout {fail "(timeout) $name"}
342 }
343 } else {
344 gdb_expect {
345 -re "Catchpoint \[0-9\]* .vfork..*$gdb_prompt $"
346 {pass $name}
347 -re "Catch of vfork not yet implemented.*$gdb_prompt $"
348 {pass $name}
349 -re "$gdb_prompt $"
350 {fail $name}
351 timeout {fail "(timeout) $name"}
352 }
353 }
354
355 set name "set catch exec, never expected to trigger"
356 send_gdb "catch exec\n"
357 gdb_expect {
358 -re "Catchpoint \[0-9\]* .exec..*$gdb_prompt $"
359 {pass $name}
360 -re "Catch of exec not yet implemented.*$gdb_prompt $"
361 {pass $name}
362 -re "$gdb_prompt $" {fail $name}
363 timeout {fail "(timeout) $name"}
364 }
365
366 # Verify that GDB responds gracefully when asked to set a breakpoint
367 # on a nonexistent source line.
368 #
369 send_gdb "break 999\n"
370 gdb_expect {
371 -re "No line 999 in file .*$gdb_prompt $"\
372 {pass "break on non-existent source line"}
373 -re "$gdb_prompt $"\
374 {fail "break on non-existent source line"}
375 timeout {fail "(timeout) break on non-existent source line"}
376 }
377
378 # Run to the desired default location. If not positioned here, the
379 # tests below don't work.
380 #
381 gdb_test "until 79" "main .* at .*:79.*" "until 79"
382
383
384 # Verify that GDB allows one to just say "break", which is treated
385 # as the "default" breakpoint. Note that GDB gets cute when printing
386 # the informational message about other breakpoints at the same
387 # location. We'll hit that bird with this stone too.
388 #
389 send_gdb "break\n"
390 gdb_expect {
391 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
392 {pass "break on default location, 1st time"}
393 -re "$gdb_prompt $"\
394 {fail "break on default location, 1st time"}
395 timeout {fail "(timeout) break on default location, 1st time"}
396 }
397
398 send_gdb "break\n"
399 gdb_expect {
400 -re "Note: breakpoint \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
401 {pass "break on default location, 2nd time"}
402 -re "$gdb_prompt $"\
403 {fail "break on default location, 2nd time"}
404 timeout {fail "(timeout) break on default location, 2nd time"}
405 }
406
407 send_gdb "break\n"
408 gdb_expect {
409 -re "Note: breakpoints \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
410 {pass "break on default location, 3rd time"}
411 -re "$gdb_prompt $"\
412 {fail "break on default location, 3rd time"}
413 timeout {fail "(timeout) break on default location, 3rd time"}
414 }
415
416 send_gdb "break\n"
417 gdb_expect {
418 -re "Note: breakpoints \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
419 {pass "break on default location, 4th time"}
420 -re "$gdb_prompt $"\
421 {fail "break on default location, 4th time"}
422 timeout {fail "(timeout) break on default location, 4th time"}
423 }
424
425 # Verify that a "silent" breakpoint can be set, and that GDB is indeed
426 # "silent" about its triggering.
427 #
428 if ![runto_main] then { fail "break tests suppressed" }
429
430 send_gdb "break 79\n"
431 gdb_expect {
432 -re "Breakpoint (\[0-9\]*) at .*, line 79.*$gdb_prompt $"\
433 {pass "set to-be-silent break 79"}
434 -re "$gdb_prompt $"\
435 {fail "set to-be-silent break 79"}
436 timeout {fail "(timeout) set to-be-silent break 79"}
437 }
438
439 send_gdb "commands $expect_out(1,string)\n"
440 send_gdb "silent\n"
441 send_gdb "end\n"
442 gdb_expect {
443 -re ".*$gdb_prompt $"\
444 {pass "set silent break 79"}
445 timeout {fail "(timeout) set silent break 79"}
446 }
447
448 send_gdb "info break $expect_out(1,string)\n"
449 gdb_expect {
450 -re "\[0-9\]*\[ \t\]*breakpoint.*:79\r\n\[ \t\]*silent.*$gdb_prompt $"\
451 {pass "info silent break 79"}
452 -re "$gdb_prompt $"\
453 {fail "info silent break 79"}
454 timeout {fail "(timeout) info silent break 79"}
455 }
456 send_gdb "continue\n"
457 gdb_expect {
458 -re "Continuing.\r\n$gdb_prompt $"\
459 {pass "hit silent break 79"}
460 -re "$gdb_prompt $"\
461 {fail "hit silent break 79"}
462 timeout {fail "(timeout) hit silent break 79"}
463 }
464 send_gdb "bt\n"
465 gdb_expect {
466 -re "#0 main .* at .*:79.*$gdb_prompt $"\
467 {pass "stopped for silent break 79"}
468 -re "$gdb_prompt $"\
469 {fail "stopped for silent break 79"}
470 timeout {fail "(timeout) stopped for silent break 79"}
471 }
472
473 # Verify that GDB can at least parse a breakpoint with the
474 # "thread" keyword. (We won't attempt to test here that a
475 # thread-specific breakpoint really triggers appropriately.
476 # The gdb.threads subdirectory contains tests for that.)
477 #
478 send_gdb "break 80 thread 999\n"
479 gdb_expect {
480 -re "Unknown thread 999.*$gdb_prompt $"\
481 {pass "thread-specific breakpoint on non-existent thread disallowed"}
482 -re "$gdb_prompt $"\
483 {fail "thread-specific breakpoint on non-existent thread disallowed"}
484 timeout {fail "(timeout) thread-specific breakpoint on non-existent thread disallowed"}
485 }
486 send_gdb "break 80 thread foo\n"
487 gdb_expect {
488 -re "Junk after thread keyword..*$gdb_prompt $"\
489 {pass "thread-specific breakpoint on bogus thread ID disallowed"}
490 -re "$gdb_prompt $"\
491 {fail "thread-specific breakpoint on bogus thread ID disallowed"}
492 timeout {fail "(timeout) thread-specific breakpoint on bogus thread ID disallowed"}
493 }
494
495 # Verify that GDB responds gracefully to a breakpoint command with
496 # trailing garbage.
497 #
498 send_gdb "break 80 foo\n"
499 gdb_expect {
500 -re "Junk at end of arguments..*$gdb_prompt $"\
501 {pass "breakpoint with trailing garbage disallowed"}
502 -re "$gdb_prompt $"\
503 {fail "breakpoint with trailing garbage disallowed"}
504 timeout {fail "(timeout) breakpoint with trailing garbage disallowed"}
505 }
506
507 # Verify that GDB responds gracefully to a "clear" command that has
508 # no matching breakpoint. (First, get us off the current source line,
509 # which we know has a breakpoint.)
510 #
511 send_gdb "next\n"
512 gdb_expect {
513 -re ".*$gdb_prompt $"\
514 {pass "step over breakpoint"}
515 timeout {fail "(timeout) step over breakpoint"}
516 }
517 send_gdb "clear 81\n"
518 gdb_expect {
519 -re "No breakpoint at 81..*$gdb_prompt $"\
520 {pass "clear line has no breakpoint disallowed"}
521 -re "$gdb_prompt $"\
522 {fail "clear line has no breakpoint disallowed"}
523 timeout {fail "(timeout) clear line has no breakpoint disallowed"}
524 }
525 send_gdb "clear\n"
526 gdb_expect {
527 -re "No breakpoint at this line..*$gdb_prompt $"\
528 {pass "clear current line has no breakpoint disallowed"}
529 -re "$gdb_prompt $"\
530 {fail "clear current line has no breakpoint disallowed"}
531 timeout {fail "(timeout) clear current line has no breakpoint disallowed"}
532 }
533
534 # Verify that we can set and clear multiple breakpoints.
535 #
536 # We don't test that it deletes the correct breakpoints. We do at
537 # least test that it deletes more than one breakpoint.
538 #
539 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #1"
540 gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #2"
541 gdb_test "clear marker3" {Deleted breakpoints [0-9]+ [0-9]+.*}
542
543 # Verify that a breakpoint can be set via a convenience variable.
544 #
545 send_gdb "set \$foo=81\n"
546 gdb_expect {
547 -re "$gdb_prompt $"\
548 {pass "set convenience variable \$foo to 81"}
549 timeout {fail "(timeout) set convenience variable \$foo to 81"}
550 }
551 send_gdb "break \$foo\n"
552 gdb_expect {
553 -re "Breakpoint (\[0-9\]*) at .*, line 81.*$gdb_prompt $"\
554 {pass "set breakpoint via convenience variable"}
555 -re "$gdb_prompt $"\
556 {fail "set breakpoint via convenience variable"}
557 timeout {fail "(timeout) set breakpoint via convenience variable"}
558 }
559
560 # Verify that GDB responds gracefully to an attempt to set a
561 # breakpoint via a convenience variable whose type is not integer.
562 #
563 send_gdb "set \$foo=81.5\n"
564 gdb_expect {
565 -re "$gdb_prompt $"\
566 {pass "set convenience variable \$foo to 81.5"}
567 timeout {fail "(timeout) set convenience variable \$foo to 81.5"}
568 }
569 send_gdb "break \$foo\n"
570 gdb_expect {
571 -re "Convenience variables used in line specs must have integer values..*$gdb_prompt $"\
572 {pass "set breakpoint via non-integer convenience variable disallowed"}
573 -re "$gdb_prompt $"\
574 {fail "set breakpoint via non-integer convenience variable disallowed"}
575 timeout {fail "(timeout) set breakpoint via non-integer convenience variable disallowed"}
576 }
577
578 # Verify that we can set and trigger a breakpoint in a user-called function.
579 #
580 send_gdb "break marker2\n"
581 gdb_expect {
582 -re "Breakpoint (\[0-9\]*) at .*, line 4\[49\].*$gdb_prompt $"\
583 {pass "set breakpoint on to-be-called function"}
584 -re "$gdb_prompt $"\
585 {fail "set breakpoint on to-be-called function"}
586 timeout {fail "(timeout) set breakpoint on to-be-called function"}
587 }
588 send_gdb "print marker2(99)\n"
589 gdb_expect {
590 -re "The program being debugged stopped while in a function called from GDB.\r\nWhen the function .marker2$proto. is done executing, GDB will silently\r\nstop .instead of continuing to evaluate the expression containing\r\nthe function call...*$gdb_prompt $"\
591 {pass "hit breakpoint on called function"}
592 -re "$gdb_prompt $"\
593 {fail "hit breakpoint on called function"}
594 timeout {fail "(timeout) hit breakpoint on called function"}
595 }
596
597 # As long as we're stopped (breakpointed) in a called function,
598 # verify that we can successfully backtrace & such from here.
599 #
600 # In this and the following test, the _sr4export check apparently is needed
601 # for hppa*-*-hpux.
602 #
603 send_gdb "bt\n"
604 gdb_expect {
605 -re "#0\[ \t\]*($hex in )?marker2.*:4\[49\]\r\n#1.*_sr4export.*$gdb_prompt $"\
606 {pass "backtrace while in called function"}
607 -re "#0\[ \t\]*($hex in )?marker2.*:4\[49\]\r\n#1.*function called from gdb.*$gdb_prompt $"\
608 {pass "backtrace while in called function"}
609 -re "$gdb_prompt $"\
610 {fail "backtrace while in called function"}
611 timeout {fail "(timeout) backtrace while in called function"}
612 }
613
614 # Return from the called function. For remote targets, it's important to do
615 # this before runto_main, which otherwise may silently stop on the dummy
616 # breakpoint inserted by GDB at the program's entry point.
617 #
618 send_gdb "finish\n"
619 gdb_expect {
620 -re "Run till exit from .*marker2.* at .*4\[49\]\r\n.* in _sr4export.*$gdb_prompt $"\
621 {pass "finish from called function"}
622 -re "Run till exit from .*marker2.* at .*4\[49\]\r\n.*function called from gdb.*$gdb_prompt $"\
623 {pass "finish from called function"}
624 -re "Run till exit from .*marker2.* at .*4\[49\]\r\n.*Value returned.*$gdb_prompt $"\
625 {pass "finish from called function"}
626 -re "$gdb_prompt $"\
627 {fail "finish from called function"}
628 timeout {fail "(timeout) finish from called function"}
629 }
630
631 # Verify that GDB responds gracefully to a "finish" command with
632 # arguments.
633 #
634 if ![runto_main] then { fail "break tests suppressed" }
635
636 send_gdb "finish 123\n"
637 gdb_expect {
638 -re "The \"finish\" command does not take any arguments.\r\n$gdb_prompt $"\
639 {pass "finish with arguments disallowed"}
640 -re "$gdb_prompt $"\
641 {fail "finish with arguments disallowed"}
642 timeout {fail "(timeout) finish with arguments disallowed"}
643 }
644
645 # Verify that GDB responds gracefully to a request to "finish" from
646 # the outermost frame. On a stub that never exits, this will just
647 # run to the stubs routine, so we don't get this error... Thus the
648 # second condition.
649 #
650
651 send_gdb "finish\n"
652 gdb_expect {
653 -re "\"finish\" not meaningful in the outermost frame.\r\n$gdb_prompt $"\
654 {pass "finish from outermost frame disallowed"}
655 -re "Run till exit from.*\r\n$gdb_prompt $" {
656 pass "finish from outermost frame disallowed"
657 }
658 -re "$gdb_prompt $"\
659 {fail "finish from outermost frame disallowed"}
660 timeout {fail "(timeout) finish from outermost frame disallowed"}
661 }
662
663 # Verify that we can explicitly ask GDB to stop on all shared library
664 # events, and that it does so.
665 #
666 if [istarget "hppa*-*-hpux*"] then {
667 if ![runto_main] then { fail "break tests suppressed" }
668
669 send_gdb "set stop-on-solib-events 1\n"
670 gdb_expect {
671 -re "$gdb_prompt $"\
672 {pass "set stop-on-solib-events"}
673 timeout {fail "(timeout) set stop-on-solib-events"}
674 }
675
676 send_gdb "run\n"
677 gdb_expect {
678 -re ".*Start it from the beginning.*y or n. $"\
679 {send_gdb "y\n"
680 gdb_expect {
681 -re ".*Stopped due to shared library event.*$gdb_prompt $"\
682 {pass "triggered stop-on-solib-events"}
683 -re "$gdb_prompt $"\
684 {fail "triggered stop-on-solib-events"}
685 timeout {fail "(timeout) triggered stop-on-solib-events"}
686 }
687 }
688 -re "$gdb_prompt $"\
689 {fail "rerun for stop-on-solib-events"}
690 timeout {fail "(timeout) rerun for stop-on-solib-events"}
691 }
692
693 send_gdb "set stop-on-solib-events 0\n"
694 gdb_expect {
695 -re "$gdb_prompt $"\
696 {pass "reset stop-on-solib-events"}
697 timeout {fail "(timeout) reset stop-on-solib-events"}
698 }
699 }
700
701 # Hardware breakpoints are unsupported on HP-UX. Verify that GDB
702 # gracefully responds to requests to create them.
703 #
704 if [istarget "hppa*-*-hpux*"] then {
705 if ![runto_main] then { fail "break tests suppressed" }
706
707 send_gdb "hbreak\n"
708 gdb_expect {
709 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
710 {pass "hw breaks disallowed"}
711 -re "$gdb_prompt $"\
712 {fail "hw breaks disallowed"}
713 timeout {fail "(timeout) hw breaks disallowed"}
714 }
715
716 send_gdb "thbreak\n"
717 gdb_expect {
718 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
719 {pass "temporary hw breaks disallowed"}
720 -re "$gdb_prompt $"\
721 {fail "temporary hw breaks disallowed"}
722 timeout {fail "(timeout) temporary hw breaks disallowed"}
723 }
724 }
725
726 #********
727
728
729 #
730 # Test "next" over recursive function call.
731 #
732
733 proc test_next_with_recursion {} {
734 global gdb_prompt
735 global decimal
736 global binfile
737
738 if [target_info exists use_gdb_stub] {
739 # Reload the program.
740 delete_breakpoints
741 gdb_load ${binfile};
742 } else {
743 # FIXME: should be using runto
744 gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y"
745
746 delete_breakpoints
747 }
748
749 gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
750
751 # Run until we call factorial with 6
752
753 if [istarget "*-*-vxworks*"] then {
754 send_gdb "run vxmain \"6\"\n"
755 } else {
756 gdb_run_cmd
757 }
758 gdb_expect {
759 -re "Break.* factorial .value=6. .*$gdb_prompt $" {}
760 -re ".*$gdb_prompt $" {
761 fail "run to factorial(6)";
762 gdb_suppress_tests;
763 }
764 timeout { fail "run to factorial(6) (timeout)" ; gdb_suppress_tests }
765 }
766
767 # Continue until we call factorial recursively with 5.
768
769 if [gdb_test "continue" \
770 "Continuing.*Break.* factorial .value=5. .*" \
771 "continue to factorial(5)"] then { gdb_suppress_tests }
772
773 # Do a backtrace just to confirm how many levels deep we are.
774
775 if [gdb_test "backtrace" \
776 "#0\[ \t\]+ factorial .value=5..*" \
777 "backtrace from factorial(5)"] then { gdb_suppress_tests }
778
779 # Now a "next" should position us at the recursive call, which
780 # we will be performing with 4.
781
782 if [gdb_test "next" \
783 ".* factorial .value - 1.;.*" \
784 "next to recursive call"] then { gdb_suppress_tests }
785
786 # Disable the breakpoint at the entry to factorial by deleting them all.
787 # The "next" should run until we return to the next line from this
788 # recursive call to factorial with 4.
789 # Buggy versions of gdb will stop instead at the innermost frame on
790 # the line where we are trying to "next" to.
791
792 delete_breakpoints
793
794 if [istarget "mips*tx39-*"] {
795 set timeout 60
796 }
797 # We used to set timeout here for all other targets as well. This
798 # is almost certainly wrong. The proper timeout depends on the
799 # target system in use, and how we communicate with it, so there
800 # is no single value appropriate for all targets. The timeout
801 # should be established by the Dejagnu config file(s) for the
802 # board, and respected by the test suite.
803 #
804 # For example, if I'm running GDB over an SSH tunnel talking to a
805 # portmaster in California talking to an ancient 68k board running
806 # a crummy ROM monitor (a situation I can only wish were
807 # hypothetical), then I need a large timeout. But that's not the
808 # kind of knowledge that belongs in this file.
809
810 gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
811 "next over recursive call"
812
813 # OK, we should be back in the same stack frame we started from.
814 # Do a backtrace just to confirm.
815
816 set result [gdb_test "backtrace" \
817 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
818 "backtrace from factorial(5.1)"]
819 if { $result != 0 } { gdb_suppress_tests }
820
821 if [target_info exists gdb,noresults] { gdb_suppress_tests }
822 gdb_continue_to_end "recursive next test"
823 gdb_stop_suppressing_tests;
824 }
825
826 test_next_with_recursion
827
828
829 #********
830
831 # build a new file with optimization enabled so that we can try breakpoints
832 # on targets with optimized prologues
833
834 set binfileo2 ${objdir}/${subdir}/${testfile}o2
835
836 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfileo2}" executable {debug additional_flags="-O2" }] != "" } {
837 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
838 }
839
840 if [get_compiler_info ${binfileo2}] {
841 return -1
842 }
843
844 gdb_exit
845 gdb_start
846 gdb_reinitialize_dir $srcdir/$subdir
847 gdb_load ${binfileo2}
848
849 if [target_info exists gdb_stub] {
850 gdb_step_for_stub;
851 }
852
853 #
854 # test break at function
855 #
856 gdb_test "break main" \
857 "Breakpoint.*at.* file .*$srcfile, line.*" \
858 "breakpoint function, optimized file"
859
860 #
861 # test break at function
862 #
863 gdb_test "break marker4" \
864 "Breakpoint.*at.* file .*$srcfile, line.*" \
865 "breakpoint small function, optimized file"
866
867 #
868 # run until the breakpoint at main is hit. For non-stubs-using targets.
869 #
870 if ![target_info exists use_gdb_stub] {
871 if [istarget "*-*-vxworks*"] then {
872 send_gdb "run vxmain \"2\"\n"
873 set timeout 120
874 verbose "Timeout is now $timeout seconds" 2
875 } else {
876 send_gdb "run\n"
877 }
878 gdb_expect {
879 -re "The program .* has been started already.*y or n. $" {
880 send_gdb "y\n"
881 exp_continue
882 }
883 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:75.*75\[\t \]+if .argc.* \{.*$gdb_prompt $"\
884 { pass "run until function breakpoint, optimized file" }
885 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$gdb_prompt $"\
886 { pass "run until function breakpoint, optimized file (code motion)" }
887 -re ".*$gdb_prompt $" { fail "run until function breakpoint, optimized file" }
888 timeout { fail "run until function breakpoint, optimized file (timeout)" }
889 }
890 } else {
891 if ![target_info exists gdb_stub] {
892 gdb_test continue ".*Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:75.*75\[\t \]+if .argc.*\{.*" "stub continue, optimized file"
893 }
894 }
895
896 #
897 # run until the breakpoint at a small function
898 #
899
900 #
901 # Add a second pass pattern. The behavior differs here between stabs
902 # and dwarf for one-line functions. Stabs preserves two line symbols
903 # (one before the prologue and one after) with the same line number,
904 # but dwarf regards these as duplicates and discards one of them.
905 # Therefore the address after the prologue (where the breakpoint is)
906 # has no exactly matching line symbol, and GDB reports the breakpoint
907 # as if it were in the middle of a line rather than at the beginning.
908
909 send_gdb "continue\n"
910 gdb_expect {
911 -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile:51\[\r\n\]+51\[\t \]+void marker4.*" {
912 pass "run until breakpoint set at small function, optimized file"
913 }
914 -re "Breakpoint $decimal, $hex in marker4 \\(d=177601976\\) at .*$srcfile:51\[\r\n\]+51\[\t \]+void marker4.*" {
915 pass "run until breakpoint set at small function, optimized file"
916 }
917 # marker4() is defined at line 46 when compiled with -DPROTOTYPES
918 -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile:46\[\r\n\]+46\[\t \]+void marker4.*" {
919 pass "run until breakpoint set at small function, optimized file"
920 }
921 -re ".*$gdb_prompt " {
922 fail "run until breakpoint set at small function, optimized file"
923 }
924 timeout {
925 fail "run until breakpoint set at small function, optimized file (timeout)"
926 }
927 }
928
929
930 # Reset the default arguments for VxWorks
931 if [istarget "*-*-vxworks*"] {
932 set timeout 10
933 verbose "Timeout is now $timeout seconds" 2
934 send_gdb "set args main\n"
935 gdb_expect -re ".*$gdb_prompt $" {}
936 }