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