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