1 # Copyright (C) 1988, 1990, 1991, 1992 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was written by Rob Savoye. (rob@cygnus.com)
27 # test running programs
33 set srcfile $binfile.c
35 if ![file exists $objdir/$subdir/$binfile] then {
36 perror "$objdir/$subdir/$binfile does not exist."
42 gdb_reinitialize_dir $srcdir/$subdir
43 gdb_load $objdir/$subdir/$binfile
46 # test simple breakpoint setting commands
50 # test deleting all breakpoints; note that gdb-init.exp provides a
51 # "delete_breakpoints" proc for general use elsewhere
53 send "delete breakpoints\n"
55 -re "Delete all breakpoints.*y or n. $"\
59 { send "info breakpoints\n"
61 -re "No breakpoints or watchpoints..*$prompt $" { pass "Deleted all breakpoints" }
62 -re ".*$prompt $" { fail "Deleted all breakpoints" }
63 timeout { fail "Deleted all breakpoints" }
66 timeout { fail "Deleted all breakpoints" }
69 -re ".*$prompt $" { fail "Deleted all breakpoints" }
70 timeout { fail "Deleted all breakpoints" }
74 # test break at function
78 -re "Breakpoint.*at.* file .*$srcfile, line.*$prompt $" { pass "breakpoint function" }
79 -re ".*$prompt $" { fail "breakpoint function" }
80 timeout { fail "(timeout) breakpoint function" }
85 # test break at function in file
87 send "break $srcfile:factorial\n"
89 -re "Breakpoint.*at.* file .*$srcfile, line.*$prompt $" { pass "breakpoint function in file" }
90 -re ".*$prompt $" { fail "breakpoint function in file" }
91 timeout { fail "(timeout) breakpoint function in file" }
96 # test break at line number
100 -re "Breakpoint.*at.* file .*$srcfile, line 60.*$prompt $" { pass "breakpoint line number" }
101 -re ".*$prompt $" { fail "breakpoint line number" }
102 timeout { fail "(timeout) breakpoint line number" }
107 # test duplicate breakpoint
111 -re "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line 60.*$prompt $"\
112 { pass "breakpoint duplicate" }
113 -re ".*$prompt $" { fail "breakpoint duplicate" }
114 timeout { fail "(timeout) breakpoint duplicate" }
119 # test break at line number in file
121 send "break $srcfile:66\n"
123 -re "Breakpoint.*at.* file .*$srcfile, line 66.*$prompt $" { pass "breakpoint line number in file" }
124 -re ".*$prompt $" { fail "breakpoint line number in file" }
125 timeout { fail "(timeout) breakpoint line number in file" }
130 # check to see what breakpoints are set
134 -re "Num Type\[ \]+Disp Enb Address\[ \]+What.*
135 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:56.*
136 \[0-9\]+\[\t \]+breakpoint keep y.* in factorial at .*$srcfile:72.*
137 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:60.*
138 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:60.*
139 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:66.*$prompt $" { pass "breakpoint info" }
140 -re ".*$prompt $" { fail "breakpoint info" }
141 timeout { fail "(timeout) breakpoint info" }
145 # FIXME: The rest of this test doesn't work with anything that can't
147 if [istarget "mips-idt-*"] then {
152 # run until the breakpoint at main is hit
154 if [istarget "*-*-vxworks"] then {
155 send "run vxmain \"2\"\n"
161 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:56.*56\[\t \]+if .argc.* \{.*$prompt $"\
162 { pass "run until function breakpoint" }
163 -re ".*$prompt $" { fail "run until function breakpoint" }
164 timeout { fail "(timeout) run until function breakpoint" }
169 # run until the breakpoint at a line number
173 -re "continue.*Continuing..*Breakpoint \[0-9\]+, main .argc.*argv.* at .*$srcfile:60.*
174 60\[\t ]+printf.*factorial.*$prompt $" { pass "run until breakpoint set at a line number" }
175 -re ".*$prompt $" { fail "run until breakpoint set at a line number" }
176 timeout { fail "(timeout) run until breakpoint set at a line number" }
181 # Run until the breakpoint set in a function in a file
185 -re "continue.*Continuing..*Breakpoint \[0-9\]+, factorial .value=2. at .*$srcfile:72.*72\[\t ]+if .value > 1. \{.*$prompt $"\
188 -re "continue.*Continuing..*Breakpoint \[0-9\]+, factorial .value=1. at .*$srcfile:72.*72\[\t ]+if .value > 1.*$prompt $" { pass "run until file:function breakpoint" }
189 -re ".*$prompt $" { fail "run until file:function breakpoint" }
190 timeout { fail "(timeout) run until file:function breakpoint" }
193 -re ".*$prompt $" { fail "run until file:function breakpoint" }
194 timeout { fail "(timeout) run until file:function breakpoint" }
199 # run until the file:function breakpoint at a line number in a file
203 -re "continue.*Continuing..*Breakpoint \[0-9\]+, main .*argc.*argv.* at .*$srcfile:66.*66\[\t ]+return 0;.*$prompt $" { pass "run until file:linenum breakpoint" }
204 -re ".*$prompt $" { fail "run until file:linenum breakpoint" }
205 timeout { fail "(timeout) run until file:linenum breakpoint" }
210 # delete all breakpoints so we can start over, course this can be a test too
212 send "delete breakpoints\n"
214 -re "Delete all breakpoints.*y or n.*$" {
218 send "info breakpoints\n"
220 -re "No breakpoints or watchpoints..*$prompt $" {
221 pass "Deleted all breakpoints"
223 -re ".*$prompt $" { fail "Deleted all breakpoints" }
224 timeout { fail "Deleted all breakpoints" }
227 timeout { fail "Deleted all breakpoints" }
230 -re ".*$prompt $" { fail "Deleted all breakpoints" }
231 timeout { fail "Deleted all breakpoints" }
236 # test temporary breakpoint at function
240 -re "Breakpoint.*at.* file .*$srcfile, line.*$prompt $" {
241 pass "Temporary breakpoint function"
244 pass "Temporary breakpoint function"
247 fail "(timeout) breakpoint function"
253 # test break at function in file
255 send "tbreak $srcfile:factorial\n"
257 -re "Breakpoint.*at.* file .*$srcfile, line.*$prompt $" {
258 pass "Temporary breakpoint function in file"
261 pass "Temporary breakpoint function in file"
264 fail "(timeout) breakpoint function in file"
270 # test break at line number
274 -re "Breakpoint.*at.* file .*$srcfile, line 60.*$prompt $" { pass "Temporary breakpoint line number" }
275 -re ".*$prompt $" { pass "Temporary breakpoint line number" }
276 timeout { fail "(timeout) breakpoint line number" }
281 # test break at line number in file
283 send "tbreak $srcfile:66\n"
285 -re "Breakpoint.*at.* file .*$srcfile, line 66.*$prompt $" { pass "Temporary breakpoint line number in file" }
286 -re ".*$prompt $" { pass "Temporary breakpoint line number in file" }
287 timeout { fail "(timeout) breakpoint line number in file" }
292 # check to see what breakpoints are set (temporary this time)
296 -re "Num Type.*Disp Enb Address.*What.*
297 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:56.*
298 \[0-9\]+\[\t \]+breakpoint del.*y.*in factorial at .*$srcfile:72.*
299 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:60.*
300 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:66.*$prompt $" {
301 pass "Temporary breakpoint info"
303 -re ".*$prompt $" { fail "Temporary breakpoint info" }
304 timeout { fail "(timeout) Temporary breakpoint info" }
308 proc test_clear_command {} {
309 gdb_test "break main" "Breakpoint.*at"
310 gdb_test "break main" "Breakpoint.*at"
312 # We don't test that it deletes the correct breakpoints. We do at
313 # least test that it deletes more than one breakpoint.
314 gdb_test "clear main" {Deleted breakpoints [0-9]+ [0-9]+}
318 # Test "next" over recursive function call.
321 proc test_next_with_recursion {} {
325 # FIXME: should be using runto
328 -re ".*Kill the program being debugged.*y or n. $" {
333 timeout { fail "killing inferior" ; return }
338 send "break factorial\n"
340 -re "Breakpoint $decimal at .*$prompt" {}
341 timeout { fail "break at factorial" ; return }
344 # Run until we call factorial with 6
346 if [istarget "*-*-vxworks"] then {
347 send "run vxmain \"6\"\n"
352 -re "Starting .*Break.* factorial .value=6. .*$prompt $" {}
353 timeout { fail "run to factorial(6)" ; return }
356 # Continue until we call factorial recursively with 5.
360 -re "Continuing.*Break.* factorial .value=5. .*$prompt $" {}
361 timeout { fail "continue to factorial(5)" ; return }
364 # Do a backtrace just to confirm how many levels deep we are.
366 set result [gdb_test "backtrace" \
367 "#0\[ \t\]+ factorial .value=5." \
368 "backtrace from factorial(5)"]
369 if $result!=0 then { return }
371 # Now a "next" should position us at the recursive call, which
372 # we will be performing with 4.
376 -re ".* factorial .value - 1.;.*$prompt $" {}
377 timeout { fail "next to recursive call (timeout)" ; return }
380 # Disable the breakpoint at the entry to factorial by deleting them all.
381 # The "next" should run until we return to the next line from this
382 # recursive call to factorial with 4.
383 # Buggy versions of gdb will stop instead at the innermost frame on
384 # the line where we are trying to "next" to.
390 -re "return .value.;.*$prompt $" {
391 # Note that the correct behavior is for GDB to *not* print the
393 pass "next over recursive call"
396 fail "next over recursive call" ; return
398 timeout { fail "next over recursive call (timeout)" ; return }
401 # OK, we should be back in the same stack frame we started from.
402 # Do a backtrace just to confirm.
404 set result [gdb_test "backtrace" \
405 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6." \
406 "backtrace from factorial(5)"]
407 if $result!=0 then { return }
409 # Continue until we exit. Should not stop again.
410 gdb_test "continue" "Continuing.\r\n720"\
411 "continue until exit in recursive next test"
415 test_next_with_recursion
417 # Reset the default arguments for VxWorks
418 if [istarget "*-*-vxworks"] then {
420 send "set args main\n"
421 expect -re ".*$prompt $" {}
424 if [istarget "a29k-*-udi"] then {
425 # FIXME: If PR 2415 is fixed, this is not needed.