* lib/gdb.exp (CFLAGS): Remove, unreferenced.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / break.exp
CommitLineData
4081daa1 1# Copyright (C) 1988, 1990, 1991, 1992, 1994 Free Software Foundation, Inc.
ef44eed1
SS
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
b998e7b8 15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
ef44eed1
SS
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
22if $tracelevel then {
23 strace $tracelevel
24 }
25
4d1edc2e
KH
26global usestubs
27
ef44eed1
SS
28#
29# test running programs
30#
31set prms_id 0
32set bug_id 0
33
782445c7
FF
34set testfile "break"
35set srcfile ${srcdir}/${subdir}/${testfile}.c
36set binfile ${objdir}/${subdir}/${testfile}
37if { [compile "${srcfile} -g -o ${binfile}"] != "" } {
38 perror "Couldn't compile ${srcfile}"
39 return -1
ef44eed1
SS
40}
41
42gdb_exit
43gdb_start
44gdb_reinitialize_dir $srcdir/$subdir
782445c7 45gdb_load ${binfile}
ef44eed1 46
4d1edc2e
KH
47if $usestubs {
48 send "step\n"
49 # if use stubs step out of the breakpoint() function.
50 expect {
51 -re "main.* at .*$prompt $" {}
52 timeout { fail "single step at breakpoint() (timeout)" ; return 0 }
53 }
54}
ef44eed1
SS
55#
56# test simple breakpoint setting commands
57#
58
b998e7b8
FF
59# Test deleting all breakpoints when there are none installed.
60# Between 4.15 and 4.16 a change made gdb stop prompting when
61# there are no user breakpoints installed.
62# Note that gdb-init.exp provides a "delete_breakpoints" proc
63# for general use elsewhere.
64
ef44eed1
SS
65send "delete breakpoints\n"
66expect {
67 -re "Delete all breakpoints.*y or n. $"\
68 { send "y\n"
69 expect {
536a7a16 70 -re ".*$prompt $" {
782445c7 71 setup_xfail "i*86-*-sysv4*" "sparc-sun-sunos4*" "alpha-dec-osf2*"
536a7a16
FF
72 fail "Delete all breakpoints when none"
73 }
b998e7b8 74 timeout { fail "Delete all breakpoints when none (timeout)" }
ef44eed1
SS
75 }
76 }
b998e7b8
FF
77 -re ".*$prompt $" { pass "Delete all breakpoints when none" }
78 timeout { fail "Delete all breakpoints when none" }
ef44eed1
SS
79}
80
81#
82# test break at function
83#
4081daa1
JK
84gdb_test "break main" \
85 "Breakpoint.*at.* file .*$srcfile, line.*" \
86 "breakpoint function"
ef44eed1
SS
87
88#
89# test break at function in file
90#
4081daa1
JK
91gdb_test "break $srcfile:factorial" \
92 "Breakpoint.*at.* file .*$srcfile, line.*" \
93 "breakpoint function in file"
ef44eed1
SS
94
95#
96# test break at line number
97#
c86bd3d4
KH
98gdb_test "break 64" \
99 "Breakpoint.*at.* file .*$srcfile, line 64\\." \
4081daa1 100 "breakpoint line number"
ef44eed1
SS
101
102#
103# test duplicate breakpoint
104#
c86bd3d4
KH
105gdb_test "break 64" \
106 "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line 64\\." \
4081daa1 107 "breakpoint duplicate"
ef44eed1
SS
108
109#
110# test break at line number in file
111#
c86bd3d4
KH
112gdb_test "break $srcfile:70" \
113 "Breakpoint.*at.* file .*$srcfile, line 70\\." \
4081daa1 114 "breakpoint line number in file"
ef44eed1
SS
115
116
117#
118# check to see what breakpoints are set
119#
b998e7b8
FF
120if $usestubs then {
121 set main_line 57
122} else {
123 set main_line 60
124}
125
4081daa1
JK
126gdb_test "info break" \
127 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
b998e7b8 128\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$main_line.*
c86bd3d4
KH
129\[0-9\]+\[\t \]+breakpoint keep y.* in factorial at .*$srcfile:76.*
130\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:64.*
131\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:64.*
132\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:70" \
4081daa1 133 "breakpoint info"
ef44eed1
SS
134
135
136# FIXME: The rest of this test doesn't work with anything that can't
137# handle arguments.
138if [istarget "mips-idt-*"] then {
139 return
140}
141
142#
c86bd3d4 143# run until the breakpoint at main is hit. For non-stubs-using targets.
ef44eed1 144#
c86bd3d4
KH
145if !$usestubs then {
146 if [istarget "*-*-vxworks*"] then {
ef44eed1
SS
147 send "run vxmain \"2\"\n"
148 set timeout 120
c86bd3d4 149 } else {
e8a256f8 150 send "run\n"
c86bd3d4
KH
151 }
152 expect {
b998e7b8
FF
153 -re "The program .* has been started already.*y or n. $" {
154 send "y\n"
155 exp_continue
156 }
c86bd3d4 157 -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:60.*60\[\t \]+if .argc.* \{.*$prompt $"\
ef44eed1
SS
158 { pass "run until function breakpoint" }
159 -re ".*$prompt $" { fail "run until function breakpoint" }
160 timeout { fail "(timeout) run until function breakpoint" }
c86bd3d4 161 }
ef44eed1
SS
162}
163
ef44eed1
SS
164#
165# run until the breakpoint at a line number
166#
c86bd3d4 167gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:64.*64\[\t \]+printf.*factorial.*" \
e8a256f8 168 "run until breakpoint set at a line number"
ef44eed1
SS
169
170#
171# Run until the breakpoint set in a function in a file
172#
e8a256f8 173for {set i 6} {$i >= 1} {incr i -1} {
c86bd3d4 174 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:76.*76\[\t \]+if .value > 1. \{" \
e8a256f8 175 "run until file:function($i) breakpoint"
ef44eed1
SS
176}
177
ef44eed1
SS
178#
179# run until the file:function breakpoint at a line number in a file
180#
c86bd3d4 181gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:70.*70\[\t \]+return 0;" \
e8a256f8 182 "run until file:linenum breakpoint"
ef44eed1
SS
183
184#
185# delete all breakpoints so we can start over, course this can be a test too
186#
187send "delete breakpoints\n"
188expect {
189 -re "Delete all breakpoints.*y or n.*$" {
190 send "y\n"
191 expect {
192 -re ".*$prompt $" {
193 send "info breakpoints\n"
194 expect {
195 -re "No breakpoints or watchpoints..*$prompt $" {
196 pass "Deleted all breakpoints"
197 }
198 -re ".*$prompt $" { fail "Deleted all breakpoints" }
199 timeout { fail "Deleted all breakpoints" }
200 }
201 }
202 timeout { fail "Deleted all breakpoints" }
203 }
204 }
205 -re ".*$prompt $" { fail "Deleted all breakpoints" }
206 timeout { fail "Deleted all breakpoints" }
207}
208
209
210#
211# test temporary breakpoint at function
212#
ef44eed1 213
1a7f57e7 214gdb_test "tbreak main" "Breakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function"
ef44eed1
SS
215
216#
217# test break at function in file
218#
ef44eed1 219
1a7f57e7
SG
220gdb_test "tbreak $srcfile:factorial" "Breakpoint.*at.* file .*$srcfile, line.*" \
221 "Temporary breakpoint function in file"
ef44eed1
SS
222
223#
224# test break at line number
225#
c86bd3d4 226send "tbreak 64\n"
ef44eed1 227expect {
c86bd3d4 228 -re "Breakpoint.*at.* file .*$srcfile, line 64.*$prompt $" { pass "Temporary breakpoint line number" }
ef44eed1
SS
229 -re ".*$prompt $" { pass "Temporary breakpoint line number" }
230 timeout { fail "(timeout) breakpoint line number" }
231}
232
1a7f57e7 233gdb_test "tbreak 60" "Breakpoint.*at.* file .*$srcfile, line 60.*" "Temporary breakpoint line number"
ef44eed1
SS
234
235#
236# test break at line number in file
237#
c86bd3d4 238send "tbreak $srcfile:70\n"
ef44eed1 239expect {
c86bd3d4 240 -re "Breakpoint.*at.* file .*$srcfile, line 70.*$prompt $" { pass "Temporary breakpoint line number in file" }
ef44eed1
SS
241 -re ".*$prompt $" { pass "Temporary breakpoint line number in file" }
242 timeout { fail "(timeout) breakpoint line number in file" }
243}
244
1a7f57e7 245gdb_test "tbreak $srcfile:66" "Breakpoint.*at.* file .*$srcfile, line 66.*" "Temporary breakpoint line number in file"
ef44eed1
SS
246
247#
248# check to see what breakpoints are set (temporary this time)
249#
250send "info break\n"
251expect {
252 -re "Num Type.*Disp Enb Address.*What.*
b998e7b8 253\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$main_line.*
c86bd3d4
KH
254\[0-9\]+\[\t \]+breakpoint del.*y.*in factorial at .*$srcfile:76.*
255\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:64.*
256\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:70.*$prompt $" {
ef44eed1
SS
257 pass "Temporary breakpoint info"
258 }
259 -re ".*$prompt $" { fail "Temporary breakpoint info" }
260 timeout { fail "(timeout) Temporary breakpoint info" }
261}
262
ef44eed1 263proc test_clear_command {} {
4081daa1
JK
264 gdb_test "break main" "Breakpoint.*at.*"
265 gdb_test "break main" "Breakpoint.*at.*"
ef44eed1
SS
266
267 # We don't test that it deletes the correct breakpoints. We do at
268 # least test that it deletes more than one breakpoint.
4081daa1 269 gdb_test "clear main" {Deleted breakpoints [0-9]+ [0-9]+.*}
ef44eed1
SS
270}
271
272#
273# Test "next" over recursive function call.
274#
275
276proc test_next_with_recursion {} {
277 global prompt
278 global decimal
279
280# FIXME: should be using runto
281 send "kill\n"
282 expect {
283 -re ".*Kill the program being debugged.*y or n. $" {
284 send "y\n"
285 exp_continue
286 }
287 -re ".*$prompt $" {}
288 timeout { fail "killing inferior" ; return }
289 }
290
291 delete_breakpoints
292
1a7f57e7 293 gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
ef44eed1
SS
294
295 # Run until we call factorial with 6
296
e965bc39 297 if [istarget "*-*-vxworks*"] then {
ef44eed1
SS
298 send "run vxmain \"6\"\n"
299 } else {
4d1edc2e 300 gdb_run_cmd
ef44eed1
SS
301 }
302 expect {
4d1edc2e 303 -re "Break.* factorial .value=6. .*$prompt $" {}
ef44eed1
SS
304 timeout { fail "run to factorial(6)" ; return }
305 }
306
307 # Continue until we call factorial recursively with 5.
308
309 send "continue\n"
310 expect {
311 -re "Continuing.*Break.* factorial .value=5. .*$prompt $" {}
312 timeout { fail "continue to factorial(5)" ; return }
313 }
314
315 # Do a backtrace just to confirm how many levels deep we are.
316
317 set result [gdb_test "backtrace" \
4081daa1 318 "#0\[ \t\]+ factorial .value=5..*" \
ef44eed1
SS
319 "backtrace from factorial(5)"]
320 if $result!=0 then { return }
321
322 # Now a "next" should position us at the recursive call, which
323 # we will be performing with 4.
324
325 send "next\n"
326 expect {
327 -re ".* factorial .value - 1.;.*$prompt $" {}
328 timeout { fail "next to recursive call (timeout)" ; return }
329 }
330
331 # Disable the breakpoint at the entry to factorial by deleting them all.
332 # The "next" should run until we return to the next line from this
333 # recursive call to factorial with 4.
334 # Buggy versions of gdb will stop instead at the innermost frame on
335 # the line where we are trying to "next" to.
336
337 delete_breakpoints
338
62f2c808
JK
339 gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
340 "next over recursive call"
ef44eed1
SS
341
342 # OK, we should be back in the same stack frame we started from.
343 # Do a backtrace just to confirm.
344
345 set result [gdb_test "backtrace" \
4081daa1 346 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
ef44eed1
SS
347 "backtrace from factorial(5)"]
348 if $result!=0 then { return }
349
350 # Continue until we exit. Should not stop again.
b998e7b8
FF
351 # Don't bother to check the output of the program, that may be
352 # extremely tough for some remote systems.
353 gdb_test "continue"\
354 "Continuing.\[\r\n0-9\]+Program exited normally\\."\
ef44eed1
SS
355 "continue until exit in recursive next test"
356}
357
358test_clear_command
359test_next_with_recursion
360
361# Reset the default arguments for VxWorks
e965bc39 362if [istarget "*-*-vxworks*"] then {
ef44eed1
SS
363 set timeout 10
364 send "set args main\n"
365 expect -re ".*$prompt $" {}
366}
This page took 0.169157 seconds and 4 git commands to generate.