Commit | Line | Data |
---|---|---|
ef44eed1 SS |
1 | # Copyright (C) 1988, 1990, 1991, 1992, 1994 Free Software Foundation, Inc. |
2 | ||
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
5 | # the Free Software Foundation; either version 2 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
8 | # This program is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with this program; if not, write to the Free Software | |
15 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
16 | ||
17 | # Please email any bugs, comments, and/or additions to this file to: | |
18 | # bug-gdb@prep.ai.mit.edu | |
19 | ||
20 | # This file was written by Rob Savoye. (rob@cygnus.com) | |
21 | ||
22 | if $tracelevel then { | |
23 | strace $tracelevel | |
24 | } | |
25 | ||
26 | set prms_id 0 | |
27 | set bug_id 0 | |
28 | ||
29 | # are we on a target board | |
30 | if ![isnative] then { | |
31 | warning "These test cases can't run on a target system." | |
32 | continue | |
33 | } | |
34 | ||
35 | proc test_with_self {} { | |
36 | global prompt | |
37 | global tool | |
38 | global det_file | |
39 | global timeout | |
40 | global decimal | |
41 | ||
42 | # load yourself into the debugger | |
43 | # This can take a relatively long time, particularly for testing where | |
44 | # the executable is being accessed over a network, or where gdb does not | |
45 | # support partial symbols for a particular target and has to load the | |
46 | # entire symbol table. Set the timeout to 10 minutes, which should be | |
47 | # adequate for most environments (it *has* timed out with 5 min on a | |
48 | # SPARCstation SLC under moderate load, so this isn't unreasonable). | |
49 | # After gdb is loaded, set the timeout to 30 seconds for the duration | |
50 | # of this test, and then back to the original value. | |
51 | ||
52 | set oldtimeout $timeout | |
53 | set timeout 600 | |
54 | if {[gdb_load "./x$tool"] <0} then { | |
55 | return -1 | |
56 | } | |
57 | ||
58 | set timeout 30 | |
59 | ||
60 | # disassemble yourself | |
61 | send "x/10i main\n" | |
62 | expect { | |
63 | -re "x/10i.*main.*main.$decimal.*main.$decimal.*$prompt $"\ | |
64 | { pass "Disassemble main" } | |
65 | -re ".*$prompt $" { fail "Disassemble main" } | |
66 | timeout { fail "(timeout) Disassemble main" } | |
67 | } | |
68 | ||
69 | set description "set breakpoint at main" | |
70 | send "break main\n" | |
71 | expect { | |
72 | -re "Breakpoint.*at.* file.*, line.*$prompt $" { | |
73 | pass "$description" | |
74 | } | |
75 | -re ".*$prompt $" { | |
76 | fail "$description" | |
77 | } | |
78 | timeout { | |
79 | fail "$description (timeout)" | |
80 | } | |
81 | } | |
82 | ||
ff884d6e JK |
83 | # We'll need this when we send a ^C to GDB. Need to do it before we |
84 | # run the program and gdb starts saving and restoring tty states. | |
85 | # On Ultrix, we don't need it and it is really slow (because shell_escape | |
86 | # doesn't use vfork). | |
87 | if ![istarget "*-*-ultrix*"] then { | |
88 | gdb_test "shell stty intr '^C'" "" \ | |
89 | "set interrupt character in test_with_self" | |
90 | } | |
91 | ||
ef44eed1 SS |
92 | # run yourself |
93 | set description "run until breakpoint at main" | |
94 | send "run\n" | |
95 | expect { | |
96 | -re "Starting program.*Breakpoint \[0-9\]+,.*main .argc.*argv.* at .*main.c:.*$prompt $" { | |
97 | pass "$description" | |
98 | } | |
99 | -re "Starting program.*Breakpoint \[0-9\]+,.*main .argc.*argv.*$prompt $" { | |
100 | xfail "$description (line numbers scrambled?)" | |
101 | } | |
102 | -re "vfork: No more processes.*$prompt $" { | |
103 | fail "$description (out of virtual memory)" | |
104 | return -1 | |
105 | } | |
106 | -re ".*$prompt $" { | |
107 | fail "$description" | |
108 | return -1 | |
109 | } | |
110 | timeout { | |
111 | fail "$description (timeout)" | |
112 | } | |
113 | } | |
114 | ||
115 | # do we have a version number ? | |
116 | send "print version\n" | |
117 | expect { | |
118 | -re ".\[0-9\]+ = +0x.*\[0-9.\]+.*$prompt $" { | |
119 | pass "printed version" | |
120 | } | |
121 | -re ".\[0-9\]+ = +.+ +0x.*\[0-9.\]+.*$prompt $" { | |
122 | pass "printed version with cast" | |
123 | } | |
124 | -re ".*$prompt $" { fail "printed version" } | |
125 | timeout { fail "(timeout) printed version" } | |
126 | } | |
127 | ||
128 | # lets do a few single steps | |
129 | ||
130 | set description "step over symarg initialization" | |
131 | send "step\n" | |
132 | expect { | |
133 | -re "char \[*\]+execarg = NULL;.*$prompt $" { | |
134 | pass "$description" | |
135 | } | |
136 | -re ".*No such file or directory.\r\n$prompt $" { | |
137 | pass "$description (no source available)" | |
138 | } | |
139 | -re ".*A file or directory .* does not exist..\r\n$prompt $" { | |
140 | pass "$description (no source available)" | |
141 | } | |
142 | -re ".*$prompt $" { | |
143 | fail "$description" | |
144 | } | |
145 | timeout { | |
146 | fail "$description (timeout)" | |
147 | } | |
148 | } | |
149 | ||
150 | set description "step over execarg initialization" | |
151 | send "step\n" | |
152 | expect { | |
153 | -re "char \[*\]corearg = NULL;.*$prompt $" { | |
154 | pass "$description" | |
155 | } | |
156 | -re ".*No such file or directory.\r\n$prompt $" { | |
157 | pass "$description (no source available)" | |
158 | } | |
159 | -re ".*A file or directory .* does not exist..\r\n$prompt $" { | |
160 | pass "$description (no source available)" | |
161 | } | |
162 | -re ".*$prompt $" { | |
163 | fail "$description" | |
164 | } | |
165 | timeout { | |
166 | fail "$description" (timeout)" | |
167 | } | |
168 | } | |
169 | ||
170 | set description "step over corearg initialization" | |
171 | send "step\n" | |
172 | expect { | |
173 | -re "char \[*\]cdarg = NULL;.*$prompt $" { | |
174 | pass "$description" | |
175 | } | |
176 | -re ".*No such file or directory.\r\n$prompt $" { | |
177 | pass "$description (no source available)" | |
178 | } | |
179 | -re ".*A file or directory .* does not exist..\r\n$prompt $" { | |
180 | pass "$description (no source available)" | |
181 | } | |
182 | -re ".*$prompt $" { | |
183 | fail "$description" | |
184 | } | |
185 | timeout { | |
186 | fail "$description" (timeout)" | |
187 | } | |
188 | } | |
189 | ||
190 | set description "step over cdarg initialization" | |
191 | send "step\n" | |
192 | expect { | |
193 | -re "char \[*\]ttyarg = NULL;.*$prompt $" { | |
194 | pass "$description" | |
195 | } | |
196 | -re ".*No such file or directory.\r\n$prompt $" { | |
197 | pass "$description (no source available)" | |
198 | } | |
199 | -re ".*A file or directory .* does not exist..\r\n$prompt $" { | |
200 | pass "$description (no source available)" | |
201 | } | |
202 | -re ".*$prompt $" { | |
203 | fail "$description" | |
204 | } | |
205 | timeout { | |
206 | fail "$description" (timeout)" | |
207 | } | |
208 | } | |
209 | ||
210 | set description "step over ttyarg initialization" | |
211 | send "step\n" | |
212 | expect { | |
3046ecae | 213 | -re ".*time_at_startup = get_run_time .*$prompt $" { |
ef44eed1 SS |
214 | pass "$description" |
215 | } | |
216 | -re ".*No such file or directory.\r\n$prompt $" { | |
217 | pass "$description (no source available)" | |
218 | } | |
219 | -re ".*A file or directory .* does not exist..\r\n$prompt $" { | |
220 | pass "$description (no source available)" | |
221 | } | |
222 | -re ".*$prompt $" { | |
223 | fail "$description" | |
224 | } | |
225 | timeout { | |
226 | fail "$description" (timeout)" | |
227 | } | |
228 | } | |
229 | ||
230 | # now jump over a few functions | |
231 | ||
3046ecae | 232 | set description "next over get_run_time and everything it calls" |
9b826d6d | 233 | set got_over_get_run_time 0 |
ef44eed1 SS |
234 | send "next\n" |
235 | expect { | |
3046ecae | 236 | -re ".*init_malloc.*$prompt $" { |
ef44eed1 | 237 | pass "$description" |
9b826d6d JK |
238 | set got_over_get_run_time 1 |
239 | } | |
240 | -re ".*No such file or directory.\r\n$prompt $" { | |
241 | pass "$description (no source available)" | |
242 | set got_over_get_run_time 1 | |
243 | } | |
244 | -re ".*A file or directory .* does not exist..\r\n$prompt $" { | |
245 | pass "$description (no source available)" | |
246 | set got_over_get_run_time 1 | |
247 | } | |
248 | -re ".*$prompt $" { | |
249 | fail "$description" | |
250 | } | |
251 | timeout { | |
252 | fail "$description (timeout)" | |
253 | } | |
254 | } | |
255 | # -re "if \(setmp \(to_top_level\)\).*$prompt $" { pass "first next" } | |
256 | ||
257 | if $got_over_get_run_time then { | |
258 | set description "next over init_malloc and everything it calls" | |
259 | send "next\n" | |
260 | expect { | |
3046ecae SS |
261 | -re "if.*SET_TOP_LEVEL.*$prompt $" { |
262 | pass "$description" | |
263 | } | |
264 | -re "i = .*count.*$prompt $" { | |
265 | pass "$description" | |
266 | set description "next over ALIGN_STACK_ON_STARTUP code" | |
267 | send "next\n" | |
268 | expect { | |
ef44eed1 SS |
269 | -re "if.*i != 0.*$prompt $" { |
270 | pass "$description" | |
271 | send "next\n" | |
272 | expect { | |
273 | -re "if.*SET_TOP_LEVEL.*$prompt $" { | |
274 | pass "$description" | |
275 | } | |
276 | -re "alloca.*$prompt $" { | |
277 | send "next\n" | |
278 | expect { | |
279 | -re "if.*level.*$prompt $" { | |
280 | pass "$description" | |
281 | } | |
282 | } | |
283 | } | |
284 | } | |
285 | } | |
3046ecae | 286 | } |
9b826d6d JK |
287 | } |
288 | -re ".*No such file or directory.\r\n$prompt $" { | |
289 | pass "$description (no source available)" | |
290 | } | |
291 | -re ".*A file or directory .* does not exist..\r\n$prompt $" { | |
292 | pass "$description (no source available)" | |
293 | } | |
294 | -re ".*$prompt $" { | |
295 | fail "$description" | |
296 | } | |
297 | default { | |
298 | fail "$description (timeout or eof)" | |
299 | } | |
ef44eed1 SS |
300 | } |
301 | } | |
9b826d6d | 302 | |
ef44eed1 SS |
303 | # This one fails on Solaris (for some versions of gdb) because you |
304 | # can't next over library functions | |
305 | setup_xfail "sparc-sun-solaris2" 1817 | |
306 | set next_ok 1 | |
307 | set need_to_step_over_cmdsize 1 | |
308 | set description "next over SET_TOP_LEVEL call" | |
309 | send "next\n" | |
310 | expect { | |
311 | -re "cmdsize = 1;.*$prompt $" { | |
312 | pass "$description" | |
313 | } | |
314 | -re "cmdarg = .*xmalloc.*$prompt $" { | |
315 | # This can happen in optimized code where the "cmdsize = 1" line | |
316 | # is basically removed. | |
317 | pass "$description" | |
318 | set need_to_step_over_cmdsize 0 | |
319 | } | |
320 | -re ".*No such file or directory.\r\n$prompt $" { | |
321 | pass "$description (no source available)" | |
322 | } | |
323 | -re ".*A file or directory .* does not exist..\r\n$prompt $" { | |
324 | pass "$description (no source available)" | |
325 | } | |
326 | -re ".*$prompt $" { | |
327 | fail "$description" | |
328 | set next_ok 0 | |
329 | } | |
330 | timeout { | |
331 | fail "$description (timeout)" | |
332 | set next_ok 0 | |
333 | } | |
334 | } | |
335 | ||
336 | set description "print a string" | |
337 | send "print \"foo\"\n" | |
338 | expect { | |
339 | -re ".\[0-9\]+ = \"foo\".*$prompt $" { | |
340 | pass "$description" | |
341 | } | |
342 | -re ".*$prompt $" { | |
343 | fail "$description" | |
344 | } | |
345 | timeout { | |
346 | fail "$description (timeout)" | |
347 | } | |
348 | } | |
349 | ||
350 | if $need_to_step_over_cmdsize { | |
351 | set description "step over cmdsize initialization" | |
352 | send "step\n" | |
353 | expect { | |
354 | -re "cmdarg = .*xmalloc.*$prompt $" { | |
355 | pass "$description" | |
356 | } | |
357 | -re ".*No such file or directory.\r\n$prompt $" { | |
358 | pass "$description (no source available)" | |
359 | } | |
360 | -re ".*A file or directory .* does not exist..\r\n$prompt $" { | |
361 | pass "$description (no source available)" | |
362 | } | |
363 | -re ".*$prompt $" { | |
364 | fail "$description" | |
365 | } | |
366 | timeout { | |
367 | fail "$description" (timeout)" | |
368 | } | |
369 | } | |
370 | } | |
371 | ||
372 | # and another step for good luck | |
373 | # This one fails on Solaris (for some versions of gdb) because you | |
374 | # can't step into library functions | |
375 | if $next_ok { | |
376 | set description "step into xmalloc call" | |
377 | send "step\n" | |
378 | expect { | |
379 | -re "xmalloc.*size=.*at.*utils.c.*$prompt $" { | |
380 | pass "$description" | |
381 | } | |
382 | -re ".*No such file or directory.\r\n$prompt $" { | |
383 | pass "$description (no source available)" | |
384 | } | |
385 | -re "A file or directory .* does not exist..\r\n$prompt $" { | |
386 | pass "$description (no source available)" | |
387 | } | |
388 | -re ".*$prompt $" { | |
389 | fail "$description" | |
390 | } | |
391 | timeout { | |
392 | fail "$description (timeout)" | |
393 | } | |
394 | } | |
395 | } | |
66b063c0 | 396 | |
ef44eed1 SS |
397 | # start the "xgdb" process |
398 | send "continue\n" | |
399 | expect { | |
400 | -re "GDB is free software and you are welcome to distribute copies of it.* | |
401 | under certain conditions; type \"show copying\" to see the conditions..* | |
402 | There is absolutely no warranty for GDB; type \"show warranty\" for details..* | |
403 | GDB.*Copyright \[0-9\]+ Free Software Foundation, Inc..*$prompt $"\ | |
404 | { pass "xgdb is at prompt" } | |
405 | -re ".*$prompt $" { fail "xgdb is at prompt" } | |
406 | timeout { fail "(timeout) xgdb is at prompt" } | |
407 | } | |
408 | ||
409 | # set xgdb prompt so we can tell which is which | |
410 | send "set prompt (xgdb) \n" | |
411 | expect { | |
412 | -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" { pass "Set xgdb prompt" } | |
413 | -re ".*$prompt $" { fail "Set xgdb prompt" } | |
414 | default { fail "(timeout) Set xgdb prompt" } | |
415 | } | |
416 | ||
417 | # kill the xgdb process | |
418 | set description "send ^C to child process" | |
419 | send "\003" | |
420 | expect { | |
421 | -re "Program received signal SIGINT.*$prompt $" { | |
422 | pass "$description" | |
423 | } | |
424 | -re ".*$prompt $" { | |
425 | fail "$description" | |
426 | } | |
427 | timeout { | |
428 | fail "$description (timeout)" | |
429 | } | |
430 | } | |
431 | ||
432 | set description "send SIGINT signal to child process" | |
433 | send "signal SIGINT\n" | |
434 | expect { | |
435 | -re "Continuing with signal SIGINT.*$prompt $" { | |
436 | pass "$description" | |
437 | } | |
438 | -re ".*$prompt $" { | |
439 | fail "$description" | |
440 | } | |
441 | timeout { | |
442 | fail "$description (timeout)" | |
443 | } | |
444 | } | |
445 | ||
446 | # get a stack trace | |
ef44eed1 SS |
447 | setup_xfail "i486-*-sysv4" |
448 | set description "backtrace through signal handler" | |
449 | send "backtrace\n" | |
450 | expect { | |
451 | -re "#0.*read.*#\[1-9\].*main.c.*$prompt $" { | |
452 | pass "$description" | |
453 | } | |
454 | -re ".*$prompt $" { | |
455 | fail "$description" | |
456 | } | |
457 | timeout { | |
458 | fail "$description (timeout)" | |
459 | } | |
460 | } | |
4a2170f0 JK |
461 | |
462 | gdb_exit | |
ef44eed1 SS |
463 | |
464 | # Set the timeout back to the value it had when we were called. | |
465 | set timeout $oldtimeout | |
466 | ||
467 | # Restart gdb in case next test expects it to be started already. | |
468 | gdb_start | |
469 | return 0 | |
470 | } | |
471 | ||
472 | # Find a pathname to a file that we would execute if the shell was asked | |
473 | # to run $arg using the current PATH. | |
474 | ||
475 | proc find_gdb { arg } { | |
476 | ||
477 | # If the arg directly specifies an existing executable file, then | |
478 | # simply use it. | |
479 | ||
480 | if [file executable $arg] then { | |
481 | return $arg | |
482 | } | |
483 | ||
484 | set result [which $arg] | |
485 | if [string match "/" [ string range $result 0 0 ]] then { | |
486 | return $result | |
487 | } | |
488 | ||
489 | # If everything fails, just return the unqualified pathname as default | |
490 | # and hope for best. | |
491 | ||
492 | return $arg | |
493 | } | |
494 | ||
495 | # Run the test with self. | |
496 | # Copy the file executable file in case this OS doesn't like to edit it's own | |
497 | # text space. | |
498 | ||
499 | set GDB_FULLPATH [find_gdb $GDB] | |
500 | ||
501 | # Remove any old copy lying around. | |
502 | catch "exec rm -f ./x$tool" | |
503 | ||
504 | if ![file executable $GDB_FULLPATH] then { | |
505 | fail "couldn't convert $GDB to absolute pathname to make local copy" | |
506 | } else { | |
507 | if [catch "exec cp $GDB_FULLPATH ./x$tool"] then { | |
508 | fail "couldn't copy $GDB_FULLPATH to current directory" | |
509 | } else { | |
510 | verbose "\t\tCopied $GDB_FULLPATH to ./x$tool" | |
511 | if {[test_with_self] <0} then { | |
512 | warning "Couldn't test self" | |
513 | catch "exec rm -f ./x$tool" | |
514 | return -1 | |
515 | } | |
516 | catch "exec rm -f ./x$tool" | |
517 | } | |
518 | } |