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