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