1 # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
2 # 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # This file was written by Fred Fish. (fnf@cygnus.com)
20 # Generic gdb subroutines that should work for any target. If these
21 # need to be modified for any target, it can be done with a variable
22 # or by passing arguments.
25 # Tests would fail, logs on get_compiler_info() would be missing.
26 send_error "`site.exp' not found, run `make site.exp'!\n"
34 if [info exists TOOL_EXECUTABLE] {
35 set GDB $TOOL_EXECUTABLE;
37 if ![info exists GDB] {
38 if ![is_remote host] {
39 set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]]
41 set GDB [transform gdb];
44 verbose "using GDB = $GDB" 2
47 if ![info exists GDBFLAGS] {
50 verbose "using GDBFLAGS = $GDBFLAGS" 2
52 # The variable gdb_prompt is a regexp which matches the gdb prompt.
53 # Set it if it is not already set.
55 if ![info exists gdb_prompt] then {
56 set gdb_prompt "\[(\]gdb\[)\]"
59 # The variable fullname_syntax_POSIX is a regexp which matches a POSIX
60 # absolute path ie. /foo/
61 set fullname_syntax_POSIX "/.*/"
62 # The variable fullname_syntax_UNC is a regexp which matches a Windows
63 # UNC path ie. \\D\foo\
64 set fullname_syntax_UNC {\\\\[^\\]+\\.+\\}
65 # The variable fullname_syntax_DOS_CASE is a regexp which matches a
66 # particular DOS case that GDB most likely will output
67 # ie. \foo\, but don't match \\.*\
68 set fullname_syntax_DOS_CASE {\\[^\\].*\\}
69 # The variable fullname_syntax_DOS is a regexp which matches a DOS path
70 # ie. a:\foo\ && a:foo\
71 set fullname_syntax_DOS {[a-zA-Z]:.*\\}
72 # The variable fullname_syntax is a regexp which matches what GDB considers
73 # an absolute path. It is currently debatable if the Windows style paths
74 # d:foo and \abc should be considered valid as an absolute path.
75 # Also, the purpse of this regexp is not to recognize a well formed
76 # absolute path, but to say with certainty that a path is absolute.
77 set fullname_syntax "($fullname_syntax_POSIX|$fullname_syntax_UNC|$fullname_syntax_DOS_CASE|$fullname_syntax_DOS)"
79 # Needed for some tests under Cygwin.
83 if ![info exists env(EXEEXT)] {
86 set EXEEXT $env(EXEEXT)
89 ### Only procedures should come after this point.
92 # gdb_version -- extract and print the version number of GDB
94 proc default_gdb_version {} {
98 set fileid [open "gdb_cmd" w];
101 set cmdfile [remote_download host "gdb_cmd"];
102 set output [remote_exec host "$GDB -nw --command $cmdfile"]
103 remote_file build delete "gdb_cmd";
104 remote_file host delete "$cmdfile";
105 set tmp [lindex $output 1];
107 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
108 if ![is_remote host] {
109 clone_output "[which $GDB] version $version $GDBFLAGS\n"
111 clone_output "$GDB on remote host version $version $GDBFLAGS\n"
115 proc gdb_version { } {
116 return [default_gdb_version];
120 # gdb_unload -- unload a file if one is loaded
129 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
130 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
131 -re "A program is being debugged already..*Kill it.*y or n. $"\
133 verbose "\t\tKilling previous program being debugged"
136 -re "Discard symbol table from .*y or n.*$" {
140 -re "$gdb_prompt $" {}
142 perror "couldn't unload file in $GDB (timed out)."
148 # Many of the tests depend on setting breakpoints at various places and
149 # running until that breakpoint is reached. At times, we want to start
150 # with a clean-slate with respect to breakpoints, so this utility proc
151 # lets us do this without duplicating this code everywhere.
154 proc delete_breakpoints {} {
157 # we need a larger timeout value here or this thing just confuses
158 # itself. May need a better implementation if possible. - guo
160 send_gdb "delete breakpoints\n"
162 -re "Delete all breakpoints.*y or n.*$" {
166 -re "$gdb_prompt $" { # This happens if there were no breakpoints
168 timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
170 send_gdb "info breakpoints\n"
172 -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
173 -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
174 -re "Delete all breakpoints.*or n.*$" {
178 timeout { perror "info breakpoints (timeout)" ; return }
184 # Generic run command.
186 # The second pattern below matches up to the first newline *only*.
187 # Using ``.*$'' could swallow up output that we attempt to match
190 proc gdb_run_cmd {args} {
193 if [target_info exists gdb_init_command] {
194 send_gdb "[target_info gdb_init_command]\n";
196 -re "$gdb_prompt $" { }
198 perror "gdb_init_command for target failed";
204 if [target_info exists use_gdb_stub] {
205 if [target_info exists gdb,do_reload_on_run] {
206 if { [gdb_reload] != 0 } {
209 send_gdb "continue\n";
211 -re "Continu\[^\r\n\]*\[\r\n\]" {}
217 if [target_info exists gdb,start_symbol] {
218 set start [target_info gdb,start_symbol];
222 send_gdb "jump *$start\n"
224 while { $start_attempt } {
225 # Cap (re)start attempts at three to ensure that this loop
226 # always eventually fails. Don't worry about trying to be
227 # clever and not send a command when it has failed.
228 if [expr $start_attempt > 3] {
229 perror "Jump to start() failed (retry count exceeded)";
232 set start_attempt [expr $start_attempt + 1];
234 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
237 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
238 perror "Can't find start symbol to run in gdb_run";
241 -re "No symbol \"start\" in current.*$gdb_prompt $" {
242 send_gdb "jump *_start\n";
244 -re "No symbol.*context.*$gdb_prompt $" {
247 -re "Line.* Jump anyway.*y or n. $" {
250 -re "The program is not being run.*$gdb_prompt $" {
251 if { [gdb_reload] != 0 } {
254 send_gdb "jump *$start\n";
257 perror "Jump to start() failed (timeout)";
262 if [target_info exists gdb_stub] {
264 -re "$gdb_prompt $" {
265 send_gdb "continue\n"
272 if [target_info exists gdb,do_reload_on_run] {
273 if { [gdb_reload] != 0 } {
277 send_gdb "run $args\n"
278 # This doesn't work quite right yet.
280 -re "The program .* has been started already.*y or n. $" {
284 # Use -notransfer here so that test cases (like chng-sym.exp)
285 # may test for additional start-up messages.
286 -notransfer -re "Starting program: \[^\r\n\]*" {}
290 # Generic start command. Return 0 if we could start the program, -1
293 proc gdb_start_cmd {args} {
296 if [target_info exists gdb_init_command] {
297 send_gdb "[target_info gdb_init_command]\n";
299 -re "$gdb_prompt $" { }
301 perror "gdb_init_command for target failed";
307 if [target_info exists use_gdb_stub] {
311 send_gdb "start $args\n"
313 -re "The program .* has been started already.*y or n. $" {
317 # Use -notransfer here so that test cases (like chng-sym.exp)
318 # may test for additional start-up messages.
319 -notransfer -re "Starting program: \[^\r\n\]*" {
326 # Set a breakpoint at FUNCTION. If there is an additional argument it is
327 # a list of options; the only currently supported option is allow-pending.
329 proc gdb_breakpoint { function args } {
333 set pending_response n
334 if {[lsearch -exact [lindex $args 0] allow-pending] != -1} {
335 set pending_response y
338 send_gdb "break $function\n"
339 # The first two regexps are what we get with -g, the third is without -g.
341 -re "Breakpoint \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
342 -re "Breakpoint \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
343 -re "Breakpoint \[0-9\]* at .*$gdb_prompt $" {}
344 -re "Breakpoint \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" {
345 if {$pending_response == "n"} {
346 fail "setting breakpoint at $function"
350 -re "Make breakpoint pending.*y or \\\[n\\\]. $" {
351 send_gdb "$pending_response\n"
354 -re "$gdb_prompt $" { fail "setting breakpoint at $function" ; return 0 }
355 timeout { fail "setting breakpoint at $function (timeout)" ; return 0 }
360 # Set breakpoint at function and run gdb until it breaks there.
361 # Since this is the only breakpoint that will be set, if it stops
362 # at a breakpoint, we will assume it is the one we want. We can't
363 # just compare to "function" because it might be a fully qualified,
364 # single quoted C++ function specifier. If there's an additional argument,
365 # pass it to gdb_breakpoint.
367 proc runto { function args } {
373 if ![gdb_breakpoint $function [lindex $args 0]] {
379 # the "at foo.c:36" output we get with -g.
380 # the "in func" output we get without -g.
382 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
385 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
388 -re "$gdb_prompt $" {
389 fail "running to $function in runto"
393 fail "running to $function in runto (timeout)"
401 # runto_main -- ask gdb to run until we hit a breakpoint at main.
402 # The case where the target uses stubs has to be handled
403 # specially--if it uses stubs, assuming we hit
404 # breakpoint() and just step out of the function.
406 proc runto_main { } {
410 if ![target_info exists gdb_stub] {
422 ### Continue, and expect to hit a breakpoint.
423 ### Report a pass or fail, depending on whether it seems to have
424 ### worked. Use NAME as part of the test name; each call to
425 ### continue_to_breakpoint should use a NAME which is unique within
427 proc gdb_continue_to_breakpoint {name} {
429 set full_name "continue to breakpoint: $name"
431 send_gdb "continue\n"
433 -re "Breakpoint .* at .*\r\n$gdb_prompt $" {
436 -re ".*$gdb_prompt $" {
440 fail "$full_name (timeout)"
446 # gdb_internal_error_resync:
448 # Answer the questions GDB asks after it reports an internal error
449 # until we get back to a GDB prompt. Decline to quit the debugging
450 # session, and decline to create a core file. Return non-zero if the
453 # This procedure just answers whatever questions come up until it sees
454 # a GDB prompt; it doesn't require you to have matched the input up to
455 # any specific point. However, it only answers questions it sees in
456 # the output itself, so if you've matched a question, you had better
457 # answer it yourself before calling this.
459 # You can use this function thus:
463 # -re ".*A problem internal to GDB has been detected" {
464 # gdb_internal_error_resync
469 proc gdb_internal_error_resync {} {
473 while {$count < 10} {
475 -re "Quit this debugging session\\? \\(y or n\\) $" {
479 -re "Create a core file of GDB\\? \\(y or n\\) $" {
483 -re "$gdb_prompt $" {
484 # We're resynchronized.
488 perror "Could not resync from internal error (timeout)"
493 perror "Could not resync from internal error (resync count exceeded)"
498 # gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS
499 # Send a command to gdb; test the result.
501 # COMMAND is the command to execute, send to GDB with send_gdb. If
502 # this is the null string no command is sent.
503 # MESSAGE is a message to be printed with the built-in failure patterns
504 # if one of them matches. If MESSAGE is empty COMMAND will be used.
505 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
506 # patterns. Pattern elements will be evaluated in the caller's
507 # context; action elements will be executed in the caller's context.
508 # Unlike patterns for gdb_test, these patterns should generally include
509 # the final newline and prompt.
512 # 1 if the test failed, according to a built-in failure pattern
513 # 0 if only user-supplied patterns matched
514 # -1 if there was an internal error.
516 # You can use this function thus:
518 # gdb_test_multiple "print foo" "test foo" {
519 # -re "expected output 1" {
522 # -re "expected output 2" {
527 # The standard patterns, such as "Program exited..." and "A problem
528 # ...", all being implicitly appended to that list.
530 proc gdb_test_multiple { command message user_code } {
534 upvar timeout timeout
535 upvar expect_out expect_out
537 if { $message == "" } {
541 # TCL/EXPECT WART ALERT
542 # Expect does something very strange when it receives a single braced
543 # argument. It splits it along word separators and performs substitutions.
544 # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
545 # evaluated as "\[ab\]". But that's not how TCL normally works; inside a
546 # double-quoted list item, "\[ab\]" is just a long way of representing
547 # "[ab]", because the backslashes will be removed by lindex.
549 # Unfortunately, there appears to be no easy way to duplicate the splitting
550 # that expect will do from within TCL. And many places make use of the
551 # "\[0-9\]" construct, so we need to support that; and some places make use
552 # of the "[func]" construct, so we need to support that too. In order to
553 # get this right we have to substitute quoted list elements differently
554 # from braced list elements.
556 # We do this roughly the same way that Expect does it. We have to use two
557 # lists, because if we leave unquoted newlines in the argument to uplevel
558 # they'll be treated as command separators, and if we escape newlines
559 # we mangle newlines inside of command blocks. This assumes that the
560 # input doesn't contain a pattern which contains actual embedded newlines
563 regsub -all {\n} ${user_code} { } subst_code
564 set subst_code [uplevel list $subst_code]
566 set processed_code ""
568 set expecting_action 0
569 foreach item $user_code subst_item $subst_code {
570 if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } {
571 lappend processed_code $item
574 if {$item == "-indices" || $item == "-re" || $item == "-ex"} {
575 lappend processed_code $item
578 if { $expecting_action } {
579 lappend processed_code "uplevel [list $item]"
580 set expecting_action 0
581 # Cosmetic, no effect on the list.
582 append processed_code "\n"
585 set expecting_action 1
586 lappend processed_code $subst_item
587 if {$patterns != ""} {
590 append patterns "\"$subst_item\""
593 # Also purely cosmetic.
594 regsub -all {\r} $patterns {\\r} patterns
595 regsub -all {\n} $patterns {\\n} patterns
598 send_user "Sending \"$command\" to gdb\n"
599 send_user "Looking to match \"$patterns\"\n"
600 send_user "Message is \"$message\"\n"
604 set string "${command}\n";
605 if { $command != "" } {
606 while { "$string" != "" } {
607 set foo [string first "\n" "$string"];
608 set len [string length "$string"];
609 if { $foo < [expr $len - 1] } {
610 set str [string range "$string" 0 $foo];
611 if { [send_gdb "$str"] != "" } {
612 global suppress_flag;
614 if { ! $suppress_flag } {
615 perror "Couldn't send $command to GDB.";
620 # since we're checking if each line of the multi-line
621 # command are 'accepted' by GDB here,
622 # we need to set -notransfer expect option so that
623 # command output is not lost for pattern matching
626 -notransfer -re "\[\r\n\]" { verbose "partial: match" 3 }
627 timeout { verbose "partial: timeout" 3 }
629 set string [string range "$string" [expr $foo + 1] end];
634 if { "$string" != "" } {
635 if { [send_gdb "$string"] != "" } {
636 global suppress_flag;
638 if { ! $suppress_flag } {
639 perror "Couldn't send $command to GDB.";
647 if [target_info exists gdb,timeout] {
648 set tmt [target_info gdb,timeout];
650 if [info exists timeout] {
654 if [info exists timeout] {
663 -re ".*A problem internal to GDB has been detected" {
664 fail "$message (GDB internal error)"
665 gdb_internal_error_resync
667 -re "\\*\\*\\* DOSEXIT code.*" {
668 if { $message != "" } {
671 gdb_suppress_entire_file "GDB died";
675 append code $processed_code
677 -re "Ending remote debugging.*$gdb_prompt $" {
678 if ![isnative] then {
679 warning "Can`t communicate to remote target."
685 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
686 perror "Undefined command \"$command\"."
690 -re "Ambiguous command.*$gdb_prompt $" {
691 perror "\"$command\" is not a unique command name."
695 -re "Program exited with code \[0-9\]+.*$gdb_prompt $" {
696 if ![string match "" $message] then {
697 set errmsg "$message (the program exited)"
699 set errmsg "$command (the program exited)"
704 -re "EXIT code \[0-9\r\n\]+Program exited normally.*$gdb_prompt $" {
705 if ![string match "" $message] then {
706 set errmsg "$message (the program exited)"
708 set errmsg "$command (the program exited)"
713 -re "The program is not being run.*$gdb_prompt $" {
714 if ![string match "" $message] then {
715 set errmsg "$message (the program is no longer running)"
717 set errmsg "$command (the program is no longer running)"
722 -re "\r\n$gdb_prompt $" {
723 if ![string match "" $message] then {
730 perror "Window too small."
734 -re "\\(y or n\\) " {
736 perror "Got interactive prompt."
741 perror "Process no longer exists"
742 if { $message != "" } {
748 perror "internal buffer is full."
753 if ![string match "" $message] then {
754 fail "$message (timeout)"
761 set code [catch {gdb_expect $tmt $code} string]
763 global errorInfo errorCode;
764 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
765 } elseif {$code == 2} {
766 return -code return $string
767 } elseif {$code == 3} {
769 } elseif {$code > 4} {
770 return -code $code $string
775 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
776 # Send a command to gdb; test the result.
778 # COMMAND is the command to execute, send to GDB with send_gdb. If
779 # this is the null string no command is sent.
780 # PATTERN is the pattern to match for a PASS, and must NOT include
781 # the \r\n sequence immediately before the gdb prompt.
782 # MESSAGE is an optional message to be printed. If this is
783 # omitted, then the pass/fail messages use the command string as the
784 # message. (If this is the empty string, then sometimes we don't
785 # call pass or fail at all; I don't understand this at all.)
786 # QUESTION is a question GDB may ask in response to COMMAND, like
788 # RESPONSE is the response to send if QUESTION appears.
791 # 1 if the test failed,
792 # 0 if the test passes,
793 # -1 if there was an internal error.
795 proc gdb_test { args } {
799 upvar timeout timeout
801 if [llength $args]>2 then {
802 set message [lindex $args 2]
804 set message [lindex $args 0]
806 set command [lindex $args 0]
807 set pattern [lindex $args 1]
809 if [llength $args]==5 {
810 set question_string [lindex $args 3];
811 set response_string [lindex $args 4];
813 set question_string "^FOOBAR$"
816 return [gdb_test_multiple $command $message {
817 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
818 if ![string match "" $message] then {
822 -re "(${question_string})$" {
823 send_gdb "$response_string\n";
829 # Test that a command gives an error. For pass or fail, return
830 # a 1 to indicate that more tests can proceed. However a timeout
831 # is a serious error, generates a special fail message, and causes
832 # a 0 to be returned to indicate that more tests are likely to fail
835 proc test_print_reject { args } {
839 if [llength $args]==2 then {
840 set expectthis [lindex $args 1]
842 set expectthis "should never match this bogus string"
844 set sendthis [lindex $args 0]
846 send_user "Sending \"$sendthis\" to gdb\n"
847 send_user "Looking to match \"$expectthis\"\n"
849 send_gdb "$sendthis\n"
850 #FIXME: Should add timeout as parameter.
852 -re "A .* in expression.*\\.*$gdb_prompt $" {
853 pass "reject $sendthis"
856 -re "Invalid syntax in expression.*$gdb_prompt $" {
857 pass "reject $sendthis"
860 -re "Junk after end of expression.*$gdb_prompt $" {
861 pass "reject $sendthis"
864 -re "Invalid number.*$gdb_prompt $" {
865 pass "reject $sendthis"
868 -re "Invalid character constant.*$gdb_prompt $" {
869 pass "reject $sendthis"
872 -re "No symbol table is loaded.*$gdb_prompt $" {
873 pass "reject $sendthis"
876 -re "No symbol .* in current context.*$gdb_prompt $" {
877 pass "reject $sendthis"
880 -re "Unmatched single quote.*$gdb_prompt $" {
881 pass "reject $sendthis"
884 -re "A character constant must contain at least one character.*$gdb_prompt $" {
885 pass "reject $sendthis"
888 -re "$expectthis.*$gdb_prompt $" {
889 pass "reject $sendthis"
892 -re ".*$gdb_prompt $" {
893 fail "reject $sendthis"
897 fail "reject $sendthis (eof or timeout)"
903 # Given an input string, adds backslashes as needed to create a
904 # regexp that will match the string.
906 proc string_to_regexp {str} {
908 regsub -all {[]*+.|()^$\[\\]} $str {\\&} result
912 # Same as gdb_test, but the second parameter is not a regexp,
913 # but a string that must match exactly.
915 proc gdb_test_exact { args } {
916 upvar timeout timeout
918 set command [lindex $args 0]
920 # This applies a special meaning to a null string pattern. Without
921 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
922 # messages from commands that should have no output except a new
923 # prompt. With this, only results of a null string will match a null
926 set pattern [lindex $args 1]
927 if [string match $pattern ""] {
928 set pattern [string_to_regexp [lindex $args 0]]
930 set pattern [string_to_regexp [lindex $args 1]]
933 # It is most natural to write the pattern argument with only
934 # embedded \n's, especially if you are trying to avoid Tcl quoting
935 # problems. But gdb_expect really wants to see \r\n in patterns. So
936 # transform the pattern here. First transform \r\n back to \n, in
937 # case some users of gdb_test_exact already do the right thing.
938 regsub -all "\r\n" $pattern "\n" pattern
939 regsub -all "\n" $pattern "\r\n" pattern
940 if [llength $args]==3 then {
941 set message [lindex $args 2]
946 return [gdb_test $command $pattern $message]
949 proc gdb_reinitialize_dir { subdir } {
952 if [is_remote host] {
957 -re "Reinitialize source path to empty.*y or n. " {
960 -re "Source directories searched.*$gdb_prompt $" {
961 send_gdb "dir $subdir\n"
963 -re "Source directories searched.*$gdb_prompt $" {
964 verbose "Dir set to $subdir"
966 -re "$gdb_prompt $" {
967 perror "Dir \"$subdir\" failed."
971 -re "$gdb_prompt $" {
972 perror "Dir \"$subdir\" failed."
976 -re "$gdb_prompt $" {
977 perror "Dir \"$subdir\" failed."
983 # gdb_exit -- exit the GDB, killing the target program if necessary
985 proc default_gdb_exit {} {
991 gdb_stop_suppressing_tests;
993 if ![info exists gdb_spawn_id] {
997 verbose "Quitting $GDB $GDBFLAGS"
999 if { [is_remote host] && [board_info host exists fileid] } {
1006 -re "DOSEXIT code" { }
1011 if ![is_remote host] {
1017 # Load a file into the debugger.
1018 # The return value is 0 for success, -1 for failure.
1020 # This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO
1021 # to one of these values:
1023 # debug file was loaded successfully and has debug information
1024 # nodebug file was loaded successfully and has no debug information
1025 # fail file was not loaded
1027 # I tried returning this information as part of the return value,
1028 # but ran into a mess because of the many re-implementations of
1029 # gdb_load in config/*.exp.
1031 # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use
1032 # this if they can get more information set.
1034 proc gdb_file_cmd { arg } {
1038 global last_loaded_file
1040 set last_loaded_file $arg
1042 # Set whether debug info was found.
1043 # Default to "fail".
1044 global gdb_file_cmd_debug_info
1045 set gdb_file_cmd_debug_info "fail"
1047 if [is_remote host] {
1048 set arg [remote_download host $arg]
1050 perror "download failed"
1055 # The file command used to kill the remote target. For the benefit
1056 # of the testsuite, preserve this behavior.
1059 -re "Kill the program being debugged. .y or n. $" {
1061 verbose "\t\tKilling previous program being debugged"
1064 -re "$gdb_prompt $" {
1069 send_gdb "file $arg\n"
1071 -re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" {
1072 verbose "\t\tLoaded $arg into the $GDB with no debugging symbols"
1073 set gdb_file_cmd_debug_info "nodebug"
1076 -re "Reading symbols from.*done.*$gdb_prompt $" {
1077 verbose "\t\tLoaded $arg into the $GDB"
1078 set gdb_file_cmd_debug_info "debug"
1081 -re "Load new symbol table from \".*\".*y or n. $" {
1084 -re "Reading symbols from.*done.*$gdb_prompt $" {
1085 verbose "\t\tLoaded $arg with new symbol table into $GDB"
1086 set gdb_file_cmd_debug_info "debug"
1090 perror "(timeout) Couldn't load $arg, other program already loaded."
1095 -re "No such file or directory.*$gdb_prompt $" {
1096 perror "($arg) No such file or directory"
1099 -re "$gdb_prompt $" {
1100 perror "couldn't load $arg into $GDB."
1104 perror "couldn't load $arg into $GDB (timed out)."
1108 # This is an attempt to detect a core dump, but seems not to
1109 # work. Perhaps we need to match .* followed by eof, in which
1110 # gdb_expect does not seem to have a way to do that.
1111 perror "couldn't load $arg into $GDB (end of file)."
1118 # start gdb -- start gdb running, default procedure
1120 # When running over NFS, particularly if running many simultaneous
1121 # tests on different hosts all using the same server, things can
1122 # get really slow. Give gdb at least 3 minutes to start up.
1124 proc default_gdb_start { } {
1130 global gdb_spawn_id;
1132 gdb_stop_suppressing_tests;
1134 verbose "Spawning $GDB -nw $GDBFLAGS"
1136 if [info exists gdb_spawn_id] {
1140 if ![is_remote host] {
1141 if { [which $GDB] == 0 } then {
1142 perror "$GDB does not exist."
1146 set res [remote_spawn host "$GDB -nw $GDBFLAGS [host_info gdb_opts]"];
1147 if { $res < 0 || $res == "" } {
1148 perror "Spawning $GDB failed."
1152 -re "\[\r\n\]$gdb_prompt $" {
1153 verbose "GDB initialized."
1155 -re "$gdb_prompt $" {
1156 perror "GDB never initialized."
1160 perror "(timeout) GDB never initialized after 10 seconds."
1165 set gdb_spawn_id -1;
1166 # force the height to "unlimited", so no pagers get used
1168 send_gdb "set height 0\n"
1170 -re "$gdb_prompt $" {
1171 verbose "Setting height to 0." 2
1174 warning "Couldn't set the height to 0"
1177 # force the width to "unlimited", so no wraparound occurs
1178 send_gdb "set width 0\n"
1180 -re "$gdb_prompt $" {
1181 verbose "Setting width to 0." 2
1184 warning "Couldn't set the width to 0."
1190 # Return a 1 for configurations for which we don't even want to try to
1193 proc skip_cplus_tests {} {
1194 if { [istarget "h8300-*-*"] } {
1198 # The C++ IO streams are too large for HC11/HC12 and are thus not
1199 # available. The gdb C++ tests use them and don't compile.
1200 if { [istarget "m6811-*-*"] } {
1203 if { [istarget "m6812-*-*"] } {
1209 # Return a 1 if I don't even want to try to test FORTRAN.
1211 proc skip_fortran_tests {} {
1215 # Return a 1 if we should skip shared library tests.
1217 proc skip_shlib_tests {} {
1218 # Run the shared library tests on native systems.
1223 # An abbreviated list of remote targets where we should be able to
1224 # run shared library tests.
1225 if {([istarget *-*-linux*]
1226 || [istarget *-*-*bsd*]
1227 || [istarget *-*-solaris2*]
1228 || [istarget arm*-*-symbianelf*]
1229 || [istarget *-*-mingw*]
1230 || [istarget *-*-cygwin*]
1231 || [istarget *-*-pe*])} {
1238 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
1239 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
1241 proc skip_altivec_tests {} {
1242 global skip_vmx_tests_saved
1243 global srcdir subdir gdb_prompt
1245 # Use the cached value, if it exists.
1246 set me "skip_altivec_tests"
1247 if [info exists skip_vmx_tests_saved] {
1248 verbose "$me: returning saved $skip_vmx_tests_saved" 2
1249 return $skip_vmx_tests_saved
1252 # Some simulators are known to not support VMX instructions.
1253 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1254 verbose "$me: target known to not support VMX, returning 1" 2
1255 return [set skip_vmx_tests_saved 1]
1258 # Make sure we have a compiler that understands altivec.
1259 set compile_flags {debug nowarnings}
1260 if [get_compiler_info not-used] {
1261 warning "Could not get compiler info"
1264 if [test_compiler_info gcc*] {
1265 set compile_flags "$compile_flags additional_flags=-maltivec"
1266 } elseif [test_compiler_info xlc*] {
1267 set compile_flags "$compile_flags additional_flags=-qaltivec"
1269 verbose "Could not compile with altivec support, returning 1" 2
1273 # Set up, compile, and execute a test program containing VMX instructions.
1274 # Include the current process ID in the file names to prevent conflicts
1275 # with invocations for multiple testsuites.
1279 set f [open $src "w"]
1280 puts $f "int main() {"
1281 puts $f "#ifdef __MACH__"
1282 puts $f " asm volatile (\"vor v0,v0,v0\");"
1284 puts $f " asm volatile (\"vor 0,0,0\");"
1286 puts $f " return 0; }"
1289 verbose "$me: compiling testfile $src" 2
1290 set lines [gdb_compile $src $exe executable $compile_flags]
1293 if ![string match "" $lines] then {
1294 verbose "$me: testfile compilation failed, returning 1" 2
1295 return [set skip_vmx_tests_saved 1]
1298 # No error message, compilation succeeded so now run it via gdb.
1302 gdb_reinitialize_dir $srcdir/$subdir
1306 -re ".*Illegal instruction.*${gdb_prompt} $" {
1307 verbose -log "\n$me altivec hardware not detected"
1308 set skip_vmx_tests_saved 1
1310 -re ".*Program exited normally.*${gdb_prompt} $" {
1311 verbose -log "\n$me: altivec hardware detected"
1312 set skip_vmx_tests_saved 0
1315 warning "\n$me: default case taken"
1316 set skip_vmx_tests_saved 1
1320 remote_file build delete $exe
1322 verbose "$me: returning $skip_vmx_tests_saved" 2
1323 return $skip_vmx_tests_saved
1326 # Skip all the tests in the file if you are not on an hppa running
1329 proc skip_hp_tests {} {
1330 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
1331 verbose "Skip hp tests is $skip_hp"
1335 set compiler_info "unknown"
1337 set hp_cc_compiler 0
1338 set hp_aCC_compiler 0
1340 # Figure out what compiler I am using.
1342 # BINFILE is a "compiler information" output file. This implementation
1343 # does not use BINFILE.
1345 # ARGS can be empty or "C++". If empty, "C" is assumed.
1347 # There are several ways to do this, with various problems.
1349 # [ gdb_compile -E $ifile -o $binfile.ci ]
1350 # source $binfile.ci
1352 # Single Unix Spec v3 says that "-E -o ..." together are not
1353 # specified. And in fact, the native compiler on hp-ux 11 (among
1354 # others) does not work with "-E -o ...". Most targets used to do
1355 # this, and it mostly worked, because it works with gcc.
1357 # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ]
1358 # source $binfile.ci
1360 # This avoids the problem with -E and -o together. This almost works
1361 # if the build machine is the same as the host machine, which is
1362 # usually true of the targets which are not gcc. But this code does
1363 # not figure which compiler to call, and it always ends up using the C
1364 # compiler. Not good for setting hp_aCC_compiler. Targets
1365 # hppa*-*-hpux* and mips*-*-irix* used to do this.
1367 # [ gdb_compile -E $ifile > $binfile.ci ]
1368 # source $binfile.ci
1370 # dejagnu target_compile says that it supports output redirection,
1371 # but the code is completely different from the normal path and I
1372 # don't want to sweep the mines from that path. So I didn't even try
1375 # set cppout [ gdb_compile $ifile "" preprocess $args quiet ]
1378 # I actually do this for all targets now. gdb_compile runs the right
1379 # compiler, and TCL captures the output, and I eval the output.
1381 # Unfortunately, expect logs the output of the command as it goes by,
1382 # and dejagnu helpfully prints a second copy of it right afterwards.
1383 # So I turn off expect logging for a moment.
1385 # [ gdb_compile $ifile $ciexe_file executable $args ]
1386 # [ remote_exec $ciexe_file ]
1387 # [ source $ci_file.out ]
1389 # I could give up on -E and just do this.
1390 # I didn't get desperate enough to try this.
1392 # -- chastain 2004-01-06
1394 proc get_compiler_info {binfile args} {
1395 # For compiler.c and compiler.cc
1398 # I am going to play with the log to keep noise out.
1402 # These come from compiler.c or compiler.cc
1403 global compiler_info
1405 # Legacy global data symbols.
1407 global hp_cc_compiler
1408 global hp_aCC_compiler
1410 # Choose which file to preprocess.
1411 set ifile "${srcdir}/lib/compiler.c"
1412 if { [llength $args] > 0 && [lindex $args 0] == "c++" } {
1413 set ifile "${srcdir}/lib/compiler.cc"
1416 # Run $ifile through the right preprocessor.
1417 # Toggle gdb.log to keep the compiler output out of the log.
1419 set cppout [ gdb_compile "${ifile}" "" preprocess [list "$args" quiet] ]
1420 log_file -a "$outdir/$tool.log"
1424 foreach cppline [ split "$cppout" "\n" ] {
1425 if { [ regexp "^#" "$cppline" ] } {
1427 } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } {
1429 } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } {
1431 verbose "get_compiler_info: $cppline" 2
1435 verbose -log "get_compiler_info: $cppline"
1440 # Reset to unknown compiler if any diagnostics happened.
1442 set compiler_info "unknown"
1445 # Set the legacy symbols.
1447 set hp_cc_compiler 0
1448 set hp_aCC_compiler 0
1449 if { [regexp "^gcc-1-" "$compiler_info" ] } { set gcc_compiled 1 }
1450 if { [regexp "^gcc-2-" "$compiler_info" ] } { set gcc_compiled 2 }
1451 if { [regexp "^gcc-3-" "$compiler_info" ] } { set gcc_compiled 3 }
1452 if { [regexp "^gcc-4-" "$compiler_info" ] } { set gcc_compiled 4 }
1453 if { [regexp "^gcc-5-" "$compiler_info" ] } { set gcc_compiled 5 }
1454 if { [regexp "^hpcc-" "$compiler_info" ] } { set hp_cc_compiler 1 }
1455 if { [regexp "^hpacc-" "$compiler_info" ] } { set hp_aCC_compiler 1 }
1457 # Log what happened.
1458 verbose -log "get_compiler_info: $compiler_info"
1460 # Most compilers will evaluate comparisons and other boolean
1461 # operations to 0 or 1.
1462 uplevel \#0 { set true 1 }
1463 uplevel \#0 { set false 0 }
1465 # Use of aCC results in boolean results being displayed as
1467 if { $hp_aCC_compiler } {
1468 uplevel \#0 { set true true }
1469 uplevel \#0 { set false false }
1475 proc test_compiler_info { {compiler ""} } {
1476 global compiler_info
1478 # if no arg, return the compiler_info string
1480 if [string match "" $compiler] {
1481 if [info exists compiler_info] {
1482 return $compiler_info
1484 perror "No compiler info found."
1488 return [string match $compiler $compiler_info]
1491 set gdb_wrapper_initialized 0
1493 proc gdb_wrapper_init { args } {
1494 global gdb_wrapper_initialized;
1495 global gdb_wrapper_file;
1496 global gdb_wrapper_flags;
1498 if { $gdb_wrapper_initialized == 1 } { return; }
1500 if {[target_info exists needs_status_wrapper] && \
1501 [target_info needs_status_wrapper] != "0"} {
1502 set result [build_wrapper "testglue.o"];
1503 if { $result != "" } {
1504 set gdb_wrapper_file [lindex $result 0];
1505 set gdb_wrapper_flags [lindex $result 1];
1507 warning "Status wrapper failed to build."
1510 set gdb_wrapper_initialized 1
1513 proc gdb_compile {source dest type options} {
1514 global GDB_TESTCASE_OPTIONS;
1515 global gdb_wrapper_file;
1516 global gdb_wrapper_flags;
1517 global gdb_wrapper_initialized;
1519 # Add platform-specific options if a shared library was specified using
1520 # "shlib=librarypath" in OPTIONS.
1523 foreach opt $options {
1524 if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] {
1525 if [test_compiler_info "xlc-*"] {
1526 # IBM xlc compiler doesn't accept shared library named other
1527 # than .so: use "-Wl," to bypass this
1528 lappend source "-Wl,$shlib_name"
1529 } elseif { ([istarget "*-*-mingw*"]
1530 || [istarget *-*-cygwin*]
1531 || [istarget *-*-pe*])} {
1532 lappend source "${shlib_name}.a"
1534 lappend source $shlib_name
1536 if {$shlib_found == 0} {
1538 if { ([test_compiler_info "gcc-*"]
1539 && ([istarget "powerpc*-*-aix*"]
1540 || [istarget "rs6000*-*-aix*"] )) } {
1541 lappend options "additional_flags=-L${objdir}/${subdir}"
1542 } elseif { [istarget "mips-sgi-irix*"] } {
1543 lappend options "additional_flags=-rpath ${objdir}/${subdir}"
1546 } elseif { $opt == "shlib_load" } {
1547 if { ([istarget "*-*-mingw*"]
1548 || [istarget *-*-cygwin*]
1549 || [istarget *-*-pe*]
1550 || [istarget arm*-*-symbianelf*]
1551 || [istarget hppa*-*-hpux*])} {
1552 # Do not need anything.
1554 lappend new_options "libs=-ldl"
1555 lappend new_options "additional_flags=-Wl,-rpath,\\\$ORIGIN"
1558 lappend new_options $opt
1561 set options $new_options
1563 if [target_info exists gdb_stub] {
1564 set options2 { "additional_flags=-Dusestubs" }
1565 lappend options "libs=[target_info gdb_stub]";
1566 set options [concat $options2 $options]
1568 if [target_info exists is_vxworks] {
1569 set options2 { "additional_flags=-Dvxworks" }
1570 lappend options "libs=[target_info gdb_stub]";
1571 set options [concat $options2 $options]
1573 if [info exists GDB_TESTCASE_OPTIONS] {
1574 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
1576 verbose "options are $options"
1577 verbose "source is $source $dest $type $options"
1579 if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init }
1581 if {[target_info exists needs_status_wrapper] && \
1582 [target_info needs_status_wrapper] != "0" && \
1583 [info exists gdb_wrapper_file]} {
1584 lappend options "libs=${gdb_wrapper_file}"
1585 lappend options "ldflags=${gdb_wrapper_flags}"
1588 # Replace the "nowarnings" option with the appropriate additional_flags
1589 # to disable compiler warnings.
1590 set nowarnings [lsearch -exact $options nowarnings]
1591 if {$nowarnings != -1} {
1592 if [target_info exists gdb,nowarnings_flag] {
1593 set flag "additional_flags=[target_info gdb,nowarnings_flag]"
1595 set flag "additional_flags=-w"
1597 set options [lreplace $options $nowarnings $nowarnings $flag]
1600 set result [target_compile $source $dest $type $options];
1602 # Prune uninteresting compiler (and linker) output.
1603 regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result
1605 regsub "\[\r\n\]*$" "$result" "" result;
1606 regsub "^\[\r\n\]*" "$result" "" result;
1608 if { $result != "" && [lsearch $options quiet] == -1} {
1609 clone_output "gdb compile failed, $result"
1615 # This is just like gdb_compile, above, except that it tries compiling
1616 # against several different thread libraries, to see which one this
1618 proc gdb_compile_pthreads {source dest type options} {
1620 set why_msg "unrecognized error"
1621 foreach lib {-lpthreads -lpthread -lthread} {
1622 # This kind of wipes out whatever libs the caller may have
1623 # set. Or maybe theirs will override ours. How infelicitous.
1624 set options_with_lib [concat $options [list libs=$lib quiet]]
1625 set ccout [gdb_compile $source $dest $type $options_with_lib]
1626 switch -regexp -- $ccout {
1627 ".*no posix threads support.*" {
1628 set why_msg "missing threads include file"
1631 ".*cannot open -lpthread.*" {
1632 set why_msg "missing runtime threads library"
1634 ".*Can't find library for -lpthread.*" {
1635 set why_msg "missing runtime threads library"
1638 pass "successfully compiled posix threads test case"
1644 if {!$built_binfile} {
1645 unsupported "Couldn't compile $source: ${why_msg}"
1650 # Build a shared library from SOURCES. You must use get_compiler_info
1653 proc gdb_compile_shlib {sources dest options} {
1654 set obj_options $options
1656 switch -glob [test_compiler_info] {
1658 lappend obj_options "additional_flags=-qpic"
1661 if { !([istarget "powerpc*-*-aix*"]
1662 || [istarget "rs6000*-*-aix*"]
1663 || [istarget "*-*-cygwin*"]
1664 || [istarget "*-*-mingw*"]
1665 || [istarget "*-*-pe*"]) } {
1666 lappend obj_options "additional_flags=-fpic"
1670 switch -glob [istarget] {
1672 lappend obj_options "additional_flags=+z"
1675 # Disable SGI compiler's implicit -Dsgi
1676 lappend obj_options "additional_flags=-Usgi"
1679 # don't know what the compiler is...
1685 set outdir [file dirname $dest]
1687 foreach source $sources {
1688 set sourcebase [file tail $source]
1689 if {[gdb_compile $source "${outdir}/${sourcebase}.o" object $obj_options] != ""} {
1692 lappend objects ${outdir}/${sourcebase}.o
1695 if [istarget "hppa*-*-hpux*"] {
1696 remote_exec build "ld -b ${objects} -o ${dest}"
1698 set link_options $options
1699 if [test_compiler_info "xlc-*"] {
1700 lappend link_options "additional_flags=-qmkshrobj"
1702 lappend link_options "additional_flags=-shared"
1704 if { ([istarget "*-*-mingw*"]
1705 || [istarget *-*-cygwin*]
1706 || [istarget *-*-pe*])} {
1707 lappend link_options "additional_flags=-Wl,--out-implib,${dest}.a"
1710 if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
1716 # This is just like gdb_compile_pthreads, above, except that we always add the
1717 # objc library for compiling Objective-C programs
1718 proc gdb_compile_objc {source dest type options} {
1720 set why_msg "unrecognized error"
1721 foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} {
1722 # This kind of wipes out whatever libs the caller may have
1723 # set. Or maybe theirs will override ours. How infelicitous.
1724 if { $lib == "solaris" } {
1725 set lib "-lpthread -lposix4"
1727 if { $lib != "-lobjc" } {
1728 set lib "-lobjc $lib"
1730 set options_with_lib [concat $options [list libs=$lib quiet]]
1731 set ccout [gdb_compile $source $dest $type $options_with_lib]
1732 switch -regexp -- $ccout {
1733 ".*no posix threads support.*" {
1734 set why_msg "missing threads include file"
1737 ".*cannot open -lpthread.*" {
1738 set why_msg "missing runtime threads library"
1740 ".*Can't find library for -lpthread.*" {
1741 set why_msg "missing runtime threads library"
1744 pass "successfully compiled objc with posix threads test case"
1750 if {!$built_binfile} {
1751 unsupported "Couldn't compile $source: ${why_msg}"
1756 proc send_gdb { string } {
1757 global suppress_flag;
1758 if { $suppress_flag } {
1759 return "suppressed";
1761 return [remote_send host "$string"];
1767 proc gdb_expect { args } {
1768 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
1769 set gtimeout [lindex $args 0];
1770 set expcode [list [lindex $args 1]];
1772 upvar timeout timeout;
1775 if [target_info exists gdb,timeout] {
1776 if [info exists timeout] {
1777 if { $timeout < [target_info gdb,timeout] } {
1778 set gtimeout [target_info gdb,timeout];
1780 set gtimeout $timeout;
1783 set gtimeout [target_info gdb,timeout];
1787 if ![info exists gtimeout] {
1789 if [info exists timeout] {
1790 set gtimeout $timeout;
1797 global suppress_flag;
1798 global remote_suppress_flag;
1799 if [info exists remote_suppress_flag] {
1800 set old_val $remote_suppress_flag;
1802 if [info exists suppress_flag] {
1803 if { $suppress_flag } {
1804 set remote_suppress_flag 1;
1808 {uplevel remote_expect host $gtimeout $expcode} string];
1809 if [info exists old_val] {
1810 set remote_suppress_flag $old_val;
1812 if [info exists remote_suppress_flag] {
1813 unset remote_suppress_flag;
1818 global errorInfo errorCode;
1820 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
1821 } elseif {$code == 2} {
1822 return -code return $string
1823 } elseif {$code == 3} {
1825 } elseif {$code > 4} {
1826 return -code $code $string
1830 # gdb_expect_list MESSAGE SENTINEL LIST -- expect a sequence of outputs
1832 # Check for long sequence of output by parts.
1833 # MESSAGE: is the test message to be printed with the test success/fail.
1834 # SENTINEL: Is the terminal pattern indicating that output has finished.
1835 # LIST: is the sequence of outputs to match.
1836 # If the sentinel is recognized early, it is considered an error.
1839 # 1 if the test failed,
1840 # 0 if the test passes,
1841 # -1 if there was an internal error.
1843 proc gdb_expect_list {test sentinel list} {
1845 global suppress_flag
1848 if { $suppress_flag } {
1850 unresolved "${test}"
1852 while { ${index} < [llength ${list}] } {
1853 set pattern [lindex ${list} ${index}]
1854 set index [expr ${index} + 1]
1855 if { ${index} == [llength ${list}] } {
1858 -re "${pattern}${sentinel}" {
1859 # pass "${test}, pattern ${index} + sentinel"
1862 fail "${test} (pattern ${index} + sentinel)"
1865 -re ".*A problem internal to GDB has been detected" {
1866 fail "${test} (GDB internal error)"
1868 gdb_internal_error_resync
1871 fail "${test} (pattern ${index} + sentinel) (timeout)"
1876 # unresolved "${test}, pattern ${index} + sentinel"
1882 # pass "${test}, pattern ${index}"
1885 fail "${test} (pattern ${index})"
1888 -re ".*A problem internal to GDB has been detected" {
1889 fail "${test} (GDB internal error)"
1891 gdb_internal_error_resync
1894 fail "${test} (pattern ${index}) (timeout)"
1899 # unresolved "${test}, pattern ${index}"
1913 proc gdb_suppress_entire_file { reason } {
1914 global suppress_flag;
1916 warning "$reason\n";
1917 set suppress_flag -1;
1921 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
1922 # gdb_expect to fail immediately (until the next call to
1923 # gdb_stop_suppressing_tests).
1925 proc gdb_suppress_tests { args } {
1926 global suppress_flag;
1928 return; # fnf - disable pending review of results where
1929 # testsuite ran better without this
1932 if { $suppress_flag == 1 } {
1933 if { [llength $args] > 0 } {
1934 warning "[lindex $args 0]\n";
1936 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
1942 # Clear suppress_flag.
1944 proc gdb_stop_suppressing_tests { } {
1945 global suppress_flag;
1947 if [info exists suppress_flag] {
1948 if { $suppress_flag > 0 } {
1949 set suppress_flag 0;
1950 clone_output "Tests restarted.\n";
1953 set suppress_flag 0;
1957 proc gdb_clear_suppressed { } {
1958 global suppress_flag;
1960 set suppress_flag 0;
1963 proc gdb_start { } {
1968 catch default_gdb_exit
1972 # gdb_load_cmd -- load a file into the debugger.
1973 # ARGS - additional args to load command.
1974 # return a -1 if anything goes wrong.
1976 proc gdb_load_cmd { args } {
1979 if [target_info exists gdb_load_timeout] {
1980 set loadtimeout [target_info gdb_load_timeout]
1982 set loadtimeout 1600
1984 send_gdb "load $args\n"
1985 verbose "Timeout is now $timeout seconds" 2
1986 gdb_expect $loadtimeout {
1987 -re "Loading section\[^\r\]*\r\n" {
1990 -re "Start address\[\r\]*\r\n" {
1993 -re "Transfer rate\[\r\]*\r\n" {
1996 -re "Memory access error\[^\r\]*\r\n" {
1997 perror "Failed to load program"
2000 -re "$gdb_prompt $" {
2003 -re "(.*)\r\n$gdb_prompt " {
2004 perror "Unexpected reponse from 'load' -- $expect_out(1,string)"
2008 perror "Timed out trying to load $arg."
2017 # Copy a file to the remote target and return its target filename.
2018 # Schedule the file to be deleted at the end of this test.
2020 proc gdb_download { filename } {
2023 set destname [remote_download target $filename]
2024 lappend cleanfiles $destname
2028 # gdb_load_shlibs LIB...
2030 # Copy the listed libraries to the target.
2032 proc gdb_load_shlibs { args } {
2033 if {![is_remote target]} {
2037 foreach file $args {
2041 # Even if the target supplies full paths for shared libraries,
2042 # they may not be paths for this system.
2043 gdb_test "set solib-search-path [file dirname [lindex $args 0]]" "" ""
2047 # gdb_load -- load a file into the debugger.
2048 # Many files in config/*.exp override this procedure.
2050 proc gdb_load { arg } {
2051 return [gdb_file_cmd $arg]
2054 # gdb_reload -- load a file into the target. Called before "running",
2055 # either the first time or after already starting the program once,
2056 # for remote targets. Most files that override gdb_load should now
2057 # override this instead.
2059 proc gdb_reload { } {
2060 # For the benefit of existing configurations, default to gdb_load.
2061 # Specifying no file defaults to the executable currently being
2063 return [gdb_load ""]
2066 proc gdb_continue { function } {
2069 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
2072 proc default_gdb_init { args } {
2073 global gdb_wrapper_initialized
2078 gdb_clear_suppressed;
2080 # Make sure that the wrapper is rebuilt
2081 # with the appropriate multilib option.
2082 set gdb_wrapper_initialized 0
2084 # Uh, this is lame. Really, really, really lame. But there's this *one*
2085 # testcase that will fail in random places if we don't increase this.
2088 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
2089 if { [llength $args] > 0 } {
2092 set file [lindex $args 0];
2094 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
2097 if [target_info exists gdb_prompt] {
2098 set gdb_prompt [target_info gdb_prompt];
2100 set gdb_prompt "\\(gdb\\)"
2104 proc gdb_init { args } {
2105 return [eval default_gdb_init $args];
2108 proc gdb_finish { } {
2111 # Exit first, so that the files are no longer in use.
2114 if { [llength $cleanfiles] > 0 } {
2115 eval remote_file target delete $cleanfiles
2121 set debug_format "unknown"
2123 # Run the gdb command "info source" and extract the debugging format
2124 # information from the output and save it in debug_format.
2126 proc get_debug_format { } {
2132 set debug_format "unknown"
2133 send_gdb "info source\n"
2135 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
2136 set debug_format $expect_out(1,string)
2137 verbose "debug format is $debug_format"
2140 -re "No current source file.\r\n$gdb_prompt $" {
2141 perror "get_debug_format used when no current source file"
2144 -re "$gdb_prompt $" {
2145 warning "couldn't check debug format (no valid response)."
2149 warning "couldn't check debug format (timed out)."
2155 # Return true if FORMAT matches the debug format the current test was
2156 # compiled with. FORMAT is a shell-style globbing pattern; it can use
2157 # `*', `[...]', and so on.
2159 # This function depends on variables set by `get_debug_format', above.
2161 proc test_debug_format {format} {
2164 return [expr [string match $format $debug_format] != 0]
2167 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
2168 # COFF, stabs, etc). If that format matches the format that the
2169 # current test was compiled with, then the next test is expected to
2170 # fail for any target. Returns 1 if the next test or set of tests is
2171 # expected to fail, 0 otherwise (or if it is unknown). Must have
2172 # previously called get_debug_format.
2173 proc setup_xfail_format { format } {
2174 set ret [test_debug_format $format];
2182 proc gdb_step_for_stub { } {
2185 if ![target_info exists gdb,use_breakpoint_for_stub] {
2186 if [target_info exists gdb_stub_step_command] {
2187 set command [target_info gdb_stub_step_command];
2191 send_gdb "${command}\n";
2194 -re "(main.* at |.*in .*start).*$gdb_prompt" {
2197 -re ".*$gdb_prompt" {
2199 if { $tries == 5 } {
2200 fail "stepping out of breakpoint function";
2203 send_gdb "${command}\n";
2207 fail "stepping out of breakpoint function";
2214 -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" {
2215 set file $expect_out(1,string);
2216 set linenum [expr $expect_out(2,string) + 1];
2217 set breakplace "${file}:${linenum}";
2221 send_gdb "break ${breakplace}\n";
2223 -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" {
2224 set breakpoint $expect_out(1,string);
2226 -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" {
2227 set breakpoint $expect_out(1,string);
2231 send_gdb "continue\n";
2233 -re "Breakpoint ${breakpoint},.*$gdb_prompt" {
2234 gdb_test "delete $breakpoint" ".*" "";
2241 # gdb_get_line_number TEXT [FILE]
2243 # Search the source file FILE, and return the line number of the
2244 # first line containing TEXT. If no match is found, return -1.
2246 # TEXT is a string literal, not a regular expression.
2248 # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is
2249 # specified, and does not start with "/", then it is assumed to be in
2250 # "$srcdir/$subdir". This is awkward, and can be fixed in the future,
2251 # by changing the callers and the interface at the same time.
2252 # In particular: gdb.base/break.exp, gdb.base/condbreak.exp,
2253 # gdb.base/ena-dis-br.exp.
2255 # Use this function to keep your test scripts independent of the
2256 # exact line numbering of the source file. Don't write:
2258 # send_gdb "break 20"
2260 # This means that if anyone ever edits your test's source file,
2261 # your test could break. Instead, put a comment like this on the
2262 # source file line you want to break at:
2264 # /* breakpoint spot: frotz.exp: test name */
2266 # and then write, in your test script (which we assume is named
2269 # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
2271 # (Yes, Tcl knows how to handle the nested quotes and brackets.
2274 # % puts "foo [lindex "bar baz" 1]"
2277 # Tcl is quite clever, for a little stringy language.)
2281 # The previous implementation of this procedure used the gdb search command.
2282 # This version is different:
2284 # . It works with MI, and it also works when gdb is not running.
2286 # . It operates on the build machine, not the host machine.
2288 # . For now, this implementation fakes a current directory of
2289 # $srcdir/$subdir to be compatible with the old implementation.
2290 # This will go away eventually and some callers will need to
2293 # . The TEXT argument is literal text and matches literally,
2294 # not a regular expression as it was before.
2296 # . State changes in gdb, such as changing the current file
2297 # and setting $_, no longer happen.
2299 # After a bit of time we can forget about the differences from the
2300 # old implementation.
2302 # --chastain 2004-08-05
2304 proc gdb_get_line_number { text { file "" } } {
2309 if { "$file" == "" } then {
2312 if { ! [regexp "^/" "$file"] } then {
2313 set file "$srcdir/$subdir/$file"
2316 if { [ catch { set fd [open "$file"] } message ] } then {
2322 for { set line 1 } { 1 } { incr line } {
2323 if { [ catch { set nchar [gets "$fd" body] } message ] } then {
2327 if { $nchar < 0 } then {
2330 if { [string first "$text" "$body"] >= 0 } then {
2336 if { [ catch { close "$fd" } message ] } then {
2344 # gdb_continue_to_end:
2345 # The case where the target uses stubs has to be handled specially. If a
2346 # stub is used, we set a breakpoint at exit because we cannot rely on
2347 # exit() behavior of a remote target.
2349 # mssg is the error message that gets printed.
2351 proc gdb_continue_to_end {mssg} {
2352 if [target_info exists use_gdb_stub] {
2353 if {![gdb_breakpoint "exit"]} {
2356 gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \
2357 "continue until exit at $mssg"
2359 # Continue until we exit. Should not stop again.
2360 # Don't bother to check the output of the program, that may be
2361 # extremely tough for some remote systems.
2362 gdb_test "continue"\
2363 "Continuing.\[\r\n0-9\]+(... EXIT code 0\[\r\n\]+|Program exited normally\\.).*"\
2364 "continue until exit at $mssg"
2368 proc rerun_to_main {} {
2371 if [target_info exists use_gdb_stub] {
2374 -re ".*Breakpoint .*main .*$gdb_prompt $"\
2375 {pass "rerun to main" ; return 0}
2376 -re "$gdb_prompt $"\
2377 {fail "rerun to main" ; return 0}
2378 timeout {fail "(timeout) rerun to main" ; return 0}
2383 -re "The program .* has been started already.*y or n. $" {
2387 -re "Starting program.*$gdb_prompt $"\
2388 {pass "rerun to main" ; return 0}
2389 -re "$gdb_prompt $"\
2390 {fail "rerun to main" ; return 0}
2391 timeout {fail "(timeout) rerun to main" ; return 0}
2396 # Print a message and return true if a test should be skipped
2397 # due to lack of floating point suport.
2399 proc gdb_skip_float_test { msg } {
2400 if [target_info exists gdb,skip_float_tests] {
2401 verbose "Skipping test '$msg': no float tests.";
2407 # Print a message and return true if a test should be skipped
2408 # due to lack of stdio support.
2410 proc gdb_skip_stdio_test { msg } {
2411 if [target_info exists gdb,noinferiorio] {
2412 verbose "Skipping test '$msg': no inferior i/o.";
2418 proc gdb_skip_bogus_test { msg } {
2422 # Return true if a test should be skipped due to lack of XML support
2425 proc gdb_skip_xml_test { } {
2428 global xml_missing_cached
2430 if {[info exists xml_missing_cached]} {
2431 return $xml_missing_cached
2435 set xml_missing_cached 0
2436 gdb_test_multiple "set tdesc filename ${srcdir}/gdb.xml/trivial.xml" "" {
2437 -re ".*XML support was disabled at compile time.*$gdb_prompt $" {
2438 set xml_missing_cached 1
2440 -re ".*$gdb_prompt $" { }
2443 return $xml_missing_cached
2446 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
2447 # ${binfile}.dbglnk, which is just like the executable ($binfile) but without
2448 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
2449 # the name of a debuginfo only file. This file will be stored in the
2450 # gdb.base/.debug subdirectory.
2452 # Functions for separate debug info testing
2454 # starting with an executable:
2455 # foo --> original executable
2457 # at the end of the process we have:
2458 # foo.stripped --> foo w/o debug info
2459 # .debug/foo.debug --> foo's debug info
2460 # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug.
2462 # Return the name of the file in which we should stor EXEC's separated
2463 # debug info. EXEC contains the full path.
2464 proc separate_debug_filename { exec } {
2466 # In a .debug subdirectory off the same directory where the testcase
2467 # executable is going to be. Something like:
2468 # <your-path>/gdb/testsuite/gdb.base/.debug/blah.debug.
2469 # This is the default location where gdb expects to findi
2470 # the debug info file.
2472 set exec_dir [file dirname $exec]
2473 set exec_file [file tail $exec]
2474 set debug_dir [file join $exec_dir ".debug"]
2475 set debug_file [file join $debug_dir "${exec_file}.debug"]
2480 # Create stripped files for DEST, replacing it. If ARGS is passed, it is a
2481 # list of optional flags. The only currently supported flag is no-main,
2482 # which removes the symbol entry for main from the separate debug file.
2484 proc gdb_gnu_strip_debug { dest args } {
2486 # First, make sure that we can do this. This is nasty. We need to
2487 # check for the stabs debug format. To do this we must run gdb on
2488 # the unstripped executable, list 'main' (as to have a default
2489 # source file), use get_debug_format (which does 'info source')
2490 # and then see if the debug info is stabs. If so, we bail out. We
2491 # cannot do this any other way because get_debug_format finds out
2492 # the debug format using gdb itself, and in case of stabs we get
2493 # an error loading the program if it is already stripped. An
2494 # alternative would be to find out the debug info from the flags
2495 # passed to dejagnu when the test is run.
2500 gdb_test "list main" "" ""
2502 if { [test_debug_format "stabs"] } then {
2503 # The separate debug info feature doesn't work well in
2504 # binutils with stabs. It produces a corrupted debug info
2505 # only file, and gdb chokes on it. It is almost impossible to
2506 # capture the failing message out of gdb, because it happens
2507 # inside gdb_load. At that point any error message is
2508 # intercepted by dejagnu itself, and, because of the error
2509 # threshold, any faulty test result is changed into an
2510 # UNRESOLVED. (see dejagnu/lib/framework.exp)
2511 unsupported "no separate debug info handling with stabs"
2513 } elseif { [test_debug_format "unknown"] } then {
2514 # gdb doesn't know what the debug format is. We are out of luck here.
2515 unsupported "unknown debugging format"
2520 set debug_file [separate_debug_filename $dest]
2521 set strip_to_file_program [transform strip]
2522 set objcopy_program [transform objcopy]
2524 # Make sure the directory that will hold the separated debug
2525 # info actually exists.
2526 set debug_dir [file dirname $debug_file]
2527 if {! [file isdirectory $debug_dir]} {
2528 file mkdir $debug_dir
2531 set debug_link [file tail $debug_file]
2532 set stripped_file "${dest}.stripped"
2534 # Get rid of the debug info, and store result in stripped_file
2535 # something like gdb/testsuite/gdb.base/blah.stripped.
2536 set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
2537 verbose "result is $result"
2538 verbose "output is $output"
2543 # Get rid of everything but the debug info, and store result in debug_file
2544 # This will be in the .debug subdirectory, see above.
2545 set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
2546 verbose "result is $result"
2547 verbose "output is $output"
2552 # If no-main is passed, strip the symbol for main from the separate
2553 # file. This is to simulate the behavior of elfutils's eu-strip, which
2554 # leaves the symtab in the original file only. There's no way to get
2555 # objcopy or strip to remove the symbol table without also removing the
2556 # debugging sections, so this is as close as we can get.
2557 if { [llength $args] == 1 && [lindex $args 0] == "no-main" } {
2558 set result [catch "exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp" output]
2559 verbose "result is $result"
2560 verbose "output is $output"
2564 file delete "${debug_file}"
2565 file rename "${debug_file}-tmp" "${debug_file}"
2568 # Link the two previous output files together, adding the .gnu_debuglink
2569 # section to the stripped_file, containing a pointer to the debug_file,
2570 # save the new file in dest.
2571 # This will be the regular executable filename, in the usual location.
2572 set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
2573 verbose "result is $result"
2574 verbose "output is $output"
2582 # Test the output of GDB_COMMAND matches the pattern obtained
2583 # by concatenating all elements of EXPECTED_LINES. This makes
2584 # it possible to split otherwise very long string into pieces.
2585 # If third argument is not empty, it's used as the name of the
2586 # test to be printed on pass/fail.
2587 proc help_test_raw { gdb_command expected_lines args } {
2588 set message $gdb_command
2589 if [llength $args]>0 then {
2590 set message [lindex $args 0]
2592 set expected_output [join $expected_lines ""]
2593 gdb_test "${gdb_command}" "${expected_output}" $message
2596 # Test the output of "help COMMNAD_CLASS". EXPECTED_INITIAL_LINES
2597 # are regular expressions that should match the beginning of output,
2598 # before the list of commands in that class. The presence of
2599 # command list and standard epilogue will be tested automatically.
2600 proc test_class_help { command_class expected_initial_lines args } {
2602 "List of commands\:.*\[\r\n\]+"
2603 "Type \"help\" followed by command name for full documentation\.\[\r\n\]+"
2604 "Type \"apropos word\" to search for commands related to \"word\"\.[\r\n\]+"
2605 "Command name abbreviations are allowed if unambiguous\."
2607 set l_entire_body [concat $expected_initial_lines $l_stock_body]
2609 eval [list help_test_raw "help ${command_class}" $l_entire_body] $args
2612 # COMMAND_LIST should have either one element -- command to test, or
2613 # two elements -- abbreviated command to test, and full command the first
2614 # element is abbreviation of.
2615 # The command must be a prefix command. EXPECTED_INITIAL_LINES
2616 # are regular expressions that should match the beginning of output,
2617 # before the list of subcommands. The presence of
2618 # subcommand list and standard epilogue will be tested automatically.
2619 proc test_prefix_command_help { command_list expected_initial_lines args } {
2620 set command [lindex $command_list 0]
2621 if {[llength $command_list]>1} {
2622 set full_command [lindex $command_list 1]
2624 set full_command $command
2626 # Use 'list' and not just {} because we want variables to
2627 # be expanded in this list.
2628 set l_stock_body [list\
2629 "List of $full_command subcommands\:.*\[\r\n\]+"\
2630 "Type \"help $full_command\" followed by $full_command subcommand name for full documentation\.\[\r\n\]+"\
2631 "Type \"apropos word\" to search for commands related to \"word\"\.\[\r\n\]+"\
2632 "Command name abbreviations are allowed if unambiguous\."]
2633 set l_entire_body [concat $expected_initial_lines $l_stock_body]
2634 if {[llength $args]>0} {
2635 help_test_raw "help ${command}" $l_entire_body [lindex $args 0]
2637 help_test_raw "help ${command}" $l_entire_body