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