1 # Copyright (C) 1992, 1994, 1995, 1997 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 prompt is a regexp which matches the gdb prompt. Set it if it
62 if ![info exists prompt] then {
63 set gdb_prompt "\[(\]gdb\[)\]"
67 # gdb_version -- extract and print the version number of GDB
69 proc default_gdb_version {} {
73 set fileid [open "gdb_cmd" w];
76 set cmdfile [remote_download host "gdb_cmd"];
77 set output [remote_exec host "$GDB -nw --command $cmdfile"]
78 remote_file build delete "gdb_cmd";
79 remote_file host delete "$cmdfile";
80 set tmp [lindex $output 1];
82 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
83 if ![is_remote host] {
84 clone_output "[which $GDB] version $version $GDBFLAGS\n"
86 clone_output "$GDB on remote host version $version $GDBFLAGS\n"
90 proc gdb_version { } {
91 return [default_gdb_version];
95 # gdb_unload -- unload a file if one is loaded
104 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
105 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
106 -re "A program is being debugged already..*Kill it.*y or n. $"\
108 verbose "\t\tKilling previous program being debugged"
111 -re "Discard symbol table from .*y or n.*$" {
115 -re "$gdb_prompt $" {}
117 perror "couldn't unload file in $GDB (timed out)."
123 # Many of the tests depend on setting breakpoints at various places and
124 # running until that breakpoint is reached. At times, we want to start
125 # with a clean-slate with respect to breakpoints, so this utility proc
126 # lets us do this without duplicating this code everywhere.
129 proc delete_breakpoints {} {
132 send_gdb "delete breakpoints\n"
134 -re "Delete all breakpoints.*y or n.*$" {
138 -re "$gdb_prompt $" { # This happens if there were no breakpoints
140 timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
142 send_gdb "info breakpoints\n"
144 -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
145 -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
146 -re "Delete all breakpoints.*or n.*$" {
150 timeout { perror "info breakpoints (timeout)" ; return }
156 # Generic run command.
158 # The second pattern below matches up to the first newline *only*.
159 # Using ``.*$'' could swallow up output that we attempt to match
162 proc gdb_run_cmd {args} {
165 if [target_info exists gdb_init_command] {
166 send_gdb "[target_info gdb_init_command]\n";
168 -re "$gdb_prompt $" { }
170 perror "gdb_init_command for target failed";
176 if [target_info exists use_gdb_stub] {
177 if [target_info exists gdb,do_reload_on_run] {
178 # According to Stu, this will always work.
180 send_gdb "continue\n";
182 -re "Continu\[^\r\n\]*\[\r\n\]" {}
188 if [target_info exists gdb,start_symbol] {
189 set start [target_info gdb,start_symbol];
193 send_gdb "jump *$start\n"
195 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
196 if ![target_info exists gdb_stub] {
200 -re "No symbol \"start\" in current.*$gdb_prompt $" {
201 send_gdb "jump *_start\n";
204 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
205 perror "Can't find start symbol to run in gdb_run";
208 -re "Line.* Jump anyway.*y or n. $" {
212 -re "No symbol.*context.*$gdb_prompt $" {}
213 -re "The program is not being run.*$gdb_prompt $" {
215 send_gdb "jump *$start\n";
218 timeout { perror "Jump to start() failed (timeout)"; return }
220 if [target_info exists gdb_stub] {
222 -re "$gdb_prompt $" {
223 send_gdb "continue\n"
229 send_gdb "run $args\n"
230 # This doesn't work quite right yet.
232 -re "The program .* has been started already.*y or n. $" {
236 -re "Starting program: \[^\r\n\]*" {}
240 proc gdb_breakpoint { function } {
244 send_gdb "break $function\n"
245 # The first two regexps are what we get with -g, the third is without -g.
247 -re "Breakpoint \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
248 -re "Breakpoint \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
249 -re "Breakpoint \[0-9\]* at .*$gdb_prompt $" {}
250 -re "$gdb_prompt $" { fail "setting breakpoint at $function" ; return 0 }
251 timeout { fail "setting breakpoint at $function (timeout)" ; return 0 }
256 # Set breakpoint at function and run gdb until it breaks there.
257 # Since this is the only breakpoint that will be set, if it stops
258 # at a breakpoint, we will assume it is the one we want. We can't
259 # just compare to "function" because it might be a fully qualified,
260 # single quoted C++ function specifier.
262 proc runto { function } {
268 if ![gdb_breakpoint $function] {
274 # the "at foo.c:36" output we get with -g.
275 # the "in func" output we get without -g.
277 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
280 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
283 -re "$gdb_prompt $" {
284 fail "running to $function in runto"
288 fail "running to $function in runto (timeout)"
296 # runto_main -- ask gdb to run until we hit a breakpoint at main.
297 # The case where the target uses stubs has to be handled
298 # specially--if it uses stubs, assuming we hit
299 # breakpoint() and just step out of the function.
301 proc runto_main { } {
305 if ![target_info exists gdb_stub] {
316 # gdb_test COMMAND PATTERN MESSAGE -- send a command to gdb; test the result.
318 # COMMAND is the command to execute, send to GDB with send_gdb. If
319 # this is the null string no command is sent.
320 # PATTERN is the pattern to match for a PASS, and must NOT include
321 # the \r\n sequence immediately before the gdb prompt.
322 # MESSAGE is an optional message to be printed. If this is
323 # omitted, then the pass/fail messages use the command string as the
324 # message. (If this is the empty string, then sometimes we don't
325 # call pass or fail at all; I don't understand this at all.)
328 # 1 if the test failed,
329 # 0 if the test passes,
330 # -1 if there was an internal error.
332 proc gdb_test { args } {
336 upvar timeout timeout
338 if [llength $args]>2 then {
339 set message [lindex $args 2]
341 set message [lindex $args 0]
343 set command [lindex $args 0]
344 set pattern [lindex $args 1]
346 if [llength $args]==5 {
347 set question_string [lindex $args 3];
348 set response_string [lindex $args 4];
350 set question_string "^FOOBAR$"
354 send_user "Sending \"$command\" to gdb\n"
355 send_user "Looking to match \"$pattern\"\n"
356 send_user "Message is \"$message\"\n"
360 set string "${command}\n";
361 if { $command != "" } {
362 while { "$string" != "" } {
363 set foo [string first "\n" "$string"];
364 set len [string length "$string"];
365 if { $foo < [expr $len - 1] } {
366 set str [string range "$string" 0 $foo];
367 if { [send_gdb "$str"] != "" } {
368 global suppress_flag;
370 if { ! $suppress_flag } {
371 perror "Couldn't send $command to GDB.";
380 set string [string range "$string" [expr $foo + 1] end];
385 if { "$string" != "" } {
386 if { [send_gdb "$string"] != "" } {
387 global suppress_flag;
389 if { ! $suppress_flag } {
390 perror "Couldn't send $command to GDB.";
398 if [info exists timeout] {
402 if [info exists timeout] {
409 -re "\\*\\*\\* DOSEXIT code.*" {
410 if { $message != "" } {
413 gdb_suppress_entire_file "GDB died";
416 -re "Ending remote debugging.*$gdb_prompt$" {
417 if ![isnative] then {
418 warning "Can`t communicate to remote target."
424 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
425 if ![string match "" $message] then {
430 -re "(${question_string})$" {
431 send_gdb "$response_string\n";
434 -re "Undefined command:.*$gdb_prompt" {
435 perror "Undefined command \"$command\"."
438 -re "Ambiguous command.*$gdb_prompt $" {
439 perror "\"$command\" is not a unique command name."
442 -re "Program exited with code \[0-9\]+.*$gdb_prompt $" {
443 if ![string match "" $message] then {
444 set errmsg "$message: the program exited"
446 set errmsg "$command: the program exited"
451 -re "The program is not being run.*$gdb_prompt $" {
452 if ![string match "" $message] then {
453 set errmsg "$message: the program is no longer running"
455 set errmsg "$command: the program is no longer running"
460 -re ".*$gdb_prompt $" {
461 if ![string match "" $message] then {
468 perror "Window too small."
470 -re "\\(y or n\\) " {
472 perror "Got interactive prompt."
475 perror "Process no longer exists"
476 if { $message != "" } {
482 perror "internal buffer is full."
485 if ![string match "" $message] then {
486 fail "$message (timeout)"
494 # Test that a command gives an error. For pass or fail, return
495 # a 1 to indicate that more tests can proceed. However a timeout
496 # is a serious error, generates a special fail message, and causes
497 # a 0 to be returned to indicate that more tests are likely to fail
500 proc test_print_reject { args } {
504 if [llength $args]==2 then {
505 set expectthis [lindex $args 1]
507 set expectthis "should never match this bogus string"
509 set sendthis [lindex $args 0]
511 send_user "Sending \"$sendthis\" to gdb\n"
512 send_user "Looking to match \"$expectthis\"\n"
514 send_gdb "$sendthis\n"
515 #FIXME: Should add timeout as parameter.
517 -re "A .* in expression.*\\.*$gdb_prompt $" {
518 pass "reject $sendthis"
521 -re "Invalid syntax in expression.*$gdb_prompt $" {
522 pass "reject $sendthis"
525 -re "Junk after end of expression.*$gdb_prompt $" {
526 pass "reject $sendthis"
529 -re "Invalid number.*$gdb_prompt $" {
530 pass "reject $sendthis"
533 -re "Invalid character constant.*$gdb_prompt $" {
534 pass "reject $sendthis"
537 -re "No symbol table is loaded.*$gdb_prompt $" {
538 pass "reject $sendthis"
541 -re "No symbol .* in current context.*$gdb_prompt $" {
542 pass "reject $sendthis"
545 -re "$expectthis.*$gdb_prompt $" {
546 pass "reject $sendthis"
549 -re ".*$gdb_prompt $" {
550 fail "reject $sendthis"
554 fail "reject $sendthis (eof or timeout)"
560 # Given an input string, adds backslashes as needed to create a
561 # regexp that will match the string.
563 proc string_to_regexp {str} {
565 regsub -all {[]*+.|()^$\[]} $str {\\&} result
569 # Same as gdb_test, but the second parameter is not a regexp,
570 # but a string that must match exactly.
572 proc gdb_test_exact { args } {
573 upvar timeout timeout
575 set command [lindex $args 0]
577 # This applies a special meaning to a null string pattern. Without
578 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
579 # messages from commands that should have no output except a new
580 # prompt. With this, only results of a null string will match a null
583 set pattern [lindex $args 1]
584 if [string match $pattern ""] {
585 set pattern [string_to_regexp [lindex $args 0]]
587 set pattern [string_to_regexp [lindex $args 1]]
590 # It is most natural to write the pattern argument with only
591 # embedded \n's, especially if you are trying to avoid Tcl quoting
592 # problems. But gdb_expect really wants to see \r\n in patterns. So
593 # transform the pattern here. First transform \r\n back to \n, in
594 # case some users of gdb_test_exact already do the right thing.
595 regsub -all "\r\n" $pattern "\n" pattern
596 regsub -all "\n" $pattern "\r\n" pattern
597 if [llength $args]==3 then {
598 set message [lindex $args 2]
603 return [gdb_test $command $pattern $message]
606 proc gdb_reinitialize_dir { subdir } {
609 if [is_remote host] {
614 -re "Reinitialize source path to empty.*y or n. " {
617 -re "Source directories searched.*$gdb_prompt $" {
618 send_gdb "dir $subdir\n"
620 -re "Source directories searched.*$gdb_prompt $" {
621 verbose "Dir set to $subdir"
623 -re "$gdb_prompt $" {
624 perror "Dir \"$subdir\" failed."
628 -re "$gdb_prompt $" {
629 perror "Dir \"$subdir\" failed."
633 -re "$gdb_prompt $" {
634 perror "Dir \"$subdir\" failed."
640 # gdb_exit -- exit the GDB, killing the target program if necessary
642 proc default_gdb_exit {} {
648 gdb_stop_suppressing_tests;
650 if ![info exists gdb_spawn_id] {
654 verbose "Quitting $GDB $GDBFLAGS"
656 if { [is_remote host] && [board_info host exists fileid] } {
663 -re "DOSEXIT code" { }
668 if ![is_remote host] {
675 # load a file into the debugger.
676 # return a -1 if anything goes wrong.
678 proc gdb_file_cmd { arg } {
684 upvar timeout timeout
686 if [is_remote host] {
687 set arg [remote_download host $arg];
689 error "download failed"
694 send_gdb "file $arg\n"
696 -re "Reading symbols from.*done.*$gdb_prompt $" {
697 verbose "\t\tLoaded $arg into the $GDB"
700 -re "has no symbol-table.*$gdb_prompt $" {
701 perror "$arg wasn't compiled with \"-g\""
704 -re "A program is being debugged already.*Kill it.*y or n. $" {
706 verbose "\t\tKilling previous program being debugged"
709 -re "Load new symbol table from \".*\".*y or n. $" {
712 -re "Reading symbols from.*done.*$gdb_prompt $" {
713 verbose "\t\tLoaded $arg with new symbol table into $GDB"
717 perror "(timeout) Couldn't load $arg, other program already loaded."
722 -re "No such file or directory.*$gdb_prompt $" {
723 perror "($arg) No such file or directory\n"
726 -re "$gdb_prompt $" {
727 perror "couldn't load $arg into $GDB."
731 perror "couldn't load $arg into $GDB (timed out)."
735 # This is an attempt to detect a core dump, but seems not to
736 # work. Perhaps we need to match .* followed by eof, in which
737 # gdb_expect does not seem to have a way to do that.
738 perror "couldn't load $arg into $GDB (end of file)."
745 # start gdb -- start gdb running, default procedure
747 # When running over NFS, particularly if running many simultaneous
748 # tests on different hosts all using the same server, things can
749 # get really slow. Give gdb at least 3 minutes to start up.
751 proc default_gdb_start { } {
759 gdb_stop_suppressing_tests;
761 verbose "Spawning $GDB -nw $GDBFLAGS"
763 if [info exists gdb_spawn_id] {
767 if ![is_remote host] {
768 if { [which $GDB] == 0 } then {
769 perror "$GDB does not exist."
773 set res [remote_spawn host "$GDB -nw $GDBFLAGS [host_info gdb_opts]"];
774 if { $res < 0 || $res == "" } {
775 perror "Spawning $GDB failed."
779 -re "\[\r\n\]$gdb_prompt $" {
780 verbose "GDB initialized."
782 -re "$gdb_prompt $" {
783 perror "GDB never initialized."
787 perror "(timeout) GDB never initialized after 10 seconds."
793 # force the height to "unlimited", so no pagers get used
795 send_gdb "set height 0\n"
797 -re "$gdb_prompt $" {
798 verbose "Setting height to 0." 2
801 warning "Couldn't set the height to 0"
804 # force the width to "unlimited", so no wraparound occurs
805 send_gdb "set width 0\n"
807 -re "$gdb_prompt $" {
808 verbose "Setting width to 0." 2
811 warning "Couldn't set the width to 0."
817 # * For crosses, the CHILL runtime doesn't build because it can't find
818 # setjmp.h, stdio.h, etc.
819 # * For AIX (as of 16 Mar 95), (a) there is no language code for
820 # CHILL in output_epilog in gcc/config/rs6000/rs6000.c, (b) collect2
821 # does not get along with AIX's too-clever linker.
822 # * On Irix5, there is a bug whereby set of bool, etc., don't get
823 # TYPE_LOW_BOUND for the bool right because force_to_range_type doesn't
824 # work with stub types.
825 # Lots of things seem to fail on the PA, and since it's not a supported
826 # chill target at the moment, don't run the chill tests.
828 proc skip_chill_tests {} {
829 if ![info exists do_chill_tests] {
832 eval set skip_chill [expr ![isnative] || [istarget "*-*-aix*"] || [istarget "*-*-irix5*"] || [istarget "*-*-irix6*"] || [istarget "alpha-*-osf*"] || [istarget "hppa*-*-*"]]
833 verbose "Skip chill tests is $skip_chill"
837 # skip all the tests in the file if you are not on an hppa running hpux target.
838 # and you compiled with gcc
839 proc skip_hp_tests {gcc_used} {
840 # if ![info exists do_hp_tests] {
843 eval set skip_hp [expr ![isnative] || ![istarget "hppa*-*-hpux*"] || $gcc_used!=0 ]
844 verbose "Skip hp tests is $skip_hp"
848 proc get_compiler_info {binfile args} {
849 # Create and source the file that provides information about the compiler
850 # used to compile the test case.
851 # Compiler_type can be null or c++. If null we assume c.
854 # These two come from compiler.c.
855 global signed_keyword_not_used
858 if {![istarget "hppa*-*-hpux*"]} {
859 if { [llength $args] > 0 } {
860 if {$args == "c++"} {
861 if { [gdb_compile "${srcdir}/${subdir}/compiler.cc" "${binfile}.ci" preprocess {}] != "" } {
862 perror "Couldn't make ${binfile}.ci file"
867 if { [gdb_compile "${srcdir}/${subdir}/compiler.c" "${binfile}.ci" preprocess {}] != "" } {
868 perror "Couldn't make ${binfile}.ci file"
873 if { [llength $args] > 0 } {
874 if {$args == "c++"} {
875 if { [eval gdb_preprocess \
876 [list "${srcdir}/${subdir}/compiler.cc" "${binfile}.ci"] \
878 perror "Couldn't make ${binfile}.ci file"
883 if { [eval gdb_preprocess \
884 [list "${srcdir}/${subdir}/compiler.c" "${binfile}.ci"] \
886 perror "Couldn't make ${binfile}.ci file"
896 proc gdb_preprocess {source dest args} {
898 global CXX_FOR_TARGET
900 if { [llength $args] == 0 } {
901 set which_compiler "c"
903 if { $args =="c++" } {
904 set which_compiler "c++"
906 perror "Unknown compiler type supplied to gdb_preprocess"
911 if [info exists CC_FOR_TARGET] {
912 if { $which_compiler == "c"} {
913 set compiler $CC_FOR_TARGET;
917 if [info exists CXX_FOR_TARGET] {
918 if { $which_compiler == "c++"} {
919 set compiler $CXX_FOR_TARGET;
923 if { ![info exists compiler] } {
924 if { $which_compiler == "c" } {
925 if {[info exists CC]} {
929 if { $which_compiler == "c++" } {
930 if {[info exists CXX]} {
934 if {![info exists compiler]} {
935 set compiler [board_info [target_info name] compiler];
936 if { $compiler == "" } {
937 puts "default_target_compile: No compiler to compile with";
938 return "default_target_compile: No compiler to compile with";
943 set cmdline "$compiler -E $source > $dest"
945 verbose "Invoking $compiler -E $source > $dest"
946 verbose -log "Executing on local host: $cmdline" 2
947 set status [catch "exec ${cmdline}" exec_output]
949 set result [prune_warnings $exec_output]
950 regsub "\[\r\n\]*$" "$result" "" result;
951 regsub "^\[\r\n\]*" "$result" "" result;
952 if { $result != "" } {
953 clone_output "gdb compile failed, $result"
958 proc gdb_compile {source dest type options} {
959 global GDB_TESTCASE_OPTIONS;
961 if [target_info exists gdb_stub] {
962 set options2 { "additional_flags=-Dusestubs" }
963 lappend options "libs=[target_info gdb_stub]";
964 set options [concat $options2 $options]
966 if [target_info exists is_vxworks] {
967 set options2 { "additional_flags=-Dvxworks" }
968 lappend options "libs=[target_info gdb_stub]";
969 set options [concat $options2 $options]
971 if [info exists GDB_TESTCASE_OPTIONS] {
972 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
974 verbose "options are $options"
975 verbose "source is $source $dest $type $options"
977 set result [target_compile $source $dest $type $options];
978 regsub "\[\r\n\]*$" "$result" "" result;
979 regsub "^\[\r\n\]*" "$result" "" result;
980 if { $result != "" } {
981 clone_output "gdb compile failed, $result"
986 proc send_gdb { string } {
987 global suppress_flag;
988 if { $suppress_flag } {
991 return [remote_send host "$string"];
997 proc gdb_expect { args } {
998 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
999 set gtimeout [lindex $args 0];
1000 set expcode [list [lindex $args 1]];
1002 upvar timeout timeout;
1005 if [target_info exists gdb,timeout] {
1006 if [info exists timeout] {
1007 if { $timeout < [target_info gdb,timeout] } {
1008 set gtimeout [target_info gdb,timeout];
1010 set gtimeout $timeout;
1013 set gtimeout [target_info gdb,timeout];
1017 if ![info exists gtimeout] {
1019 if [info exists timeout] {
1020 set gtimeout $timeout;
1027 global suppress_flag;
1028 global remote_suppress_flag;
1029 if [info exists remote_suppress_flag] {
1030 set old_val $remote_suppress_flag;
1032 if [info exists suppress_flag] {
1033 if { $suppress_flag } {
1034 set remote_suppress_flag 1;
1037 set code [catch {uplevel remote_expect host $gtimeout $expcode} string];
1038 if [info exists old_val] {
1039 set remote_suppress_flag $old_val;
1041 if [info exists remote_suppress_flag] {
1042 unset remote_suppress_flag;
1047 global errorInfo errorCode;
1049 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
1050 } elseif {$code == 2} {
1051 return -code return $string
1052 } elseif {$code == 3} {
1054 } elseif {$code > 4} {
1055 return -code $code $string
1059 proc gdb_suppress_entire_file { reason } {
1060 global suppress_flag;
1062 warning "$reason\n";
1063 set suppress_flag -1;
1067 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
1068 # gdb_expect to fail immediately (until the next call to
1069 # gdb_stop_suppressing_tests).
1071 proc gdb_suppress_tests { args } {
1072 global suppress_flag;
1074 return; # fnf - disable pending review of results where
1075 # testsuite ran better without this
1078 if { $suppress_flag == 1 } {
1079 if { [llength $args] > 0 } {
1080 warning "[lindex $args 0]\n";
1082 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
1088 # Clear suppress_flag.
1090 proc gdb_stop_suppressing_tests { } {
1091 global suppress_flag;
1093 if [info exists suppress_flag] {
1094 if { $suppress_flag > 0 } {
1095 set suppress_flag 0;
1096 clone_output "Tests restarted.\n";
1099 set suppress_flag 0;
1103 proc gdb_clear_suppressed { } {
1104 global suppress_flag;
1106 set suppress_flag 0;
1109 proc gdb_start { } {
1114 catch default_gdb_exit
1118 # gdb_load -- load a file into the debugger.
1119 # return a -1 if anything goes wrong.
1121 proc gdb_load { arg } {
1122 return [gdb_file_cmd $arg]
1125 proc gdb_continue { function } {
1128 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
1131 proc default_gdb_init { args } {
1132 gdb_clear_suppressed;
1134 # Uh, this is lame. Really, really, really lame. But there's this *one*
1135 # testcase that will fail in random places if we don't increase this.
1138 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
1139 if { [llength $args] > 0 } {
1142 set file [lindex $args 0];
1144 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
1147 if [target_info exists gdb_prompt] {
1148 set gdb_prompt [target_info gdb_prompt];
1150 set gdb_prompt "\\(gdb\\)"
1154 proc gdb_init { args } {
1155 return [eval default_gdb_init $args];
1158 proc gdb_finish { } {
1164 # Run the gdb command "info source" and extract the debugging format
1165 # information from the output and save it in debug_format.
1167 proc get_debug_format { } {
1173 set debug_format "unknown"
1174 send_gdb "info source\n"
1176 -re "Compiled with (.*) debugging format.\r\n$gdb_prompt $" {
1177 set debug_format $expect_out(1,string)
1178 verbose "debug format is $debug_format"
1181 -re "No current source file.\r\n$gdb_prompt $" {
1182 perror "get_debug_format used when no current source file"
1185 -re "$gdb_prompt $" {
1186 warning "couldn't check debug format (no valid response)."
1190 warning "couldn't check debug format (timed out)."
1196 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
1197 # COFF, stabs, etc). If that format matches the format that the
1198 # current test was compiled with, then the next test is expected to
1199 # fail for any target. Returns 1 if the next test or set of tests is
1200 # expected to fail, 0 otherwise (or if it is unknown). Must have
1201 # previously called get_debug_format.
1203 proc setup_xfail_format { format } {
1206 if [string match $debug_format $format] then {
1213 proc gdb_step_for_stub { } {
1216 if ![target_info exists gdb,use_breakpoint_for_stub] {
1217 if [target_info exists gdb_stub_step_command] {
1218 set command [target_info gdb_stub_step_command];
1222 send_gdb "${command}\n";
1225 -re "(main.* at |.*in .*start).*$gdb_prompt" {
1228 -re ".*$gdb_prompt" {
1230 if { $tries == 5 } {
1231 fail "stepping out of breakpoint function";
1234 send_gdb "${command}\n";
1238 fail "stepping out of breakpoint function";
1245 -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" {
1246 set file $expect_out(1,string);
1247 set linenum [expr $expect_out(2,string) + 1];
1248 set breakplace "${file}:${linenum}";
1252 send_gdb "break ${breakplace}\n";
1254 -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" {
1255 set breakpoint $expect_out(1,string);
1257 -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" {
1258 set breakpoint $expect_out(1,string);
1262 send_gdb "continue\n";
1264 -re "Breakpoint ${breakpoint},.*$gdb_prompt" {
1265 gdb_test "delete $breakpoint" ".*" "";
1272 ### gdb_get_line_number TEXT [FILE]
1274 ### Search the source file FILE, and return the line number of a line
1275 ### containing TEXT. Use this function instead of hard-coding line
1276 ### numbers into your test script.
1278 ### Specifically, this function uses GDB's "search" command to search
1279 ### FILE for the first line containing TEXT, and returns its line
1280 ### number. Thus, FILE must be a source file, compiled into the
1281 ### executable you are running. If omitted, FILE defaults to the
1282 ### value of the global variable `srcfile'; most test scripts set
1283 ### `srcfile' appropriately at the top anyway.
1285 ### Use this function to keep your test scripts independent of the
1286 ### exact line numbering of the source file. Don't write:
1288 ### send_gdb "break 20"
1290 ### This means that if anyone ever edits your test's source file,
1291 ### your test could break. Instead, put a comment like this on the
1292 ### source file line you want to break at:
1294 ### /* breakpoint spot: frotz.exp: test name */
1296 ### and then write, in your test script (which we assume is named
1299 ### send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
1301 ### (Yes, Tcl knows how to handle the nested quotes and brackets.
1304 ### % puts "foo [lindex "bar baz" 1]"
1307 ### Tcl is quite clever, for a little stringy language.)
1309 proc gdb_get_line_number {text {file /omitted/}} {
1313 if {! [string compare $file /omitted/]} {
1318 gdb_test "list ${file}:1,1" ".*" ""
1319 send_gdb "search ${text}\n"
1321 -re "\[\r\n\]+(\[0-9\]+)\[ \t\].*${text}.*$gdb_prompt $" {
1322 set result $expect_out(1,string)
1324 -re ".*$gdb_prompt $" {
1325 fail "find line number containing \"${text}\""
1328 fail "find line number containing \"${text}\" (timeout)"