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 "Make breakpoint pending.*y or n. $" {
273 gdb_test "n" "" "setting breakpoint at $function" ;
276 -re "$gdb_prompt $" { fail "setting breakpoint at $function" ; return 0 }
277 timeout { fail "setting breakpoint at $function (timeout)" ; return 0 }
282 # Set breakpoint at function and run gdb until it breaks there.
283 # Since this is the only breakpoint that will be set, if it stops
284 # at a breakpoint, we will assume it is the one we want. We can't
285 # just compare to "function" because it might be a fully qualified,
286 # single quoted C++ function specifier.
288 proc runto { function } {
294 if ![gdb_breakpoint $function] {
300 # the "at foo.c:36" output we get with -g.
301 # the "in func" output we get without -g.
303 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
306 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
309 -re "$gdb_prompt $" {
310 fail "running to $function in runto"
314 fail "running to $function in runto (timeout)"
322 # runto_main -- ask gdb to run until we hit a breakpoint at main.
323 # The case where the target uses stubs has to be handled
324 # specially--if it uses stubs, assuming we hit
325 # breakpoint() and just step out of the function.
327 proc runto_main { } {
331 if ![target_info exists gdb_stub] {
343 ### Continue, and expect to hit a breakpoint.
344 ### Report a pass or fail, depending on whether it seems to have
345 ### worked. Use NAME as part of the test name; each call to
346 ### continue_to_breakpoint should use a NAME which is unique within
348 proc gdb_continue_to_breakpoint {name} {
350 set full_name "continue to breakpoint: $name"
352 send_gdb "continue\n"
354 -re "Breakpoint .* at .*\r\n$gdb_prompt $" {
357 -re ".*$gdb_prompt $" {
361 fail "$full_name (timeout)"
367 # gdb_internal_error_resync:
369 # Answer the questions GDB asks after it reports an internal error
370 # until we get back to a GDB prompt. Decline to quit the debugging
371 # session, and decline to create a core file. Return non-zero if the
374 # This procedure just answers whatever questions come up until it sees
375 # a GDB prompt; it doesn't require you to have matched the input up to
376 # any specific point. However, it only answers questions it sees in
377 # the output itself, so if you've matched a question, you had better
378 # answer it yourself before calling this.
380 # You can use this function thus:
384 # -re ".*A problem internal to GDB has been detected" {
385 # gdb_internal_error_resync
390 proc gdb_internal_error_resync {} {
394 while {$count < 10} {
396 -re "Quit this debugging session\\? \\(y or n\\) $" {
400 -re "Create a core file of GDB\\? \\(y or n\\) $" {
404 -re "$gdb_prompt $" {
405 # We're resynchronized.
409 perror "Could not resync from internal error (timeout)"
414 perror "Could not resync from internal error (resync count exceeded)"
419 # gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS
420 # Send a command to gdb; test the result.
422 # COMMAND is the command to execute, send to GDB with send_gdb. If
423 # this is the null string no command is sent.
424 # MESSAGE is a message to be printed with the built-in failure patterns
425 # if one of them matches. If MESSAGE is empty COMMAND will be used.
426 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
427 # patterns. Pattern elements will be evaluated in the caller's
428 # context; action elements will be executed in the caller's context.
429 # Unlike patterns for gdb_test, these patterns should generally include
430 # the final newline and prompt.
433 # 1 if the test failed, according to a built-in failure pattern
434 # 0 if only user-supplied patterns matched
435 # -1 if there was an internal error.
437 # You can use this function thus:
439 # gdb_test_multiple "print foo" "test foo" {
440 # -re "expected output 1" {
443 # -re "expected output 2" {
448 # The standard patterns, such as "Program exited..." and "A problem
449 # ...", all being implicitly appended to that list.
451 proc gdb_test_multiple { command message user_code } {
455 upvar timeout timeout
456 upvar expect_out expect_out
458 if { $message == "" } {
462 # TCL/EXPECT WART ALERT
463 # Expect does something very strange when it receives a single braced
464 # argument. It splits it along word separators and performs substitutions.
465 # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
466 # evaluated as "\[ab\]". But that's not how TCL normally works; inside a
467 # double-quoted list item, "\[ab\]" is just a long way of representing
468 # "[ab]", because the backslashes will be removed by lindex.
470 # Unfortunately, there appears to be no easy way to duplicate the splitting
471 # that expect will do from within TCL. And many places make use of the
472 # "\[0-9\]" construct, so we need to support that; and some places make use
473 # of the "[func]" construct, so we need to support that too. In order to
474 # get this right we have to substitute quoted list elements differently
475 # from braced list elements.
477 # We do this roughly the same way that Expect does it. We have to use two
478 # lists, because if we leave unquoted newlines in the argument to uplevel
479 # they'll be treated as command separators, and if we escape newlines
480 # we mangle newlines inside of command blocks. This assumes that the
481 # input doesn't contain a pattern which contains actual embedded newlines
484 regsub -all {\n} ${user_code} { } subst_code
485 set subst_code [uplevel list $subst_code]
487 set processed_code ""
489 set expecting_action 0
490 foreach item $user_code subst_item $subst_code {
491 if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } {
492 lappend processed_code $item
495 if {$item == "-indices" || $item == "-re" || $item == "-ex"} {
496 lappend processed_code $item
499 if { $expecting_action } {
500 lappend processed_code "uplevel [list $item]"
501 set expecting_action 0
502 # Cosmetic, no effect on the list.
503 append processed_code "\n"
506 set expecting_action 1
507 lappend processed_code $subst_item
508 if {$patterns != ""} {
511 append patterns "\"$subst_item\""
514 # Also purely cosmetic.
515 regsub -all {\r} $patterns {\\r} patterns
516 regsub -all {\n} $patterns {\\n} patterns
519 send_user "Sending \"$command\" to gdb\n"
520 send_user "Looking to match \"$patterns\"\n"
521 send_user "Message is \"$message\"\n"
525 set string "${command}\n";
526 if { $command != "" } {
527 while { "$string" != "" } {
528 set foo [string first "\n" "$string"];
529 set len [string length "$string"];
530 if { $foo < [expr $len - 1] } {
531 set str [string range "$string" 0 $foo];
532 if { [send_gdb "$str"] != "" } {
533 global suppress_flag;
535 if { ! $suppress_flag } {
536 perror "Couldn't send $command to GDB.";
541 # since we're checking if each line of the multi-line
542 # command are 'accepted' by GDB here,
543 # we need to set -notransfer expect option so that
544 # command output is not lost for pattern matching
547 -notransfer -re "\[\r\n\]" { verbose "partial: match" 3 }
548 timeout { verbose "partial: timeout" 3 }
550 set string [string range "$string" [expr $foo + 1] end];
555 if { "$string" != "" } {
556 if { [send_gdb "$string"] != "" } {
557 global suppress_flag;
559 if { ! $suppress_flag } {
560 perror "Couldn't send $command to GDB.";
568 if [target_info exists gdb,timeout] {
569 set tmt [target_info gdb,timeout];
571 if [info exists timeout] {
575 if [info exists timeout] {
584 -re ".*A problem internal to GDB has been detected" {
585 fail "$message (GDB internal error)"
586 gdb_internal_error_resync
588 -re "\\*\\*\\* DOSEXIT code.*" {
589 if { $message != "" } {
592 gdb_suppress_entire_file "GDB died";
595 -re "Ending remote debugging.*$gdb_prompt $" {
596 if ![isnative] then {
597 warning "Can`t communicate to remote target."
604 append code $processed_code
606 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
607 perror "Undefined command \"$command\"."
611 -re "Ambiguous command.*$gdb_prompt $" {
612 perror "\"$command\" is not a unique command name."
616 -re "Program exited with code \[0-9\]+.*$gdb_prompt $" {
617 if ![string match "" $message] then {
618 set errmsg "$message (the program exited)"
620 set errmsg "$command (the program exited)"
625 -re "EXIT code \[0-9\r\n\]+Program exited normally.*$gdb_prompt $" {
626 if ![string match "" $message] then {
627 set errmsg "$message (the program exited)"
629 set errmsg "$command (the program exited)"
634 -re "The program is not being run.*$gdb_prompt $" {
635 if ![string match "" $message] then {
636 set errmsg "$message (the program is no longer running)"
638 set errmsg "$command (the program is no longer running)"
643 -re ".*$gdb_prompt $" {
644 if ![string match "" $message] then {
651 perror "Window too small."
655 -re "\\(y or n\\) " {
657 perror "Got interactive prompt."
662 perror "Process no longer exists"
663 if { $message != "" } {
669 perror "internal buffer is full."
674 if ![string match "" $message] then {
675 fail "$message (timeout)"
682 gdb_expect $tmt $code
686 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
687 # Send a command to gdb; test the result.
689 # COMMAND is the command to execute, send to GDB with send_gdb. If
690 # this is the null string no command is sent.
691 # PATTERN is the pattern to match for a PASS, and must NOT include
692 # the \r\n sequence immediately before the gdb prompt.
693 # MESSAGE is an optional message to be printed. If this is
694 # omitted, then the pass/fail messages use the command string as the
695 # message. (If this is the empty string, then sometimes we don't
696 # call pass or fail at all; I don't understand this at all.)
697 # QUESTION is a question GDB may ask in response to COMMAND, like
699 # RESPONSE is the response to send if QUESTION appears.
702 # 1 if the test failed,
703 # 0 if the test passes,
704 # -1 if there was an internal error.
706 proc gdb_test { args } {
710 upvar timeout timeout
712 if [llength $args]>2 then {
713 set message [lindex $args 2]
715 set message [lindex $args 0]
717 set command [lindex $args 0]
718 set pattern [lindex $args 1]
720 if [llength $args]==5 {
721 set question_string [lindex $args 3];
722 set response_string [lindex $args 4];
724 set question_string "^FOOBAR$"
727 return [gdb_test_multiple $command $message {
728 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
729 if ![string match "" $message] then {
733 -re "(${question_string})$" {
734 send_gdb "$response_string\n";
740 # Test that a command gives an error. For pass or fail, return
741 # a 1 to indicate that more tests can proceed. However a timeout
742 # is a serious error, generates a special fail message, and causes
743 # a 0 to be returned to indicate that more tests are likely to fail
746 proc test_print_reject { args } {
750 if [llength $args]==2 then {
751 set expectthis [lindex $args 1]
753 set expectthis "should never match this bogus string"
755 set sendthis [lindex $args 0]
757 send_user "Sending \"$sendthis\" to gdb\n"
758 send_user "Looking to match \"$expectthis\"\n"
760 send_gdb "$sendthis\n"
761 #FIXME: Should add timeout as parameter.
763 -re "A .* in expression.*\\.*$gdb_prompt $" {
764 pass "reject $sendthis"
767 -re "Invalid syntax in expression.*$gdb_prompt $" {
768 pass "reject $sendthis"
771 -re "Junk after end of expression.*$gdb_prompt $" {
772 pass "reject $sendthis"
775 -re "Invalid number.*$gdb_prompt $" {
776 pass "reject $sendthis"
779 -re "Invalid character constant.*$gdb_prompt $" {
780 pass "reject $sendthis"
783 -re "No symbol table is loaded.*$gdb_prompt $" {
784 pass "reject $sendthis"
787 -re "No symbol .* in current context.*$gdb_prompt $" {
788 pass "reject $sendthis"
791 -re "Unmatched single quote.*$gdb_prompt $" {
792 pass "reject $sendthis"
795 -re "A character constant must contain at least one character.*$gdb_prompt $" {
796 pass "reject $sendthis"
799 -re "$expectthis.*$gdb_prompt $" {
800 pass "reject $sendthis"
803 -re ".*$gdb_prompt $" {
804 fail "reject $sendthis"
808 fail "reject $sendthis (eof or timeout)"
814 # Given an input string, adds backslashes as needed to create a
815 # regexp that will match the string.
817 proc string_to_regexp {str} {
819 regsub -all {[]*+.|()^$\[]} $str {\\&} result
823 # Same as gdb_test, but the second parameter is not a regexp,
824 # but a string that must match exactly.
826 proc gdb_test_exact { args } {
827 upvar timeout timeout
829 set command [lindex $args 0]
831 # This applies a special meaning to a null string pattern. Without
832 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
833 # messages from commands that should have no output except a new
834 # prompt. With this, only results of a null string will match a null
837 set pattern [lindex $args 1]
838 if [string match $pattern ""] {
839 set pattern [string_to_regexp [lindex $args 0]]
841 set pattern [string_to_regexp [lindex $args 1]]
844 # It is most natural to write the pattern argument with only
845 # embedded \n's, especially if you are trying to avoid Tcl quoting
846 # problems. But gdb_expect really wants to see \r\n in patterns. So
847 # transform the pattern here. First transform \r\n back to \n, in
848 # case some users of gdb_test_exact already do the right thing.
849 regsub -all "\r\n" $pattern "\n" pattern
850 regsub -all "\n" $pattern "\r\n" pattern
851 if [llength $args]==3 then {
852 set message [lindex $args 2]
857 return [gdb_test $command $pattern $message]
860 proc gdb_reinitialize_dir { subdir } {
863 if [is_remote host] {
868 -re "Reinitialize source path to empty.*y or n. " {
871 -re "Source directories searched.*$gdb_prompt $" {
872 send_gdb "dir $subdir\n"
874 -re "Source directories searched.*$gdb_prompt $" {
875 verbose "Dir set to $subdir"
877 -re "$gdb_prompt $" {
878 perror "Dir \"$subdir\" failed."
882 -re "$gdb_prompt $" {
883 perror "Dir \"$subdir\" failed."
887 -re "$gdb_prompt $" {
888 perror "Dir \"$subdir\" failed."
894 # gdb_exit -- exit the GDB, killing the target program if necessary
896 proc default_gdb_exit {} {
902 gdb_stop_suppressing_tests;
904 if ![info exists gdb_spawn_id] {
908 verbose "Quitting $GDB $GDBFLAGS"
910 if { [is_remote host] && [board_info host exists fileid] } {
917 -re "DOSEXIT code" { }
922 if ![is_remote host] {
929 # load a file into the debugger.
930 # return a -1 if anything goes wrong.
932 proc gdb_file_cmd { arg } {
938 upvar timeout timeout
940 if [is_remote host] {
941 set arg [remote_download host $arg];
943 error "download failed"
948 send_gdb "file $arg\n"
950 -re "Reading symbols from.*done.*$gdb_prompt $" {
951 verbose "\t\tLoaded $arg into the $GDB"
954 -re "has no symbol-table.*$gdb_prompt $" {
955 perror "$arg wasn't compiled with \"-g\""
958 -re "A program is being debugged already.*Kill it.*y or n. $" {
960 verbose "\t\tKilling previous program being debugged"
963 -re "Load new symbol table from \".*\".*y or n. $" {
966 -re "Reading symbols from.*done.*$gdb_prompt $" {
967 verbose "\t\tLoaded $arg with new symbol table into $GDB"
971 perror "(timeout) Couldn't load $arg, other program already loaded."
976 -re "No such file or directory.*$gdb_prompt $" {
977 perror "($arg) No such file or directory\n"
980 -re "$gdb_prompt $" {
981 perror "couldn't load $arg into $GDB."
985 perror "couldn't load $arg into $GDB (timed out)."
989 # This is an attempt to detect a core dump, but seems not to
990 # work. Perhaps we need to match .* followed by eof, in which
991 # gdb_expect does not seem to have a way to do that.
992 perror "couldn't load $arg into $GDB (end of file)."
999 # start gdb -- start gdb running, default procedure
1001 # When running over NFS, particularly if running many simultaneous
1002 # tests on different hosts all using the same server, things can
1003 # get really slow. Give gdb at least 3 minutes to start up.
1005 proc default_gdb_start { } {
1011 global gdb_spawn_id;
1013 gdb_stop_suppressing_tests;
1015 verbose "Spawning $GDB -nw $GDBFLAGS"
1017 if [info exists gdb_spawn_id] {
1021 if ![is_remote host] {
1022 if { [which $GDB] == 0 } then {
1023 perror "$GDB does not exist."
1027 set res [remote_spawn host "$GDB -nw $GDBFLAGS [host_info gdb_opts]"];
1028 if { $res < 0 || $res == "" } {
1029 perror "Spawning $GDB failed."
1033 -re "\[\r\n\]$gdb_prompt $" {
1034 verbose "GDB initialized."
1036 -re "$gdb_prompt $" {
1037 perror "GDB never initialized."
1041 perror "(timeout) GDB never initialized after 10 seconds."
1046 set gdb_spawn_id -1;
1047 # force the height to "unlimited", so no pagers get used
1049 send_gdb "set height 0\n"
1051 -re "$gdb_prompt $" {
1052 verbose "Setting height to 0." 2
1055 warning "Couldn't set the height to 0"
1058 # force the width to "unlimited", so no wraparound occurs
1059 send_gdb "set width 0\n"
1061 -re "$gdb_prompt $" {
1062 verbose "Setting width to 0." 2
1065 warning "Couldn't set the width to 0."
1071 # Return a 1 for configurations for which we don't even want to try to
1074 proc skip_cplus_tests {} {
1075 if { [istarget "d10v-*-*"] } {
1078 if { [istarget "h8300-*-*"] } {
1082 # The C++ IO streams are too large for HC11/HC12 and are thus not
1083 # available. The gdb C++ tests use them and don't compile.
1084 if { [istarget "m6811-*-*"] } {
1087 if { [istarget "m6812-*-*"] } {
1093 # Skip all the tests in the file if you are not on an hppa running
1096 proc skip_hp_tests {} {
1097 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
1098 verbose "Skip hp tests is $skip_hp"
1102 set compiler_info "unknown"
1104 set hp_cc_compiler 0
1105 set hp_aCC_compiler 0
1106 set signed_keyword_not_used 0
1108 # Figure out what compiler I am using.
1110 # BINFILE is a "compiler information" output file. This implementation
1111 # does not use BINFILE.
1113 # ARGS can be empty or "C++". If empty, "C" is assumed.
1115 # There are several ways to do this, with various problems.
1117 # [ gdb_compile -E $ifile -o $binfile.ci ]
1118 # source $binfile.ci
1120 # Single Unix Spec v3 says that "-E -o ..." together are not
1121 # specified. And in fact, the native compiler on hp-ux 11 (among
1122 # others) does not work with "-E -o ...". Most targets used to do
1123 # this, and it mostly worked, because it works with gcc.
1125 # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ]
1126 # source $binfile.ci
1128 # This avoids the problem with -E and -o together. This almost works
1129 # if the build machine is the same as the host machine, which is
1130 # usually true of the targets which are not gcc. But this code does
1131 # not figure which compiler to call, and it always ends up using the C
1132 # compiler. Not good for setting hp_aCC_compiler. Targets
1133 # hppa*-*-hpux* and mips*-*-irix* used to do this.
1135 # [ gdb_compile -E $ifile > $binfile.ci ]
1136 # source $binfile.ci
1138 # dejagnu target_compile says that it supports output redirection,
1139 # but the code is completely different from the normal path and I
1140 # don't want to sweep the mines from that path. So I didn't even try
1143 # set cppout [ gdb_compile $ifile "" preprocess $args quiet ]
1146 # I actually do this for all targets now. gdb_compile runs the right
1147 # compiler, and TCL captures the output, and I eval the output.
1149 # Unfortunately, expect logs the output of the command as it goes by,
1150 # and dejagnu helpfully prints a second copy of it right afterwards.
1151 # So I turn off expect logging for a moment.
1153 # [ gdb_compile $ifile $ciexe_file executable $args ]
1154 # [ remote_exec $ciexe_file ]
1155 # [ source $ci_file.out ]
1157 # I could give up on -E and just do this.
1158 # I didn't get desperate enough to try this.
1160 # -- chastain 2004-01-06
1162 proc get_compiler_info {binfile args} {
1163 # For compiler.c and compiler.cc
1166 # I am going to play with the log to keep noise out.
1170 # These come from compiler.c or compiler.cc
1171 global compiler_info
1173 global hp_cc_compiler
1174 global hp_aCC_compiler
1175 global signed_keyword_not_used
1177 # Choose which file to preprocess.
1178 set ifile "${srcdir}/lib/compiler.c"
1179 if { [llength $args] > 0 && [lindex $args 0] == "c++" } {
1180 set ifile "${srcdir}/lib/compiler.cc"
1183 # Run $ifile through the right preprocessor.
1184 # Toggle gdb.log to keep the compiler output out of the log.
1186 set cppout [ gdb_compile "${ifile}" "" preprocess [list "$args" quiet] ]
1187 log_file -a "$outdir/$tool.log"
1189 # Source the output.
1190 foreach cppline [ split "$cppout" "\n" ] {
1191 if { ! [ regexp "^#" "$cppline" ] } {
1192 if { ! [ regexp "^\[\n\r\t \]*$" "$cppline" ] } {
1193 verbose "get_compiler_info: $cppline" 2
1198 verbose -log "get_compiler_info: $compiler_info"
1200 # Most compilers will evaluate comparisons and other boolean
1201 # operations to 0 or 1.
1202 uplevel \#0 { set true 1 }
1203 uplevel \#0 { set false 0 }
1205 # Use of aCC results in boolean results being displayed as
1207 if { $hp_aCC_compiler } {
1208 uplevel \#0 { set true true }
1209 uplevel \#0 { set false false }
1215 proc test_compiler_info { compiler } {
1216 global compiler_info
1217 return [string match $compiler $compiler_info]
1220 set gdb_wrapper_initialized 0
1222 proc gdb_wrapper_init { args } {
1223 global gdb_wrapper_initialized;
1224 global gdb_wrapper_file;
1225 global gdb_wrapper_flags;
1227 if { $gdb_wrapper_initialized == 1 } { return; }
1229 if {[target_info exists needs_status_wrapper] && \
1230 [target_info needs_status_wrapper] != "0"} {
1231 set result [build_wrapper "testglue.o"];
1232 if { $result != "" } {
1233 set gdb_wrapper_file [lindex $result 0];
1234 set gdb_wrapper_flags [lindex $result 1];
1236 warning "Status wrapper failed to build."
1239 set gdb_wrapper_initialized 1
1242 proc gdb_compile {source dest type options} {
1243 global GDB_TESTCASE_OPTIONS;
1244 global gdb_wrapper_file;
1245 global gdb_wrapper_flags;
1246 global gdb_wrapper_initialized;
1248 if [target_info exists gdb_stub] {
1249 set options2 { "additional_flags=-Dusestubs" }
1250 lappend options "libs=[target_info gdb_stub]";
1251 set options [concat $options2 $options]
1253 if [target_info exists is_vxworks] {
1254 set options2 { "additional_flags=-Dvxworks" }
1255 lappend options "libs=[target_info gdb_stub]";
1256 set options [concat $options2 $options]
1258 if [info exists GDB_TESTCASE_OPTIONS] {
1259 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
1261 verbose "options are $options"
1262 verbose "source is $source $dest $type $options"
1264 if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init }
1266 if {[target_info exists needs_status_wrapper] && \
1267 [target_info needs_status_wrapper] != "0" && \
1268 [info exists gdb_wrapper_file]} {
1269 lappend options "libs=${gdb_wrapper_file}"
1270 lappend options "ldflags=${gdb_wrapper_flags}"
1273 set result [target_compile $source $dest $type $options];
1274 regsub "\[\r\n\]*$" "$result" "" result;
1275 regsub "^\[\r\n\]*" "$result" "" result;
1276 if { $result != "" && [lsearch $options quiet] == -1} {
1277 clone_output "gdb compile failed, $result"
1283 # This is just like gdb_compile, above, except that it tries compiling
1284 # against several different thread libraries, to see which one this
1286 proc gdb_compile_pthreads {source dest type options} {
1288 set why_msg "unrecognized error"
1289 foreach lib {-lpthreads -lpthread -lthread} {
1290 # This kind of wipes out whatever libs the caller may have
1291 # set. Or maybe theirs will override ours. How infelicitous.
1292 set options_with_lib [concat $options [list libs=$lib quiet]]
1293 set ccout [gdb_compile $source $dest $type $options_with_lib]
1294 switch -regexp -- $ccout {
1295 ".*no posix threads support.*" {
1296 set why_msg "missing threads include file"
1299 ".*cannot open -lpthread.*" {
1300 set why_msg "missing runtime threads library"
1302 ".*Can't find library for -lpthread.*" {
1303 set why_msg "missing runtime threads library"
1306 pass "successfully compiled posix threads test case"
1312 if {!$built_binfile} {
1313 unsupported "Couldn't compile $source: ${why_msg}"
1318 # This is just like gdb_compile_pthreads, above, except that we always add the
1319 # objc library for compiling Objective-C programs
1320 proc gdb_compile_objc {source dest type options} {
1322 set why_msg "unrecognized error"
1323 foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} {
1324 # This kind of wipes out whatever libs the caller may have
1325 # set. Or maybe theirs will override ours. How infelicitous.
1326 if { $lib == "solaris" } {
1327 set lib "-lpthread -lposix4"
1329 if { $lib != "-lobjc" } {
1330 set lib "-lobjc $lib"
1332 set options_with_lib [concat $options [list libs=$lib quiet]]
1333 set ccout [gdb_compile $source $dest $type $options_with_lib]
1334 switch -regexp -- $ccout {
1335 ".*no posix threads support.*" {
1336 set why_msg "missing threads include file"
1339 ".*cannot open -lpthread.*" {
1340 set why_msg "missing runtime threads library"
1342 ".*Can't find library for -lpthread.*" {
1343 set why_msg "missing runtime threads library"
1346 pass "successfully compiled objc with posix threads test case"
1352 if {!$built_binfile} {
1353 unsupported "Couldn't compile $source: ${why_msg}"
1358 proc send_gdb { string } {
1359 global suppress_flag;
1360 if { $suppress_flag } {
1361 return "suppressed";
1363 return [remote_send host "$string"];
1369 proc gdb_expect { args } {
1370 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
1371 set gtimeout [lindex $args 0];
1372 set expcode [list [lindex $args 1]];
1374 upvar timeout timeout;
1377 if [target_info exists gdb,timeout] {
1378 if [info exists timeout] {
1379 if { $timeout < [target_info gdb,timeout] } {
1380 set gtimeout [target_info gdb,timeout];
1382 set gtimeout $timeout;
1385 set gtimeout [target_info gdb,timeout];
1389 if ![info exists gtimeout] {
1391 if [info exists timeout] {
1392 set gtimeout $timeout;
1399 global suppress_flag;
1400 global remote_suppress_flag;
1401 if [info exists remote_suppress_flag] {
1402 set old_val $remote_suppress_flag;
1404 if [info exists suppress_flag] {
1405 if { $suppress_flag } {
1406 set remote_suppress_flag 1;
1410 {uplevel remote_expect host $gtimeout $expcode} string];
1411 if [info exists old_val] {
1412 set remote_suppress_flag $old_val;
1414 if [info exists remote_suppress_flag] {
1415 unset remote_suppress_flag;
1420 global errorInfo errorCode;
1422 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
1423 } elseif {$code == 2} {
1424 return -code return $string
1425 } elseif {$code == 3} {
1427 } elseif {$code > 4} {
1428 return -code $code $string
1432 # gdb_expect_list MESSAGE SENTINEL LIST -- expect a sequence of outputs
1434 # Check for long sequence of output by parts.
1435 # MESSAGE: is the test message to be printed with the test success/fail.
1436 # SENTINEL: Is the terminal pattern indicating that output has finished.
1437 # LIST: is the sequence of outputs to match.
1438 # If the sentinel is recognized early, it is considered an error.
1441 # 1 if the test failed,
1442 # 0 if the test passes,
1443 # -1 if there was an internal error.
1445 proc gdb_expect_list {test sentinel list} {
1447 global suppress_flag
1450 if { $suppress_flag } {
1452 unresolved "${test}"
1454 while { ${index} < [llength ${list}] } {
1455 set pattern [lindex ${list} ${index}]
1456 set index [expr ${index} + 1]
1457 if { ${index} == [llength ${list}] } {
1460 -re "${pattern}${sentinel}" {
1461 # pass "${test}, pattern ${index} + sentinel"
1464 fail "${test} (pattern ${index} + sentinel)"
1468 fail "${test} (pattern ${index} + sentinel) (timeout)"
1473 # unresolved "${test}, pattern ${index} + sentinel"
1479 # pass "${test}, pattern ${index}"
1482 fail "${test} (pattern ${index})"
1486 fail "${test} (pattern ${index}) (timeout)"
1491 # unresolved "${test}, pattern ${index}"
1505 proc gdb_suppress_entire_file { reason } {
1506 global suppress_flag;
1508 warning "$reason\n";
1509 set suppress_flag -1;
1513 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
1514 # gdb_expect to fail immediately (until the next call to
1515 # gdb_stop_suppressing_tests).
1517 proc gdb_suppress_tests { args } {
1518 global suppress_flag;
1520 return; # fnf - disable pending review of results where
1521 # testsuite ran better without this
1524 if { $suppress_flag == 1 } {
1525 if { [llength $args] > 0 } {
1526 warning "[lindex $args 0]\n";
1528 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
1534 # Clear suppress_flag.
1536 proc gdb_stop_suppressing_tests { } {
1537 global suppress_flag;
1539 if [info exists suppress_flag] {
1540 if { $suppress_flag > 0 } {
1541 set suppress_flag 0;
1542 clone_output "Tests restarted.\n";
1545 set suppress_flag 0;
1549 proc gdb_clear_suppressed { } {
1550 global suppress_flag;
1552 set suppress_flag 0;
1555 proc gdb_start { } {
1560 catch default_gdb_exit
1564 # gdb_load -- load a file into the debugger.
1565 # return a -1 if anything goes wrong.
1567 proc gdb_load { arg } {
1568 return [gdb_file_cmd $arg]
1571 proc gdb_continue { function } {
1574 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
1577 proc default_gdb_init { args } {
1578 global gdb_wrapper_initialized
1580 gdb_clear_suppressed;
1582 # Make sure that the wrapper is rebuilt
1583 # with the appropriate multilib option.
1584 set gdb_wrapper_initialized 0
1586 # Uh, this is lame. Really, really, really lame. But there's this *one*
1587 # testcase that will fail in random places if we don't increase this.
1590 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
1591 if { [llength $args] > 0 } {
1594 set file [lindex $args 0];
1596 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
1599 if [target_info exists gdb_prompt] {
1600 set gdb_prompt [target_info gdb_prompt];
1602 set gdb_prompt "\\(gdb\\)"
1606 proc gdb_init { args } {
1607 return [eval default_gdb_init $args];
1610 proc gdb_finish { } {
1615 set debug_format "unknown"
1617 # Run the gdb command "info source" and extract the debugging format
1618 # information from the output and save it in debug_format.
1620 proc get_debug_format { } {
1626 set debug_format "unknown"
1627 send_gdb "info source\n"
1629 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
1630 set debug_format $expect_out(1,string)
1631 verbose "debug format is $debug_format"
1634 -re "No current source file.\r\n$gdb_prompt $" {
1635 perror "get_debug_format used when no current source file"
1638 -re "$gdb_prompt $" {
1639 warning "couldn't check debug format (no valid response)."
1643 warning "couldn't check debug format (timed out)."
1649 # Return true if FORMAT matches the debug format the current test was
1650 # compiled with. FORMAT is a shell-style globbing pattern; it can use
1651 # `*', `[...]', and so on.
1653 # This function depends on variables set by `get_debug_format', above.
1655 proc test_debug_format {format} {
1658 return [expr [string match $format $debug_format] != 0]
1661 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
1662 # COFF, stabs, etc). If that format matches the format that the
1663 # current test was compiled with, then the next test is expected to
1664 # fail for any target. Returns 1 if the next test or set of tests is
1665 # expected to fail, 0 otherwise (or if it is unknown). Must have
1666 # previously called get_debug_format.
1667 proc setup_xfail_format { format } {
1668 set ret [test_debug_format $format];
1676 proc gdb_step_for_stub { } {
1679 if ![target_info exists gdb,use_breakpoint_for_stub] {
1680 if [target_info exists gdb_stub_step_command] {
1681 set command [target_info gdb_stub_step_command];
1685 send_gdb "${command}\n";
1688 -re "(main.* at |.*in .*start).*$gdb_prompt" {
1691 -re ".*$gdb_prompt" {
1693 if { $tries == 5 } {
1694 fail "stepping out of breakpoint function";
1697 send_gdb "${command}\n";
1701 fail "stepping out of breakpoint function";
1708 -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" {
1709 set file $expect_out(1,string);
1710 set linenum [expr $expect_out(2,string) + 1];
1711 set breakplace "${file}:${linenum}";
1715 send_gdb "break ${breakplace}\n";
1717 -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" {
1718 set breakpoint $expect_out(1,string);
1720 -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" {
1721 set breakpoint $expect_out(1,string);
1725 send_gdb "continue\n";
1727 -re "Breakpoint ${breakpoint},.*$gdb_prompt" {
1728 gdb_test "delete $breakpoint" ".*" "";
1735 ### gdb_get_line_number TEXT [FILE]
1737 ### Search the source file FILE, and return the line number of a line
1738 ### containing TEXT. Use this function instead of hard-coding line
1739 ### numbers into your test script.
1741 ### Specifically, this function uses GDB's "search" command to search
1742 ### FILE for the first line containing TEXT, and returns its line
1743 ### number. Thus, FILE must be a source file, compiled into the
1744 ### executable you are running. If omitted, FILE defaults to the
1745 ### value of the global variable `srcfile'; most test scripts set
1746 ### `srcfile' appropriately at the top anyway.
1748 ### Use this function to keep your test scripts independent of the
1749 ### exact line numbering of the source file. Don't write:
1751 ### send_gdb "break 20"
1753 ### This means that if anyone ever edits your test's source file,
1754 ### your test could break. Instead, put a comment like this on the
1755 ### source file line you want to break at:
1757 ### /* breakpoint spot: frotz.exp: test name */
1759 ### and then write, in your test script (which we assume is named
1762 ### send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
1764 ### (Yes, Tcl knows how to handle the nested quotes and brackets.
1767 ### % puts "foo [lindex "bar baz" 1]"
1770 ### Tcl is quite clever, for a little stringy language.)
1772 proc gdb_get_line_number {text {file /omitted/}} {
1776 if {! [string compare $file /omitted/]} {
1781 gdb_test "list ${file}:1,1" ".*" ""
1782 send_gdb "search ${text}\n"
1784 -re "\[\r\n\]+(\[0-9\]+)\[ \t\].*${text}.*$gdb_prompt $" {
1785 set result $expect_out(1,string)
1787 -re ".*$gdb_prompt $" {
1788 fail "find line number containing \"${text}\""
1791 fail "find line number containing \"${text}\" (timeout)"
1797 # gdb_continue_to_end:
1798 # The case where the target uses stubs has to be handled specially. If a
1799 # stub is used, we set a breakpoint at exit because we cannot rely on
1800 # exit() behavior of a remote target.
1802 # mssg is the error message that gets printed.
1804 proc gdb_continue_to_end {mssg} {
1805 if [target_info exists use_gdb_stub] {
1806 if {![gdb_breakpoint "exit"]} {
1809 gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \
1810 "continue until exit at $mssg"
1812 # Continue until we exit. Should not stop again.
1813 # Don't bother to check the output of the program, that may be
1814 # extremely tough for some remote systems.
1815 gdb_test "continue"\
1816 "Continuing.\[\r\n0-9\]+(... EXIT code 0\[\r\n\]+|Program exited normally\\.).*"\
1817 "continue until exit at $mssg"
1821 proc rerun_to_main {} {
1824 if [target_info exists use_gdb_stub] {
1827 -re ".*Breakpoint .*main .*$gdb_prompt $"\
1828 {pass "rerun to main" ; return 0}
1829 -re "$gdb_prompt $"\
1830 {fail "rerun to main" ; return 0}
1831 timeout {fail "(timeout) rerun to main" ; return 0}
1836 -re "The program .* has been started already.*y or n. $" {
1840 -re "Starting program.*$gdb_prompt $"\
1841 {pass "rerun to main" ; return 0}
1842 -re "$gdb_prompt $"\
1843 {fail "rerun to main" ; return 0}
1844 timeout {fail "(timeout) rerun to main" ; return 0}
1849 # Print a message and return true if a test should be skipped
1850 # due to lack of floating point suport.
1852 proc gdb_skip_float_test { msg } {
1853 if [target_info exists gdb,skip_float_tests] {
1854 verbose "Skipping test '$msg': no float tests.";
1860 # Print a message and return true if a test should be skipped
1861 # due to lack of stdio support.
1863 proc gdb_skip_stdio_test { msg } {
1864 if [target_info exists gdb,noinferiorio] {
1865 verbose "Skipping test '$msg': no inferior i/o.";
1871 proc gdb_skip_bogus_test { msg } {
1876 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
1877 # ${binfile}.dbglnk, which is just like the executable ($binfile) but without
1878 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
1879 # the name of a idebuginfo only file. This file will be stored in the
1880 # gdb.base/.debug subdirectory.
1882 # Functions for separate debug info testing
1884 # starting with an executable:
1885 # foo --> original executable
1887 # at the end of the process we have:
1888 # foo.stripped --> foo w/o debug info
1889 # .debug/foo.debug --> foo's debug info
1890 # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug.
1892 # Return the name of the file in which we should stor EXEC's separated
1893 # debug info. EXEC contains the full path.
1894 proc separate_debug_filename { exec } {
1896 # In a .debug subdirectory off the same directory where the testcase
1897 # executable is going to be. Something like:
1898 # <your-path>/gdb/testsuite/gdb.base/.debug/blah.debug.
1899 # This is the default location where gdb expects to findi
1900 # the debug info file.
1902 set exec_dir [file dirname $exec]
1903 set exec_file [file tail $exec]
1904 set debug_dir [file join $exec_dir ".debug"]
1905 set debug_file [file join $debug_dir "${exec_file}.debug"]
1911 proc gdb_gnu_strip_debug { dest } {
1913 set debug_file [separate_debug_filename $dest]
1914 set strip_to_file_program strip
1915 set objcopy_program objcopy
1917 # Make sure the directory that will hold the separated debug
1918 # info actually exists.
1919 set debug_dir [file dirname $debug_file]
1920 if {! [file isdirectory $debug_dir]} {
1921 file mkdir $debug_dir
1924 set debug_link [file tail $debug_file]
1925 set stripped_file "${dest}.stripped"
1927 # Get rid of the debug info, and store result in stripped_file
1928 # something like gdb/testsuite/gdb.base/blah.stripped.
1929 set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
1930 verbose "result is $result"
1931 verbose "output is $output"
1936 # Get rid of everything but the debug info, and store result in debug_file
1937 # This will be in the .debug subdirectory, see above.
1938 set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
1939 verbose "result is $result"
1940 verbose "output is $output"
1945 # Link the two previous output files together, adding the .gnu_debuglink
1946 # section to the stripped_file, containing a pointer to the debug_file,
1947 # save the new file in dest.
1948 # This will be the regular executable filename, in the usual location.
1949 set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
1950 verbose "result is $result"
1951 verbose "output is $output"