* gdb.base/a1-selftest.exp (test_with_self): Run without windows.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / a1-selftest.exp
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 return
32 }
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 return -1
40 }
41
42 proc test_with_self {} {
43 global prompt
44 global tool
45 global det_file
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).
55 # After gdb is started, set the timeout to 30 seconds for the duration
56 # of this test, and then back to the original value.
57
58 set timeout 600
59 if {[gdb_load "./x$tool"] <0} then {
60 return -1
61 }
62
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
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
95 # run yourself
96 set description "run until breakpoint at main"
97 send "run -nw\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
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
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 setup_xfail "alpha-dec-osf2*"
158 set description "step over execarg initialization"
159 send "step\n"
160 expect {
161 -re "char \[*\]corearg = NULL;.*$prompt $" {
162 pass "$description"
163 }
164 -re ".*No such file or directory.\r\n$prompt $" {
165 pass "$description (no source available)"
166 }
167 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
168 pass "$description (no source available)"
169 }
170 -re ".*$prompt $" {
171 fail "$description"
172 }
173 timeout {
174 fail "$description (timeout)"
175 }
176 }
177
178 setup_xfail "alpha-dec-osf2*"
179 set description "step over corearg initialization"
180 send "step\n"
181 expect {
182 -re "char \[*\]cdarg = NULL;.*$prompt $" {
183 pass "$description"
184 }
185 -re ".*No such file or directory.\r\n$prompt $" {
186 pass "$description (no source available)"
187 }
188 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
189 pass "$description (no source available)"
190 }
191 -re ".*$prompt $" {
192 fail "$description"
193 }
194 timeout {
195 fail "$description (timeout)"
196 }
197 }
198
199 set description "step over cdarg initialization"
200 send "step\n"
201 expect {
202 -re "char \[*\]ttyarg = NULL;.*$prompt $" {
203 pass "$description"
204 }
205 -re ".*No such file or directory.\r\n$prompt $" {
206 pass "$description (no source available)"
207 }
208 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
209 pass "$description (no source available)"
210 }
211 -re ".*$prompt $" {
212 fail "$description"
213 }
214 timeout {
215 fail "$description (timeout)"
216 }
217 }
218
219 set description "step over ttyarg initialization"
220 send "step\n"
221 expect {
222 -re ".*time_at_startup = get_run_time .*$prompt $" {
223 pass "$description"
224 }
225 -re ".*No such file or directory.\r\n$prompt $" {
226 pass "$description (no source available)"
227 }
228 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
229 pass "$description (no source available)"
230 }
231 -re ".*$prompt $" {
232 fail "$description"
233 }
234 timeout {
235 fail "$description (timeout)"
236 }
237 }
238
239 # now jump over a few functions
240
241 set description "next over get_run_time and everything it calls"
242 set got_over_get_run_time 0
243 send "next\n"
244 expect {
245 -re ".*init_malloc.*$prompt $" {
246 pass "$description"
247 set got_over_get_run_time 1
248 }
249 -re ".*No such file or directory.\r\n$prompt $" {
250 pass "$description (no source available)"
251 set got_over_get_run_time 1
252 }
253 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
254 pass "$description (no source available)"
255 set got_over_get_run_time 1
256 }
257 -re ".*$prompt $" {
258 fail "$description"
259 }
260 timeout {
261 fail "$description (timeout)"
262 }
263 }
264 # -re "if \(setmp \(to_top_level\)\).*$prompt $" { pass "first next" }
265
266 if $got_over_get_run_time then {
267 set description "next over init_malloc and everything it calls"
268 send "next\n"
269 expect {
270 -re "if.*SET_TOP_LEVEL.*$prompt $" {
271 pass "$description"
272 }
273 -re "i = .*count.*$prompt $" {
274 pass "$description"
275 set description "next over ALIGN_STACK_ON_STARTUP code"
276 send "next\n"
277 expect {
278 -re "if.*i != 0.*$prompt $" {
279 pass "$description"
280 send "next\n"
281 expect {
282 -re "if.*SET_TOP_LEVEL.*$prompt $" {
283 pass "$description"
284 }
285 -re "alloca.*$prompt $" {
286 send "next\n"
287 expect {
288 -re "if.*level.*$prompt $" {
289 pass "$description"
290 }
291 }
292 }
293 }
294 }
295 }
296 }
297 -re ".*No such file or directory.\r\n$prompt $" {
298 pass "$description (no source available)"
299 }
300 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
301 pass "$description (no source available)"
302 }
303 -re ".*$prompt $" {
304 fail "$description"
305 }
306 default {
307 fail "$description (timeout or eof)"
308 }
309 }
310 }
311
312 set next_ok 1
313 set need_to_step_over_cmdsize 1
314 set description "next over SET_TOP_LEVEL call"
315 send "next\n"
316 expect {
317 -re "cmdsize = 1;.*$prompt $" {
318 pass "$description"
319 }
320 -re "cmdarg = .*xmalloc.*$prompt $" {
321 # This can happen in optimized code where the "cmdsize = 1" line
322 # is basically removed.
323 pass "$description"
324 set need_to_step_over_cmdsize 0
325 }
326 -re ".*No such file or directory.\r\n$prompt $" {
327 pass "$description (no source available)"
328 }
329 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
330 pass "$description (no source available)"
331 }
332 -re ".*$prompt $" {
333 fail "$description"
334 set next_ok 0
335 }
336 timeout {
337 fail "$description (timeout)"
338 set next_ok 0
339 }
340 }
341
342 set description "print a string"
343 send "print \"foo\"\n"
344 expect {
345 -re ".\[0-9\]+ = \"foo\".*$prompt $" {
346 pass "$description"
347 }
348 -re ".*$prompt $" {
349 fail "$description"
350 }
351 timeout {
352 fail "$description (timeout)"
353 }
354 }
355
356 if $need_to_step_over_cmdsize {
357 set description "step over cmdsize initialization"
358 send "step\n"
359 expect {
360 -re "cmdarg = .*xmalloc.*$prompt $" {
361 pass "$description"
362 }
363 -re ".*No such file or directory.\r\n$prompt $" {
364 pass "$description (no source available)"
365 }
366 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
367 pass "$description (no source available)"
368 }
369 -re ".*$prompt $" {
370 fail "$description"
371 }
372 timeout {
373 fail "$description (timeout)"
374 }
375 }
376 }
377
378 # and another step for good luck
379 if $next_ok {
380 set description "step into xmalloc call"
381 send "step\n"
382 expect {
383 -re "xmalloc.*size=.*at.*utils.c.*$prompt $" {
384 pass "$description"
385 }
386 -re ".*No such file or directory.\r\n$prompt $" {
387 pass "$description (no source available)"
388 }
389 -re "A file or directory .* does not exist..\r\n$prompt $" {
390 pass "$description (no source available)"
391 }
392 -re ".*$prompt $" {
393 fail "$description"
394 }
395 timeout {
396 fail "$description (timeout)"
397 }
398 }
399 }
400
401 # start the "xgdb" process
402 send "continue\n"
403 expect {
404 -re "GDB is free software and you are welcome to distribute copies of it.*
405 under certain conditions; type \"show copying\" to see the conditions..*
406 There is absolutely no warranty for GDB; type \"show warranty\" for details..*
407 GDB.*Copyright \[0-9\]+ Free Software Foundation, Inc..*$prompt $"\
408 { pass "xgdb is at prompt" }
409 -re ".*$prompt $" { fail "xgdb is at prompt" }
410 timeout { fail "(timeout) xgdb is at prompt" }
411 }
412
413 # set xgdb prompt so we can tell which is which
414 send "set prompt (xgdb) \n"
415 expect {
416 -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" { pass "Set xgdb prompt" }
417 -re ".*$prompt $" { fail "Set xgdb prompt" }
418 default { fail "(timeout) Set xgdb prompt" }
419 }
420
421 # kill the xgdb process
422 set description "send ^C to child process"
423 send "\003"
424 expect {
425 -re "Program received signal SIGINT.*$prompt $" {
426 pass "$description"
427 }
428 -re ".*$prompt $" {
429 fail "$description"
430 }
431 timeout {
432 fail "$description (timeout)"
433 }
434 }
435
436 set description "send SIGINT signal to child process"
437 send "signal SIGINT\n"
438 expect {
439 -re "Continuing with signal SIGINT.*$prompt $" {
440 pass "$description"
441 }
442 -re ".*$prompt $" {
443 fail "$description"
444 }
445 timeout {
446 fail "$description (timeout)"
447 }
448 }
449
450 # get a stack trace
451 setup_xfail "i*86-*-linuxaout"
452 set description "backtrace through signal handler"
453 send "backtrace\n"
454 expect {
455 -re "#0.*read.*in main \\(.*\\) at .*main\\.c.*$prompt $" {
456 pass "$description"
457 }
458 -re ".*$prompt $" {
459 # On the alpha, we hit the infamous problem about gdb
460 # being unable to get the frame pointer (mentioned in
461 # gdb/README). As it is intermittent, there is no way to
462 # XFAIL it which will give us an XPASS if the problem goes
463 # away.
464 setup_xfail "alpha*-*-osf*"
465 fail "$description"
466 }
467 timeout {
468 fail "$description (timeout)"
469 }
470 }
471
472 gdb_exit
473
474 # Set the timeout back to the value it had when we were called.
475
476 # Restart gdb in case next test expects it to be started already.
477 gdb_start
478 return 0
479 }
480
481 # Find a pathname to a file that we would execute if the shell was asked
482 # to run $arg using the current PATH.
483
484 proc find_gdb { arg } {
485
486 # If the arg directly specifies an existing executable file, then
487 # simply use it.
488
489 if [file executable $arg] then {
490 return $arg
491 }
492
493 set result [which $arg]
494 if [string match "/" [ string range $result 0 0 ]] then {
495 return $result
496 }
497
498 # If everything fails, just return the unqualified pathname as default
499 # and hope for best.
500
501 return $arg
502 }
503
504 # Run the test with self.
505 # Copy the file executable file in case this OS doesn't like to edit it's own
506 # text space.
507
508 set GDB_FULLPATH [find_gdb $GDB]
509
510 # Remove any old copy lying around.
511 catch "exec rm -f ./x$tool"
512
513 if ![file executable $GDB_FULLPATH] then {
514 fail "couldn't convert $GDB to absolute pathname to make local copy"
515 } else {
516 if [catch "exec cp $GDB_FULLPATH ./x$tool"] then {
517 fail "couldn't copy $GDB_FULLPATH to current directory"
518 } else {
519 verbose "\t\tCopied $GDB_FULLPATH to ./x$tool"
520 if {[test_with_self] <0} then {
521 warning "Couldn't test self"
522 catch "exec rm -f ./x$tool"
523 return -1
524 }
525 catch "exec rm -f ./x$tool"
526 }
527 }
This page took 0.068006 seconds and 4 git commands to generate.