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