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