OSDN Git Service

f3e3ed33b5f317297679506b68f9502b39bb8ed4
[pf3gnuchains/pf3gnuchains4x.git] / gdb / testsuite / lib / gdb.exp
1 # Copyright (C) 1992, 1994, 1995, 1997, 1999 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 Fred Fish. (fnf@cygnus.com)
21
22 # Generic gdb subroutines that should work for any target.  If these
23 # need to be modified for any target, it can be done with a variable
24 # or by passing arguments.
25
26 load_lib libgloss.exp
27
28 global GDB
29 global CHILL_LIB
30 global CHILL_RT0
31
32 if ![info exists CHILL_LIB] {
33     set CHILL_LIB [findfile $base_dir/../../gcc/ch/runtime/libchill.a "$base_dir/../../gcc/ch/runtime/libchill.a" [transform -lchill]]
34 }
35 verbose "using CHILL_LIB = $CHILL_LIB" 2
36 if ![info exists CHILL_RT0] {
37     set CHILL_RT0 [findfile $base_dir/../../gcc/ch/runtime/chillrt0.o "$base_dir/../../gcc/ch/runtime/chillrt0.o" ""]
38 }
39 verbose "using CHILL_RT0 = $CHILL_RT0" 2
40
41 if [info exists TOOL_EXECUTABLE] {
42     set GDB $TOOL_EXECUTABLE;
43 }
44 if ![info exists GDB] {
45     if ![is_remote host] {
46         set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]]
47     } else {
48         set GDB [transform gdb];
49     }
50 }
51 verbose "using GDB = $GDB" 2
52
53 global GDBFLAGS
54 if ![info exists GDBFLAGS] {
55     set GDBFLAGS "-nx"
56 }
57 verbose "using GDBFLAGS = $GDBFLAGS" 2
58
59 # The variable gdb_prompt is a regexp which matches the gdb prompt.
60 # Set it if it is not already set.
61 global gdb_prompt
62 if ![info exists gdb_prompt] then {
63     set gdb_prompt "\[(\]gdb\[)\]"
64 }
65
66 ### Only procedures should come after this point.
67
68 #
69 # gdb_version -- extract and print the version number of GDB
70 #
71 proc default_gdb_version {} {
72     global GDB
73     global GDBFLAGS
74     global gdb_prompt
75     set fileid [open "gdb_cmd" w];
76     puts $fileid "q";
77     close $fileid;
78     set cmdfile [remote_download host "gdb_cmd"];
79     set output [remote_exec host "$GDB -nw --command $cmdfile"]
80     remote_file build delete "gdb_cmd";
81     remote_file host delete "$cmdfile";
82     set tmp [lindex $output 1];
83     set version ""
84     regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
85     if ![is_remote host] {
86         clone_output "[which $GDB] version $version $GDBFLAGS\n"
87     } else {
88         clone_output "$GDB on remote host version $version $GDBFLAGS\n"
89     }
90 }
91
92 proc gdb_version { } {
93     return [default_gdb_version];
94 }
95
96 #
97 # gdb_unload -- unload a file if one is loaded
98 #
99
100 proc gdb_unload {} {
101     global verbose
102     global GDB
103     global gdb_prompt
104     send_gdb "file\n"
105     gdb_expect 60 {
106         -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
107         -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
108         -re "A program is being debugged already..*Kill it.*y or n. $"\
109             { send_gdb "y\n"
110                 verbose "\t\tKilling previous program being debugged"
111             exp_continue
112         }
113         -re "Discard symbol table from .*y or n.*$" {
114             send_gdb "y\n"
115             exp_continue
116         }
117         -re "$gdb_prompt $" {}
118         timeout {
119             perror "couldn't unload file in $GDB (timed out)."
120             return -1
121         }
122     }
123 }
124
125 # Many of the tests depend on setting breakpoints at various places and
126 # running until that breakpoint is reached.  At times, we want to start
127 # with a clean-slate with respect to breakpoints, so this utility proc 
128 # lets us do this without duplicating this code everywhere.
129 #
130
131 proc delete_breakpoints {} {
132     global gdb_prompt
133
134     # we need a larger timeout value here or this thing just confuses
135     # itself.  May need a better implementation if possible. - guo
136     #
137     send_gdb "delete breakpoints\n"
138     gdb_expect 100 {
139          -re "Delete all breakpoints.*y or n.*$" {
140             send_gdb "y\n";
141             exp_continue
142         }
143          -re "$gdb_prompt $" { # This happens if there were no breakpoints
144             }
145          timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
146     }
147     send_gdb "info breakpoints\n"
148     gdb_expect 100 {
149          -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
150          -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
151          -re "Delete all breakpoints.*or n.*$" {
152             send_gdb "y\n";
153             exp_continue
154         }
155          timeout { perror "info breakpoints (timeout)" ; return }
156     }
157 }
158
159
160 #
161 # Generic run command.
162 #
163 # The second pattern below matches up to the first newline *only*.
164 # Using ``.*$'' could swallow up output that we attempt to match
165 # elsewhere.
166 #
167 proc gdb_run_cmd {args} {
168     global gdb_prompt
169
170     if [target_info exists gdb_init_command] {
171         send_gdb "[target_info gdb_init_command]\n";
172         gdb_expect 30 {
173             -re "$gdb_prompt $" { }
174             default {
175                 perror "gdb_init_command for target failed";
176                 return;
177             }
178         }
179     }
180
181     if [target_info exists use_gdb_stub] {
182         if [target_info exists gdb,do_reload_on_run] {
183             # Specifying no file, defaults to the executable
184             # currently being debugged.
185             if { [gdb_load ""] < 0 } {
186                 return;
187             }
188             send_gdb "continue\n";
189             gdb_expect 60 {
190                 -re "Continu\[^\r\n\]*\[\r\n\]" {}
191                 default {}
192             }
193             return;
194         }
195
196         if [target_info exists gdb,start_symbol] {
197             set start [target_info gdb,start_symbol];
198         } else {
199             set start "start";
200         }
201         send_gdb  "jump *$start\n"
202         set start_attempt 1;
203         while { $start_attempt } {
204             # Cap (re)start attempts at three to ensure that this loop
205             # always eventually fails.  Don't worry about trying to be
206             # clever and not send a command when it has failed.
207             if [expr $start_attempt > 3] {
208                 perror "Jump to start() failed (retry count exceeded)";
209                 return;
210             }
211             set start_attempt [expr $start_attempt + 1];
212             gdb_expect 30 {
213                 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
214                     set start_attempt 0;
215                 }
216                 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
217                     perror "Can't find start symbol to run in gdb_run";
218                     return;
219                 }
220                 -re "No symbol \"start\" in current.*$gdb_prompt $" {
221                     send_gdb "jump *_start\n";
222                 }
223                 -re "No symbol.*context.*$gdb_prompt $" {
224                     set start_attempt 0;
225                 }
226                 -re "Line.* Jump anyway.*y or n. $" {
227                     send_gdb "y\n"
228                 }
229                 -re "The program is not being run.*$gdb_prompt $" {
230                     if { [gdb_load ""] < 0 } {
231                         return;
232                     }
233                     send_gdb "jump *$start\n";
234                 }
235                 timeout {
236                     perror "Jump to start() failed (timeout)"; 
237                     return
238                 }
239             }
240         }
241         if [target_info exists gdb_stub] {
242             gdb_expect 60 {
243                 -re "$gdb_prompt $" {
244                     send_gdb "continue\n"
245                 }
246             }
247         }
248         return
249     }
250     send_gdb "run $args\n"
251 # This doesn't work quite right yet.
252     gdb_expect 60 {
253         -re "The program .* has been started already.*y or n. $" {
254             send_gdb "y\n"
255             exp_continue
256         }
257         -re "Starting program: \[^\r\n\]*" {}
258     }
259 }
260
261 proc gdb_breakpoint { function } {
262     global gdb_prompt
263     global decimal
264
265     send_gdb "break $function\n"
266     # The first two regexps are what we get with -g, the third is without -g.
267     gdb_expect 30 {
268         -re "Breakpoint \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
269         -re "Breakpoint \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
270         -re "Breakpoint \[0-9\]* at .*$gdb_prompt $" {}
271         -re "$gdb_prompt $" { fail "setting breakpoint at $function" ; return 0 }
272         timeout { fail "setting breakpoint at $function (timeout)" ; return 0 }
273     }
274     return 1;
275 }    
276
277 # Set breakpoint at function and run gdb until it breaks there.
278 # Since this is the only breakpoint that will be set, if it stops
279 # at a breakpoint, we will assume it is the one we want.  We can't
280 # just compare to "function" because it might be a fully qualified,
281 # single quoted C++ function specifier.
282
283 proc runto { function } {
284     global gdb_prompt
285     global decimal
286
287     delete_breakpoints
288
289     if ![gdb_breakpoint $function] {
290         return 0;
291     }
292
293     gdb_run_cmd
294     
295     # the "at foo.c:36" output we get with -g.
296     # the "in func" output we get without -g.
297     gdb_expect 30 {
298         -re "Break.* at .*:$decimal.*$gdb_prompt $" {
299             return 1
300         }
301         -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" { 
302             return 1
303         }
304         -re "$gdb_prompt $" { 
305             fail "running to $function in runto"
306             return 0
307         }
308         timeout { 
309             fail "running to $function in runto (timeout)"
310             return 0
311         }
312     }
313     return 1
314 }
315
316 #
317 # runto_main -- ask gdb to run until we hit a breakpoint at main.
318 #               The case where the target uses stubs has to be handled
319 #               specially--if it uses stubs, assuming we hit
320 #               breakpoint() and just step out of the function.
321 #
322 proc runto_main { } {
323     global gdb_prompt
324     global decimal
325
326     if ![target_info exists gdb_stub] {
327         return [runto main]
328     }                   
329
330     delete_breakpoints
331
332     gdb_step_for_stub;
333
334     return 1
335 }
336
337
338 # gdb_test COMMAND PATTERN MESSAGE -- send a command to gdb; test the result.
339 #
340 # COMMAND is the command to execute, send to GDB with send_gdb.  If
341 #   this is the null string no command is sent.
342 # PATTERN is the pattern to match for a PASS, and must NOT include
343 #   the \r\n sequence immediately before the gdb prompt.
344 # MESSAGE is an optional message to be printed.  If this is
345 #   omitted, then the pass/fail messages use the command string as the
346 #   message.  (If this is the empty string, then sometimes we don't
347 #   call pass or fail at all; I don't understand this at all.)
348 #
349 # Returns:
350 #    1 if the test failed,
351 #    0 if the test passes,
352 #   -1 if there was an internal error.
353 #  
354 proc gdb_test { args } {
355     global verbose
356     global gdb_prompt
357     global GDB
358     upvar timeout timeout
359
360     if [llength $args]>2 then {
361         set message [lindex $args 2]
362     } else {
363         set message [lindex $args 0]
364     }
365     set command [lindex $args 0]
366     set pattern [lindex $args 1]
367
368     if [llength $args]==5 {
369         set question_string [lindex $args 3];
370         set response_string [lindex $args 4];
371     } else {
372         set question_string "^FOOBAR$"
373     }
374
375     if $verbose>2 then {
376         send_user "Sending \"$command\" to gdb\n"
377         send_user "Looking to match \"$pattern\"\n"
378         send_user "Message is \"$message\"\n"
379     }
380
381     set result -1
382     set string "${command}\n";
383     if { $command != "" } {
384         while { "$string" != "" } {
385             set foo [string first "\n" "$string"];
386             set len [string length "$string"];
387             if { $foo < [expr $len - 1] } {
388                 set str [string range "$string" 0 $foo];
389                 if { [send_gdb "$str"] != "" } {
390                     global suppress_flag;
391
392                     if { ! $suppress_flag } {
393                         perror "Couldn't send $command to GDB.";
394                     }
395                     fail "$message";
396                     return $result;
397                 }
398                 # since we're checking if each line of the multi-line
399                 # command are 'accepted' by GDB here,
400                 # we need to set -notransfer expect option so that
401                 # command output is not lost for pattern matching
402                 # - guo
403                 gdb_expect -notransfer 2 {
404                     -re "\[\r\n\]" { }
405                     timeout { }
406                 }
407                 set string [string range "$string" [expr $foo + 1] end];
408             } else {
409                 break;
410             }
411         }
412         if { "$string" != "" } {
413             if { [send_gdb "$string"] != "" } {
414                 global suppress_flag;
415
416                 if { ! $suppress_flag } {
417                     perror "Couldn't send $command to GDB.";
418                 }
419                 fail "$message";
420                 return $result;
421             }
422         }
423     }
424
425     if [info exists timeout] {
426         set tmt $timeout;
427     } else {
428         global timeout;
429         if [info exists timeout] {
430             set tmt $timeout;
431         } else {
432             set tmt 60;
433         }
434     }
435     gdb_expect $tmt {
436          -re "\\*\\*\\* DOSEXIT code.*" {
437              if { $message != "" } {
438                  fail "$message";
439              }
440              gdb_suppress_entire_file "GDB died";
441              return -1;
442          }
443          -re "Ending remote debugging.*$gdb_prompt $" {
444             if ![isnative] then {
445                 warning "Can`t communicate to remote target."
446             }
447             gdb_exit
448             gdb_start
449             set result -1
450         }
451          -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
452             if ![string match "" $message] then {
453                 pass "$message"
454             }
455             set result 0
456         }
457          -re "(${question_string})$" {
458             send_gdb "$response_string\n";
459             exp_continue;
460         }
461          -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
462             perror "Undefined command \"$command\"."
463             fail "$message"
464             set result 1
465         }
466          -re "Ambiguous command.*$gdb_prompt $" {
467             perror "\"$command\" is not a unique command name."
468             fail "$message"
469             set result 1
470         }
471          -re "Program exited with code \[0-9\]+.*$gdb_prompt $" {
472             if ![string match "" $message] then {
473                 set errmsg "$message: the program exited"
474             } else {
475                 set errmsg "$command: the program exited"
476             }
477             fail "$errmsg"
478             return -1
479         }
480          -re "The program is not being run.*$gdb_prompt $" {
481             if ![string match "" $message] then {
482                 set errmsg "$message: the program is no longer running"
483             } else {
484                 set errmsg "$command: the program is no longer running"
485             }
486             fail "$errmsg"
487             return -1
488         }
489          -re ".*$gdb_prompt $" {
490             if ![string match "" $message] then {
491                 fail "$message"
492             }
493             set result 1
494         }
495          "<return>" {
496             send_gdb "\n"
497             perror "Window too small."
498             fail "$message"
499         }
500          -re "\\(y or n\\) " {
501             send_gdb "n\n"
502             perror "Got interactive prompt."
503             fail "$message"
504         }
505          eof {
506              perror "Process no longer exists"
507              if { $message != "" } {
508                  fail "$message"
509              }
510              return -1
511         }
512          full_buffer {
513             perror "internal buffer is full."
514             fail "$message"
515         }
516         timeout {
517             if ![string match "" $message] then {
518                 fail "$message (timeout)"
519             }
520             set result 1
521         }
522     }
523     return $result
524 }
525 \f
526 # Test that a command gives an error.  For pass or fail, return
527 # a 1 to indicate that more tests can proceed.  However a timeout
528 # is a serious error, generates a special fail message, and causes
529 # a 0 to be returned to indicate that more tests are likely to fail
530 # as well.
531
532 proc test_print_reject { args } {
533     global gdb_prompt
534     global verbose
535
536     if [llength $args]==2 then {
537         set expectthis [lindex $args 1]
538     } else {
539         set expectthis "should never match this bogus string"
540     }
541     set sendthis [lindex $args 0]
542     if $verbose>2 then {
543         send_user "Sending \"$sendthis\" to gdb\n"
544         send_user "Looking to match \"$expectthis\"\n"
545     }
546     send_gdb "$sendthis\n"
547     #FIXME: Should add timeout as parameter.
548     gdb_expect {
549         -re "A .* in expression.*\\.*$gdb_prompt $" {
550             pass "reject $sendthis"
551             return 1
552         }
553         -re "Invalid syntax in expression.*$gdb_prompt $" {
554             pass "reject $sendthis"
555             return 1
556         }
557         -re "Junk after end of expression.*$gdb_prompt $" {
558             pass "reject $sendthis"
559             return 1
560         }
561         -re "Invalid number.*$gdb_prompt $" {
562             pass "reject $sendthis"
563             return 1
564         }
565         -re "Invalid character constant.*$gdb_prompt $" {
566             pass "reject $sendthis"
567             return 1
568         }
569         -re "No symbol table is loaded.*$gdb_prompt $" {
570             pass "reject $sendthis"
571             return 1
572         }
573         -re "No symbol .* in current context.*$gdb_prompt $" {
574             pass "reject $sendthis"
575             return 1
576         }
577         -re "$expectthis.*$gdb_prompt $" {
578             pass "reject $sendthis"
579             return 1
580         }
581         -re ".*$gdb_prompt $" {
582             fail "reject $sendthis"
583             return 1
584         }
585         default {
586             fail "reject $sendthis (eof or timeout)"
587             return 0
588         }
589     }
590 }
591 \f
592 # Given an input string, adds backslashes as needed to create a
593 # regexp that will match the string.
594
595 proc string_to_regexp {str} {
596     set result $str
597     regsub -all {[]*+.|()^$\[]} $str {\\&} result
598     return $result
599 }
600
601 # Same as gdb_test, but the second parameter is not a regexp,
602 # but a string that must match exactly.
603
604 proc gdb_test_exact { args } {
605     upvar timeout timeout
606
607     set command [lindex $args 0]
608
609     # This applies a special meaning to a null string pattern.  Without
610     # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
611     # messages from commands that should have no output except a new
612     # prompt.  With this, only results of a null string will match a null
613     # string pattern.
614
615     set pattern [lindex $args 1]
616     if [string match $pattern ""] {
617         set pattern [string_to_regexp [lindex $args 0]]
618     } else {
619         set pattern [string_to_regexp [lindex $args 1]]
620     }
621
622     # It is most natural to write the pattern argument with only
623     # embedded \n's, especially if you are trying to avoid Tcl quoting
624     # problems.  But gdb_expect really wants to see \r\n in patterns.  So
625     # transform the pattern here.  First transform \r\n back to \n, in
626     # case some users of gdb_test_exact already do the right thing.
627     regsub -all "\r\n" $pattern "\n" pattern
628     regsub -all "\n" $pattern "\r\n" pattern
629     if [llength $args]==3 then {
630         set message [lindex $args 2]
631     } else {
632         set message $command
633     }
634
635     return [gdb_test $command $pattern $message]
636 }
637 \f
638 proc gdb_reinitialize_dir { subdir } {
639     global gdb_prompt
640
641     if [is_remote host] {
642         return "";
643     }
644     send_gdb "dir\n"
645     gdb_expect 60 {
646         -re "Reinitialize source path to empty.*y or n. " {
647             send_gdb "y\n"
648             gdb_expect 60 {
649                 -re "Source directories searched.*$gdb_prompt $" {
650                     send_gdb "dir $subdir\n"
651                     gdb_expect 60 {
652                         -re "Source directories searched.*$gdb_prompt $" {
653                             verbose "Dir set to $subdir"
654                         }
655                         -re "$gdb_prompt $" {
656                             perror "Dir \"$subdir\" failed."
657                         }
658                     }
659                 }
660                 -re "$gdb_prompt $" {
661                     perror "Dir \"$subdir\" failed."
662                 }
663             }
664         }
665         -re "$gdb_prompt $" {
666             perror "Dir \"$subdir\" failed."
667         }
668     }
669 }
670
671 #
672 # gdb_exit -- exit the GDB, killing the target program if necessary
673 #
674 proc default_gdb_exit {} {
675     global GDB
676     global GDBFLAGS
677     global verbose
678     global gdb_spawn_id;
679
680     gdb_stop_suppressing_tests;
681
682     if ![info exists gdb_spawn_id] {
683         return;
684     }
685
686     verbose "Quitting $GDB $GDBFLAGS"
687
688     if { [is_remote host] && [board_info host exists fileid] } {
689         send_gdb "quit\n";
690         gdb_expect 10 {
691             -re "y or n" {
692                 send_gdb "y\n";
693                 exp_continue;
694             }
695             -re "DOSEXIT code" { }
696             default { }
697         }
698     }
699
700     if ![is_remote host] {
701         remote_close host;
702     }
703     unset gdb_spawn_id
704 }
705
706 #
707 # load a file into the debugger.
708 # return a -1 if anything goes wrong.
709 #
710 proc gdb_file_cmd { arg } {
711     global verbose
712     global loadpath
713     global loadfile
714     global GDB
715     global gdb_prompt
716     upvar timeout timeout
717
718     if [is_remote host] {
719         set arg [remote_download host $arg];
720         if { $arg == "" } {
721             error "download failed"
722             return -1;
723         }
724     }
725
726     send_gdb "file $arg\n"
727     gdb_expect 120 {
728         -re "Reading symbols from.*done.*$gdb_prompt $" {
729             verbose "\t\tLoaded $arg into the $GDB"
730             return 0
731         }
732         -re "has no symbol-table.*$gdb_prompt $" {
733             perror "$arg wasn't compiled with \"-g\""
734             return -1
735         }
736         -re "A program is being debugged already.*Kill it.*y or n. $" {
737             send_gdb "y\n"
738                 verbose "\t\tKilling previous program being debugged"
739             exp_continue
740         }
741         -re "Load new symbol table from \".*\".*y or n. $" {
742             send_gdb "y\n"
743             gdb_expect 120 {
744                 -re "Reading symbols from.*done.*$gdb_prompt $" {
745                     verbose "\t\tLoaded $arg with new symbol table into $GDB"
746                     return 0
747                 }
748                 timeout {
749                     perror "(timeout) Couldn't load $arg, other program already loaded."
750                     return -1
751                 }
752             }
753         }
754         -re "No such file or directory.*$gdb_prompt $" {
755             perror "($arg) No such file or directory\n"
756             return -1
757         }
758         -re "$gdb_prompt $" {
759             perror "couldn't load $arg into $GDB."
760             return -1
761             }
762         timeout {
763             perror "couldn't load $arg into $GDB (timed out)."
764             return -1
765         }
766         eof {
767             # This is an attempt to detect a core dump, but seems not to
768             # work.  Perhaps we need to match .* followed by eof, in which
769             # gdb_expect does not seem to have a way to do that.
770             perror "couldn't load $arg into $GDB (end of file)."
771             return -1
772         }
773     }
774 }
775
776 #
777 # start gdb -- start gdb running, default procedure
778 #
779 # When running over NFS, particularly if running many simultaneous
780 # tests on different hosts all using the same server, things can
781 # get really slow.  Give gdb at least 3 minutes to start up.
782 #
783 proc default_gdb_start { } {
784     global verbose
785     global GDB
786     global GDBFLAGS
787     global gdb_prompt
788     global timeout
789     global gdb_spawn_id;
790
791     gdb_stop_suppressing_tests;
792
793     verbose "Spawning $GDB -nw $GDBFLAGS"
794
795     if [info exists gdb_spawn_id] {
796         return 0;
797     }
798
799     if ![is_remote host] {
800         if { [which $GDB] == 0 } then {
801             perror "$GDB does not exist."
802             exit 1
803         }
804     }
805     set res [remote_spawn host "$GDB -nw $GDBFLAGS [host_info gdb_opts]"];
806     if { $res < 0 || $res == "" } {
807         perror "Spawning $GDB failed."
808         return 1;
809     }
810     gdb_expect 360 {
811         -re "\[\r\n\]$gdb_prompt $" {
812             verbose "GDB initialized."
813         }
814         -re "$gdb_prompt $"     {
815             perror "GDB never initialized."
816             return -1
817         }
818         timeout {
819             perror "(timeout) GDB never initialized after 10 seconds."
820             remote_close host;
821             return -1
822         }
823     }
824     set gdb_spawn_id -1;
825     # force the height to "unlimited", so no pagers get used
826
827     send_gdb "set height 0\n"
828     gdb_expect 10 {
829         -re "$gdb_prompt $" { 
830             verbose "Setting height to 0." 2
831         }
832         timeout {
833             warning "Couldn't set the height to 0"
834         }
835     }
836     # force the width to "unlimited", so no wraparound occurs
837     send_gdb "set width 0\n"
838     gdb_expect 10 {
839         -re "$gdb_prompt $" {
840             verbose "Setting width to 0." 2
841         }
842         timeout {
843             warning "Couldn't set the width to 0."
844         }
845     }
846     return 0;
847 }
848
849 # Return a 1 for configurations for which we don't even want to try to
850 # test C++.
851
852 proc skip_cplus_tests {} {
853     if { [istarget "d10v-*-*"] } {
854         return 1
855     }
856     if { [istarget "h8300-*-*"] } {
857         return 1
858     }
859     return 0
860 }
861
862 # * For crosses, the CHILL runtime doesn't build because it can't find
863 # setjmp.h, stdio.h, etc.
864 # * For AIX (as of 16 Mar 95), (a) there is no language code for
865 # CHILL in output_epilog in gcc/config/rs6000/rs6000.c, (b) collect2
866 # does not get along with AIX's too-clever linker.
867 # * On Irix5, there is a bug whereby set of bool, etc., don't get
868 # TYPE_LOW_BOUND for the bool right because force_to_range_type doesn't
869 # work with stub types.
870 # Lots of things seem to fail on the PA, and since it's not a supported
871 # chill target at the moment, don't run the chill tests.
872
873 proc skip_chill_tests {} {
874     if ![info exists do_chill_tests] {
875         return 1;
876     }
877     eval set skip_chill [expr ![isnative] || [istarget "*-*-aix*"] || [istarget "*-*-irix5*"] || [istarget "*-*-irix6*"] || [istarget "alpha-*-osf*"] || [istarget "hppa*-*-*"]]
878     verbose "Skip chill tests is $skip_chill"
879     return $skip_chill
880 }
881
882 # Skip all the tests in the file if you are not on an hppa running
883 # hpux target.
884
885 proc skip_hp_tests {} {
886     eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
887     verbose "Skip hp tests is $skip_hp"
888     return $skip_hp
889 }
890
891 proc get_compiler_info {binfile args} {
892     # Create and source the file that provides information about the compiler
893     # used to compile the test case.
894     # Compiler_type can be null or c++. If null we assume c.
895     global srcdir
896     global subdir
897     # These two come from compiler.c.
898     global signed_keyword_not_used
899     global gcc_compiled
900
901     if {![istarget "hppa*-*-hpux*"]} {
902         if { [llength $args] > 0 } {
903             if {$args == "c++"} {
904                 if { [gdb_compile "${srcdir}/${subdir}/compiler.cc" "${binfile}.ci" preprocess {}] != "" } {
905                     perror "Couldn't make ${binfile}.ci file"
906                     return 1;
907                 }
908             }
909         } else {
910             if { [gdb_compile "${srcdir}/${subdir}/compiler.c" "${binfile}.ci" preprocess {}] != "" } {
911                 perror "Couldn't make ${binfile}.ci file"
912                 return 1;
913             }
914         }
915     } else {
916         if { [llength $args] > 0 } {
917             if {$args == "c++"} {
918                 if { [eval gdb_preprocess \
919                         [list "${srcdir}/${subdir}/compiler.cc" "${binfile}.ci"] \
920                         $args] != "" } {
921                     perror "Couldn't make ${binfile}.ci file"
922                     return 1;
923                 }
924             }
925         } elseif { $args != "f77" } {
926             if { [eval gdb_preprocess \
927                     [list "${srcdir}/${subdir}/compiler.c" "${binfile}.ci"] \
928                     $args] != "" } {
929                 perror "Couldn't make ${binfile}.ci file"
930                 return 1;
931             }
932         }
933     }
934     
935     uplevel \#0 { set gcc_compiled 0 }
936
937     if { [llength $args] == 0 || $args != "f77" } {
938         source ${binfile}.ci
939     }
940
941     # Most compilers will evaluate comparisons and other boolean
942     # operations to 0 or 1.
943     uplevel \#0 { set true 1 }
944     uplevel \#0 { set false 0 }
945
946     uplevel \#0 { set hp_cc_compiler 0 }
947     uplevel \#0 { set hp_aCC_compiler 0 }
948     uplevel \#0 { set hp_f77_compiler 0 }
949     uplevel \#0 { set hp_f90_compiler 0 }
950     if { !$gcc_compiled && [istarget "hppa*-*-hpux*"] } {
951         # Check for the HP compilers
952         set compiler [lindex [split [get_compiler $args] " "] 0]
953         catch "exec what $compiler" output
954         if [regexp ".*HP aC\\+\\+.*" $output] {
955             uplevel \#0 { set hp_aCC_compiler 1 }
956             # Use of aCC results in boolean results being displayed as
957             # "true" or "false"
958             uplevel \#0 { set true true }
959             uplevel \#0 { set false false }
960         } elseif [regexp ".*HP C Compiler.*" $output] {
961             uplevel \#0 { set hp_cc_compiler 1 }
962         } elseif [regexp ".*HP-UX f77.*" $output] {
963             uplevel \#0 { set hp_f77_compiler 1 }
964         } elseif [regexp ".*HP-UX f90.*" $output] {
965             uplevel \#0 { set hp_f90_compiler 1 }
966         }
967     }
968
969     return 0;
970 }
971
972 proc get_compiler {args} {
973     global CC CC_FOR_TARGET CXX CXX_FOR_TARGET F77_FOR_TARGET
974
975     if { [llength $args] == 0 
976          || ([llength $args] == 1 && [lindex $args 0] == "") } {
977         set which_compiler "c"
978     } else {
979         if { $args =="c++" } {
980             set which_compiler "c++"
981         } elseif { $args =="f77" } {
982             set which_compiler "f77"
983         } else {
984             perror "Unknown compiler type supplied to gdb_preprocess"
985             return ""
986         }
987     }
988
989     if [info exists CC_FOR_TARGET] {
990         if {$which_compiler == "c"} {
991             set compiler $CC_FOR_TARGET
992         }
993     }
994  
995     if [info exists CXX_FOR_TARGET] {
996         if {$which_compiler == "c++"} {
997             set compiler $CXX_FOR_TARGET
998         }
999     }
1000
1001     if [info exists F77_FOR_TARGET] {
1002         if {$which_compiler == "f77"} {
1003             set compiler $F77_FOR_TARGET
1004         }
1005     }
1006
1007     if { ![info exists compiler] } {
1008         if { $which_compiler == "c" } {
1009             if {[info exists CC]} {
1010                 set compiler $CC
1011             }
1012         }
1013         if { $which_compiler == "c++" } {
1014             if {[info exists CXX]} {
1015                 set compiler $CXX
1016             }
1017         }
1018         if {![info exists compiler]} {
1019             set compiler [board_info [target_info name] compiler];
1020             if { $compiler == "" } {
1021                 perror "get_compiler: No compiler found"
1022                 return ""
1023             }
1024         }
1025     }
1026
1027     return $compiler
1028 }
1029
1030 proc gdb_preprocess {source dest args} {
1031     set compiler [get_compiler "$args"]
1032     if { $compiler == "" } {
1033         return 1
1034     }
1035
1036     set cmdline "$compiler -E $source > $dest"
1037
1038     verbose "Invoking $compiler -E $source > $dest"
1039     verbose -log "Executing on local host: $cmdline" 2
1040     set status [catch "exec ${cmdline}" exec_output]
1041
1042     set result [prune_warnings $exec_output]
1043     regsub "\[\r\n\]*$" "$result" "" result;
1044     regsub "^\[\r\n\]*" "$result" "" result;
1045     if { $result != "" } {
1046         clone_output "gdb compile failed, $result"
1047     }
1048     return $result;
1049 }
1050
1051 proc gdb_compile {source dest type options} {
1052     global GDB_TESTCASE_OPTIONS;
1053
1054     if [target_info exists gdb_stub] {
1055         set options2 { "additional_flags=-Dusestubs" }
1056         lappend options "libs=[target_info gdb_stub]";
1057         set options [concat $options2 $options]
1058     }
1059     if [target_info exists is_vxworks] {
1060         set options2 { "additional_flags=-Dvxworks" }
1061         lappend options "libs=[target_info gdb_stub]";
1062         set options [concat $options2 $options]
1063     }
1064     if [info exists GDB_TESTCASE_OPTIONS] {
1065         lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
1066     }
1067     verbose "options are $options"
1068     verbose "source is $source $dest $type $options"
1069
1070     set result [target_compile $source $dest $type $options];
1071     regsub "\[\r\n\]*$" "$result" "" result;
1072     regsub "^\[\r\n\]*" "$result" "" result;
1073     if { $result != "" } {
1074         clone_output "gdb compile failed, $result"
1075     }
1076     return $result;
1077 }
1078
1079 proc send_gdb { string } {
1080     global suppress_flag;
1081     if { $suppress_flag } {
1082         return "suppressed";
1083     }
1084     return [remote_send host "$string"];
1085 }
1086
1087 #
1088 #
1089
1090 proc gdb_expect { args } {
1091     # allow -notransfer expect flag specification,
1092     # used by gdb_test routine for multi-line commands.
1093     # packed with gtimeout when fed to remote_expect routine,
1094     # which is a hack but due to what looks like a res and orig
1095     # parsing problem in remote_expect routine (dejagnu/lib/remote.exp):
1096     # what's fed into res is not removed from orig.
1097     # - guo
1098     if { [lindex $args 0] == "-notransfer" } {
1099         set notransfer -notransfer;
1100         set args [lrange $args 1 end];
1101     } else {
1102         set notransfer "";
1103     }
1104
1105     if { [llength $args] == 2  && [lindex $args 0] != "-re" } {
1106         set gtimeout [lindex $args 0];
1107         set expcode [list [lindex $args 1]];
1108     } else {
1109         upvar timeout timeout;
1110
1111         set expcode $args;
1112         if [target_info exists gdb,timeout] {
1113             if [info exists timeout] {
1114                 if { $timeout < [target_info gdb,timeout] } {
1115                     set gtimeout [target_info gdb,timeout];
1116                 } else {
1117                     set gtimeout $timeout;
1118                 }
1119             } else {
1120                 set gtimeout [target_info gdb,timeout];
1121             }
1122         }
1123
1124         if ![info exists gtimeout] {
1125             global timeout;
1126             if [info exists timeout] {
1127                 set gtimeout $timeout;
1128             } else {
1129                 # Eeeeew.
1130                 set gtimeout 60;
1131             }
1132         }
1133     }
1134     global suppress_flag;
1135     global remote_suppress_flag;
1136     if [info exists remote_suppress_flag] {
1137         set old_val $remote_suppress_flag;
1138     }
1139     if [info exists suppress_flag] {
1140         if { $suppress_flag } {
1141             set remote_suppress_flag 1;
1142         }
1143     }
1144     set code [catch \
1145         {uplevel remote_expect host "$gtimeout $notransfer" $expcode} string];
1146     if [info exists old_val] {
1147         set remote_suppress_flag $old_val;
1148     } else {
1149         if [info exists remote_suppress_flag] {
1150             unset remote_suppress_flag;
1151         }
1152     }
1153
1154     if {$code == 1} {
1155         global errorInfo errorCode;
1156
1157         return -code error -errorinfo $errorInfo -errorcode $errorCode $string
1158     } elseif {$code == 2} {
1159         return -code return $string
1160     } elseif {$code == 3} {
1161         return
1162     } elseif {$code > 4} {
1163         return -code $code $string
1164     }
1165 }
1166
1167 #
1168 # Check for long sequence of output by parts.
1169 # TEST: is the test message.
1170 # SENTINEL: Is the terminal pattern indicating that output has finished.
1171 # LIST: is the sequence of outputs to match.
1172 # If the sentinel is recognized early, it is considered an error.
1173 #
1174 proc gdb_expect_list {test sentinal list} {
1175     global gdb_prompt
1176     set index 0
1177     set ok 1
1178     while { ${index} < [llength ${list}] } {
1179         set pattern [lindex ${list} ${index}]
1180         set index [expr ${index} + 1]
1181         if { ${index} == [llength ${list}] } {
1182             if { ${ok} } {
1183                 gdb_expect {
1184                     -re "${pattern}${sentinal}" {
1185                         pass "${test}, pattern ${index} + sentinal"
1186                     }
1187                     timeout {
1188                         fail "${test}, pattern ${index} + sentinal (timeout)"
1189                         set ok 0
1190                     }
1191                 }
1192             } else {
1193                 fail "${test}, pattern ${index} + sentinal"
1194             }
1195         } else {
1196             if { ${ok} } {
1197                 gdb_expect {
1198                     -re "${pattern}" {
1199                         pass "${test}, pattern ${index}"
1200                     }
1201                     -re "${sentinal}" {
1202                         fail "${test}, pattern ${index}"
1203                         set ok 0
1204                     }
1205                     timeout {
1206                         fail "${test}, pattern ${index} (timeout)"
1207                         set ok 0
1208                     }
1209                 }
1210             } else {
1211                 fail "${test}, pattern ${index}"
1212             }
1213         }
1214     }
1215 }
1216
1217 #
1218 #
1219 proc gdb_suppress_entire_file { reason } {
1220     global suppress_flag;
1221
1222     warning "$reason\n";
1223     set suppress_flag -1;
1224 }
1225
1226 #
1227 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
1228 # gdb_expect to fail immediately (until the next call to 
1229 # gdb_stop_suppressing_tests).
1230 #
1231 proc gdb_suppress_tests { args } {
1232     global suppress_flag;
1233
1234     return;  # fnf - disable pending review of results where
1235              # testsuite ran better without this
1236     incr suppress_flag;
1237
1238     if { $suppress_flag == 1 } {
1239         if { [llength $args] > 0 } {
1240             warning "[lindex $args 0]\n";
1241         } else {
1242             warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
1243         }
1244     }
1245 }
1246
1247 #
1248 # Clear suppress_flag.
1249 #
1250 proc gdb_stop_suppressing_tests { } {
1251     global suppress_flag;
1252
1253     if [info exists suppress_flag] {
1254         if { $suppress_flag > 0 } {
1255             set suppress_flag 0;
1256             clone_output "Tests restarted.\n";
1257         }
1258     } else {
1259         set suppress_flag 0;
1260     }
1261 }
1262
1263 proc gdb_clear_suppressed { } {
1264     global suppress_flag;
1265
1266     set suppress_flag 0;
1267 }
1268
1269 proc gdb_start { } {
1270     default_gdb_start
1271 }
1272
1273 proc gdb_exit { } {
1274     catch default_gdb_exit
1275 }
1276
1277 #
1278 # gdb_load -- load a file into the debugger.
1279 #             return a -1 if anything goes wrong.
1280 #
1281 proc gdb_load { arg } {
1282     return [gdb_file_cmd $arg]
1283 }
1284
1285 proc gdb_continue { function } {
1286     global decimal
1287
1288     return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
1289 }
1290
1291 proc default_gdb_init { args } {
1292     gdb_clear_suppressed;
1293
1294     # Uh, this is lame. Really, really, really lame. But there's this *one*
1295     # testcase that will fail in random places if we don't increase this.
1296     match_max -d 20000
1297
1298     # We want to add the name of the TCL testcase to the PASS/FAIL messages.
1299     if { [llength $args] > 0 } {
1300         global pf_prefix
1301
1302         set file [lindex $args 0];
1303
1304         set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
1305     }
1306     global gdb_prompt;
1307     if [target_info exists gdb_prompt] {
1308         set gdb_prompt [target_info gdb_prompt];
1309     } else {
1310         set gdb_prompt "\\(gdb\\)"
1311     }
1312 }
1313
1314 proc gdb_init { args } {
1315     return [eval default_gdb_init $args];
1316 }
1317
1318 proc gdb_finish { } {
1319     gdb_exit;
1320 }
1321
1322 global debug_format
1323 set debug_format "unknown"
1324
1325 # Run the gdb command "info source" and extract the debugging format
1326 # information from the output and save it in debug_format.
1327
1328 proc get_debug_format { } {
1329     global gdb_prompt
1330     global verbose
1331     global expect_out
1332     global debug_format
1333
1334     set debug_format "unknown"
1335     send_gdb "info source\n"
1336     gdb_expect 10 {
1337         -re "Compiled with (.*) debugging format.\r\n$gdb_prompt $" {
1338             set debug_format $expect_out(1,string)
1339             verbose "debug format is $debug_format"
1340             return 1;
1341         }
1342         -re "No current source file.\r\n$gdb_prompt $" {
1343             perror "get_debug_format used when no current source file"
1344             return 0;
1345         }
1346         -re "$gdb_prompt $" {
1347             warning "couldn't check debug format (no valid response)."
1348             return 1;
1349         }
1350         timeout {
1351             warning "couldn't check debug format (timed out)."
1352             return 1;
1353         }
1354     }
1355 }
1356
1357 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
1358 # COFF, stabs, etc).  If that format matches the format that the
1359 # current test was compiled with, then the next test is expected to
1360 # fail for any target.  Returns 1 if the next test or set of tests is
1361 # expected to fail, 0 otherwise (or if it is unknown).  Must have
1362 # previously called get_debug_format.
1363
1364 proc setup_xfail_format { format } {
1365     global debug_format
1366
1367     if [string match $debug_format $format] then {
1368         setup_xfail "*-*-*"
1369         return 1;
1370     }
1371     return 0
1372 }    
1373
1374 proc gdb_step_for_stub { } {
1375     global gdb_prompt;
1376
1377     if ![target_info exists gdb,use_breakpoint_for_stub] {
1378         if [target_info exists gdb_stub_step_command] {
1379             set command [target_info gdb_stub_step_command];
1380         } else {
1381             set command "step";
1382         }
1383         send_gdb "${command}\n";
1384         set tries 0;
1385         gdb_expect 60 {
1386             -re "(main.* at |.*in .*start).*$gdb_prompt" {
1387                 return;
1388             }
1389             -re ".*$gdb_prompt" {
1390                 incr tries;
1391                 if { $tries == 5 } {
1392                     fail "stepping out of breakpoint function";
1393                     return;
1394                 }
1395                 send_gdb "${command}\n";
1396                 exp_continue;
1397             }
1398             default {
1399                 fail "stepping out of breakpoint function";
1400                 return;
1401             }
1402         }
1403     }
1404     send_gdb "where\n";
1405     gdb_expect {
1406         -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" {
1407             set file $expect_out(1,string);
1408             set linenum [expr $expect_out(2,string) + 1];
1409             set breakplace "${file}:${linenum}";
1410         }
1411         default {}
1412     }
1413     send_gdb "break ${breakplace}\n";
1414     gdb_expect 60 {
1415         -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" {
1416             set breakpoint $expect_out(1,string);
1417         }
1418         -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" {
1419             set breakpoint $expect_out(1,string);
1420         }
1421         default {}
1422     }
1423     send_gdb "continue\n";
1424     gdb_expect 60 {
1425         -re "Breakpoint ${breakpoint},.*$gdb_prompt" {
1426             gdb_test "delete $breakpoint" ".*" "";
1427             return;
1428         }
1429         default {}
1430     }
1431 }
1432
1433 ### gdb_get_line_number TEXT [FILE]
1434 ###
1435 ### Search the source file FILE, and return the line number of a line
1436 ### containing TEXT.  Use this function instead of hard-coding line
1437 ### numbers into your test script.
1438 ###
1439 ### Specifically, this function uses GDB's "search" command to search
1440 ### FILE for the first line containing TEXT, and returns its line
1441 ### number.  Thus, FILE must be a source file, compiled into the
1442 ### executable you are running.  If omitted, FILE defaults to the
1443 ### value of the global variable `srcfile'; most test scripts set
1444 ### `srcfile' appropriately at the top anyway.
1445 ###
1446 ### Use this function to keep your test scripts independent of the
1447 ### exact line numbering of the source file.  Don't write:
1448 ### 
1449 ###   send_gdb "break 20"
1450 ### 
1451 ### This means that if anyone ever edits your test's source file, 
1452 ### your test could break.  Instead, put a comment like this on the
1453 ### source file line you want to break at:
1454 ### 
1455 ###   /* breakpoint spot: frotz.exp: test name */
1456 ### 
1457 ### and then write, in your test script (which we assume is named
1458 ### frotz.exp):
1459 ### 
1460 ###   send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
1461 ###
1462 ### (Yes, Tcl knows how to handle the nested quotes and brackets.
1463 ### Try this:
1464 ###     $ tclsh
1465 ###     % puts "foo [lindex "bar baz" 1]"
1466 ###     foo baz
1467 ###     % 
1468 ### Tcl is quite clever, for a little stringy language.)
1469
1470 proc gdb_get_line_number {text {file /omitted/}} {
1471     global gdb_prompt;
1472     global srcfile;
1473
1474     if {! [string compare $file /omitted/]} {
1475         set file $srcfile
1476     }
1477
1478     set result -1;
1479     gdb_test "list ${file}:1,1" ".*" ""
1480     send_gdb "search ${text}\n"
1481     gdb_expect {
1482         -re "\[\r\n\]+(\[0-9\]+)\[ \t\].*${text}.*$gdb_prompt $" {
1483             set result $expect_out(1,string)
1484         }
1485         -re ".*$gdb_prompt $" {
1486             fail "find line number containing \"${text}\""
1487         }
1488         timeout {
1489             fail "find line number containing \"${text}\" (timeout)"
1490         }
1491     }
1492     return $result;
1493 }
1494
1495 # gdb_continue_to_end:
1496 #       The case where the target uses stubs has to be handled specially. If a
1497 #       stub is used, we set a breakpoint at exit because we cannot rely on
1498 #       exit() behavior of a remote target.
1499
1500 # mssg is the error message that gets printed.
1501
1502 proc gdb_continue_to_end {mssg} {
1503   if [target_info exists use_gdb_stub] {
1504     if {![gdb_breakpoint "exit"]} {
1505       return 0
1506     }
1507     gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \
1508       "continue until exit at $mssg"
1509   } else {
1510     # Continue until we exit.  Should not stop again.
1511     # Don't bother to check the output of the program, that may be
1512     # extremely tough for some remote systems.
1513     gdb_test "continue"\
1514       "Continuing.\[\r\n0-9\]+Program exited normally\\..*"\
1515       "continue until exit at $mssg"
1516   }
1517 }
1518
1519 proc rerun_to_main {} {
1520   global gdb_prompt
1521
1522   if [target_info exists use_gdb_stub] {
1523     gdb_run_cmd
1524     gdb_expect {
1525       -re ".*Breakpoint .*main .*$gdb_prompt $"\
1526               {pass "rerun to main" ; return 0}
1527       -re "$gdb_prompt $"\
1528               {fail "rerun to main" ; return 0}
1529       timeout {fail "(timeout) rerun to main" ; return 0}
1530     }
1531   } else {
1532     send_gdb "run\n"
1533     gdb_expect {
1534       -re "Starting program.*$gdb_prompt $"\
1535               {pass "rerun to main" ; return 0}
1536       -re "$gdb_prompt $"\
1537               {fail "rerun to main" ; return 0}
1538       timeout {fail "(timeout) rerun to main" ; return 0}
1539     }
1540   }
1541 }
1542