* lib/gdb.exp (gdb_test): Between $pattern and $prompt, expect
[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 60" \
91 "Breakpoint.*at.* file .*$srcfile, line 60\\." \
92 "breakpoint line number"
93
94 #
95 # test duplicate breakpoint
96 #
97 gdb_test "break 60" \
98 "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line 60\\." \
99 "breakpoint duplicate"
100
101 #
102 # test break at line number in file
103 #
104 gdb_test "break $srcfile:66" \
105 "Breakpoint.*at.* file .*$srcfile, line 66\\." \
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: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" \
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
130 #
131 if [istarget "*-*-vxworks"] then {
132 send "run vxmain \"2\"\n"
133 set timeout 120
134 } else {
135 send "run 2\n"
136 }
137 expect {
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" }
142 }
143
144
145 #
146 # run until the breakpoint at a line number
147 #
148 send "continue\n"
149 expect {
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" }
154 }
155
156
157 #
158 # Run until the breakpoint set in a function in a file
159 #
160 send "continue\n"
161 expect {
162 -re "continue.*Continuing..*Breakpoint \[0-9\]+, factorial .value=2. at .*$srcfile:72.*72\[\t ]+if .value > 1. \{.*$prompt $"\
163 { send "continue\n"
164 expect {
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" }
168 }
169 }
170 -re ".*$prompt $" { fail "run until file:function breakpoint" }
171 timeout { fail "(timeout) run until file:function breakpoint" }
172 }
173
174
175 #
176 # run until the file:function breakpoint at a line number in a file
177 #
178 send "continue\n"
179 expect {
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" }
183 }
184
185
186 #
187 # delete all breakpoints so we can start over, course this can be a test too
188 #
189 send "delete breakpoints\n"
190 expect {
191 -re "Delete all breakpoints.*y or n.*$" {
192 send "y\n"
193 expect {
194 -re ".*$prompt $" {
195 send "info breakpoints\n"
196 expect {
197 -re "No breakpoints or watchpoints..*$prompt $" {
198 pass "Deleted all breakpoints"
199 }
200 -re ".*$prompt $" { fail "Deleted all breakpoints" }
201 timeout { fail "Deleted all breakpoints" }
202 }
203 }
204 timeout { fail "Deleted all breakpoints" }
205 }
206 }
207 -re ".*$prompt $" { fail "Deleted all breakpoints" }
208 timeout { fail "Deleted all breakpoints" }
209 }
210
211
212 #
213 # test temporary breakpoint at function
214 #
215 send "tbreak main\n"
216 expect {
217 -re "Breakpoint.*at.* file .*$srcfile, line.*$prompt $" {
218 pass "Temporary breakpoint function"
219 }
220 -re ".*$prompt $" {
221 pass "Temporary breakpoint function"
222 }
223 timeout {
224 fail "(timeout) breakpoint function"
225 }
226 }
227
228
229 #
230 # test break at function in file
231 #
232 send "tbreak $srcfile:factorial\n"
233 expect {
234 -re "Breakpoint.*at.* file .*$srcfile, line.*$prompt $" {
235 pass "Temporary breakpoint function in file"
236 }
237 -re ".*$prompt $" {
238 pass "Temporary breakpoint function in file"
239 }
240 timeout {
241 fail "(timeout) breakpoint function in file"
242 }
243 }
244
245
246 #
247 # test break at line number
248 #
249 send "tbreak 60\n"
250 expect {
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" }
254 }
255
256
257 #
258 # test break at line number in file
259 #
260 send "tbreak $srcfile:66\n"
261 expect {
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" }
265 }
266
267
268 #
269 # check to see what breakpoints are set (temporary this time)
270 #
271 send "info break\n"
272 expect {
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"
279 }
280 -re ".*$prompt $" { fail "Temporary breakpoint info" }
281 timeout { fail "(timeout) Temporary breakpoint info" }
282 }
283
284
285 proc test_clear_command {} {
286 gdb_test "break main" "Breakpoint.*at.*"
287 gdb_test "break main" "Breakpoint.*at.*"
288
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]+.*}
292 }
293
294 #
295 # Test "next" over recursive function call.
296 #
297
298 proc test_next_with_recursion {} {
299 global prompt
300 global decimal
301
302 # FIXME: should be using runto
303 send "kill\n"
304 expect {
305 -re ".*Kill the program being debugged.*y or n. $" {
306 send "y\n"
307 exp_continue
308 }
309 -re ".*$prompt $" {}
310 timeout { fail "killing inferior" ; return }
311 }
312
313 delete_breakpoints
314
315 send "break factorial\n"
316 expect {
317 -re "Breakpoint $decimal at .*$prompt" {}
318 timeout { fail "break at factorial" ; return }
319 }
320
321 # Run until we call factorial with 6
322
323 if [istarget "*-*-vxworks"] then {
324 send "run vxmain \"6\"\n"
325 } else {
326 send "run 6\n"
327 }
328 expect {
329 -re "Starting .*Break.* factorial .value=6. .*$prompt $" {}
330 timeout { fail "run to factorial(6)" ; return }
331 }
332
333 # Continue until we call factorial recursively with 5.
334
335 send "continue\n"
336 expect {
337 -re "Continuing.*Break.* factorial .value=5. .*$prompt $" {}
338 timeout { fail "continue to factorial(5)" ; return }
339 }
340
341 # Do a backtrace just to confirm how many levels deep we are.
342
343 set result [gdb_test "backtrace" \
344 "#0\[ \t\]+ factorial .value=5..*" \
345 "backtrace from factorial(5)"]
346 if $result!=0 then { return }
347
348 # Now a "next" should position us at the recursive call, which
349 # we will be performing with 4.
350
351 send "next\n"
352 expect {
353 -re ".* factorial .value - 1.;.*$prompt $" {}
354 timeout { fail "next to recursive call (timeout)" ; return }
355 }
356
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.
362
363 delete_breakpoints
364
365 send "next\n"
366 expect {
367 -re "return .value.;.*$prompt $" {
368 # Note that the correct behavior is for GDB to *not* print the
369 # frame.
370 pass "next over recursive call"
371 }
372 -re ".*$prompt $" {
373 fail "next over recursive call" ; return
374 }
375 timeout { fail "next over recursive call (timeout)" ; return }
376 }
377
378 # OK, we should be back in the same stack frame we started from.
379 # Do a backtrace just to confirm.
380
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 }
385
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"
389 }
390
391 test_clear_command
392 test_next_with_recursion
393
394 # Reset the default arguments for VxWorks
395 if [istarget "*-*-vxworks"] then {
396 set timeout 10
397 send "set args main\n"
398 expect -re ".*$prompt $" {}
399 }