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