1 # Copyright (C) 1988, 1990, 1991, 1992, 1994 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
76 gdb_test "break main" \
77 "Breakpoint.*at.* file .*$srcfile, line.*" \
81 # test break at function in file
83 gdb_test "break $srcfile:factorial" \
84 "Breakpoint.*at.* file .*$srcfile, line.*" \
85 "breakpoint function in file"
88 # test break at line number
91 "Breakpoint.*at.* file .*$srcfile, line 60\\." \
92 "breakpoint line number"
95 # test duplicate breakpoint
98 "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line 60\\." \
99 "breakpoint duplicate"
102 # test break at line number in file
104 gdb_test "break $srcfile:66" \
105 "Breakpoint.*at.* file .*$srcfile, line 66\\." \
106 "breakpoint line number in file"
110 # check to see what breakpoints are set
112 gdb_test "info break" \
113 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
114 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:56.*
115 \[0-9\]+\[\t \]+breakpoint keep y.* in factorial at .*$srcfile:72.*
116 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:60.*
117 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:60.*
118 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:66" \
122 # FIXME: The rest of this test doesn't work with anything that can't
124 if [istarget "mips-idt-*"] then {
129 # run until the breakpoint at main is hit
131 if [istarget "*-*-vxworks"] then {
132 send "run vxmain \"2\"\n"
138 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:56.*56\[\t \]+if .argc.* \{.*$prompt $"\
139 { pass "run until function breakpoint" }
140 -re ".*$prompt $" { fail "run until function breakpoint" }
141 timeout { fail "(timeout) run until function breakpoint" }
146 # run until the breakpoint at a line number
150 -re "continue.*Continuing..*Breakpoint \[0-9\]+, main .argc.*argv.* at .*$srcfile:60.*
151 60\[\t ]+printf.*factorial.*$prompt $" { pass "run until breakpoint set at a line number" }
152 -re ".*$prompt $" { fail "run until breakpoint set at a line number" }
153 timeout { fail "(timeout) run until breakpoint set at a line number" }
158 # Run until the breakpoint set in a function in a file
162 -re "continue.*Continuing..*Breakpoint \[0-9\]+, factorial .value=2. at .*$srcfile:72.*72\[\t ]+if .value > 1. \{.*$prompt $"\
165 -re "continue.*Continuing..*Breakpoint \[0-9\]+, factorial .value=1. at .*$srcfile:72.*72\[\t ]+if .value > 1.*$prompt $" { pass "run until file:function breakpoint" }
166 -re ".*$prompt $" { fail "run until file:function breakpoint" }
167 timeout { fail "(timeout) run until file:function breakpoint" }
170 -re ".*$prompt $" { fail "run until file:function breakpoint" }
171 timeout { fail "(timeout) run until file:function breakpoint" }
176 # run until the file:function breakpoint at a line number in a file
180 -re "continue.*Continuing..*Breakpoint \[0-9\]+, main .*argc.*argv.* at .*$srcfile:66.*66\[\t ]+return 0;.*$prompt $" { pass "run until file:linenum breakpoint" }
181 -re ".*$prompt $" { fail "run until file:linenum breakpoint" }
182 timeout { fail "(timeout) run until file:linenum breakpoint" }
187 # delete all breakpoints so we can start over, course this can be a test too
189 send "delete breakpoints\n"
191 -re "Delete all breakpoints.*y or n.*$" {
195 send "info breakpoints\n"
197 -re "No breakpoints or watchpoints..*$prompt $" {
198 pass "Deleted all breakpoints"
200 -re ".*$prompt $" { fail "Deleted all breakpoints" }
201 timeout { fail "Deleted all breakpoints" }
204 timeout { fail "Deleted all breakpoints" }
207 -re ".*$prompt $" { fail "Deleted all breakpoints" }
208 timeout { fail "Deleted all breakpoints" }
213 # test temporary breakpoint at function
217 -re "Breakpoint.*at.* file .*$srcfile, line.*$prompt $" {
218 pass "Temporary breakpoint function"
221 pass "Temporary breakpoint function"
224 fail "(timeout) breakpoint function"
230 # test break at function in file
232 send "tbreak $srcfile:factorial\n"
234 -re "Breakpoint.*at.* file .*$srcfile, line.*$prompt $" {
235 pass "Temporary breakpoint function in file"
238 pass "Temporary breakpoint function in file"
241 fail "(timeout) breakpoint function in file"
247 # test break at line number
251 -re "Breakpoint.*at.* file .*$srcfile, line 60.*$prompt $" { pass "Temporary breakpoint line number" }
252 -re ".*$prompt $" { pass "Temporary breakpoint line number" }
253 timeout { fail "(timeout) breakpoint line number" }
258 # test break at line number in file
260 send "tbreak $srcfile:66\n"
262 -re "Breakpoint.*at.* file .*$srcfile, line 66.*$prompt $" { pass "Temporary breakpoint line number in file" }
263 -re ".*$prompt $" { pass "Temporary breakpoint line number in file" }
264 timeout { fail "(timeout) breakpoint line number in file" }
269 # check to see what breakpoints are set (temporary this time)
273 -re "Num Type.*Disp Enb Address.*What.*
274 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:56.*
275 \[0-9\]+\[\t \]+breakpoint del.*y.*in factorial at .*$srcfile:72.*
276 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:60.*
277 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:66.*$prompt $" {
278 pass "Temporary breakpoint info"
280 -re ".*$prompt $" { fail "Temporary breakpoint info" }
281 timeout { fail "(timeout) Temporary breakpoint info" }
285 proc test_clear_command {} {
286 gdb_test "break main" "Breakpoint.*at.*"
287 gdb_test "break main" "Breakpoint.*at.*"
289 # We don't test that it deletes the correct breakpoints. We do at
290 # least test that it deletes more than one breakpoint.
291 gdb_test "clear main" {Deleted breakpoints [0-9]+ [0-9]+.*}
295 # Test "next" over recursive function call.
298 proc test_next_with_recursion {} {
302 # FIXME: should be using runto
305 -re ".*Kill the program being debugged.*y or n. $" {
310 timeout { fail "killing inferior" ; return }
315 send "break factorial\n"
317 -re "Breakpoint $decimal at .*$prompt" {}
318 timeout { fail "break at factorial" ; return }
321 # Run until we call factorial with 6
323 if [istarget "*-*-vxworks"] then {
324 send "run vxmain \"6\"\n"
329 -re "Starting .*Break.* factorial .value=6. .*$prompt $" {}
330 timeout { fail "run to factorial(6)" ; return }
333 # Continue until we call factorial recursively with 5.
337 -re "Continuing.*Break.* factorial .value=5. .*$prompt $" {}
338 timeout { fail "continue to factorial(5)" ; return }
341 # Do a backtrace just to confirm how many levels deep we are.
343 set result [gdb_test "backtrace" \
344 "#0\[ \t\]+ factorial .value=5..*" \
345 "backtrace from factorial(5)"]
346 if $result!=0 then { return }
348 # Now a "next" should position us at the recursive call, which
349 # we will be performing with 4.
353 -re ".* factorial .value - 1.;.*$prompt $" {}
354 timeout { fail "next to recursive call (timeout)" ; return }
357 # Disable the breakpoint at the entry to factorial by deleting them all.
358 # The "next" should run until we return to the next line from this
359 # recursive call to factorial with 4.
360 # Buggy versions of gdb will stop instead at the innermost frame on
361 # the line where we are trying to "next" to.
367 -re "return .value.;.*$prompt $" {
368 # Note that the correct behavior is for GDB to *not* print the
370 pass "next over recursive call"
373 fail "next over recursive call" ; return
375 timeout { fail "next over recursive call (timeout)" ; return }
378 # OK, we should be back in the same stack frame we started from.
379 # Do a backtrace just to confirm.
381 set result [gdb_test "backtrace" \
382 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
383 "backtrace from factorial(5)"]
384 if $result!=0 then { return }
386 # Continue until we exit. Should not stop again.
387 gdb_test "continue" "Continuing.\r\n720\r\n\r\nProgram exited normally\\."\
388 "continue until exit in recursive next test"
392 test_next_with_recursion
394 # Reset the default arguments for VxWorks
395 if [istarget "*-*-vxworks"] then {
397 send "set args main\n"
398 expect -re ".*$prompt $" {}