1 # Copyright (C) 1992, 1994, 1995, 1997, 1999 Free Software Foundation, Inc.
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.
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.
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.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was written by Fred Fish. (fnf@cygnus.com)
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.
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]]
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" ""]
39 verbose "using CHILL_RT0 = $CHILL_RT0" 2
41 if [info exists TOOL_EXECUTABLE] {
42 set GDB $TOOL_EXECUTABLE;
44 if ![info exists GDB] {
45 if ![is_remote host] {
46 set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]]
48 set GDB [transform gdb];
51 verbose "using GDB = $GDB" 2
54 if ![info exists GDBFLAGS] {
57 verbose "using GDBFLAGS = $GDBFLAGS" 2
59 # The variable gdb_prompt is a regexp which matches the gdb prompt.
60 # Set it if it is not already set.
62 if ![info exists gdb_prompt] then {
63 set gdb_prompt "\[(\]gdb\[)\]"
66 # Needed for some tests under Cygwin.
70 if ![info exists env(EXEEXT)] {
73 set EXEEXT $env(EXEEXT)
76 ### Only procedures should come after this point.
79 # gdb_version -- extract and print the version number of GDB
81 proc default_gdb_version {} {
85 set fileid [open "gdb_cmd" w];
88 set cmdfile [remote_download host "gdb_cmd"];
89 set output [remote_exec host "$GDB -nw --command $cmdfile"]
90 remote_file build delete "gdb_cmd";
91 remote_file host delete "$cmdfile";
92 set tmp [lindex $output 1];
94 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
95 if ![is_remote host] {
96 clone_output "[which $GDB] version $version $GDBFLAGS\n"
98 clone_output "$GDB on remote host version $version $GDBFLAGS\n"
102 proc gdb_version { } {
103 return [default_gdb_version];
107 # gdb_unload -- unload a file if one is loaded
116 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
117 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
118 -re "A program is being debugged already..*Kill it.*y or n. $"\
120 verbose "\t\tKilling previous program being debugged"
123 -re "Discard symbol table from .*y or n.*$" {
127 -re "$gdb_prompt $" {}
129 perror "couldn't unload file in $GDB (timed out)."
135 # Many of the tests depend on setting breakpoints at various places and
136 # running until that breakpoint is reached. At times, we want to start
137 # with a clean-slate with respect to breakpoints, so this utility proc
138 # lets us do this without duplicating this code everywhere.
141 proc delete_breakpoints {} {
144 # we need a larger timeout value here or this thing just confuses
145 # itself. May need a better implementation if possible. - guo
147 send_gdb "delete breakpoints\n"
149 -re "Delete all breakpoints.*y or n.*$" {
153 -re "$gdb_prompt $" { # This happens if there were no breakpoints
155 timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
157 send_gdb "info breakpoints\n"
159 -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
160 -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
161 -re "Delete all breakpoints.*or n.*$" {
165 timeout { perror "info breakpoints (timeout)" ; return }
171 # Generic run command.
173 # The second pattern below matches up to the first newline *only*.
174 # Using ``.*$'' could swallow up output that we attempt to match
177 proc gdb_run_cmd {args} {
180 if [target_info exists gdb_init_command] {
181 send_gdb "[target_info gdb_init_command]\n";
183 -re "$gdb_prompt $" { }
185 perror "gdb_init_command for target failed";
191 if [target_info exists use_gdb_stub] {
192 if [target_info exists gdb,do_reload_on_run] {
193 # Specifying no file, defaults to the executable
194 # currently being debugged.
195 if { [gdb_load ""] < 0 } {
198 send_gdb "continue\n";
200 -re "Continu\[^\r\n\]*\[\r\n\]" {}
206 if [target_info exists gdb,start_symbol] {
207 set start [target_info gdb,start_symbol];
211 send_gdb "jump *$start\n"
213 while { $start_attempt } {
214 # Cap (re)start attempts at three to ensure that this loop
215 # always eventually fails. Don't worry about trying to be
216 # clever and not send a command when it has failed.
217 if [expr $start_attempt > 3] {
218 perror "Jump to start() failed (retry count exceeded)";
221 set start_attempt [expr $start_attempt + 1];
223 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
226 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
227 perror "Can't find start symbol to run in gdb_run";
230 -re "No symbol \"start\" in current.*$gdb_prompt $" {
231 send_gdb "jump *_start\n";
233 -re "No symbol.*context.*$gdb_prompt $" {
236 -re "Line.* Jump anyway.*y or n. $" {
239 -re "The program is not being run.*$gdb_prompt $" {
240 if { [gdb_load ""] < 0 } {
243 send_gdb "jump *$start\n";
246 perror "Jump to start() failed (timeout)";
251 if [target_info exists gdb_stub] {
253 -re "$gdb_prompt $" {
254 send_gdb "continue\n"
260 send_gdb "run $args\n"
261 # This doesn't work quite right yet.
263 -re "The program .* has been started already.*y or n. $" {
267 -re "Starting program: \[^\r\n\]*" {}
271 proc gdb_breakpoint { function } {
275 send_gdb "break $function\n"
276 # The first two regexps are what we get with -g, the third is without -g.
278 -re "Breakpoint \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
279 -re "Breakpoint \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
280 -re "Breakpoint \[0-9\]* at .*$gdb_prompt $" {}
281 -re "$gdb_prompt $" { fail "setting breakpoint at $function" ; return 0 }
282 timeout { fail "setting breakpoint at $function (timeout)" ; return 0 }
287 # Set breakpoint at function and run gdb until it breaks there.
288 # Since this is the only breakpoint that will be set, if it stops
289 # at a breakpoint, we will assume it is the one we want. We can't
290 # just compare to "function" because it might be a fully qualified,
291 # single quoted C++ function specifier.
293 proc runto { function } {
299 if ![gdb_breakpoint $function] {
305 # the "at foo.c:36" output we get with -g.
306 # the "in func" output we get without -g.
308 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
311 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
314 -re "$gdb_prompt $" {
315 fail "running to $function in runto"
319 fail "running to $function in runto (timeout)"
327 # runto_main -- ask gdb to run until we hit a breakpoint at main.
328 # The case where the target uses stubs has to be handled
329 # specially--if it uses stubs, assuming we hit
330 # breakpoint() and just step out of the function.
332 proc runto_main { } {
336 if ![target_info exists gdb_stub] {
348 ### Continue, and expect to hit a breakpoint.
349 ### Report a pass or fail, depending on whether it seems to have
350 ### worked. Use NAME as part of the test name; each call to
351 ### continue_to_breakpoint should use a NAME which is unique within
353 proc gdb_continue_to_breakpoint {name} {
355 set full_name "continue to breakpoint: $name"
357 send_gdb "continue\n"
359 -re "Breakpoint .* at .*\r\n$gdb_prompt $" {
362 -re ".*$gdb_prompt $" {
366 fail "$full_name (timeout)"
373 # gdb_test COMMAND PATTERN MESSAGE -- send a command to gdb; test the result.
375 # COMMAND is the command to execute, send to GDB with send_gdb. If
376 # this is the null string no command is sent.
377 # PATTERN is the pattern to match for a PASS, and must NOT include
378 # the \r\n sequence immediately before the gdb prompt.
379 # MESSAGE is an optional message to be printed. If this is
380 # omitted, then the pass/fail messages use the command string as the
381 # message. (If this is the empty string, then sometimes we don't
382 # call pass or fail at all; I don't understand this at all.)
385 # 1 if the test failed,
386 # 0 if the test passes,
387 # -1 if there was an internal error.
389 proc gdb_test { args } {
393 upvar timeout timeout
395 if [llength $args]>2 then {
396 set message [lindex $args 2]
398 set message [lindex $args 0]
400 set command [lindex $args 0]
401 set pattern [lindex $args 1]
403 if [llength $args]==5 {
404 set question_string [lindex $args 3];
405 set response_string [lindex $args 4];
407 set question_string "^FOOBAR$"
411 send_user "Sending \"$command\" to gdb\n"
412 send_user "Looking to match \"$pattern\"\n"
413 send_user "Message is \"$message\"\n"
417 set string "${command}\n";
418 if { $command != "" } {
419 while { "$string" != "" } {
420 set foo [string first "\n" "$string"];
421 set len [string length "$string"];
422 if { $foo < [expr $len - 1] } {
423 set str [string range "$string" 0 $foo];
424 if { [send_gdb "$str"] != "" } {
425 global suppress_flag;
427 if { ! $suppress_flag } {
428 perror "Couldn't send $command to GDB.";
433 # since we're checking if each line of the multi-line
434 # command are 'accepted' by GDB here,
435 # we need to set -notransfer expect option so that
436 # command output is not lost for pattern matching
438 gdb_expect -notransfer 2 {
442 set string [string range "$string" [expr $foo + 1] end];
447 if { "$string" != "" } {
448 if { [send_gdb "$string"] != "" } {
449 global suppress_flag;
451 if { ! $suppress_flag } {
452 perror "Couldn't send $command to GDB.";
460 if [info exists timeout] {
464 if [info exists timeout] {
471 -re "\\*\\*\\* DOSEXIT code.*" {
472 if { $message != "" } {
475 gdb_suppress_entire_file "GDB died";
478 -re "Ending remote debugging.*$gdb_prompt $" {
479 if ![isnative] then {
480 warning "Can`t communicate to remote target."
486 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
487 if ![string match "" $message] then {
492 -re "(${question_string})$" {
493 send_gdb "$response_string\n";
496 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
497 perror "Undefined command \"$command\"."
501 -re "Ambiguous command.*$gdb_prompt $" {
502 perror "\"$command\" is not a unique command name."
506 -re "Program exited with code \[0-9\]+.*$gdb_prompt $" {
507 if ![string match "" $message] then {
508 set errmsg "$message: the program exited"
510 set errmsg "$command: the program exited"
515 -re "The program is not being run.*$gdb_prompt $" {
516 if ![string match "" $message] then {
517 set errmsg "$message: the program is no longer running"
519 set errmsg "$command: the program is no longer running"
524 -re ".*$gdb_prompt $" {
525 if ![string match "" $message] then {
532 perror "Window too small."
535 -re "\\(y or n\\) " {
537 perror "Got interactive prompt."
541 perror "Process no longer exists"
542 if { $message != "" } {
548 perror "internal buffer is full."
552 if ![string match "" $message] then {
553 fail "$message (timeout)"
561 # Test that a command gives an error. For pass or fail, return
562 # a 1 to indicate that more tests can proceed. However a timeout
563 # is a serious error, generates a special fail message, and causes
564 # a 0 to be returned to indicate that more tests are likely to fail
567 proc test_print_reject { args } {
571 if [llength $args]==2 then {
572 set expectthis [lindex $args 1]
574 set expectthis "should never match this bogus string"
576 set sendthis [lindex $args 0]
578 send_user "Sending \"$sendthis\" to gdb\n"
579 send_user "Looking to match \"$expectthis\"\n"
581 send_gdb "$sendthis\n"
582 #FIXME: Should add timeout as parameter.
584 -re "A .* in expression.*\\.*$gdb_prompt $" {
585 pass "reject $sendthis"
588 -re "Invalid syntax in expression.*$gdb_prompt $" {
589 pass "reject $sendthis"
592 -re "Junk after end of expression.*$gdb_prompt $" {
593 pass "reject $sendthis"
596 -re "Invalid number.*$gdb_prompt $" {
597 pass "reject $sendthis"
600 -re "Invalid character constant.*$gdb_prompt $" {
601 pass "reject $sendthis"
604 -re "No symbol table is loaded.*$gdb_prompt $" {
605 pass "reject $sendthis"
608 -re "No symbol .* in current context.*$gdb_prompt $" {
609 pass "reject $sendthis"
612 -re "$expectthis.*$gdb_prompt $" {
613 pass "reject $sendthis"
616 -re ".*$gdb_prompt $" {
617 fail "reject $sendthis"
621 fail "reject $sendthis (eof or timeout)"
627 # Given an input string, adds backslashes as needed to create a
628 # regexp that will match the string.
630 proc string_to_regexp {str} {
632 regsub -all {[]*+.|()^$\[]} $str {\\&} result
636 # Same as gdb_test, but the second parameter is not a regexp,
637 # but a string that must match exactly.
639 proc gdb_test_exact { args } {
640 upvar timeout timeout
642 set command [lindex $args 0]
644 # This applies a special meaning to a null string pattern. Without
645 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
646 # messages from commands that should have no output except a new
647 # prompt. With this, only results of a null string will match a null
650 set pattern [lindex $args 1]
651 if [string match $pattern ""] {
652 set pattern [string_to_regexp [lindex $args 0]]
654 set pattern [string_to_regexp [lindex $args 1]]
657 # It is most natural to write the pattern argument with only
658 # embedded \n's, especially if you are trying to avoid Tcl quoting
659 # problems. But gdb_expect really wants to see \r\n in patterns. So
660 # transform the pattern here. First transform \r\n back to \n, in
661 # case some users of gdb_test_exact already do the right thing.
662 regsub -all "\r\n" $pattern "\n" pattern
663 regsub -all "\n" $pattern "\r\n" pattern
664 if [llength $args]==3 then {
665 set message [lindex $args 2]
670 return [gdb_test $command $pattern $message]
673 proc gdb_reinitialize_dir { subdir } {
676 if [is_remote host] {
681 -re "Reinitialize source path to empty.*y or n. " {
684 -re "Source directories searched.*$gdb_prompt $" {
685 send_gdb "dir $subdir\n"
687 -re "Source directories searched.*$gdb_prompt $" {
688 verbose "Dir set to $subdir"
690 -re "$gdb_prompt $" {
691 perror "Dir \"$subdir\" failed."
695 -re "$gdb_prompt $" {
696 perror "Dir \"$subdir\" failed."
700 -re "$gdb_prompt $" {
701 perror "Dir \"$subdir\" failed."
707 # gdb_exit -- exit the GDB, killing the target program if necessary
709 proc default_gdb_exit {} {
715 gdb_stop_suppressing_tests;
717 if ![info exists gdb_spawn_id] {
721 verbose "Quitting $GDB $GDBFLAGS"
723 if { [is_remote host] && [board_info host exists fileid] } {
730 -re "DOSEXIT code" { }
735 if ![is_remote host] {
742 # load a file into the debugger.
743 # return a -1 if anything goes wrong.
745 proc gdb_file_cmd { arg } {
751 upvar timeout timeout
753 if [is_remote host] {
754 set arg [remote_download host $arg];
756 error "download failed"
761 send_gdb "file $arg\n"
763 -re "Reading symbols from.*done.*$gdb_prompt $" {
764 verbose "\t\tLoaded $arg into the $GDB"
767 -re "has no symbol-table.*$gdb_prompt $" {
768 perror "$arg wasn't compiled with \"-g\""
771 -re "A program is being debugged already.*Kill it.*y or n. $" {
773 verbose "\t\tKilling previous program being debugged"
776 -re "Load new symbol table from \".*\".*y or n. $" {
779 -re "Reading symbols from.*done.*$gdb_prompt $" {
780 verbose "\t\tLoaded $arg with new symbol table into $GDB"
784 perror "(timeout) Couldn't load $arg, other program already loaded."
789 -re "No such file or directory.*$gdb_prompt $" {
790 perror "($arg) No such file or directory\n"
793 -re "$gdb_prompt $" {
794 perror "couldn't load $arg into $GDB."
798 perror "couldn't load $arg into $GDB (timed out)."
802 # This is an attempt to detect a core dump, but seems not to
803 # work. Perhaps we need to match .* followed by eof, in which
804 # gdb_expect does not seem to have a way to do that.
805 perror "couldn't load $arg into $GDB (end of file)."
812 # start gdb -- start gdb running, default procedure
814 # When running over NFS, particularly if running many simultaneous
815 # tests on different hosts all using the same server, things can
816 # get really slow. Give gdb at least 3 minutes to start up.
818 proc default_gdb_start { } {
826 gdb_stop_suppressing_tests;
828 verbose "Spawning $GDB -nw $GDBFLAGS"
830 if [info exists gdb_spawn_id] {
834 if ![is_remote host] {
835 if { [which $GDB] == 0 } then {
836 perror "$GDB does not exist."
840 set res [remote_spawn host "$GDB -nw $GDBFLAGS [host_info gdb_opts]"];
841 if { $res < 0 || $res == "" } {
842 perror "Spawning $GDB failed."
846 -re "\[\r\n\]$gdb_prompt $" {
847 verbose "GDB initialized."
849 -re "$gdb_prompt $" {
850 perror "GDB never initialized."
854 perror "(timeout) GDB never initialized after 10 seconds."
860 # force the height to "unlimited", so no pagers get used
862 send_gdb "set height 0\n"
864 -re "$gdb_prompt $" {
865 verbose "Setting height to 0." 2
868 warning "Couldn't set the height to 0"
871 # force the width to "unlimited", so no wraparound occurs
872 send_gdb "set width 0\n"
874 -re "$gdb_prompt $" {
875 verbose "Setting width to 0." 2
878 warning "Couldn't set the width to 0."
884 # Return a 1 for configurations for which we don't even want to try to
887 proc skip_cplus_tests {} {
888 if { [istarget "d10v-*-*"] } {
891 if { [istarget "h8300-*-*"] } {
897 # * For crosses, the CHILL runtime doesn't build because it can't find
898 # setjmp.h, stdio.h, etc.
899 # * For AIX (as of 16 Mar 95), (a) there is no language code for
900 # CHILL in output_epilog in gcc/config/rs6000/rs6000.c, (b) collect2
901 # does not get along with AIX's too-clever linker.
902 # * On Irix5, there is a bug whereby set of bool, etc., don't get
903 # TYPE_LOW_BOUND for the bool right because force_to_range_type doesn't
904 # work with stub types.
905 # Lots of things seem to fail on the PA, and since it's not a supported
906 # chill target at the moment, don't run the chill tests.
908 proc skip_chill_tests {} {
909 if ![info exists do_chill_tests] {
912 eval set skip_chill [expr ![isnative] || [istarget "*-*-aix*"] || [istarget "*-*-irix5*"] || [istarget "*-*-irix6*"] || [istarget "alpha-*-osf*"] || [istarget "hppa*-*-*"]]
913 verbose "Skip chill tests is $skip_chill"
917 # Skip all the tests in the file if you are not on an hppa running
920 proc skip_hp_tests {} {
921 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
922 verbose "Skip hp tests is $skip_hp"
926 proc get_compiler_info {binfile args} {
927 # Create and source the file that provides information about the compiler
928 # used to compile the test case.
929 # Compiler_type can be null or c++. If null we assume c.
932 # These two come from compiler.c.
933 global signed_keyword_not_used
936 if {![istarget "hppa*-*-hpux*"]} {
937 if { [llength $args] > 0 } {
938 if {$args == "c++"} {
939 if { [gdb_compile "${srcdir}/lib/compiler.cc" "${binfile}.ci" preprocess {}] != "" } {
940 perror "Couldn't make ${binfile}.ci file"
945 if { [gdb_compile "${srcdir}/lib/compiler.c" "${binfile}.ci" preprocess {}] != "" } {
946 perror "Couldn't make ${binfile}.ci file"
951 if { [llength $args] > 0 } {
952 if {$args == "c++"} {
953 if { [eval gdb_preprocess \
954 [list "${srcdir}/lib/compiler.cc" "${binfile}.ci"] \
956 perror "Couldn't make ${binfile}.ci file"
960 } elseif { $args != "f77" } {
961 if { [eval gdb_preprocess \
962 [list "${srcdir}/lib/compiler.c" "${binfile}.ci"] \
964 perror "Couldn't make ${binfile}.ci file"
970 uplevel \#0 { set gcc_compiled 0 }
972 if { [llength $args] == 0 || $args != "f77" } {
976 # Most compilers will evaluate comparisons and other boolean
977 # operations to 0 or 1.
978 uplevel \#0 { set true 1 }
979 uplevel \#0 { set false 0 }
981 uplevel \#0 { set hp_cc_compiler 0 }
982 uplevel \#0 { set hp_aCC_compiler 0 }
983 uplevel \#0 { set hp_f77_compiler 0 }
984 uplevel \#0 { set hp_f90_compiler 0 }
985 if { !$gcc_compiled && [istarget "hppa*-*-hpux*"] } {
986 # Check for the HP compilers
987 set compiler [lindex [split [get_compiler $args] " "] 0]
988 catch "exec what $compiler" output
989 if [regexp ".*HP aC\\+\\+.*" $output] {
990 uplevel \#0 { set hp_aCC_compiler 1 }
991 # Use of aCC results in boolean results being displayed as
993 uplevel \#0 { set true true }
994 uplevel \#0 { set false false }
995 } elseif [regexp ".*HP C Compiler.*" $output] {
996 uplevel \#0 { set hp_cc_compiler 1 }
997 } elseif [regexp ".*HP-UX f77.*" $output] {
998 uplevel \#0 { set hp_f77_compiler 1 }
999 } elseif [regexp ".*HP-UX f90.*" $output] {
1000 uplevel \#0 { set hp_f90_compiler 1 }
1007 proc get_compiler {args} {
1008 global CC CC_FOR_TARGET CXX CXX_FOR_TARGET F77_FOR_TARGET
1010 if { [llength $args] == 0
1011 || ([llength $args] == 1 && [lindex $args 0] == "") } {
1012 set which_compiler "c"
1014 if { $args =="c++" } {
1015 set which_compiler "c++"
1016 } elseif { $args =="f77" } {
1017 set which_compiler "f77"
1019 perror "Unknown compiler type supplied to gdb_preprocess"
1024 if [info exists CC_FOR_TARGET] {
1025 if {$which_compiler == "c"} {
1026 set compiler $CC_FOR_TARGET
1030 if [info exists CXX_FOR_TARGET] {
1031 if {$which_compiler == "c++"} {
1032 set compiler $CXX_FOR_TARGET
1036 if [info exists F77_FOR_TARGET] {
1037 if {$which_compiler == "f77"} {
1038 set compiler $F77_FOR_TARGET
1042 if { ![info exists compiler] } {
1043 if { $which_compiler == "c" } {
1044 if {[info exists CC]} {
1048 if { $which_compiler == "c++" } {
1049 if {[info exists CXX]} {
1053 if {![info exists compiler]} {
1054 set compiler [board_info [target_info name] compiler];
1055 if { $compiler == "" } {
1056 perror "get_compiler: No compiler found"
1065 proc gdb_preprocess {source dest args} {
1066 set compiler [get_compiler "$args"]
1067 if { $compiler == "" } {
1071 set cmdline "$compiler -E $source > $dest"
1073 verbose "Invoking $compiler -E $source > $dest"
1074 verbose -log "Executing on local host: $cmdline" 2
1075 set status [catch "exec ${cmdline}" exec_output]
1077 set result [prune_warnings $exec_output]
1078 regsub "\[\r\n\]*$" "$result" "" result;
1079 regsub "^\[\r\n\]*" "$result" "" result;
1080 if { $result != "" } {
1081 clone_output "gdb compile failed, $result"
1086 proc gdb_compile {source dest type options} {
1087 global GDB_TESTCASE_OPTIONS;
1089 if [target_info exists gdb_stub] {
1090 set options2 { "additional_flags=-Dusestubs" }
1091 lappend options "libs=[target_info gdb_stub]";
1092 set options [concat $options2 $options]
1094 if [target_info exists is_vxworks] {
1095 set options2 { "additional_flags=-Dvxworks" }
1096 lappend options "libs=[target_info gdb_stub]";
1097 set options [concat $options2 $options]
1099 if [info exists GDB_TESTCASE_OPTIONS] {
1100 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
1102 verbose "options are $options"
1103 verbose "source is $source $dest $type $options"
1105 set result [target_compile $source $dest $type $options];
1106 regsub "\[\r\n\]*$" "$result" "" result;
1107 regsub "^\[\r\n\]*" "$result" "" result;
1108 if { $result != "" } {
1109 clone_output "gdb compile failed, $result"
1114 proc send_gdb { string } {
1115 global suppress_flag;
1116 if { $suppress_flag } {
1117 return "suppressed";
1119 return [remote_send host "$string"];
1125 proc gdb_expect { args } {
1126 # allow -notransfer expect flag specification,
1127 # used by gdb_test routine for multi-line commands.
1128 # packed with gtimeout when fed to remote_expect routine,
1129 # which is a hack but due to what looks like a res and orig
1130 # parsing problem in remote_expect routine (dejagnu/lib/remote.exp):
1131 # what's fed into res is not removed from orig.
1133 if { [lindex $args 0] == "-notransfer" } {
1134 set notransfer -notransfer;
1135 set args [lrange $args 1 end];
1140 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
1141 set gtimeout [lindex $args 0];
1142 set expcode [list [lindex $args 1]];
1144 upvar timeout timeout;
1147 if [target_info exists gdb,timeout] {
1148 if [info exists timeout] {
1149 if { $timeout < [target_info gdb,timeout] } {
1150 set gtimeout [target_info gdb,timeout];
1152 set gtimeout $timeout;
1155 set gtimeout [target_info gdb,timeout];
1159 if ![info exists gtimeout] {
1161 if [info exists timeout] {
1162 set gtimeout $timeout;
1169 global suppress_flag;
1170 global remote_suppress_flag;
1171 if [info exists remote_suppress_flag] {
1172 set old_val $remote_suppress_flag;
1174 if [info exists suppress_flag] {
1175 if { $suppress_flag } {
1176 set remote_suppress_flag 1;
1180 {uplevel remote_expect host "$gtimeout $notransfer" $expcode} string];
1181 if [info exists old_val] {
1182 set remote_suppress_flag $old_val;
1184 if [info exists remote_suppress_flag] {
1185 unset remote_suppress_flag;
1190 global errorInfo errorCode;
1192 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
1193 } elseif {$code == 2} {
1194 return -code return $string
1195 } elseif {$code == 3} {
1197 } elseif {$code > 4} {
1198 return -code $code $string
1202 # gdb_expect_list MESSAGE SENTINEL LIST -- expect a sequence of outputs
1204 # Check for long sequence of output by parts.
1205 # MESSAGE: is the test message to be printed with the test success/fail.
1206 # SENTINEL: Is the terminal pattern indicating that output has finished.
1207 # LIST: is the sequence of outputs to match.
1208 # If the sentinel is recognized early, it is considered an error.
1211 # 1 if the test failed,
1212 # 0 if the test passes,
1213 # -1 if there was an internal error.
1215 proc gdb_expect_list {test sentinel list} {
1217 global suppress_flag
1220 if { $suppress_flag } {
1223 while { ${index} < [llength ${list}] } {
1224 set pattern [lindex ${list} ${index}]
1225 set index [expr ${index} + 1]
1226 if { ${index} == [llength ${list}] } {
1229 -re "${pattern}${sentinel}" {
1230 pass "${test}, pattern ${index} + sentinel"
1233 fail "${test}, pattern ${index} + sentinel"
1237 fail "${test}, pattern ${index} + sentinel (timeout)"
1242 unresolved "${test}, pattern ${index} + sentinel"
1248 pass "${test}, pattern ${index}"
1251 fail "${test}, pattern ${index}"
1255 fail "${test}, pattern ${index} (timeout)"
1260 unresolved "${test}, pattern ${index}"
1273 proc gdb_suppress_entire_file { reason } {
1274 global suppress_flag;
1276 warning "$reason\n";
1277 set suppress_flag -1;
1281 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
1282 # gdb_expect to fail immediately (until the next call to
1283 # gdb_stop_suppressing_tests).
1285 proc gdb_suppress_tests { args } {
1286 global suppress_flag;
1288 return; # fnf - disable pending review of results where
1289 # testsuite ran better without this
1292 if { $suppress_flag == 1 } {
1293 if { [llength $args] > 0 } {
1294 warning "[lindex $args 0]\n";
1296 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
1302 # Clear suppress_flag.
1304 proc gdb_stop_suppressing_tests { } {
1305 global suppress_flag;
1307 if [info exists suppress_flag] {
1308 if { $suppress_flag > 0 } {
1309 set suppress_flag 0;
1310 clone_output "Tests restarted.\n";
1313 set suppress_flag 0;
1317 proc gdb_clear_suppressed { } {
1318 global suppress_flag;
1320 set suppress_flag 0;
1323 proc gdb_start { } {
1328 catch default_gdb_exit
1332 # gdb_load -- load a file into the debugger.
1333 # return a -1 if anything goes wrong.
1335 proc gdb_load { arg } {
1336 return [gdb_file_cmd $arg]
1339 proc gdb_continue { function } {
1342 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
1345 proc default_gdb_init { args } {
1346 gdb_clear_suppressed;
1348 # Uh, this is lame. Really, really, really lame. But there's this *one*
1349 # testcase that will fail in random places if we don't increase this.
1352 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
1353 if { [llength $args] > 0 } {
1356 set file [lindex $args 0];
1358 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
1361 if [target_info exists gdb_prompt] {
1362 set gdb_prompt [target_info gdb_prompt];
1364 set gdb_prompt "\\(gdb\\)"
1368 proc gdb_init { args } {
1369 return [eval default_gdb_init $args];
1372 proc gdb_finish { } {
1377 set debug_format "unknown"
1379 # Run the gdb command "info source" and extract the debugging format
1380 # information from the output and save it in debug_format.
1382 proc get_debug_format { } {
1388 set debug_format "unknown"
1389 send_gdb "info source\n"
1391 -re "Compiled with (.*) debugging format.\r\n$gdb_prompt $" {
1392 set debug_format $expect_out(1,string)
1393 verbose "debug format is $debug_format"
1396 -re "No current source file.\r\n$gdb_prompt $" {
1397 perror "get_debug_format used when no current source file"
1400 -re "$gdb_prompt $" {
1401 warning "couldn't check debug format (no valid response)."
1405 warning "couldn't check debug format (timed out)."
1411 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
1412 # COFF, stabs, etc). If that format matches the format that the
1413 # current test was compiled with, then the next test is expected to
1414 # fail for any target. Returns 1 if the next test or set of tests is
1415 # expected to fail, 0 otherwise (or if it is unknown). Must have
1416 # previously called get_debug_format.
1418 proc setup_xfail_format { format } {
1421 if [string match $debug_format $format] then {
1428 proc gdb_step_for_stub { } {
1431 if ![target_info exists gdb,use_breakpoint_for_stub] {
1432 if [target_info exists gdb_stub_step_command] {
1433 set command [target_info gdb_stub_step_command];
1437 send_gdb "${command}\n";
1440 -re "(main.* at |.*in .*start).*$gdb_prompt" {
1443 -re ".*$gdb_prompt" {
1445 if { $tries == 5 } {
1446 fail "stepping out of breakpoint function";
1449 send_gdb "${command}\n";
1453 fail "stepping out of breakpoint function";
1460 -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" {
1461 set file $expect_out(1,string);
1462 set linenum [expr $expect_out(2,string) + 1];
1463 set breakplace "${file}:${linenum}";
1467 send_gdb "break ${breakplace}\n";
1469 -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" {
1470 set breakpoint $expect_out(1,string);
1472 -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" {
1473 set breakpoint $expect_out(1,string);
1477 send_gdb "continue\n";
1479 -re "Breakpoint ${breakpoint},.*$gdb_prompt" {
1480 gdb_test "delete $breakpoint" ".*" "";
1487 ### gdb_get_line_number TEXT [FILE]
1489 ### Search the source file FILE, and return the line number of a line
1490 ### containing TEXT. Use this function instead of hard-coding line
1491 ### numbers into your test script.
1493 ### Specifically, this function uses GDB's "search" command to search
1494 ### FILE for the first line containing TEXT, and returns its line
1495 ### number. Thus, FILE must be a source file, compiled into the
1496 ### executable you are running. If omitted, FILE defaults to the
1497 ### value of the global variable `srcfile'; most test scripts set
1498 ### `srcfile' appropriately at the top anyway.
1500 ### Use this function to keep your test scripts independent of the
1501 ### exact line numbering of the source file. Don't write:
1503 ### send_gdb "break 20"
1505 ### This means that if anyone ever edits your test's source file,
1506 ### your test could break. Instead, put a comment like this on the
1507 ### source file line you want to break at:
1509 ### /* breakpoint spot: frotz.exp: test name */
1511 ### and then write, in your test script (which we assume is named
1514 ### send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
1516 ### (Yes, Tcl knows how to handle the nested quotes and brackets.
1519 ### % puts "foo [lindex "bar baz" 1]"
1522 ### Tcl is quite clever, for a little stringy language.)
1524 proc gdb_get_line_number {text {file /omitted/}} {
1528 if {! [string compare $file /omitted/]} {
1533 gdb_test "list ${file}:1,1" ".*" ""
1534 send_gdb "search ${text}\n"
1536 -re "\[\r\n\]+(\[0-9\]+)\[ \t\].*${text}.*$gdb_prompt $" {
1537 set result $expect_out(1,string)
1539 -re ".*$gdb_prompt $" {
1540 fail "find line number containing \"${text}\""
1543 fail "find line number containing \"${text}\" (timeout)"
1549 # gdb_continue_to_end:
1550 # The case where the target uses stubs has to be handled specially. If a
1551 # stub is used, we set a breakpoint at exit because we cannot rely on
1552 # exit() behavior of a remote target.
1554 # mssg is the error message that gets printed.
1556 proc gdb_continue_to_end {mssg} {
1557 if [target_info exists use_gdb_stub] {
1558 if {![gdb_breakpoint "exit"]} {
1561 gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \
1562 "continue until exit at $mssg"
1564 # Continue until we exit. Should not stop again.
1565 # Don't bother to check the output of the program, that may be
1566 # extremely tough for some remote systems.
1567 gdb_test "continue"\
1568 "Continuing.\[\r\n0-9\]+Program exited normally\\..*"\
1569 "continue until exit at $mssg"
1573 proc rerun_to_main {} {
1576 if [target_info exists use_gdb_stub] {
1579 -re ".*Breakpoint .*main .*$gdb_prompt $"\
1580 {pass "rerun to main" ; return 0}
1581 -re "$gdb_prompt $"\
1582 {fail "rerun to main" ; return 0}
1583 timeout {fail "(timeout) rerun to main" ; return 0}
1588 -re "Starting program.*$gdb_prompt $"\
1589 {pass "rerun to main" ; return 0}
1590 -re "$gdb_prompt $"\
1591 {fail "rerun to main" ; return 0}
1592 timeout {fail "(timeout) rerun to main" ; return 0}
1598 # srcdir = testsuite src dir (e.g., devo/gdb/testsuite)
1599 # objdir = testsuite obj dir (e.g., gdb/testsuite)
1600 # subdir = subdir of testsuite (e.g., gdb.gdbtk)
1603 # env(DEFS)=the "defs" files (e.g., devo/gdb/testsuite/gdb.gdbtk/defs)
1604 # env(SRCDIR)=directory containing the test code (e.g., *.test)
1605 # env(OBJDIR)=directory which contains any executables
1606 # (e.g., gdb/testsuite/gdb.gdbtk)
1607 proc gdbtk_start {test} {
1611 global env srcdir subdir objdir
1613 gdb_stop_suppressing_tests;
1615 verbose "Starting $GDB -nx -q --tclcommand=$test"
1617 set real_test [which $test]
1618 if {$real_test == 0} {
1619 perror "$test is not found"
1623 if {![is_remote host]} {
1624 if { [which $GDB] == 0 } {
1625 perror "$GDB does not exist."
1633 set abs_srcdir [pwd]
1634 cd [file join $abs_srcdir .. gdbtk library]
1635 set env(GDBTK_LIBRARY) [pwd]
1636 cd [file join $abs_srcdir .. .. tcl library]
1637 set env(TCL_LIBRARY) [pwd]
1638 cd [file join $abs_srcdir .. .. tk library]
1639 set env(TK_LIBRARY) [pwd]
1640 cd [file join $abs_srcdir .. .. tix library]
1641 set env(TIX_LIBRARY) [pwd]
1642 cd [file join $abs_srcdir .. .. itcl itcl library]
1643 set env(ITCL_LIBRARY) [pwd]
1644 cd [file join .. $abs_srcdir .. .. libgui library]
1645 set env(CYGNUS_GUI_LIBRARY) [pwd]
1647 cd [file join $abs_srcdir $subdir]
1648 set env(DEFS) [file join [pwd] defs]
1650 cd [file join $objdir $subdir]
1651 set env(OBJDIR) [pwd]
1654 set env(SRCDIR) $abs_srcdir
1655 set env(GDBTK_VERBOSE) 1
1656 set env(GDBTK_LOGFILE) [file join $objdir gdb.log]
1657 set env(GDBTK_TEST_RUNNING) 1
1658 set err [catch {exec $GDB -nx -q --tclcommand=$test} res]
1660 perror "Execing $GDB failed: $res"
1666 # gdbtk tests call this function to print out the results of the
1667 # tests. The argument is a proper list of lists of the form:
1668 # {status name description msg}. All of these things typically
1669 # come from the testsuite harness.
1670 proc gdbtk_analyze_results {results} {
1671 foreach test $results {
1672 set status [lindex $test 0]
1673 set name [lindex $test 1]
1674 set description [lindex $test 2]
1675 set msg [lindex $test 3]
1679 pass "$description ($name)"
1683 fail "$description ($name)"
1691 xfail "$description ($name)"
1695 xpass "$description ($name)"
1701 # Print a message and return true if a test should be skipped
1702 # due to lack of floating point suport.
1704 proc gdb_skip_float_test { msg } {
1705 if [target_info exists gdb,skip_float_tests] {
1706 verbose "Skipping test '$msg': no float tests.";
1712 # Print a message and return true if a test should be skipped
1713 # due to lack of stdio support.
1715 proc gdb_skip_stdio_test { msg } {
1716 if [target_info exists gdb,noinferiorio] {
1717 verbose "Skipping test '$msg': no inferior i/o.";
1723 proc gdb_skip_bogus_test { msg } {