1 # Copyright (C) 1988, 1990, 1991, 1992, 1994, 1997 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 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
42 gdb_reinitialize_dir $srcdir/$subdir
45 if [target_info exists gdb_stub] {
49 # test simple breakpoint setting commands
52 # Test deleting all breakpoints when there are none installed.
53 # Between 4.15 and 4.16 a change made gdb stop prompting when
54 # there are no user breakpoints installed.
55 # Note that gdb-init.exp provides a "delete_breakpoints" proc
56 # for general use elsewhere.
58 send_gdb "delete breakpoints\n"
60 -re "Delete all breakpoints.*$" {
64 setup_xfail "i*86-*-sysv4*" "sparc-sun-sunos4*" "alpha-dec-osf*" "mips-dec-ultrix*"
65 fail "Delete all breakpoints when none (unexpected prompt)"
67 timeout { fail "Delete all breakpoints when none (timeout after unexpected prompt)" }
70 -re ".*$gdb_prompt $" { pass "Delete all breakpoints when none" }
71 timeout { fail "Delete all breakpoints when none (timeout)" }
75 # test break at function
77 gdb_test "break main" \
78 "Breakpoint.*at.* file .*$srcfile, line.*" \
82 # test break at function in file
84 gdb_test "break $srcfile:factorial" \
85 "Breakpoint.*at.* file .*$srcfile, line.*" \
86 "breakpoint function in file"
89 # test break at line number
92 "Breakpoint.*at.* file .*$srcfile, line 64\\." \
93 "breakpoint line number"
96 # test duplicate breakpoint
99 "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line 64\\." \
100 "breakpoint duplicate"
103 # test break at line number in file
105 gdb_test "break $srcfile:70" \
106 "Breakpoint.*at.* file .*$srcfile, line 70\\." \
107 "breakpoint line number in file"
111 # check to see what breakpoints are set
113 if [target_info exists gdb_stub] {
119 gdb_test "info break" \
120 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
121 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$main_line.*
122 \[0-9\]+\[\t \]+breakpoint keep y.* in factorial at .*$srcfile:76.*
123 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:64.*
124 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:64.*
125 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:70" \
129 # FIXME: The rest of this test doesn't work with anything that can't
131 # Huh? There doesn't *appear* to be anything that passes arguments
133 if [istarget "mips-idt-*"] then {
138 # run until the breakpoint at main is hit. For non-stubs-using targets.
140 if ![target_info exists use_gdb_stub] {
141 if [istarget "*-*-vxworks*"] then {
142 send_gdb "run vxmain \"2\"\n"
144 verbose "Timeout is now $timeout seconds" 2
149 -re "The program .* has been started already.*y or n. $" {
153 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:60.*60\[\t \]+if .argc.* \{.*$gdb_prompt $"\
154 { pass "run until function breakpoint" }
155 -re ".*$gdb_prompt $" { fail "run until function breakpoint" }
156 timeout { fail "run until function breakpoint (timeout)" }
159 if ![target_info exists gdb_stub] {
160 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:60.*60\[\t \]+if .argc.*\{" "stub continue"
165 # run until the breakpoint at a line number
167 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:64.*64\[\t \]+printf.*factorial.*" \
168 "run until breakpoint set at a line number"
171 # Run until the breakpoint set in a function in a file
173 for {set i 6} {$i >= 1} {incr i -1} {
174 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:76.*76\[\t \]+if .value > 1. \{" \
175 "run until file:function($i) breakpoint"
179 # run until the file:function breakpoint at a line number in a file
181 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:70.*70\[\t \]+return 0;" \
182 "run until file:linenum breakpoint"
185 # delete all breakpoints so we can start over, course this can be a test too
190 # test temporary breakpoint at function
193 gdb_test "tbreak main" "Breakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function"
196 # test break at function in file
199 gdb_test "tbreak $srcfile:factorial" "Breakpoint.*at.* file .*$srcfile, line.*" \
200 "Temporary breakpoint function in file"
203 # test break at line number
205 send_gdb "tbreak 64\n"
207 -re "Breakpoint.*at.* file .*$srcfile, line 64.*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
208 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
209 timeout { fail "breakpoint line number #1 (timeout)" }
212 gdb_test "tbreak 60" "Breakpoint.*at.* file .*$srcfile, line 60.*" "Temporary breakpoint line number #2"
215 # test break at line number in file
217 send_gdb "tbreak $srcfile:70\n"
219 -re "Breakpoint.*at.* file .*$srcfile, line 70.*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
220 -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
221 timeout { fail "Temporary breakpoint line number in file #1 (timeout)" }
224 gdb_test "tbreak $srcfile:66" "Breakpoint.*at.* file .*$srcfile, line 66.*" "Temporary breakpoint line number in file #2"
227 # check to see what breakpoints are set (temporary this time)
229 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"
231 proc test_clear_command {} {
232 gdb_test "break main" "Breakpoint.*at.*" "break main #1"
233 gdb_test "break main" "Breakpoint.*at.*" "break main #2"
235 # We don't test that it deletes the correct breakpoints. We do at
236 # least test that it deletes more than one breakpoint.
237 gdb_test "clear main" {Deleted breakpoints [0-9]+ [0-9]+.*}
241 # Test "next" over recursive function call.
244 proc test_next_with_recursion {} {
249 if [istarget "d10v-*-*"] {
250 # Doesn't work right now.
253 if [target_info exists use_gdb_stub] {
254 # Reload the program.
258 # FIXME: should be using runto
259 gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y"
264 gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
266 # Run until we call factorial with 6
268 if [istarget "*-*-vxworks*"] then {
269 send_gdb "run vxmain \"6\"\n"
274 -re "Break.* factorial .value=6. .*$gdb_prompt $" {}
275 -re ".*$gdb_prompt $" {
276 fail "run to factorial(6)";
279 timeout { fail "run to factorial(6) (timeout)" ; gdb_suppress_tests }
282 # Continue until we call factorial recursively with 5.
284 send_gdb "continue\n"
286 -re "Continuing.*Break.* factorial .value=5. .*$gdb_prompt $" {}
287 timeout { fail "continue to factorial(5) (timeout)" ; gdb_suppress_tests }
290 # Do a backtrace just to confirm how many levels deep we are.
292 set result [gdb_test "backtrace" \
293 "#0\[ \t\]+ factorial .value=5..*" \
294 "backtrace from factorial(5)"]
295 if $result!=0 then { gdb_suppress_tests }
297 # Now a "next" should position us at the recursive call, which
298 # we will be performing with 4.
302 -re ".* factorial .value - 1.;.*$gdb_prompt $" {}
303 timeout { fail "next to recursive call (timeout)" ; gdb_suppress_tests }
306 # Disable the breakpoint at the entry to factorial by deleting them all.
307 # The "next" should run until we return to the next line from this
308 # recursive call to factorial with 4.
309 # Buggy versions of gdb will stop instead at the innermost frame on
310 # the line where we are trying to "next" to.
314 if [istarget "mips*tx39-*"] {
320 gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
321 "next over recursive call"
323 # OK, we should be back in the same stack frame we started from.
324 # Do a backtrace just to confirm.
326 set result [gdb_test "backtrace" \
327 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
328 "backtrace from factorial(5.1)"]
329 if { $result != 0 } { gdb_suppress_tests }
331 if [target_info exists gdb,noresults] { gdb_suppress_tests }
332 if [target_info exists use_gdb_stub] {
333 gdb_breakpoint "exit"
334 gdb_test "continue" "Continuing..*Breakpoint .*exit \[(\].*=0\[)\].*" "continue until exit in recursive next test"
336 # Continue until we exit. Should not stop again.
337 # Don't bother to check the output of the program, that may be
338 # extremely tough for some remote systems.
340 "Continuing.\[\r\n0-9\]+Program exited normally\\..*"\
341 "continue until exit in recursive next test"
343 gdb_stop_suppressing_tests;
347 test_next_with_recursion
349 # Reset the default arguments for VxWorks
350 if [istarget "*-*-vxworks*"] {
352 verbose "Timeout is now $timeout seconds" 2
353 send_gdb "set args main\n"
354 gdb_expect -re ".*$gdb_prompt $" {}