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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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)
28 # test running programs
34 set srcfile ${testfile}.c
35 set binfile ${objdir}/${subdir}/${testfile}
36 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-w}] != "" } {
37 perror "Couldn't compile ${srcfile}"
43 gdb_reinitialize_dir $srcdir/$subdir
46 if [target_info exists gdb_stub] {
47 gdb_test "step" "(main.* at .*|.*in .*start.*)" "step for stub"
50 # test simple breakpoint setting commands
53 # Test deleting all breakpoints when there are none installed.
54 # Between 4.15 and 4.16 a change made gdb stop prompting when
55 # there are no user breakpoints installed.
56 # Note that gdb-init.exp provides a "delete_breakpoints" proc
57 # for general use elsewhere.
59 send_gdb "delete breakpoints\n"
61 -i $gdb_spawn_id -re "Delete all breakpoints.*$" {
65 setup_xfail "i*86-*-sysv4*" "sparc-sun-sunos4*" "alpha-dec-osf*" "mips-dec-ultrix*"
66 fail "Delete all breakpoints when none (unexpected prompt)"
68 timeout { fail "Delete all breakpoints when none (timeout after unexpected prompt)" }
71 -i $gdb_spawn_id -re ".*$gdb_prompt $" { pass "Delete all breakpoints when none" }
72 timeout { fail "Delete all breakpoints when none (timeout)" }
76 # test break at function
78 gdb_test "break main" \
79 "Breakpoint.*at.* file .*$srcfile, line.*" \
83 # test break at function in file
85 gdb_test "break $srcfile:factorial" \
86 "Breakpoint.*at.* file .*$srcfile, line.*" \
87 "breakpoint function in file"
90 # test break at line number
93 "Breakpoint.*at.* file .*$srcfile, line 64\\." \
94 "breakpoint line number"
97 # test duplicate breakpoint
100 "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line 64\\." \
101 "breakpoint duplicate"
104 # test break at line number in file
106 gdb_test "break $srcfile:70" \
107 "Breakpoint.*at.* file .*$srcfile, line 70\\." \
108 "breakpoint line number in file"
112 # check to see what breakpoints are set
114 if [target_info exists gdb_stub] {
120 gdb_test "info break" \
121 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
122 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$main_line.*
123 \[0-9\]+\[\t \]+breakpoint keep y.* in factorial at .*$srcfile:76.*
124 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:64.*
125 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:64.*
126 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:70" \
130 # FIXME: The rest of this test doesn't work with anything that can't
132 # Huh? There doesn't *appear* to be anything that passes arguments
134 if [istarget "mips-idt-*"] then {
139 # run until the breakpoint at main is hit. For non-stubs-using targets.
141 if ![target_info exists use_gdb_stub] {
142 if [istarget "*-*-vxworks*"] then {
143 send_gdb "run vxmain \"2\"\n"
145 verbose "Timeout is now $timeout seconds" 2
150 -re "The program .* has been started already.*y or n. $" {
154 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:60.*60\[\t \]+if .argc.* \{.*$gdb_prompt $"\
155 { pass "run until function breakpoint" }
156 -re ".*$gdb_prompt $" { fail "run until function breakpoint" }
157 timeout { fail "run until function breakpoint (timeout)" }
160 if ![target_info exists gdb_stub] {
161 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:60.*60\[\t \]+if .argc.*\{" "stub continue"
166 # run until the breakpoint at a line number
168 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:64.*64\[\t \]+printf.*factorial.*" \
169 "run until breakpoint set at a line number"
172 # Run until the breakpoint set in a function in a file
174 for {set i 6} {$i >= 1} {incr i -1} {
175 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:76.*76\[\t \]+if .value > 1. \{" \
176 "run until file:function($i) breakpoint"
180 # run until the file:function breakpoint at a line number in a file
182 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:70.*70\[\t \]+return 0;" \
183 "run until file:linenum breakpoint"
186 # delete all breakpoints so we can start over, course this can be a test too
191 # test temporary breakpoint at function
194 gdb_test "tbreak main" "Breakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function"
197 # test break at function in file
200 gdb_test "tbreak $srcfile:factorial" "Breakpoint.*at.* file .*$srcfile, line.*" \
201 "Temporary breakpoint function in file"
204 # test break at line number
206 send_gdb "tbreak 64\n"
208 -re "Breakpoint.*at.* file .*$srcfile, line 64.*$gdb_prompt $" { pass "Temporary breakpoint line number" }
209 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number" }
210 timeout { fail "breakpoint line number (timeout)" }
213 gdb_test "tbreak 60" "Breakpoint.*at.* file .*$srcfile, line 60.*" "Temporary breakpoint line number"
216 # test break at line number in file
218 send_gdb "tbreak $srcfile:70\n"
220 -re "Breakpoint.*at.* file .*$srcfile, line 70.*$gdb_prompt $" { pass "Temporary breakpoint line number in file" }
221 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number in file" }
222 timeout { fail "Temporary breakpoint line number in file (timeout)" }
225 gdb_test "tbreak $srcfile:66" "Breakpoint.*at.* file .*$srcfile, line 66.*" "Temporary breakpoint line number in file"
228 # check to see what breakpoints are set (temporary this time)
230 gdb_test "info break" "Num Type.*Disp Enb Address.*What.*\[\r\n\]\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$main_line.*\[\r\n\]\[0-9\]+\[\t \]+breakpoint del.*y.*in factorial at .*$srcfile:76.*\[\r\n\]\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:64.*\[\r\n\]\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:70.*" "Temporary breakpoint info"
232 proc test_clear_command {} {
233 gdb_test "break main" "Breakpoint.*at.*"
234 gdb_test "break main" "Breakpoint.*at.*"
236 # We don't test that it deletes the correct breakpoints. We do at
237 # least test that it deletes more than one breakpoint.
238 gdb_test "clear main" {Deleted breakpoints [0-9]+ [0-9]+.*}
242 # Test "next" over recursive function call.
245 proc test_next_with_recursion {} {
251 if [istarget "d10v-*-*"] {
252 # Doesn't work right now.
255 if [target_info exists use_gdb_stub] {
256 # Reload the program.
260 # FIXME: should be using runto
261 gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y"
266 gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
268 # Run until we call factorial with 6
270 if [istarget "*-*-vxworks*"] then {
271 send_gdb "run vxmain \"6\"\n"
276 -re "Break.* factorial .value=6. .*$gdb_prompt $" {}
277 timeout { fail "run to factorial(6) (timeout)" ; return }
280 # Continue until we call factorial recursively with 5.
282 send_gdb "continue\n"
284 -re "Continuing.*Break.* factorial .value=5. .*$gdb_prompt $" {}
285 timeout { fail "continue to factorial(5) (timeout)" ; return }
288 # Do a backtrace just to confirm how many levels deep we are.
290 set result [gdb_test "backtrace" \
291 "#0\[ \t\]+ factorial .value=5..*" \
292 "backtrace from factorial(5)"]
293 if $result!=0 then { return }
295 # Now a "next" should position us at the recursive call, which
296 # we will be performing with 4.
300 -re ".* factorial .value - 1.;.*$gdb_prompt $" {}
301 timeout { fail "next to recursive call (timeout)" ; return }
304 # Disable the breakpoint at the entry to factorial by deleting them all.
305 # The "next" should run until we return to the next line from this
306 # recursive call to factorial with 4.
307 # Buggy versions of gdb will stop instead at the innermost frame on
308 # the line where we are trying to "next" to.
314 gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
315 "next over recursive call"
317 # OK, we should be back in the same stack frame we started from.
318 # Do a backtrace just to confirm.
320 set result [gdb_test "backtrace" \
321 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
322 "backtrace from factorial(5.1)"]
323 if { $result != 0 } { return }
325 if { $noresults == 1 } { return }
326 if [target_info exists use_gdb_stub] {
327 gdb_breakpoint "exit"
328 gdb_test "continue" "Continuing..*Breakpoint .*exit .code=0.*" "continue until exit in recursive next test"
330 # Continue until we exit. Should not stop again.
331 # Don't bother to check the output of the program, that may be
332 # extremely tough for some remote systems.
334 "Continuing.\[\r\n0-9\]+Program exited normally\\..*"\
335 "continue until exit in recursive next test"
340 test_next_with_recursion
342 # Reset the default arguments for VxWorks
343 if [istarget "*-*-vxworks*"] {
345 verbose "Timeout is now $timeout seconds" 2
346 send_gdb "set args main\n"
347 expect -re ".*$gdb_prompt $" {}