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 # Specifying no file, defaults to the executable
207 # currently being debugged.
208 if { [gdb_load ""] != 0 } {
211 send_gdb "continue\n";
213 -re "Continu\[^\r\n\]*\[\r\n\]" {}
219 if [target_info exists gdb,start_symbol] {
220 set start [target_info gdb,start_symbol];
224 send_gdb "jump *$start\n"
226 while { $start_attempt } {
227 # Cap (re)start attempts at three to ensure that this loop
228 # always eventually fails. Don't worry about trying to be
229 # clever and not send a command when it has failed.
230 if [expr $start_attempt > 3] {
231 perror "Jump to start() failed (retry count exceeded)";
234 set start_attempt [expr $start_attempt + 1];
236 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
239 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
240 perror "Can't find start symbol to run in gdb_run";
243 -re "No symbol \"start\" in current.*$gdb_prompt $" {
244 send_gdb "jump *_start\n";
246 -re "No symbol.*context.*$gdb_prompt $" {
249 -re "Line.* Jump anyway.*y or n. $" {
252 -re "The program is not being run.*$gdb_prompt $" {
253 if { [gdb_load ""] != 0 } {
256 send_gdb "jump *$start\n";
259 perror "Jump to start() failed (timeout)";
264 if [target_info exists gdb_stub] {
266 -re "$gdb_prompt $" {
267 send_gdb "continue\n"
274 if [target_info exists gdb,do_reload_on_run] {
275 if { [gdb_load ""] != 0 } {
279 send_gdb "run $args\n"
280 # This doesn't work quite right yet.
282 -re "The program .* has been started already.*y or n. $" {
286 -re "Starting program: \[^\r\n\]*" {}
290 # Set a breakpoint at FUNCTION. If there is an additional argument it is
291 # a list of options; the only currently supported option is allow-pending.
293 proc gdb_breakpoint { function args } {
297 set pending_response n
298 if {[lsearch -exact [lindex $args 0] allow-pending] != -1} {
299 set pending_response y
302 send_gdb "break $function\n"
303 # The first two regexps are what we get with -g, the third is without -g.
305 -re "Breakpoint \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
306 -re "Breakpoint \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
307 -re "Breakpoint \[0-9\]* at .*$gdb_prompt $" {}
308 -re "Breakpoint \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" {
309 if {$pending_response == "n"} {
310 fail "setting breakpoint at $function"
314 -re "Make breakpoint pending.*y or \\\[n\\\]. $" {
315 send_gdb "$pending_response\n"
318 -re "$gdb_prompt $" { fail "setting breakpoint at $function" ; return 0 }
319 timeout { fail "setting breakpoint at $function (timeout)" ; return 0 }
324 # Set breakpoint at function and run gdb until it breaks there.
325 # Since this is the only breakpoint that will be set, if it stops
326 # at a breakpoint, we will assume it is the one we want. We can't
327 # just compare to "function" because it might be a fully qualified,
328 # single quoted C++ function specifier. If there's an additional argument,
329 # pass it to gdb_breakpoint.
331 proc runto { function args } {
337 if ![gdb_breakpoint $function [lindex $args 0]] {
343 # the "at foo.c:36" output we get with -g.
344 # the "in func" output we get without -g.
346 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
349 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
352 -re "$gdb_prompt $" {
353 fail "running to $function in runto"
357 fail "running to $function in runto (timeout)"
365 # runto_main -- ask gdb to run until we hit a breakpoint at main.
366 # The case where the target uses stubs has to be handled
367 # specially--if it uses stubs, assuming we hit
368 # breakpoint() and just step out of the function.
370 proc runto_main { } {
374 if ![target_info exists gdb_stub] {
386 ### Continue, and expect to hit a breakpoint.
387 ### Report a pass or fail, depending on whether it seems to have
388 ### worked. Use NAME as part of the test name; each call to
389 ### continue_to_breakpoint should use a NAME which is unique within
391 proc gdb_continue_to_breakpoint {name} {
393 set full_name "continue to breakpoint: $name"
395 send_gdb "continue\n"
397 -re "Breakpoint .* at .*\r\n$gdb_prompt $" {
400 -re ".*$gdb_prompt $" {
404 fail "$full_name (timeout)"
410 # gdb_internal_error_resync:
412 # Answer the questions GDB asks after it reports an internal error
413 # until we get back to a GDB prompt. Decline to quit the debugging
414 # session, and decline to create a core file. Return non-zero if the
417 # This procedure just answers whatever questions come up until it sees
418 # a GDB prompt; it doesn't require you to have matched the input up to
419 # any specific point. However, it only answers questions it sees in
420 # the output itself, so if you've matched a question, you had better
421 # answer it yourself before calling this.
423 # You can use this function thus:
427 # -re ".*A problem internal to GDB has been detected" {
428 # gdb_internal_error_resync
433 proc gdb_internal_error_resync {} {
437 while {$count < 10} {
439 -re "Quit this debugging session\\? \\(y or n\\) $" {
443 -re "Create a core file of GDB\\? \\(y or n\\) $" {
447 -re "$gdb_prompt $" {
448 # We're resynchronized.
452 perror "Could not resync from internal error (timeout)"
457 perror "Could not resync from internal error (resync count exceeded)"
462 # gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS
463 # Send a command to gdb; test the result.
465 # COMMAND is the command to execute, send to GDB with send_gdb. If
466 # this is the null string no command is sent.
467 # MESSAGE is a message to be printed with the built-in failure patterns
468 # if one of them matches. If MESSAGE is empty COMMAND will be used.
469 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
470 # patterns. Pattern elements will be evaluated in the caller's
471 # context; action elements will be executed in the caller's context.
472 # Unlike patterns for gdb_test, these patterns should generally include
473 # the final newline and prompt.
476 # 1 if the test failed, according to a built-in failure pattern
477 # 0 if only user-supplied patterns matched
478 # -1 if there was an internal error.
480 # You can use this function thus:
482 # gdb_test_multiple "print foo" "test foo" {
483 # -re "expected output 1" {
486 # -re "expected output 2" {
491 # The standard patterns, such as "Program exited..." and "A problem
492 # ...", all being implicitly appended to that list.
494 proc gdb_test_multiple { command message user_code } {
498 upvar timeout timeout
499 upvar expect_out expect_out
501 if { $message == "" } {
505 # TCL/EXPECT WART ALERT
506 # Expect does something very strange when it receives a single braced
507 # argument. It splits it along word separators and performs substitutions.
508 # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
509 # evaluated as "\[ab\]". But that's not how TCL normally works; inside a
510 # double-quoted list item, "\[ab\]" is just a long way of representing
511 # "[ab]", because the backslashes will be removed by lindex.
513 # Unfortunately, there appears to be no easy way to duplicate the splitting
514 # that expect will do from within TCL. And many places make use of the
515 # "\[0-9\]" construct, so we need to support that; and some places make use
516 # of the "[func]" construct, so we need to support that too. In order to
517 # get this right we have to substitute quoted list elements differently
518 # from braced list elements.
520 # We do this roughly the same way that Expect does it. We have to use two
521 # lists, because if we leave unquoted newlines in the argument to uplevel
522 # they'll be treated as command separators, and if we escape newlines
523 # we mangle newlines inside of command blocks. This assumes that the
524 # input doesn't contain a pattern which contains actual embedded newlines
527 regsub -all {\n} ${user_code} { } subst_code
528 set subst_code [uplevel list $subst_code]
530 set processed_code ""
532 set expecting_action 0
533 foreach item $user_code subst_item $subst_code {
534 if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } {
535 lappend processed_code $item
538 if {$item == "-indices" || $item == "-re" || $item == "-ex"} {
539 lappend processed_code $item
542 if { $expecting_action } {
543 lappend processed_code "uplevel [list $item]"
544 set expecting_action 0
545 # Cosmetic, no effect on the list.
546 append processed_code "\n"
549 set expecting_action 1
550 lappend processed_code $subst_item
551 if {$patterns != ""} {
554 append patterns "\"$subst_item\""
557 # Also purely cosmetic.
558 regsub -all {\r} $patterns {\\r} patterns
559 regsub -all {\n} $patterns {\\n} patterns
562 send_user "Sending \"$command\" to gdb\n"
563 send_user "Looking to match \"$patterns\"\n"
564 send_user "Message is \"$message\"\n"
568 set string "${command}\n";
569 if { $command != "" } {
570 while { "$string" != "" } {
571 set foo [string first "\n" "$string"];
572 set len [string length "$string"];
573 if { $foo < [expr $len - 1] } {
574 set str [string range "$string" 0 $foo];
575 if { [send_gdb "$str"] != "" } {
576 global suppress_flag;
578 if { ! $suppress_flag } {
579 perror "Couldn't send $command to GDB.";
584 # since we're checking if each line of the multi-line
585 # command are 'accepted' by GDB here,
586 # we need to set -notransfer expect option so that
587 # command output is not lost for pattern matching
590 -notransfer -re "\[\r\n\]" { verbose "partial: match" 3 }
591 timeout { verbose "partial: timeout" 3 }
593 set string [string range "$string" [expr $foo + 1] end];
598 if { "$string" != "" } {
599 if { [send_gdb "$string"] != "" } {
600 global suppress_flag;
602 if { ! $suppress_flag } {
603 perror "Couldn't send $command to GDB.";
611 if [target_info exists gdb,timeout] {
612 set tmt [target_info gdb,timeout];
614 if [info exists timeout] {
618 if [info exists timeout] {
627 -re ".*A problem internal to GDB has been detected" {
628 fail "$message (GDB internal error)"
629 gdb_internal_error_resync
631 -re "\\*\\*\\* DOSEXIT code.*" {
632 if { $message != "" } {
635 gdb_suppress_entire_file "GDB died";
638 -re "Ending remote debugging.*$gdb_prompt $" {
639 if ![isnative] then {
640 warning "Can`t communicate to remote target."
647 append code $processed_code
649 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
650 perror "Undefined command \"$command\"."
654 -re "Ambiguous command.*$gdb_prompt $" {
655 perror "\"$command\" is not a unique command name."
659 -re "Program exited with code \[0-9\]+.*$gdb_prompt $" {
660 if ![string match "" $message] then {
661 set errmsg "$message (the program exited)"
663 set errmsg "$command (the program exited)"
668 -re "EXIT code \[0-9\r\n\]+Program exited normally.*$gdb_prompt $" {
669 if ![string match "" $message] then {
670 set errmsg "$message (the program exited)"
672 set errmsg "$command (the program exited)"
677 -re "The program is not being run.*$gdb_prompt $" {
678 if ![string match "" $message] then {
679 set errmsg "$message (the program is no longer running)"
681 set errmsg "$command (the program is no longer running)"
686 -re "\r\n$gdb_prompt $" {
687 if ![string match "" $message] then {
694 perror "Window too small."
698 -re "\\(y or n\\) " {
700 perror "Got interactive prompt."
705 perror "Process no longer exists"
706 if { $message != "" } {
712 perror "internal buffer is full."
717 if ![string match "" $message] then {
718 fail "$message (timeout)"
725 set code [catch {gdb_expect $tmt $code} string]
727 global errorInfo errorCode;
728 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
729 } elseif {$code == 2} {
730 return -code return $string
731 } elseif {$code == 3} {
733 } elseif {$code > 4} {
734 return -code $code $string
739 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
740 # Send a command to gdb; test the result.
742 # COMMAND is the command to execute, send to GDB with send_gdb. If
743 # this is the null string no command is sent.
744 # PATTERN is the pattern to match for a PASS, and must NOT include
745 # the \r\n sequence immediately before the gdb prompt.
746 # MESSAGE is an optional message to be printed. If this is
747 # omitted, then the pass/fail messages use the command string as the
748 # message. (If this is the empty string, then sometimes we don't
749 # call pass or fail at all; I don't understand this at all.)
750 # QUESTION is a question GDB may ask in response to COMMAND, like
752 # RESPONSE is the response to send if QUESTION appears.
755 # 1 if the test failed,
756 # 0 if the test passes,
757 # -1 if there was an internal error.
759 proc gdb_test { args } {
763 upvar timeout timeout
765 if [llength $args]>2 then {
766 set message [lindex $args 2]
768 set message [lindex $args 0]
770 set command [lindex $args 0]
771 set pattern [lindex $args 1]
773 if [llength $args]==5 {
774 set question_string [lindex $args 3];
775 set response_string [lindex $args 4];
777 set question_string "^FOOBAR$"
780 return [gdb_test_multiple $command $message {
781 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
782 if ![string match "" $message] then {
786 -re "(${question_string})$" {
787 send_gdb "$response_string\n";
793 # Test that a command gives an error. For pass or fail, return
794 # a 1 to indicate that more tests can proceed. However a timeout
795 # is a serious error, generates a special fail message, and causes
796 # a 0 to be returned to indicate that more tests are likely to fail
799 proc test_print_reject { args } {
803 if [llength $args]==2 then {
804 set expectthis [lindex $args 1]
806 set expectthis "should never match this bogus string"
808 set sendthis [lindex $args 0]
810 send_user "Sending \"$sendthis\" to gdb\n"
811 send_user "Looking to match \"$expectthis\"\n"
813 send_gdb "$sendthis\n"
814 #FIXME: Should add timeout as parameter.
816 -re "A .* in expression.*\\.*$gdb_prompt $" {
817 pass "reject $sendthis"
820 -re "Invalid syntax in expression.*$gdb_prompt $" {
821 pass "reject $sendthis"
824 -re "Junk after end of expression.*$gdb_prompt $" {
825 pass "reject $sendthis"
828 -re "Invalid number.*$gdb_prompt $" {
829 pass "reject $sendthis"
832 -re "Invalid character constant.*$gdb_prompt $" {
833 pass "reject $sendthis"
836 -re "No symbol table is loaded.*$gdb_prompt $" {
837 pass "reject $sendthis"
840 -re "No symbol .* in current context.*$gdb_prompt $" {
841 pass "reject $sendthis"
844 -re "Unmatched single quote.*$gdb_prompt $" {
845 pass "reject $sendthis"
848 -re "A character constant must contain at least one character.*$gdb_prompt $" {
849 pass "reject $sendthis"
852 -re "$expectthis.*$gdb_prompt $" {
853 pass "reject $sendthis"
856 -re ".*$gdb_prompt $" {
857 fail "reject $sendthis"
861 fail "reject $sendthis (eof or timeout)"
867 # Given an input string, adds backslashes as needed to create a
868 # regexp that will match the string.
870 proc string_to_regexp {str} {
872 regsub -all {[]*+.|()^$\[\\]} $str {\\&} result
876 # Same as gdb_test, but the second parameter is not a regexp,
877 # but a string that must match exactly.
879 proc gdb_test_exact { args } {
880 upvar timeout timeout
882 set command [lindex $args 0]
884 # This applies a special meaning to a null string pattern. Without
885 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
886 # messages from commands that should have no output except a new
887 # prompt. With this, only results of a null string will match a null
890 set pattern [lindex $args 1]
891 if [string match $pattern ""] {
892 set pattern [string_to_regexp [lindex $args 0]]
894 set pattern [string_to_regexp [lindex $args 1]]
897 # It is most natural to write the pattern argument with only
898 # embedded \n's, especially if you are trying to avoid Tcl quoting
899 # problems. But gdb_expect really wants to see \r\n in patterns. So
900 # transform the pattern here. First transform \r\n back to \n, in
901 # case some users of gdb_test_exact already do the right thing.
902 regsub -all "\r\n" $pattern "\n" pattern
903 regsub -all "\n" $pattern "\r\n" pattern
904 if [llength $args]==3 then {
905 set message [lindex $args 2]
910 return [gdb_test $command $pattern $message]
913 proc gdb_reinitialize_dir { subdir } {
916 if [is_remote host] {
921 -re "Reinitialize source path to empty.*y or n. " {
924 -re "Source directories searched.*$gdb_prompt $" {
925 send_gdb "dir $subdir\n"
927 -re "Source directories searched.*$gdb_prompt $" {
928 verbose "Dir set to $subdir"
930 -re "$gdb_prompt $" {
931 perror "Dir \"$subdir\" failed."
935 -re "$gdb_prompt $" {
936 perror "Dir \"$subdir\" failed."
940 -re "$gdb_prompt $" {
941 perror "Dir \"$subdir\" failed."
947 # gdb_exit -- exit the GDB, killing the target program if necessary
949 proc default_gdb_exit {} {
955 gdb_stop_suppressing_tests;
957 if ![info exists gdb_spawn_id] {
961 verbose "Quitting $GDB $GDBFLAGS"
963 if { [is_remote host] && [board_info host exists fileid] } {
970 -re "DOSEXIT code" { }
975 if ![is_remote host] {
981 # Load a file into the debugger.
982 # The return value is 0 for success, -1 for failure.
984 # This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO
985 # to one of these values:
987 # debug file was loaded successfully and has debug information
988 # nodebug file was loaded successfully and has no debug information
989 # fail file was not loaded
991 # I tried returning this information as part of the return value,
992 # but ran into a mess because of the many re-implementations of
993 # gdb_load in config/*.exp.
995 # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use
996 # this if they can get more information set.
998 proc gdb_file_cmd { arg } {
1003 # Set whether debug info was found.
1004 # Default to "fail".
1005 global gdb_file_cmd_debug_info
1006 set gdb_file_cmd_debug_info "fail"
1008 if [is_remote host] {
1009 set arg [remote_download host $arg]
1011 perror "download failed"
1016 # The file command used to kill the remote target. For the benefit
1017 # of the testsuite, preserve this behavior.
1020 -re "Kill the program being debugged. .y or n. $" {
1022 verbose "\t\tKilling previous program being debugged"
1025 -re "$gdb_prompt $" {
1030 send_gdb "file $arg\n"
1032 -re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" {
1033 verbose "\t\tLoaded $arg into the $GDB with no debugging symbols"
1034 set gdb_file_cmd_debug_info "nodebug"
1037 -re "Reading symbols from.*done.*$gdb_prompt $" {
1038 verbose "\t\tLoaded $arg into the $GDB"
1039 set gdb_file_cmd_debug_info "debug"
1042 -re "Load new symbol table from \".*\".*y or n. $" {
1045 -re "Reading symbols from.*done.*$gdb_prompt $" {
1046 verbose "\t\tLoaded $arg with new symbol table into $GDB"
1047 set gdb_file_cmd_debug_info "debug"
1051 perror "(timeout) Couldn't load $arg, other program already loaded."
1056 -re "No such file or directory.*$gdb_prompt $" {
1057 perror "($arg) No such file or directory"
1060 -re "$gdb_prompt $" {
1061 perror "couldn't load $arg into $GDB."
1065 perror "couldn't load $arg into $GDB (timed out)."
1069 # This is an attempt to detect a core dump, but seems not to
1070 # work. Perhaps we need to match .* followed by eof, in which
1071 # gdb_expect does not seem to have a way to do that.
1072 perror "couldn't load $arg into $GDB (end of file)."
1079 # start gdb -- start gdb running, default procedure
1081 # When running over NFS, particularly if running many simultaneous
1082 # tests on different hosts all using the same server, things can
1083 # get really slow. Give gdb at least 3 minutes to start up.
1085 proc default_gdb_start { } {
1091 global gdb_spawn_id;
1093 gdb_stop_suppressing_tests;
1095 verbose "Spawning $GDB -nw $GDBFLAGS"
1097 if [info exists gdb_spawn_id] {
1101 if ![is_remote host] {
1102 if { [which $GDB] == 0 } then {
1103 perror "$GDB does not exist."
1107 set res [remote_spawn host "$GDB -nw $GDBFLAGS [host_info gdb_opts]"];
1108 if { $res < 0 || $res == "" } {
1109 perror "Spawning $GDB failed."
1113 -re "\[\r\n\]$gdb_prompt $" {
1114 verbose "GDB initialized."
1116 -re "$gdb_prompt $" {
1117 perror "GDB never initialized."
1121 perror "(timeout) GDB never initialized after 10 seconds."
1126 set gdb_spawn_id -1;
1127 # force the height to "unlimited", so no pagers get used
1129 send_gdb "set height 0\n"
1131 -re "$gdb_prompt $" {
1132 verbose "Setting height to 0." 2
1135 warning "Couldn't set the height to 0"
1138 # force the width to "unlimited", so no wraparound occurs
1139 send_gdb "set width 0\n"
1141 -re "$gdb_prompt $" {
1142 verbose "Setting width to 0." 2
1145 warning "Couldn't set the width to 0."
1151 # Return a 1 for configurations for which we don't even want to try to
1154 proc skip_cplus_tests {} {
1155 if { [istarget "d10v-*-*"] } {
1158 if { [istarget "h8300-*-*"] } {
1162 # The C++ IO streams are too large for HC11/HC12 and are thus not
1163 # available. The gdb C++ tests use them and don't compile.
1164 if { [istarget "m6811-*-*"] } {
1167 if { [istarget "m6812-*-*"] } {
1173 # Return a 1 if I don't even want to try to test FORTRAN.
1175 proc skip_fortran_tests {} {
1179 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
1180 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
1182 proc skip_altivec_tests {} {
1183 global skip_vmx_tests_saved
1184 global srcdir subdir gdb_prompt
1186 # Use the cached value, if it exists.
1187 set me "skip_altivec_tests"
1188 if [info exists skip_vmx_tests_saved] {
1189 verbose "$me: returning saved $skip_vmx_tests_saved" 2
1190 return $skip_vmx_tests_saved
1193 # Some simulators are known to not support VMX instructions.
1194 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1195 verbose "$me: target known to not support VMX, returning 1" 2
1196 return [set skip_vmx_tests_saved 1]
1199 # Make sure we have a compiler that understands altivec.
1200 set compile_flags {debug nowarnings}
1201 if [get_compiler_info not-used] {
1202 warning "Could not get compiler info"
1205 if [test_compiler_info gcc*] {
1206 set compile_flags "$compile_flags additional_flags=-maltivec"
1207 } elseif [test_compiler_info xlc*] {
1208 set compile_flags "$compile_flags additional_flags=-qaltivec"
1210 verbose "Could not compile with altivec support, returning 1" 2
1214 # Set up, compile, and execute a test program containing VMX instructions.
1215 # Include the current process ID in the file names to prevent conflicts
1216 # with invocations for multiple testsuites.
1220 set f [open $src "w"]
1221 puts $f "int main() {"
1222 puts $f "#ifdef __MACH__"
1223 puts $f " asm volatile (\"vor v0,v0,v0\");"
1225 puts $f " asm volatile (\"vor 0,0,0\");"
1227 puts $f " return 0; }"
1230 verbose "$me: compiling testfile $src" 2
1231 set lines [gdb_compile $src $exe executable $compile_flags]
1234 if ![string match "" $lines] then {
1235 verbose "$me: testfile compilation failed, returning 1" 2
1236 return [set skip_vmx_tests_saved 1]
1239 # No error message, compilation succeeded so now run it via gdb.
1243 gdb_reinitialize_dir $srcdir/$subdir
1247 -re ".*Illegal instruction.*${gdb_prompt} $" {
1248 verbose -log "\n$me altivec hardware not detected"
1249 set skip_vmx_tests_saved 1
1251 -re ".*Program exited normally.*${gdb_prompt} $" {
1252 verbose -log "\n$me: altivec hardware detected"
1253 set skip_vmx_tests_saved 0
1256 warning "\n$me: default case taken"
1257 set skip_vmx_tests_saved 1
1261 remote_file build delete $exe
1263 verbose "$me: returning $skip_vmx_tests_saved" 2
1264 return $skip_vmx_tests_saved
1267 # Skip all the tests in the file if you are not on an hppa running
1270 proc skip_hp_tests {} {
1271 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
1272 verbose "Skip hp tests is $skip_hp"
1276 set compiler_info "unknown"
1278 set hp_cc_compiler 0
1279 set hp_aCC_compiler 0
1281 # Figure out what compiler I am using.
1283 # BINFILE is a "compiler information" output file. This implementation
1284 # does not use BINFILE.
1286 # ARGS can be empty or "C++". If empty, "C" is assumed.
1288 # There are several ways to do this, with various problems.
1290 # [ gdb_compile -E $ifile -o $binfile.ci ]
1291 # source $binfile.ci
1293 # Single Unix Spec v3 says that "-E -o ..." together are not
1294 # specified. And in fact, the native compiler on hp-ux 11 (among
1295 # others) does not work with "-E -o ...". Most targets used to do
1296 # this, and it mostly worked, because it works with gcc.
1298 # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ]
1299 # source $binfile.ci
1301 # This avoids the problem with -E and -o together. This almost works
1302 # if the build machine is the same as the host machine, which is
1303 # usually true of the targets which are not gcc. But this code does
1304 # not figure which compiler to call, and it always ends up using the C
1305 # compiler. Not good for setting hp_aCC_compiler. Targets
1306 # hppa*-*-hpux* and mips*-*-irix* used to do this.
1308 # [ gdb_compile -E $ifile > $binfile.ci ]
1309 # source $binfile.ci
1311 # dejagnu target_compile says that it supports output redirection,
1312 # but the code is completely different from the normal path and I
1313 # don't want to sweep the mines from that path. So I didn't even try
1316 # set cppout [ gdb_compile $ifile "" preprocess $args quiet ]
1319 # I actually do this for all targets now. gdb_compile runs the right
1320 # compiler, and TCL captures the output, and I eval the output.
1322 # Unfortunately, expect logs the output of the command as it goes by,
1323 # and dejagnu helpfully prints a second copy of it right afterwards.
1324 # So I turn off expect logging for a moment.
1326 # [ gdb_compile $ifile $ciexe_file executable $args ]
1327 # [ remote_exec $ciexe_file ]
1328 # [ source $ci_file.out ]
1330 # I could give up on -E and just do this.
1331 # I didn't get desperate enough to try this.
1333 # -- chastain 2004-01-06
1335 proc get_compiler_info {binfile args} {
1336 # For compiler.c and compiler.cc
1339 # I am going to play with the log to keep noise out.
1343 # These come from compiler.c or compiler.cc
1344 global compiler_info
1346 # Legacy global data symbols.
1348 global hp_cc_compiler
1349 global hp_aCC_compiler
1351 # Choose which file to preprocess.
1352 set ifile "${srcdir}/lib/compiler.c"
1353 if { [llength $args] > 0 && [lindex $args 0] == "c++" } {
1354 set ifile "${srcdir}/lib/compiler.cc"
1357 # Run $ifile through the right preprocessor.
1358 # Toggle gdb.log to keep the compiler output out of the log.
1360 set cppout [ gdb_compile "${ifile}" "" preprocess [list "$args" quiet] ]
1361 log_file -a "$outdir/$tool.log"
1365 foreach cppline [ split "$cppout" "\n" ] {
1366 if { [ regexp "^#" "$cppline" ] } {
1368 } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } {
1370 } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } {
1372 verbose "get_compiler_info: $cppline" 2
1376 verbose -log "get_compiler_info: $cppline"
1381 # Reset to unknown compiler if any diagnostics happened.
1383 set compiler_info "unknown"
1386 # Set the legacy symbols.
1388 set hp_cc_compiler 0
1389 set hp_aCC_compiler 0
1390 if { [regexp "^gcc-1-" "$compiler_info" ] } { set gcc_compiled 1 }
1391 if { [regexp "^gcc-2-" "$compiler_info" ] } { set gcc_compiled 2 }
1392 if { [regexp "^gcc-3-" "$compiler_info" ] } { set gcc_compiled 3 }
1393 if { [regexp "^gcc-4-" "$compiler_info" ] } { set gcc_compiled 4 }
1394 if { [regexp "^gcc-5-" "$compiler_info" ] } { set gcc_compiled 5 }
1395 if { [regexp "^hpcc-" "$compiler_info" ] } { set hp_cc_compiler 1 }
1396 if { [regexp "^hpacc-" "$compiler_info" ] } { set hp_aCC_compiler 1 }
1398 # Log what happened.
1399 verbose -log "get_compiler_info: $compiler_info"
1401 # Most compilers will evaluate comparisons and other boolean
1402 # operations to 0 or 1.
1403 uplevel \#0 { set true 1 }
1404 uplevel \#0 { set false 0 }
1406 # Use of aCC results in boolean results being displayed as
1408 if { $hp_aCC_compiler } {
1409 uplevel \#0 { set true true }
1410 uplevel \#0 { set false false }
1416 proc test_compiler_info { {compiler ""} } {
1417 global compiler_info
1419 # if no arg, return the compiler_info string
1421 if [string match "" $compiler] {
1422 if [info exists compiler_info] {
1423 return $compiler_info
1425 perror "No compiler info found."
1429 return [string match $compiler $compiler_info]
1432 set gdb_wrapper_initialized 0
1434 proc gdb_wrapper_init { args } {
1435 global gdb_wrapper_initialized;
1436 global gdb_wrapper_file;
1437 global gdb_wrapper_flags;
1439 if { $gdb_wrapper_initialized == 1 } { return; }
1441 if {[target_info exists needs_status_wrapper] && \
1442 [target_info needs_status_wrapper] != "0"} {
1443 set result [build_wrapper "testglue.o"];
1444 if { $result != "" } {
1445 set gdb_wrapper_file [lindex $result 0];
1446 set gdb_wrapper_flags [lindex $result 1];
1448 warning "Status wrapper failed to build."
1451 set gdb_wrapper_initialized 1
1454 proc gdb_compile {source dest type options} {
1455 global GDB_TESTCASE_OPTIONS;
1456 global gdb_wrapper_file;
1457 global gdb_wrapper_flags;
1458 global gdb_wrapper_initialized;
1460 # Add platform-specific options if a shared library was specified using
1461 # "shlib=librarypath" in OPTIONS.
1464 foreach opt $options {
1465 if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] {
1466 if [test_compiler_info "xlc-*"] {
1467 # IBM xlc compiler doesn't accept shared library named other
1468 # than .so: use "-Wl," to bypass this
1469 lappend source "-Wl,$shlib_name"
1471 lappend source $shlib_name
1473 if {$shlib_found == 0} {
1475 if { ([test_compiler_info "gcc-*"]
1476 && ([istarget "powerpc*-*-aix*"]
1477 || [istarget "rs6000*-*-aix*"] )) } {
1478 lappend options "additional_flags=-L${objdir}/${subdir}"
1479 } elseif { [istarget "mips-sgi-irix*"] } {
1480 lappend options "additional_flags=-rpath ${objdir}/${subdir}"
1484 lappend new_options $opt
1487 set options $new_options
1489 if [target_info exists gdb_stub] {
1490 set options2 { "additional_flags=-Dusestubs" }
1491 lappend options "libs=[target_info gdb_stub]";
1492 set options [concat $options2 $options]
1494 if [target_info exists is_vxworks] {
1495 set options2 { "additional_flags=-Dvxworks" }
1496 lappend options "libs=[target_info gdb_stub]";
1497 set options [concat $options2 $options]
1499 if [info exists GDB_TESTCASE_OPTIONS] {
1500 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
1502 verbose "options are $options"
1503 verbose "source is $source $dest $type $options"
1505 if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init }
1507 if {[target_info exists needs_status_wrapper] && \
1508 [target_info needs_status_wrapper] != "0" && \
1509 [info exists gdb_wrapper_file]} {
1510 lappend options "libs=${gdb_wrapper_file}"
1511 lappend options "ldflags=${gdb_wrapper_flags}"
1514 # Replace the "nowarnings" option with the appropriate additional_flags
1515 # to disable compiler warnings.
1516 set nowarnings [lsearch -exact $options nowarnings]
1517 if {$nowarnings != -1} {
1518 if [target_info exists gdb,nowarnings_flag] {
1519 set flag "additional_flags=[target_info gdb,nowarnings_flag]"
1521 set flag "additional_flags=-w"
1523 set options [lreplace $options $nowarnings $nowarnings $flag]
1526 set result [target_compile $source $dest $type $options];
1527 regsub "\[\r\n\]*$" "$result" "" result;
1528 regsub "^\[\r\n\]*" "$result" "" result;
1529 if { $result != "" && [lsearch $options quiet] == -1} {
1530 clone_output "gdb compile failed, $result"
1536 # This is just like gdb_compile, above, except that it tries compiling
1537 # against several different thread libraries, to see which one this
1539 proc gdb_compile_pthreads {source dest type options} {
1541 set why_msg "unrecognized error"
1542 foreach lib {-lpthreads -lpthread -lthread} {
1543 # This kind of wipes out whatever libs the caller may have
1544 # set. Or maybe theirs will override ours. How infelicitous.
1545 set options_with_lib [concat $options [list libs=$lib quiet]]
1546 set ccout [gdb_compile $source $dest $type $options_with_lib]
1547 switch -regexp -- $ccout {
1548 ".*no posix threads support.*" {
1549 set why_msg "missing threads include file"
1552 ".*cannot open -lpthread.*" {
1553 set why_msg "missing runtime threads library"
1555 ".*Can't find library for -lpthread.*" {
1556 set why_msg "missing runtime threads library"
1559 pass "successfully compiled posix threads test case"
1565 if {!$built_binfile} {
1566 unsupported "Couldn't compile $source: ${why_msg}"
1571 # Build a shared library from SOURCES. You must use get_compiler_info
1574 proc gdb_compile_shlib {sources dest options} {
1575 set obj_options $options
1577 switch -glob [test_compiler_info] {
1579 lappend obj_options "additional_flags=-qpic"
1582 if { !([istarget "powerpc*-*-aix*"]
1583 || [istarget "rs6000*-*-aix*"]
1584 || [istarget "*-*-cygwin*"]
1585 || [istarget "*-*-mingw*"]
1586 || [istarget "*-*-pe*"]) } {
1587 lappend obj_options "additional_flags=-fpic"
1591 switch -glob [istarget] {
1593 lappend obj_options "additional_flags=+z"
1596 # Disable SGI compiler's implicit -Dsgi
1597 lappend obj_options "additional_flags=-Usgi"
1600 # don't know what the compiler is...
1606 set outdir [file dirname $dest]
1608 foreach source $sources {
1609 set sourcebase [file tail $source]
1610 if {[gdb_compile $source "${outdir}/${sourcebase}.o" object $obj_options] != ""} {
1613 lappend objects ${outdir}/${sourcebase}.o
1616 if [istarget "hppa*-*-hpux*"] {
1617 remote_exec build "ld -b ${objects} -o ${dest}"
1619 set link_options $options
1620 if [test_compiler_info "xlc-*"] {
1621 lappend link_options "additional_flags=-qmkshrobj"
1623 lappend link_options "additional_flags=-shared"
1625 if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
1631 # This is just like gdb_compile_pthreads, above, except that we always add the
1632 # objc library for compiling Objective-C programs
1633 proc gdb_compile_objc {source dest type options} {
1635 set why_msg "unrecognized error"
1636 foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} {
1637 # This kind of wipes out whatever libs the caller may have
1638 # set. Or maybe theirs will override ours. How infelicitous.
1639 if { $lib == "solaris" } {
1640 set lib "-lpthread -lposix4"
1642 if { $lib != "-lobjc" } {
1643 set lib "-lobjc $lib"
1645 set options_with_lib [concat $options [list libs=$lib quiet]]
1646 set ccout [gdb_compile $source $dest $type $options_with_lib]
1647 switch -regexp -- $ccout {
1648 ".*no posix threads support.*" {
1649 set why_msg "missing threads include file"
1652 ".*cannot open -lpthread.*" {
1653 set why_msg "missing runtime threads library"
1655 ".*Can't find library for -lpthread.*" {
1656 set why_msg "missing runtime threads library"
1659 pass "successfully compiled objc with posix threads test case"
1665 if {!$built_binfile} {
1666 unsupported "Couldn't compile $source: ${why_msg}"
1671 proc send_gdb { string } {
1672 global suppress_flag;
1673 if { $suppress_flag } {
1674 return "suppressed";
1676 return [remote_send host "$string"];
1682 proc gdb_expect { args } {
1683 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
1684 set gtimeout [lindex $args 0];
1685 set expcode [list [lindex $args 1]];
1687 upvar timeout timeout;
1690 if [target_info exists gdb,timeout] {
1691 if [info exists timeout] {
1692 if { $timeout < [target_info gdb,timeout] } {
1693 set gtimeout [target_info gdb,timeout];
1695 set gtimeout $timeout;
1698 set gtimeout [target_info gdb,timeout];
1702 if ![info exists gtimeout] {
1704 if [info exists timeout] {
1705 set gtimeout $timeout;
1712 global suppress_flag;
1713 global remote_suppress_flag;
1714 if [info exists remote_suppress_flag] {
1715 set old_val $remote_suppress_flag;
1717 if [info exists suppress_flag] {
1718 if { $suppress_flag } {
1719 set remote_suppress_flag 1;
1723 {uplevel remote_expect host $gtimeout $expcode} string];
1724 if [info exists old_val] {
1725 set remote_suppress_flag $old_val;
1727 if [info exists remote_suppress_flag] {
1728 unset remote_suppress_flag;
1733 global errorInfo errorCode;
1735 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
1736 } elseif {$code == 2} {
1737 return -code return $string
1738 } elseif {$code == 3} {
1740 } elseif {$code > 4} {
1741 return -code $code $string
1745 # gdb_expect_list MESSAGE SENTINEL LIST -- expect a sequence of outputs
1747 # Check for long sequence of output by parts.
1748 # MESSAGE: is the test message to be printed with the test success/fail.
1749 # SENTINEL: Is the terminal pattern indicating that output has finished.
1750 # LIST: is the sequence of outputs to match.
1751 # If the sentinel is recognized early, it is considered an error.
1754 # 1 if the test failed,
1755 # 0 if the test passes,
1756 # -1 if there was an internal error.
1758 proc gdb_expect_list {test sentinel list} {
1760 global suppress_flag
1763 if { $suppress_flag } {
1765 unresolved "${test}"
1767 while { ${index} < [llength ${list}] } {
1768 set pattern [lindex ${list} ${index}]
1769 set index [expr ${index} + 1]
1770 if { ${index} == [llength ${list}] } {
1773 -re "${pattern}${sentinel}" {
1774 # pass "${test}, pattern ${index} + sentinel"
1777 fail "${test} (pattern ${index} + sentinel)"
1780 -re ".*A problem internal to GDB has been detected" {
1781 fail "${test} (GDB internal error)"
1783 gdb_internal_error_resync
1786 fail "${test} (pattern ${index} + sentinel) (timeout)"
1791 # unresolved "${test}, pattern ${index} + sentinel"
1797 # pass "${test}, pattern ${index}"
1800 fail "${test} (pattern ${index})"
1803 -re ".*A problem internal to GDB has been detected" {
1804 fail "${test} (GDB internal error)"
1806 gdb_internal_error_resync
1809 fail "${test} (pattern ${index}) (timeout)"
1814 # unresolved "${test}, pattern ${index}"
1828 proc gdb_suppress_entire_file { reason } {
1829 global suppress_flag;
1831 warning "$reason\n";
1832 set suppress_flag -1;
1836 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
1837 # gdb_expect to fail immediately (until the next call to
1838 # gdb_stop_suppressing_tests).
1840 proc gdb_suppress_tests { args } {
1841 global suppress_flag;
1843 return; # fnf - disable pending review of results where
1844 # testsuite ran better without this
1847 if { $suppress_flag == 1 } {
1848 if { [llength $args] > 0 } {
1849 warning "[lindex $args 0]\n";
1851 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
1857 # Clear suppress_flag.
1859 proc gdb_stop_suppressing_tests { } {
1860 global suppress_flag;
1862 if [info exists suppress_flag] {
1863 if { $suppress_flag > 0 } {
1864 set suppress_flag 0;
1865 clone_output "Tests restarted.\n";
1868 set suppress_flag 0;
1872 proc gdb_clear_suppressed { } {
1873 global suppress_flag;
1875 set suppress_flag 0;
1878 proc gdb_start { } {
1883 catch default_gdb_exit
1887 # gdb_load_cmd -- load a file into the debugger.
1888 # ARGS - additional args to load command.
1889 # return a -1 if anything goes wrong.
1891 proc gdb_load_cmd { args } {
1894 if [target_info exists gdb_load_timeout] {
1895 set loadtimeout [target_info gdb_load_timeout]
1897 set loadtimeout 1600
1899 send_gdb "load $args\n"
1900 verbose "Timeout is now $timeout seconds" 2
1901 gdb_expect $loadtimeout {
1902 -re "Loading section\[^\r\]*\r\n" {
1905 -re "Start address\[\r\]*\r\n" {
1908 -re "Transfer rate\[\r\]*\r\n" {
1911 -re "Memory access error\[^\r\]*\r\n" {
1912 perror "Failed to load program"
1915 -re "$gdb_prompt $" {
1918 -re "(.*)\r\n$gdb_prompt " {
1919 perror "Unexpected reponse from 'load' -- $expect_out(1,string)"
1923 perror "Timed out trying to load $arg."
1931 # gdb_load -- load a file into the debugger.
1932 # Many files in config/*.exp override this procedure.
1934 proc gdb_load { arg } {
1935 return [gdb_file_cmd $arg]
1938 proc gdb_continue { function } {
1941 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
1944 proc default_gdb_init { args } {
1945 global gdb_wrapper_initialized
1947 gdb_clear_suppressed;
1949 # Make sure that the wrapper is rebuilt
1950 # with the appropriate multilib option.
1951 set gdb_wrapper_initialized 0
1953 # Uh, this is lame. Really, really, really lame. But there's this *one*
1954 # testcase that will fail in random places if we don't increase this.
1957 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
1958 if { [llength $args] > 0 } {
1961 set file [lindex $args 0];
1963 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
1966 if [target_info exists gdb_prompt] {
1967 set gdb_prompt [target_info gdb_prompt];
1969 set gdb_prompt "\\(gdb\\)"
1973 proc gdb_init { args } {
1974 return [eval default_gdb_init $args];
1977 proc gdb_finish { } {
1982 set debug_format "unknown"
1984 # Run the gdb command "info source" and extract the debugging format
1985 # information from the output and save it in debug_format.
1987 proc get_debug_format { } {
1993 set debug_format "unknown"
1994 send_gdb "info source\n"
1996 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
1997 set debug_format $expect_out(1,string)
1998 verbose "debug format is $debug_format"
2001 -re "No current source file.\r\n$gdb_prompt $" {
2002 perror "get_debug_format used when no current source file"
2005 -re "$gdb_prompt $" {
2006 warning "couldn't check debug format (no valid response)."
2010 warning "couldn't check debug format (timed out)."
2016 # Return true if FORMAT matches the debug format the current test was
2017 # compiled with. FORMAT is a shell-style globbing pattern; it can use
2018 # `*', `[...]', and so on.
2020 # This function depends on variables set by `get_debug_format', above.
2022 proc test_debug_format {format} {
2025 return [expr [string match $format $debug_format] != 0]
2028 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
2029 # COFF, stabs, etc). If that format matches the format that the
2030 # current test was compiled with, then the next test is expected to
2031 # fail for any target. Returns 1 if the next test or set of tests is
2032 # expected to fail, 0 otherwise (or if it is unknown). Must have
2033 # previously called get_debug_format.
2034 proc setup_xfail_format { format } {
2035 set ret [test_debug_format $format];
2043 proc gdb_step_for_stub { } {
2046 if ![target_info exists gdb,use_breakpoint_for_stub] {
2047 if [target_info exists gdb_stub_step_command] {
2048 set command [target_info gdb_stub_step_command];
2052 send_gdb "${command}\n";
2055 -re "(main.* at |.*in .*start).*$gdb_prompt" {
2058 -re ".*$gdb_prompt" {
2060 if { $tries == 5 } {
2061 fail "stepping out of breakpoint function";
2064 send_gdb "${command}\n";
2068 fail "stepping out of breakpoint function";
2075 -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" {
2076 set file $expect_out(1,string);
2077 set linenum [expr $expect_out(2,string) + 1];
2078 set breakplace "${file}:${linenum}";
2082 send_gdb "break ${breakplace}\n";
2084 -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" {
2085 set breakpoint $expect_out(1,string);
2087 -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" {
2088 set breakpoint $expect_out(1,string);
2092 send_gdb "continue\n";
2094 -re "Breakpoint ${breakpoint},.*$gdb_prompt" {
2095 gdb_test "delete $breakpoint" ".*" "";
2102 # gdb_get_line_number TEXT [FILE]
2104 # Search the source file FILE, and return the line number of the
2105 # first line containing TEXT. If no match is found, return -1.
2107 # TEXT is a string literal, not a regular expression.
2109 # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is
2110 # specified, and does not start with "/", then it is assumed to be in
2111 # "$srcdir/$subdir". This is awkward, and can be fixed in the future,
2112 # by changing the callers and the interface at the same time.
2113 # In particular: gdb.base/break.exp, gdb.base/condbreak.exp,
2114 # gdb.base/ena-dis-br.exp.
2116 # Use this function to keep your test scripts independent of the
2117 # exact line numbering of the source file. Don't write:
2119 # send_gdb "break 20"
2121 # This means that if anyone ever edits your test's source file,
2122 # your test could break. Instead, put a comment like this on the
2123 # source file line you want to break at:
2125 # /* breakpoint spot: frotz.exp: test name */
2127 # and then write, in your test script (which we assume is named
2130 # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
2132 # (Yes, Tcl knows how to handle the nested quotes and brackets.
2135 # % puts "foo [lindex "bar baz" 1]"
2138 # Tcl is quite clever, for a little stringy language.)
2142 # The previous implementation of this procedure used the gdb search command.
2143 # This version is different:
2145 # . It works with MI, and it also works when gdb is not running.
2147 # . It operates on the build machine, not the host machine.
2149 # . For now, this implementation fakes a current directory of
2150 # $srcdir/$subdir to be compatible with the old implementation.
2151 # This will go away eventually and some callers will need to
2154 # . The TEXT argument is literal text and matches literally,
2155 # not a regular expression as it was before.
2157 # . State changes in gdb, such as changing the current file
2158 # and setting $_, no longer happen.
2160 # After a bit of time we can forget about the differences from the
2161 # old implementation.
2163 # --chastain 2004-08-05
2165 proc gdb_get_line_number { text { file "" } } {
2170 if { "$file" == "" } then {
2173 if { ! [regexp "^/" "$file"] } then {
2174 set file "$srcdir/$subdir/$file"
2177 if { [ catch { set fd [open "$file"] } message ] } then {
2183 for { set line 1 } { 1 } { incr line } {
2184 if { [ catch { set nchar [gets "$fd" body] } message ] } then {
2188 if { $nchar < 0 } then {
2191 if { [string first "$text" "$body"] >= 0 } then {
2197 if { [ catch { close "$fd" } message ] } then {
2205 # gdb_continue_to_end:
2206 # The case where the target uses stubs has to be handled specially. If a
2207 # stub is used, we set a breakpoint at exit because we cannot rely on
2208 # exit() behavior of a remote target.
2210 # mssg is the error message that gets printed.
2212 proc gdb_continue_to_end {mssg} {
2213 if [target_info exists use_gdb_stub] {
2214 if {![gdb_breakpoint "exit"]} {
2217 gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \
2218 "continue until exit at $mssg"
2220 # Continue until we exit. Should not stop again.
2221 # Don't bother to check the output of the program, that may be
2222 # extremely tough for some remote systems.
2223 gdb_test "continue"\
2224 "Continuing.\[\r\n0-9\]+(... EXIT code 0\[\r\n\]+|Program exited normally\\.).*"\
2225 "continue until exit at $mssg"
2229 proc rerun_to_main {} {
2232 if [target_info exists use_gdb_stub] {
2235 -re ".*Breakpoint .*main .*$gdb_prompt $"\
2236 {pass "rerun to main" ; return 0}
2237 -re "$gdb_prompt $"\
2238 {fail "rerun to main" ; return 0}
2239 timeout {fail "(timeout) rerun to main" ; return 0}
2244 -re "The program .* has been started already.*y or n. $" {
2248 -re "Starting program.*$gdb_prompt $"\
2249 {pass "rerun to main" ; return 0}
2250 -re "$gdb_prompt $"\
2251 {fail "rerun to main" ; return 0}
2252 timeout {fail "(timeout) rerun to main" ; return 0}
2257 # Print a message and return true if a test should be skipped
2258 # due to lack of floating point suport.
2260 proc gdb_skip_float_test { msg } {
2261 if [target_info exists gdb,skip_float_tests] {
2262 verbose "Skipping test '$msg': no float tests.";
2268 # Print a message and return true if a test should be skipped
2269 # due to lack of stdio support.
2271 proc gdb_skip_stdio_test { msg } {
2272 if [target_info exists gdb,noinferiorio] {
2273 verbose "Skipping test '$msg': no inferior i/o.";
2279 proc gdb_skip_bogus_test { msg } {
2284 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
2285 # ${binfile}.dbglnk, which is just like the executable ($binfile) but without
2286 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
2287 # the name of a debuginfo only file. This file will be stored in the
2288 # gdb.base/.debug subdirectory.
2290 # Functions for separate debug info testing
2292 # starting with an executable:
2293 # foo --> original executable
2295 # at the end of the process we have:
2296 # foo.stripped --> foo w/o debug info
2297 # .debug/foo.debug --> foo's debug info
2298 # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug.
2300 # Return the name of the file in which we should stor EXEC's separated
2301 # debug info. EXEC contains the full path.
2302 proc separate_debug_filename { exec } {
2304 # In a .debug subdirectory off the same directory where the testcase
2305 # executable is going to be. Something like:
2306 # <your-path>/gdb/testsuite/gdb.base/.debug/blah.debug.
2307 # This is the default location where gdb expects to findi
2308 # the debug info file.
2310 set exec_dir [file dirname $exec]
2311 set exec_file [file tail $exec]
2312 set debug_dir [file join $exec_dir ".debug"]
2313 set debug_file [file join $debug_dir "${exec_file}.debug"]
2318 # Create stripped files for DEST, replacing it. If ARGS is passed, it is a
2319 # list of optional flags. The only currently supported flag is no-main,
2320 # which removes the symbol entry for main from the separate debug file.
2322 proc gdb_gnu_strip_debug { dest args } {
2324 # First, make sure that we can do this. This is nasty. We need to
2325 # check for the stabs debug format. To do this we must run gdb on
2326 # the unstripped executable, list 'main' (as to have a default
2327 # source file), use get_debug_format (which does 'info source')
2328 # and then see if the debug info is stabs. If so, we bail out. We
2329 # cannot do this any other way because get_debug_format finds out
2330 # the debug format using gdb itself, and in case of stabs we get
2331 # an error loading the program if it is already stripped. An
2332 # alternative would be to find out the debug info from the flags
2333 # passed to dejagnu when the test is run.
2338 gdb_test "list main" "" ""
2340 if { [test_debug_format "stabs"] } then {
2341 # The separate debug info feature doesn't work well in
2342 # binutils with stabs. It produces a corrupted debug info
2343 # only file, and gdb chokes on it. It is almost impossible to
2344 # capture the failing message out of gdb, because it happens
2345 # inside gdb_load. At that point any error message is
2346 # intercepted by dejagnu itself, and, because of the error
2347 # threshold, any faulty test result is changed into an
2348 # UNRESOLVED. (see dejagnu/lib/framework.exp)
2349 unsupported "no separate debug info handling with stabs"
2351 } elseif { [test_debug_format "unknown"] } then {
2352 # gdb doesn't know what the debug format is. We are out of luck here.
2353 unsupported "unknown debugging format"
2358 set debug_file [separate_debug_filename $dest]
2359 set strip_to_file_program strip
2360 set objcopy_program objcopy
2362 # Make sure the directory that will hold the separated debug
2363 # info actually exists.
2364 set debug_dir [file dirname $debug_file]
2365 if {! [file isdirectory $debug_dir]} {
2366 file mkdir $debug_dir
2369 set debug_link [file tail $debug_file]
2370 set stripped_file "${dest}.stripped"
2372 # Get rid of the debug info, and store result in stripped_file
2373 # something like gdb/testsuite/gdb.base/blah.stripped.
2374 set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
2375 verbose "result is $result"
2376 verbose "output is $output"
2381 # Get rid of everything but the debug info, and store result in debug_file
2382 # This will be in the .debug subdirectory, see above.
2383 set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
2384 verbose "result is $result"
2385 verbose "output is $output"
2390 # If no-main is passed, strip the symbol for main from the separate
2391 # file. This is to simulate the behavior of elfutils's eu-strip, which
2392 # leaves the symtab in the original file only. There's no way to get
2393 # objcopy or strip to remove the symbol table without also removing the
2394 # debugging sections, so this is as close as we can get.
2395 if { [llength $args] == 1 && [lindex $args 0] == "no-main" } {
2396 set result [catch "exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp" output]
2397 verbose "result is $result"
2398 verbose "output is $output"
2402 file delete "${debug_file}"
2403 file rename "${debug_file}-tmp" "${debug_file}"
2406 # Link the two previous output files together, adding the .gnu_debuglink
2407 # section to the stripped_file, containing a pointer to the debug_file,
2408 # save the new file in dest.
2409 # This will be the regular executable filename, in the usual location.
2410 set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
2411 verbose "result is $result"
2412 verbose "output is $output"
2420 # Test the output of GDB_COMMAND matches the pattern obtained
2421 # by concatenating all elements of EXPECTED_LINES. This makes
2422 # it possible to split otherwise very long string into pieces.
2423 # If third argument is not empty, it's used as the name of the
2424 # test to be printed on pass/fail.
2425 proc help_test_raw { gdb_command expected_lines args } {
2426 set message $gdb_command
2427 if [llength $args]>0 then {
2428 set message [lindex $args 0]
2430 set expected_output [join $expected_lines ""]
2431 gdb_test "${gdb_command}" "${expected_output}" $message
2434 # Test the output of "help COMMNAD_CLASS". EXPECTED_INITIAL_LINES
2435 # are regular expressions that should match the beginning of output,
2436 # before the list of commands in that class. The presence of
2437 # command list and standard epilogue will be tested automatically.
2438 proc test_class_help { command_class expected_initial_lines args } {
2440 "List of commands\:.*\[\r\n\]+"
2441 "Type \"help\" followed by command name for full documentation\.\[\r\n\]+"
2442 "Type \"apropos word\" to search for commands related to \"word\"\.[\r\n\]+"
2443 "Command name abbreviations are allowed if unambiguous\."
2445 set l_entire_body [concat $expected_initial_lines $l_stock_body]
2447 eval [list help_test_raw "help ${command_class}" $l_entire_body] $args
2450 # COMMAND_LIST should have either one element -- command to test, or
2451 # two elements -- abbreviated command to test, and full command the first
2452 # element is abbreviation of.
2453 # The command must be a prefix command. EXPECTED_INITIAL_LINES
2454 # are regular expressions that should match the beginning of output,
2455 # before the list of subcommands. The presence of
2456 # subcommand list and standard epilogue will be tested automatically.
2457 proc test_prefix_command_help { command_list expected_initial_lines args } {
2458 set command [lindex $command_list 0]
2459 if {[llength $command_list]>1} {
2460 set full_command [lindex $command_list 1]
2462 set full_command $command
2464 # Use 'list' and not just {} because we want variables to
2465 # be expanded in this list.
2466 set l_stock_body [list\
2467 "List of $full_command subcommands\:.*\[\r\n\]+"\
2468 "Type \"help $full_command\" followed by $full_command subcommand name for full documentation\.\[\r\n\]+"\
2469 "Type \"apropos word\" to search for commands related to \"word\"\.\[\r\n\]+"\
2470 "Command name abbreviations are allowed if unambiguous\."]
2471 set l_entire_body [concat $expected_initial_lines $l_stock_body]
2472 if {[llength $args]>0} {
2473 help_test_raw "help ${command}" $l_entire_body [lindex $args 0]
2475 help_test_raw "help ${command}" $l_entire_body