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