5e6ce3d1a6e9339fcf78b53a4048e7a08237b021
[external/binutils.git] / gdb / testsuite / lib / gdb.exp
1 # Copyright (C) 1992, 1994, 1995, 1997 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 GDB] {
42     if ![is_remote host] {
43         set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]]
44     } else {
45         set GDB [transform gdb];
46     }
47 }
48 verbose "using GDB = $GDB" 2
49
50 global GDBFLAGS
51 if ![info exists GDBFLAGS] {
52     set GDBFLAGS "-nx"
53 }
54 verbose "using GDBFLAGS = $GDBFLAGS" 2
55
56 # The variable prompt is a regexp which matches the gdb prompt.  Set it if it
57 # is not already set.
58 global gdb_prompt
59 if ![info exists prompt] then {
60     set gdb_prompt "\[(\]gdb\[)\]"
61 }
62
63 #
64 # gdb_version -- extract and print the version number of GDB
65 #
66 proc default_gdb_version {} {
67     global GDB
68     global GDBFLAGS
69     global gdb_prompt
70     set fileid [open "gdb_cmd" w];
71     puts $fileid "q";
72     close $fileid;
73     set cmdfile [remote_download host "gdb_cmd"];
74     set output [remote_exec host "$GDB -nw --command $cmdfile"]
75     remote_file build delete "gdb_cmd";
76     remote_file host delete "$cmdfile";
77     set tmp [lindex $output 1];
78     set version ""
79     regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
80     if ![is_remote host] {
81         clone_output "[which $GDB] version $version $GDBFLAGS\n"
82     } else {
83         clone_output "$GDB on remote host version $version $GDBFLAGS\n"
84     }
85 }
86
87 proc gdb_version { } {
88     return [default_gdb_version];
89 }
90
91 #
92 # gdb_unload -- unload a file if one is loaded
93 #
94
95 proc gdb_unload {} {
96     global verbose
97     global GDB
98     global gdb_prompt
99     send_gdb "file\n"
100     gdb_expect 60 {
101         -re "No exec file now\[^\r\n\]*\[\r\n\]" { exp_continue }
102         -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
103         -re "A program is being debugged already..*Kill it.*y or n. $"\
104             { send_gdb "y\n"
105                 verbose "\t\tKilling previous program being debugged"
106             exp_continue
107         }
108         -re "Discard symbol table from .*y or n.*$" {
109             send_gdb "y\n"
110             exp_continue
111         }
112         -re "$gdb_prompt $" {}
113         timeout {
114             perror "couldn't unload file in $GDB (timed out)."
115             return -1
116         }
117     }
118 }
119
120 # Many of the tests depend on setting breakpoints at various places and
121 # running until that breakpoint is reached.  At times, we want to start
122 # with a clean-slate with respect to breakpoints, so this utility proc 
123 # lets us do this without duplicating this code everywhere.
124 #
125
126 proc delete_breakpoints {} {
127     global gdb_prompt
128
129     send_gdb "delete breakpoints\n"
130     gdb_expect 30 {
131          -re "Delete all breakpoints.*y or n.*$" {
132             send_gdb "y\n";
133             exp_continue
134         }
135          -re "$gdb_prompt $" { # This happens if there were no breakpoints
136             }
137          timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
138     }
139     send_gdb "info breakpoints\n"
140     gdb_expect 30 {
141          -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
142          -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
143          -re "Delete all breakpoints.*or n.*$" {
144             send_gdb "y\n";
145             exp_continue
146         }
147          timeout { perror "info breakpoints (timeout)" ; return }
148     }
149 }
150
151
152 #
153 # Generic run command.
154 #
155 # The second pattern below matches up to the first newline *only*.
156 # Using ``.*$'' could swallow up output that we attempt to match
157 # elsewhere.
158 #
159 proc gdb_run_cmd {args} {
160     global gdb_prompt
161
162     if [target_info exists gdb_init_command] {
163         send_gdb "[target_info gdb_init_command]\n";
164         gdb_expect 30 {
165             -re "$gdb_prompt $" { }
166             default {
167                 perror "gdb_init_command for target failed";
168                 return;
169             }
170         }
171     }
172
173     if [target_info exists use_gdb_stub] {
174         if [target_info exists gdb,start_symbol] {
175             set start [target_info gdb,start_symbol];
176         } else {
177             set start "start";
178         }
179         send_gdb  "jump *$start\n"
180         gdb_expect 30 {
181             -re "Continuing at \[^\r\n\]*\[\r\n\]" {
182                 if ![target_info exists gdb_stub] {
183                     return;
184                 }
185             }
186             -re "No symbol \"start\" in current.*$gdb_prompt $" {
187                 send_gdb "jump *_start\n";
188                 exp_continue;
189             }
190             -re "No symbol \"_start\" in current.*$gdb_prompt $" {
191                 perror "Can't find start symbol to run in gdb_run";
192                 return;
193             }
194             -re "Line.* Jump anyway.*y or n. $" {
195                 send_gdb "y\n"
196                 exp_continue;
197             }
198             -re "No symbol.*context.*$gdb_prompt $" {}
199             -re "The program is not being run.*$gdb_prompt $" {
200                 gdb_load "";
201                 send_gdb "jump *$start\n";
202                 exp_continue;
203             }
204             timeout { perror "Jump to start() failed (timeout)"; return }
205         }
206         if [target_info exists gdb_stub] {
207             gdb_expect 60 {
208                 -re "$gdb_prompt $" {
209                     send_gdb "continue\n"
210                 }
211             }
212         }
213         return
214     }
215     send_gdb "run $args\n"
216 # This doesn't work quite right yet.
217     gdb_expect 60 {
218         -re "The program .* has been started already.*y or n. $" {
219             send_gdb "y\n"
220             exp_continue
221         }
222         -re "Starting program: \[^\r\n\]*" {}
223     }
224 }
225
226 proc gdb_breakpoint { function } {
227     global gdb_prompt
228     global decimal
229
230     send_gdb "break $function\n"
231     # The first two regexps are what we get with -g, the third is without -g.
232     gdb_expect 30 {
233         -re "Breakpoint \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
234         -re "Breakpoint \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
235         -re "Breakpoint \[0-9\]* at .*$gdb_prompt $" {}
236         -re "$gdb_prompt $" { fail "setting breakpoint at $function" ; return 0 }
237         timeout { fail "setting breakpoint at $function (timeout)" ; return 0 }
238     }
239     return 1;
240 }    
241
242 # Set breakpoint at function and run gdb until it breaks there.
243 # Since this is the only breakpoint that will be set, if it stops
244 # at a breakpoint, we will assume it is the one we want.  We can't
245 # just compare to "function" because it might be a fully qualified,
246 # single quoted C++ function specifier.
247
248 proc runto { function } {
249     global gdb_prompt
250     global decimal
251
252     delete_breakpoints
253
254     if ![gdb_breakpoint $function] {
255         return 0;
256     }
257
258     gdb_run_cmd
259     
260     # the "at foo.c:36" output we get with -g.
261     # the "in func" output we get without -g.
262     gdb_expect 30 {
263         -re "Break.* at .*:$decimal.*$gdb_prompt $" {
264             return 1
265         }
266         -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" { 
267             return 1
268         }
269         -re "$gdb_prompt $" { 
270             fail "running to $function in runto"
271             return 0
272         }
273         timeout { 
274             fail "running to $function in runto (timeout)"
275             return 0
276         }
277     }
278     return 1
279 }
280
281 #
282 # runto_main -- ask gdb to run until we hit a breakpoint at main.
283 #               The case where the target uses stubs has to be handled
284 #               specially--if it uses stubs, assuming we hit
285 #               breakpoint() and just step out of the function.
286 #
287 proc runto_main {} {
288     global gdb_prompt
289     global decimal
290
291     if ![target_info exists gdb_stub] {
292         return [runto main]
293     }                   
294
295     delete_breakpoints
296
297     send_gdb "step\n"
298     # if use stubs step out of the breakpoint() function.
299     gdb_expect 120 {
300         -re "main.* at .*$gdb_prompt $" {}
301         -re "_start.*$gdb_prompt $" {}
302         timeout { fail "single step at breakpoint() (timeout)" ; return 0 }
303     }
304     return 1
305 }
306
307 #
308 # gdb_test -- send_gdb a command to gdb and test the result.
309 #             Takes three parameters.
310 #             Parameters:
311 #                First one is the command to execute.  If this is the null string
312 #                  then no command is sent.
313 #                Second one is the pattern to match for a PASS, and must NOT include
314 #                  the \r\n sequence immediately before the gdb prompt.
315 #                Third one is an optional message to be printed. If this
316 #                  a null string "", then the pass/fail messages use the command
317 #                  string as the message.
318 #             Returns:
319 #                1 if the test failed,
320 #                0 if the test passes,
321 #               -1 if there was an internal error.
322 #
323 proc gdb_test { args } {
324     global verbose
325     global gdb_prompt
326     global GDB
327     global expect_out
328     upvar timeout timeout
329
330     if [llength $args]>2 then {
331         set message [lindex $args 2]
332     } else {
333         set message [lindex $args 0]
334     }
335     set command [lindex $args 0]
336     set pattern [lindex $args 1]
337
338     if [llength $args]==5 {
339         set question_string [lindex $args 3];
340         set response_string [lindex $args 4];
341     } else {
342         set question_string "^FOOBAR$"
343     }
344
345     if $verbose>2 then {
346         send_user "Sending \"$command\" to gdb\n"
347         send_user "Looking to match \"$pattern\"\n"
348         send_user "Message is \"$message\"\n"
349     }
350
351     set result -1
352     if ![string match $command ""] {
353         if { [send_gdb "$command\n"] != "" } {
354             global suppress_flag;
355
356             if { ! $suppress_flag } {
357                 perror "Couldn't send $command to GDB.";
358             }
359             fail "$message";
360             return $result;
361         }
362     }
363
364     gdb_expect 600 {
365          -re "Ending remote debugging.*$gdb_prompt$" {
366             if ![isnative] then {
367                 warning "Can`t communicate to remote target."
368             }
369             gdb_exit
370             gdb_start
371             set result -1
372         }
373          -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
374             if ![string match "" $message] then {
375                 pass "$message"
376             }
377             set result 0
378         }
379          -re "(${question_string})$" {
380             send_gdb "$response_string\n";
381             exp_continue;
382         }
383          -re "Undefined command:.*$gdb_prompt" {
384             perror "Undefined command \"$command\"."
385             set result 1
386         }
387          -re "Ambiguous command.*$gdb_prompt $" {
388             perror "\"$command\" is not a unique command name."
389             set result 1
390         }
391          -re "Program exited with code \[0-9\]+.*$gdb_prompt $" {
392             if ![string match "" $message] then {
393                 set errmsg "$message: the program exited"
394             } else {
395                 set errmsg "$command: the program exited"
396             }
397             fail "$errmsg"
398             return -1
399         }
400          -re "The program is not being run.*$gdb_prompt $" {
401             if ![string match "" $message] then {
402                 set errmsg "$message: the program is no longer running"
403             } else {
404                 set errmsg "$command: the program is no longer running"
405             }
406             fail "$errmsg"
407             return -1
408         }
409          -re ".*$gdb_prompt $" {
410             if ![string match "" $message] then {
411                 fail "$message"
412             }
413             set result 1
414         }
415          "<return>" {
416             send_gdb "\n"
417             perror "Window too small."
418         }
419          -re "\\(y or n\\) " {
420             send_gdb "n\n"
421             perror "Got interactive prompt."
422         }
423          eof {
424              perror "Process no longer exists"
425              if { $message != "" } {
426                  fail "$message"
427              }
428              return -1
429         }
430          full_buffer {
431             perror "internal buffer is full."
432         }
433         timeout {
434             if ![string match "" $message] then {
435                 fail "$message (timeout)"
436             }
437             set result 1
438         }
439     }
440     return $result
441 }
442 \f
443 # Test that a command gives an error.  For pass or fail, return
444 # a 1 to indicate that more tests can proceed.  However a timeout
445 # is a serious error, generates a special fail message, and causes
446 # a 0 to be returned to indicate that more tests are likely to fail
447 # as well.
448
449 proc test_print_reject { args } {
450     global gdb_prompt
451     global verbose
452
453     if [llength $args]==2 then {
454         set expectthis [lindex $args 1]
455     } else {
456         set expectthis "should never match this bogus string"
457     }
458     set sendthis [lindex $args 0]
459     if $verbose>2 then {
460         send_user "Sending \"$sendthis\" to gdb\n"
461         send_user "Looking to match \"$expectthis\"\n"
462     }
463     send_gdb "$sendthis\n"
464     #FIXME: Should add timeout as parameter.
465     gdb_expect {
466         -re "A .* in expression.*\\.*$gdb_prompt $" {
467             pass "reject $sendthis"
468             return 1
469         }
470         -re "Invalid syntax in expression.*$gdb_prompt $" {
471             pass "reject $sendthis"
472             return 1
473         }
474         -re "Junk after end of expression.*$gdb_prompt $" {
475             pass "reject $sendthis"
476             return 1
477         }
478         -re "Invalid number.*$gdb_prompt $" {
479             pass "reject $sendthis"
480             return 1
481         }
482         -re "Invalid character constant.*$gdb_prompt $" {
483             pass "reject $sendthis"
484             return 1
485         }
486         -re "No symbol table is loaded.*$gdb_prompt $" {
487             pass "reject $sendthis"
488             return 1
489         }
490         -re "No symbol .* in current context.*$gdb_prompt $" {
491             pass "reject $sendthis"
492             return 1
493         }
494         -re "$expectthis.*$gdb_prompt $" {
495             pass "reject $sendthis"
496             return 1
497         }
498         -re ".*$gdb_prompt $" {
499             fail "reject $sendthis"
500             return 1
501         }
502         default {
503             fail "reject $sendthis (eof or timeout)"
504             return 0
505         }
506     }
507 }
508 \f
509 # Given an input string, adds backslashes as needed to create a
510 # regexp that will match the string.
511
512 proc string_to_regexp {str} {
513     set result $str
514     regsub -all {[]*+.|()^$\[]} $str {\\&} result
515     return $result
516 }
517
518 # Same as gdb_test, but the second parameter is not a regexp,
519 # but a string that must match exactly.
520
521 proc gdb_test_exact { args } {
522     upvar timeout timeout
523
524     set command [lindex $args 0]
525
526     # This applies a special meaning to a null string pattern.  Without
527     # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
528     # messages from commands that should have no output except a new
529     # prompt.  With this, only results of a null string will match a null
530     # string pattern.
531
532     set pattern [lindex $args 1]
533     if [string match $pattern ""] {
534         set pattern [string_to_regexp [lindex $args 0]]
535     } else {
536         set pattern [string_to_regexp [lindex $args 1]]
537     }
538
539     # It is most natural to write the pattern argument with only
540     # embedded \n's, especially if you are trying to avoid Tcl quoting
541     # problems.  But gdb_expect really wants to see \r\n in patterns.  So
542     # transform the pattern here.  First transform \r\n back to \n, in
543     # case some users of gdb_test_exact already do the right thing.
544     regsub -all "\r\n" $pattern "\n" pattern
545     regsub -all "\n" $pattern "\r\n" pattern
546     if [llength $args]==3 then {
547         set message [lindex $args 2]
548     } else {
549         set message $command
550     }
551
552     return [gdb_test $command $pattern $message]
553 }
554 \f
555 proc gdb_reinitialize_dir { subdir } {
556     global gdb_prompt
557
558     if [is_remote host] {
559         return "";
560     }
561     send_gdb "dir\n"
562     gdb_expect 60 {
563         -re "Reinitialize source path to empty.*y or n. " {
564             send_gdb "y\n"
565             gdb_expect 60 {
566                 -re "Source directories searched.*$gdb_prompt $" {
567                     send_gdb "dir $subdir\n"
568                     gdb_expect 60 {
569                         -re "Source directories searched.*$gdb_prompt $" {
570                             verbose "Dir set to $subdir"
571                         }
572                         -re "$gdb_prompt $" {
573                             perror "Dir \"$subdir\" failed."
574                         }
575                     }
576                 }
577                 -re "$gdb_prompt $" {
578                     perror "Dir \"$subdir\" failed."
579                 }
580             }
581         }
582         -re "$gdb_prompt $" {
583             perror "Dir \"$subdir\" failed."
584         }
585     }
586 }
587
588 #
589 # gdb_exit -- exit the GDB, killing the target program if necessary
590 #
591 proc default_gdb_exit {} {
592     global GDB
593     global GDBFLAGS
594     global verbose
595     global gdb_spawn_id;
596
597     gdb_stop_suppressing_tests;
598
599     if ![info exists gdb_spawn_id] {
600         return;
601     }
602
603     verbose "Quitting $GDB $GDBFLAGS"
604
605     if [is_remote host] {
606         send_gdb "quit\n";
607         gdb_expect 10 {
608              -re "and kill it.*y or n. " {
609                 send_gdb "y\n";
610                 exp_continue;
611             }
612             timeout { }
613         }
614     }
615
616     remote_close host;
617     unset gdb_spawn_id
618 }
619
620 #
621 # load a file into the debugger.
622 # return a -1 if anything goes wrong.
623 #
624 proc gdb_file_cmd { arg } {
625     global verbose
626     global loadpath
627     global loadfile
628     global GDB
629     global gdb_prompt
630     upvar timeout timeout
631
632     if [is_remote host] {
633         set arg [remote_download host $arg];
634         if { $arg == "" } {
635             error "download failed"
636             return -1;
637         }
638     }
639
640     send_gdb "file $arg\n"
641     gdb_expect 120 {
642         -re "Reading symbols from.*done.*$gdb_prompt $" {
643             verbose "\t\tLoaded $arg into the $GDB"
644             return 0
645         }
646         -re "has no symbol-table.*$gdb_prompt $" {
647             perror "$arg wasn't compiled with \"-g\""
648             return -1
649         }
650         -re "A program is being debugged already.*Kill it.*y or n. $" {
651             send_gdb "y\n"
652                 verbose "\t\tKilling previous program being debugged"
653             exp_continue
654         }
655         -re "Load new symbol table from \".*\".*y or n. $" {
656             send_gdb "y\n"
657             gdb_expect 120 {
658                 -re "Reading symbols from.*done.*$gdb_prompt $" {
659                     verbose "\t\tLoaded $arg with new symbol table into $GDB"
660                     return 0
661                 }
662                 timeout {
663                     perror "(timeout) Couldn't load $arg, other program already loaded."
664                     return -1
665                 }
666             }
667         }
668         -re "No such file or directory.*$gdb_prompt $" {
669             perror "($arg) No such file or directory\n"
670             return -1
671         }
672         -re "$gdb_prompt $" {
673             perror "couldn't load $arg into $GDB."
674             return -1
675             }
676         timeout {
677             perror "couldn't load $arg into $GDB (timed out)."
678             return -1
679         }
680         eof {
681             # This is an attempt to detect a core dump, but seems not to
682             # work.  Perhaps we need to match .* followed by eof, in which
683             # gdb_expect does not seem to have a way to do that.
684             perror "couldn't load $arg into $GDB (end of file)."
685             return -1
686         }
687     }
688 }
689
690 #
691 # start gdb -- start gdb running, default procedure
692 #
693 # When running over NFS, particularly if running many simultaneous
694 # tests on different hosts all using the same server, things can
695 # get really slow.  Give gdb at least 3 minutes to start up.
696 #
697 proc default_gdb_start { } {
698     global verbose
699     global GDB
700     global GDBFLAGS
701     global gdb_prompt
702     global timeout
703     global gdb_spawn_id;
704
705     gdb_stop_suppressing_tests;
706
707     verbose "Spawning $GDB -nw $GDBFLAGS"
708
709     if [info exists gdb_spawn_id] {
710         return 0;
711     }
712
713     if [is_remote host] {
714         set res [remote_spawn host "$GDB -nw $GDBFLAGS --command gdbinit"];
715     } else {
716         if { [which $GDB] == 0 } then {
717             perror "$GDB does not exist."
718             exit 1
719         }
720
721         set res [remote_spawn host "$GDB -nw $GDBFLAGS"];
722     }
723     if { $res < 0 || $res == "" } {
724         perror "Spawning $GDB failed."
725         return 1;
726     }
727     gdb_expect 360 {
728         -re "\[\r\n\]$gdb_prompt $" {
729             verbose "GDB initialized."
730         }
731         -re "$gdb_prompt $"     {
732             perror "GDB never initialized."
733             return -1
734         }
735         timeout {
736             perror "(timeout) GDB never initialized after 10 seconds."
737             remote_close host;
738             return -1
739         }
740     }
741     set gdb_spawn_id -1;
742     # force the height to "unlimited", so no pagers get used
743
744     send_gdb "set height 0\n"
745     gdb_expect 10 {
746         -re "$gdb_prompt $" { 
747             verbose "Setting height to 0." 2
748         }
749         timeout {
750             warning "Couldn't set the height to 0"
751         }
752     }
753     # force the width to "unlimited", so no wraparound occurs
754     send_gdb "set width 0\n"
755     gdb_expect 10 {
756         -re "$gdb_prompt $" {
757             verbose "Setting width to 0." 2
758         }
759         timeout {
760             warning "Couldn't set the width to 0."
761         }
762     }
763     return 0;
764 }
765
766 # * For crosses, the CHILL runtime doesn't build because it can't find
767 # setjmp.h, stdio.h, etc.
768 # * For AIX (as of 16 Mar 95), (a) there is no language code for
769 # CHILL in output_epilog in gcc/config/rs6000/rs6000.c, (b) collect2
770 # does not get along with AIX's too-clever linker.
771 # * On Irix5, there is a bug whereby set of bool, etc., don't get
772 # TYPE_LOW_BOUND for the bool right because force_to_range_type doesn't
773 # work with stub types.
774 # Lots of things seem to fail on the PA, and since it's not a supported
775 # chill target at the moment, don't run the chill tests.
776
777 proc skip_chill_tests {} {
778     if ![info exists do_chill_tests] {
779         return 1;
780     }
781     eval set skip_chill [expr ![isnative] || [istarget "*-*-aix*"] || [istarget "*-*-irix5*"] || [istarget "*-*-irix6*"] || [istarget "alpha-*-osf*"] || [istarget "hppa*-*-*"]]
782     verbose "Skip chill tests is $skip_chill"
783     return $skip_chill
784 }
785
786 proc get_compiler_info {binfile} {
787     # Create and source the file that provides information about the compiler
788     # used to compile the test case.
789     global srcdir
790     global subdir
791     # These two come from compiler.c.
792     global signed_keyword_not_used
793     global gcc_compiled
794
795     if { [gdb_compile "${srcdir}/${subdir}/compiler.c" "${binfile}.ci" preprocess {}] != "" } {
796         perror "Couldn't make ${binfile}.ci file"
797         return 1;
798     }
799     source ${binfile}.ci
800     return 0;
801 }
802
803 proc gdb_compile {source dest type options} {
804     global GDB_TESTCASE_OPTIONS;
805
806     if [target_info exists gdb_stub] {
807         set options2 { "additional_flags=-Dusestubs" }
808         lappend options "libs=[target_info gdb_stub]";
809         set options [concat $options2 $options]
810     }
811     if [info exists GDB_TESTCASE_OPTIONS] {
812         lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
813     }
814     verbose "options are $options"
815     verbose "source is $source $dest $type $options"
816     set result [target_compile $source $dest $type $options];
817     regsub "\[\r\n\]*$" "$result" "" result;
818     regsub "^\[\r\n\]*" "$result" "" result;
819     if { $result != "" } {
820         clone_output "gdb compile failed, $result"
821     }
822     return $result;
823 }
824
825 proc send_gdb { string } {
826     global suppress_flag;
827     if { $suppress_flag } {
828         return "suppressed";
829     }
830     return [remote_send host "$string"];
831 }
832
833 #
834 #
835
836 proc gdb_expect { args } {
837     if { [llength $args] == 2  && [lindex $args 0] != "-re" } {
838         set gtimeout [lindex $args 0];
839         set expcode [list [lindex $args 1]];
840     } else {
841         upvar timeout timeout;
842
843         set expcode $args;
844         if [target_info exists gdb,timeout] {
845             if [info exists timeout] {
846                 if { $timeout < [target_info gdb,timeout] } {
847                     set gtimeout [target_info gdb,timeout];
848                 } else {
849                     set gtimeout $timeout;
850                 }
851             } else {
852                 set gtimeout [target_info gdb,timeout];
853             }
854         }
855
856         if ![info exists gtimeout] {
857             global timeout;
858             if [info exists timeout] {
859                 set gtimeout $timeout;
860             } else {
861                 # Eeeeew.
862                 set gtimeout 60;
863             }
864         }
865     }
866     set code [catch {uplevel remote_expect host $gtimeout $expcode} string];
867
868     if {$code == 1} {
869         global errorInfo errorCode;
870
871         return -code error -errorinfo $errorInfo -errorcode $errorCode $string
872     } elseif {$code == 2} {
873         return -code return $string
874     } elseif {$code == 3} {
875         return
876     } elseif {$code > 4} {
877         return -code $code $string
878     }
879 }
880
881 #
882 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
883 # gdb_expect to fail immediately (until the next call to 
884 # gdb_stop_suppressing_tests).
885 #
886 proc gdb_suppress_tests { args } {
887     global suppress_flag;
888
889     incr suppress_flag;
890
891     if { $suppress_flag == 1 } {
892         if { [llength $args] > 0 } {
893             warning "[lindex $args 0]\n";
894         } else {
895             warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
896         }
897     }
898 }
899
900 #
901 # Clear suppress_flag.
902 #
903 proc gdb_stop_suppressing_tests { } {
904     global suppress_flag;
905
906     if [info exists suppress_flag] {
907         if { $suppress_flag != 0 } {
908             set suppress_flag 0;
909             clone_output "Tests restarted.\n";
910         }
911     } else {
912         set suppress_flag 0;
913     }
914 }
915
916 proc gdb_start { } {
917     default_gdb_start
918 }
919
920 proc gdb_exit { } {
921     catch default_gdb_exit
922 }
923
924 #
925 # gdb_load -- load a file into the debugger.
926 #             return a -1 if anything goes wrong.
927 #
928 proc gdb_load { arg } {
929     return [gdb_file_cmd $arg]
930 }
931
932 proc gdb_continue { function } {
933     global decimal
934
935     return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
936 }
937
938 proc default_gdb_init { args } {
939     gdb_stop_suppressing_tests;
940
941     # Uh, this is lame. Really, really, really lame. But there's this *one*
942     # testcase that will fail in random places if we don't increase this.
943     match_max -d 20000
944
945     # We want to add the name of the TCL testcase to the PASS/FAIL messages.
946     if { [llength $args] > 0 } {
947         global pf_prefix
948
949         set file [lindex $args 0];
950
951         set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
952     }
953 }
954
955 proc gdb_init { args } {
956     return [eval default_gdb_init $args];
957 }
958
959 proc gdb_finish { } {
960     gdb_exit;
961 }