1 # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3 # Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 # Please email any bugs, comments, and/or additions to this file to:
20 # bug-gdb@prep.ai.mit.edu
22 # This file was written by Fred Fish. (fnf@cygnus.com)
24 # Generic gdb subroutines that should work for any target. If these
25 # need to be modified for any target, it can be done with a variable
26 # or by passing arguments.
32 if [info exists TOOL_EXECUTABLE] {
33 set GDB $TOOL_EXECUTABLE;
35 if ![info exists GDB] {
36 if ![is_remote host] {
37 set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]]
39 set GDB [transform gdb];
42 verbose "using GDB = $GDB" 2
45 if ![info exists GDBFLAGS] {
48 verbose "using GDBFLAGS = $GDBFLAGS" 2
50 # The variable gdb_prompt is a regexp which matches the gdb prompt.
51 # Set it if it is not already set.
53 if ![info exists gdb_prompt] then {
54 set gdb_prompt "\[(\]gdb\[)\]"
57 # Needed for some tests under Cygwin.
61 if ![info exists env(EXEEXT)] {
64 set EXEEXT $env(EXEEXT)
67 # Make sure we are using the C locale.
70 ### Only procedures should come after this point.
73 # gdb_version -- extract and print the version number of GDB
75 proc default_gdb_version {} {
79 set fileid [open "gdb_cmd" w];
82 set cmdfile [remote_download host "gdb_cmd"];
83 set output [remote_exec host "$GDB -nw --command $cmdfile"]
84 remote_file build delete "gdb_cmd";
85 remote_file host delete "$cmdfile";
86 set tmp [lindex $output 1];
88 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
89 if ![is_remote host] {
90 clone_output "[which $GDB] version $version $GDBFLAGS\n"
92 clone_output "$GDB on remote host version $version $GDBFLAGS\n"
96 proc gdb_version { } {
97 return [default_gdb_version];
101 # gdb_unload -- unload a file if one is loaded
110 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
111 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
112 -re "A program is being debugged already..*Kill it.*y or n. $"\
114 verbose "\t\tKilling previous program being debugged"
117 -re "Discard symbol table from .*y or n.*$" {
121 -re "$gdb_prompt $" {}
123 perror "couldn't unload file in $GDB (timed out)."
129 # Many of the tests depend on setting breakpoints at various places and
130 # running until that breakpoint is reached. At times, we want to start
131 # with a clean-slate with respect to breakpoints, so this utility proc
132 # lets us do this without duplicating this code everywhere.
135 proc delete_breakpoints {} {
138 # we need a larger timeout value here or this thing just confuses
139 # itself. May need a better implementation if possible. - guo
141 send_gdb "delete breakpoints\n"
143 -re "Delete all breakpoints.*y or n.*$" {
147 -re "$gdb_prompt $" { # This happens if there were no breakpoints
149 timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
151 send_gdb "info breakpoints\n"
153 -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
154 -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
155 -re "Delete all breakpoints.*or n.*$" {
159 timeout { perror "info breakpoints (timeout)" ; return }
165 # Generic run command.
167 # The second pattern below matches up to the first newline *only*.
168 # Using ``.*$'' could swallow up output that we attempt to match
171 proc gdb_run_cmd {args} {
174 if [target_info exists gdb_init_command] {
175 send_gdb "[target_info gdb_init_command]\n";
177 -re "$gdb_prompt $" { }
179 perror "gdb_init_command for target failed";
185 if [target_info exists use_gdb_stub] {
186 if [target_info exists gdb,do_reload_on_run] {
187 # Specifying no file, defaults to the executable
188 # currently being debugged.
189 if { [gdb_load ""] < 0 } {
192 send_gdb "continue\n";
194 -re "Continu\[^\r\n\]*\[\r\n\]" {}
200 if [target_info exists gdb,start_symbol] {
201 set start [target_info gdb,start_symbol];
205 send_gdb "jump *$start\n"
207 while { $start_attempt } {
208 # Cap (re)start attempts at three to ensure that this loop
209 # always eventually fails. Don't worry about trying to be
210 # clever and not send a command when it has failed.
211 if [expr $start_attempt > 3] {
212 perror "Jump to start() failed (retry count exceeded)";
215 set start_attempt [expr $start_attempt + 1];
217 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
220 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
221 perror "Can't find start symbol to run in gdb_run";
224 -re "No symbol \"start\" in current.*$gdb_prompt $" {
225 send_gdb "jump *_start\n";
227 -re "No symbol.*context.*$gdb_prompt $" {
230 -re "Line.* Jump anyway.*y or n. $" {
233 -re "The program is not being run.*$gdb_prompt $" {
234 if { [gdb_load ""] < 0 } {
237 send_gdb "jump *$start\n";
240 perror "Jump to start() failed (timeout)";
245 if [target_info exists gdb_stub] {
247 -re "$gdb_prompt $" {
248 send_gdb "continue\n"
254 send_gdb "run $args\n"
255 # This doesn't work quite right yet.
257 -re "The program .* has been started already.*y or n. $" {
261 -re "Starting program: \[^\r\n\]*" {}
265 proc gdb_breakpoint { function } {
269 send_gdb "break $function\n"
270 # The first two regexps are what we get with -g, the third is without -g.
272 -re "Breakpoint \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
273 -re "Breakpoint \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
274 -re "Breakpoint \[0-9\]* at .*$gdb_prompt $" {}
275 -re "$gdb_prompt $" { fail "setting breakpoint at $function" ; return 0 }
276 timeout { fail "setting breakpoint at $function (timeout)" ; return 0 }
281 # Set breakpoint at function and run gdb until it breaks there.
282 # Since this is the only breakpoint that will be set, if it stops
283 # at a breakpoint, we will assume it is the one we want. We can't
284 # just compare to "function" because it might be a fully qualified,
285 # single quoted C++ function specifier.
287 proc runto { function } {
293 if ![gdb_breakpoint $function] {
299 # the "at foo.c:36" output we get with -g.
300 # the "in func" output we get without -g.
302 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
305 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
308 -re "$gdb_prompt $" {
309 fail "running to $function in runto"
313 fail "running to $function in runto (timeout)"
321 # runto_main -- ask gdb to run until we hit a breakpoint at main.
322 # The case where the target uses stubs has to be handled
323 # specially--if it uses stubs, assuming we hit
324 # breakpoint() and just step out of the function.
326 proc runto_main { } {
330 if ![target_info exists gdb_stub] {
342 ### Continue, and expect to hit a breakpoint.
343 ### Report a pass or fail, depending on whether it seems to have
344 ### worked. Use NAME as part of the test name; each call to
345 ### continue_to_breakpoint should use a NAME which is unique within
347 proc gdb_continue_to_breakpoint {name} {
349 set full_name "continue to breakpoint: $name"
351 send_gdb "continue\n"
353 -re "Breakpoint .* at .*\r\n$gdb_prompt $" {
356 -re ".*$gdb_prompt $" {
360 fail "$full_name (timeout)"
367 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
368 # Send a command to gdb; test the result.
370 # COMMAND is the command to execute, send to GDB with send_gdb. If
371 # this is the null string no command is sent.
372 # PATTERN is the pattern to match for a PASS, and must NOT include
373 # the \r\n sequence immediately before the gdb prompt.
374 # MESSAGE is an optional message to be printed. If this is
375 # omitted, then the pass/fail messages use the command string as the
376 # message. (If this is the empty string, then sometimes we don't
377 # call pass or fail at all; I don't understand this at all.)
378 # QUESTION is a question GDB may ask in response to COMMAND, like
380 # RESPONSE is the response to send if QUESTION appears.
383 # 1 if the test failed,
384 # 0 if the test passes,
385 # -1 if there was an internal error.
387 proc gdb_test { args } {
391 upvar timeout timeout
393 if [llength $args]>2 then {
394 set message [lindex $args 2]
396 set message [lindex $args 0]
398 set command [lindex $args 0]
399 set pattern [lindex $args 1]
401 if [llength $args]==5 {
402 set question_string [lindex $args 3];
403 set response_string [lindex $args 4];
405 set question_string "^FOOBAR$"
409 send_user "Sending \"$command\" to gdb\n"
410 send_user "Looking to match \"$pattern\"\n"
411 send_user "Message is \"$message\"\n"
415 set string "${command}\n";
416 if { $command != "" } {
417 while { "$string" != "" } {
418 set foo [string first "\n" "$string"];
419 set len [string length "$string"];
420 if { $foo < [expr $len - 1] } {
421 set str [string range "$string" 0 $foo];
422 if { [send_gdb "$str"] != "" } {
423 global suppress_flag;
425 if { ! $suppress_flag } {
426 perror "Couldn't send $command to GDB.";
431 # since we're checking if each line of the multi-line
432 # command are 'accepted' by GDB here,
433 # we need to set -notransfer expect option so that
434 # command output is not lost for pattern matching
437 -notransfer -re "\[\r\n\]" { verbose "partial: match" 3 }
438 timeout { verbose "partial: timeout" 3 }
440 set string [string range "$string" [expr $foo + 1] end];
445 if { "$string" != "" } {
446 if { [send_gdb "$string"] != "" } {
447 global suppress_flag;
449 if { ! $suppress_flag } {
450 perror "Couldn't send $command to GDB.";
458 if [target_info exists gdb,timeout] {
459 set tmt [target_info gdb,timeout];
461 if [info exists timeout] {
465 if [info exists timeout] {
473 -re "\\*\\*\\* DOSEXIT code.*" {
474 if { $message != "" } {
477 gdb_suppress_entire_file "GDB died";
480 -re "Ending remote debugging.*$gdb_prompt $" {
481 if ![isnative] then {
482 warning "Can`t communicate to remote target."
488 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
489 if ![string match "" $message] then {
494 -re "(${question_string})$" {
495 send_gdb "$response_string\n";
498 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
499 perror "Undefined command \"$command\"."
503 -re "Ambiguous command.*$gdb_prompt $" {
504 perror "\"$command\" is not a unique command name."
508 -re "Program exited with code \[0-9\]+.*$gdb_prompt $" {
509 if ![string match "" $message] then {
510 set errmsg "$message: the program exited"
512 set errmsg "$command: the program exited"
517 -re "EXIT code \[0-9\r\n\]+Program exited normally.*$gdb_prompt $" {
518 if ![string match "" $message] then {
519 set errmsg "$message: the program exited"
521 set errmsg "$command: the program exited"
526 -re "The program is not being run.*$gdb_prompt $" {
527 if ![string match "" $message] then {
528 set errmsg "$message: the program is no longer running"
530 set errmsg "$command: the program is no longer running"
535 -re ".*$gdb_prompt $" {
536 if ![string match "" $message] then {
543 perror "Window too small."
546 -re "\\(y or n\\) " {
548 perror "Got interactive prompt."
552 perror "Process no longer exists"
553 if { $message != "" } {
559 perror "internal buffer is full."
563 if ![string match "" $message] then {
564 fail "$message (timeout)"
572 # Test that a command gives an error. For pass or fail, return
573 # a 1 to indicate that more tests can proceed. However a timeout
574 # is a serious error, generates a special fail message, and causes
575 # a 0 to be returned to indicate that more tests are likely to fail
578 proc test_print_reject { args } {
582 if [llength $args]==2 then {
583 set expectthis [lindex $args 1]
585 set expectthis "should never match this bogus string"
587 set sendthis [lindex $args 0]
589 send_user "Sending \"$sendthis\" to gdb\n"
590 send_user "Looking to match \"$expectthis\"\n"
592 send_gdb "$sendthis\n"
593 #FIXME: Should add timeout as parameter.
595 -re "A .* in expression.*\\.*$gdb_prompt $" {
596 pass "reject $sendthis"
599 -re "Invalid syntax in expression.*$gdb_prompt $" {
600 pass "reject $sendthis"
603 -re "Junk after end of expression.*$gdb_prompt $" {
604 pass "reject $sendthis"
607 -re "Invalid number.*$gdb_prompt $" {
608 pass "reject $sendthis"
611 -re "Invalid character constant.*$gdb_prompt $" {
612 pass "reject $sendthis"
615 -re "No symbol table is loaded.*$gdb_prompt $" {
616 pass "reject $sendthis"
619 -re "No symbol .* in current context.*$gdb_prompt $" {
620 pass "reject $sendthis"
623 -re "Unmatched single quote.*$gdb_prompt $" {
624 pass "reject $sendthis"
627 -re "A character constant must contain at least one character.*$gdb_prompt $" {
628 pass "reject $sendthis"
631 -re "$expectthis.*$gdb_prompt $" {
632 pass "reject $sendthis"
635 -re ".*$gdb_prompt $" {
636 fail "reject $sendthis"
640 fail "reject $sendthis (eof or timeout)"
646 # Given an input string, adds backslashes as needed to create a
647 # regexp that will match the string.
649 proc string_to_regexp {str} {
651 regsub -all {[]*+.|()^$\[]} $str {\\&} result
655 # Same as gdb_test, but the second parameter is not a regexp,
656 # but a string that must match exactly.
658 proc gdb_test_exact { args } {
659 upvar timeout timeout
661 set command [lindex $args 0]
663 # This applies a special meaning to a null string pattern. Without
664 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
665 # messages from commands that should have no output except a new
666 # prompt. With this, only results of a null string will match a null
669 set pattern [lindex $args 1]
670 if [string match $pattern ""] {
671 set pattern [string_to_regexp [lindex $args 0]]
673 set pattern [string_to_regexp [lindex $args 1]]
676 # It is most natural to write the pattern argument with only
677 # embedded \n's, especially if you are trying to avoid Tcl quoting
678 # problems. But gdb_expect really wants to see \r\n in patterns. So
679 # transform the pattern here. First transform \r\n back to \n, in
680 # case some users of gdb_test_exact already do the right thing.
681 regsub -all "\r\n" $pattern "\n" pattern
682 regsub -all "\n" $pattern "\r\n" pattern
683 if [llength $args]==3 then {
684 set message [lindex $args 2]
689 return [gdb_test $command $pattern $message]
692 proc gdb_reinitialize_dir { subdir } {
695 if [is_remote host] {
700 -re "Reinitialize source path to empty.*y or n. " {
703 -re "Source directories searched.*$gdb_prompt $" {
704 send_gdb "dir $subdir\n"
706 -re "Source directories searched.*$gdb_prompt $" {
707 verbose "Dir set to $subdir"
709 -re "$gdb_prompt $" {
710 perror "Dir \"$subdir\" failed."
714 -re "$gdb_prompt $" {
715 perror "Dir \"$subdir\" failed."
719 -re "$gdb_prompt $" {
720 perror "Dir \"$subdir\" failed."
726 # gdb_exit -- exit the GDB, killing the target program if necessary
728 proc default_gdb_exit {} {
734 gdb_stop_suppressing_tests;
736 if ![info exists gdb_spawn_id] {
740 verbose "Quitting $GDB $GDBFLAGS"
742 if { [is_remote host] && [board_info host exists fileid] } {
749 -re "DOSEXIT code" { }
754 if ![is_remote host] {
761 # load a file into the debugger.
762 # return a -1 if anything goes wrong.
764 proc gdb_file_cmd { arg } {
770 upvar timeout timeout
772 if [is_remote host] {
773 set arg [remote_download host $arg];
775 error "download failed"
780 send_gdb "file $arg\n"
782 -re "Reading symbols from.*done.*$gdb_prompt $" {
783 verbose "\t\tLoaded $arg into the $GDB"
786 -re "has no symbol-table.*$gdb_prompt $" {
787 perror "$arg wasn't compiled with \"-g\""
790 -re "A program is being debugged already.*Kill it.*y or n. $" {
792 verbose "\t\tKilling previous program being debugged"
795 -re "Load new symbol table from \".*\".*y or n. $" {
798 -re "Reading symbols from.*done.*$gdb_prompt $" {
799 verbose "\t\tLoaded $arg with new symbol table into $GDB"
803 perror "(timeout) Couldn't load $arg, other program already loaded."
808 -re "No such file or directory.*$gdb_prompt $" {
809 perror "($arg) No such file or directory\n"
812 -re "$gdb_prompt $" {
813 perror "couldn't load $arg into $GDB."
817 perror "couldn't load $arg into $GDB (timed out)."
821 # This is an attempt to detect a core dump, but seems not to
822 # work. Perhaps we need to match .* followed by eof, in which
823 # gdb_expect does not seem to have a way to do that.
824 perror "couldn't load $arg into $GDB (end of file)."
831 # start gdb -- start gdb running, default procedure
833 # When running over NFS, particularly if running many simultaneous
834 # tests on different hosts all using the same server, things can
835 # get really slow. Give gdb at least 3 minutes to start up.
837 proc default_gdb_start { } {
845 gdb_stop_suppressing_tests;
847 verbose "Spawning $GDB -nw $GDBFLAGS"
849 if [info exists gdb_spawn_id] {
853 if ![is_remote host] {
854 if { [which $GDB] == 0 } then {
855 perror "$GDB does not exist."
859 set res [remote_spawn host "$GDB -nw $GDBFLAGS [host_info gdb_opts]"];
860 if { $res < 0 || $res == "" } {
861 perror "Spawning $GDB failed."
865 -re "\[\r\n\]$gdb_prompt $" {
866 verbose "GDB initialized."
868 -re "$gdb_prompt $" {
869 perror "GDB never initialized."
873 perror "(timeout) GDB never initialized after 10 seconds."
879 # force the height to "unlimited", so no pagers get used
881 send_gdb "set height 0\n"
883 -re "$gdb_prompt $" {
884 verbose "Setting height to 0." 2
887 warning "Couldn't set the height to 0"
890 # force the width to "unlimited", so no wraparound occurs
891 send_gdb "set width 0\n"
893 -re "$gdb_prompt $" {
894 verbose "Setting width to 0." 2
897 warning "Couldn't set the width to 0."
903 # Return a 1 for configurations for which we don't even want to try to
906 proc skip_cplus_tests {} {
907 if { [istarget "d10v-*-*"] } {
910 if { [istarget "h8300-*-*"] } {
916 # Skip all the tests in the file if you are not on an hppa running
919 proc skip_hp_tests {} {
920 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
921 verbose "Skip hp tests is $skip_hp"
925 proc get_compiler_info {binfile args} {
926 # Create and source the file that provides information about the compiler
927 # used to compile the test case.
928 # Compiler_type can be null or c++. If null we assume c.
931 # These two come from compiler.c.
932 global signed_keyword_not_used
935 if {![istarget "hppa*-*-hpux*"] && ![istarget "mips*-*-irix*"]} {
936 if { [llength $args] > 0 } {
937 if {$args == "c++"} {
938 if { [gdb_compile "${srcdir}/lib/compiler.cc" "${binfile}.ci" preprocess {}] != "" } {
939 perror "Couldn't make ${binfile}.ci file"
944 if { [gdb_compile "${srcdir}/lib/compiler.c" "${binfile}.ci" preprocess {}] != "" } {
945 perror "Couldn't make ${binfile}.ci file"
950 if { [llength $args] > 0 } {
951 if {$args == "c++"} {
952 if { [eval gdb_preprocess \
953 [list "${srcdir}/lib/compiler.cc" "${binfile}.ci"] \
955 perror "Couldn't make ${binfile}.ci file"
959 } elseif { $args != "f77" } {
960 if { [eval gdb_preprocess \
961 [list "${srcdir}/lib/compiler.c" "${binfile}.ci"] \
963 perror "Couldn't make ${binfile}.ci file"
969 uplevel \#0 { set gcc_compiled 0 }
971 if { [llength $args] == 0 || $args != "f77" } {
975 # Most compilers will evaluate comparisons and other boolean
976 # operations to 0 or 1.
977 uplevel \#0 { set true 1 }
978 uplevel \#0 { set false 0 }
980 uplevel \#0 { set hp_cc_compiler 0 }
981 uplevel \#0 { set hp_aCC_compiler 0 }
982 uplevel \#0 { set hp_f77_compiler 0 }
983 uplevel \#0 { set hp_f90_compiler 0 }
984 if { !$gcc_compiled && [istarget "hppa*-*-hpux*"] } {
985 # Check for the HP compilers
986 set compiler [lindex [split [get_compiler $args] " "] 0]
987 catch "exec what $compiler" output
988 if [regexp ".*HP aC\\+\\+.*" $output] {
989 uplevel \#0 { set hp_aCC_compiler 1 }
990 # Use of aCC results in boolean results being displayed as
992 uplevel \#0 { set true true }
993 uplevel \#0 { set false false }
994 } elseif [regexp ".*HP C Compiler.*" $output] {
995 uplevel \#0 { set hp_cc_compiler 1 }
996 } elseif [regexp ".*HP-UX f77.*" $output] {
997 uplevel \#0 { set hp_f77_compiler 1 }
998 } elseif [regexp ".*HP-UX f90.*" $output] {
999 uplevel \#0 { set hp_f90_compiler 1 }
1006 proc get_compiler {args} {
1007 global CC CC_FOR_TARGET CXX CXX_FOR_TARGET F77_FOR_TARGET
1009 if { [llength $args] == 0
1010 || ([llength $args] == 1 && [lindex $args 0] == "") } {
1011 set which_compiler "c"
1013 if { $args =="c++" } {
1014 set which_compiler "c++"
1015 } elseif { $args =="f77" } {
1016 set which_compiler "f77"
1018 perror "Unknown compiler type supplied to gdb_preprocess"
1023 if [info exists CC_FOR_TARGET] {
1024 if {$which_compiler == "c"} {
1025 set compiler $CC_FOR_TARGET
1029 if [info exists CXX_FOR_TARGET] {
1030 if {$which_compiler == "c++"} {
1031 set compiler $CXX_FOR_TARGET
1035 if [info exists F77_FOR_TARGET] {
1036 if {$which_compiler == "f77"} {
1037 set compiler $F77_FOR_TARGET
1041 if { ![info exists compiler] } {
1042 if { $which_compiler == "c" } {
1043 if {[info exists CC]} {
1047 if { $which_compiler == "c++" } {
1048 if {[info exists CXX]} {
1052 if {![info exists compiler]} {
1053 set compiler [board_info [target_info name] compiler];
1054 if { $compiler == "" } {
1055 perror "get_compiler: No compiler found"
1064 proc gdb_preprocess {source dest args} {
1065 set compiler [get_compiler "$args"]
1066 if { $compiler == "" } {
1070 set cmdline "$compiler -E $source > $dest"
1072 verbose "Invoking $compiler -E $source > $dest"
1073 verbose -log "Executing on local host: $cmdline" 2
1074 set status [catch "exec ${cmdline}" exec_output]
1076 set result [prune_warnings $exec_output]
1077 regsub "\[\r\n\]*$" "$result" "" result;
1078 regsub "^\[\r\n\]*" "$result" "" result;
1079 if { $result != "" } {
1080 clone_output "gdb compile failed, $result"
1085 set gdb_wrapper_initialized 0
1087 proc gdb_wrapper_init { args } {
1088 global gdb_wrapper_initialized;
1089 global gdb_wrapper_file;
1090 global gdb_wrapper_flags;
1092 if { $gdb_wrapper_initialized == 1 } { return; }
1094 if {[target_info exists needs_status_wrapper] && \
1095 [target_info needs_status_wrapper] != "0"} {
1096 set result [build_wrapper "testglue.o"];
1097 if { $result != "" } {
1098 set gdb_wrapper_file [lindex $result 0];
1099 set gdb_wrapper_flags [lindex $result 1];
1101 warning "Status wrapper failed to build."
1104 set gdb_wrapper_initialized 1
1107 proc gdb_compile {source dest type options} {
1108 global GDB_TESTCASE_OPTIONS;
1109 global gdb_wrapper_file;
1110 global gdb_wrapper_flags;
1111 global gdb_wrapper_initialized;
1113 if [target_info exists gdb_stub] {
1114 set options2 { "additional_flags=-Dusestubs" }
1115 lappend options "libs=[target_info gdb_stub]";
1116 set options [concat $options2 $options]
1118 if [target_info exists is_vxworks] {
1119 set options2 { "additional_flags=-Dvxworks" }
1120 lappend options "libs=[target_info gdb_stub]";
1121 set options [concat $options2 $options]
1123 if [info exists GDB_TESTCASE_OPTIONS] {
1124 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
1126 verbose "options are $options"
1127 verbose "source is $source $dest $type $options"
1129 if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init }
1131 if {[target_info exists needs_status_wrapper] && \
1132 [target_info needs_status_wrapper] != "0" && \
1133 [info exists gdb_wrapper_file]} {
1134 lappend options "libs=${gdb_wrapper_file}"
1135 lappend options "ldflags=${gdb_wrapper_flags}"
1138 set result [target_compile $source $dest $type $options];
1139 regsub "\[\r\n\]*$" "$result" "" result;
1140 regsub "^\[\r\n\]*" "$result" "" result;
1141 if { $result != "" && [lsearch $options quiet] == -1} {
1142 clone_output "gdb compile failed, $result"
1148 # This is just like gdb_compile, above, except that it tries compiling
1149 # against several different thread libraries, to see which one this
1151 proc gdb_compile_pthreads {source dest type options} {
1153 set why_msg "unrecognized error"
1154 foreach lib {-lpthreads -lpthread -lthread} {
1155 # This kind of wipes out whatever libs the caller may have
1156 # set. Or maybe theirs will override ours. How infelicitous.
1157 set options_with_lib [concat $options [list libs=$lib quiet]]
1158 set ccout [gdb_compile $source $dest $type $options_with_lib]
1159 switch -regexp -- $ccout {
1160 ".*no posix threads support.*" {
1161 set why_msg "missing threads include file"
1164 ".*cannot open -lpthread.*" {
1165 set why_msg "missing runtime threads library"
1167 ".*Can't find library for -lpthread.*" {
1168 set why_msg "missing runtime threads library"
1171 pass "successfully compiled posix threads test case"
1177 if {!$built_binfile} {
1178 unsupported "Couldn't compile $source: ${why_msg}"
1183 proc send_gdb { string } {
1184 global suppress_flag;
1185 if { $suppress_flag } {
1186 return "suppressed";
1188 return [remote_send host "$string"];
1194 proc gdb_expect { args } {
1195 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
1196 set gtimeout [lindex $args 0];
1197 set expcode [list [lindex $args 1]];
1199 upvar timeout timeout;
1202 if [target_info exists gdb,timeout] {
1203 if [info exists timeout] {
1204 if { $timeout < [target_info gdb,timeout] } {
1205 set gtimeout [target_info gdb,timeout];
1207 set gtimeout $timeout;
1210 set gtimeout [target_info gdb,timeout];
1214 if ![info exists gtimeout] {
1216 if [info exists timeout] {
1217 set gtimeout $timeout;
1224 global suppress_flag;
1225 global remote_suppress_flag;
1226 if [info exists remote_suppress_flag] {
1227 set old_val $remote_suppress_flag;
1229 if [info exists suppress_flag] {
1230 if { $suppress_flag } {
1231 set remote_suppress_flag 1;
1235 {uplevel remote_expect host $gtimeout $expcode} string];
1236 if [info exists old_val] {
1237 set remote_suppress_flag $old_val;
1239 if [info exists remote_suppress_flag] {
1240 unset remote_suppress_flag;
1245 global errorInfo errorCode;
1247 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
1248 } elseif {$code == 2} {
1249 return -code return $string
1250 } elseif {$code == 3} {
1252 } elseif {$code > 4} {
1253 return -code $code $string
1257 # gdb_expect_list MESSAGE SENTINEL LIST -- expect a sequence of outputs
1259 # Check for long sequence of output by parts.
1260 # MESSAGE: is the test message to be printed with the test success/fail.
1261 # SENTINEL: Is the terminal pattern indicating that output has finished.
1262 # LIST: is the sequence of outputs to match.
1263 # If the sentinel is recognized early, it is considered an error.
1266 # 1 if the test failed,
1267 # 0 if the test passes,
1268 # -1 if there was an internal error.
1270 proc gdb_expect_list {test sentinel list} {
1272 global suppress_flag
1275 if { $suppress_flag } {
1277 unresolved "${test}"
1279 while { ${index} < [llength ${list}] } {
1280 set pattern [lindex ${list} ${index}]
1281 set index [expr ${index} + 1]
1282 if { ${index} == [llength ${list}] } {
1285 -re "${pattern}${sentinel}" {
1286 # pass "${test}, pattern ${index} + sentinel"
1289 fail "${test} (pattern ${index} + sentinel)"
1293 fail "${test} (pattern ${index} + sentinel) (timeout)"
1298 # unresolved "${test}, pattern ${index} + sentinel"
1304 # pass "${test}, pattern ${index}"
1307 fail "${test} (pattern ${index})"
1311 fail "${test} (pattern ${index}) (timeout)"
1316 # unresolved "${test}, pattern ${index}"
1330 proc gdb_suppress_entire_file { reason } {
1331 global suppress_flag;
1333 warning "$reason\n";
1334 set suppress_flag -1;
1338 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
1339 # gdb_expect to fail immediately (until the next call to
1340 # gdb_stop_suppressing_tests).
1342 proc gdb_suppress_tests { args } {
1343 global suppress_flag;
1345 return; # fnf - disable pending review of results where
1346 # testsuite ran better without this
1349 if { $suppress_flag == 1 } {
1350 if { [llength $args] > 0 } {
1351 warning "[lindex $args 0]\n";
1353 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
1359 # Clear suppress_flag.
1361 proc gdb_stop_suppressing_tests { } {
1362 global suppress_flag;
1364 if [info exists suppress_flag] {
1365 if { $suppress_flag > 0 } {
1366 set suppress_flag 0;
1367 clone_output "Tests restarted.\n";
1370 set suppress_flag 0;
1374 proc gdb_clear_suppressed { } {
1375 global suppress_flag;
1377 set suppress_flag 0;
1380 proc gdb_start { } {
1385 catch default_gdb_exit
1389 # gdb_load -- load a file into the debugger.
1390 # return a -1 if anything goes wrong.
1392 proc gdb_load { arg } {
1393 return [gdb_file_cmd $arg]
1396 proc gdb_continue { function } {
1399 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
1402 proc default_gdb_init { args } {
1403 global gdb_wrapper_initialized
1405 gdb_clear_suppressed;
1407 # Make sure that the wrapper is rebuilt
1408 # with the appropriate multilib option.
1409 set gdb_wrapper_initialized 0
1411 # Uh, this is lame. Really, really, really lame. But there's this *one*
1412 # testcase that will fail in random places if we don't increase this.
1415 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
1416 if { [llength $args] > 0 } {
1419 set file [lindex $args 0];
1421 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
1424 if [target_info exists gdb_prompt] {
1425 set gdb_prompt [target_info gdb_prompt];
1427 set gdb_prompt "\\(gdb\\)"
1431 proc gdb_init { args } {
1432 return [eval default_gdb_init $args];
1435 proc gdb_finish { } {
1440 set debug_format "unknown"
1442 # Run the gdb command "info source" and extract the debugging format
1443 # information from the output and save it in debug_format.
1445 proc get_debug_format { } {
1451 set debug_format "unknown"
1452 send_gdb "info source\n"
1454 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
1455 set debug_format $expect_out(1,string)
1456 verbose "debug format is $debug_format"
1459 -re "No current source file.\r\n$gdb_prompt $" {
1460 perror "get_debug_format used when no current source file"
1463 -re "$gdb_prompt $" {
1464 warning "couldn't check debug format (no valid response)."
1468 warning "couldn't check debug format (timed out)."
1474 # Return true if FORMAT matches the debug format the current test was
1475 # compiled with. FORMAT is a shell-style globbing pattern; it can use
1476 # `*', `[...]', and so on.
1478 # This function depends on variables set by `get_debug_format', above.
1480 proc test_debug_format {format} {
1483 return [expr [string match $format $debug_format] != 0]
1486 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
1487 # COFF, stabs, etc). If that format matches the format that the
1488 # current test was compiled with, then the next test is expected to
1489 # fail for any target. Returns 1 if the next test or set of tests is
1490 # expected to fail, 0 otherwise (or if it is unknown). Must have
1491 # previously called get_debug_format.
1492 proc setup_xfail_format { format } {
1493 set ret [test_debug_format $format];
1501 proc gdb_step_for_stub { } {
1504 if ![target_info exists gdb,use_breakpoint_for_stub] {
1505 if [target_info exists gdb_stub_step_command] {
1506 set command [target_info gdb_stub_step_command];
1510 send_gdb "${command}\n";
1513 -re "(main.* at |.*in .*start).*$gdb_prompt" {
1516 -re ".*$gdb_prompt" {
1518 if { $tries == 5 } {
1519 fail "stepping out of breakpoint function";
1522 send_gdb "${command}\n";
1526 fail "stepping out of breakpoint function";
1533 -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" {
1534 set file $expect_out(1,string);
1535 set linenum [expr $expect_out(2,string) + 1];
1536 set breakplace "${file}:${linenum}";
1540 send_gdb "break ${breakplace}\n";
1542 -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" {
1543 set breakpoint $expect_out(1,string);
1545 -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" {
1546 set breakpoint $expect_out(1,string);
1550 send_gdb "continue\n";
1552 -re "Breakpoint ${breakpoint},.*$gdb_prompt" {
1553 gdb_test "delete $breakpoint" ".*" "";
1560 ### gdb_get_line_number TEXT [FILE]
1562 ### Search the source file FILE, and return the line number of a line
1563 ### containing TEXT. Use this function instead of hard-coding line
1564 ### numbers into your test script.
1566 ### Specifically, this function uses GDB's "search" command to search
1567 ### FILE for the first line containing TEXT, and returns its line
1568 ### number. Thus, FILE must be a source file, compiled into the
1569 ### executable you are running. If omitted, FILE defaults to the
1570 ### value of the global variable `srcfile'; most test scripts set
1571 ### `srcfile' appropriately at the top anyway.
1573 ### Use this function to keep your test scripts independent of the
1574 ### exact line numbering of the source file. Don't write:
1576 ### send_gdb "break 20"
1578 ### This means that if anyone ever edits your test's source file,
1579 ### your test could break. Instead, put a comment like this on the
1580 ### source file line you want to break at:
1582 ### /* breakpoint spot: frotz.exp: test name */
1584 ### and then write, in your test script (which we assume is named
1587 ### send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
1589 ### (Yes, Tcl knows how to handle the nested quotes and brackets.
1592 ### % puts "foo [lindex "bar baz" 1]"
1595 ### Tcl is quite clever, for a little stringy language.)
1597 proc gdb_get_line_number {text {file /omitted/}} {
1601 if {! [string compare $file /omitted/]} {
1606 gdb_test "list ${file}:1,1" ".*" ""
1607 send_gdb "search ${text}\n"
1609 -re "\[\r\n\]+(\[0-9\]+)\[ \t\].*${text}.*$gdb_prompt $" {
1610 set result $expect_out(1,string)
1612 -re ".*$gdb_prompt $" {
1613 fail "find line number containing \"${text}\""
1616 fail "find line number containing \"${text}\" (timeout)"
1622 # gdb_continue_to_end:
1623 # The case where the target uses stubs has to be handled specially. If a
1624 # stub is used, we set a breakpoint at exit because we cannot rely on
1625 # exit() behavior of a remote target.
1627 # mssg is the error message that gets printed.
1629 proc gdb_continue_to_end {mssg} {
1630 if [target_info exists use_gdb_stub] {
1631 if {![gdb_breakpoint "exit"]} {
1634 gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \
1635 "continue until exit at $mssg"
1637 # Continue until we exit. Should not stop again.
1638 # Don't bother to check the output of the program, that may be
1639 # extremely tough for some remote systems.
1640 gdb_test "continue"\
1641 "Continuing.\[\r\n0-9\]+(... EXIT code 0\[\r\n\]+|Program exited normally\\.).*"\
1642 "continue until exit at $mssg"
1646 proc rerun_to_main {} {
1649 if [target_info exists use_gdb_stub] {
1652 -re ".*Breakpoint .*main .*$gdb_prompt $"\
1653 {pass "rerun to main" ; return 0}
1654 -re "$gdb_prompt $"\
1655 {fail "rerun to main" ; return 0}
1656 timeout {fail "(timeout) rerun to main" ; return 0}
1661 -re "The program .* has been started already.*y or n. $" {
1665 -re "Starting program.*$gdb_prompt $"\
1666 {pass "rerun to main" ; return 0}
1667 -re "$gdb_prompt $"\
1668 {fail "rerun to main" ; return 0}
1669 timeout {fail "(timeout) rerun to main" ; return 0}
1674 # Print a message and return true if a test should be skipped
1675 # due to lack of floating point suport.
1677 proc gdb_skip_float_test { msg } {
1678 if [target_info exists gdb,skip_float_tests] {
1679 verbose "Skipping test '$msg': no float tests.";
1685 # Print a message and return true if a test should be skipped
1686 # due to lack of stdio support.
1688 proc gdb_skip_stdio_test { msg } {
1689 if [target_info exists gdb,noinferiorio] {
1690 verbose "Skipping test '$msg': no inferior i/o.";
1696 proc gdb_skip_bogus_test { msg } {