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