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 [target_info exists gdb,timeout] {
461 set tmt [target_info gdb,timeout];
463 if [info exists timeout] {
467 if [info exists timeout] {
475 -re "\\*\\*\\* DOSEXIT code.*" {
476 if { $message != "" } {
479 gdb_suppress_entire_file "GDB died";
482 -re "Ending remote debugging.*$gdb_prompt $" {
483 if ![isnative] then {
484 warning "Can`t communicate to remote target."
490 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
491 if ![string match "" $message] then {
496 -re "(${question_string})$" {
497 send_gdb "$response_string\n";
500 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
501 perror "Undefined command \"$command\"."
505 -re "Ambiguous command.*$gdb_prompt $" {
506 perror "\"$command\" is not a unique command name."
510 -re "Program exited with code \[0-9\]+.*$gdb_prompt $" {
511 if ![string match "" $message] then {
512 set errmsg "$message: the program exited"
514 set errmsg "$command: the program exited"
519 -re "The program is not being run.*$gdb_prompt $" {
520 if ![string match "" $message] then {
521 set errmsg "$message: the program is no longer running"
523 set errmsg "$command: the program is no longer running"
528 -re ".*$gdb_prompt $" {
529 if ![string match "" $message] then {
536 perror "Window too small."
539 -re "\\(y or n\\) " {
541 perror "Got interactive prompt."
545 perror "Process no longer exists"
546 if { $message != "" } {
552 perror "internal buffer is full."
556 if ![string match "" $message] then {
557 fail "$message (timeout)"
565 # Test that a command gives an error. For pass or fail, return
566 # a 1 to indicate that more tests can proceed. However a timeout
567 # is a serious error, generates a special fail message, and causes
568 # a 0 to be returned to indicate that more tests are likely to fail
571 proc test_print_reject { args } {
575 if [llength $args]==2 then {
576 set expectthis [lindex $args 1]
578 set expectthis "should never match this bogus string"
580 set sendthis [lindex $args 0]
582 send_user "Sending \"$sendthis\" to gdb\n"
583 send_user "Looking to match \"$expectthis\"\n"
585 send_gdb "$sendthis\n"
586 #FIXME: Should add timeout as parameter.
588 -re "A .* in expression.*\\.*$gdb_prompt $" {
589 pass "reject $sendthis"
592 -re "Invalid syntax in expression.*$gdb_prompt $" {
593 pass "reject $sendthis"
596 -re "Junk after end of expression.*$gdb_prompt $" {
597 pass "reject $sendthis"
600 -re "Invalid number.*$gdb_prompt $" {
601 pass "reject $sendthis"
604 -re "Invalid character constant.*$gdb_prompt $" {
605 pass "reject $sendthis"
608 -re "No symbol table is loaded.*$gdb_prompt $" {
609 pass "reject $sendthis"
612 -re "No symbol .* in current context.*$gdb_prompt $" {
613 pass "reject $sendthis"
616 -re "$expectthis.*$gdb_prompt $" {
617 pass "reject $sendthis"
620 -re ".*$gdb_prompt $" {
621 fail "reject $sendthis"
625 fail "reject $sendthis (eof or timeout)"
631 # Given an input string, adds backslashes as needed to create a
632 # regexp that will match the string.
634 proc string_to_regexp {str} {
636 regsub -all {[]*+.|()^$\[]} $str {\\&} result
640 # Same as gdb_test, but the second parameter is not a regexp,
641 # but a string that must match exactly.
643 proc gdb_test_exact { args } {
644 upvar timeout timeout
646 set command [lindex $args 0]
648 # This applies a special meaning to a null string pattern. Without
649 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
650 # messages from commands that should have no output except a new
651 # prompt. With this, only results of a null string will match a null
654 set pattern [lindex $args 1]
655 if [string match $pattern ""] {
656 set pattern [string_to_regexp [lindex $args 0]]
658 set pattern [string_to_regexp [lindex $args 1]]
661 # It is most natural to write the pattern argument with only
662 # embedded \n's, especially if you are trying to avoid Tcl quoting
663 # problems. But gdb_expect really wants to see \r\n in patterns. So
664 # transform the pattern here. First transform \r\n back to \n, in
665 # case some users of gdb_test_exact already do the right thing.
666 regsub -all "\r\n" $pattern "\n" pattern
667 regsub -all "\n" $pattern "\r\n" pattern
668 if [llength $args]==3 then {
669 set message [lindex $args 2]
674 return [gdb_test $command $pattern $message]
677 proc gdb_reinitialize_dir { subdir } {
680 if [is_remote host] {
685 -re "Reinitialize source path to empty.*y or n. " {
688 -re "Source directories searched.*$gdb_prompt $" {
689 send_gdb "dir $subdir\n"
691 -re "Source directories searched.*$gdb_prompt $" {
692 verbose "Dir set to $subdir"
694 -re "$gdb_prompt $" {
695 perror "Dir \"$subdir\" failed."
699 -re "$gdb_prompt $" {
700 perror "Dir \"$subdir\" failed."
704 -re "$gdb_prompt $" {
705 perror "Dir \"$subdir\" failed."
711 # gdb_exit -- exit the GDB, killing the target program if necessary
713 proc default_gdb_exit {} {
719 gdb_stop_suppressing_tests;
721 if ![info exists gdb_spawn_id] {
725 verbose "Quitting $GDB $GDBFLAGS"
727 if { [is_remote host] && [board_info host exists fileid] } {
734 -re "DOSEXIT code" { }
739 if ![is_remote host] {
746 # load a file into the debugger.
747 # return a -1 if anything goes wrong.
749 proc gdb_file_cmd { arg } {
755 upvar timeout timeout
757 if [is_remote host] {
758 set arg [remote_download host $arg];
760 error "download failed"
765 send_gdb "file $arg\n"
767 -re "Reading symbols from.*done.*$gdb_prompt $" {
768 verbose "\t\tLoaded $arg into the $GDB"
771 -re "has no symbol-table.*$gdb_prompt $" {
772 perror "$arg wasn't compiled with \"-g\""
775 -re "A program is being debugged already.*Kill it.*y or n. $" {
777 verbose "\t\tKilling previous program being debugged"
780 -re "Load new symbol table from \".*\".*y or n. $" {
783 -re "Reading symbols from.*done.*$gdb_prompt $" {
784 verbose "\t\tLoaded $arg with new symbol table into $GDB"
788 perror "(timeout) Couldn't load $arg, other program already loaded."
793 -re "No such file or directory.*$gdb_prompt $" {
794 perror "($arg) No such file or directory\n"
797 -re "$gdb_prompt $" {
798 perror "couldn't load $arg into $GDB."
802 perror "couldn't load $arg into $GDB (timed out)."
806 # This is an attempt to detect a core dump, but seems not to
807 # work. Perhaps we need to match .* followed by eof, in which
808 # gdb_expect does not seem to have a way to do that.
809 perror "couldn't load $arg into $GDB (end of file)."
816 # start gdb -- start gdb running, default procedure
818 # When running over NFS, particularly if running many simultaneous
819 # tests on different hosts all using the same server, things can
820 # get really slow. Give gdb at least 3 minutes to start up.
822 proc default_gdb_start { } {
830 gdb_stop_suppressing_tests;
832 verbose "Spawning $GDB -nw $GDBFLAGS"
834 if [info exists gdb_spawn_id] {
838 if ![is_remote host] {
839 if { [which $GDB] == 0 } then {
840 perror "$GDB does not exist."
844 set res [remote_spawn host "$GDB -nw $GDBFLAGS [host_info gdb_opts]"];
845 if { $res < 0 || $res == "" } {
846 perror "Spawning $GDB failed."
850 -re "\[\r\n\]$gdb_prompt $" {
851 verbose "GDB initialized."
853 -re "$gdb_prompt $" {
854 perror "GDB never initialized."
858 perror "(timeout) GDB never initialized after 10 seconds."
864 # force the height to "unlimited", so no pagers get used
866 send_gdb "set height 0\n"
868 -re "$gdb_prompt $" {
869 verbose "Setting height to 0." 2
872 warning "Couldn't set the height to 0"
875 # force the width to "unlimited", so no wraparound occurs
876 send_gdb "set width 0\n"
878 -re "$gdb_prompt $" {
879 verbose "Setting width to 0." 2
882 warning "Couldn't set the width to 0."
888 # Return a 1 for configurations for which we don't even want to try to
891 proc skip_cplus_tests {} {
892 if { [istarget "d10v-*-*"] } {
895 if { [istarget "h8300-*-*"] } {
901 # * For crosses, the CHILL runtime doesn't build because it can't find
902 # setjmp.h, stdio.h, etc.
903 # * For AIX (as of 16 Mar 95), (a) there is no language code for
904 # CHILL in output_epilog in gcc/config/rs6000/rs6000.c, (b) collect2
905 # does not get along with AIX's too-clever linker.
906 # * On Irix5, there is a bug whereby set of bool, etc., don't get
907 # TYPE_LOW_BOUND for the bool right because force_to_range_type doesn't
908 # work with stub types.
909 # Lots of things seem to fail on the PA, and since it's not a supported
910 # chill target at the moment, don't run the chill tests.
912 proc skip_chill_tests {} {
913 if ![info exists do_chill_tests] {
916 eval set skip_chill [expr ![isnative] || [istarget "*-*-aix*"] || [istarget "*-*-irix5*"] || [istarget "*-*-irix6*"] || [istarget "alpha-*-osf*"] || [istarget "hppa*-*-*"]]
917 verbose "Skip chill tests is $skip_chill"
921 # Skip all the tests in the file if you are not on an hppa running
924 proc skip_hp_tests {} {
925 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
926 verbose "Skip hp tests is $skip_hp"
930 proc get_compiler_info {binfile args} {
931 # Create and source the file that provides information about the compiler
932 # used to compile the test case.
933 # Compiler_type can be null or c++. If null we assume c.
936 # These two come from compiler.c.
937 global signed_keyword_not_used
940 if {![istarget "hppa*-*-hpux*"]} {
941 if { [llength $args] > 0 } {
942 if {$args == "c++"} {
943 if { [gdb_compile "${srcdir}/lib/compiler.cc" "${binfile}.ci" preprocess {}] != "" } {
944 perror "Couldn't make ${binfile}.ci file"
949 if { [gdb_compile "${srcdir}/lib/compiler.c" "${binfile}.ci" preprocess {}] != "" } {
950 perror "Couldn't make ${binfile}.ci file"
955 if { [llength $args] > 0 } {
956 if {$args == "c++"} {
957 if { [eval gdb_preprocess \
958 [list "${srcdir}/lib/compiler.cc" "${binfile}.ci"] \
960 perror "Couldn't make ${binfile}.ci file"
964 } elseif { $args != "f77" } {
965 if { [eval gdb_preprocess \
966 [list "${srcdir}/lib/compiler.c" "${binfile}.ci"] \
968 perror "Couldn't make ${binfile}.ci file"
974 uplevel \#0 { set gcc_compiled 0 }
976 if { [llength $args] == 0 || $args != "f77" } {
980 # Most compilers will evaluate comparisons and other boolean
981 # operations to 0 or 1.
982 uplevel \#0 { set true 1 }
983 uplevel \#0 { set false 0 }
985 uplevel \#0 { set hp_cc_compiler 0 }
986 uplevel \#0 { set hp_aCC_compiler 0 }
987 uplevel \#0 { set hp_f77_compiler 0 }
988 uplevel \#0 { set hp_f90_compiler 0 }
989 if { !$gcc_compiled && [istarget "hppa*-*-hpux*"] } {
990 # Check for the HP compilers
991 set compiler [lindex [split [get_compiler $args] " "] 0]
992 catch "exec what $compiler" output
993 if [regexp ".*HP aC\\+\\+.*" $output] {
994 uplevel \#0 { set hp_aCC_compiler 1 }
995 # Use of aCC results in boolean results being displayed as
997 uplevel \#0 { set true true }
998 uplevel \#0 { set false false }
999 } elseif [regexp ".*HP C Compiler.*" $output] {
1000 uplevel \#0 { set hp_cc_compiler 1 }
1001 } elseif [regexp ".*HP-UX f77.*" $output] {
1002 uplevel \#0 { set hp_f77_compiler 1 }
1003 } elseif [regexp ".*HP-UX f90.*" $output] {
1004 uplevel \#0 { set hp_f90_compiler 1 }
1011 proc get_compiler {args} {
1012 global CC CC_FOR_TARGET CXX CXX_FOR_TARGET F77_FOR_TARGET
1014 if { [llength $args] == 0
1015 || ([llength $args] == 1 && [lindex $args 0] == "") } {
1016 set which_compiler "c"
1018 if { $args =="c++" } {
1019 set which_compiler "c++"
1020 } elseif { $args =="f77" } {
1021 set which_compiler "f77"
1023 perror "Unknown compiler type supplied to gdb_preprocess"
1028 if [info exists CC_FOR_TARGET] {
1029 if {$which_compiler == "c"} {
1030 set compiler $CC_FOR_TARGET
1034 if [info exists CXX_FOR_TARGET] {
1035 if {$which_compiler == "c++"} {
1036 set compiler $CXX_FOR_TARGET
1040 if [info exists F77_FOR_TARGET] {
1041 if {$which_compiler == "f77"} {
1042 set compiler $F77_FOR_TARGET
1046 if { ![info exists compiler] } {
1047 if { $which_compiler == "c" } {
1048 if {[info exists CC]} {
1052 if { $which_compiler == "c++" } {
1053 if {[info exists CXX]} {
1057 if {![info exists compiler]} {
1058 set compiler [board_info [target_info name] compiler];
1059 if { $compiler == "" } {
1060 perror "get_compiler: No compiler found"
1069 proc gdb_preprocess {source dest args} {
1070 set compiler [get_compiler "$args"]
1071 if { $compiler == "" } {
1075 set cmdline "$compiler -E $source > $dest"
1077 verbose "Invoking $compiler -E $source > $dest"
1078 verbose -log "Executing on local host: $cmdline" 2
1079 set status [catch "exec ${cmdline}" exec_output]
1081 set result [prune_warnings $exec_output]
1082 regsub "\[\r\n\]*$" "$result" "" result;
1083 regsub "^\[\r\n\]*" "$result" "" result;
1084 if { $result != "" } {
1085 clone_output "gdb compile failed, $result"
1090 proc gdb_compile {source dest type options} {
1091 global GDB_TESTCASE_OPTIONS;
1093 if [target_info exists gdb_stub] {
1094 set options2 { "additional_flags=-Dusestubs" }
1095 lappend options "libs=[target_info gdb_stub]";
1096 set options [concat $options2 $options]
1098 if [target_info exists is_vxworks] {
1099 set options2 { "additional_flags=-Dvxworks" }
1100 lappend options "libs=[target_info gdb_stub]";
1101 set options [concat $options2 $options]
1103 if [info exists GDB_TESTCASE_OPTIONS] {
1104 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
1106 verbose "options are $options"
1107 verbose "source is $source $dest $type $options"
1109 set result [target_compile $source $dest $type $options];
1110 regsub "\[\r\n\]*$" "$result" "" result;
1111 regsub "^\[\r\n\]*" "$result" "" result;
1112 if { $result != "" } {
1113 clone_output "gdb compile failed, $result"
1118 proc send_gdb { string } {
1119 global suppress_flag;
1120 if { $suppress_flag } {
1121 return "suppressed";
1123 return [remote_send host "$string"];
1129 proc gdb_expect { args } {
1130 # allow -notransfer expect flag specification,
1131 # used by gdb_test routine for multi-line commands.
1132 # packed with gtimeout when fed to remote_expect routine,
1133 # which is a hack but due to what looks like a res and orig
1134 # parsing problem in remote_expect routine (dejagnu/lib/remote.exp):
1135 # what's fed into res is not removed from orig.
1137 if { [lindex $args 0] == "-notransfer" } {
1138 set notransfer -notransfer;
1139 set args [lrange $args 1 end];
1144 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
1145 set gtimeout [lindex $args 0];
1146 set expcode [list [lindex $args 1]];
1148 upvar timeout timeout;
1151 if [target_info exists gdb,timeout] {
1152 if [info exists timeout] {
1153 if { $timeout < [target_info gdb,timeout] } {
1154 set gtimeout [target_info gdb,timeout];
1156 set gtimeout $timeout;
1159 set gtimeout [target_info gdb,timeout];
1163 if ![info exists gtimeout] {
1165 if [info exists timeout] {
1166 set gtimeout $timeout;
1173 global suppress_flag;
1174 global remote_suppress_flag;
1175 if [info exists remote_suppress_flag] {
1176 set old_val $remote_suppress_flag;
1178 if [info exists suppress_flag] {
1179 if { $suppress_flag } {
1180 set remote_suppress_flag 1;
1184 {uplevel remote_expect host "$gtimeout $notransfer" $expcode} string];
1185 if [info exists old_val] {
1186 set remote_suppress_flag $old_val;
1188 if [info exists remote_suppress_flag] {
1189 unset remote_suppress_flag;
1194 global errorInfo errorCode;
1196 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
1197 } elseif {$code == 2} {
1198 return -code return $string
1199 } elseif {$code == 3} {
1201 } elseif {$code > 4} {
1202 return -code $code $string
1206 # gdb_expect_list MESSAGE SENTINEL LIST -- expect a sequence of outputs
1208 # Check for long sequence of output by parts.
1209 # MESSAGE: is the test message to be printed with the test success/fail.
1210 # SENTINEL: Is the terminal pattern indicating that output has finished.
1211 # LIST: is the sequence of outputs to match.
1212 # If the sentinel is recognized early, it is considered an error.
1215 # 1 if the test failed,
1216 # 0 if the test passes,
1217 # -1 if there was an internal error.
1219 proc gdb_expect_list {test sentinel list} {
1221 global suppress_flag
1224 if { $suppress_flag } {
1227 while { ${index} < [llength ${list}] } {
1228 set pattern [lindex ${list} ${index}]
1229 set index [expr ${index} + 1]
1230 if { ${index} == [llength ${list}] } {
1233 -re "${pattern}${sentinel}" {
1234 pass "${test}, pattern ${index} + sentinel"
1237 fail "${test}, pattern ${index} + sentinel"
1241 fail "${test}, pattern ${index} + sentinel (timeout)"
1246 unresolved "${test}, pattern ${index} + sentinel"
1252 pass "${test}, pattern ${index}"
1255 fail "${test}, pattern ${index}"
1259 fail "${test}, pattern ${index} (timeout)"
1264 unresolved "${test}, pattern ${index}"
1277 proc gdb_suppress_entire_file { reason } {
1278 global suppress_flag;
1280 warning "$reason\n";
1281 set suppress_flag -1;
1285 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
1286 # gdb_expect to fail immediately (until the next call to
1287 # gdb_stop_suppressing_tests).
1289 proc gdb_suppress_tests { args } {
1290 global suppress_flag;
1292 return; # fnf - disable pending review of results where
1293 # testsuite ran better without this
1296 if { $suppress_flag == 1 } {
1297 if { [llength $args] > 0 } {
1298 warning "[lindex $args 0]\n";
1300 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
1306 # Clear suppress_flag.
1308 proc gdb_stop_suppressing_tests { } {
1309 global suppress_flag;
1311 if [info exists suppress_flag] {
1312 if { $suppress_flag > 0 } {
1313 set suppress_flag 0;
1314 clone_output "Tests restarted.\n";
1317 set suppress_flag 0;
1321 proc gdb_clear_suppressed { } {
1322 global suppress_flag;
1324 set suppress_flag 0;
1327 proc gdb_start { } {
1332 catch default_gdb_exit
1336 # gdb_load -- load a file into the debugger.
1337 # return a -1 if anything goes wrong.
1339 proc gdb_load { arg } {
1340 return [gdb_file_cmd $arg]
1343 proc gdb_continue { function } {
1346 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
1349 proc default_gdb_init { args } {
1350 gdb_clear_suppressed;
1352 # Uh, this is lame. Really, really, really lame. But there's this *one*
1353 # testcase that will fail in random places if we don't increase this.
1356 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
1357 if { [llength $args] > 0 } {
1360 set file [lindex $args 0];
1362 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
1365 if [target_info exists gdb_prompt] {
1366 set gdb_prompt [target_info gdb_prompt];
1368 set gdb_prompt "\\(gdb\\)"
1372 proc gdb_init { args } {
1373 return [eval default_gdb_init $args];
1376 proc gdb_finish { } {
1381 set debug_format "unknown"
1383 # Run the gdb command "info source" and extract the debugging format
1384 # information from the output and save it in debug_format.
1386 proc get_debug_format { } {
1392 set debug_format "unknown"
1393 send_gdb "info source\n"
1395 -re "Compiled with (.*) debugging format.\r\n$gdb_prompt $" {
1396 set debug_format $expect_out(1,string)
1397 verbose "debug format is $debug_format"
1400 -re "No current source file.\r\n$gdb_prompt $" {
1401 perror "get_debug_format used when no current source file"
1404 -re "$gdb_prompt $" {
1405 warning "couldn't check debug format (no valid response)."
1409 warning "couldn't check debug format (timed out)."
1415 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
1416 # COFF, stabs, etc). If that format matches the format that the
1417 # current test was compiled with, then the next test is expected to
1418 # fail for any target. Returns 1 if the next test or set of tests is
1419 # expected to fail, 0 otherwise (or if it is unknown). Must have
1420 # previously called get_debug_format.
1422 proc setup_xfail_format { format } {
1425 if [string match $debug_format $format] then {
1432 proc gdb_step_for_stub { } {
1435 if ![target_info exists gdb,use_breakpoint_for_stub] {
1436 if [target_info exists gdb_stub_step_command] {
1437 set command [target_info gdb_stub_step_command];
1441 send_gdb "${command}\n";
1444 -re "(main.* at |.*in .*start).*$gdb_prompt" {
1447 -re ".*$gdb_prompt" {
1449 if { $tries == 5 } {
1450 fail "stepping out of breakpoint function";
1453 send_gdb "${command}\n";
1457 fail "stepping out of breakpoint function";
1464 -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" {
1465 set file $expect_out(1,string);
1466 set linenum [expr $expect_out(2,string) + 1];
1467 set breakplace "${file}:${linenum}";
1471 send_gdb "break ${breakplace}\n";
1473 -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" {
1474 set breakpoint $expect_out(1,string);
1476 -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" {
1477 set breakpoint $expect_out(1,string);
1481 send_gdb "continue\n";
1483 -re "Breakpoint ${breakpoint},.*$gdb_prompt" {
1484 gdb_test "delete $breakpoint" ".*" "";
1491 ### gdb_get_line_number TEXT [FILE]
1493 ### Search the source file FILE, and return the line number of a line
1494 ### containing TEXT. Use this function instead of hard-coding line
1495 ### numbers into your test script.
1497 ### Specifically, this function uses GDB's "search" command to search
1498 ### FILE for the first line containing TEXT, and returns its line
1499 ### number. Thus, FILE must be a source file, compiled into the
1500 ### executable you are running. If omitted, FILE defaults to the
1501 ### value of the global variable `srcfile'; most test scripts set
1502 ### `srcfile' appropriately at the top anyway.
1504 ### Use this function to keep your test scripts independent of the
1505 ### exact line numbering of the source file. Don't write:
1507 ### send_gdb "break 20"
1509 ### This means that if anyone ever edits your test's source file,
1510 ### your test could break. Instead, put a comment like this on the
1511 ### source file line you want to break at:
1513 ### /* breakpoint spot: frotz.exp: test name */
1515 ### and then write, in your test script (which we assume is named
1518 ### send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
1520 ### (Yes, Tcl knows how to handle the nested quotes and brackets.
1523 ### % puts "foo [lindex "bar baz" 1]"
1526 ### Tcl is quite clever, for a little stringy language.)
1528 proc gdb_get_line_number {text {file /omitted/}} {
1532 if {! [string compare $file /omitted/]} {
1537 gdb_test "list ${file}:1,1" ".*" ""
1538 send_gdb "search ${text}\n"
1540 -re "\[\r\n\]+(\[0-9\]+)\[ \t\].*${text}.*$gdb_prompt $" {
1541 set result $expect_out(1,string)
1543 -re ".*$gdb_prompt $" {
1544 fail "find line number containing \"${text}\""
1547 fail "find line number containing \"${text}\" (timeout)"
1553 # gdb_continue_to_end:
1554 # The case where the target uses stubs has to be handled specially. If a
1555 # stub is used, we set a breakpoint at exit because we cannot rely on
1556 # exit() behavior of a remote target.
1558 # mssg is the error message that gets printed.
1560 proc gdb_continue_to_end {mssg} {
1561 if [target_info exists use_gdb_stub] {
1562 if {![gdb_breakpoint "exit"]} {
1565 gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \
1566 "continue until exit at $mssg"
1568 # Continue until we exit. Should not stop again.
1569 # Don't bother to check the output of the program, that may be
1570 # extremely tough for some remote systems.
1571 gdb_test "continue"\
1572 "Continuing.\[\r\n0-9\]+Program exited normally\\..*"\
1573 "continue until exit at $mssg"
1577 proc rerun_to_main {} {
1580 if [target_info exists use_gdb_stub] {
1583 -re ".*Breakpoint .*main .*$gdb_prompt $"\
1584 {pass "rerun to main" ; return 0}
1585 -re "$gdb_prompt $"\
1586 {fail "rerun to main" ; return 0}
1587 timeout {fail "(timeout) rerun to main" ; return 0}
1592 -re "Starting program.*$gdb_prompt $"\
1593 {pass "rerun to main" ; return 0}
1594 -re "$gdb_prompt $"\
1595 {fail "rerun to main" ; return 0}
1596 timeout {fail "(timeout) rerun to main" ; return 0}
1602 # srcdir = testsuite src dir (e.g., devo/gdb/testsuite)
1603 # objdir = testsuite obj dir (e.g., gdb/testsuite)
1604 # subdir = subdir of testsuite (e.g., gdb.gdbtk)
1607 # env(DEFS)=the "defs" files (e.g., devo/gdb/testsuite/gdb.gdbtk/defs)
1608 # env(SRCDIR)=directory containing the test code (e.g., *.test)
1609 # env(OBJDIR)=directory which contains any executables
1610 # (e.g., gdb/testsuite/gdb.gdbtk)
1611 proc gdbtk_start {test} {
1615 global env srcdir subdir objdir
1617 gdb_stop_suppressing_tests;
1619 verbose "Starting $GDB -nx -q --tclcommand=$test"
1621 set real_test [which $test]
1622 if {$real_test == 0} {
1623 perror "$test is not found"
1627 if {![is_remote host]} {
1628 if { [which $GDB] == 0 } {
1629 perror "$GDB does not exist."
1637 set abs_srcdir [pwd]
1638 cd [file join $abs_srcdir .. gdbtk library]
1639 set env(GDBTK_LIBRARY) [pwd]
1640 cd [file join $abs_srcdir .. .. tcl library]
1641 set env(TCL_LIBRARY) [pwd]
1642 cd [file join $abs_srcdir .. .. tk library]
1643 set env(TK_LIBRARY) [pwd]
1644 cd [file join $abs_srcdir .. .. tix library]
1645 set env(TIX_LIBRARY) [pwd]
1646 cd [file join $abs_srcdir .. .. itcl itcl library]
1647 set env(ITCL_LIBRARY) [pwd]
1648 cd [file join .. $abs_srcdir .. .. libgui library]
1649 set env(CYGNUS_GUI_LIBRARY) [pwd]
1651 cd [file join $abs_srcdir $subdir]
1652 set env(DEFS) [file join [pwd] defs]
1654 cd [file join $objdir $subdir]
1655 set env(OBJDIR) [pwd]
1658 set env(SRCDIR) $abs_srcdir
1659 set env(GDBTK_VERBOSE) 1
1660 set env(GDBTK_LOGFILE) [file join $objdir gdb.log]
1661 set env(GDBTK_TEST_RUNNING) 1
1662 set err [catch {exec $GDB -nx -q --tclcommand=$test} res]
1664 perror "Execing $GDB failed: $res"
1670 # gdbtk tests call this function to print out the results of the
1671 # tests. The argument is a proper list of lists of the form:
1672 # {status name description msg}. All of these things typically
1673 # come from the testsuite harness.
1674 proc gdbtk_analyze_results {results} {
1675 foreach test $results {
1676 set status [lindex $test 0]
1677 set name [lindex $test 1]
1678 set description [lindex $test 2]
1679 set msg [lindex $test 3]
1683 pass "$description ($name)"
1687 fail "$description ($name)"
1695 xfail "$description ($name)"
1699 xpass "$description ($name)"
1705 # Print a message and return true if a test should be skipped
1706 # due to lack of floating point suport.
1708 proc gdb_skip_float_test { msg } {
1709 if [target_info exists gdb,skip_float_tests] {
1710 verbose "Skipping test '$msg': no float tests.";
1716 # Print a message and return true if a test should be skipped
1717 # due to lack of stdio support.
1719 proc gdb_skip_stdio_test { msg } {
1720 if [target_info exists gdb,noinferiorio] {
1721 verbose "Skipping test '$msg': no inferior i/o.";
1727 proc gdb_skip_bogus_test { msg } {