]>
Commit | Line | Data |
---|---|---|
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 | 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 | # | |
4dfef5be SM |
476 | if ![runto_main] then { |
477 | return | |
478 | } | |
c906108c | 479 | |
10125099 SM |
480 | gdb_test "catch fork" "Catchpoint \[0-9\]+ \\(fork\\)" \ |
481 | "set catch fork, never expected to trigger" | |
c906108c | 482 | |
10125099 SM |
483 | gdb_test "catch vfork" "Catchpoint \[0-9\]+ \\(vfork\\)" \ |
484 | "set catch vfork, never expected to trigger" | |
c906108c | 485 | |
10125099 SM |
486 | gdb_test "catch exec" "Catchpoint \[0-9\]+ \\(exec\\)" \ |
487 | "set catch exec, never expected to trigger" | |
c906108c | 488 | |
c906108c SS |
489 | # Verify that GDB responds gracefully when asked to set a breakpoint |
490 | # on a nonexistent source line. | |
491 | # | |
f8eba3c6 | 492 | gdb_test_no_output "set breakpoint pending off" |
22454424 | 493 | gdb_test "break 999" \ |
f8eba3c6 | 494 | "No line 999 in the current file." \ |
22454424 | 495 | "break on non-existent source line" |
c906108c | 496 | |
0fbc361c EZ |
497 | # Run to the desired default location. If not positioned here, the |
498 | # tests below don't work. | |
499 | # | |
22454424 MS |
500 | gdb_test "until $bp_location1" "main .* at .*:$bp_location1.*" \ |
501 | "until bp_location1" | |
0fbc361c | 502 | |
c906108c SS |
503 | # Verify that GDB allows one to just say "break", which is treated |
504 | # as the "default" breakpoint. Note that GDB gets cute when printing | |
505 | # the informational message about other breakpoints at the same | |
506 | # location. We'll hit that bird with this stone too. | |
507 | # | |
22454424 MS |
508 | gdb_test "break" "Breakpoint \[0-9\]*.*" \ |
509 | "break on default location, 1st time" | |
c906108c | 510 | |
22454424 MS |
511 | gdb_test "break" \ |
512 | "Note: breakpoint \[0-9\]* also set at .*Breakpoint \[0-9\]*.*" \ | |
513 | "break on default location, 2nd time" | |
c906108c | 514 | |
22454424 MS |
515 | gdb_test "break" \ |
516 | "Note: breakpoints \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*" \ | |
517 | "break on default location, 3rd time" | |
c906108c | 518 | |
22454424 MS |
519 | gdb_test "break" \ |
520 | "Note: breakpoints \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*" \ | |
521 | "break on default location, 4th time" | |
c906108c SS |
522 | |
523 | # Verify that a "silent" breakpoint can be set, and that GDB is indeed | |
524 | # "silent" about its triggering. | |
525 | # | |
4dfef5be SM |
526 | if ![runto_main] then { |
527 | return | |
528 | } | |
c906108c | 529 | |
22454424 MS |
530 | gdb_test_multiple "break $bp_location1" \ |
531 | "set to-be-silent break bp_location1" { | |
532 | -re "Breakpoint (\[0-9\]*) at .*, line $bp_location1.*$gdb_prompt $" { | |
533 | pass "set to-be-silent break bp_location1" | |
534 | } | |
535 | } | |
c906108c | 536 | |
e809353a | 537 | gdb_test "commands $expect_out(1,string)\nsilent\nend" ">end" "set silent break bp_location1" |
c906108c | 538 | |
22454424 MS |
539 | gdb_test "info break $expect_out(1,string)" \ |
540 | "\[0-9\]*\[ \t\]*breakpoint.*:$bp_location1\r\n\[ \t\]*silent.*" \ | |
541 | "info silent break bp_location1" | |
542 | ||
543 | gdb_test "continue" "Continuing." \ | |
544 | "hit silent break bp_location1" | |
545 | ||
546 | gdb_test "bt" "#0 main .* at .*:$bp_location1.*" \ | |
547 | "stopped for silent break bp_location1" | |
c906108c SS |
548 | |
549 | # Verify that GDB can at least parse a breakpoint with the | |
550 | # "thread" keyword. (We won't attempt to test here that a | |
551 | # thread-specific breakpoint really triggers appropriately. | |
552 | # The gdb.threads subdirectory contains tests for that.) | |
553 | # | |
a50d3602 | 554 | set bp_location12 [gdb_get_line_number "set breakpoint 12 here"] |
22454424 MS |
555 | gdb_test "break $bp_location12 thread 999" "Unknown thread 999.*" \ |
556 | "thread-specific breakpoint on non-existent thread disallowed" | |
557 | ||
558 | gdb_test "break $bp_location12 thread foo" \ | |
5d5658a1 | 559 | "Invalid thread ID: foo" \ |
22454424 | 560 | "thread-specific breakpoint on bogus thread ID disallowed" |
c906108c SS |
561 | |
562 | # Verify that GDB responds gracefully to a breakpoint command with | |
563 | # trailing garbage. | |
564 | # | |
22454424 | 565 | gdb_test "break $bp_location12 foo" \ |
40e084e1 | 566 | "malformed linespec error: unexpected string, \"foo\".*" \ |
22454424 | 567 | "breakpoint with trailing garbage disallowed" |
c906108c SS |
568 | |
569 | # Verify that GDB responds gracefully to a "clear" command that has | |
570 | # no matching breakpoint. (First, get us off the current source line, | |
571 | # which we know has a breakpoint.) | |
572 | # | |
22454424 MS |
573 | gdb_test "next" "marker1.*" "step over breakpoint" |
574 | ||
575 | gdb_test "clear 81" "No breakpoint at 81.*" \ | |
576 | "clear line has no breakpoint disallowed" | |
577 | ||
578 | gdb_test "clear" "No breakpoint at this line.*" \ | |
579 | "clear current line has no breakpoint disallowed" | |
c906108c | 580 | |
4a7bddb6 MC |
581 | # Verify that we can set and clear multiple breakpoints. |
582 | # | |
583 | # We don't test that it deletes the correct breakpoints. We do at | |
584 | # least test that it deletes more than one breakpoint. | |
585 | # | |
586 | gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #1" | |
587 | gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #2" | |
588 | gdb_test "clear marker3" {Deleted breakpoints [0-9]+ [0-9]+.*} | |
589 | ||
c906108c SS |
590 | # Verify that a breakpoint can be set via a convenience variable. |
591 | # | |
22454424 | 592 | |
42e165c3 SM |
593 | with_test_prefix "set line breakpoint via convenience variable" { |
594 | gdb_test_no_output "set \$foo=$bp_location11" \ | |
595 | "set convenience variable \$foo to bp_location11" | |
c906108c | 596 | |
42e165c3 SM |
597 | gdb_test "break \$foo" \ |
598 | "Breakpoint (\[0-9\]*) at .*, line $bp_location11.*" | |
599 | ||
600 | # Verify that GDB responds gracefully to an attempt to set a | |
601 | # breakpoint via a convenience variable whose type is not integer. | |
602 | # | |
22454424 | 603 | |
42e165c3 SM |
604 | gdb_test_no_output "set \$foo=81.5" \ |
605 | "set convenience variable \$foo to 81.5" | |
606 | ||
607 | gdb_test "break \$foo" \ | |
608 | "Convenience variables used in line specs must have integer values.*" \ | |
609 | "non-integer convenience variable disallowed" | |
610 | } | |
c906108c SS |
611 | |
612 | # Verify that we can set and trigger a breakpoint in a user-called function. | |
613 | # | |
22454424 | 614 | gdb_test "break marker2" \ |
3b377a3a | 615 | "Breakpoint (\[0-9\]*) at .*, line $bp_location8.*" \ |
22454424 MS |
616 | "set breakpoint on to-be-called function" |
617 | ||
618 | gdb_test "print marker2(99)" \ | |
52bb0902 | 619 | "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 | 620 | "hit breakpoint on called function" |
c906108c SS |
621 | |
622 | # As long as we're stopped (breakpointed) in a called function, | |
623 | # verify that we can successfully backtrace & such from here. | |
3ca22649 SM |
624 | gdb_test "bt" \ |
625 | "#0\[ \t\]*($hex in )?marker2.*:$bp_location8\r\n#1\[ \t\]*<function called from gdb>.*" \ | |
626 | "backtrace while in called function" | |
30e87cd3 ND |
627 | |
628 | # Return from the called function. For remote targets, it's important to do | |
629 | # this before runto_main, which otherwise may silently stop on the dummy | |
630 | # breakpoint inserted by GDB at the program's entry point. | |
631 | # | |
22454424 | 632 | gdb_test_multiple "finish" "finish from called function" { |
3b377a3a | 633 | -re "Run till exit from .*marker2.* at .*$bp_location8\r\n.*function called from gdb.*$gdb_prompt $" { |
22454424 MS |
634 | pass "finish from called function" |
635 | } | |
3b377a3a | 636 | -re "Run till exit from .*marker2.* at .*$bp_location8\r\n.*Value returned.*$gdb_prompt $" { |
22454424 MS |
637 | pass "finish from called function" |
638 | } | |
c906108c SS |
639 | } |
640 | ||
641 | # Verify that GDB responds gracefully to a "finish" command with | |
642 | # arguments. | |
643 | # | |
4dfef5be SM |
644 | if ![runto_main] then { |
645 | return | |
646 | } | |
c906108c SS |
647 | |
648 | send_gdb "finish 123\n" | |
649 | gdb_expect { | |
650 | -re "The \"finish\" command does not take any arguments.\r\n$gdb_prompt $"\ | |
651 | {pass "finish with arguments disallowed"} | |
652 | -re "$gdb_prompt $"\ | |
653 | {fail "finish with arguments disallowed"} | |
654 | timeout {fail "(timeout) finish with arguments disallowed"} | |
655 | } | |
656 | ||
657 | # Verify that GDB responds gracefully to a request to "finish" from | |
7a292a7a SS |
658 | # the outermost frame. On a stub that never exits, this will just |
659 | # run to the stubs routine, so we don't get this error... Thus the | |
660 | # second condition. | |
c906108c | 661 | # |
7a292a7a | 662 | |
22454424 MS |
663 | gdb_test_multiple "finish" "finish from outermost frame disallowed" { |
664 | -re "\"finish\" not meaningful in the outermost frame.\r\n$gdb_prompt $" { | |
665 | pass "finish from outermost frame disallowed" | |
666 | } | |
667 | -re "Run till exit from.*\r\n$gdb_prompt $" { | |
668 | pass "finish from outermost frame disallowed" | |
669 | } | |
c906108c SS |
670 | } |
671 | ||
c906108c SS |
672 | #******** |
673 | ||
674 | ||
c906108c SS |
675 | # |
676 | # Test "next" over recursive function call. | |
677 | # | |
678 | ||
679 | proc test_next_with_recursion {} { | |
680 | global gdb_prompt | |
681 | global decimal | |
682 | global binfile | |
683 | ||
b741e217 DJ |
684 | gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y" |
685 | delete_breakpoints | |
c906108c SS |
686 | |
687 | gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial" | |
688 | ||
689 | # Run until we call factorial with 6 | |
690 | ||
b741e217 | 691 | gdb_run_cmd |
fa43b1d7 | 692 | gdb_test "" "Break.* factorial .value=6. .*" "run to factorial(6)" |
c906108c SS |
693 | |
694 | # Continue until we call factorial recursively with 5. | |
695 | ||
0ac85db5 | 696 | gdb_test "continue" \ |
c906108c | 697 | "Continuing.*Break.* factorial .value=5. .*" \ |
0ac85db5 | 698 | "continue to factorial(5)" |
c906108c SS |
699 | |
700 | # Do a backtrace just to confirm how many levels deep we are. | |
701 | ||
0ac85db5 | 702 | gdb_test "backtrace" \ |
c906108c | 703 | "#0\[ \t\]+ factorial .value=5..*" \ |
0ac85db5 | 704 | "backtrace from factorial(5)" |
c906108c SS |
705 | |
706 | # Now a "next" should position us at the recursive call, which | |
707 | # we will be performing with 4. | |
708 | ||
0ac85db5 | 709 | gdb_test "next" \ |
c906108c | 710 | ".* factorial .value - 1.;.*" \ |
0ac85db5 | 711 | "next to recursive call" |
c906108c SS |
712 | |
713 | # Disable the breakpoint at the entry to factorial by deleting them all. | |
714 | # The "next" should run until we return to the next line from this | |
715 | # recursive call to factorial with 4. | |
716 | # Buggy versions of gdb will stop instead at the innermost frame on | |
717 | # the line where we are trying to "next" to. | |
718 | ||
719 | delete_breakpoints | |
720 | ||
721 | if [istarget "mips*tx39-*"] { | |
722 | set timeout 60 | |
c906108c | 723 | } |
7a345fb3 JB |
724 | # We used to set timeout here for all other targets as well. This |
725 | # is almost certainly wrong. The proper timeout depends on the | |
726 | # target system in use, and how we communicate with it, so there | |
727 | # is no single value appropriate for all targets. The timeout | |
728 | # should be established by the Dejagnu config file(s) for the | |
729 | # board, and respected by the test suite. | |
730 | # | |
731 | # For example, if I'm running GDB over an SSH tunnel talking to a | |
732 | # portmaster in California talking to an ancient 68k board running | |
733 | # a crummy ROM monitor (a situation I can only wish were | |
734 | # hypothetical), then I need a large timeout. But that's not the | |
735 | # kind of knowledge that belongs in this file. | |
c906108c SS |
736 | |
737 | gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \ | |
738 | "next over recursive call" | |
739 | ||
740 | # OK, we should be back in the same stack frame we started from. | |
741 | # Do a backtrace just to confirm. | |
742 | ||
0ac85db5 | 743 | gdb_test "backtrace" \ |
c906108c | 744 | "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \ |
0ac85db5 | 745 | "backtrace from factorial(5.1)" |
c906108c | 746 | |
0ac85db5 SM |
747 | if { ![target_info exists gdb,noresults] } { |
748 | gdb_continue_to_end "recursive next test" | |
749 | } | |
c906108c SS |
750 | } |
751 | ||
c906108c SS |
752 | test_next_with_recursion |
753 | ||
c1790a9d JL |
754 | |
755 | #******** | |
756 | ||
757 | # build a new file with optimization enabled so that we can try breakpoints | |
758 | # on targets with optimized prologues | |
759 | ||
5b362f04 | 760 | if { [prepare_for_testing "failed to prepare" "breako2" {break.c break1.c} {debug nowarnings optimize=-O2}] } { |
c1790a9d JL |
761 | return -1 |
762 | } | |
763 | ||
c1790a9d JL |
764 | # |
765 | # test break at function | |
766 | # | |
e777225b | 767 | gdb_test "break -q main" \ |
954de43b | 768 | "Breakpoint.*at.* file .*, line.*" \ |
c1790a9d JL |
769 | "breakpoint function, optimized file" |
770 | ||
771 | # | |
772 | # test break at function | |
773 | # | |
774 | gdb_test "break marker4" \ | |
a1dea79a | 775 | "Breakpoint.*at.* file .*$srcfile1, line.*" \ |
c1790a9d JL |
776 | "breakpoint small function, optimized file" |
777 | ||
778 | # | |
779 | # run until the breakpoint at main is hit. For non-stubs-using targets. | |
780 | # | |
b741e217 | 781 | gdb_run_cmd |
fa43b1d7 PA |
782 | |
783 | set test "run until function breakpoint, optimized file" | |
784 | gdb_test_multiple "" $test { | |
b741e217 | 785 | -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $" { |
fa43b1d7 | 786 | pass $test |
c1790a9d | 787 | } |
b741e217 | 788 | -re "Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$gdb_prompt $" { |
fa43b1d7 | 789 | pass "$test (code motion)" |
c1790a9d JL |
790 | } |
791 | } | |
792 | ||
793 | # | |
794 | # run until the breakpoint at a small function | |
795 | # | |
1a570b2f MS |
796 | |
797 | # | |
798 | # Add a second pass pattern. The behavior differs here between stabs | |
799 | # and dwarf for one-line functions. Stabs preserves two line symbols | |
800 | # (one before the prologue and one after) with the same line number, | |
801 | # but dwarf regards these as duplicates and discards one of them. | |
802 | # Therefore the address after the prologue (where the breakpoint is) | |
803 | # has no exactly matching line symbol, and GDB reports the breakpoint | |
804 | # as if it were in the middle of a line rather than at the beginning. | |
805 | ||
a1dea79a | 806 | set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile1] |
22454424 MS |
807 | |
808 | gdb_test_multiple "continue" \ | |
809 | "run until breakpoint set at small function, optimized file" { | |
e18b2753 | 810 | -re "Breakpoint $decimal, marker4 \\(d=(d@entry=)?177601976\\) at .*$srcfile1:$bp_location14\[\r\n\]+$bp_location14\[\t \]+void marker4.*" { |
22454424 MS |
811 | pass "run until breakpoint set at small function, optimized file (line bp_location14)" |
812 | } | |
813 | -re "Breakpoint $decimal, factorial \\(.*\\) .*\{\r\n$gdb_prompt" { | |
814 | # GCC 4.3 emits bad line number information - see gcc/36748. | |
815 | if { [test_compiler_info "gcc-4-3-*"] } { | |
816 | setup_xfail *-*-* | |
817 | } | |
818 | fail "run until breakpoint set at small function, optimized file" | |
edb3359d | 819 | } |
1a570b2f | 820 | } |
c1790a9d | 821 | |
dbc52822 | 822 | clean_restart breako2 |
6214f497 DJ |
823 | |
824 | # | |
825 | # test that 'rbreak' on a symbol that may be from a shared library doesn't | |
826 | # cause a "Junk at end of arguments." error. | |
827 | # | |
828 | # On x86 GNU/Linux, this test will choke on e.g. __libc_start_main@plt. | |
829 | # | |
830 | # Note that this test won't necessarily choke on all targets even if | |
831 | # all the rbreak issue is present. rbreak needs to match and set a | |
832 | # breakpoint on a symbol causes 'break' to choke. | |
833 | # | |
834 | ||
27d3a1a2 | 835 | gdb_test_no_output "set breakpoint pending on" "rbreak junk pending setup" |
6214f497 DJ |
836 | |
837 | # We expect at least one breakpoint to be set when we "rbreak main". | |
838 | gdb_test "rbreak main" \ | |
839 | ".*Breakpoint.*at.* file .*$srcfile, line.*" \ | |
840 | "rbreak junk set breakpoint" | |
841 | ||
842 | # Run to a breakpoint. Fail if we see "Junk at end of arguments". | |
843 | gdb_run_cmd | |
fa43b1d7 PA |
844 | |
845 | set test "rbreak junk" | |
846 | gdb_test_multiple "" $test { | |
6214f497 | 847 | -re "Junk at end of arguments" { |
fa43b1d7 | 848 | fail $test |
6214f497 DJ |
849 | } |
850 | -re ".*Breakpoint \[0-9\]+,.*$gdb_prompt $" { | |
fa43b1d7 | 851 | pass $test |
6214f497 DJ |
852 | } |
853 | } | |
854 | ||
b4013987 AA |
855 | # |
856 | # Test break via convenience variable with file name | |
857 | # | |
b4013987 | 858 | |
42e165c3 SM |
859 | with_test_prefix "set line:file breakpoint via convenience variable" { |
860 | set line [gdb_get_line_number "set breakpoint 1 here"] | |
861 | gdb_test_no_output "set \$l = $line" | |
862 | ||
863 | set line_actual "-1" | |
864 | set test "break ${srcfile}:\$l" | |
865 | gdb_test_multiple "$test" $test { | |
866 | -re "Breakpoint $decimal at $hex: file .*break\\.c, line ($decimal)\\.\r\n$gdb_prompt $" { | |
867 | # Save the actual line number on which the breakpoint was | |
868 | # actually set. On some systems (Eg: Ubuntu 16.04 with GCC | |
869 | # version 5.4.0), that line gets completely inlined, including | |
870 | # the call to printf, and so we end up inserting the breakpoint | |
871 | # on one of the following lines instead. | |
872 | set line_actual $expect_out(1,string) | |
873 | pass $test | |
874 | } | |
875 | } | |
99598d71 | 876 | |
42e165c3 SM |
877 | gdb_test_no_output "set \$foo=81.5" \ |
878 | "set convenience variable \$foo to 81.5" | |
879 | gdb_test "break $srcfile:\$foo" \ | |
880 | "Convenience variables used in line specs must have integer values.*" \ | |
881 | "non-integer convenience variable disallowed" | |
882 | } | |
99598d71 TT |
883 | |
884 | # | |
885 | # Test that commands can be cleared without error. | |
886 | # | |
887 | ||
888 | gdb_test "commands\nprint 232323\nend" ">end" "set some breakpoint commands" | |
889 | gdb_test "commands\nend" ">end" "clear breakpoint commands" | |
890 | # We verify that the commands were cleared by ensuring that the last | |
891 | # breakpoint's location ends the output -- if there were commands, | |
892 | # they would have been printed after the location. | |
fc413dc4 | 893 | gdb_test "info break" "$srcfile:$line_actual" "verify that they were cleared" |