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