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