* gdb.base/break.exp (test_next_with_recursion): Accept any line
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / break.exp
1 # Copyright (C) 1988, 1990, 1991, 1992, 1994 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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. */
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 # This file was written by Rob Savoye. (rob@cygnus.com)
21
22 if $tracelevel then {
23 strace $tracelevel
24 }
25
26 #
27 # test running programs
28 #
29 set prms_id 0
30 set bug_id 0
31
32 set binfile "break"
33 set srcfile $binfile.c
34
35 if ![file exists $objdir/$subdir/$binfile] then {
36 perror "$objdir/$subdir/$binfile does not exist."
37 return 0
38 }
39
40 gdb_exit
41 gdb_start
42 gdb_reinitialize_dir $srcdir/$subdir
43 gdb_load $objdir/$subdir/$binfile
44
45 #
46 # test simple breakpoint setting commands
47 #
48
49 #
50 # test deleting all breakpoints; note that gdb-init.exp provides a
51 # "delete_breakpoints" proc for general use elsewhere
52 #
53 send "delete breakpoints\n"
54 expect {
55 -re "Delete all breakpoints.*y or n. $"\
56 { send "y\n"
57 expect {
58 -re ".*$prompt $"\
59 { send "info breakpoints\n"
60 expect {
61 -re "No breakpoints or watchpoints..*$prompt $" { pass "Deleted all breakpoints" }
62 -re ".*$prompt $" { fail "Deleted all breakpoints" }
63 timeout { fail "Deleted all breakpoints" }
64 }
65 }
66 timeout { fail "Deleted all breakpoints" }
67 }
68 }
69 -re ".*$prompt $" { fail "Deleted all breakpoints" }
70 timeout { fail "Deleted all breakpoints" }
71 }
72
73 #
74 # test break at function
75 #
76 gdb_test "break main" \
77 "Breakpoint.*at.* file .*$srcfile, line.*" \
78 "breakpoint function"
79
80 #
81 # test break at function in file
82 #
83 gdb_test "break $srcfile:factorial" \
84 "Breakpoint.*at.* file .*$srcfile, line.*" \
85 "breakpoint function in file"
86
87 #
88 # test break at line number
89 #
90 gdb_test "break 64" \
91 "Breakpoint.*at.* file .*$srcfile, line 64\\." \
92 "breakpoint line number"
93
94 #
95 # test duplicate breakpoint
96 #
97 gdb_test "break 64" \
98 "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line 64\\." \
99 "breakpoint duplicate"
100
101 #
102 # test break at line number in file
103 #
104 gdb_test "break $srcfile:70" \
105 "Breakpoint.*at.* file .*$srcfile, line 70\\." \
106 "breakpoint line number in file"
107
108
109 #
110 # check to see what breakpoints are set
111 #
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" \
119 "breakpoint info"
120
121
122 # FIXME: The rest of this test doesn't work with anything that can't
123 # handle arguments.
124 if [istarget "mips-idt-*"] then {
125 return
126 }
127
128 #
129 # run until the breakpoint at main is hit. For non-stubs-using targets.
130 #
131 if !$usestubs then {
132 if [istarget "*-*-vxworks*"] then {
133 send "run vxmain \"2\"\n"
134 set timeout 120
135 } else {
136 send "run\n"
137 }
138 expect {
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" }
143 }
144 }
145
146 if $usestubs {
147 gdb_test $cmd "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:56.*56\[\t \]+if .argc.*" \
148 "run until function breakpoint"
149 }
150
151 #
152 # run until the breakpoint at a line number
153 #
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"
156
157 #
158 # Run until the breakpoint set in a function in a file
159 #
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"
163 }
164
165 #
166 # run until the file:function breakpoint at a line number in a file
167 #
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"
170
171 #
172 # delete all breakpoints so we can start over, course this can be a test too
173 #
174 send "delete breakpoints\n"
175 expect {
176 -re "Delete all breakpoints.*y or n.*$" {
177 send "y\n"
178 expect {
179 -re ".*$prompt $" {
180 send "info breakpoints\n"
181 expect {
182 -re "No breakpoints or watchpoints..*$prompt $" {
183 pass "Deleted all breakpoints"
184 }
185 -re ".*$prompt $" { fail "Deleted all breakpoints" }
186 timeout { fail "Deleted all breakpoints" }
187 }
188 }
189 timeout { fail "Deleted all breakpoints" }
190 }
191 }
192 -re ".*$prompt $" { fail "Deleted all breakpoints" }
193 timeout { fail "Deleted all breakpoints" }
194 }
195
196
197 #
198 # test temporary breakpoint at function
199 #
200
201 gdb_test "tbreak main" "Breakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function"
202
203 #
204 # test break at function in file
205 #
206
207 gdb_test "tbreak $srcfile:factorial" "Breakpoint.*at.* file .*$srcfile, line.*" \
208 "Temporary breakpoint function in file"
209
210 #
211 # test break at line number
212 #
213 send "tbreak 64\n"
214 expect {
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" }
218 }
219
220 gdb_test "tbreak 60" "Breakpoint.*at.* file .*$srcfile, line 60.*" "Temporary breakpoint line number"
221
222 #
223 # test break at line number in file
224 #
225 send "tbreak $srcfile:70\n"
226 expect {
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" }
230 }
231
232 gdb_test "tbreak $srcfile:66" "Breakpoint.*at.* file .*$srcfile, line 66.*" "Temporary breakpoint line number in file"
233
234 #
235 # check to see what breakpoints are set (temporary this time)
236 #
237 send "info break\n"
238 expect {
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"
245 }
246 -re ".*$prompt $" { fail "Temporary breakpoint info" }
247 timeout { fail "(timeout) Temporary breakpoint info" }
248 }
249
250 proc test_clear_command {} {
251 gdb_test "break main" "Breakpoint.*at.*"
252 gdb_test "break main" "Breakpoint.*at.*"
253
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]+.*}
257 }
258
259 #
260 # Test "next" over recursive function call.
261 #
262
263 proc test_next_with_recursion {} {
264 global prompt
265 global decimal
266
267 # FIXME: should be using runto
268 send "kill\n"
269 expect {
270 -re ".*Kill the program being debugged.*y or n. $" {
271 send "y\n"
272 exp_continue
273 }
274 -re ".*$prompt $" {}
275 timeout { fail "killing inferior" ; return }
276 }
277
278 delete_breakpoints
279
280 gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
281
282 # Run until we call factorial with 6
283
284 if [istarget "*-*-vxworks*"] then {
285 send "run vxmain \"6\"\n"
286 } else {
287 send "run\n"
288 }
289 expect {
290 -re "Starting .*Break.* factorial .value=6. .*$prompt $" {}
291 timeout { fail "run to factorial(6)" ; return }
292 }
293
294 # Continue until we call factorial recursively with 5.
295
296 send "continue\n"
297 expect {
298 -re "Continuing.*Break.* factorial .value=5. .*$prompt $" {}
299 timeout { fail "continue to factorial(5)" ; return }
300 }
301
302 # Do a backtrace just to confirm how many levels deep we are.
303
304 set result [gdb_test "backtrace" \
305 "#0\[ \t\]+ factorial .value=5..*" \
306 "backtrace from factorial(5)"]
307 if $result!=0 then { return }
308
309 # Now a "next" should position us at the recursive call, which
310 # we will be performing with 4.
311
312 send "next\n"
313 expect {
314 -re ".* factorial .value - 1.;.*$prompt $" {}
315 timeout { fail "next to recursive call (timeout)" ; return }
316 }
317
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.
323
324 delete_breakpoints
325
326 gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
327 "next over recursive call"
328
329 # OK, we should be back in the same stack frame we started from.
330 # Do a backtrace just to confirm.
331
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 }
336
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"
340 }
341
342 test_clear_command
343 test_next_with_recursion
344
345 # Reset the default arguments for VxWorks
346 if [istarget "*-*-vxworks*"] then {
347 set timeout 10
348 send "set args main\n"
349 expect -re ".*$prompt $" {}
350 }
This page took 0.036156 seconds and 4 git commands to generate.