import gdb-1999-08-30 snapshot
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / break.exp
CommitLineData
c906108c
SS
1# Copyright (C) 1988, 1990, 1991, 1992, 1994, 1997, 1998
2# Free 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 2 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, write to the Free Software
16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18# Please email any bugs, comments, and/or additions to this file to:
19# bug-gdb@prep.ai.mit.edu
20
21# This file was written by Rob Savoye. (rob@cygnus.com)
22
23if $tracelevel then {
24 strace $tracelevel
25}
26
27
28#
29# test running programs
30#
31set prms_id 0
32set bug_id 0
33
34set testfile "break"
35set srcfile ${testfile}.c
36set binfile ${objdir}/${subdir}/${testfile}
37
38if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-w}] != "" } {
39 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
40}
41
085dd6e6
JM
42if [get_compiler_info ${binfile}] {
43 return -1
44}
45
c906108c
SS
46gdb_exit
47gdb_start
48gdb_reinitialize_dir $srcdir/$subdir
49gdb_load ${binfile}
50
51if [target_info exists gdb_stub] {
52 gdb_step_for_stub;
53}
54#
55# test simple breakpoint setting commands
56#
57
58# Test deleting all breakpoints when there are none installed,
59# GDB should not prompt for confirmation.
60# Note that gdb-init.exp provides a "delete_breakpoints" proc
61# for general use elsewhere.
62
63send_gdb "delete breakpoints\n"
64gdb_expect {
65 -re "Delete all breakpoints.*$" {
66 send_gdb "y\n"
67 gdb_expect {
68 -re "$gdb_prompt $" {
69 fail "Delete all breakpoints when none (unexpected prompt)"
70 }
71 timeout { fail "Delete all breakpoints when none (timeout after unexpected prompt)" }
72 }
73 }
74 -re ".*$gdb_prompt $" { pass "Delete all breakpoints when none" }
75 timeout { fail "Delete all breakpoints when none (timeout)" }
76}
77
78#
79# test break at function
80#
81gdb_test "break main" \
82 "Breakpoint.*at.* file .*$srcfile, line.*" \
83 "breakpoint function"
84
85#
86# test break at function in file
87#
88gdb_test "break $srcfile:factorial" \
89 "Breakpoint.*at.* file .*$srcfile, line.*" \
90 "breakpoint function in file"
91
92#
93# test break at line number
94#
085dd6e6
JM
95gdb_test "break 79" \
96 "Breakpoint.*at.* file .*$srcfile, line 79\\." \
c906108c
SS
97 "breakpoint line number"
98
99#
100# test duplicate breakpoint
101#
085dd6e6
JM
102gdb_test "break 79" \
103 "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line 79\\." \
c906108c
SS
104 "breakpoint duplicate"
105
106#
107# test break at line number in file
108#
085dd6e6
JM
109gdb_test "break $srcfile:85" \
110 "Breakpoint.*at.* file .*$srcfile, line 85\\." \
c906108c
SS
111 "breakpoint line number in file"
112
113
114#
115# check to see what breakpoints are set
116#
117if [target_info exists gdb_stub] {
085dd6e6 118 set main_line 72
c906108c 119} else {
085dd6e6 120 set main_line 75
c906108c
SS
121}
122
085dd6e6
JM
123if {$hp_aCC_compiler} {
124 set proto "\\(int\\)"
125} else {
126 set proto ""
127}
c906108c
SS
128gdb_test "info break" \
129 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
130\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$main_line.*
085dd6e6
JM
131\[0-9\]+\[\t \]+breakpoint keep y.* in factorial$proto at .*$srcfile:95.*
132\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:79.*
133\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:79.*
134\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:85" \
c906108c
SS
135 "breakpoint info"
136
137
138# FIXME: The rest of this test doesn't work with anything that can't
139# handle arguments.
140# Huh? There doesn't *appear* to be anything that passes arguments
141# below.
142if [istarget "mips-idt-*"] then {
143 return
144}
145
146#
147# run until the breakpoint at main is hit. For non-stubs-using targets.
148#
149if ![target_info exists use_gdb_stub] {
150 if [istarget "*-*-vxworks*"] then {
151 send_gdb "run vxmain \"2\"\n"
152 set timeout 120
153 verbose "Timeout is now $timeout seconds" 2
154 } else {
155 send_gdb "run\n"
156 }
157 gdb_expect {
158 -re "The program .* has been started already.*y or n. $" {
159 send_gdb "y\n"
160 exp_continue
161 }
085dd6e6 162 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:75.*75\[\t \]+if .argc.* \{.*$gdb_prompt $"\
c906108c
SS
163 { pass "run until function breakpoint" }
164 -re ".*$gdb_prompt $" { fail "run until function breakpoint" }
165 timeout { fail "run until function breakpoint (timeout)" }
166 }
167} else {
168 if ![target_info exists gdb_stub] {
085dd6e6 169 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:75.*75\[\t \]+if .argc.*\{" "stub continue"
c906108c
SS
170 }
171}
172
173#
174# run until the breakpoint at a line number
175#
085dd6e6 176gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:79.*79\[\t \]+printf.*factorial.*" \
c906108c
SS
177 "run until breakpoint set at a line number"
178
179#
180# Run until the breakpoint set in a function in a file
181#
182for {set i 6} {$i >= 1} {incr i -1} {
085dd6e6 183 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:95.*95\[\t \]+.*if .value > 1. \{.*" \
c906108c
SS
184 "run until file:function($i) breakpoint"
185}
186
187#
188# run until the file:function breakpoint at a line number in a file
189#
085dd6e6 190gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:85.*85\[\t \]+return 0;" \
c906108c
SS
191 "run until file:linenum breakpoint"
192
193#
194# delete all breakpoints so we can start over, course this can be a test too
195#
196delete_breakpoints
197
198#
199# test temporary breakpoint at function
200#
201
202gdb_test "tbreak main" "Breakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function"
203
204#
205# test break at function in file
206#
207
208gdb_test "tbreak $srcfile:factorial" "Breakpoint.*at.* file .*$srcfile, line.*" \
209 "Temporary breakpoint function in file"
210
211#
212# test break at line number
213#
085dd6e6 214send_gdb "tbreak 79\n"
c906108c 215gdb_expect {
085dd6e6 216 -re "Breakpoint.*at.* file .*$srcfile, line 79.*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
c906108c
SS
217 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
218 timeout { fail "breakpoint line number #1 (timeout)" }
219}
220
085dd6e6 221gdb_test "tbreak 75" "Breakpoint.*at.* file .*$srcfile, line 75.*" "Temporary breakpoint line number #2"
c906108c
SS
222
223#
224# test break at line number in file
225#
085dd6e6 226send_gdb "tbreak $srcfile:85\n"
c906108c 227gdb_expect {
085dd6e6 228 -re "Breakpoint.*at.* file .*$srcfile, line 85.*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
c906108c
SS
229 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
230 timeout { fail "Temporary breakpoint line number in file #1 (timeout)" }
231}
232
085dd6e6 233gdb_test "tbreak $srcfile:81" "Breakpoint.*at.* file .*$srcfile, line 81.*" "Temporary breakpoint line number in file #2"
c906108c
SS
234
235#
236# check to see what breakpoints are set (temporary this time)
237#
085dd6e6
JM
238gdb_test "info break" "Num Type.*Disp Enb Address.*What.*\[\r\n\]
239\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$main_line.*\[\r\n\]
240\[0-9\]+\[\t \]+breakpoint del.*y.*in factorial$proto at .*$srcfile:95.*\[\r\n\]
241\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:79.*\[\r\n\]
242\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:75.*\[\r\n\]
243\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:85.*\[\r\n\]
244\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:81.*" \
245 "Temporary breakpoint info"
c906108c
SS
246
247
248#***********
249
250# Verify that catchpoints for fork, vfork and exec don't trigger
251# inappropriately. (There are no calls to those system functions
252# in this test program.)
253#
254if ![runto_main] then { fail "break tests suppressed" }
255
256send_gdb "catch\n"
257gdb_expect {
258 -re "Catch requires an event name.*$gdb_prompt $"\
259 {pass "catch requires an event name"}
260 -re "$gdb_prompt $"\
261 {fail "catch requires an event name"}
262 timeout {fail "(timeout) catch requires an event name"}
263}
264
265
266set name "set catch fork, never expected to trigger"
267send_gdb "catch fork\n"
268gdb_expect {
269 -re "Catchpoint \[0-9\]* .fork..*$gdb_prompt $"
270 {pass $name}
271 -re "Catch of fork not yet implemented.*$gdb_prompt $"
272 {pass $name}
273 -re "$gdb_prompt $"
274 {fail $name}
275 timeout {fail "(timeout) $name"}
276}
277
278
279set name "set catch vfork, never expected to trigger"
280send_gdb "catch vfork\n"
281
282# If we are on HP-UX 10.20, we expect an error message to be
283# printed if we type "catch vfork" at the gdb gdb_prompt. This is
284# because on HP-UX 10.20, we cannot catch vfork events.
285
286if [istarget "hppa*-hp-hpux10.20"] then {
287 gdb_expect {
288 -re "Catch of vfork events not supported on HP-UX 10.20..*$gdb_prompt $"
289 {pass $name}
290 -re "$gdb_prompt $"
291 {fail $name}
292 timeout {fail "(timeout) $name"}
293 }
294} else {
295 gdb_expect {
296 -re "Catchpoint \[0-9\]* .vfork..*$gdb_prompt $"
297 {pass $name}
298 -re "Catch of vfork not yet implemented.*$gdb_prompt $"
299 {pass $name}
300 -re "$gdb_prompt $"
301 {fail $name}
302 timeout {fail "(timeout) $name"}
303 }
304}
305
306set name "set catch exec, never expected to trigger"
307send_gdb "catch exec\n"
308gdb_expect {
309 -re "Catchpoint \[0-9\]* .exec..*$gdb_prompt $"
310 {pass $name}
311 -re "Catch of exec not yet implemented.*$gdb_prompt $"
312 {pass $name}
313 -re "$gdb_prompt $" {fail $name}
314 timeout {fail "(timeout) $name"}
315}
316
317# Verify that "until <location>" works. (This is really just syntactic
318# sugar for "tbreak <location>; continue".)
319#
085dd6e6 320send_gdb "until 79\n"
c906108c 321gdb_expect {
085dd6e6
JM
322 -re "main .* at .*:79.*$gdb_prompt $"\
323 {pass "until 79"}
c906108c 324 -re "$gdb_prompt $"\
085dd6e6
JM
325 {fail "until 79"}
326 timeout {fail "(timeout) until 79"}
c906108c
SS
327}
328
329# Verify that a malformed "until" is gracefully caught.
330#
085dd6e6 331send_gdb "until 80 then stop\n"
c906108c
SS
332gdb_expect {
333 -re "Junk at end of arguments..*$gdb_prompt $"\
334 {pass "malformed until"}
335 -re "$gdb_prompt $"\
336 {fail "malformed until"}
337 timeout {fail "(timeout) malformed until"}
338}
339
340# Verify that GDB responds gracefully when asked to set a breakpoint
341# on a nonexistent source line.
342#
343send_gdb "break 999\n"
344gdb_expect {
345 -re "No line 999 in file .*$gdb_prompt $"\
346 {pass "break on non-existent source line"}
347 -re "$gdb_prompt $"\
348 {fail "break on non-existent source line"}
349 timeout {fail "(timeout) break on non-existent source line"}
350}
351
352# Verify that GDB allows one to just say "break", which is treated
353# as the "default" breakpoint. Note that GDB gets cute when printing
354# the informational message about other breakpoints at the same
355# location. We'll hit that bird with this stone too.
356#
357send_gdb "break\n"
358gdb_expect {
359 -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
360 {pass "break on default location, 1st time"}
361 -re "$gdb_prompt $"\
362 {fail "break on default location, 1st time"}
363 timeout {fail "(timeout) break on default location, 1st time"}
364}
365
366send_gdb "break\n"
367gdb_expect {
368 -re "Note: breakpoint \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
369 {pass "break on default location, 2nd time"}
370 -re "$gdb_prompt $"\
371 {fail "break on default location, 2nd time"}
372 timeout {fail "(timeout) break on default location, 2nd time"}
373}
374
375send_gdb "break\n"
376gdb_expect {
377 -re "Note: breakpoints \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
378 {pass "break on default location, 3rd time"}
379 -re "$gdb_prompt $"\
380 {fail "break on default location, 3rd time"}
381 timeout {fail "(timeout) break on default location, 3rd time"}
382}
383
384send_gdb "break\n"
385gdb_expect {
386 -re "Note: breakpoints \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
387 {pass "break on default location, 4th time"}
388 -re "$gdb_prompt $"\
389 {fail "break on default location, 4th time"}
390 timeout {fail "(timeout) break on default location, 4th time"}
391}
392
393# Verify that a "silent" breakpoint can be set, and that GDB is indeed
394# "silent" about its triggering.
395#
396if ![runto_main] then { fail "break tests suppressed" }
397
085dd6e6 398send_gdb "break 79\n"
c906108c 399gdb_expect {
085dd6e6
JM
400 -re "Breakpoint (\[0-9\]*) at .*, line 79.*$gdb_prompt $"\
401 {pass "set to-be-silent break 79"}
c906108c 402 -re "$gdb_prompt $"\
085dd6e6
JM
403 {fail "set to-be-silent break 79"}
404 timeout {fail "(timeout) set to-be-silent break 79"}
c906108c
SS
405}
406
407send_gdb "commands $expect_out(1,string)\n"
408send_gdb "silent\n"
409send_gdb "end\n"
410gdb_expect {
411 -re ".*$gdb_prompt $"\
085dd6e6
JM
412 {pass "set silent break 79"}
413 timeout {fail "(timeout) set silent break 79"}
c906108c
SS
414}
415
416send_gdb "info break $expect_out(1,string)\n"
417gdb_expect {
085dd6e6
JM
418 -re "\[0-9\]*\[ \t\]*breakpoint.*:79\r\n\[ \t\]*silent.*$gdb_prompt $"\
419 {pass "info silent break 79"}
c906108c 420 -re "$gdb_prompt $"\
085dd6e6
JM
421 {fail "info silent break 79"}
422 timeout {fail "(timeout) info silent break 79"}
c906108c
SS
423}
424send_gdb "continue\n"
425gdb_expect {
426 -re "Continuing.\r\n$gdb_prompt $"\
085dd6e6 427 {pass "hit silent break 79"}
c906108c 428 -re "$gdb_prompt $"\
085dd6e6
JM
429 {fail "hit silent break 79"}
430 timeout {fail "(timeout) hit silent break 79"}
c906108c
SS
431}
432send_gdb "bt\n"
433gdb_expect {
085dd6e6
JM
434 -re "#0 main .* at .*:79.*$gdb_prompt $"\
435 {pass "stopped for silent break 79"}
c906108c 436 -re "$gdb_prompt $"\
085dd6e6
JM
437 {fail "stopped for silent break 79"}
438 timeout {fail "(timeout) stopped for silent break 79"}
c906108c
SS
439}
440
441# Verify that GDB can at least parse a breakpoint with the
442# "thread" keyword. (We won't attempt to test here that a
443# thread-specific breakpoint really triggers appropriately.
444# The gdb.threads subdirectory contains tests for that.)
445#
085dd6e6 446send_gdb "break 80 thread 999\n"
c906108c
SS
447gdb_expect {
448 -re "Unknown thread 999.*$gdb_prompt $"\
449 {pass "thread-specific breakpoint on non-existent thread disallowed"}
450 -re "$gdb_prompt $"\
451 {fail "thread-specific breakpoint on non-existent thread disallowed"}
452 timeout {fail "(timeout) thread-specific breakpoint on non-existent thread disallowed"}
453}
085dd6e6 454send_gdb "break 80 thread foo\n"
c906108c
SS
455gdb_expect {
456 -re "Junk after thread keyword..*$gdb_prompt $"\
457 {pass "thread-specific breakpoint on bogus thread ID disallowed"}
458 -re "$gdb_prompt $"\
459 {fail "thread-specific breakpoint on bogus thread ID disallowed"}
460 timeout {fail "(timeout) thread-specific breakpoint on bogus thread ID disallowed"}
461}
462
463# Verify that GDB responds gracefully to a breakpoint command with
464# trailing garbage.
465#
085dd6e6 466send_gdb "break 80 foo\n"
c906108c
SS
467gdb_expect {
468 -re "Junk at end of arguments..*$gdb_prompt $"\
469 {pass "breakpoint with trailing garbage disallowed"}
470 -re "$gdb_prompt $"\
471 {fail "breakpoint with trailing garbage disallowed"}
472 timeout {fail "(timeout) breakpoint with trailing garbage disallowed"}
473}
474
475# Verify that GDB responds gracefully to a "clear" command that has
476# no matching breakpoint. (First, get us off the current source line,
477# which we know has a breakpoint.)
478#
479send_gdb "next\n"
480gdb_expect {
481 -re ".*$gdb_prompt $"\
482 {pass "step over breakpoint"}
483 timeout {fail "(timeout) step over breakpoint"}
484}
085dd6e6 485send_gdb "clear 81\n"
c906108c 486gdb_expect {
085dd6e6 487 -re "No breakpoint at 81..*$gdb_prompt $"\
c906108c
SS
488 {pass "clear line has no breakpoint disallowed"}
489 -re "$gdb_prompt $"\
490 {fail "clear line has no breakpoint disallowed"}
491 timeout {fail "(timeout) clear line has no breakpoint disallowed"}
492}
493send_gdb "clear\n"
494gdb_expect {
495 -re "No breakpoint at this line..*$gdb_prompt $"\
496 {pass "clear current line has no breakpoint disallowed"}
497 -re "$gdb_prompt $"\
498 {fail "clear current line has no breakpoint disallowed"}
499 timeout {fail "(timeout) clear current line has no breakpoint disallowed"}
500}
501
502# Verify that a breakpoint can be set via a convenience variable.
503#
085dd6e6 504send_gdb "set \$foo=81\n"
c906108c
SS
505gdb_expect {
506 -re "$gdb_prompt $"\
085dd6e6
JM
507 {pass "set convenience variable \$foo to 81"}
508 timeout {fail "(timeout) set convenience variable \$foo to 81"}
c906108c
SS
509}
510send_gdb "break \$foo\n"
511gdb_expect {
085dd6e6 512 -re "Breakpoint (\[0-9\]*) at .*, line 81.*$gdb_prompt $"\
c906108c
SS
513 {pass "set breakpoint via convenience variable"}
514 -re "$gdb_prompt $"\
515 {fail "set breakpoint via convenience variable"}
516 timeout {fail "(timeout) set breakpoint via convenience variable"}
517}
518
519# Verify that GDB responds gracefully to an attempt to set a
520# breakpoint via a convenience variable whose type is not integer.
521#
085dd6e6 522send_gdb "set \$foo=81.5\n"
c906108c
SS
523gdb_expect {
524 -re "$gdb_prompt $"\
085dd6e6
JM
525 {pass "set convenience variable \$foo to 81.5"}
526 timeout {fail "(timeout) set convenience variable \$foo to 81.5"}
c906108c
SS
527}
528send_gdb "break \$foo\n"
529gdb_expect {
530 -re "Convenience variables used in line specs must have integer values..*$gdb_prompt $"\
531 {pass "set breakpoint via non-integer convenience variable disallowed"}
532 -re "$gdb_prompt $"\
533 {fail "set breakpoint via non-integer convenience variable disallowed"}
534 timeout {fail "(timeout) set breakpoint via non-integer convenience variable disallowed"}
535}
536
537# Verify that we can set and trigger a breakpoint in a user-called function.
538#
539send_gdb "break marker2\n"
540gdb_expect {
085dd6e6 541 -re "Breakpoint (\[0-9\]*) at .*, line 4\[49\].*$gdb_prompt $"\
c906108c
SS
542 {pass "set breakpoint on to-be-called function"}
543 -re "$gdb_prompt $"\
544 {fail "set breakpoint on to-be-called function"}
545 timeout {fail "(timeout) set breakpoint on to-be-called function"}
546}
547send_gdb "print marker2(99)\n"
548gdb_expect {
085dd6e6 549 -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 $"\
c906108c
SS
550 {pass "hit breakpoint on called function"}
551 -re "$gdb_prompt $"\
552 {fail "hit breakpoint on called function"}
553 timeout {fail "(timeout) hit breakpoint on called function"}
554}
555
556# As long as we're stopped (breakpointed) in a called function,
557# verify that we can successfully backtrace & such from here.
558#
559if [istarget "hppa*-*-hpux*"] then {
560 send_gdb "bt\n"
561 gdb_expect {
104c1213 562 -re "#0\[ \t\]*0x\[0-9\]* in marker2.*:4\[49\]\r\n#1.*_sr4export.*$gdb_prompt $"\
085dd6e6 563 {pass "backtrace while in called function"}
104c1213
JM
564 -re "#0\[ \t\]*0x\[0-9\]* in marker2.*:4\[49\]\r\n#1.*function called from gdb.*$gdb_prompt $"\
565
c906108c
SS
566 {pass "backtrace while in called function"}
567 -re "$gdb_prompt $"\
568 {fail "backtrace while in called function"}
569 timeout {fail "(timeout) backtrace while in called function"}
570 }
571 send_gdb "finish\n"
572 gdb_expect {
085dd6e6
JM
573 -re "Run till exit from .*marker2.* at .*4\[49\]\r\n.* in _sr4export.*$gdb_prompt $"\
574 {pass "finish from called function"}
575 -re "Run till exit from .*marker2.* at .*4\[49\]\r\n.*function called from gdb.*$gdb_prompt $"\
c906108c 576 {pass "finish from called function"}
104c1213
JM
577 -re "Run till exit from .*marker2.* at .*4\[49\]\r\n.*Value returned.*$gdb_prompt $"\
578 {pass "finish from called function"}
c906108c
SS
579 -re "$gdb_prompt $"\
580 {fail "finish from called function"}
581 timeout {fail "(timeout) finish from called function"}
582 }
583}
584
585# Verify that GDB responds gracefully to a "finish" command with
586# arguments.
587#
588if ![runto_main] then { fail "break tests suppressed" }
589
590send_gdb "finish 123\n"
591gdb_expect {
592 -re "The \"finish\" command does not take any arguments.\r\n$gdb_prompt $"\
593 {pass "finish with arguments disallowed"}
594 -re "$gdb_prompt $"\
595 {fail "finish with arguments disallowed"}
596 timeout {fail "(timeout) finish with arguments disallowed"}
597}
598
599# Verify that GDB responds gracefully to a request to "finish" from
7a292a7a
SS
600# the outermost frame. On a stub that never exits, this will just
601# run to the stubs routine, so we don't get this error... Thus the
602# second condition.
c906108c 603#
7a292a7a 604
c906108c
SS
605send_gdb "finish\n"
606gdb_expect {
607 -re "\"finish\" not meaningful in the outermost frame.\r\n$gdb_prompt $"\
608 {pass "finish from outermost frame disallowed"}
7a292a7a
SS
609 -re "Run till exit from.*" {
610 pass "finish from outermost frame disallowed"
611 }
c906108c
SS
612 -re "$gdb_prompt $"\
613 {fail "finish from outermost frame disallowed"}
614 timeout {fail "(timeout) finish from outermost frame disallowed"}
615}
616
617# Verify that we can explicitly ask GDB to stop on all shared library
618# events, and that it does so.
619#
620if [istarget "hppa*-*-hpux*"] then {
621 if ![runto_main] then { fail "break tests suppressed" }
622
623 send_gdb "set stop-on-solib-events 1\n"
624 gdb_expect {
625 -re "$gdb_prompt $"\
626 {pass "set stop-on-solib-events"}
627 timeout {fail "(timeout) set stop-on-solib-events"}
628 }
629
630 send_gdb "run\n"
631 gdb_expect {
632 -re ".*Start it from the beginning.*y or n. $"\
633 {send_gdb "y\n"
634 gdb_expect {
635 -re ".*Stopped due to shared library event.*$gdb_prompt $"\
636 {pass "triggered stop-on-solib-events"}
637 -re "$gdb_prompt $"\
638 {fail "triggered stop-on-solib-events"}
639 timeout {fail "(timeout) triggered stop-on-solib-events"}
640 }
641 }
642 -re "$gdb_prompt $"\
643 {fail "rerun for stop-on-solib-events"}
644 timeout {fail "(timeout) rerun for stop-on-solib-events"}
645 }
646
647 send_gdb "set stop-on-solib-events 0\n"
648 gdb_expect {
649 -re "$gdb_prompt $"\
650 {pass "reset stop-on-solib-events"}
651 timeout {fail "(timeout) reset stop-on-solib-events"}
652 }
653}
654
655# Hardware breakpoints are unsupported on HP-UX. Verify that GDB
656# gracefully responds to requests to create them.
657#
658if [istarget "hppa*-*-hpux*"] then {
659 if ![runto_main] then { fail "break tests suppressed" }
660
661 send_gdb "hbreak\n"
662 gdb_expect {
663 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
664 {pass "hw breaks disallowed"}
665 -re "$gdb_prompt $"\
666 {fail "hw breaks disallowed"}
667 timeout {fail "(timeout) hw breaks disallowed"}
668 }
669
670 send_gdb "thbreak\n"
671 gdb_expect {
672 -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
673 {pass "temporary hw breaks disallowed"}
674 -re "$gdb_prompt $"\
675 {fail "temporary hw breaks disallowed"}
676 timeout {fail "(timeout) temporary hw breaks disallowed"}
677 }
678}
679
680#********
681
682
683proc test_clear_command {} {
684 gdb_test "break main" "Breakpoint.*at.*" "break main #1"
685 gdb_test "break main" "Breakpoint.*at.*" "break main #2"
686
687 # We don't test that it deletes the correct breakpoints. We do at
688 # least test that it deletes more than one breakpoint.
689 gdb_test "clear main" {Deleted breakpoints [0-9]+ [0-9]+.*}
690}
691
692#
693# Test "next" over recursive function call.
694#
695
696proc test_next_with_recursion {} {
697 global gdb_prompt
698 global decimal
699 global binfile
700
701 if [target_info exists use_gdb_stub] {
702 # Reload the program.
703 delete_breakpoints
704 gdb_load ${binfile};
705 } else {
706 # FIXME: should be using runto
707 gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y"
708
709 delete_breakpoints
710 }
711
712 gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
713
714 # Run until we call factorial with 6
715
716 if [istarget "*-*-vxworks*"] then {
717 send_gdb "run vxmain \"6\"\n"
718 } else {
719 gdb_run_cmd
720 }
721 gdb_expect {
722 -re "Break.* factorial .value=6. .*$gdb_prompt $" {}
723 -re ".*$gdb_prompt $" {
724 fail "run to factorial(6)";
725 gdb_suppress_tests;
726 }
727 timeout { fail "run to factorial(6) (timeout)" ; gdb_suppress_tests }
728 }
729
730 # Continue until we call factorial recursively with 5.
731
732 if [gdb_test "continue" \
733 "Continuing.*Break.* factorial .value=5. .*" \
734 "continue to factorial(5)"] then { gdb_suppress_tests }
735
736 # Do a backtrace just to confirm how many levels deep we are.
737
738 if [gdb_test "backtrace" \
739 "#0\[ \t\]+ factorial .value=5..*" \
740 "backtrace from factorial(5)"] then { gdb_suppress_tests }
741
742 # Now a "next" should position us at the recursive call, which
743 # we will be performing with 4.
744
745 if [gdb_test "next" \
746 ".* factorial .value - 1.;.*" \
747 "next to recursive call"] then { gdb_suppress_tests }
748
749 # Disable the breakpoint at the entry to factorial by deleting them all.
750 # The "next" should run until we return to the next line from this
751 # recursive call to factorial with 4.
752 # Buggy versions of gdb will stop instead at the innermost frame on
753 # the line where we are trying to "next" to.
754
755 delete_breakpoints
756
757 if [istarget "mips*tx39-*"] {
758 set timeout 60
759 } else {
760 set timeout 20
761 }
762
763 gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
764 "next over recursive call"
765
766 # OK, we should be back in the same stack frame we started from.
767 # Do a backtrace just to confirm.
768
769 set result [gdb_test "backtrace" \
770 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
771 "backtrace from factorial(5.1)"]
772 if { $result != 0 } { gdb_suppress_tests }
773
774 if [target_info exists gdb,noresults] { gdb_suppress_tests }
7a292a7a
SS
775 gdb_continue_to_end "recursive next test"
776 gdb_stop_suppressing_tests;
c906108c
SS
777}
778
779test_clear_command
780test_next_with_recursion
781
782# Reset the default arguments for VxWorks
783if [istarget "*-*-vxworks*"] {
784 set timeout 10
785 verbose "Timeout is now $timeout seconds" 2
786 send_gdb "set args main\n"
787 gdb_expect -re ".*$gdb_prompt $" {}
788}
This page took 0.065258 seconds and 4 git commands to generate.