* gdb.base/help.exp: Replace most of docstring for "define" with ".*".
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / break.exp
1 # Copyright (C) 1988, 1990, 1991, 1992 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 send "break main\n"
77 expect {
78 -re "Breakpoint.*at.* file .*$srcfile, line.*$prompt $" { pass "breakpoint function" }
79 -re ".*$prompt $" { fail "breakpoint function" }
80 timeout { fail "(timeout) breakpoint function" }
81 }
82
83
84 #
85 # test break at function in file
86 #
87 send "break $srcfile:factorial\n"
88 expect {
89 -re "Breakpoint.*at.* file .*$srcfile, line.*$prompt $" { pass "breakpoint function in file" }
90 -re ".*$prompt $" { fail "breakpoint function in file" }
91 timeout { fail "(timeout) breakpoint function in file" }
92 }
93
94
95 #
96 # test break at line number
97 #
98 send "break 60\n"
99 expect {
100 -re "Breakpoint.*at.* file .*$srcfile, line 60.*$prompt $" { pass "breakpoint line number" }
101 -re ".*$prompt $" { fail "breakpoint line number" }
102 timeout { fail "(timeout) breakpoint line number" }
103 }
104
105
106 #
107 # test duplicate breakpoint
108 #
109 send "break 60\n"
110 expect {
111 -re "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line 60.*$prompt $"\
112 { pass "breakpoint duplicate" }
113 -re ".*$prompt $" { fail "breakpoint duplicate" }
114 timeout { fail "(timeout) breakpoint duplicate" }
115 }
116
117
118 #
119 # test break at line number in file
120 #
121 send "break $srcfile:66\n"
122 expect {
123 -re "Breakpoint.*at.* file .*$srcfile, line 66.*$prompt $" { pass "breakpoint line number in file" }
124 -re ".*$prompt $" { fail "breakpoint line number in file" }
125 timeout { fail "(timeout) breakpoint line number in file" }
126 }
127
128
129 #
130 # check to see what breakpoints are set
131 #
132 send "info break\n"
133 expect {
134 -re "Num Type\[ \]+Disp Enb Address\[ \]+What.*
135 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:56.*
136 \[0-9\]+\[\t \]+breakpoint keep y.* in factorial at .*$srcfile:72.*
137 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:60.*
138 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:60.*
139 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:66.*$prompt $" { pass "breakpoint info" }
140 -re ".*$prompt $" { fail "breakpoint info" }
141 timeout { fail "(timeout) breakpoint info" }
142 }
143
144
145 # FIXME: The rest of this test doesn't work with anything that can't
146 # handle arguments.
147 if [istarget "mips-idt-*"] then {
148 return
149 }
150
151 #
152 # run until the breakpoint at main is hit
153 #
154 if [istarget "*-*-vxworks"] then {
155 send "run vxmain \"2\"\n"
156 set timeout 120
157 } else {
158 send "run 2\n"
159 }
160 expect {
161 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:56.*56\[\t \]+if .argc.* \{.*$prompt $"\
162 { pass "run until function breakpoint" }
163 -re ".*$prompt $" { fail "run until function breakpoint" }
164 timeout { fail "(timeout) run until function breakpoint" }
165 }
166
167
168 #
169 # run until the breakpoint at a line number
170 #
171 send "continue\n"
172 expect {
173 -re "continue.*Continuing..*Breakpoint \[0-9\]+, main .argc.*argv.* at .*$srcfile:60.*
174 60\[\t ]+printf.*factorial.*$prompt $" { pass "run until breakpoint set at a line number" }
175 -re ".*$prompt $" { fail "run until breakpoint set at a line number" }
176 timeout { fail "(timeout) run until breakpoint set at a line number" }
177 }
178
179
180 #
181 # Run until the breakpoint set in a function in a file
182 #
183 send "continue\n"
184 expect {
185 -re "continue.*Continuing..*Breakpoint \[0-9\]+, factorial .value=2. at .*$srcfile:72.*72\[\t ]+if .value > 1. \{.*$prompt $"\
186 { send "continue\n"
187 expect {
188 -re "continue.*Continuing..*Breakpoint \[0-9\]+, factorial .value=1. at .*$srcfile:72.*72\[\t ]+if .value > 1.*$prompt $" { pass "run until file:function breakpoint" }
189 -re ".*$prompt $" { fail "run until file:function breakpoint" }
190 timeout { fail "(timeout) run until file:function breakpoint" }
191 }
192 }
193 -re ".*$prompt $" { fail "run until file:function breakpoint" }
194 timeout { fail "(timeout) run until file:function breakpoint" }
195 }
196
197
198 #
199 # run until the file:function breakpoint at a line number in a file
200 #
201 send "continue\n"
202 expect {
203 -re "continue.*Continuing..*Breakpoint \[0-9\]+, main .*argc.*argv.* at .*$srcfile:66.*66\[\t ]+return 0;.*$prompt $" { pass "run until file:linenum breakpoint" }
204 -re ".*$prompt $" { fail "run until file:linenum breakpoint" }
205 timeout { fail "(timeout) run until file:linenum breakpoint" }
206 }
207
208
209 #
210 # delete all breakpoints so we can start over, course this can be a test too
211 #
212 send "delete breakpoints\n"
213 expect {
214 -re "Delete all breakpoints.*y or n.*$" {
215 send "y\n"
216 expect {
217 -re ".*$prompt $" {
218 send "info breakpoints\n"
219 expect {
220 -re "No breakpoints or watchpoints..*$prompt $" {
221 pass "Deleted all breakpoints"
222 }
223 -re ".*$prompt $" { fail "Deleted all breakpoints" }
224 timeout { fail "Deleted all breakpoints" }
225 }
226 }
227 timeout { fail "Deleted all breakpoints" }
228 }
229 }
230 -re ".*$prompt $" { fail "Deleted all breakpoints" }
231 timeout { fail "Deleted all breakpoints" }
232 }
233
234
235 #
236 # test temporary breakpoint at function
237 #
238 send "tbreak main\n"
239 expect {
240 -re "Breakpoint.*at.* file .*$srcfile, line.*$prompt $" {
241 pass "Temporary breakpoint function"
242 }
243 -re ".*$prompt $" {
244 pass "Temporary breakpoint function"
245 }
246 timeout {
247 fail "(timeout) breakpoint function"
248 }
249 }
250
251
252 #
253 # test break at function in file
254 #
255 send "tbreak $srcfile:factorial\n"
256 expect {
257 -re "Breakpoint.*at.* file .*$srcfile, line.*$prompt $" {
258 pass "Temporary breakpoint function in file"
259 }
260 -re ".*$prompt $" {
261 pass "Temporary breakpoint function in file"
262 }
263 timeout {
264 fail "(timeout) breakpoint function in file"
265 }
266 }
267
268
269 #
270 # test break at line number
271 #
272 send "tbreak 60\n"
273 expect {
274 -re "Breakpoint.*at.* file .*$srcfile, line 60.*$prompt $" { pass "Temporary breakpoint line number" }
275 -re ".*$prompt $" { pass "Temporary breakpoint line number" }
276 timeout { fail "(timeout) breakpoint line number" }
277 }
278
279
280 #
281 # test break at line number in file
282 #
283 send "tbreak $srcfile:66\n"
284 expect {
285 -re "Breakpoint.*at.* file .*$srcfile, line 66.*$prompt $" { pass "Temporary breakpoint line number in file" }
286 -re ".*$prompt $" { pass "Temporary breakpoint line number in file" }
287 timeout { fail "(timeout) breakpoint line number in file" }
288 }
289
290
291 #
292 # check to see what breakpoints are set (temporary this time)
293 #
294 send "info break\n"
295 expect {
296 -re "Num Type.*Disp Enb Address.*What.*
297 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:56.*
298 \[0-9\]+\[\t \]+breakpoint del.*y.*in factorial at .*$srcfile:72.*
299 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:60.*
300 \[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:66.*$prompt $" {
301 pass "Temporary breakpoint info"
302 }
303 -re ".*$prompt $" { fail "Temporary breakpoint info" }
304 timeout { fail "(timeout) Temporary breakpoint info" }
305 }
306
307
308 proc test_clear_command {} {
309 gdb_test "break main" "Breakpoint.*at"
310 gdb_test "break main" "Breakpoint.*at"
311
312 # We don't test that it deletes the correct breakpoints. We do at
313 # least test that it deletes more than one breakpoint.
314 gdb_test "clear main" {Deleted breakpoints [0-9]+ [0-9]+}
315 }
316
317 #
318 # Test "next" over recursive function call.
319 #
320
321 proc test_next_with_recursion {} {
322 global prompt
323 global decimal
324
325 # FIXME: should be using runto
326 send "kill\n"
327 expect {
328 -re ".*Kill the program being debugged.*y or n. $" {
329 send "y\n"
330 exp_continue
331 }
332 -re ".*$prompt $" {}
333 timeout { fail "killing inferior" ; return }
334 }
335
336 delete_breakpoints
337
338 send "break factorial\n"
339 expect {
340 -re "Breakpoint $decimal at .*$prompt" {}
341 timeout { fail "break at factorial" ; return }
342 }
343
344 # Run until we call factorial with 6
345
346 if [istarget "*-*-vxworks"] then {
347 send "run vxmain \"6\"\n"
348 } else {
349 send "run 6\n"
350 }
351 expect {
352 -re "Starting .*Break.* factorial .value=6. .*$prompt $" {}
353 timeout { fail "run to factorial(6)" ; return }
354 }
355
356 # Continue until we call factorial recursively with 5.
357
358 send "continue\n"
359 expect {
360 -re "Continuing.*Break.* factorial .value=5. .*$prompt $" {}
361 timeout { fail "continue to factorial(5)" ; return }
362 }
363
364 # Do a backtrace just to confirm how many levels deep we are.
365
366 set result [gdb_test "backtrace" \
367 "#0\[ \t\]+ factorial .value=5." \
368 "backtrace from factorial(5)"]
369 if $result!=0 then { return }
370
371 # Now a "next" should position us at the recursive call, which
372 # we will be performing with 4.
373
374 send "next\n"
375 expect {
376 -re ".* factorial .value - 1.;.*$prompt $" {}
377 timeout { fail "next to recursive call (timeout)" ; return }
378 }
379
380 # Disable the breakpoint at the entry to factorial by deleting them all.
381 # The "next" should run until we return to the next line from this
382 # recursive call to factorial with 4.
383 # Buggy versions of gdb will stop instead at the innermost frame on
384 # the line where we are trying to "next" to.
385
386 delete_breakpoints
387
388 send "next\n"
389 expect {
390 -re "return .value.;.*$prompt $" {
391 # Note that the correct behavior is for GDB to *not* print the
392 # frame.
393 pass "next over recursive call"
394 }
395 -re ".*$prompt $" {
396 fail "next over recursive call" ; return
397 }
398 timeout { fail "next over recursive call (timeout)" ; return }
399 }
400
401 # OK, we should be back in the same stack frame we started from.
402 # Do a backtrace just to confirm.
403
404 set result [gdb_test "backtrace" \
405 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6." \
406 "backtrace from factorial(5)"]
407 if $result!=0 then { return }
408
409 # Continue until we exit. Should not stop again.
410 gdb_test "continue" "Continuing.\r\n720"\
411 "continue until exit in recursive next test"
412 }
413
414 test_clear_command
415 test_next_with_recursion
416
417 # Reset the default arguments for VxWorks
418 if [istarget "*-*-vxworks"] then {
419 set timeout 10
420 send "set args main\n"
421 expect -re ".*$prompt $" {}
422 }
423
424 if [istarget "a29k-*-udi"] then {
425 # FIXME: If PR 2415 is fixed, this is not needed.
426 gdb_target_udi
427 }
This page took 0.03869 seconds and 4 git commands to generate.