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 ### Only procedures should come after this point.
69 # gdb_version -- extract and print the version number of GDB
71 proc default_gdb_version {} {
75 set fileid [open "gdb_cmd" w];
78 set cmdfile [remote_download host "gdb_cmd"];
79 set output [remote_exec host "$GDB -nw --command $cmdfile"]
80 remote_file build delete "gdb_cmd";
81 remote_file host delete "$cmdfile";
82 set tmp [lindex $output 1];
84 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
85 if ![is_remote host] {
86 clone_output "[which $GDB] version $version $GDBFLAGS\n"
88 clone_output "$GDB on remote host version $version $GDBFLAGS\n"
92 proc gdb_version { } {
93 return [default_gdb_version];
97 # gdb_unload -- unload a file if one is loaded
106 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
107 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
108 -re "A program is being debugged already..*Kill it.*y or n. $"\
110 verbose "\t\tKilling previous program being debugged"
113 -re "Discard symbol table from .*y or n.*$" {
117 -re "$gdb_prompt $" {}
119 perror "couldn't unload file in $GDB (timed out)."
125 # Many of the tests depend on setting breakpoints at various places and
126 # running until that breakpoint is reached. At times, we want to start
127 # with a clean-slate with respect to breakpoints, so this utility proc
128 # lets us do this without duplicating this code everywhere.
131 proc delete_breakpoints {} {
134 send_gdb "delete breakpoints\n"
136 -re "Delete all breakpoints.*y or n.*$" {
140 -re "$gdb_prompt $" { # This happens if there were no breakpoints
142 timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
144 send_gdb "info breakpoints\n"
146 -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
147 -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
148 -re "Delete all breakpoints.*or n.*$" {
152 timeout { perror "info breakpoints (timeout)" ; return }
158 # Generic run command.
160 # The second pattern below matches up to the first newline *only*.
161 # Using ``.*$'' could swallow up output that we attempt to match
164 proc gdb_run_cmd {args} {
167 if [target_info exists gdb_init_command] {
168 send_gdb "[target_info gdb_init_command]\n";
170 -re "$gdb_prompt $" { }
172 perror "gdb_init_command for target failed";
178 if [target_info exists use_gdb_stub] {
179 if [target_info exists gdb,do_reload_on_run] {
180 # According to Stu, this will always work.
182 send_gdb "continue\n";
184 -re "Continu\[^\r\n\]*\[\r\n\]" {}
190 if [target_info exists gdb,start_symbol] {
191 set start [target_info gdb,start_symbol];
195 send_gdb "jump *$start\n"
197 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
198 if ![target_info exists gdb_stub] {
202 -re "No symbol \"start\" in current.*$gdb_prompt $" {
203 send_gdb "jump *_start\n";
206 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
207 perror "Can't find start symbol to run in gdb_run";
210 -re "Line.* Jump anyway.*y or n. $" {
214 -re "No symbol.*context.*$gdb_prompt $" {}
215 -re "The program is not being run.*$gdb_prompt $" {
217 send_gdb "jump *$start\n";
220 timeout { perror "Jump to start() failed (timeout)"; return }
222 if [target_info exists gdb_stub] {
224 -re "$gdb_prompt $" {
225 send_gdb "continue\n"
231 send_gdb "run $args\n"
232 # This doesn't work quite right yet.
234 -re "The program .* has been started already.*y or n. $" {
238 -re "Starting program: \[^\r\n\]*" {}
242 proc gdb_breakpoint { function } {
246 send_gdb "break $function\n"
247 # The first two regexps are what we get with -g, the third is without -g.
249 -re "Breakpoint \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
250 -re "Breakpoint \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
251 -re "Breakpoint \[0-9\]* at .*$gdb_prompt $" {}
252 -re "$gdb_prompt $" { fail "setting breakpoint at $function" ; return 0 }
253 timeout { fail "setting breakpoint at $function (timeout)" ; return 0 }
258 # Set breakpoint at function and run gdb until it breaks there.
259 # Since this is the only breakpoint that will be set, if it stops
260 # at a breakpoint, we will assume it is the one we want. We can't
261 # just compare to "function" because it might be a fully qualified,
262 # single quoted C++ function specifier.
264 proc runto { function } {
270 if ![gdb_breakpoint $function] {
276 # the "at foo.c:36" output we get with -g.
277 # the "in func" output we get without -g.
279 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
282 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
285 -re "$gdb_prompt $" {
286 fail "running to $function in runto"
290 fail "running to $function in runto (timeout)"
298 # runto_main -- ask gdb to run until we hit a breakpoint at main.
299 # The case where the target uses stubs has to be handled
300 # specially--if it uses stubs, assuming we hit
301 # breakpoint() and just step out of the function.
303 proc runto_main { } {
307 if ![target_info exists gdb_stub] {
319 # gdb_test COMMAND PATTERN MESSAGE -- send a command to gdb; test the result.
321 # COMMAND is the command to execute, send to GDB with send_gdb. If
322 # this is the null string no command is sent.
323 # PATTERN is the pattern to match for a PASS, and must NOT include
324 # the \r\n sequence immediately before the gdb prompt.
325 # MESSAGE is an optional message to be printed. If this is
326 # omitted, then the pass/fail messages use the command string as the
327 # message. (If this is the empty string, then sometimes we don't
328 # call pass or fail at all; I don't understand this at all.)
331 # 1 if the test failed,
332 # 0 if the test passes,
333 # -1 if there was an internal error.
335 proc gdb_test { args } {
339 upvar timeout timeout
341 if [llength $args]>2 then {
342 set message [lindex $args 2]
344 set message [lindex $args 0]
346 set command [lindex $args 0]
347 set pattern [lindex $args 1]
349 if [llength $args]==5 {
350 set question_string [lindex $args 3];
351 set response_string [lindex $args 4];
353 set question_string "^FOOBAR$"
357 send_user "Sending \"$command\" to gdb\n"
358 send_user "Looking to match \"$pattern\"\n"
359 send_user "Message is \"$message\"\n"
363 set string "${command}\n";
364 if { $command != "" } {
365 while { "$string" != "" } {
366 set foo [string first "\n" "$string"];
367 set len [string length "$string"];
368 if { $foo < [expr $len - 1] } {
369 set str [string range "$string" 0 $foo];
370 if { [send_gdb "$str"] != "" } {
371 global suppress_flag;
373 if { ! $suppress_flag } {
374 perror "Couldn't send $command to GDB.";
383 set string [string range "$string" [expr $foo + 1] end];
388 if { "$string" != "" } {
389 if { [send_gdb "$string"] != "" } {
390 global suppress_flag;
392 if { ! $suppress_flag } {
393 perror "Couldn't send $command to GDB.";
401 if [info exists timeout] {
405 if [info exists timeout] {
412 -re "\\*\\*\\* DOSEXIT code.*" {
413 if { $message != "" } {
416 gdb_suppress_entire_file "GDB died";
419 -re "Ending remote debugging.*$gdb_prompt $" {
420 if ![isnative] then {
421 warning "Can`t communicate to remote target."
427 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
428 if ![string match "" $message] then {
433 -re "(${question_string})$" {
434 send_gdb "$response_string\n";
437 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
438 perror "Undefined command \"$command\"."
442 -re "Ambiguous command.*$gdb_prompt $" {
443 perror "\"$command\" is not a unique command name."
447 -re "Program exited with code \[0-9\]+.*$gdb_prompt $" {
448 if ![string match "" $message] then {
449 set errmsg "$message: the program exited"
451 set errmsg "$command: the program exited"
456 -re "The program is not being run.*$gdb_prompt $" {
457 if ![string match "" $message] then {
458 set errmsg "$message: the program is no longer running"
460 set errmsg "$command: the program is no longer running"
465 -re ".*$gdb_prompt $" {
466 if ![string match "" $message] then {
473 perror "Window too small."
476 -re "\\(y or n\\) " {
478 perror "Got interactive prompt."
482 perror "Process no longer exists"
483 if { $message != "" } {
489 perror "internal buffer is full."
493 if ![string match "" $message] then {
494 fail "$message (timeout)"
502 # Test that a command gives an error. For pass or fail, return
503 # a 1 to indicate that more tests can proceed. However a timeout
504 # is a serious error, generates a special fail message, and causes
505 # a 0 to be returned to indicate that more tests are likely to fail
508 proc test_print_reject { args } {
512 if [llength $args]==2 then {
513 set expectthis [lindex $args 1]
515 set expectthis "should never match this bogus string"
517 set sendthis [lindex $args 0]
519 send_user "Sending \"$sendthis\" to gdb\n"
520 send_user "Looking to match \"$expectthis\"\n"
522 send_gdb "$sendthis\n"
523 #FIXME: Should add timeout as parameter.
525 -re "A .* in expression.*\\.*$gdb_prompt $" {
526 pass "reject $sendthis"
529 -re "Invalid syntax in expression.*$gdb_prompt $" {
530 pass "reject $sendthis"
533 -re "Junk after end of expression.*$gdb_prompt $" {
534 pass "reject $sendthis"
537 -re "Invalid number.*$gdb_prompt $" {
538 pass "reject $sendthis"
541 -re "Invalid character constant.*$gdb_prompt $" {
542 pass "reject $sendthis"
545 -re "No symbol table is loaded.*$gdb_prompt $" {
546 pass "reject $sendthis"
549 -re "No symbol .* in current context.*$gdb_prompt $" {
550 pass "reject $sendthis"
553 -re "$expectthis.*$gdb_prompt $" {
554 pass "reject $sendthis"
557 -re ".*$gdb_prompt $" {
558 fail "reject $sendthis"
562 fail "reject $sendthis (eof or timeout)"
568 # Given an input string, adds backslashes as needed to create a
569 # regexp that will match the string.
571 proc string_to_regexp {str} {
573 regsub -all {[]*+.|()^$\[]} $str {\\&} result
577 # Same as gdb_test, but the second parameter is not a regexp,
578 # but a string that must match exactly.
580 proc gdb_test_exact { args } {
581 upvar timeout timeout
583 set command [lindex $args 0]
585 # This applies a special meaning to a null string pattern. Without
586 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
587 # messages from commands that should have no output except a new
588 # prompt. With this, only results of a null string will match a null
591 set pattern [lindex $args 1]
592 if [string match $pattern ""] {
593 set pattern [string_to_regexp [lindex $args 0]]
595 set pattern [string_to_regexp [lindex $args 1]]
598 # It is most natural to write the pattern argument with only
599 # embedded \n's, especially if you are trying to avoid Tcl quoting
600 # problems. But gdb_expect really wants to see \r\n in patterns. So
601 # transform the pattern here. First transform \r\n back to \n, in
602 # case some users of gdb_test_exact already do the right thing.
603 regsub -all "\r\n" $pattern "\n" pattern
604 regsub -all "\n" $pattern "\r\n" pattern
605 if [llength $args]==3 then {
606 set message [lindex $args 2]
611 return [gdb_test $command $pattern $message]
614 proc gdb_reinitialize_dir { subdir } {
617 if [is_remote host] {
622 -re "Reinitialize source path to empty.*y or n. " {
625 -re "Source directories searched.*$gdb_prompt $" {
626 send_gdb "dir $subdir\n"
628 -re "Source directories searched.*$gdb_prompt $" {
629 verbose "Dir set to $subdir"
631 -re "$gdb_prompt $" {
632 perror "Dir \"$subdir\" failed."
636 -re "$gdb_prompt $" {
637 perror "Dir \"$subdir\" failed."
641 -re "$gdb_prompt $" {
642 perror "Dir \"$subdir\" failed."
648 # gdb_exit -- exit the GDB, killing the target program if necessary
650 proc default_gdb_exit {} {
656 gdb_stop_suppressing_tests;
658 if ![info exists gdb_spawn_id] {
662 verbose "Quitting $GDB $GDBFLAGS"
664 if { [is_remote host] && [board_info host exists fileid] } {
671 -re "DOSEXIT code" { }
676 if ![is_remote host] {
683 # load a file into the debugger.
684 # return a -1 if anything goes wrong.
686 proc gdb_file_cmd { arg } {
692 upvar timeout timeout
694 if [is_remote host] {
695 set arg [remote_download host $arg];
697 error "download failed"
702 send_gdb "file $arg\n"
704 -re "Reading symbols from.*done.*$gdb_prompt $" {
705 verbose "\t\tLoaded $arg into the $GDB"
708 -re "has no symbol-table.*$gdb_prompt $" {
709 perror "$arg wasn't compiled with \"-g\""
712 -re "A program is being debugged already.*Kill it.*y or n. $" {
714 verbose "\t\tKilling previous program being debugged"
717 -re "Load new symbol table from \".*\".*y or n. $" {
720 -re "Reading symbols from.*done.*$gdb_prompt $" {
721 verbose "\t\tLoaded $arg with new symbol table into $GDB"
725 perror "(timeout) Couldn't load $arg, other program already loaded."
730 -re "No such file or directory.*$gdb_prompt $" {
731 perror "($arg) No such file or directory\n"
734 -re "$gdb_prompt $" {
735 perror "couldn't load $arg into $GDB."
739 perror "couldn't load $arg into $GDB (timed out)."
743 # This is an attempt to detect a core dump, but seems not to
744 # work. Perhaps we need to match .* followed by eof, in which
745 # gdb_expect does not seem to have a way to do that.
746 perror "couldn't load $arg into $GDB (end of file)."
753 # start gdb -- start gdb running, default procedure
755 # When running over NFS, particularly if running many simultaneous
756 # tests on different hosts all using the same server, things can
757 # get really slow. Give gdb at least 3 minutes to start up.
759 proc default_gdb_start { } {
767 gdb_stop_suppressing_tests;
769 verbose "Spawning $GDB -nw $GDBFLAGS"
771 if [info exists gdb_spawn_id] {
775 if ![is_remote host] {
776 if { [which $GDB] == 0 } then {
777 perror "$GDB does not exist."
781 set res [remote_spawn host "$GDB -nw $GDBFLAGS [host_info gdb_opts]"];
782 if { $res < 0 || $res == "" } {
783 perror "Spawning $GDB failed."
787 -re "\[\r\n\]$gdb_prompt $" {
788 verbose "GDB initialized."
790 -re "$gdb_prompt $" {
791 perror "GDB never initialized."
795 perror "(timeout) GDB never initialized after 10 seconds."
801 # force the height to "unlimited", so no pagers get used
803 send_gdb "set height 0\n"
805 -re "$gdb_prompt $" {
806 verbose "Setting height to 0." 2
809 warning "Couldn't set the height to 0"
812 # force the width to "unlimited", so no wraparound occurs
813 send_gdb "set width 0\n"
815 -re "$gdb_prompt $" {
816 verbose "Setting width to 0." 2
819 warning "Couldn't set the width to 0."
825 # * For crosses, the CHILL runtime doesn't build because it can't find
826 # setjmp.h, stdio.h, etc.
827 # * For AIX (as of 16 Mar 95), (a) there is no language code for
828 # CHILL in output_epilog in gcc/config/rs6000/rs6000.c, (b) collect2
829 # does not get along with AIX's too-clever linker.
830 # * On Irix5, there is a bug whereby set of bool, etc., don't get
831 # TYPE_LOW_BOUND for the bool right because force_to_range_type doesn't
832 # work with stub types.
833 # Lots of things seem to fail on the PA, and since it's not a supported
834 # chill target at the moment, don't run the chill tests.
836 proc skip_chill_tests {} {
837 if ![info exists do_chill_tests] {
840 eval set skip_chill [expr ![isnative] || [istarget "*-*-aix*"] || [istarget "*-*-irix5*"] || [istarget "*-*-irix6*"] || [istarget "alpha-*-osf*"] || [istarget "hppa*-*-*"]]
841 verbose "Skip chill tests is $skip_chill"
845 # Skip all the tests in the file if you are not on an hppa running
848 proc skip_hp_tests {} {
849 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
850 verbose "Skip hp tests is $skip_hp"
854 proc get_compiler_info {binfile args} {
855 # Create and source the file that provides information about the compiler
856 # used to compile the test case.
857 # Compiler_type can be null or c++. If null we assume c.
860 # These two come from compiler.c.
861 global signed_keyword_not_used
864 if {![istarget "hppa*-*-hpux*"]} {
865 if { [llength $args] > 0 } {
866 if {$args == "c++"} {
867 if { [gdb_compile "${srcdir}/${subdir}/compiler.cc" "${binfile}.ci" preprocess {}] != "" } {
868 perror "Couldn't make ${binfile}.ci file"
873 if { [gdb_compile "${srcdir}/${subdir}/compiler.c" "${binfile}.ci" preprocess {}] != "" } {
874 perror "Couldn't make ${binfile}.ci file"
879 if { [llength $args] > 0 } {
880 if {$args == "c++"} {
881 if { [eval gdb_preprocess \
882 [list "${srcdir}/${subdir}/compiler.cc" "${binfile}.ci"] \
884 perror "Couldn't make ${binfile}.ci file"
889 if { [eval gdb_preprocess \
890 [list "${srcdir}/${subdir}/compiler.c" "${binfile}.ci"] \
892 perror "Couldn't make ${binfile}.ci file"
898 uplevel \#0 { set gcc_compiled 0 }
900 if { [llength $args] == 0 || $args != "f77" } {
904 # Most compilers will evaluate comparisons and other boolean
905 # operations to 0 or 1.
906 uplevel \#0 { set true 1 }
907 uplevel \#0 { set false 0 }
909 uplevel \#0 { set hp_cc_compiler 0 }
910 uplevel \#0 { set hp_aCC_compiler 0 }
911 uplevel \#0 { set hp_f77_compiler 0 }
912 uplevel \#0 { set hp_f90_compiler 0 }
913 if { !$gcc_compiled && [istarget "hppa*-*-hpux*"] } {
914 # Check for the HP compilers
915 set compiler [lindex [split [get_compiler $args] " "] 0]
916 catch "exec what $compiler" output
917 if [regexp ".*HP aC\\+\\+.*" $output] {
918 uplevel \#0 { set hp_aCC_compiler 1 }
919 # Use of aCC results in boolean results being displayed as
921 uplevel \#0 { set true true }
922 uplevel \#0 { set false false }
923 } elseif [regexp ".*HP C Compiler.*" $output] {
924 uplevel \#0 { set hp_cc_compiler 1 }
925 } elseif [regexp ".*HP-UX f77.*" $output] {
926 uplevel \#0 { set hp_f77_compiler 1 }
927 } elseif [regexp ".*HP-UX f90.*" $output] {
928 uplevel \#0 { set hp_f90_compiler 1 }
935 proc gdb_preprocess {source dest args} {
937 global CXX_FOR_TARGET
939 if { [llength $args] == 0 } {
940 set which_compiler "c"
942 if { $args =="c++" } {
943 set which_compiler "c++"
945 perror "Unknown compiler type supplied to gdb_preprocess"
950 if [info exists CC_FOR_TARGET] {
951 if { $which_compiler == "c"} {
952 set compiler $CC_FOR_TARGET;
956 if [info exists CXX_FOR_TARGET] {
957 if { $which_compiler == "c++"} {
958 set compiler $CXX_FOR_TARGET;
962 if { ![info exists compiler] } {
963 if { $which_compiler == "c" } {
964 if {[info exists CC]} {
968 if { $which_compiler == "c++" } {
969 if {[info exists CXX]} {
973 if {![info exists compiler]} {
974 set compiler [board_info [target_info name] compiler];
975 if { $compiler == "" } {
976 puts "default_target_compile: No compiler to compile with";
977 return "default_target_compile: No compiler to compile with";
982 set cmdline "$compiler -E $source > $dest"
984 verbose "Invoking $compiler -E $source > $dest"
985 verbose -log "Executing on local host: $cmdline" 2
986 set status [catch "exec ${cmdline}" exec_output]
988 set result [prune_warnings $exec_output]
989 regsub "\[\r\n\]*$" "$result" "" result;
990 regsub "^\[\r\n\]*" "$result" "" result;
991 if { $result != "" } {
992 clone_output "gdb compile failed, $result"
997 proc gdb_compile {source dest type options} {
998 global GDB_TESTCASE_OPTIONS;
1000 if [target_info exists gdb_stub] {
1001 set options2 { "additional_flags=-Dusestubs" }
1002 lappend options "libs=[target_info gdb_stub]";
1003 set options [concat $options2 $options]
1005 if [target_info exists is_vxworks] {
1006 set options2 { "additional_flags=-Dvxworks" }
1007 lappend options "libs=[target_info gdb_stub]";
1008 set options [concat $options2 $options]
1010 if [info exists GDB_TESTCASE_OPTIONS] {
1011 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
1013 verbose "options are $options"
1014 verbose "source is $source $dest $type $options"
1016 set result [target_compile $source $dest $type $options];
1017 regsub "\[\r\n\]*$" "$result" "" result;
1018 regsub "^\[\r\n\]*" "$result" "" result;
1019 if { $result != "" } {
1020 clone_output "gdb compile failed, $result"
1025 proc send_gdb { string } {
1026 global suppress_flag;
1027 if { $suppress_flag } {
1028 return "suppressed";
1030 return [remote_send host "$string"];
1036 proc gdb_expect { args } {
1037 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
1038 set gtimeout [lindex $args 0];
1039 set expcode [list [lindex $args 1]];
1041 upvar timeout timeout;
1044 if [target_info exists gdb,timeout] {
1045 if [info exists timeout] {
1046 if { $timeout < [target_info gdb,timeout] } {
1047 set gtimeout [target_info gdb,timeout];
1049 set gtimeout $timeout;
1052 set gtimeout [target_info gdb,timeout];
1056 if ![info exists gtimeout] {
1058 if [info exists timeout] {
1059 set gtimeout $timeout;
1066 global suppress_flag;
1067 global remote_suppress_flag;
1068 if [info exists remote_suppress_flag] {
1069 set old_val $remote_suppress_flag;
1071 if [info exists suppress_flag] {
1072 if { $suppress_flag } {
1073 set remote_suppress_flag 1;
1076 set code [catch {uplevel remote_expect host $gtimeout $expcode} string];
1077 if [info exists old_val] {
1078 set remote_suppress_flag $old_val;
1080 if [info exists remote_suppress_flag] {
1081 unset remote_suppress_flag;
1086 global errorInfo errorCode;
1088 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
1089 } elseif {$code == 2} {
1090 return -code return $string
1091 } elseif {$code == 3} {
1093 } elseif {$code > 4} {
1094 return -code $code $string
1099 # Check for long sequence of output by parts.
1100 # TEST: is the test message.
1101 # SENTINEL: Is the terminal pattern indicating that output has finished.
1102 # LIST: is the sequence of outputs to match.
1103 # If the sentinel is recognized early, it is considered an error.
1105 proc gdb_expect_list {test sentinal list} {
1108 while { ${index} >= 0 && ${index} < [llength ${list}] } {
1109 set pattern [lindex ${list} ${index}]
1110 set index [expr ${index} + 1]
1111 if { ${index} == [llength ${list}] } {
1113 -re "${pattern}${sentinal}" {
1114 pass "${test} (sentinal)"
1117 fail "(timeout on sentinal) ${test}"
1124 pass "${test} (line ${index})"
1127 fail "${test} (line ${index})"
1131 fail "(timeout on line ${index}) ${test}"
1137 if { ${index} >= 0 } {
1144 proc gdb_suppress_entire_file { reason } {
1145 global suppress_flag;
1147 warning "$reason\n";
1148 set suppress_flag -1;
1152 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
1153 # gdb_expect to fail immediately (until the next call to
1154 # gdb_stop_suppressing_tests).
1156 proc gdb_suppress_tests { args } {
1157 global suppress_flag;
1159 return; # fnf - disable pending review of results where
1160 # testsuite ran better without this
1163 if { $suppress_flag == 1 } {
1164 if { [llength $args] > 0 } {
1165 warning "[lindex $args 0]\n";
1167 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
1173 # Clear suppress_flag.
1175 proc gdb_stop_suppressing_tests { } {
1176 global suppress_flag;
1178 if [info exists suppress_flag] {
1179 if { $suppress_flag > 0 } {
1180 set suppress_flag 0;
1181 clone_output "Tests restarted.\n";
1184 set suppress_flag 0;
1188 proc gdb_clear_suppressed { } {
1189 global suppress_flag;
1191 set suppress_flag 0;
1194 proc gdb_start { } {
1199 catch default_gdb_exit
1203 # gdb_load -- load a file into the debugger.
1204 # return a -1 if anything goes wrong.
1206 proc gdb_load { arg } {
1207 return [gdb_file_cmd $arg]
1210 proc gdb_continue { function } {
1213 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
1216 proc default_gdb_init { args } {
1217 gdb_clear_suppressed;
1219 # Uh, this is lame. Really, really, really lame. But there's this *one*
1220 # testcase that will fail in random places if we don't increase this.
1223 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
1224 if { [llength $args] > 0 } {
1227 set file [lindex $args 0];
1229 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
1232 if [target_info exists gdb_prompt] {
1233 set gdb_prompt [target_info gdb_prompt];
1235 set gdb_prompt "\\(gdb\\)"
1239 proc gdb_init { args } {
1240 return [eval default_gdb_init $args];
1243 proc gdb_finish { } {
1248 set debug_format "unknown"
1250 # Run the gdb command "info source" and extract the debugging format
1251 # information from the output and save it in debug_format.
1253 proc get_debug_format { } {
1259 set debug_format "unknown"
1260 send_gdb "info source\n"
1262 -re "Compiled with (.*) debugging format.\r\n$gdb_prompt $" {
1263 set debug_format $expect_out(1,string)
1264 verbose "debug format is $debug_format"
1267 -re "No current source file.\r\n$gdb_prompt $" {
1268 perror "get_debug_format used when no current source file"
1271 -re "$gdb_prompt $" {
1272 warning "couldn't check debug format (no valid response)."
1276 warning "couldn't check debug format (timed out)."
1282 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
1283 # COFF, stabs, etc). If that format matches the format that the
1284 # current test was compiled with, then the next test is expected to
1285 # fail for any target. Returns 1 if the next test or set of tests is
1286 # expected to fail, 0 otherwise (or if it is unknown). Must have
1287 # previously called get_debug_format.
1289 proc setup_xfail_format { format } {
1292 if [string match $debug_format $format] then {
1299 proc gdb_step_for_stub { } {
1302 if ![target_info exists gdb,use_breakpoint_for_stub] {
1303 if [target_info exists gdb_stub_step_command] {
1304 set command [target_info gdb_stub_step_command];
1308 send_gdb "${command}\n";
1311 -re "(main.* at |.*in .*start).*$gdb_prompt" {
1314 -re ".*$gdb_prompt" {
1316 if { $tries == 5 } {
1317 fail "stepping out of breakpoint function";
1320 send_gdb "${command}\n";
1324 fail "stepping out of breakpoint function";
1331 -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" {
1332 set file $expect_out(1,string);
1333 set linenum [expr $expect_out(2,string) + 1];
1334 set breakplace "${file}:${linenum}";
1338 send_gdb "break ${breakplace}\n";
1340 -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" {
1341 set breakpoint $expect_out(1,string);
1343 -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" {
1344 set breakpoint $expect_out(1,string);
1348 send_gdb "continue\n";
1350 -re "Breakpoint ${breakpoint},.*$gdb_prompt" {
1351 gdb_test "delete $breakpoint" ".*" "";
1358 ### gdb_get_line_number TEXT [FILE]
1360 ### Search the source file FILE, and return the line number of a line
1361 ### containing TEXT. Use this function instead of hard-coding line
1362 ### numbers into your test script.
1364 ### Specifically, this function uses GDB's "search" command to search
1365 ### FILE for the first line containing TEXT, and returns its line
1366 ### number. Thus, FILE must be a source file, compiled into the
1367 ### executable you are running. If omitted, FILE defaults to the
1368 ### value of the global variable `srcfile'; most test scripts set
1369 ### `srcfile' appropriately at the top anyway.
1371 ### Use this function to keep your test scripts independent of the
1372 ### exact line numbering of the source file. Don't write:
1374 ### send_gdb "break 20"
1376 ### This means that if anyone ever edits your test's source file,
1377 ### your test could break. Instead, put a comment like this on the
1378 ### source file line you want to break at:
1380 ### /* breakpoint spot: frotz.exp: test name */
1382 ### and then write, in your test script (which we assume is named
1385 ### send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
1387 ### (Yes, Tcl knows how to handle the nested quotes and brackets.
1390 ### % puts "foo [lindex "bar baz" 1]"
1393 ### Tcl is quite clever, for a little stringy language.)
1395 proc gdb_get_line_number {text {file /omitted/}} {
1399 if {! [string compare $file /omitted/]} {
1404 gdb_test "list ${file}:1,1" ".*" ""
1405 send_gdb "search ${text}\n"
1407 -re "\[\r\n\]+(\[0-9\]+)\[ \t\].*${text}.*$gdb_prompt $" {
1408 set result $expect_out(1,string)
1410 -re ".*$gdb_prompt $" {
1411 fail "find line number containing \"${text}\""
1414 fail "find line number containing \"${text}\" (timeout)"
1420 # gdb_continue_to_end:
1421 # The case where the target uses stubs has to be handled specially. If a
1422 # stub is used, we set a breakpoint at exit because we cannot rely on
1423 # exit() behavior of a remote target.
1425 # mssg is the error message that gets printed.
1427 proc gdb_continue_to_end {mssg} {
1428 if [target_info exists use_gdb_stub] {
1429 if {![gdb_breakpoint "exit"]} {
1432 gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \
1433 "continue until exit at $mssg"
1435 # Continue until we exit. Should not stop again.
1436 # Don't bother to check the output of the program, that may be
1437 # extremely tough for some remote systems.
1438 gdb_test "continue"\
1439 "Continuing.\[\r\n0-9\]+Program exited normally\\..*"\
1440 "continue until exit at $mssg"
1444 proc rerun_to_main {} {
1447 if [target_info exists use_gdb_stub] {
1450 -re ".*Breakpoint .*main .*$gdb_prompt $"\
1451 {pass "rerun to main" ; return 0}
1452 -re "$gdb_prompt $"\
1453 {fail "rerun to main" ; return 0}
1454 timeout {fail "(timeout) rerun to main" ; return 0}
1459 -re "Starting program.*$gdb_prompt $"\
1460 {pass "rerun to main" ; return 0}
1461 -re "$gdb_prompt $"\
1462 {fail "rerun to main" ; return 0}
1463 timeout {fail "(timeout) rerun to main" ; return 0}