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