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