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 # we need a larger timeout value here or this thing just confuses
135 # itself. May need a better implementation if possible. - guo
137 send_gdb "delete breakpoints\n"
139 -re "Delete all breakpoints.*y or n.*$" {
143 -re "$gdb_prompt $" { # This happens if there were no breakpoints
145 timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
147 send_gdb "info breakpoints\n"
149 -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
150 -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
151 -re "Delete all breakpoints.*or n.*$" {
155 timeout { perror "info breakpoints (timeout)" ; return }
161 # Generic run command.
163 # The second pattern below matches up to the first newline *only*.
164 # Using ``.*$'' could swallow up output that we attempt to match
167 proc gdb_run_cmd {args} {
170 if [target_info exists gdb_init_command] {
171 send_gdb "[target_info gdb_init_command]\n";
173 -re "$gdb_prompt $" { }
175 perror "gdb_init_command for target failed";
181 if [target_info exists use_gdb_stub] {
182 if [target_info exists gdb,do_reload_on_run] {
183 # Specifying no file, defaults to the executable
184 # currently being debugged.
185 if { [gdb_load ""] < 0 } {
188 send_gdb "continue\n";
190 -re "Continu\[^\r\n\]*\[\r\n\]" {}
196 if [target_info exists gdb,start_symbol] {
197 set start [target_info gdb,start_symbol];
201 send_gdb "jump *$start\n"
203 while { $start_attempt } {
204 # Cap (re)start attempts at three to ensure that this loop
205 # always eventually fails. Don't worry about trying to be
206 # clever and not send a command when it has failed.
207 if [expr $start_attempt > 3] {
208 perror "Jump to start() failed (retry count exceeded)";
211 set start_attempt [expr $start_attempt + 1];
213 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
216 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
217 perror "Can't find start symbol to run in gdb_run";
220 -re "No symbol \"start\" in current.*$gdb_prompt $" {
221 send_gdb "jump *_start\n";
223 -re "No symbol.*context.*$gdb_prompt $" {
226 -re "Line.* Jump anyway.*y or n. $" {
229 -re "The program is not being run.*$gdb_prompt $" {
230 if { [gdb_load ""] < 0 } {
233 send_gdb "jump *$start\n";
236 perror "Jump to start() failed (timeout)";
241 if [target_info exists gdb_stub] {
243 -re "$gdb_prompt $" {
244 send_gdb "continue\n"
250 send_gdb "run $args\n"
251 # This doesn't work quite right yet.
253 -re "The program .* has been started already.*y or n. $" {
257 -re "Starting program: \[^\r\n\]*" {}
261 proc gdb_breakpoint { function } {
265 send_gdb "break $function\n"
266 # The first two regexps are what we get with -g, the third is without -g.
268 -re "Breakpoint \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
269 -re "Breakpoint \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
270 -re "Breakpoint \[0-9\]* at .*$gdb_prompt $" {}
271 -re "$gdb_prompt $" { fail "setting breakpoint at $function" ; return 0 }
272 timeout { fail "setting breakpoint at $function (timeout)" ; return 0 }
277 # Set breakpoint at function and run gdb until it breaks there.
278 # Since this is the only breakpoint that will be set, if it stops
279 # at a breakpoint, we will assume it is the one we want. We can't
280 # just compare to "function" because it might be a fully qualified,
281 # single quoted C++ function specifier.
283 proc runto { function } {
289 if ![gdb_breakpoint $function] {
295 # the "at foo.c:36" output we get with -g.
296 # the "in func" output we get without -g.
298 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
301 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
304 -re "$gdb_prompt $" {
305 fail "running to $function in runto"
309 fail "running to $function in runto (timeout)"
317 # runto_main -- ask gdb to run until we hit a breakpoint at main.
318 # The case where the target uses stubs has to be handled
319 # specially--if it uses stubs, assuming we hit
320 # breakpoint() and just step out of the function.
322 proc runto_main { } {
326 if ![target_info exists gdb_stub] {
338 ### Continue, and expect to hit a breakpoint.
339 ### Report a pass or fail, depending on whether it seems to have
340 ### worked. Use NAME as part of the test name; each call to
341 ### continue_to_breakpoint should use a NAME which is unique within
343 proc gdb_continue_to_breakpoint {name} {
345 set full_name "continue to breakpoint: $name"
347 send_gdb "continue\n"
349 -re "Breakpoint .* at .*\r\n$gdb_prompt $" {
352 -re ".*$gdb_prompt $" {
356 fail "$full_name (timeout)"
363 # gdb_test COMMAND PATTERN MESSAGE -- send a command to gdb; test the result.
365 # COMMAND is the command to execute, send to GDB with send_gdb. If
366 # this is the null string no command is sent.
367 # PATTERN is the pattern to match for a PASS, and must NOT include
368 # the \r\n sequence immediately before the gdb prompt.
369 # MESSAGE is an optional message to be printed. If this is
370 # omitted, then the pass/fail messages use the command string as the
371 # message. (If this is the empty string, then sometimes we don't
372 # call pass or fail at all; I don't understand this at all.)
375 # 1 if the test failed,
376 # 0 if the test passes,
377 # -1 if there was an internal error.
379 proc gdb_test { args } {
383 upvar timeout timeout
385 if [llength $args]>2 then {
386 set message [lindex $args 2]
388 set message [lindex $args 0]
390 set command [lindex $args 0]
391 set pattern [lindex $args 1]
393 if [llength $args]==5 {
394 set question_string [lindex $args 3];
395 set response_string [lindex $args 4];
397 set question_string "^FOOBAR$"
401 send_user "Sending \"$command\" to gdb\n"
402 send_user "Looking to match \"$pattern\"\n"
403 send_user "Message is \"$message\"\n"
407 set string "${command}\n";
408 if { $command != "" } {
409 while { "$string" != "" } {
410 set foo [string first "\n" "$string"];
411 set len [string length "$string"];
412 if { $foo < [expr $len - 1] } {
413 set str [string range "$string" 0 $foo];
414 if { [send_gdb "$str"] != "" } {
415 global suppress_flag;
417 if { ! $suppress_flag } {
418 perror "Couldn't send $command to GDB.";
423 # since we're checking if each line of the multi-line
424 # command are 'accepted' by GDB here,
425 # we need to set -notransfer expect option so that
426 # command output is not lost for pattern matching
428 gdb_expect -notransfer 2 {
432 set string [string range "$string" [expr $foo + 1] end];
437 if { "$string" != "" } {
438 if { [send_gdb "$string"] != "" } {
439 global suppress_flag;
441 if { ! $suppress_flag } {
442 perror "Couldn't send $command to GDB.";
450 if [info exists timeout] {
454 if [info exists timeout] {
461 -re "\\*\\*\\* DOSEXIT code.*" {
462 if { $message != "" } {
465 gdb_suppress_entire_file "GDB died";
468 -re "Ending remote debugging.*$gdb_prompt $" {
469 if ![isnative] then {
470 warning "Can`t communicate to remote target."
476 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
477 if ![string match "" $message] then {
482 -re "(${question_string})$" {
483 send_gdb "$response_string\n";
486 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
487 perror "Undefined command \"$command\"."
491 -re "Ambiguous command.*$gdb_prompt $" {
492 perror "\"$command\" is not a unique command name."
496 -re "Program exited with code \[0-9\]+.*$gdb_prompt $" {
497 if ![string match "" $message] then {
498 set errmsg "$message: the program exited"
500 set errmsg "$command: the program exited"
505 -re "The program is not being run.*$gdb_prompt $" {
506 if ![string match "" $message] then {
507 set errmsg "$message: the program is no longer running"
509 set errmsg "$command: the program is no longer running"
514 -re ".*$gdb_prompt $" {
515 if ![string match "" $message] then {
522 perror "Window too small."
525 -re "\\(y or n\\) " {
527 perror "Got interactive prompt."
531 perror "Process no longer exists"
532 if { $message != "" } {
538 perror "internal buffer is full."
542 if ![string match "" $message] then {
543 fail "$message (timeout)"
551 # Test that a command gives an error. For pass or fail, return
552 # a 1 to indicate that more tests can proceed. However a timeout
553 # is a serious error, generates a special fail message, and causes
554 # a 0 to be returned to indicate that more tests are likely to fail
557 proc test_print_reject { args } {
561 if [llength $args]==2 then {
562 set expectthis [lindex $args 1]
564 set expectthis "should never match this bogus string"
566 set sendthis [lindex $args 0]
568 send_user "Sending \"$sendthis\" to gdb\n"
569 send_user "Looking to match \"$expectthis\"\n"
571 send_gdb "$sendthis\n"
572 #FIXME: Should add timeout as parameter.
574 -re "A .* in expression.*\\.*$gdb_prompt $" {
575 pass "reject $sendthis"
578 -re "Invalid syntax in expression.*$gdb_prompt $" {
579 pass "reject $sendthis"
582 -re "Junk after end of expression.*$gdb_prompt $" {
583 pass "reject $sendthis"
586 -re "Invalid number.*$gdb_prompt $" {
587 pass "reject $sendthis"
590 -re "Invalid character constant.*$gdb_prompt $" {
591 pass "reject $sendthis"
594 -re "No symbol table is loaded.*$gdb_prompt $" {
595 pass "reject $sendthis"
598 -re "No symbol .* in current context.*$gdb_prompt $" {
599 pass "reject $sendthis"
602 -re "$expectthis.*$gdb_prompt $" {
603 pass "reject $sendthis"
606 -re ".*$gdb_prompt $" {
607 fail "reject $sendthis"
611 fail "reject $sendthis (eof or timeout)"
617 # Given an input string, adds backslashes as needed to create a
618 # regexp that will match the string.
620 proc string_to_regexp {str} {
622 regsub -all {[]*+.|()^$\[]} $str {\\&} result
626 # Same as gdb_test, but the second parameter is not a regexp,
627 # but a string that must match exactly.
629 proc gdb_test_exact { args } {
630 upvar timeout timeout
632 set command [lindex $args 0]
634 # This applies a special meaning to a null string pattern. Without
635 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
636 # messages from commands that should have no output except a new
637 # prompt. With this, only results of a null string will match a null
640 set pattern [lindex $args 1]
641 if [string match $pattern ""] {
642 set pattern [string_to_regexp [lindex $args 0]]
644 set pattern [string_to_regexp [lindex $args 1]]
647 # It is most natural to write the pattern argument with only
648 # embedded \n's, especially if you are trying to avoid Tcl quoting
649 # problems. But gdb_expect really wants to see \r\n in patterns. So
650 # transform the pattern here. First transform \r\n back to \n, in
651 # case some users of gdb_test_exact already do the right thing.
652 regsub -all "\r\n" $pattern "\n" pattern
653 regsub -all "\n" $pattern "\r\n" pattern
654 if [llength $args]==3 then {
655 set message [lindex $args 2]
660 return [gdb_test $command $pattern $message]
663 proc gdb_reinitialize_dir { subdir } {
666 if [is_remote host] {
671 -re "Reinitialize source path to empty.*y or n. " {
674 -re "Source directories searched.*$gdb_prompt $" {
675 send_gdb "dir $subdir\n"
677 -re "Source directories searched.*$gdb_prompt $" {
678 verbose "Dir set to $subdir"
680 -re "$gdb_prompt $" {
681 perror "Dir \"$subdir\" failed."
685 -re "$gdb_prompt $" {
686 perror "Dir \"$subdir\" failed."
690 -re "$gdb_prompt $" {
691 perror "Dir \"$subdir\" failed."
697 # gdb_exit -- exit the GDB, killing the target program if necessary
699 proc default_gdb_exit {} {
705 gdb_stop_suppressing_tests;
707 if ![info exists gdb_spawn_id] {
711 verbose "Quitting $GDB $GDBFLAGS"
713 if { [is_remote host] && [board_info host exists fileid] } {
720 -re "DOSEXIT code" { }
725 if ![is_remote host] {
732 # load a file into the debugger.
733 # return a -1 if anything goes wrong.
735 proc gdb_file_cmd { arg } {
741 upvar timeout timeout
743 if [is_remote host] {
744 set arg [remote_download host $arg];
746 error "download failed"
751 send_gdb "file $arg\n"
753 -re "Reading symbols from.*done.*$gdb_prompt $" {
754 verbose "\t\tLoaded $arg into the $GDB"
757 -re "has no symbol-table.*$gdb_prompt $" {
758 perror "$arg wasn't compiled with \"-g\""
761 -re "A program is being debugged already.*Kill it.*y or n. $" {
763 verbose "\t\tKilling previous program being debugged"
766 -re "Load new symbol table from \".*\".*y or n. $" {
769 -re "Reading symbols from.*done.*$gdb_prompt $" {
770 verbose "\t\tLoaded $arg with new symbol table into $GDB"
774 perror "(timeout) Couldn't load $arg, other program already loaded."
779 -re "No such file or directory.*$gdb_prompt $" {
780 perror "($arg) No such file or directory\n"
783 -re "$gdb_prompt $" {
784 perror "couldn't load $arg into $GDB."
788 perror "couldn't load $arg into $GDB (timed out)."
792 # This is an attempt to detect a core dump, but seems not to
793 # work. Perhaps we need to match .* followed by eof, in which
794 # gdb_expect does not seem to have a way to do that.
795 perror "couldn't load $arg into $GDB (end of file)."
802 # start gdb -- start gdb running, default procedure
804 # When running over NFS, particularly if running many simultaneous
805 # tests on different hosts all using the same server, things can
806 # get really slow. Give gdb at least 3 minutes to start up.
808 proc default_gdb_start { } {
816 gdb_stop_suppressing_tests;
818 verbose "Spawning $GDB -nw $GDBFLAGS"
820 if [info exists gdb_spawn_id] {
824 if ![is_remote host] {
825 if { [which $GDB] == 0 } then {
826 perror "$GDB does not exist."
830 set res [remote_spawn host "$GDB -nw $GDBFLAGS [host_info gdb_opts]"];
831 if { $res < 0 || $res == "" } {
832 perror "Spawning $GDB failed."
836 -re "\[\r\n\]$gdb_prompt $" {
837 verbose "GDB initialized."
839 -re "$gdb_prompt $" {
840 perror "GDB never initialized."
844 perror "(timeout) GDB never initialized after 10 seconds."
850 # force the height to "unlimited", so no pagers get used
852 send_gdb "set height 0\n"
854 -re "$gdb_prompt $" {
855 verbose "Setting height to 0." 2
858 warning "Couldn't set the height to 0"
861 # force the width to "unlimited", so no wraparound occurs
862 send_gdb "set width 0\n"
864 -re "$gdb_prompt $" {
865 verbose "Setting width to 0." 2
868 warning "Couldn't set the width to 0."
874 # Return a 1 for configurations for which we don't even want to try to
877 proc skip_cplus_tests {} {
878 if { [istarget "d10v-*-*"] } {
881 if { [istarget "h8300-*-*"] } {
887 # * For crosses, the CHILL runtime doesn't build because it can't find
888 # setjmp.h, stdio.h, etc.
889 # * For AIX (as of 16 Mar 95), (a) there is no language code for
890 # CHILL in output_epilog in gcc/config/rs6000/rs6000.c, (b) collect2
891 # does not get along with AIX's too-clever linker.
892 # * On Irix5, there is a bug whereby set of bool, etc., don't get
893 # TYPE_LOW_BOUND for the bool right because force_to_range_type doesn't
894 # work with stub types.
895 # Lots of things seem to fail on the PA, and since it's not a supported
896 # chill target at the moment, don't run the chill tests.
898 proc skip_chill_tests {} {
899 if ![info exists do_chill_tests] {
902 eval set skip_chill [expr ![isnative] || [istarget "*-*-aix*"] || [istarget "*-*-irix5*"] || [istarget "*-*-irix6*"] || [istarget "alpha-*-osf*"] || [istarget "hppa*-*-*"]]
903 verbose "Skip chill tests is $skip_chill"
907 # Skip all the tests in the file if you are not on an hppa running
910 proc skip_hp_tests {} {
911 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
912 verbose "Skip hp tests is $skip_hp"
916 proc get_compiler_info {binfile args} {
917 # Create and source the file that provides information about the compiler
918 # used to compile the test case.
919 # Compiler_type can be null or c++. If null we assume c.
922 # These two come from compiler.c.
923 global signed_keyword_not_used
926 if {![istarget "hppa*-*-hpux*"]} {
927 if { [llength $args] > 0 } {
928 if {$args == "c++"} {
929 if { [gdb_compile "${srcdir}/lib/compiler.cc" "${binfile}.ci" preprocess {}] != "" } {
930 perror "Couldn't make ${binfile}.ci file"
935 if { [gdb_compile "${srcdir}/lib/compiler.c" "${binfile}.ci" preprocess {}] != "" } {
936 perror "Couldn't make ${binfile}.ci file"
941 if { [llength $args] > 0 } {
942 if {$args == "c++"} {
943 if { [eval gdb_preprocess \
944 [list "${srcdir}/lib/compiler.cc" "${binfile}.ci"] \
946 perror "Couldn't make ${binfile}.ci file"
950 } elseif { $args != "f77" } {
951 if { [eval gdb_preprocess \
952 [list "${srcdir}/lib/compiler.c" "${binfile}.ci"] \
954 perror "Couldn't make ${binfile}.ci file"
960 uplevel \#0 { set gcc_compiled 0 }
962 if { [llength $args] == 0 || $args != "f77" } {
966 # Most compilers will evaluate comparisons and other boolean
967 # operations to 0 or 1.
968 uplevel \#0 { set true 1 }
969 uplevel \#0 { set false 0 }
971 uplevel \#0 { set hp_cc_compiler 0 }
972 uplevel \#0 { set hp_aCC_compiler 0 }
973 uplevel \#0 { set hp_f77_compiler 0 }
974 uplevel \#0 { set hp_f90_compiler 0 }
975 if { !$gcc_compiled && [istarget "hppa*-*-hpux*"] } {
976 # Check for the HP compilers
977 set compiler [lindex [split [get_compiler $args] " "] 0]
978 catch "exec what $compiler" output
979 if [regexp ".*HP aC\\+\\+.*" $output] {
980 uplevel \#0 { set hp_aCC_compiler 1 }
981 # Use of aCC results in boolean results being displayed as
983 uplevel \#0 { set true true }
984 uplevel \#0 { set false false }
985 } elseif [regexp ".*HP C Compiler.*" $output] {
986 uplevel \#0 { set hp_cc_compiler 1 }
987 } elseif [regexp ".*HP-UX f77.*" $output] {
988 uplevel \#0 { set hp_f77_compiler 1 }
989 } elseif [regexp ".*HP-UX f90.*" $output] {
990 uplevel \#0 { set hp_f90_compiler 1 }
997 proc get_compiler {args} {
998 global CC CC_FOR_TARGET CXX CXX_FOR_TARGET F77_FOR_TARGET
1000 if { [llength $args] == 0
1001 || ([llength $args] == 1 && [lindex $args 0] == "") } {
1002 set which_compiler "c"
1004 if { $args =="c++" } {
1005 set which_compiler "c++"
1006 } elseif { $args =="f77" } {
1007 set which_compiler "f77"
1009 perror "Unknown compiler type supplied to gdb_preprocess"
1014 if [info exists CC_FOR_TARGET] {
1015 if {$which_compiler == "c"} {
1016 set compiler $CC_FOR_TARGET
1020 if [info exists CXX_FOR_TARGET] {
1021 if {$which_compiler == "c++"} {
1022 set compiler $CXX_FOR_TARGET
1026 if [info exists F77_FOR_TARGET] {
1027 if {$which_compiler == "f77"} {
1028 set compiler $F77_FOR_TARGET
1032 if { ![info exists compiler] } {
1033 if { $which_compiler == "c" } {
1034 if {[info exists CC]} {
1038 if { $which_compiler == "c++" } {
1039 if {[info exists CXX]} {
1043 if {![info exists compiler]} {
1044 set compiler [board_info [target_info name] compiler];
1045 if { $compiler == "" } {
1046 perror "get_compiler: No compiler found"
1055 proc gdb_preprocess {source dest args} {
1056 set compiler [get_compiler "$args"]
1057 if { $compiler == "" } {
1061 set cmdline "$compiler -E $source > $dest"
1063 verbose "Invoking $compiler -E $source > $dest"
1064 verbose -log "Executing on local host: $cmdline" 2
1065 set status [catch "exec ${cmdline}" exec_output]
1067 set result [prune_warnings $exec_output]
1068 regsub "\[\r\n\]*$" "$result" "" result;
1069 regsub "^\[\r\n\]*" "$result" "" result;
1070 if { $result != "" } {
1071 clone_output "gdb compile failed, $result"
1076 proc gdb_compile {source dest type options} {
1077 global GDB_TESTCASE_OPTIONS;
1079 if [target_info exists gdb_stub] {
1080 set options2 { "additional_flags=-Dusestubs" }
1081 lappend options "libs=[target_info gdb_stub]";
1082 set options [concat $options2 $options]
1084 if [target_info exists is_vxworks] {
1085 set options2 { "additional_flags=-Dvxworks" }
1086 lappend options "libs=[target_info gdb_stub]";
1087 set options [concat $options2 $options]
1089 if [info exists GDB_TESTCASE_OPTIONS] {
1090 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
1092 verbose "options are $options"
1093 verbose "source is $source $dest $type $options"
1095 set result [target_compile $source $dest $type $options];
1096 regsub "\[\r\n\]*$" "$result" "" result;
1097 regsub "^\[\r\n\]*" "$result" "" result;
1098 if { $result != "" } {
1099 clone_output "gdb compile failed, $result"
1104 proc send_gdb { string } {
1105 global suppress_flag;
1106 if { $suppress_flag } {
1107 return "suppressed";
1109 return [remote_send host "$string"];
1115 proc gdb_expect { args } {
1116 # allow -notransfer expect flag specification,
1117 # used by gdb_test routine for multi-line commands.
1118 # packed with gtimeout when fed to remote_expect routine,
1119 # which is a hack but due to what looks like a res and orig
1120 # parsing problem in remote_expect routine (dejagnu/lib/remote.exp):
1121 # what's fed into res is not removed from orig.
1123 if { [lindex $args 0] == "-notransfer" } {
1124 set notransfer -notransfer;
1125 set args [lrange $args 1 end];
1130 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
1131 set gtimeout [lindex $args 0];
1132 set expcode [list [lindex $args 1]];
1134 upvar timeout timeout;
1137 if [target_info exists gdb,timeout] {
1138 if [info exists timeout] {
1139 if { $timeout < [target_info gdb,timeout] } {
1140 set gtimeout [target_info gdb,timeout];
1142 set gtimeout $timeout;
1145 set gtimeout [target_info gdb,timeout];
1149 if ![info exists gtimeout] {
1151 if [info exists timeout] {
1152 set gtimeout $timeout;
1159 global suppress_flag;
1160 global remote_suppress_flag;
1161 if [info exists remote_suppress_flag] {
1162 set old_val $remote_suppress_flag;
1164 if [info exists suppress_flag] {
1165 if { $suppress_flag } {
1166 set remote_suppress_flag 1;
1170 {uplevel remote_expect host "$gtimeout $notransfer" $expcode} string];
1171 if [info exists old_val] {
1172 set remote_suppress_flag $old_val;
1174 if [info exists remote_suppress_flag] {
1175 unset remote_suppress_flag;
1180 global errorInfo errorCode;
1182 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
1183 } elseif {$code == 2} {
1184 return -code return $string
1185 } elseif {$code == 3} {
1187 } elseif {$code > 4} {
1188 return -code $code $string
1192 # gdb_expect_list MESSAGE SENTINEL LIST -- expect a sequence of outputs
1194 # Check for long sequence of output by parts.
1195 # MESSAGE: is the test message to be printed with the test success/fail.
1196 # SENTINEL: Is the terminal pattern indicating that output has finished.
1197 # LIST: is the sequence of outputs to match.
1198 # If the sentinel is recognized early, it is considered an error.
1201 # 1 if the test failed,
1202 # 0 if the test passes,
1203 # -1 if there was an internal error.
1205 proc gdb_expect_list {test sentinel list} {
1207 global suppress_flag
1210 if { $suppress_flag } {
1213 while { ${index} < [llength ${list}] } {
1214 set pattern [lindex ${list} ${index}]
1215 set index [expr ${index} + 1]
1216 if { ${index} == [llength ${list}] } {
1219 -re "${pattern}${sentinel}" {
1220 pass "${test}, pattern ${index} + sentinel"
1223 fail "${test}, pattern ${index} + sentinel"
1227 fail "${test}, pattern ${index} + sentinel (timeout)"
1232 unresolved "${test}, pattern ${index} + sentinel"
1238 pass "${test}, pattern ${index}"
1241 fail "${test}, pattern ${index}"
1245 fail "${test}, pattern ${index} (timeout)"
1250 unresolved "${test}, pattern ${index}"
1263 proc gdb_suppress_entire_file { reason } {
1264 global suppress_flag;
1266 warning "$reason\n";
1267 set suppress_flag -1;
1271 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
1272 # gdb_expect to fail immediately (until the next call to
1273 # gdb_stop_suppressing_tests).
1275 proc gdb_suppress_tests { args } {
1276 global suppress_flag;
1278 return; # fnf - disable pending review of results where
1279 # testsuite ran better without this
1282 if { $suppress_flag == 1 } {
1283 if { [llength $args] > 0 } {
1284 warning "[lindex $args 0]\n";
1286 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
1292 # Clear suppress_flag.
1294 proc gdb_stop_suppressing_tests { } {
1295 global suppress_flag;
1297 if [info exists suppress_flag] {
1298 if { $suppress_flag > 0 } {
1299 set suppress_flag 0;
1300 clone_output "Tests restarted.\n";
1303 set suppress_flag 0;
1307 proc gdb_clear_suppressed { } {
1308 global suppress_flag;
1310 set suppress_flag 0;
1313 proc gdb_start { } {
1318 catch default_gdb_exit
1322 # gdb_load -- load a file into the debugger.
1323 # return a -1 if anything goes wrong.
1325 proc gdb_load { arg } {
1326 return [gdb_file_cmd $arg]
1329 proc gdb_continue { function } {
1332 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
1335 proc default_gdb_init { args } {
1336 gdb_clear_suppressed;
1338 # Uh, this is lame. Really, really, really lame. But there's this *one*
1339 # testcase that will fail in random places if we don't increase this.
1342 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
1343 if { [llength $args] > 0 } {
1346 set file [lindex $args 0];
1348 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
1351 if [target_info exists gdb_prompt] {
1352 set gdb_prompt [target_info gdb_prompt];
1354 set gdb_prompt "\\(gdb\\)"
1358 proc gdb_init { args } {
1359 return [eval default_gdb_init $args];
1362 proc gdb_finish { } {
1367 set debug_format "unknown"
1369 # Run the gdb command "info source" and extract the debugging format
1370 # information from the output and save it in debug_format.
1372 proc get_debug_format { } {
1378 set debug_format "unknown"
1379 send_gdb "info source\n"
1381 -re "Compiled with (.*) debugging format.\r\n$gdb_prompt $" {
1382 set debug_format $expect_out(1,string)
1383 verbose "debug format is $debug_format"
1386 -re "No current source file.\r\n$gdb_prompt $" {
1387 perror "get_debug_format used when no current source file"
1390 -re "$gdb_prompt $" {
1391 warning "couldn't check debug format (no valid response)."
1395 warning "couldn't check debug format (timed out)."
1401 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
1402 # COFF, stabs, etc). If that format matches the format that the
1403 # current test was compiled with, then the next test is expected to
1404 # fail for any target. Returns 1 if the next test or set of tests is
1405 # expected to fail, 0 otherwise (or if it is unknown). Must have
1406 # previously called get_debug_format.
1408 proc setup_xfail_format { format } {
1411 if [string match $debug_format $format] then {
1418 proc gdb_step_for_stub { } {
1421 if ![target_info exists gdb,use_breakpoint_for_stub] {
1422 if [target_info exists gdb_stub_step_command] {
1423 set command [target_info gdb_stub_step_command];
1427 send_gdb "${command}\n";
1430 -re "(main.* at |.*in .*start).*$gdb_prompt" {
1433 -re ".*$gdb_prompt" {
1435 if { $tries == 5 } {
1436 fail "stepping out of breakpoint function";
1439 send_gdb "${command}\n";
1443 fail "stepping out of breakpoint function";
1450 -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" {
1451 set file $expect_out(1,string);
1452 set linenum [expr $expect_out(2,string) + 1];
1453 set breakplace "${file}:${linenum}";
1457 send_gdb "break ${breakplace}\n";
1459 -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" {
1460 set breakpoint $expect_out(1,string);
1462 -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" {
1463 set breakpoint $expect_out(1,string);
1467 send_gdb "continue\n";
1469 -re "Breakpoint ${breakpoint},.*$gdb_prompt" {
1470 gdb_test "delete $breakpoint" ".*" "";
1477 ### gdb_get_line_number TEXT [FILE]
1479 ### Search the source file FILE, and return the line number of a line
1480 ### containing TEXT. Use this function instead of hard-coding line
1481 ### numbers into your test script.
1483 ### Specifically, this function uses GDB's "search" command to search
1484 ### FILE for the first line containing TEXT, and returns its line
1485 ### number. Thus, FILE must be a source file, compiled into the
1486 ### executable you are running. If omitted, FILE defaults to the
1487 ### value of the global variable `srcfile'; most test scripts set
1488 ### `srcfile' appropriately at the top anyway.
1490 ### Use this function to keep your test scripts independent of the
1491 ### exact line numbering of the source file. Don't write:
1493 ### send_gdb "break 20"
1495 ### This means that if anyone ever edits your test's source file,
1496 ### your test could break. Instead, put a comment like this on the
1497 ### source file line you want to break at:
1499 ### /* breakpoint spot: frotz.exp: test name */
1501 ### and then write, in your test script (which we assume is named
1504 ### send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
1506 ### (Yes, Tcl knows how to handle the nested quotes and brackets.
1509 ### % puts "foo [lindex "bar baz" 1]"
1512 ### Tcl is quite clever, for a little stringy language.)
1514 proc gdb_get_line_number {text {file /omitted/}} {
1518 if {! [string compare $file /omitted/]} {
1523 gdb_test "list ${file}:1,1" ".*" ""
1524 send_gdb "search ${text}\n"
1526 -re "\[\r\n\]+(\[0-9\]+)\[ \t\].*${text}.*$gdb_prompt $" {
1527 set result $expect_out(1,string)
1529 -re ".*$gdb_prompt $" {
1530 fail "find line number containing \"${text}\""
1533 fail "find line number containing \"${text}\" (timeout)"
1539 # gdb_continue_to_end:
1540 # The case where the target uses stubs has to be handled specially. If a
1541 # stub is used, we set a breakpoint at exit because we cannot rely on
1542 # exit() behavior of a remote target.
1544 # mssg is the error message that gets printed.
1546 proc gdb_continue_to_end {mssg} {
1547 if [target_info exists use_gdb_stub] {
1548 if {![gdb_breakpoint "exit"]} {
1551 gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \
1552 "continue until exit at $mssg"
1554 # Continue until we exit. Should not stop again.
1555 # Don't bother to check the output of the program, that may be
1556 # extremely tough for some remote systems.
1557 gdb_test "continue"\
1558 "Continuing.\[\r\n0-9\]+Program exited normally\\..*"\
1559 "continue until exit at $mssg"
1563 proc rerun_to_main {} {
1566 if [target_info exists use_gdb_stub] {
1569 -re ".*Breakpoint .*main .*$gdb_prompt $"\
1570 {pass "rerun to main" ; return 0}
1571 -re "$gdb_prompt $"\
1572 {fail "rerun to main" ; return 0}
1573 timeout {fail "(timeout) rerun to main" ; return 0}
1578 -re "Starting program.*$gdb_prompt $"\
1579 {pass "rerun to main" ; return 0}
1580 -re "$gdb_prompt $"\
1581 {fail "rerun to main" ; return 0}
1582 timeout {fail "(timeout) rerun to main" ; return 0}
1588 # srcdir = testsuite src dir (e.g., devo/gdb/testsuite)
1589 # objdir = testsuite obj dir (e.g., gdb/testsuite)
1590 # subdir = subdir of testsuite (e.g., gdb.gdbtk)
1593 # env(DEFS)=the "defs" files (e.g., devo/gdb/testsuite/gdb.gdbtk/defs)
1594 # env(SRCDIR)=directory containing the test code (e.g., *.test)
1595 # env(OBJDIR)=directory which contains any executables
1596 # (e.g., gdb/testsuite/gdb.gdbtk)
1597 proc gdbtk_start {test} {
1601 global env srcdir subdir objdir
1603 gdb_stop_suppressing_tests;
1605 verbose "Starting $GDB -nx -q --tclcommand=$test"
1607 set real_test [which $test]
1608 if {$real_test == 0} {
1609 perror "$test is not found"
1613 if {![is_remote host]} {
1614 if { [which $GDB] == 0 } {
1615 perror "$GDB does not exist."
1621 cd [file join $srcdir .. gdbtcl2]
1622 set env(GDBTK_LIBRARY) [pwd]
1623 cd [file join $srcdir .. .. tcl library]
1624 set env(TCL_LIBRARY) [pwd]
1625 cd [file join $srcdir .. .. tk library]
1626 set env(TK_LIBRARY) [pwd]
1627 cd [file join $srcdir .. .. tix library]
1628 set env(TIX_LIBRARY) [pwd]
1629 cd [file join $srcdir .. .. itcl itcl library]
1630 set env(ITCL_LIBRARY) [pwd]
1631 cd [file join .. $srcdir .. .. libgui library]
1632 set env(CYGNUS_GUI_LIBRARY) [pwd]
1634 cd [file join $srcdir $subdir]
1635 set env(DEFS) [file join [pwd] defs]
1637 cd [file join $objdir $subdir]
1638 set env(OBJDIR) [pwd]
1641 set env(SRCDIR) [pwd]
1643 set env(GDBTK_VERBOSE) 1
1644 set env(GDBTK_LOGFILE) [file join $objdir gdb.log]
1645 set env(GDBTK_TEST_RUNNING) 1
1646 set err [catch {exec $GDB -nx -q --tclcommand=$test} res]
1648 perror "Execing $GDB failed: $res"
1654 # gdbtk tests call this function to print out the results of the
1655 # tests. The argument is a proper list of lists of the form:
1656 # {status name description msg}. All of these things typically
1657 # come from the testsuite harness.
1658 proc gdbtk_analyze_results {results} {
1659 foreach test $results {
1660 set status [lindex $test 0]
1661 set name [lindex $test 1]
1662 set description [lindex $test 2]
1663 set msg [lindex $test 3]
1667 pass "$description ($name)"
1671 fail "$description ($name)"
1679 xfail "$description ($name)"
1683 xpass "$description ($name)"