1 # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
21 # This file was written by Fred Fish. (fnf@cygnus.com)
23 # Generic gdb subroutines that should work for any target. If these
24 # need to be modified for any target, it can be done with a variable
25 # or by passing arguments.
33 if ![info exists CHILL_LIB] {
34 set CHILL_LIB [findfile $base_dir/../../gcc/ch/runtime/libchill.a "$base_dir/../../gcc/ch/runtime/libchill.a" [transform -lchill]]
36 verbose "using CHILL_LIB = $CHILL_LIB" 2
37 if ![info exists CHILL_RT0] {
38 set CHILL_RT0 [findfile $base_dir/../../gcc/ch/runtime/chillrt0.o "$base_dir/../../gcc/ch/runtime/chillrt0.o" ""]
40 verbose "using CHILL_RT0 = $CHILL_RT0" 2
42 if [info exists TOOL_EXECUTABLE] {
43 set GDB $TOOL_EXECUTABLE;
45 if ![info exists GDB] {
46 if ![is_remote host] {
47 set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]]
49 set GDB [transform gdb];
52 verbose "using GDB = $GDB" 2
55 if ![info exists GDBFLAGS] {
58 verbose "using GDBFLAGS = $GDBFLAGS" 2
60 # The variable gdb_prompt is a regexp which matches the gdb prompt.
61 # Set it if it is not already set.
63 if ![info exists gdb_prompt] then {
64 set gdb_prompt "\[(\]gdb\[)\]"
67 # Needed for some tests under Cygwin.
71 if ![info exists env(EXEEXT)] {
74 set EXEEXT $env(EXEEXT)
77 ### Only procedures should come after this point.
80 # gdb_version -- extract and print the version number of GDB
82 proc default_gdb_version {} {
86 set fileid [open "gdb_cmd" w];
89 set cmdfile [remote_download host "gdb_cmd"];
90 set output [remote_exec host "$GDB -nw --command $cmdfile"]
91 remote_file build delete "gdb_cmd";
92 remote_file host delete "$cmdfile";
93 set tmp [lindex $output 1];
95 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
96 if ![is_remote host] {
97 clone_output "[which $GDB] version $version $GDBFLAGS\n"
99 clone_output "$GDB on remote host version $version $GDBFLAGS\n"
103 proc gdb_version { } {
104 return [default_gdb_version];
108 # gdb_unload -- unload a file if one is loaded
117 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
118 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
119 -re "A program is being debugged already..*Kill it.*y or n. $"\
121 verbose "\t\tKilling previous program being debugged"
124 -re "Discard symbol table from .*y or n.*$" {
128 -re "$gdb_prompt $" {}
130 perror "couldn't unload file in $GDB (timed out)."
136 # Many of the tests depend on setting breakpoints at various places and
137 # running until that breakpoint is reached. At times, we want to start
138 # with a clean-slate with respect to breakpoints, so this utility proc
139 # lets us do this without duplicating this code everywhere.
142 proc delete_breakpoints {} {
145 # we need a larger timeout value here or this thing just confuses
146 # itself. May need a better implementation if possible. - guo
148 send_gdb "delete breakpoints\n"
150 -re "Delete all breakpoints.*y or n.*$" {
154 -re "$gdb_prompt $" { # This happens if there were no breakpoints
156 timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
158 send_gdb "info breakpoints\n"
160 -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
161 -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
162 -re "Delete all breakpoints.*or n.*$" {
166 timeout { perror "info breakpoints (timeout)" ; return }
172 # Generic run command.
174 # The second pattern below matches up to the first newline *only*.
175 # Using ``.*$'' could swallow up output that we attempt to match
178 proc gdb_run_cmd {args} {
181 if [target_info exists gdb_init_command] {
182 send_gdb "[target_info gdb_init_command]\n";
184 -re "$gdb_prompt $" { }
186 perror "gdb_init_command for target failed";
192 if [target_info exists use_gdb_stub] {
193 if [target_info exists gdb,do_reload_on_run] {
194 # Specifying no file, defaults to the executable
195 # currently being debugged.
196 if { [gdb_load ""] < 0 } {
199 send_gdb "continue\n";
201 -re "Continu\[^\r\n\]*\[\r\n\]" {}
207 if [target_info exists gdb,start_symbol] {
208 set start [target_info gdb,start_symbol];
212 send_gdb "jump *$start\n"
214 while { $start_attempt } {
215 # Cap (re)start attempts at three to ensure that this loop
216 # always eventually fails. Don't worry about trying to be
217 # clever and not send a command when it has failed.
218 if [expr $start_attempt > 3] {
219 perror "Jump to start() failed (retry count exceeded)";
222 set start_attempt [expr $start_attempt + 1];
224 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
227 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
228 perror "Can't find start symbol to run in gdb_run";
231 -re "No symbol \"start\" in current.*$gdb_prompt $" {
232 send_gdb "jump *_start\n";
234 -re "No symbol.*context.*$gdb_prompt $" {
237 -re "Line.* Jump anyway.*y or n. $" {
240 -re "The program is not being run.*$gdb_prompt $" {
241 if { [gdb_load ""] < 0 } {
244 send_gdb "jump *$start\n";
247 perror "Jump to start() failed (timeout)";
252 if [target_info exists gdb_stub] {
254 -re "$gdb_prompt $" {
255 send_gdb "continue\n"
261 send_gdb "run $args\n"
262 # This doesn't work quite right yet.
264 -re "The program .* has been started already.*y or n. $" {
268 -re "Starting program: \[^\r\n\]*" {}
272 proc gdb_breakpoint { function } {
276 send_gdb "break $function\n"
277 # The first two regexps are what we get with -g, the third is without -g.
279 -re "Breakpoint \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
280 -re "Breakpoint \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
281 -re "Breakpoint \[0-9\]* at .*$gdb_prompt $" {}
282 -re "$gdb_prompt $" { fail "setting breakpoint at $function" ; return 0 }
283 timeout { fail "setting breakpoint at $function (timeout)" ; return 0 }
288 # Set breakpoint at function and run gdb until it breaks there.
289 # Since this is the only breakpoint that will be set, if it stops
290 # at a breakpoint, we will assume it is the one we want. We can't
291 # just compare to "function" because it might be a fully qualified,
292 # single quoted C++ function specifier.
294 proc runto { function } {
300 if ![gdb_breakpoint $function] {
306 # the "at foo.c:36" output we get with -g.
307 # the "in func" output we get without -g.
309 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
312 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
315 -re "$gdb_prompt $" {
316 fail "running to $function in runto"
320 fail "running to $function in runto (timeout)"
328 # runto_main -- ask gdb to run until we hit a breakpoint at main.
329 # The case where the target uses stubs has to be handled
330 # specially--if it uses stubs, assuming we hit
331 # breakpoint() and just step out of the function.
333 proc runto_main { } {
337 if ![target_info exists gdb_stub] {
349 ### Continue, and expect to hit a breakpoint.
350 ### Report a pass or fail, depending on whether it seems to have
351 ### worked. Use NAME as part of the test name; each call to
352 ### continue_to_breakpoint should use a NAME which is unique within
354 proc gdb_continue_to_breakpoint {name} {
356 set full_name "continue to breakpoint: $name"
358 send_gdb "continue\n"
360 -re "Breakpoint .* at .*\r\n$gdb_prompt $" {
363 -re ".*$gdb_prompt $" {
367 fail "$full_name (timeout)"
374 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
375 # Send a command to gdb; test the result.
377 # COMMAND is the command to execute, send to GDB with send_gdb. If
378 # this is the null string no command is sent.
379 # PATTERN is the pattern to match for a PASS, and must NOT include
380 # the \r\n sequence immediately before the gdb prompt.
381 # MESSAGE is an optional message to be printed. If this is
382 # omitted, then the pass/fail messages use the command string as the
383 # message. (If this is the empty string, then sometimes we don't
384 # call pass or fail at all; I don't understand this at all.)
385 # QUESTION is a question GDB may ask in response to COMMAND, like
387 # RESPONSE is the response to send if QUESTION appears.
390 # 1 if the test failed,
391 # 0 if the test passes,
392 # -1 if there was an internal error.
394 proc gdb_test { args } {
398 upvar timeout timeout
400 if [llength $args]>2 then {
401 set message [lindex $args 2]
403 set message [lindex $args 0]
405 set command [lindex $args 0]
406 set pattern [lindex $args 1]
408 if [llength $args]==5 {
409 set question_string [lindex $args 3];
410 set response_string [lindex $args 4];
412 set question_string "^FOOBAR$"
416 send_user "Sending \"$command\" to gdb\n"
417 send_user "Looking to match \"$pattern\"\n"
418 send_user "Message is \"$message\"\n"
422 set string "${command}\n";
423 if { $command != "" } {
424 while { "$string" != "" } {
425 set foo [string first "\n" "$string"];
426 set len [string length "$string"];
427 if { $foo < [expr $len - 1] } {
428 set str [string range "$string" 0 $foo];
429 if { [send_gdb "$str"] != "" } {
430 global suppress_flag;
432 if { ! $suppress_flag } {
433 perror "Couldn't send $command to GDB.";
438 # since we're checking if each line of the multi-line
439 # command are 'accepted' by GDB here,
440 # we need to set -notransfer expect option so that
441 # command output is not lost for pattern matching
444 -notransfer -re "\[\r\n\]" { verbose "partial: match" 3 }
445 timeout { verbose "partial: timeout" 3 }
447 set string [string range "$string" [expr $foo + 1] end];
452 if { "$string" != "" } {
453 if { [send_gdb "$string"] != "" } {
454 global suppress_flag;
456 if { ! $suppress_flag } {
457 perror "Couldn't send $command to GDB.";
465 if [target_info exists gdb,timeout] {
466 set tmt [target_info gdb,timeout];
468 if [info exists timeout] {
472 if [info exists timeout] {
480 -re "\\*\\*\\* DOSEXIT code.*" {
481 if { $message != "" } {
484 gdb_suppress_entire_file "GDB died";
487 -re "Ending remote debugging.*$gdb_prompt $" {
488 if ![isnative] then {
489 warning "Can`t communicate to remote target."
495 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
496 if ![string match "" $message] then {
501 -re "(${question_string})$" {
502 send_gdb "$response_string\n";
505 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
506 perror "Undefined command \"$command\"."
510 -re "Ambiguous command.*$gdb_prompt $" {
511 perror "\"$command\" is not a unique command name."
515 -re "Program exited with code \[0-9\]+.*$gdb_prompt $" {
516 if ![string match "" $message] then {
517 set errmsg "$message: the program exited"
519 set errmsg "$command: the program exited"
524 -re "The program is not being run.*$gdb_prompt $" {
525 if ![string match "" $message] then {
526 set errmsg "$message: the program is no longer running"
528 set errmsg "$command: the program is no longer running"
533 -re ".*$gdb_prompt $" {
534 if ![string match "" $message] then {
541 perror "Window too small."
544 -re "\\(y or n\\) " {
546 perror "Got interactive prompt."
550 perror "Process no longer exists"
551 if { $message != "" } {
557 perror "internal buffer is full."
561 if ![string match "" $message] then {
562 fail "$message (timeout)"
570 # Test that a command gives an error. For pass or fail, return
571 # a 1 to indicate that more tests can proceed. However a timeout
572 # is a serious error, generates a special fail message, and causes
573 # a 0 to be returned to indicate that more tests are likely to fail
576 proc test_print_reject { args } {
580 if [llength $args]==2 then {
581 set expectthis [lindex $args 1]
583 set expectthis "should never match this bogus string"
585 set sendthis [lindex $args 0]
587 send_user "Sending \"$sendthis\" to gdb\n"
588 send_user "Looking to match \"$expectthis\"\n"
590 send_gdb "$sendthis\n"
591 #FIXME: Should add timeout as parameter.
593 -re "A .* in expression.*\\.*$gdb_prompt $" {
594 pass "reject $sendthis"
597 -re "Invalid syntax in expression.*$gdb_prompt $" {
598 pass "reject $sendthis"
601 -re "Junk after end of expression.*$gdb_prompt $" {
602 pass "reject $sendthis"
605 -re "Invalid number.*$gdb_prompt $" {
606 pass "reject $sendthis"
609 -re "Invalid character constant.*$gdb_prompt $" {
610 pass "reject $sendthis"
613 -re "No symbol table is loaded.*$gdb_prompt $" {
614 pass "reject $sendthis"
617 -re "No symbol .* in current context.*$gdb_prompt $" {
618 pass "reject $sendthis"
621 -re "$expectthis.*$gdb_prompt $" {
622 pass "reject $sendthis"
625 -re ".*$gdb_prompt $" {
626 fail "reject $sendthis"
630 fail "reject $sendthis (eof or timeout)"
636 # Given an input string, adds backslashes as needed to create a
637 # regexp that will match the string.
639 proc string_to_regexp {str} {
641 regsub -all {[]*+.|()^$\[]} $str {\\&} result
645 # Same as gdb_test, but the second parameter is not a regexp,
646 # but a string that must match exactly.
648 proc gdb_test_exact { args } {
649 upvar timeout timeout
651 set command [lindex $args 0]
653 # This applies a special meaning to a null string pattern. Without
654 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
655 # messages from commands that should have no output except a new
656 # prompt. With this, only results of a null string will match a null
659 set pattern [lindex $args 1]
660 if [string match $pattern ""] {
661 set pattern [string_to_regexp [lindex $args 0]]
663 set pattern [string_to_regexp [lindex $args 1]]
666 # It is most natural to write the pattern argument with only
667 # embedded \n's, especially if you are trying to avoid Tcl quoting
668 # problems. But gdb_expect really wants to see \r\n in patterns. So
669 # transform the pattern here. First transform \r\n back to \n, in
670 # case some users of gdb_test_exact already do the right thing.
671 regsub -all "\r\n" $pattern "\n" pattern
672 regsub -all "\n" $pattern "\r\n" pattern
673 if [llength $args]==3 then {
674 set message [lindex $args 2]
679 return [gdb_test $command $pattern $message]
682 proc gdb_reinitialize_dir { subdir } {
685 if [is_remote host] {
690 -re "Reinitialize source path to empty.*y or n. " {
693 -re "Source directories searched.*$gdb_prompt $" {
694 send_gdb "dir $subdir\n"
696 -re "Source directories searched.*$gdb_prompt $" {
697 verbose "Dir set to $subdir"
699 -re "$gdb_prompt $" {
700 perror "Dir \"$subdir\" failed."
704 -re "$gdb_prompt $" {
705 perror "Dir \"$subdir\" failed."
709 -re "$gdb_prompt $" {
710 perror "Dir \"$subdir\" failed."
716 # gdb_exit -- exit the GDB, killing the target program if necessary
718 proc default_gdb_exit {} {
724 gdb_stop_suppressing_tests;
726 if ![info exists gdb_spawn_id] {
730 verbose "Quitting $GDB $GDBFLAGS"
732 if { [is_remote host] && [board_info host exists fileid] } {
739 -re "DOSEXIT code" { }
744 if ![is_remote host] {
751 # load a file into the debugger.
752 # return a -1 if anything goes wrong.
754 proc gdb_file_cmd { arg } {
760 upvar timeout timeout
762 if [is_remote host] {
763 set arg [remote_download host $arg];
765 error "download failed"
770 send_gdb "file $arg\n"
772 -re "Reading symbols from.*done.*$gdb_prompt $" {
773 verbose "\t\tLoaded $arg into the $GDB"
776 -re "has no symbol-table.*$gdb_prompt $" {
777 perror "$arg wasn't compiled with \"-g\""
780 -re "A program is being debugged already.*Kill it.*y or n. $" {
782 verbose "\t\tKilling previous program being debugged"
785 -re "Load new symbol table from \".*\".*y or n. $" {
788 -re "Reading symbols from.*done.*$gdb_prompt $" {
789 verbose "\t\tLoaded $arg with new symbol table into $GDB"
793 perror "(timeout) Couldn't load $arg, other program already loaded."
798 -re "No such file or directory.*$gdb_prompt $" {
799 perror "($arg) No such file or directory\n"
802 -re "$gdb_prompt $" {
803 perror "couldn't load $arg into $GDB."
807 perror "couldn't load $arg into $GDB (timed out)."
811 # This is an attempt to detect a core dump, but seems not to
812 # work. Perhaps we need to match .* followed by eof, in which
813 # gdb_expect does not seem to have a way to do that.
814 perror "couldn't load $arg into $GDB (end of file)."
821 # start gdb -- start gdb running, default procedure
823 # When running over NFS, particularly if running many simultaneous
824 # tests on different hosts all using the same server, things can
825 # get really slow. Give gdb at least 3 minutes to start up.
827 proc default_gdb_start { } {
835 gdb_stop_suppressing_tests;
837 verbose "Spawning $GDB -nw $GDBFLAGS"
839 if [info exists gdb_spawn_id] {
843 if ![is_remote host] {
844 if { [which $GDB] == 0 } then {
845 perror "$GDB does not exist."
849 set res [remote_spawn host "$GDB -nw $GDBFLAGS [host_info gdb_opts]"];
850 if { $res < 0 || $res == "" } {
851 perror "Spawning $GDB failed."
855 -re "\[\r\n\]$gdb_prompt $" {
856 verbose "GDB initialized."
858 -re "$gdb_prompt $" {
859 perror "GDB never initialized."
863 perror "(timeout) GDB never initialized after 10 seconds."
869 # force the height to "unlimited", so no pagers get used
871 send_gdb "set height 0\n"
873 -re "$gdb_prompt $" {
874 verbose "Setting height to 0." 2
877 warning "Couldn't set the height to 0"
880 # force the width to "unlimited", so no wraparound occurs
881 send_gdb "set width 0\n"
883 -re "$gdb_prompt $" {
884 verbose "Setting width to 0." 2
887 warning "Couldn't set the width to 0."
893 # Return a 1 for configurations for which we don't even want to try to
896 proc skip_cplus_tests {} {
897 if { [istarget "d10v-*-*"] } {
900 if { [istarget "h8300-*-*"] } {
906 # * For crosses, the CHILL runtime doesn't build because it can't find
907 # setjmp.h, stdio.h, etc.
908 # * For AIX (as of 16 Mar 95), (a) there is no language code for
909 # CHILL in output_epilog in gcc/config/rs6000/rs6000.c, (b) collect2
910 # does not get along with AIX's too-clever linker.
911 # * On Irix5, there is a bug whereby set of bool, etc., don't get
912 # TYPE_LOW_BOUND for the bool right because force_to_range_type doesn't
913 # work with stub types.
914 # Lots of things seem to fail on the PA, and since it's not a supported
915 # chill target at the moment, don't run the chill tests.
917 proc skip_chill_tests {} {
918 if ![info exists do_chill_tests] {
921 eval set skip_chill [expr ![isnative] || [istarget "*-*-aix*"] || [istarget "*-*-irix5*"] || [istarget "*-*-irix6*"] || [istarget "alpha-*-osf*"] || [istarget "hppa*-*-*"]]
922 verbose "Skip chill tests is $skip_chill"
926 # Skip all the tests in the file if you are not on an hppa running
929 proc skip_hp_tests {} {
930 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
931 verbose "Skip hp tests is $skip_hp"
935 proc get_compiler_info {binfile args} {
936 # Create and source the file that provides information about the compiler
937 # used to compile the test case.
938 # Compiler_type can be null or c++. If null we assume c.
941 # These two come from compiler.c.
942 global signed_keyword_not_used
945 if {![istarget "hppa*-*-hpux*"]} {
946 if { [llength $args] > 0 } {
947 if {$args == "c++"} {
948 if { [gdb_compile "${srcdir}/lib/compiler.cc" "${binfile}.ci" preprocess {}] != "" } {
949 perror "Couldn't make ${binfile}.ci file"
954 if { [gdb_compile "${srcdir}/lib/compiler.c" "${binfile}.ci" preprocess {}] != "" } {
955 perror "Couldn't make ${binfile}.ci file"
960 if { [llength $args] > 0 } {
961 if {$args == "c++"} {
962 if { [eval gdb_preprocess \
963 [list "${srcdir}/lib/compiler.cc" "${binfile}.ci"] \
965 perror "Couldn't make ${binfile}.ci file"
969 } elseif { $args != "f77" } {
970 if { [eval gdb_preprocess \
971 [list "${srcdir}/lib/compiler.c" "${binfile}.ci"] \
973 perror "Couldn't make ${binfile}.ci file"
979 uplevel \#0 { set gcc_compiled 0 }
981 if { [llength $args] == 0 || $args != "f77" } {
985 # Most compilers will evaluate comparisons and other boolean
986 # operations to 0 or 1.
987 uplevel \#0 { set true 1 }
988 uplevel \#0 { set false 0 }
990 uplevel \#0 { set hp_cc_compiler 0 }
991 uplevel \#0 { set hp_aCC_compiler 0 }
992 uplevel \#0 { set hp_f77_compiler 0 }
993 uplevel \#0 { set hp_f90_compiler 0 }
994 if { !$gcc_compiled && [istarget "hppa*-*-hpux*"] } {
995 # Check for the HP compilers
996 set compiler [lindex [split [get_compiler $args] " "] 0]
997 catch "exec what $compiler" output
998 if [regexp ".*HP aC\\+\\+.*" $output] {
999 uplevel \#0 { set hp_aCC_compiler 1 }
1000 # Use of aCC results in boolean results being displayed as
1002 uplevel \#0 { set true true }
1003 uplevel \#0 { set false false }
1004 } elseif [regexp ".*HP C Compiler.*" $output] {
1005 uplevel \#0 { set hp_cc_compiler 1 }
1006 } elseif [regexp ".*HP-UX f77.*" $output] {
1007 uplevel \#0 { set hp_f77_compiler 1 }
1008 } elseif [regexp ".*HP-UX f90.*" $output] {
1009 uplevel \#0 { set hp_f90_compiler 1 }
1016 proc get_compiler {args} {
1017 global CC CC_FOR_TARGET CXX CXX_FOR_TARGET F77_FOR_TARGET
1019 if { [llength $args] == 0
1020 || ([llength $args] == 1 && [lindex $args 0] == "") } {
1021 set which_compiler "c"
1023 if { $args =="c++" } {
1024 set which_compiler "c++"
1025 } elseif { $args =="f77" } {
1026 set which_compiler "f77"
1028 perror "Unknown compiler type supplied to gdb_preprocess"
1033 if [info exists CC_FOR_TARGET] {
1034 if {$which_compiler == "c"} {
1035 set compiler $CC_FOR_TARGET
1039 if [info exists CXX_FOR_TARGET] {
1040 if {$which_compiler == "c++"} {
1041 set compiler $CXX_FOR_TARGET
1045 if [info exists F77_FOR_TARGET] {
1046 if {$which_compiler == "f77"} {
1047 set compiler $F77_FOR_TARGET
1051 if { ![info exists compiler] } {
1052 if { $which_compiler == "c" } {
1053 if {[info exists CC]} {
1057 if { $which_compiler == "c++" } {
1058 if {[info exists CXX]} {
1062 if {![info exists compiler]} {
1063 set compiler [board_info [target_info name] compiler];
1064 if { $compiler == "" } {
1065 perror "get_compiler: No compiler found"
1074 proc gdb_preprocess {source dest args} {
1075 set compiler [get_compiler "$args"]
1076 if { $compiler == "" } {
1080 set cmdline "$compiler -E $source > $dest"
1082 verbose "Invoking $compiler -E $source > $dest"
1083 verbose -log "Executing on local host: $cmdline" 2
1084 set status [catch "exec ${cmdline}" exec_output]
1086 set result [prune_warnings $exec_output]
1087 regsub "\[\r\n\]*$" "$result" "" result;
1088 regsub "^\[\r\n\]*" "$result" "" result;
1089 if { $result != "" } {
1090 clone_output "gdb compile failed, $result"
1095 set gdb_wrapper_initialized 0
1097 proc gdb_wrapper_init { args } {
1098 global gdb_wrapper_initialized;
1099 global gdb_wrapper_file;
1100 global gdb_wrapper_flags;
1102 if { $gdb_wrapper_initialized == 1 } { return; }
1104 if {[target_info exists needs_status_wrapper] && \
1105 [target_info needs_status_wrapper] != "0" && \
1106 ![info exists gdb_wrapper_file]} {
1107 set result [build_wrapper "testglue.o"];
1108 if { $result != "" } {
1109 set gdb_wrapper_file [lindex $result 0];
1110 set gdb_wrapper_flags [lindex $result 1];
1112 warning "Status wrapper failed to build."
1115 set gdb_wrapper_initialized 1
1118 proc gdb_compile {source dest type options} {
1119 global GDB_TESTCASE_OPTIONS;
1120 global gdb_wrapper_file;
1121 global gdb_wrapper_flags;
1122 global gdb_wrapper_initialized;
1124 if [target_info exists gdb_stub] {
1125 set options2 { "additional_flags=-Dusestubs" }
1126 lappend options "libs=[target_info gdb_stub]";
1127 set options [concat $options2 $options]
1129 if [target_info exists is_vxworks] {
1130 set options2 { "additional_flags=-Dvxworks" }
1131 lappend options "libs=[target_info gdb_stub]";
1132 set options [concat $options2 $options]
1134 if [info exists GDB_TESTCASE_OPTIONS] {
1135 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
1137 verbose "options are $options"
1138 verbose "source is $source $dest $type $options"
1140 if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init }
1142 if {[target_info exists needs_status_wrapper] && \
1143 [target_info needs_status_wrapper] != "0" && \
1144 [info exists gdb_wrapper_file]} {
1145 lappend options "libs=${gdb_wrapper_file}"
1146 lappend options "ldflags=${gdb_wrapper_flags}"
1149 set result [target_compile $source $dest $type $options];
1150 regsub "\[\r\n\]*$" "$result" "" result;
1151 regsub "^\[\r\n\]*" "$result" "" result;
1152 if { $result != "" } {
1153 clone_output "gdb compile failed, $result"
1158 proc send_gdb { string } {
1159 global suppress_flag;
1160 if { $suppress_flag } {
1161 return "suppressed";
1163 return [remote_send host "$string"];
1169 proc gdb_expect { args } {
1170 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
1171 set gtimeout [lindex $args 0];
1172 set expcode [list [lindex $args 1]];
1174 upvar timeout timeout;
1177 if [target_info exists gdb,timeout] {
1178 if [info exists timeout] {
1179 if { $timeout < [target_info gdb,timeout] } {
1180 set gtimeout [target_info gdb,timeout];
1182 set gtimeout $timeout;
1185 set gtimeout [target_info gdb,timeout];
1189 if ![info exists gtimeout] {
1191 if [info exists timeout] {
1192 set gtimeout $timeout;
1199 global suppress_flag;
1200 global remote_suppress_flag;
1201 if [info exists remote_suppress_flag] {
1202 set old_val $remote_suppress_flag;
1204 if [info exists suppress_flag] {
1205 if { $suppress_flag } {
1206 set remote_suppress_flag 1;
1210 {uplevel remote_expect host $gtimeout $expcode} string];
1211 if [info exists old_val] {
1212 set remote_suppress_flag $old_val;
1214 if [info exists remote_suppress_flag] {
1215 unset remote_suppress_flag;
1220 global errorInfo errorCode;
1222 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
1223 } elseif {$code == 2} {
1224 return -code return $string
1225 } elseif {$code == 3} {
1227 } elseif {$code > 4} {
1228 return -code $code $string
1232 # gdb_expect_list MESSAGE SENTINEL LIST -- expect a sequence of outputs
1234 # Check for long sequence of output by parts.
1235 # MESSAGE: is the test message to be printed with the test success/fail.
1236 # SENTINEL: Is the terminal pattern indicating that output has finished.
1237 # LIST: is the sequence of outputs to match.
1238 # If the sentinel is recognized early, it is considered an error.
1241 # 1 if the test failed,
1242 # 0 if the test passes,
1243 # -1 if there was an internal error.
1245 proc gdb_expect_list {test sentinel list} {
1247 global suppress_flag
1250 if { $suppress_flag } {
1253 while { ${index} < [llength ${list}] } {
1254 set pattern [lindex ${list} ${index}]
1255 set index [expr ${index} + 1]
1256 if { ${index} == [llength ${list}] } {
1259 -re "${pattern}${sentinel}" {
1260 pass "${test}, pattern ${index} + sentinel"
1263 fail "${test}, pattern ${index} + sentinel"
1267 fail "${test}, pattern ${index} + sentinel (timeout)"
1272 unresolved "${test}, pattern ${index} + sentinel"
1278 pass "${test}, pattern ${index}"
1281 fail "${test}, pattern ${index}"
1285 fail "${test}, pattern ${index} (timeout)"
1290 unresolved "${test}, pattern ${index}"
1303 proc gdb_suppress_entire_file { reason } {
1304 global suppress_flag;
1306 warning "$reason\n";
1307 set suppress_flag -1;
1311 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
1312 # gdb_expect to fail immediately (until the next call to
1313 # gdb_stop_suppressing_tests).
1315 proc gdb_suppress_tests { args } {
1316 global suppress_flag;
1318 return; # fnf - disable pending review of results where
1319 # testsuite ran better without this
1322 if { $suppress_flag == 1 } {
1323 if { [llength $args] > 0 } {
1324 warning "[lindex $args 0]\n";
1326 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
1332 # Clear suppress_flag.
1334 proc gdb_stop_suppressing_tests { } {
1335 global suppress_flag;
1337 if [info exists suppress_flag] {
1338 if { $suppress_flag > 0 } {
1339 set suppress_flag 0;
1340 clone_output "Tests restarted.\n";
1343 set suppress_flag 0;
1347 proc gdb_clear_suppressed { } {
1348 global suppress_flag;
1350 set suppress_flag 0;
1353 proc gdb_start { } {
1358 catch default_gdb_exit
1362 # gdb_load -- load a file into the debugger.
1363 # return a -1 if anything goes wrong.
1365 proc gdb_load { arg } {
1366 return [gdb_file_cmd $arg]
1369 proc gdb_continue { function } {
1372 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
1375 proc default_gdb_init { args } {
1376 gdb_clear_suppressed;
1378 # Uh, this is lame. Really, really, really lame. But there's this *one*
1379 # testcase that will fail in random places if we don't increase this.
1382 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
1383 if { [llength $args] > 0 } {
1386 set file [lindex $args 0];
1388 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
1391 if [target_info exists gdb_prompt] {
1392 set gdb_prompt [target_info gdb_prompt];
1394 set gdb_prompt "\\(gdb\\)"
1398 proc gdb_init { args } {
1399 return [eval default_gdb_init $args];
1402 proc gdb_finish { } {
1407 set debug_format "unknown"
1409 # Run the gdb command "info source" and extract the debugging format
1410 # information from the output and save it in debug_format.
1412 proc get_debug_format { } {
1418 set debug_format "unknown"
1419 send_gdb "info source\n"
1421 -re "Compiled with (.*) debugging format.\r\n$gdb_prompt $" {
1422 set debug_format $expect_out(1,string)
1423 verbose "debug format is $debug_format"
1426 -re "No current source file.\r\n$gdb_prompt $" {
1427 perror "get_debug_format used when no current source file"
1430 -re "$gdb_prompt $" {
1431 warning "couldn't check debug format (no valid response)."
1435 warning "couldn't check debug format (timed out)."
1441 # Return true if FORMAT matches the debug format the current test was
1442 # compiled with. FORMAT is a shell-style globbing pattern; it can use
1443 # `*', `[...]', and so on.
1445 # This function depends on variables set by `get_debug_format', above.
1447 proc test_debug_format {format} {
1450 return [expr [string match $format $debug_format] != 0]
1453 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
1454 # COFF, stabs, etc). If that format matches the format that the
1455 # current test was compiled with, then the next test is expected to
1456 # fail for any target. Returns 1 if the next test or set of tests is
1457 # expected to fail, 0 otherwise (or if it is unknown). Must have
1458 # previously called get_debug_format.
1459 proc setup_xfail_format { format } {
1460 set ret [test_debug_format $format];
1468 proc gdb_step_for_stub { } {
1471 if ![target_info exists gdb,use_breakpoint_for_stub] {
1472 if [target_info exists gdb_stub_step_command] {
1473 set command [target_info gdb_stub_step_command];
1477 send_gdb "${command}\n";
1480 -re "(main.* at |.*in .*start).*$gdb_prompt" {
1483 -re ".*$gdb_prompt" {
1485 if { $tries == 5 } {
1486 fail "stepping out of breakpoint function";
1489 send_gdb "${command}\n";
1493 fail "stepping out of breakpoint function";
1500 -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" {
1501 set file $expect_out(1,string);
1502 set linenum [expr $expect_out(2,string) + 1];
1503 set breakplace "${file}:${linenum}";
1507 send_gdb "break ${breakplace}\n";
1509 -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" {
1510 set breakpoint $expect_out(1,string);
1512 -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" {
1513 set breakpoint $expect_out(1,string);
1517 send_gdb "continue\n";
1519 -re "Breakpoint ${breakpoint},.*$gdb_prompt" {
1520 gdb_test "delete $breakpoint" ".*" "";
1527 ### gdb_get_line_number TEXT [FILE]
1529 ### Search the source file FILE, and return the line number of a line
1530 ### containing TEXT. Use this function instead of hard-coding line
1531 ### numbers into your test script.
1533 ### Specifically, this function uses GDB's "search" command to search
1534 ### FILE for the first line containing TEXT, and returns its line
1535 ### number. Thus, FILE must be a source file, compiled into the
1536 ### executable you are running. If omitted, FILE defaults to the
1537 ### value of the global variable `srcfile'; most test scripts set
1538 ### `srcfile' appropriately at the top anyway.
1540 ### Use this function to keep your test scripts independent of the
1541 ### exact line numbering of the source file. Don't write:
1543 ### send_gdb "break 20"
1545 ### This means that if anyone ever edits your test's source file,
1546 ### your test could break. Instead, put a comment like this on the
1547 ### source file line you want to break at:
1549 ### /* breakpoint spot: frotz.exp: test name */
1551 ### and then write, in your test script (which we assume is named
1554 ### send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
1556 ### (Yes, Tcl knows how to handle the nested quotes and brackets.
1559 ### % puts "foo [lindex "bar baz" 1]"
1562 ### Tcl is quite clever, for a little stringy language.)
1564 proc gdb_get_line_number {text {file /omitted/}} {
1568 if {! [string compare $file /omitted/]} {
1573 gdb_test "list ${file}:1,1" ".*" ""
1574 send_gdb "search ${text}\n"
1576 -re "\[\r\n\]+(\[0-9\]+)\[ \t\].*${text}.*$gdb_prompt $" {
1577 set result $expect_out(1,string)
1579 -re ".*$gdb_prompt $" {
1580 fail "find line number containing \"${text}\""
1583 fail "find line number containing \"${text}\" (timeout)"
1589 # gdb_continue_to_end:
1590 # The case where the target uses stubs has to be handled specially. If a
1591 # stub is used, we set a breakpoint at exit because we cannot rely on
1592 # exit() behavior of a remote target.
1594 # mssg is the error message that gets printed.
1596 proc gdb_continue_to_end {mssg} {
1597 if [target_info exists use_gdb_stub] {
1598 if {![gdb_breakpoint "exit"]} {
1601 gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \
1602 "continue until exit at $mssg"
1604 # Continue until we exit. Should not stop again.
1605 # Don't bother to check the output of the program, that may be
1606 # extremely tough for some remote systems.
1607 gdb_test "continue"\
1608 "Continuing.\[\r\n0-9\]+Program exited normally\\..*"\
1609 "continue until exit at $mssg"
1613 proc rerun_to_main {} {
1616 if [target_info exists use_gdb_stub] {
1619 -re ".*Breakpoint .*main .*$gdb_prompt $"\
1620 {pass "rerun to main" ; return 0}
1621 -re "$gdb_prompt $"\
1622 {fail "rerun to main" ; return 0}
1623 timeout {fail "(timeout) rerun to main" ; return 0}
1628 -re "Starting program.*$gdb_prompt $"\
1629 {pass "rerun to main" ; return 0}
1630 -re "$gdb_prompt $"\
1631 {fail "rerun to main" ; return 0}
1632 timeout {fail "(timeout) rerun to main" ; return 0}
1637 # Print a message and return true if a test should be skipped
1638 # due to lack of floating point suport.
1640 proc gdb_skip_float_test { msg } {
1641 if [target_info exists gdb,skip_float_tests] {
1642 verbose "Skipping test '$msg': no float tests.";
1648 # Print a message and return true if a test should be skipped
1649 # due to lack of stdio support.
1651 proc gdb_skip_stdio_test { msg } {
1652 if [target_info exists gdb,noinferiorio] {
1653 verbose "Skipping test '$msg': no inferior i/o.";
1659 proc gdb_skip_bogus_test { msg } {