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