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