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