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