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 64\\." \
92 "breakpoint line number"
95 # test duplicate breakpoint
98 "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line 64\\." \
99 "breakpoint duplicate"
102 # test break at line number in file
104 gdb_test "break $srcfile:70" \
105 "Breakpoint.*at.* file .*$srcfile, line 70\\." \
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:60.*
115 \[0-9\]+\[\t \]+breakpoint keep y.* in factorial at .*$srcfile:76.*
116 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:64.*
117 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:64.*
118 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:70" \
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. For non-stubs-using targets.
132 if [istarget "*-*-vxworks*"] then {
133 send "run vxmain \"2\"\n"
139 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:60.*60\[\t \]+if .argc.* \{.*$prompt $"\
140 { pass "run until function breakpoint" }
141 -re ".*$prompt $" { fail "run until function breakpoint" }
142 timeout { fail "(timeout) run until function breakpoint" }
147 gdb_test $cmd "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:56.*56\[\t \]+if .argc.*" \
148 "run until function breakpoint"
152 # run until the breakpoint at a line number
154 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:64.*64\[\t \]+printf.*factorial.*" \
155 "run until breakpoint set at a line number"
158 # Run until the breakpoint set in a function in a file
160 for {set i 6} {$i >= 1} {incr i -1} {
161 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:76.*76\[\t \]+if .value > 1. \{" \
162 "run until file:function($i) breakpoint"
166 # run until the file:function breakpoint at a line number in a file
168 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:70.*70\[\t \]+return 0;" \
169 "run until file:linenum breakpoint"
172 # delete all breakpoints so we can start over, course this can be a test too
174 send "delete breakpoints\n"
176 -re "Delete all breakpoints.*y or n.*$" {
180 send "info breakpoints\n"
182 -re "No breakpoints or watchpoints..*$prompt $" {
183 pass "Deleted all breakpoints"
185 -re ".*$prompt $" { fail "Deleted all breakpoints" }
186 timeout { fail "Deleted all breakpoints" }
189 timeout { fail "Deleted all breakpoints" }
192 -re ".*$prompt $" { fail "Deleted all breakpoints" }
193 timeout { fail "Deleted all breakpoints" }
198 # test temporary breakpoint at function
201 gdb_test "tbreak main" "Breakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function"
204 # test break at function in file
207 gdb_test "tbreak $srcfile:factorial" "Breakpoint.*at.* file .*$srcfile, line.*" \
208 "Temporary breakpoint function in file"
211 # test break at line number
215 -re "Breakpoint.*at.* file .*$srcfile, line 64.*$prompt $" { pass "Temporary breakpoint line number" }
216 -re ".*$prompt $" { pass "Temporary breakpoint line number" }
217 timeout { fail "(timeout) breakpoint line number" }
220 gdb_test "tbreak 60" "Breakpoint.*at.* file .*$srcfile, line 60.*" "Temporary breakpoint line number"
223 # test break at line number in file
225 send "tbreak $srcfile:70\n"
227 -re "Breakpoint.*at.* file .*$srcfile, line 70.*$prompt $" { pass "Temporary breakpoint line number in file" }
228 -re ".*$prompt $" { pass "Temporary breakpoint line number in file" }
229 timeout { fail "(timeout) breakpoint line number in file" }
232 gdb_test "tbreak $srcfile:66" "Breakpoint.*at.* file .*$srcfile, line 66.*" "Temporary breakpoint line number in file"
235 # check to see what breakpoints are set (temporary this time)
239 -re "Num Type.*Disp Enb Address.*What.*
240 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:60.*
241 \[0-9\]+\[\t \]+breakpoint del.*y.*in factorial at .*$srcfile:76.*
242 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:64.*
243 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:70.*$prompt $" {
244 pass "Temporary breakpoint info"
246 -re ".*$prompt $" { fail "Temporary breakpoint info" }
247 timeout { fail "(timeout) Temporary breakpoint info" }
250 proc test_clear_command {} {
251 gdb_test "break main" "Breakpoint.*at.*"
252 gdb_test "break main" "Breakpoint.*at.*"
254 # We don't test that it deletes the correct breakpoints. We do at
255 # least test that it deletes more than one breakpoint.
256 gdb_test "clear main" {Deleted breakpoints [0-9]+ [0-9]+.*}
260 # Test "next" over recursive function call.
263 proc test_next_with_recursion {} {
267 # FIXME: should be using runto
270 -re ".*Kill the program being debugged.*y or n. $" {
275 timeout { fail "killing inferior" ; return }
280 gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
282 # Run until we call factorial with 6
284 if [istarget "*-*-vxworks*"] then {
285 send "run vxmain \"6\"\n"
290 -re "Starting .*Break.* factorial .value=6. .*$prompt $" {}
291 timeout { fail "run to factorial(6)" ; return }
294 # Continue until we call factorial recursively with 5.
298 -re "Continuing.*Break.* factorial .value=5. .*$prompt $" {}
299 timeout { fail "continue to factorial(5)" ; return }
302 # Do a backtrace just to confirm how many levels deep we are.
304 set result [gdb_test "backtrace" \
305 "#0\[ \t\]+ factorial .value=5..*" \
306 "backtrace from factorial(5)"]
307 if $result!=0 then { return }
309 # Now a "next" should position us at the recursive call, which
310 # we will be performing with 4.
314 -re ".* factorial .value - 1.;.*$prompt $" {}
315 timeout { fail "next to recursive call (timeout)" ; return }
318 # Disable the breakpoint at the entry to factorial by deleting them all.
319 # The "next" should run until we return to the next line from this
320 # recursive call to factorial with 4.
321 # Buggy versions of gdb will stop instead at the innermost frame on
322 # the line where we are trying to "next" to.
326 gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
327 "next over recursive call"
329 # OK, we should be back in the same stack frame we started from.
330 # Do a backtrace just to confirm.
332 set result [gdb_test "backtrace" \
333 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
334 "backtrace from factorial(5)"]
335 if $result!=0 then { return }
337 # Continue until we exit. Should not stop again.
338 gdb_test "continue" "Continuing.\r\n720\r\n\r\nProgram exited normally\\."\
339 "continue until exit in recursive next test"
343 test_next_with_recursion
345 # Reset the default arguments for VxWorks
346 if [istarget "*-*-vxworks*"] then {
348 send "set args main\n"
349 expect -re ".*$prompt $" {}