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