1 # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3 # Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 # Please email any bugs, comments, and/or additions to this file to:
20 # bug-gdb@prep.ai.mit.edu
22 # This file was written by Fred Fish. (fnf@cygnus.com)
24 # Generic gdb subroutines that should work for any target. If these
25 # need to be modified for any target, it can be done with a variable
26 # or by passing arguments.
32 if [info exists TOOL_EXECUTABLE] {
33 set GDB $TOOL_EXECUTABLE;
35 if ![info exists GDB] {
36 if ![is_remote host] {
37 set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]]
39 set GDB [transform gdb];
42 verbose "using GDB = $GDB" 2
45 if ![info exists GDBFLAGS] {
48 verbose "using GDBFLAGS = $GDBFLAGS" 2
50 # The variable gdb_prompt is a regexp which matches the gdb prompt.
51 # Set it if it is not already set.
53 if ![info exists gdb_prompt] then {
54 set gdb_prompt "\[(\]gdb\[)\]"
57 # Needed for some tests under Cygwin.
61 if ![info exists env(EXEEXT)] {
64 set EXEEXT $env(EXEEXT)
67 ### Only procedures should come after this point.
70 # gdb_version -- extract and print the version number of GDB
72 proc default_gdb_version {} {
76 set fileid [open "gdb_cmd" w];
79 set cmdfile [remote_download host "gdb_cmd"];
80 set output [remote_exec host "$GDB -nw --command $cmdfile"]
81 remote_file build delete "gdb_cmd";
82 remote_file host delete "$cmdfile";
83 set tmp [lindex $output 1];
85 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
86 if ![is_remote host] {
87 clone_output "[which $GDB] version $version $GDBFLAGS\n"
89 clone_output "$GDB on remote host version $version $GDBFLAGS\n"
93 proc gdb_version { } {
94 return [default_gdb_version];
98 # gdb_unload -- unload a file if one is loaded
107 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
108 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
109 -re "A program is being debugged already..*Kill it.*y or n. $"\
111 verbose "\t\tKilling previous program being debugged"
114 -re "Discard symbol table from .*y or n.*$" {
118 -re "$gdb_prompt $" {}
120 perror "couldn't unload file in $GDB (timed out)."
126 # Many of the tests depend on setting breakpoints at various places and
127 # running until that breakpoint is reached. At times, we want to start
128 # with a clean-slate with respect to breakpoints, so this utility proc
129 # lets us do this without duplicating this code everywhere.
132 proc delete_breakpoints {} {
135 # we need a larger timeout value here or this thing just confuses
136 # itself. May need a better implementation if possible. - guo
138 send_gdb "delete breakpoints\n"
140 -re "Delete all breakpoints.*y or n.*$" {
144 -re "$gdb_prompt $" { # This happens if there were no breakpoints
146 timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
148 send_gdb "info breakpoints\n"
150 -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
151 -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
152 -re "Delete all breakpoints.*or n.*$" {
156 timeout { perror "info breakpoints (timeout)" ; return }
162 # Generic run command.
164 # The second pattern below matches up to the first newline *only*.
165 # Using ``.*$'' could swallow up output that we attempt to match
168 proc gdb_run_cmd {args} {
171 if [target_info exists gdb_init_command] {
172 send_gdb "[target_info gdb_init_command]\n";
174 -re "$gdb_prompt $" { }
176 perror "gdb_init_command for target failed";
182 if [target_info exists use_gdb_stub] {
183 if [target_info exists gdb,do_reload_on_run] {
184 # Specifying no file, defaults to the executable
185 # currently being debugged.
186 if { [gdb_load ""] < 0 } {
189 send_gdb "continue\n";
191 -re "Continu\[^\r\n\]*\[\r\n\]" {}
197 if [target_info exists gdb,start_symbol] {
198 set start [target_info gdb,start_symbol];
202 send_gdb "jump *$start\n"
204 while { $start_attempt } {
205 # Cap (re)start attempts at three to ensure that this loop
206 # always eventually fails. Don't worry about trying to be
207 # clever and not send a command when it has failed.
208 if [expr $start_attempt > 3] {
209 perror "Jump to start() failed (retry count exceeded)";
212 set start_attempt [expr $start_attempt + 1];
214 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
217 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
218 perror "Can't find start symbol to run in gdb_run";
221 -re "No symbol \"start\" in current.*$gdb_prompt $" {
222 send_gdb "jump *_start\n";
224 -re "No symbol.*context.*$gdb_prompt $" {
227 -re "Line.* Jump anyway.*y or n. $" {
230 -re "The program is not being run.*$gdb_prompt $" {
231 if { [gdb_load ""] < 0 } {
234 send_gdb "jump *$start\n";
237 perror "Jump to start() failed (timeout)";
242 if [target_info exists gdb_stub] {
244 -re "$gdb_prompt $" {
245 send_gdb "continue\n"
251 send_gdb "run $args\n"
252 # This doesn't work quite right yet.
254 -re "The program .* has been started already.*y or n. $" {
258 -re "Starting program: \[^\r\n\]*" {}
262 proc gdb_breakpoint { function } {
266 send_gdb "break $function\n"
267 # The first two regexps are what we get with -g, the third is without -g.
269 -re "Breakpoint \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
270 -re "Breakpoint \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
271 -re "Breakpoint \[0-9\]* at .*$gdb_prompt $" {}
272 -re "$gdb_prompt $" { fail "setting breakpoint at $function" ; return 0 }
273 timeout { fail "setting breakpoint at $function (timeout)" ; return 0 }
278 # Set breakpoint at function and run gdb until it breaks there.
279 # Since this is the only breakpoint that will be set, if it stops
280 # at a breakpoint, we will assume it is the one we want. We can't
281 # just compare to "function" because it might be a fully qualified,
282 # single quoted C++ function specifier.
284 proc runto { function } {
290 if ![gdb_breakpoint $function] {
296 # the "at foo.c:36" output we get with -g.
297 # the "in func" output we get without -g.
299 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
302 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
305 -re "$gdb_prompt $" {
306 fail "running to $function in runto"
310 fail "running to $function in runto (timeout)"
318 # runto_main -- ask gdb to run until we hit a breakpoint at main.
319 # The case where the target uses stubs has to be handled
320 # specially--if it uses stubs, assuming we hit
321 # breakpoint() and just step out of the function.
323 proc runto_main { } {
327 if ![target_info exists gdb_stub] {
339 ### Continue, and expect to hit a breakpoint.
340 ### Report a pass or fail, depending on whether it seems to have
341 ### worked. Use NAME as part of the test name; each call to
342 ### continue_to_breakpoint should use a NAME which is unique within
344 proc gdb_continue_to_breakpoint {name} {
346 set full_name "continue to breakpoint: $name"
348 send_gdb "continue\n"
350 -re "Breakpoint .* at .*\r\n$gdb_prompt $" {
353 -re ".*$gdb_prompt $" {
357 fail "$full_name (timeout)"
364 # gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS
365 # Send a command to gdb; test the result.
367 # COMMAND is the command to execute, send to GDB with send_gdb. If
368 # this is the null string no command is sent.
369 # MESSAGE is a message to be printed with the built-in failure patterns
370 # if one of them matches. If MESSAGE is empty COMMAND will be used.
371 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
372 # patterns. Pattern elements will be evaluated in the caller's
373 # context; action elements will be executed in the caller's context.
374 # Unlike patterns for gdb_test, these patterns should generally include
375 # the final newline and prompt.
378 # 1 if the test failed, according to a built-in failure pattern
379 # 0 if only user-supplied patterns matched
380 # -1 if there was an internal error.
382 proc gdb_test_multiple { command message user_code } {
386 upvar timeout timeout
388 if { $message == "" } {
392 # TCL/EXPECT WART ALERT
393 # Expect does something very strange when it receives a single braced
394 # argument. It splits it along word separators and performs substitutions.
395 # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
396 # evaluated as "\[ab\]". But that's not how TCL normally works; inside a
397 # double-quoted list item, "\[ab\]" is just a long way of representing
398 # "[ab]", because the backslashes will be removed by lindex.
400 # Unfortunately, there appears to be no easy way to duplicate the splitting
401 # that expect will do from within TCL. And many places make use of the
402 # "\[0-9\]" construct, so we need to support that; and some places make use
403 # of the "[func]" construct, so we need to support that too. In order to
404 # get this right we have to substitute quoted list elements differently
405 # from braced list elements.
407 # We do this roughly the same way that Expect does it. We have to use two
408 # lists, because if we leave unquoted newlines in the argument to uplevel
409 # they'll be treated as command separators, and if we escape newlines
410 # we mangle newlines inside of command blocks. This assumes that the
411 # input doesn't contain a pattern which contains actual embedded newlines
414 regsub -all {\n} ${user_code} { } subst_code
415 set subst_code [uplevel list $subst_code]
417 set processed_code ""
419 set expecting_action 0
420 foreach item $user_code subst_item $subst_code {
421 if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } {
422 lappend processed_code $item
425 if {$item == "-indices" || $item == "-re" || $item == "-ex"} {
426 lappend processed_code $item
429 if { $expecting_action } {
430 lappend processed_code "uplevel [list $item]"
431 set expecting_action 0
432 # Cosmetic, no effect on the list.
433 append processed_code "\n"
436 set expecting_action 1
437 lappend processed_code $subst_item
438 if {$patterns != ""} {
441 append patterns "\"$subst_item\""
444 # Also purely cosmetic.
445 regsub -all {\r} $patterns {\\r} patterns
446 regsub -all {\n} $patterns {\\n} patterns
449 send_user "Sending \"$command\" to gdb\n"
450 send_user "Looking to match \"$patterns\"\n"
451 send_user "Message is \"$message\"\n"
455 set string "${command}\n";
456 if { $command != "" } {
457 while { "$string" != "" } {
458 set foo [string first "\n" "$string"];
459 set len [string length "$string"];
460 if { $foo < [expr $len - 1] } {
461 set str [string range "$string" 0 $foo];
462 if { [send_gdb "$str"] != "" } {
463 global suppress_flag;
465 if { ! $suppress_flag } {
466 perror "Couldn't send $command to GDB.";
471 # since we're checking if each line of the multi-line
472 # command are 'accepted' by GDB here,
473 # we need to set -notransfer expect option so that
474 # command output is not lost for pattern matching
477 -notransfer -re "\[\r\n\]" { verbose "partial: match" 3 }
478 timeout { verbose "partial: timeout" 3 }
480 set string [string range "$string" [expr $foo + 1] end];
485 if { "$string" != "" } {
486 if { [send_gdb "$string"] != "" } {
487 global suppress_flag;
489 if { ! $suppress_flag } {
490 perror "Couldn't send $command to GDB.";
498 if [target_info exists gdb,timeout] {
499 set tmt [target_info gdb,timeout];
501 if [info exists timeout] {
505 if [info exists timeout] {
514 -re "\\*\\*\\* DOSEXIT code.*" {
515 if { $message != "" } {
518 gdb_suppress_entire_file "GDB died";
521 -re "Ending remote debugging.*$gdb_prompt $" {
522 if ![isnative] then {
523 warning "Can`t communicate to remote target."
530 append code $processed_code
532 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
533 perror "Undefined command \"$command\"."
537 -re "Ambiguous command.*$gdb_prompt $" {
538 perror "\"$command\" is not a unique command name."
542 -re "Program exited with code \[0-9\]+.*$gdb_prompt $" {
543 if ![string match "" $message] then {
544 set errmsg "$message (the program exited)"
546 set errmsg "$command (the program exited)"
551 -re "EXIT code \[0-9\r\n\]+Program exited normally.*$gdb_prompt $" {
552 if ![string match "" $message] then {
553 set errmsg "$message (the program exited)"
555 set errmsg "$command (the program exited)"
560 -re "The program is not being run.*$gdb_prompt $" {
561 if ![string match "" $message] then {
562 set errmsg "$message (the program is no longer running)"
564 set errmsg "$command (the program is no longer running)"
569 -re ".*$gdb_prompt $" {
570 if ![string match "" $message] then {
577 perror "Window too small."
581 -re "\\(y or n\\) " {
583 perror "Got interactive prompt."
588 perror "Process no longer exists"
589 if { $message != "" } {
595 perror "internal buffer is full."
600 if ![string match "" $message] then {
601 fail "$message (timeout)"
608 gdb_expect $tmt $code
612 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
613 # Send a command to gdb; test the result.
615 # COMMAND is the command to execute, send to GDB with send_gdb. If
616 # this is the null string no command is sent.
617 # PATTERN is the pattern to match for a PASS, and must NOT include
618 # the \r\n sequence immediately before the gdb prompt.
619 # MESSAGE is an optional message to be printed. If this is
620 # omitted, then the pass/fail messages use the command string as the
621 # message. (If this is the empty string, then sometimes we don't
622 # call pass or fail at all; I don't understand this at all.)
623 # QUESTION is a question GDB may ask in response to COMMAND, like
625 # RESPONSE is the response to send if QUESTION appears.
628 # 1 if the test failed,
629 # 0 if the test passes,
630 # -1 if there was an internal error.
632 proc gdb_test { args } {
636 upvar timeout timeout
638 if [llength $args]>2 then {
639 set message [lindex $args 2]
641 set message [lindex $args 0]
643 set command [lindex $args 0]
644 set pattern [lindex $args 1]
646 if [llength $args]==5 {
647 set question_string [lindex $args 3];
648 set response_string [lindex $args 4];
650 set question_string "^FOOBAR$"
653 return [gdb_test_multiple $command $message {
654 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
655 if ![string match "" $message] then {
659 -re "(${question_string})$" {
660 send_gdb "$response_string\n";
666 # Test that a command gives an error. For pass or fail, return
667 # a 1 to indicate that more tests can proceed. However a timeout
668 # is a serious error, generates a special fail message, and causes
669 # a 0 to be returned to indicate that more tests are likely to fail
672 proc test_print_reject { args } {
676 if [llength $args]==2 then {
677 set expectthis [lindex $args 1]
679 set expectthis "should never match this bogus string"
681 set sendthis [lindex $args 0]
683 send_user "Sending \"$sendthis\" to gdb\n"
684 send_user "Looking to match \"$expectthis\"\n"
686 send_gdb "$sendthis\n"
687 #FIXME: Should add timeout as parameter.
689 -re "A .* in expression.*\\.*$gdb_prompt $" {
690 pass "reject $sendthis"
693 -re "Invalid syntax in expression.*$gdb_prompt $" {
694 pass "reject $sendthis"
697 -re "Junk after end of expression.*$gdb_prompt $" {
698 pass "reject $sendthis"
701 -re "Invalid number.*$gdb_prompt $" {
702 pass "reject $sendthis"
705 -re "Invalid character constant.*$gdb_prompt $" {
706 pass "reject $sendthis"
709 -re "No symbol table is loaded.*$gdb_prompt $" {
710 pass "reject $sendthis"
713 -re "No symbol .* in current context.*$gdb_prompt $" {
714 pass "reject $sendthis"
717 -re "Unmatched single quote.*$gdb_prompt $" {
718 pass "reject $sendthis"
721 -re "A character constant must contain at least one character.*$gdb_prompt $" {
722 pass "reject $sendthis"
725 -re "$expectthis.*$gdb_prompt $" {
726 pass "reject $sendthis"
729 -re ".*$gdb_prompt $" {
730 fail "reject $sendthis"
734 fail "reject $sendthis (eof or timeout)"
740 # Given an input string, adds backslashes as needed to create a
741 # regexp that will match the string.
743 proc string_to_regexp {str} {
745 regsub -all {[]*+.|()^$\[]} $str {\\&} result
749 # Same as gdb_test, but the second parameter is not a regexp,
750 # but a string that must match exactly.
752 proc gdb_test_exact { args } {
753 upvar timeout timeout
755 set command [lindex $args 0]
757 # This applies a special meaning to a null string pattern. Without
758 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
759 # messages from commands that should have no output except a new
760 # prompt. With this, only results of a null string will match a null
763 set pattern [lindex $args 1]
764 if [string match $pattern ""] {
765 set pattern [string_to_regexp [lindex $args 0]]
767 set pattern [string_to_regexp [lindex $args 1]]
770 # It is most natural to write the pattern argument with only
771 # embedded \n's, especially if you are trying to avoid Tcl quoting
772 # problems. But gdb_expect really wants to see \r\n in patterns. So
773 # transform the pattern here. First transform \r\n back to \n, in
774 # case some users of gdb_test_exact already do the right thing.
775 regsub -all "\r\n" $pattern "\n" pattern
776 regsub -all "\n" $pattern "\r\n" pattern
777 if [llength $args]==3 then {
778 set message [lindex $args 2]
783 return [gdb_test $command $pattern $message]
786 proc gdb_reinitialize_dir { subdir } {
789 if [is_remote host] {
794 -re "Reinitialize source path to empty.*y or n. " {
797 -re "Source directories searched.*$gdb_prompt $" {
798 send_gdb "dir $subdir\n"
800 -re "Source directories searched.*$gdb_prompt $" {
801 verbose "Dir set to $subdir"
803 -re "$gdb_prompt $" {
804 perror "Dir \"$subdir\" failed."
808 -re "$gdb_prompt $" {
809 perror "Dir \"$subdir\" failed."
813 -re "$gdb_prompt $" {
814 perror "Dir \"$subdir\" failed."
820 # gdb_exit -- exit the GDB, killing the target program if necessary
822 proc default_gdb_exit {} {
828 gdb_stop_suppressing_tests;
830 if ![info exists gdb_spawn_id] {
834 verbose "Quitting $GDB $GDBFLAGS"
836 if { [is_remote host] && [board_info host exists fileid] } {
843 -re "DOSEXIT code" { }
848 if ![is_remote host] {
855 # load a file into the debugger.
856 # return a -1 if anything goes wrong.
858 proc gdb_file_cmd { arg } {
864 upvar timeout timeout
866 if [is_remote host] {
867 set arg [remote_download host $arg];
869 error "download failed"
874 send_gdb "file $arg\n"
876 -re "Reading symbols from.*done.*$gdb_prompt $" {
877 verbose "\t\tLoaded $arg into the $GDB"
880 -re "has no symbol-table.*$gdb_prompt $" {
881 perror "$arg wasn't compiled with \"-g\""
884 -re "A program is being debugged already.*Kill it.*y or n. $" {
886 verbose "\t\tKilling previous program being debugged"
889 -re "Load new symbol table from \".*\".*y or n. $" {
892 -re "Reading symbols from.*done.*$gdb_prompt $" {
893 verbose "\t\tLoaded $arg with new symbol table into $GDB"
897 perror "(timeout) Couldn't load $arg, other program already loaded."
902 -re "No such file or directory.*$gdb_prompt $" {
903 perror "($arg) No such file or directory\n"
906 -re "$gdb_prompt $" {
907 perror "couldn't load $arg into $GDB."
911 perror "couldn't load $arg into $GDB (timed out)."
915 # This is an attempt to detect a core dump, but seems not to
916 # work. Perhaps we need to match .* followed by eof, in which
917 # gdb_expect does not seem to have a way to do that.
918 perror "couldn't load $arg into $GDB (end of file)."
925 # start gdb -- start gdb running, default procedure
927 # When running over NFS, particularly if running many simultaneous
928 # tests on different hosts all using the same server, things can
929 # get really slow. Give gdb at least 3 minutes to start up.
931 proc default_gdb_start { } {
939 gdb_stop_suppressing_tests;
941 verbose "Spawning $GDB -nw $GDBFLAGS"
943 if [info exists gdb_spawn_id] {
947 if ![is_remote host] {
948 if { [which $GDB] == 0 } then {
949 perror "$GDB does not exist."
953 set res [remote_spawn host "$GDB -nw $GDBFLAGS [host_info gdb_opts]"];
954 if { $res < 0 || $res == "" } {
955 perror "Spawning $GDB failed."
959 -re "\[\r\n\]$gdb_prompt $" {
960 verbose "GDB initialized."
962 -re "$gdb_prompt $" {
963 perror "GDB never initialized."
967 perror "(timeout) GDB never initialized after 10 seconds."
973 # force the height to "unlimited", so no pagers get used
975 send_gdb "set height 0\n"
977 -re "$gdb_prompt $" {
978 verbose "Setting height to 0." 2
981 warning "Couldn't set the height to 0"
984 # force the width to "unlimited", so no wraparound occurs
985 send_gdb "set width 0\n"
987 -re "$gdb_prompt $" {
988 verbose "Setting width to 0." 2
991 warning "Couldn't set the width to 0."
997 # Return a 1 for configurations for which we don't even want to try to
1000 proc skip_cplus_tests {} {
1001 if { [istarget "d10v-*-*"] } {
1004 if { [istarget "h8300-*-*"] } {
1008 # The C++ IO streams are too large for HC11/HC12 and are thus not
1009 # available. The gdb C++ tests use them and don't compile.
1010 if { [istarget "m6811-*-*"] } {
1013 if { [istarget "m6812-*-*"] } {
1019 # Skip all the tests in the file if you are not on an hppa running
1022 proc skip_hp_tests {} {
1023 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
1024 verbose "Skip hp tests is $skip_hp"
1028 proc get_compiler_info {binfile args} {
1029 # Create and source the file that provides information about the compiler
1030 # used to compile the test case.
1031 # Compiler_type can be null or c++. If null we assume c.
1034 # These two come from compiler.c.
1035 global signed_keyword_not_used
1038 if {![istarget "hppa*-*-hpux*"] && ![istarget "mips*-*-irix*"]} {
1039 if { [llength $args] > 0 } {
1040 if {$args == "c++"} {
1041 if { [gdb_compile "${srcdir}/lib/compiler.cc" "${binfile}.ci" preprocess {}] != "" } {
1042 perror "Couldn't make ${binfile}.ci file"
1047 if { [gdb_compile "${srcdir}/lib/compiler.c" "${binfile}.ci" preprocess {}] != "" } {
1048 perror "Couldn't make ${binfile}.ci file"
1053 if { [llength $args] > 0 } {
1054 if {$args == "c++"} {
1055 if { [eval gdb_preprocess \
1056 [list "${srcdir}/lib/compiler.cc" "${binfile}.ci"] \
1058 perror "Couldn't make ${binfile}.ci file"
1062 } elseif { $args != "f77" } {
1063 if { [eval gdb_preprocess \
1064 [list "${srcdir}/lib/compiler.c" "${binfile}.ci"] \
1066 perror "Couldn't make ${binfile}.ci file"
1072 uplevel \#0 { set gcc_compiled 0 }
1074 if { [llength $args] == 0 || $args != "f77" } {
1075 source ${binfile}.ci
1078 # Most compilers will evaluate comparisons and other boolean
1079 # operations to 0 or 1.
1080 uplevel \#0 { set true 1 }
1081 uplevel \#0 { set false 0 }
1083 uplevel \#0 { set hp_cc_compiler 0 }
1084 uplevel \#0 { set hp_aCC_compiler 0 }
1085 uplevel \#0 { set hp_f77_compiler 0 }
1086 uplevel \#0 { set hp_f90_compiler 0 }
1087 if { !$gcc_compiled && [istarget "hppa*-*-hpux*"] } {
1088 # Check for the HP compilers
1089 set compiler [lindex [split [get_compiler $args] " "] 0]
1090 catch "exec what $compiler" output
1091 if [regexp ".*HP aC\\+\\+.*" $output] {
1092 uplevel \#0 { set hp_aCC_compiler 1 }
1093 # Use of aCC results in boolean results being displayed as
1095 uplevel \#0 { set true true }
1096 uplevel \#0 { set false false }
1097 } elseif [regexp ".*HP C Compiler.*" $output] {
1098 uplevel \#0 { set hp_cc_compiler 1 }
1099 } elseif [regexp ".*HP-UX f77.*" $output] {
1100 uplevel \#0 { set hp_f77_compiler 1 }
1101 } elseif [regexp ".*HP-UX f90.*" $output] {
1102 uplevel \#0 { set hp_f90_compiler 1 }
1109 proc get_compiler {args} {
1110 global CC CC_FOR_TARGET CXX CXX_FOR_TARGET F77_FOR_TARGET
1112 if { [llength $args] == 0
1113 || ([llength $args] == 1 && [lindex $args 0] == "") } {
1114 set which_compiler "c"
1116 if { $args =="c++" } {
1117 set which_compiler "c++"
1118 } elseif { $args =="f77" } {
1119 set which_compiler "f77"
1121 perror "Unknown compiler type supplied to gdb_preprocess"
1126 if [info exists CC_FOR_TARGET] {
1127 if {$which_compiler == "c"} {
1128 set compiler $CC_FOR_TARGET
1132 if [info exists CXX_FOR_TARGET] {
1133 if {$which_compiler == "c++"} {
1134 set compiler $CXX_FOR_TARGET
1138 if [info exists F77_FOR_TARGET] {
1139 if {$which_compiler == "f77"} {
1140 set compiler $F77_FOR_TARGET
1144 if { ![info exists compiler] } {
1145 if { $which_compiler == "c" } {
1146 if {[info exists CC]} {
1150 if { $which_compiler == "c++" } {
1151 if {[info exists CXX]} {
1155 if {![info exists compiler]} {
1156 set compiler [board_info [target_info name] compiler];
1157 if { $compiler == "" } {
1158 perror "get_compiler: No compiler found"
1167 proc gdb_preprocess {source dest args} {
1168 set compiler [get_compiler "$args"]
1169 if { $compiler == "" } {
1173 set cmdline "$compiler -E $source > $dest"
1175 verbose "Invoking $compiler -E $source > $dest"
1176 verbose -log "Executing on local host: $cmdline" 2
1177 set status [catch "exec ${cmdline}" exec_output]
1179 set result [prune_warnings $exec_output]
1180 regsub "\[\r\n\]*$" "$result" "" result;
1181 regsub "^\[\r\n\]*" "$result" "" result;
1182 if { $result != "" } {
1183 clone_output "gdb compile failed, $result"
1188 set gdb_wrapper_initialized 0
1190 proc gdb_wrapper_init { args } {
1191 global gdb_wrapper_initialized;
1192 global gdb_wrapper_file;
1193 global gdb_wrapper_flags;
1195 if { $gdb_wrapper_initialized == 1 } { return; }
1197 if {[target_info exists needs_status_wrapper] && \
1198 [target_info needs_status_wrapper] != "0"} {
1199 set result [build_wrapper "testglue.o"];
1200 if { $result != "" } {
1201 set gdb_wrapper_file [lindex $result 0];
1202 set gdb_wrapper_flags [lindex $result 1];
1204 warning "Status wrapper failed to build."
1207 set gdb_wrapper_initialized 1
1210 proc gdb_compile {source dest type options} {
1211 global GDB_TESTCASE_OPTIONS;
1212 global gdb_wrapper_file;
1213 global gdb_wrapper_flags;
1214 global gdb_wrapper_initialized;
1216 if [target_info exists gdb_stub] {
1217 set options2 { "additional_flags=-Dusestubs" }
1218 lappend options "libs=[target_info gdb_stub]";
1219 set options [concat $options2 $options]
1221 if [target_info exists is_vxworks] {
1222 set options2 { "additional_flags=-Dvxworks" }
1223 lappend options "libs=[target_info gdb_stub]";
1224 set options [concat $options2 $options]
1226 if [info exists GDB_TESTCASE_OPTIONS] {
1227 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
1229 verbose "options are $options"
1230 verbose "source is $source $dest $type $options"
1232 if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init }
1234 if {[target_info exists needs_status_wrapper] && \
1235 [target_info needs_status_wrapper] != "0" && \
1236 [info exists gdb_wrapper_file]} {
1237 lappend options "libs=${gdb_wrapper_file}"
1238 lappend options "ldflags=${gdb_wrapper_flags}"
1241 set result [target_compile $source $dest $type $options];
1242 regsub "\[\r\n\]*$" "$result" "" result;
1243 regsub "^\[\r\n\]*" "$result" "" result;
1244 if { $result != "" && [lsearch $options quiet] == -1} {
1245 clone_output "gdb compile failed, $result"
1251 # This is just like gdb_compile, above, except that it tries compiling
1252 # against several different thread libraries, to see which one this
1254 proc gdb_compile_pthreads {source dest type options} {
1256 set why_msg "unrecognized error"
1257 foreach lib {-lpthreads -lpthread -lthread} {
1258 # This kind of wipes out whatever libs the caller may have
1259 # set. Or maybe theirs will override ours. How infelicitous.
1260 set options_with_lib [concat $options [list libs=$lib quiet]]
1261 set ccout [gdb_compile $source $dest $type $options_with_lib]
1262 switch -regexp -- $ccout {
1263 ".*no posix threads support.*" {
1264 set why_msg "missing threads include file"
1267 ".*cannot open -lpthread.*" {
1268 set why_msg "missing runtime threads library"
1270 ".*Can't find library for -lpthread.*" {
1271 set why_msg "missing runtime threads library"
1274 pass "successfully compiled posix threads test case"
1280 if {!$built_binfile} {
1281 unsupported "Couldn't compile $source: ${why_msg}"
1286 proc send_gdb { string } {
1287 global suppress_flag;
1288 if { $suppress_flag } {
1289 return "suppressed";
1291 return [remote_send host "$string"];
1297 proc gdb_expect { args } {
1298 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
1299 set gtimeout [lindex $args 0];
1300 set expcode [list [lindex $args 1]];
1302 upvar timeout timeout;
1305 if [target_info exists gdb,timeout] {
1306 if [info exists timeout] {
1307 if { $timeout < [target_info gdb,timeout] } {
1308 set gtimeout [target_info gdb,timeout];
1310 set gtimeout $timeout;
1313 set gtimeout [target_info gdb,timeout];
1317 if ![info exists gtimeout] {
1319 if [info exists timeout] {
1320 set gtimeout $timeout;
1327 global suppress_flag;
1328 global remote_suppress_flag;
1329 if [info exists remote_suppress_flag] {
1330 set old_val $remote_suppress_flag;
1332 if [info exists suppress_flag] {
1333 if { $suppress_flag } {
1334 set remote_suppress_flag 1;
1338 {uplevel remote_expect host $gtimeout $expcode} string];
1339 if [info exists old_val] {
1340 set remote_suppress_flag $old_val;
1342 if [info exists remote_suppress_flag] {
1343 unset remote_suppress_flag;
1348 global errorInfo errorCode;
1350 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
1351 } elseif {$code == 2} {
1352 return -code return $string
1353 } elseif {$code == 3} {
1355 } elseif {$code > 4} {
1356 return -code $code $string
1360 # gdb_expect_list MESSAGE SENTINEL LIST -- expect a sequence of outputs
1362 # Check for long sequence of output by parts.
1363 # MESSAGE: is the test message to be printed with the test success/fail.
1364 # SENTINEL: Is the terminal pattern indicating that output has finished.
1365 # LIST: is the sequence of outputs to match.
1366 # If the sentinel is recognized early, it is considered an error.
1369 # 1 if the test failed,
1370 # 0 if the test passes,
1371 # -1 if there was an internal error.
1373 proc gdb_expect_list {test sentinel list} {
1375 global suppress_flag
1378 if { $suppress_flag } {
1380 unresolved "${test}"
1382 while { ${index} < [llength ${list}] } {
1383 set pattern [lindex ${list} ${index}]
1384 set index [expr ${index} + 1]
1385 if { ${index} == [llength ${list}] } {
1388 -re "${pattern}${sentinel}" {
1389 # pass "${test}, pattern ${index} + sentinel"
1392 fail "${test} (pattern ${index} + sentinel)"
1396 fail "${test} (pattern ${index} + sentinel) (timeout)"
1401 # unresolved "${test}, pattern ${index} + sentinel"
1407 # pass "${test}, pattern ${index}"
1410 fail "${test} (pattern ${index})"
1414 fail "${test} (pattern ${index}) (timeout)"
1419 # unresolved "${test}, pattern ${index}"
1433 proc gdb_suppress_entire_file { reason } {
1434 global suppress_flag;
1436 warning "$reason\n";
1437 set suppress_flag -1;
1441 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
1442 # gdb_expect to fail immediately (until the next call to
1443 # gdb_stop_suppressing_tests).
1445 proc gdb_suppress_tests { args } {
1446 global suppress_flag;
1448 return; # fnf - disable pending review of results where
1449 # testsuite ran better without this
1452 if { $suppress_flag == 1 } {
1453 if { [llength $args] > 0 } {
1454 warning "[lindex $args 0]\n";
1456 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
1462 # Clear suppress_flag.
1464 proc gdb_stop_suppressing_tests { } {
1465 global suppress_flag;
1467 if [info exists suppress_flag] {
1468 if { $suppress_flag > 0 } {
1469 set suppress_flag 0;
1470 clone_output "Tests restarted.\n";
1473 set suppress_flag 0;
1477 proc gdb_clear_suppressed { } {
1478 global suppress_flag;
1480 set suppress_flag 0;
1483 proc gdb_start { } {
1488 catch default_gdb_exit
1492 # gdb_load -- load a file into the debugger.
1493 # return a -1 if anything goes wrong.
1495 proc gdb_load { arg } {
1496 return [gdb_file_cmd $arg]
1499 proc gdb_continue { function } {
1502 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
1505 proc default_gdb_init { args } {
1506 global gdb_wrapper_initialized
1508 gdb_clear_suppressed;
1510 # Make sure that the wrapper is rebuilt
1511 # with the appropriate multilib option.
1512 set gdb_wrapper_initialized 0
1514 # Uh, this is lame. Really, really, really lame. But there's this *one*
1515 # testcase that will fail in random places if we don't increase this.
1518 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
1519 if { [llength $args] > 0 } {
1522 set file [lindex $args 0];
1524 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
1527 if [target_info exists gdb_prompt] {
1528 set gdb_prompt [target_info gdb_prompt];
1530 set gdb_prompt "\\(gdb\\)"
1534 proc gdb_init { args } {
1535 return [eval default_gdb_init $args];
1538 proc gdb_finish { } {
1543 set debug_format "unknown"
1545 # Run the gdb command "info source" and extract the debugging format
1546 # information from the output and save it in debug_format.
1548 proc get_debug_format { } {
1554 set debug_format "unknown"
1555 send_gdb "info source\n"
1557 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
1558 set debug_format $expect_out(1,string)
1559 verbose "debug format is $debug_format"
1562 -re "No current source file.\r\n$gdb_prompt $" {
1563 perror "get_debug_format used when no current source file"
1566 -re "$gdb_prompt $" {
1567 warning "couldn't check debug format (no valid response)."
1571 warning "couldn't check debug format (timed out)."
1577 # Return true if FORMAT matches the debug format the current test was
1578 # compiled with. FORMAT is a shell-style globbing pattern; it can use
1579 # `*', `[...]', and so on.
1581 # This function depends on variables set by `get_debug_format', above.
1583 proc test_debug_format {format} {
1586 return [expr [string match $format $debug_format] != 0]
1589 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
1590 # COFF, stabs, etc). If that format matches the format that the
1591 # current test was compiled with, then the next test is expected to
1592 # fail for any target. Returns 1 if the next test or set of tests is
1593 # expected to fail, 0 otherwise (or if it is unknown). Must have
1594 # previously called get_debug_format.
1595 proc setup_xfail_format { format } {
1596 set ret [test_debug_format $format];
1604 proc gdb_step_for_stub { } {
1607 if ![target_info exists gdb,use_breakpoint_for_stub] {
1608 if [target_info exists gdb_stub_step_command] {
1609 set command [target_info gdb_stub_step_command];
1613 send_gdb "${command}\n";
1616 -re "(main.* at |.*in .*start).*$gdb_prompt" {
1619 -re ".*$gdb_prompt" {
1621 if { $tries == 5 } {
1622 fail "stepping out of breakpoint function";
1625 send_gdb "${command}\n";
1629 fail "stepping out of breakpoint function";
1636 -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" {
1637 set file $expect_out(1,string);
1638 set linenum [expr $expect_out(2,string) + 1];
1639 set breakplace "${file}:${linenum}";
1643 send_gdb "break ${breakplace}\n";
1645 -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" {
1646 set breakpoint $expect_out(1,string);
1648 -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" {
1649 set breakpoint $expect_out(1,string);
1653 send_gdb "continue\n";
1655 -re "Breakpoint ${breakpoint},.*$gdb_prompt" {
1656 gdb_test "delete $breakpoint" ".*" "";
1663 ### gdb_get_line_number TEXT [FILE]
1665 ### Search the source file FILE, and return the line number of a line
1666 ### containing TEXT. Use this function instead of hard-coding line
1667 ### numbers into your test script.
1669 ### Specifically, this function uses GDB's "search" command to search
1670 ### FILE for the first line containing TEXT, and returns its line
1671 ### number. Thus, FILE must be a source file, compiled into the
1672 ### executable you are running. If omitted, FILE defaults to the
1673 ### value of the global variable `srcfile'; most test scripts set
1674 ### `srcfile' appropriately at the top anyway.
1676 ### Use this function to keep your test scripts independent of the
1677 ### exact line numbering of the source file. Don't write:
1679 ### send_gdb "break 20"
1681 ### This means that if anyone ever edits your test's source file,
1682 ### your test could break. Instead, put a comment like this on the
1683 ### source file line you want to break at:
1685 ### /* breakpoint spot: frotz.exp: test name */
1687 ### and then write, in your test script (which we assume is named
1690 ### send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
1692 ### (Yes, Tcl knows how to handle the nested quotes and brackets.
1695 ### % puts "foo [lindex "bar baz" 1]"
1698 ### Tcl is quite clever, for a little stringy language.)
1700 proc gdb_get_line_number {text {file /omitted/}} {
1704 if {! [string compare $file /omitted/]} {
1709 gdb_test "list ${file}:1,1" ".*" ""
1710 send_gdb "search ${text}\n"
1712 -re "\[\r\n\]+(\[0-9\]+)\[ \t\].*${text}.*$gdb_prompt $" {
1713 set result $expect_out(1,string)
1715 -re ".*$gdb_prompt $" {
1716 fail "find line number containing \"${text}\""
1719 fail "find line number containing \"${text}\" (timeout)"
1725 # gdb_continue_to_end:
1726 # The case where the target uses stubs has to be handled specially. If a
1727 # stub is used, we set a breakpoint at exit because we cannot rely on
1728 # exit() behavior of a remote target.
1730 # mssg is the error message that gets printed.
1732 proc gdb_continue_to_end {mssg} {
1733 if [target_info exists use_gdb_stub] {
1734 if {![gdb_breakpoint "exit"]} {
1737 gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \
1738 "continue until exit at $mssg"
1740 # Continue until we exit. Should not stop again.
1741 # Don't bother to check the output of the program, that may be
1742 # extremely tough for some remote systems.
1743 gdb_test "continue"\
1744 "Continuing.\[\r\n0-9\]+(... EXIT code 0\[\r\n\]+|Program exited normally\\.).*"\
1745 "continue until exit at $mssg"
1749 proc rerun_to_main {} {
1752 if [target_info exists use_gdb_stub] {
1755 -re ".*Breakpoint .*main .*$gdb_prompt $"\
1756 {pass "rerun to main" ; return 0}
1757 -re "$gdb_prompt $"\
1758 {fail "rerun to main" ; return 0}
1759 timeout {fail "(timeout) rerun to main" ; return 0}
1764 -re "The program .* has been started already.*y or n. $" {
1768 -re "Starting program.*$gdb_prompt $"\
1769 {pass "rerun to main" ; return 0}
1770 -re "$gdb_prompt $"\
1771 {fail "rerun to main" ; return 0}
1772 timeout {fail "(timeout) rerun to main" ; return 0}
1777 # Print a message and return true if a test should be skipped
1778 # due to lack of floating point suport.
1780 proc gdb_skip_float_test { msg } {
1781 if [target_info exists gdb,skip_float_tests] {
1782 verbose "Skipping test '$msg': no float tests.";
1788 # Print a message and return true if a test should be skipped
1789 # due to lack of stdio support.
1791 proc gdb_skip_stdio_test { msg } {
1792 if [target_info exists gdb,noinferiorio] {
1793 verbose "Skipping test '$msg': no inferior i/o.";
1799 proc gdb_skip_bogus_test { msg } {