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