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