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