]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/break.exp
the "ambiguous linespec" series
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / break.exp
CommitLineData
b6ba6518 1# Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999,
7b6bb8da
JB
2# 2000, 2002, 2003, 2007, 2008, 2009, 2010, 2011
3# Free Software Foundation, Inc.
c906108c
SS
4
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
e22f8b7c 7# the Free Software Foundation; either version 3 of the License, or
c906108c 8# (at your option) any later version.
e22f8b7c 9#
c906108c
SS
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
e22f8b7c 14#
c906108c 15# You should have received a copy of the GNU General Public License
e22f8b7c 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 17
c906108c
SS
18# This file was written by Rob Savoye. (rob@cygnus.com)
19
dbc52822 20if { [prepare_for_testing break.exp "break" {break.c break1.c} {debug nowarnings}] } {
085dd6e6
JM
21 return -1
22}
dbc52822
VP
23set srcfile break.c
24set srcfile1 break1.c
c906108c
SS
25#
26# test simple breakpoint setting commands
27#
28
29# Test deleting all breakpoints when there are none installed,
30# GDB should not prompt for confirmation.
9d6f42e9 31# Note that lib/gdb.exp provides a "delete_breakpoints" proc
c906108c
SS
32# for general use elsewhere.
33
34send_gdb "delete breakpoints\n"
35gdb_expect {
36 -re "Delete all breakpoints.*$" {
37 send_gdb "y\n"
38 gdb_expect {
39 -re "$gdb_prompt $" {
40 fail "Delete all breakpoints when none (unexpected prompt)"
41 }
42 timeout { fail "Delete all breakpoints when none (timeout after unexpected prompt)" }
43 }
44 }
45 -re ".*$gdb_prompt $" { pass "Delete all breakpoints when none" }
46 timeout { fail "Delete all breakpoints when none (timeout)" }
47}
48
49#
50# test break at function
51#
52gdb_test "break main" \
53 "Breakpoint.*at.* file .*$srcfile, line.*" \
54 "breakpoint function"
55
df763c7f
DJ
56#
57# test break at quoted function
58#
59gdb_test "break \"marker2\"" \
a1dea79a 60 "Breakpoint.*at.* file .*$srcfile1, line.*" \
df763c7f
DJ
61 "breakpoint quoted function"
62
c906108c
SS
63#
64# test break at function in file
65#
66gdb_test "break $srcfile:factorial" \
67 "Breakpoint.*at.* file .*$srcfile, line.*" \
68 "breakpoint function in file"
69
a50d3602
EZ
70set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
71
c906108c
SS
72#
73# test break at line number
74#
e6f9e514
JB
75# Note that the default source file is the last one whose source text
76# was printed. For native debugging, before we've executed the
77# program, this is the file containing main, but for remote debugging,
78# it's wherever the processor was stopped when we connected to the
79# board. So, to be sure, we do a list command.
80#
81gdb_test "list main" \
82 ".*main \\(argc, argv, envp\\).*" \
83 "use `list' to establish default source file"
a50d3602
EZ
84gdb_test "break $bp_location1" \
85 "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\." \
c906108c
SS
86 "breakpoint line number"
87
88#
89# test duplicate breakpoint
90#
a50d3602
EZ
91gdb_test "break $bp_location1" \
92 "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line $bp_location1\\." \
c906108c
SS
93 "breakpoint duplicate"
94
a50d3602
EZ
95set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
96
c906108c
SS
97#
98# test break at line number in file
99#
a50d3602
EZ
100gdb_test "break $srcfile:$bp_location2" \
101 "Breakpoint.*at.* file .*$srcfile, line $bp_location2\\." \
c906108c
SS
102 "breakpoint line number in file"
103
a50d3602
EZ
104set bp_location3 [gdb_get_line_number "set breakpoint 3 here"]
105set bp_location4 [gdb_get_line_number "set breakpoint 4 here"]
c906108c 106
f286b2c3
JL
107#
108# Test putting a break at the start of a multi-line if conditional.
109# Verify the breakpoint was put at the start of the conditional.
110#
111gdb_test "break multi_line_if_conditional" \
a50d3602 112 "Breakpoint.*at.* file .*$srcfile, line $bp_location3\\." \
f286b2c3
JL
113 "breakpoint at start of multi line if conditional"
114
115gdb_test "break multi_line_while_conditional" \
a50d3602 116 "Breakpoint.*at.* file .*$srcfile, line $bp_location4\\." \
f286b2c3
JL
117 "breakpoint at start of multi line while conditional"
118
a50d3602
EZ
119set bp_location5 [gdb_get_line_number "set breakpoint 5 here"]
120set bp_location6 [gdb_get_line_number "set breakpoint 6 here"]
121
c906108c
SS
122#
123# check to see what breakpoints are set
124#
125if [target_info exists gdb_stub] {
a50d3602 126 set main_line $bp_location5
c906108c 127} else {
a50d3602 128 set main_line $bp_location6
c906108c
SS
129}
130
085dd6e6
JM
131if {$hp_aCC_compiler} {
132 set proto "\\(int\\)"
133} else {
134 set proto ""
135}
82025e13 136
a50d3602 137set bp_location7 [gdb_get_line_number "set breakpoint 7 here"]
a1dea79a
FF
138set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile1]
139set bp_location9 [gdb_get_line_number "set breakpoint 9 here" $srcfile1]
a50d3602 140
c906108c 141gdb_test "info break" \
54e52265 142 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
c906108c 143\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$main_line.*
a1dea79a 144\[0-9\]+\[\t \]+breakpoint keep y.* in marker2 at .*$srcfile1:($bp_location8|$bp_location9).*
a50d3602
EZ
145\[0-9\]+\[\t \]+breakpoint keep y.* in factorial$proto at .*$srcfile:$bp_location7.*
146\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.*
147\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.*
148\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location2.*
149\[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_if_conditional at .*$srcfile:$bp_location3.*
150\[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_while_conditional at .*$srcfile:$bp_location4" \
c906108c
SS
151 "breakpoint info"
152
e5a67952
MS
153#
154# Test info breakpoint with arguments
155#
156
157set see1 0
158set see2 0
159set see3 0
160set see4 0
161set see5 0
162set see6 0
163
164gdb_test_multiple "info break 2 4 6" "info break 2 4 6" {
165 -re "1\[\t \]+breakpoint *keep y\[^\r\n\]*:$main_line\[^\r\n\]*" {
166 set see1 1
167 exp_continue
168 }
169 -re "2\[\t \]+breakpoint *keep y\[^\r\n\]* in marker2 at \[^\r\n\]*" {
170 set see2 1
171 exp_continue
172 }
173 -re "3\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location7\[^\r\n\]*" {
174 set see3 1
175 exp_continue
176 }
177 -re "4\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location1\[^\r\n\]*" {
178 set see4 1
179 exp_continue
180 }
181 -re "5\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location1\[^\r\n\]*" {
182 set see5 1
183 exp_continue
184 }
185 -re "6\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location2\[^\r\n\]*" {
186 set see6 1
187 exp_continue
188 }
189 -re ".*$gdb_prompt $" {
190 if { !$see1 && $see2 && !$see3 && $see4 && !$see5 && $see6 } then {
191 pass "info break 2 4 6"
192 } else {
193 fail "info break 2 4 6"
194 }
195 }
196}
197
198set see1 0
199set see2 0
200set see3 0
201set see4 0
202set see5 0
203set see6 0
204
205gdb_test_multiple "info break 3-5" "info break 3-5" {
206 -re "1\[\t \]+breakpoint *keep y.* in main at .*:$main_line\[^\r\n\]*" {
207 set see1 1
208 exp_continue
209 }
210 -re "2\[\t \]+breakpoint *keep y\[^\r\n\]* in marker2 at \[^\r\n\]*" {
211 set see2 1
212 exp_continue
213 }
214 -re "3\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location7\[^\r\n\]*" {
215 set see3 1
216 exp_continue
217 }
218 -re "4\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location1\[^\r\n\]*" {
219 set see4 1
220 exp_continue
221 }
222 -re "5\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location1\[^\r\n\]*" {
223 set see5 1
224 exp_continue
225 }
226 -re "6\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location2\[^\r\n\]*" {
227 set see6 1
228 exp_continue
229 }
230 -re ".*$gdb_prompt $" {
231 if { !$see1 && !$see2 && $see3 && $see4 && $see5 && !$see6 } then {
232 pass "info break 3-5"
233 } else {
234 fail "info break 3-5"
235 }
236 }
237}
238
3bd0f5ef
MS
239#
240# Test disable/enable with arguments
241#
242
243# Test with value history
244
245gdb_test "print 1" "" ""
246gdb_test "print 2" "" ""
247gdb_test "print 3" "" ""
248gdb_test "print 4" "" ""
249gdb_test "print 5" "" ""
250gdb_test "print 6" "" ""
251
252# $2 is 2 and $$ is 5
253gdb_test_no_output "disable \$2 \$\$" "disable using history values"
254
255set see1 0
256set see2 0
257set see3 0
258set see4 0
259set see5 0
260set see6 0
261
262gdb_test_multiple "info break" "check disable with history values" {
263 -re "1\[\t \]+breakpoint *keep y.* in main at .*:$main_line\[^\r\n\]*" {
264 set see1 1
265 exp_continue
266 }
267 -re "2\[\t \]+breakpoint *keep n\[^\r\n\]* in marker2 at \[^\r\n\]*" {
268 set see2 1
269 exp_continue
270 }
271 -re "3\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location7\[^\r\n\]*" {
272 set see3 1
273 exp_continue
274 }
275 -re "4\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location1\[^\r\n\]*" {
276 set see4 1
277 exp_continue
278 }
279 -re "5\[\t \]+breakpoint *keep n\[^\r\n\]*$bp_location1\[^\r\n\]*" {
280 set see5 1
281 exp_continue
282 }
283 -re "6\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location2\[^\r\n\]*" {
284 set see6 1
285 exp_continue
286 }
287 -re ".*$gdb_prompt $" {
288 if { $see1 && $see2 && $see3 && $see4 && $see5 && $see6 } then {
289 pass "check disable with history values"
290 } else {
291 fail "check disable with history values"
292 }
293 }
294}
295
296gdb_test "enable" "" ""
297gdb_test "set \$foo = 3" "" ""
298gdb_test "set \$bar = 6" "" ""
299gdb_test_no_output "disable \$foo \$bar" "disable with convenience values"
300
301set see1 0
302set see2 0
303set see3 0
304set see4 0
305set see5 0
306set see6 0
307
308gdb_test_multiple "info break" "check disable with convenience values" {
309 -re "1\[\t \]+breakpoint *keep y.* in main at .*:$main_line\[^\r\n\]*" {
310 set see1 1
311 exp_continue
312 }
313 -re "2\[\t \]+breakpoint *keep y\[^\r\n\]* in marker2 at \[^\r\n\]*" {
314 set see2 1
315 exp_continue
316 }
317 -re "3\[\t \]+breakpoint *keep n\[^\r\n\]*$bp_location7\[^\r\n\]*" {
318 set see3 1
319 exp_continue
320 }
321 -re "4\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location1\[^\r\n\]*" {
322 set see4 1
323 exp_continue
324 }
325 -re "5\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location1\[^\r\n\]*" {
326 set see5 1
327 exp_continue
328 }
329 -re "6\[\t \]+breakpoint *keep n\[^\r\n\]*$bp_location2\[^\r\n\]*" {
330 set see6 1
331 exp_continue
332 }
333 -re ".*$gdb_prompt $" {
334 if { $see1 && $see2 && $see3 && $see4 && $see5 && $see6 } then {
335 pass "check disable with convenience values"
336 } else {
337 fail "check disable with convenience values"
338 }
339 }
340}
341
342# test with bad values
343
344gdb_test "enable" "" ""
345gdb_test "disable 10" "No breakpoint number 10." \
346 "disable non-existent breakpoint 10"
347
348gdb_test "set \$baz 1.234"
349gdb_test "disable \$baz" \
350 "Convenience variable must have integer value.*" \
351 "disable with non-integer convenience var"
352gdb_test "disable \$grbx" \
353 "Convenience variable must have integer value.*" \
354 "disable with non-existent convenience var"
355gdb_test "disable \$10" \
356 "History has not yet reached .10." \
357 "disable with non-existent history value"
358gdb_test "disable \$1foo" \
359 "Convenience variable must have integer value.*" \
360 "disable with badly formed history value"
361
c906108c
SS
362# FIXME: The rest of this test doesn't work with anything that can't
363# handle arguments.
364# Huh? There doesn't *appear* to be anything that passes arguments
365# below.
366if [istarget "mips-idt-*"] then {
367 return
368}
369
370#
371# run until the breakpoint at main is hit. For non-stubs-using targets.
372#
b741e217
DJ
373gdb_run_cmd
374gdb_expect {
375 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $" {
376 pass "run until function breakpoint"
c906108c 377 }
b741e217
DJ
378 -re "$gdb_prompt $" {
379 fail "run until function breakpoint"
380 }
381 timeout {
382 fail "run until function breakpoint (timeout)"
c906108c
SS
383 }
384}
385
386#
387# run until the breakpoint at a line number
388#
a50d3602 389gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \
c906108c
SS
390 "run until breakpoint set at a line number"
391
392#
393# Run until the breakpoint set in a function in a file
394#
395for {set i 6} {$i >= 1} {incr i -1} {
a50d3602 396 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:$bp_location7.*$bp_location7\[\t \]+.*if .value > 1. \{.*" \
c906108c
SS
397 "run until file:function($i) breakpoint"
398}
399
df763c7f
DJ
400#
401# Run until the breakpoint set at a quoted function
402#
a1dea79a 403gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, (0x\[0-9a-f\]+ in )?marker2 \\(a=43\\) at .*$srcfile1:($bp_location8|$bp_location9).*" \
df763c7f 404 "run until quoted breakpoint"
c906108c
SS
405#
406# run until the file:function breakpoint at a line number in a file
407#
a50d3602 408gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location2.*$bp_location2\[\t \]+argc = \\(argc == 12345\\);.*" \
c906108c
SS
409 "run until file:linenum breakpoint"
410
2acceee2 411# Test break at offset +1
a50d3602 412set bp_location10 [gdb_get_line_number "set breakpoint 10 here"]
2acceee2
JM
413
414gdb_test "break +1" \
a50d3602 415 "Breakpoint.*at.* file .*$srcfile, line $bp_location10\\." \
2acceee2
JM
416 "breakpoint offset +1"
417
418# Check to see if breakpoint is hit when stepped onto
419
420gdb_test "step" \
a50d3602 421 ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10.*$bp_location10\[\t \]+return argc;.*breakpoint 10 here.*" \
2acceee2
JM
422 "step onto breakpoint"
423
e1c2defa
NS
424# Check to see if breakpoint can be set on ending brace of function
425set bp_location10a [gdb_get_line_number "set breakpoint 10a here"]
426
427gdb_test "break $bp_location10a" \
428 "Breakpoint.*at.* file .*$srcfile, line $bp_location10a\\." \
429 "setting breakpoint at }"
430
431gdb_test "continue" \
432 ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10a.*$bp_location10a\[\t \]+}.*breakpoint 10a here.*" \
433 "continue to breakpoint at }"
434
c906108c
SS
435#
436# delete all breakpoints so we can start over, course this can be a test too
437#
438delete_breakpoints
439
440#
441# test temporary breakpoint at function
442#
443
18ac113b 444gdb_test "tbreak main" "Temporary breakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function"
c906108c
SS
445
446#
447# test break at function in file
448#
449
18ac113b 450gdb_test "tbreak $srcfile:factorial" "Temporary breakpoint.*at.* file .*$srcfile, line.*" \
c906108c
SS
451 "Temporary breakpoint function in file"
452
453#
454# test break at line number
455#
22454424
MS
456gdb_test "tbreak $bp_location1" \
457 "Temporary breakpoint.*at.* file .*$srcfile, line $bp_location1.*" \
458 "Temporary breakpoint line number #1"
c906108c 459
18ac113b 460gdb_test "tbreak $bp_location6" "Temporary breakpoint.*at.* file .*$srcfile, line $bp_location6.*" "Temporary breakpoint line number #2"
c906108c
SS
461
462#
463# test break at line number in file
464#
22454424
MS
465gdb_test "tbreak $srcfile:$bp_location2" \
466 "Temporary breakpoint.*at.* file .*$srcfile, line $bp_location2.*" \
467 "Temporary breakpoint line number in file #1"
c906108c 468
a50d3602 469set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
18ac113b 470gdb_test "tbreak $srcfile:$bp_location11" "Temporary breakpoint.*at.* file .*$srcfile, line $bp_location11.*" "Temporary breakpoint line number in file #2"
c906108c
SS
471
472#
473# check to see what breakpoints are set (temporary this time)
474#
54e52265 475gdb_test "info break" "Num Type.*Disp Enb Address.*What.*\[\r\n\]
085dd6e6 476\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$main_line.*\[\r\n\]
a50d3602
EZ
477\[0-9\]+\[\t \]+breakpoint del.*y.*in factorial$proto at .*$srcfile:$bp_location7.*\[\r\n\]
478\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location1.*\[\r\n\]
479\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location6.*\[\r\n\]
480\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location2.*\[\r\n\]
481\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location11.*" \
085dd6e6 482 "Temporary breakpoint info"
c906108c
SS
483
484
485#***********
486
487# Verify that catchpoints for fork, vfork and exec don't trigger
488# inappropriately. (There are no calls to those system functions
489# in this test program.)
490#
491if ![runto_main] then { fail "break tests suppressed" }
492
22454424
MS
493gdb_test "catch" \
494 "Catch requires an event name." \
495 "catch requires an event name"
c906108c
SS
496
497
498set name "set catch fork, never expected to trigger"
22454424
MS
499gdb_test_multiple "catch fork" "$name" {
500 -re "Catchpoint \[0-9\]* .fork..*$gdb_prompt $" {
501 pass $name
502 }
503 -re "Catch of fork not yet implemented.*$gdb_prompt $" {
504 pass $name
505 }
c906108c
SS
506}
507
508
c906108c
SS
509# If we are on HP-UX 10.20, we expect an error message to be
510# printed if we type "catch vfork" at the gdb gdb_prompt. This is
511# because on HP-UX 10.20, we cannot catch vfork events.
512
22454424
MS
513set name "set catch vfork, never expected to trigger"
514
c906108c 515if [istarget "hppa*-hp-hpux10.20"] then {
22454424
MS
516 gdb_test "catch vfork" \
517 "Catch of vfork events not supported on HP-UX 10.20..*" \
518 "$name"
c906108c 519} else {
22454424
MS
520 gdb_test_multiple "catch vfork" "$name" {
521 -re "Catchpoint \[0-9\]* .vfork..*$gdb_prompt $" {
522 pass $name
523 }
524 -re "Catch of vfork not yet implemented.*$gdb_prompt $" {
525 pass $name
526 }
c906108c
SS
527 }
528}
529
530set name "set catch exec, never expected to trigger"
22454424
MS
531gdb_test_multiple "catch exec" "$name" {
532 -re "Catchpoint \[0-9\]* .exec..*$gdb_prompt $" {
533 pass $name
534 }
535 -re "Catch of exec not yet implemented.*$gdb_prompt $" {
536 pass $name
537 }
c906108c
SS
538}
539
c906108c
SS
540# Verify that GDB responds gracefully when asked to set a breakpoint
541# on a nonexistent source line.
542#
f8eba3c6 543gdb_test_no_output "set breakpoint pending off"
22454424 544gdb_test "break 999" \
f8eba3c6 545 "No line 999 in the current file." \
22454424 546 "break on non-existent source line"
c906108c 547
0fbc361c
EZ
548# Run to the desired default location. If not positioned here, the
549# tests below don't work.
550#
22454424
MS
551gdb_test "until $bp_location1" "main .* at .*:$bp_location1.*" \
552 "until bp_location1"
0fbc361c 553
c906108c
SS
554# Verify that GDB allows one to just say "break", which is treated
555# as the "default" breakpoint. Note that GDB gets cute when printing
556# the informational message about other breakpoints at the same
557# location. We'll hit that bird with this stone too.
558#
22454424
MS
559gdb_test "break" "Breakpoint \[0-9\]*.*" \
560 "break on default location, 1st time"
c906108c 561
22454424
MS
562gdb_test "break" \
563 "Note: breakpoint \[0-9\]* also set at .*Breakpoint \[0-9\]*.*" \
564 "break on default location, 2nd time"
c906108c 565
22454424
MS
566gdb_test "break" \
567 "Note: breakpoints \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*" \
568 "break on default location, 3rd time"
c906108c 569
22454424
MS
570gdb_test "break" \
571 "Note: breakpoints \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*" \
572 "break on default location, 4th time"
c906108c
SS
573
574# Verify that a "silent" breakpoint can be set, and that GDB is indeed
575# "silent" about its triggering.
576#
577if ![runto_main] then { fail "break tests suppressed" }
578
22454424
MS
579gdb_test_multiple "break $bp_location1" \
580 "set to-be-silent break bp_location1" {
581 -re "Breakpoint (\[0-9\]*) at .*, line $bp_location1.*$gdb_prompt $" {
582 pass "set to-be-silent break bp_location1"
583 }
584 }
c906108c
SS
585
586send_gdb "commands $expect_out(1,string)\n"
587send_gdb "silent\n"
588send_gdb "end\n"
589gdb_expect {
590 -re ".*$gdb_prompt $"\
a1dea79a
FF
591 {pass "set silent break bp_location1"}
592 timeout {fail "(timeout) set silent break bp_location1"}
c906108c
SS
593}
594
22454424
MS
595gdb_test "info break $expect_out(1,string)" \
596 "\[0-9\]*\[ \t\]*breakpoint.*:$bp_location1\r\n\[ \t\]*silent.*" \
597 "info silent break bp_location1"
598
599gdb_test "continue" "Continuing." \
600 "hit silent break bp_location1"
601
602gdb_test "bt" "#0 main .* at .*:$bp_location1.*" \
603 "stopped for silent break bp_location1"
c906108c
SS
604
605# Verify that GDB can at least parse a breakpoint with the
606# "thread" keyword. (We won't attempt to test here that a
607# thread-specific breakpoint really triggers appropriately.
608# The gdb.threads subdirectory contains tests for that.)
609#
a50d3602 610set bp_location12 [gdb_get_line_number "set breakpoint 12 here"]
22454424
MS
611gdb_test "break $bp_location12 thread 999" "Unknown thread 999.*" \
612 "thread-specific breakpoint on non-existent thread disallowed"
613
614gdb_test "break $bp_location12 thread foo" \
615 "Junk after thread keyword.*" \
616 "thread-specific breakpoint on bogus thread ID disallowed"
c906108c
SS
617
618# Verify that GDB responds gracefully to a breakpoint command with
619# trailing garbage.
620#
22454424
MS
621gdb_test "break $bp_location12 foo" \
622 "Junk at end of arguments.*" \
623 "breakpoint with trailing garbage disallowed"
c906108c
SS
624
625# Verify that GDB responds gracefully to a "clear" command that has
626# no matching breakpoint. (First, get us off the current source line,
627# which we know has a breakpoint.)
628#
22454424
MS
629gdb_test "next" "marker1.*" "step over breakpoint"
630
631gdb_test "clear 81" "No breakpoint at 81.*" \
632 "clear line has no breakpoint disallowed"
633
634gdb_test "clear" "No breakpoint at this line.*" \
635 "clear current line has no breakpoint disallowed"
c906108c 636
4a7bddb6
MC
637# Verify that we can set and clear multiple breakpoints.
638#
639# We don't test that it deletes the correct breakpoints. We do at
640# least test that it deletes more than one breakpoint.
641#
642gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #1"
643gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #2"
644gdb_test "clear marker3" {Deleted breakpoints [0-9]+ [0-9]+.*}
645
c906108c
SS
646# Verify that a breakpoint can be set via a convenience variable.
647#
22454424
MS
648gdb_test_no_output "set \$foo=$bp_location11" \
649 "set convenience variable \$foo to bp_location11"
650
651gdb_test "break \$foo" \
652 "Breakpoint (\[0-9\]*) at .*, line $bp_location11.*" \
653 "set breakpoint via convenience variable"
c906108c
SS
654
655# Verify that GDB responds gracefully to an attempt to set a
656# breakpoint via a convenience variable whose type is not integer.
657#
22454424
MS
658gdb_test_no_output "set \$foo=81.5" \
659 "set convenience variable \$foo to 81.5"
660
661gdb_test "break \$foo" \
662 "Convenience variables used in line specs must have integer values.*" \
663 "set breakpoint via non-integer convenience variable disallowed"
c906108c
SS
664
665# Verify that we can set and trigger a breakpoint in a user-called function.
666#
22454424
MS
667gdb_test "break marker2" \
668 "Breakpoint (\[0-9\]*) at .*, line ($bp_location8|$bp_location9).*" \
669 "set breakpoint on to-be-called function"
670
671gdb_test "print marker2(99)" \
672 "The program being debugged stopped while in a function called from GDB.\r\nEvaluation of the expression containing the function\r\n.marker2$proto. will be abandoned.\r\nWhen the function is done executing, GDB will silently stop.*" \
673 "hit breakpoint on called function"
c906108c
SS
674
675# As long as we're stopped (breakpointed) in a called function,
676# verify that we can successfully backtrace & such from here.
677#
30e87cd3
ND
678# In this and the following test, the _sr4export check apparently is needed
679# for hppa*-*-hpux.
680#
22454424
MS
681gdb_test_multiple "bt" "backtrace while in called function" {
682 -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*_sr4export.*$gdb_prompt $" {
683 pass "backtrace while in called function"
684 }
685 -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*function called from gdb.*$gdb_prompt $" {
686 pass "backtrace while in called function"
687 }
30e87cd3
ND
688}
689
690# Return from the called function. For remote targets, it's important to do
691# this before runto_main, which otherwise may silently stop on the dummy
692# breakpoint inserted by GDB at the program's entry point.
693#
22454424
MS
694gdb_test_multiple "finish" "finish from called function" {
695 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.* in _sr4export.*$gdb_prompt $" {
696 pass "finish from called function"
697 }
698 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*function called from gdb.*$gdb_prompt $" {
699 pass "finish from called function"
700 }
701 -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*Value returned.*$gdb_prompt $" {
702 pass "finish from called function"
703 }
c906108c
SS
704}
705
706# Verify that GDB responds gracefully to a "finish" command with
707# arguments.
708#
709if ![runto_main] then { fail "break tests suppressed" }
710
711send_gdb "finish 123\n"
712gdb_expect {
713 -re "The \"finish\" command does not take any arguments.\r\n$gdb_prompt $"\
714 {pass "finish with arguments disallowed"}
715 -re "$gdb_prompt $"\
716 {fail "finish with arguments disallowed"}
717 timeout {fail "(timeout) finish with arguments disallowed"}
718}
719
720# Verify that GDB responds gracefully to a request to "finish" from
7a292a7a
SS
721# the outermost frame. On a stub that never exits, this will just
722# run to the stubs routine, so we don't get this error... Thus the
723# second condition.
c906108c 724#
7a292a7a 725
22454424
MS
726gdb_test_multiple "finish" "finish from outermost frame disallowed" {
727 -re "\"finish\" not meaningful in the outermost frame.\r\n$gdb_prompt $" {
728 pass "finish from outermost frame disallowed"
729 }
730 -re "Run till exit from.*\r\n$gdb_prompt $" {
731 pass "finish from outermost frame disallowed"
732 }
c906108c
SS
733}
734
735# Verify that we can explicitly ask GDB to stop on all shared library
736# events, and that it does so.
737#
738if [istarget "hppa*-*-hpux*"] then {
22454424
MS
739 if ![runto_main] then { fail "break tests suppressed" }
740
741 gdb_test_no_output "set stop-on-solib-events 1" \
742 "set stop-on-solib-events"
743
744 gdb_test "run" \
745 "Stopped due to shared library event.*" \
746 "triggered stop-on-solib-events" \
747 "Start it from the beginning.*y or n. $" \
748 "y"
749
750 gdb_test_no_output "set stop-on-solib-events 0" \
751 "reset stop-on-solib-events"
c906108c
SS
752}
753
754# Hardware breakpoints are unsupported on HP-UX. Verify that GDB
755# gracefully responds to requests to create them.
756#
757if [istarget "hppa*-*-hpux*"] then {
22454424
MS
758 if ![runto_main] then { fail "break tests suppressed" }
759
760 gdb_test "hbreak" \
761 "No hardware breakpoint support in the target.*" \
762 "hw breaks disallowed"
763
764 gdb_test "thbreak" \
765 "No hardware breakpoint support in the target.*" \
766 "temporary hw breaks disallowed"
c906108c
SS
767}
768
769#********
770
771
c906108c
SS
772#
773# Test "next" over recursive function call.
774#
775
776proc test_next_with_recursion {} {
777 global gdb_prompt
778 global decimal
779 global binfile
780
b741e217
DJ
781 gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y"
782 delete_breakpoints
c906108c
SS
783
784 gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
785
786 # Run until we call factorial with 6
787
b741e217 788 gdb_run_cmd
c906108c
SS
789 gdb_expect {
790 -re "Break.* factorial .value=6. .*$gdb_prompt $" {}
791 -re ".*$gdb_prompt $" {
792 fail "run to factorial(6)";
793 gdb_suppress_tests;
794 }
795 timeout { fail "run to factorial(6) (timeout)" ; gdb_suppress_tests }
796 }
797
798 # Continue until we call factorial recursively with 5.
799
800 if [gdb_test "continue" \
801 "Continuing.*Break.* factorial .value=5. .*" \
802 "continue to factorial(5)"] then { gdb_suppress_tests }
803
804 # Do a backtrace just to confirm how many levels deep we are.
805
806 if [gdb_test "backtrace" \
807 "#0\[ \t\]+ factorial .value=5..*" \
808 "backtrace from factorial(5)"] then { gdb_suppress_tests }
809
810 # Now a "next" should position us at the recursive call, which
811 # we will be performing with 4.
812
813 if [gdb_test "next" \
814 ".* factorial .value - 1.;.*" \
815 "next to recursive call"] then { gdb_suppress_tests }
816
817 # Disable the breakpoint at the entry to factorial by deleting them all.
818 # The "next" should run until we return to the next line from this
819 # recursive call to factorial with 4.
820 # Buggy versions of gdb will stop instead at the innermost frame on
821 # the line where we are trying to "next" to.
822
823 delete_breakpoints
824
825 if [istarget "mips*tx39-*"] {
826 set timeout 60
c906108c 827 }
7a345fb3
JB
828 # We used to set timeout here for all other targets as well. This
829 # is almost certainly wrong. The proper timeout depends on the
830 # target system in use, and how we communicate with it, so there
831 # is no single value appropriate for all targets. The timeout
832 # should be established by the Dejagnu config file(s) for the
833 # board, and respected by the test suite.
834 #
835 # For example, if I'm running GDB over an SSH tunnel talking to a
836 # portmaster in California talking to an ancient 68k board running
837 # a crummy ROM monitor (a situation I can only wish were
838 # hypothetical), then I need a large timeout. But that's not the
839 # kind of knowledge that belongs in this file.
c906108c
SS
840
841 gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
842 "next over recursive call"
843
844 # OK, we should be back in the same stack frame we started from.
845 # Do a backtrace just to confirm.
846
847 set result [gdb_test "backtrace" \
848 "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
849 "backtrace from factorial(5.1)"]
850 if { $result != 0 } { gdb_suppress_tests }
851
852 if [target_info exists gdb,noresults] { gdb_suppress_tests }
7a292a7a
SS
853 gdb_continue_to_end "recursive next test"
854 gdb_stop_suppressing_tests;
c906108c
SS
855}
856
c906108c
SS
857test_next_with_recursion
858
c1790a9d
JL
859
860#********
861
862# build a new file with optimization enabled so that we can try breakpoints
863# on targets with optimized prologues
864
dbc52822 865if { [prepare_for_testing break.exp "breako2" {break.c break1.c} {debug nowarnings optimize=-O2}] } {
c1790a9d
JL
866 return -1
867}
868
c1790a9d
JL
869#
870# test break at function
871#
872gdb_test "break main" \
954de43b 873 "Breakpoint.*at.* file .*, line.*" \
c1790a9d
JL
874 "breakpoint function, optimized file"
875
876#
877# test break at function
878#
879gdb_test "break marker4" \
a1dea79a 880 "Breakpoint.*at.* file .*$srcfile1, line.*" \
c1790a9d
JL
881 "breakpoint small function, optimized file"
882
883#
884# run until the breakpoint at main is hit. For non-stubs-using targets.
885#
b741e217
DJ
886gdb_run_cmd
887gdb_expect {
888 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $" {
889 pass "run until function breakpoint, optimized file"
c1790a9d 890 }
b741e217
DJ
891 -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$gdb_prompt $" {
892 pass "run until function breakpoint, optimized file (code motion)"
893 }
894 -re "$gdb_prompt $" {
895 fail "run until function breakpoint, optimized file"
896 }
897 timeout {
898 fail "run until function breakpoint, optimized file (timeout)"
c1790a9d
JL
899 }
900}
901
902#
903# run until the breakpoint at a small function
904#
1a570b2f
MS
905
906#
907# Add a second pass pattern. The behavior differs here between stabs
908# and dwarf for one-line functions. Stabs preserves two line symbols
909# (one before the prologue and one after) with the same line number,
910# but dwarf regards these as duplicates and discards one of them.
911# Therefore the address after the prologue (where the breakpoint is)
912# has no exactly matching line symbol, and GDB reports the breakpoint
913# as if it were in the middle of a line rather than at the beginning.
914
a1dea79a
FF
915set bp_location13 [gdb_get_line_number "set breakpoint 13 here" $srcfile1]
916set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile1]
22454424
MS
917
918gdb_test_multiple "continue" \
919 "run until breakpoint set at small function, optimized file" {
e18b2753 920 -re "Breakpoint $decimal, marker4 \\(d=(d@entry=)?177601976\\) at .*$srcfile1:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
22454424
MS
921 pass "run until breakpoint set at small function, optimized file"
922 }
e18b2753 923 -re "Breakpoint $decimal, $hex in marker4 \\(d=(d@entry=)?177601976\\) at .*$srcfile1:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
22454424
MS
924 pass "run until breakpoint set at small function, optimized file"
925 }
e18b2753 926 -re "Breakpoint $decimal, marker4 \\(d=(d@entry=)?177601976\\) at .*$srcfile1:$bp_location14\[\r\n\]+$bp_location14\[\t \]+void marker4.*" {
22454424
MS
927 # marker4() is defined at line 46 when compiled with -DPROTOTYPES
928 pass "run until breakpoint set at small function, optimized file (line bp_location14)"
929 }
930 -re "Breakpoint $decimal, factorial \\(.*\\) .*\{\r\n$gdb_prompt" {
931 # GCC 4.3 emits bad line number information - see gcc/36748.
932 if { [test_compiler_info "gcc-4-3-*"] } {
933 setup_xfail *-*-*
934 }
935 fail "run until breakpoint set at small function, optimized file"
edb3359d 936 }
1a570b2f 937 }
c1790a9d 938
dbc52822 939clean_restart breako2
6214f497
DJ
940
941#
942# test that 'rbreak' on a symbol that may be from a shared library doesn't
943# cause a "Junk at end of arguments." error.
944#
945# On x86 GNU/Linux, this test will choke on e.g. __libc_start_main@plt.
946#
947# Note that this test won't necessarily choke on all targets even if
948# all the rbreak issue is present. rbreak needs to match and set a
949# breakpoint on a symbol causes 'break' to choke.
950#
951
27d3a1a2 952gdb_test_no_output "set breakpoint pending on" "rbreak junk pending setup"
6214f497
DJ
953
954# We expect at least one breakpoint to be set when we "rbreak main".
955gdb_test "rbreak main" \
956 ".*Breakpoint.*at.* file .*$srcfile, line.*" \
957 "rbreak junk set breakpoint"
958
959# Run to a breakpoint. Fail if we see "Junk at end of arguments".
960gdb_run_cmd
961gdb_expect {
962 -re "Junk at end of arguments" {
963 fail "rbreak junk"
964 }
965 -re ".*Breakpoint \[0-9\]+,.*$gdb_prompt $" {
966 pass "rbreak junk"
967 }
968 timeout {
969 fail "rbreak junk (timeout)"
970 }
971}
972
973
c906108c
SS
974# Reset the default arguments for VxWorks
975if [istarget "*-*-vxworks*"] {
976 set timeout 10
977 verbose "Timeout is now $timeout seconds" 2
22454424 978 gdb_test_no_output "set args main"
c906108c 979}