1 # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3 # Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 # This file was written by Fred Fish. (fnf@cygnus.com)
21 # Generic gdb subroutines that should work for any target. If these
22 # need to be modified for any target, it can be done with a variable
23 # or by passing arguments.
29 if [info exists TOOL_EXECUTABLE] {
30 set GDB $TOOL_EXECUTABLE;
32 if ![info exists GDB] {
33 if ![is_remote host] {
34 set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]]
36 set GDB [transform gdb];
39 verbose "using GDB = $GDB" 2
42 if ![info exists GDBFLAGS] {
45 verbose "using GDBFLAGS = $GDBFLAGS" 2
47 # The variable gdb_prompt is a regexp which matches the gdb prompt.
48 # Set it if it is not already set.
50 if ![info exists gdb_prompt] then {
51 set gdb_prompt "\[(\]gdb\[)\]"
54 # Needed for some tests under Cygwin.
58 if ![info exists env(EXEEXT)] {
61 set EXEEXT $env(EXEEXT)
64 ### Only procedures should come after this point.
67 # gdb_version -- extract and print the version number of GDB
69 proc default_gdb_version {} {
73 set fileid [open "gdb_cmd" w];
76 set cmdfile [remote_download host "gdb_cmd"];
77 set output [remote_exec host "$GDB -nw --command $cmdfile"]
78 remote_file build delete "gdb_cmd";
79 remote_file host delete "$cmdfile";
80 set tmp [lindex $output 1];
82 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
83 if ![is_remote host] {
84 clone_output "[which $GDB] version $version $GDBFLAGS\n"
86 clone_output "$GDB on remote host version $version $GDBFLAGS\n"
90 proc gdb_version { } {
91 return [default_gdb_version];
95 # gdb_unload -- unload a file if one is loaded
104 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
105 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
106 -re "A program is being debugged already..*Kill it.*y or n. $"\
108 verbose "\t\tKilling previous program being debugged"
111 -re "Discard symbol table from .*y or n.*$" {
115 -re "$gdb_prompt $" {}
117 perror "couldn't unload file in $GDB (timed out)."
123 # Many of the tests depend on setting breakpoints at various places and
124 # running until that breakpoint is reached. At times, we want to start
125 # with a clean-slate with respect to breakpoints, so this utility proc
126 # lets us do this without duplicating this code everywhere.
129 proc delete_breakpoints {} {
132 # we need a larger timeout value here or this thing just confuses
133 # itself. May need a better implementation if possible. - guo
135 send_gdb "delete breakpoints\n"
137 -re "Delete all breakpoints.*y or n.*$" {
141 -re "$gdb_prompt $" { # This happens if there were no breakpoints
143 timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
145 send_gdb "info breakpoints\n"
147 -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
148 -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
149 -re "Delete all breakpoints.*or n.*$" {
153 timeout { perror "info breakpoints (timeout)" ; return }
159 # Generic run command.
161 # The second pattern below matches up to the first newline *only*.
162 # Using ``.*$'' could swallow up output that we attempt to match
165 proc gdb_run_cmd {args} {
168 if [target_info exists gdb_init_command] {
169 send_gdb "[target_info gdb_init_command]\n";
171 -re "$gdb_prompt $" { }
173 perror "gdb_init_command for target failed";
179 if [target_info exists use_gdb_stub] {
180 if [target_info exists gdb,do_reload_on_run] {
181 # Specifying no file, defaults to the executable
182 # currently being debugged.
183 if { [gdb_load ""] != 0 } {
186 send_gdb "continue\n";
188 -re "Continu\[^\r\n\]*\[\r\n\]" {}
194 if [target_info exists gdb,start_symbol] {
195 set start [target_info gdb,start_symbol];
199 send_gdb "jump *$start\n"
201 while { $start_attempt } {
202 # Cap (re)start attempts at three to ensure that this loop
203 # always eventually fails. Don't worry about trying to be
204 # clever and not send a command when it has failed.
205 if [expr $start_attempt > 3] {
206 perror "Jump to start() failed (retry count exceeded)";
209 set start_attempt [expr $start_attempt + 1];
211 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
214 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
215 perror "Can't find start symbol to run in gdb_run";
218 -re "No symbol \"start\" in current.*$gdb_prompt $" {
219 send_gdb "jump *_start\n";
221 -re "No symbol.*context.*$gdb_prompt $" {
224 -re "Line.* Jump anyway.*y or n. $" {
227 -re "The program is not being run.*$gdb_prompt $" {
228 if { [gdb_load ""] != 0 } {
231 send_gdb "jump *$start\n";
234 perror "Jump to start() failed (timeout)";
239 if [target_info exists gdb_stub] {
241 -re "$gdb_prompt $" {
242 send_gdb "continue\n"
249 if [target_info exists gdb,do_reload_on_run] {
250 if { [gdb_load ""] != 0 } {
254 send_gdb "run $args\n"
255 # This doesn't work quite right yet.
257 -re "The program .* has been started already.*y or n. $" {
261 -re "Starting program: \[^\r\n\]*" {}
265 # Set a breakpoint at FUNCTION. If there is an additional argument it is
266 # a list of options; the only currently supported option is allow-pending.
268 proc gdb_breakpoint { function args } {
272 set pending_response n
273 if {[lsearch -exact [lindex $args 0] allow-pending] != -1} {
274 set pending_response y
277 send_gdb "break $function\n"
278 # The first two regexps are what we get with -g, the third is without -g.
280 -re "Breakpoint \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
281 -re "Breakpoint \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
282 -re "Breakpoint \[0-9\]* at .*$gdb_prompt $" {}
283 -re "Breakpoint \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" {
284 if {$pending_response == "n"} {
285 fail "setting breakpoint at $function"
289 -re "Make breakpoint pending.*y or \\\[n\\\]. $" {
290 send_gdb "$pending_response\n"
293 -re "$gdb_prompt $" { fail "setting breakpoint at $function" ; return 0 }
294 timeout { fail "setting breakpoint at $function (timeout)" ; return 0 }
299 # Set breakpoint at function and run gdb until it breaks there.
300 # Since this is the only breakpoint that will be set, if it stops
301 # at a breakpoint, we will assume it is the one we want. We can't
302 # just compare to "function" because it might be a fully qualified,
303 # single quoted C++ function specifier. If there's an additional argument,
304 # pass it to gdb_breakpoint.
306 proc runto { function args } {
312 if ![gdb_breakpoint $function [lindex $args 0]] {
318 # the "at foo.c:36" output we get with -g.
319 # the "in func" output we get without -g.
321 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
324 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
327 -re "$gdb_prompt $" {
328 fail "running to $function in runto"
332 fail "running to $function in runto (timeout)"
340 # runto_main -- ask gdb to run until we hit a breakpoint at main.
341 # The case where the target uses stubs has to be handled
342 # specially--if it uses stubs, assuming we hit
343 # breakpoint() and just step out of the function.
345 proc runto_main { } {
349 if ![target_info exists gdb_stub] {
361 ### Continue, and expect to hit a breakpoint.
362 ### Report a pass or fail, depending on whether it seems to have
363 ### worked. Use NAME as part of the test name; each call to
364 ### continue_to_breakpoint should use a NAME which is unique within
366 proc gdb_continue_to_breakpoint {name} {
368 set full_name "continue to breakpoint: $name"
370 send_gdb "continue\n"
372 -re "Breakpoint .* at .*\r\n$gdb_prompt $" {
375 -re ".*$gdb_prompt $" {
379 fail "$full_name (timeout)"
385 # gdb_internal_error_resync:
387 # Answer the questions GDB asks after it reports an internal error
388 # until we get back to a GDB prompt. Decline to quit the debugging
389 # session, and decline to create a core file. Return non-zero if the
392 # This procedure just answers whatever questions come up until it sees
393 # a GDB prompt; it doesn't require you to have matched the input up to
394 # any specific point. However, it only answers questions it sees in
395 # the output itself, so if you've matched a question, you had better
396 # answer it yourself before calling this.
398 # You can use this function thus:
402 # -re ".*A problem internal to GDB has been detected" {
403 # gdb_internal_error_resync
408 proc gdb_internal_error_resync {} {
412 while {$count < 10} {
414 -re "Quit this debugging session\\? \\(y or n\\) $" {
418 -re "Create a core file of GDB\\? \\(y or n\\) $" {
422 -re "$gdb_prompt $" {
423 # We're resynchronized.
427 perror "Could not resync from internal error (timeout)"
432 perror "Could not resync from internal error (resync count exceeded)"
437 # gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS
438 # Send a command to gdb; test the result.
440 # COMMAND is the command to execute, send to GDB with send_gdb. If
441 # this is the null string no command is sent.
442 # MESSAGE is a message to be printed with the built-in failure patterns
443 # if one of them matches. If MESSAGE is empty COMMAND will be used.
444 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
445 # patterns. Pattern elements will be evaluated in the caller's
446 # context; action elements will be executed in the caller's context.
447 # Unlike patterns for gdb_test, these patterns should generally include
448 # the final newline and prompt.
451 # 1 if the test failed, according to a built-in failure pattern
452 # 0 if only user-supplied patterns matched
453 # -1 if there was an internal error.
455 # You can use this function thus:
457 # gdb_test_multiple "print foo" "test foo" {
458 # -re "expected output 1" {
461 # -re "expected output 2" {
466 # The standard patterns, such as "Program exited..." and "A problem
467 # ...", all being implicitly appended to that list.
469 proc gdb_test_multiple { command message user_code } {
473 upvar timeout timeout
474 upvar expect_out expect_out
476 if { $message == "" } {
480 # TCL/EXPECT WART ALERT
481 # Expect does something very strange when it receives a single braced
482 # argument. It splits it along word separators and performs substitutions.
483 # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
484 # evaluated as "\[ab\]". But that's not how TCL normally works; inside a
485 # double-quoted list item, "\[ab\]" is just a long way of representing
486 # "[ab]", because the backslashes will be removed by lindex.
488 # Unfortunately, there appears to be no easy way to duplicate the splitting
489 # that expect will do from within TCL. And many places make use of the
490 # "\[0-9\]" construct, so we need to support that; and some places make use
491 # of the "[func]" construct, so we need to support that too. In order to
492 # get this right we have to substitute quoted list elements differently
493 # from braced list elements.
495 # We do this roughly the same way that Expect does it. We have to use two
496 # lists, because if we leave unquoted newlines in the argument to uplevel
497 # they'll be treated as command separators, and if we escape newlines
498 # we mangle newlines inside of command blocks. This assumes that the
499 # input doesn't contain a pattern which contains actual embedded newlines
502 regsub -all {\n} ${user_code} { } subst_code
503 set subst_code [uplevel list $subst_code]
505 set processed_code ""
507 set expecting_action 0
508 foreach item $user_code subst_item $subst_code {
509 if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } {
510 lappend processed_code $item
513 if {$item == "-indices" || $item == "-re" || $item == "-ex"} {
514 lappend processed_code $item
517 if { $expecting_action } {
518 lappend processed_code "uplevel [list $item]"
519 set expecting_action 0
520 # Cosmetic, no effect on the list.
521 append processed_code "\n"
524 set expecting_action 1
525 lappend processed_code $subst_item
526 if {$patterns != ""} {
529 append patterns "\"$subst_item\""
532 # Also purely cosmetic.
533 regsub -all {\r} $patterns {\\r} patterns
534 regsub -all {\n} $patterns {\\n} patterns
537 send_user "Sending \"$command\" to gdb\n"
538 send_user "Looking to match \"$patterns\"\n"
539 send_user "Message is \"$message\"\n"
543 set string "${command}\n";
544 if { $command != "" } {
545 while { "$string" != "" } {
546 set foo [string first "\n" "$string"];
547 set len [string length "$string"];
548 if { $foo < [expr $len - 1] } {
549 set str [string range "$string" 0 $foo];
550 if { [send_gdb "$str"] != "" } {
551 global suppress_flag;
553 if { ! $suppress_flag } {
554 perror "Couldn't send $command to GDB.";
559 # since we're checking if each line of the multi-line
560 # command are 'accepted' by GDB here,
561 # we need to set -notransfer expect option so that
562 # command output is not lost for pattern matching
565 -notransfer -re "\[\r\n\]" { verbose "partial: match" 3 }
566 timeout { verbose "partial: timeout" 3 }
568 set string [string range "$string" [expr $foo + 1] end];
573 if { "$string" != "" } {
574 if { [send_gdb "$string"] != "" } {
575 global suppress_flag;
577 if { ! $suppress_flag } {
578 perror "Couldn't send $command to GDB.";
586 if [target_info exists gdb,timeout] {
587 set tmt [target_info gdb,timeout];
589 if [info exists timeout] {
593 if [info exists timeout] {
602 -re ".*A problem internal to GDB has been detected" {
603 fail "$message (GDB internal error)"
604 gdb_internal_error_resync
606 -re "\\*\\*\\* DOSEXIT code.*" {
607 if { $message != "" } {
610 gdb_suppress_entire_file "GDB died";
613 -re "Ending remote debugging.*$gdb_prompt $" {
614 if ![isnative] then {
615 warning "Can`t communicate to remote target."
622 append code $processed_code
624 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
625 perror "Undefined command \"$command\"."
629 -re "Ambiguous command.*$gdb_prompt $" {
630 perror "\"$command\" is not a unique command name."
634 -re "Program exited with code \[0-9\]+.*$gdb_prompt $" {
635 if ![string match "" $message] then {
636 set errmsg "$message (the program exited)"
638 set errmsg "$command (the program exited)"
643 -re "EXIT code \[0-9\r\n\]+Program exited normally.*$gdb_prompt $" {
644 if ![string match "" $message] then {
645 set errmsg "$message (the program exited)"
647 set errmsg "$command (the program exited)"
652 -re "The program is not being run.*$gdb_prompt $" {
653 if ![string match "" $message] then {
654 set errmsg "$message (the program is no longer running)"
656 set errmsg "$command (the program is no longer running)"
661 -re "\r\n$gdb_prompt $" {
662 if ![string match "" $message] then {
669 perror "Window too small."
673 -re "\\(y or n\\) " {
675 perror "Got interactive prompt."
680 perror "Process no longer exists"
681 if { $message != "" } {
687 perror "internal buffer is full."
692 if ![string match "" $message] then {
693 fail "$message (timeout)"
700 set code [catch {gdb_expect $tmt $code} string]
702 global errorInfo errorCode;
703 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
704 } elseif {$code == 2} {
705 return -code return $string
706 } elseif {$code == 3} {
708 } elseif {$code > 4} {
709 return -code $code $string
714 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
715 # Send a command to gdb; test the result.
717 # COMMAND is the command to execute, send to GDB with send_gdb. If
718 # this is the null string no command is sent.
719 # PATTERN is the pattern to match for a PASS, and must NOT include
720 # the \r\n sequence immediately before the gdb prompt.
721 # MESSAGE is an optional message to be printed. If this is
722 # omitted, then the pass/fail messages use the command string as the
723 # message. (If this is the empty string, then sometimes we don't
724 # call pass or fail at all; I don't understand this at all.)
725 # QUESTION is a question GDB may ask in response to COMMAND, like
727 # RESPONSE is the response to send if QUESTION appears.
730 # 1 if the test failed,
731 # 0 if the test passes,
732 # -1 if there was an internal error.
734 proc gdb_test { args } {
738 upvar timeout timeout
740 if [llength $args]>2 then {
741 set message [lindex $args 2]
743 set message [lindex $args 0]
745 set command [lindex $args 0]
746 set pattern [lindex $args 1]
748 if [llength $args]==5 {
749 set question_string [lindex $args 3];
750 set response_string [lindex $args 4];
752 set question_string "^FOOBAR$"
755 return [gdb_test_multiple $command $message {
756 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
757 if ![string match "" $message] then {
761 -re "(${question_string})$" {
762 send_gdb "$response_string\n";
768 # Test that a command gives an error. For pass or fail, return
769 # a 1 to indicate that more tests can proceed. However a timeout
770 # is a serious error, generates a special fail message, and causes
771 # a 0 to be returned to indicate that more tests are likely to fail
774 proc test_print_reject { args } {
778 if [llength $args]==2 then {
779 set expectthis [lindex $args 1]
781 set expectthis "should never match this bogus string"
783 set sendthis [lindex $args 0]
785 send_user "Sending \"$sendthis\" to gdb\n"
786 send_user "Looking to match \"$expectthis\"\n"
788 send_gdb "$sendthis\n"
789 #FIXME: Should add timeout as parameter.
791 -re "A .* in expression.*\\.*$gdb_prompt $" {
792 pass "reject $sendthis"
795 -re "Invalid syntax in expression.*$gdb_prompt $" {
796 pass "reject $sendthis"
799 -re "Junk after end of expression.*$gdb_prompt $" {
800 pass "reject $sendthis"
803 -re "Invalid number.*$gdb_prompt $" {
804 pass "reject $sendthis"
807 -re "Invalid character constant.*$gdb_prompt $" {
808 pass "reject $sendthis"
811 -re "No symbol table is loaded.*$gdb_prompt $" {
812 pass "reject $sendthis"
815 -re "No symbol .* in current context.*$gdb_prompt $" {
816 pass "reject $sendthis"
819 -re "Unmatched single quote.*$gdb_prompt $" {
820 pass "reject $sendthis"
823 -re "A character constant must contain at least one character.*$gdb_prompt $" {
824 pass "reject $sendthis"
827 -re "$expectthis.*$gdb_prompt $" {
828 pass "reject $sendthis"
831 -re ".*$gdb_prompt $" {
832 fail "reject $sendthis"
836 fail "reject $sendthis (eof or timeout)"
842 # Given an input string, adds backslashes as needed to create a
843 # regexp that will match the string.
845 proc string_to_regexp {str} {
847 regsub -all {[]*+.|()^$\[]} $str {\\&} result
851 # Same as gdb_test, but the second parameter is not a regexp,
852 # but a string that must match exactly.
854 proc gdb_test_exact { args } {
855 upvar timeout timeout
857 set command [lindex $args 0]
859 # This applies a special meaning to a null string pattern. Without
860 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
861 # messages from commands that should have no output except a new
862 # prompt. With this, only results of a null string will match a null
865 set pattern [lindex $args 1]
866 if [string match $pattern ""] {
867 set pattern [string_to_regexp [lindex $args 0]]
869 set pattern [string_to_regexp [lindex $args 1]]
872 # It is most natural to write the pattern argument with only
873 # embedded \n's, especially if you are trying to avoid Tcl quoting
874 # problems. But gdb_expect really wants to see \r\n in patterns. So
875 # transform the pattern here. First transform \r\n back to \n, in
876 # case some users of gdb_test_exact already do the right thing.
877 regsub -all "\r\n" $pattern "\n" pattern
878 regsub -all "\n" $pattern "\r\n" pattern
879 if [llength $args]==3 then {
880 set message [lindex $args 2]
885 return [gdb_test $command $pattern $message]
888 proc gdb_reinitialize_dir { subdir } {
891 if [is_remote host] {
896 -re "Reinitialize source path to empty.*y or n. " {
899 -re "Source directories searched.*$gdb_prompt $" {
900 send_gdb "dir $subdir\n"
902 -re "Source directories searched.*$gdb_prompt $" {
903 verbose "Dir set to $subdir"
905 -re "$gdb_prompt $" {
906 perror "Dir \"$subdir\" failed."
910 -re "$gdb_prompt $" {
911 perror "Dir \"$subdir\" failed."
915 -re "$gdb_prompt $" {
916 perror "Dir \"$subdir\" failed."
922 # gdb_exit -- exit the GDB, killing the target program if necessary
924 proc default_gdb_exit {} {
930 gdb_stop_suppressing_tests;
932 if ![info exists gdb_spawn_id] {
936 verbose "Quitting $GDB $GDBFLAGS"
938 if { [is_remote host] && [board_info host exists fileid] } {
945 -re "DOSEXIT code" { }
950 if ![is_remote host] {
956 # Load a file into the debugger.
957 # The return value is 0 for success, -1 for failure.
959 # This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO
960 # to one of these values:
962 # debug file was loaded successfully and has debug information
963 # nodebug file was loaded successfully and has no debug information
964 # fail file was not loaded
966 # I tried returning this information as part of the return value,
967 # but ran into a mess because of the many re-implementations of
968 # gdb_load in config/*.exp.
970 # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use
971 # this if they can get more information set.
973 proc gdb_file_cmd { arg } {
978 # Set whether debug info was found.
980 global gdb_file_cmd_debug_info
981 set gdb_file_cmd_debug_info "fail"
983 if [is_remote host] {
984 set arg [remote_download host $arg]
986 perror "download failed"
991 send_gdb "file $arg\n"
993 -re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" {
994 verbose "\t\tLoaded $arg into the $GDB with no debugging symbols"
995 set gdb_file_cmd_debug_info "nodebug"
998 -re "Reading symbols from.*done.*$gdb_prompt $" {
999 verbose "\t\tLoaded $arg into the $GDB"
1000 set gdb_file_cmd_debug_info "debug"
1003 -re "A program is being debugged already.*Kill it.*y or n. $" {
1005 verbose "\t\tKilling previous program being debugged"
1008 -re "Load new symbol table from \".*\".*y or n. $" {
1011 -re "Reading symbols from.*done.*$gdb_prompt $" {
1012 verbose "\t\tLoaded $arg with new symbol table into $GDB"
1013 set gdb_file_cmd_debug_info "debug"
1017 perror "(timeout) Couldn't load $arg, other program already loaded."
1022 -re "No such file or directory.*$gdb_prompt $" {
1023 perror "($arg) No such file or directory"
1026 -re "$gdb_prompt $" {
1027 perror "couldn't load $arg into $GDB."
1031 perror "couldn't load $arg into $GDB (timed out)."
1035 # This is an attempt to detect a core dump, but seems not to
1036 # work. Perhaps we need to match .* followed by eof, in which
1037 # gdb_expect does not seem to have a way to do that.
1038 perror "couldn't load $arg into $GDB (end of file)."
1045 # start gdb -- start gdb running, default procedure
1047 # When running over NFS, particularly if running many simultaneous
1048 # tests on different hosts all using the same server, things can
1049 # get really slow. Give gdb at least 3 minutes to start up.
1051 proc default_gdb_start { } {
1057 global gdb_spawn_id;
1059 gdb_stop_suppressing_tests;
1061 verbose "Spawning $GDB -nw $GDBFLAGS"
1063 if [info exists gdb_spawn_id] {
1067 if ![is_remote host] {
1068 if { [which $GDB] == 0 } then {
1069 perror "$GDB does not exist."
1073 set res [remote_spawn host "$GDB -nw $GDBFLAGS [host_info gdb_opts]"];
1074 if { $res < 0 || $res == "" } {
1075 perror "Spawning $GDB failed."
1079 -re "\[\r\n\]$gdb_prompt $" {
1080 verbose "GDB initialized."
1082 -re "$gdb_prompt $" {
1083 perror "GDB never initialized."
1087 perror "(timeout) GDB never initialized after 10 seconds."
1092 set gdb_spawn_id -1;
1093 # force the height to "unlimited", so no pagers get used
1095 send_gdb "set height 0\n"
1097 -re "$gdb_prompt $" {
1098 verbose "Setting height to 0." 2
1101 warning "Couldn't set the height to 0"
1104 # force the width to "unlimited", so no wraparound occurs
1105 send_gdb "set width 0\n"
1107 -re "$gdb_prompt $" {
1108 verbose "Setting width to 0." 2
1111 warning "Couldn't set the width to 0."
1117 # Return a 1 for configurations for which we don't even want to try to
1120 proc skip_cplus_tests {} {
1121 if { [istarget "d10v-*-*"] } {
1124 if { [istarget "h8300-*-*"] } {
1128 # The C++ IO streams are too large for HC11/HC12 and are thus not
1129 # available. The gdb C++ tests use them and don't compile.
1130 if { [istarget "m6811-*-*"] } {
1133 if { [istarget "m6812-*-*"] } {
1139 # Return a 1 if I don't even want to try to test FORTRAN.
1141 proc skip_fortran_tests {} {
1145 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
1146 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
1148 proc skip_altivec_tests {} {
1149 global skip_vmx_tests_saved
1150 global srcdir subdir gdb_prompt
1152 # Use the cached value, if it exists.
1153 set me "skip_altivec_tests"
1154 if [info exists skip_vmx_tests_saved] {
1155 verbose "$me: returning saved $skip_vmx_tests_saved" 2
1156 return $skip_vmx_tests_saved
1159 # Some simulators are known to not support VMX instructions.
1160 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1161 verbose "$me: target known to not support VMX, returning 1" 2
1162 return [set $skip_vmx_tests_saved 1]
1165 # Make sure we have a compiler that understands altivec.
1166 set compile_flags {debug additional_flags=-w}
1167 if [get_compiler_info not-used] {
1168 warning "Could not get compiler info"
1171 if [test_compiler_info gcc*] {
1172 set compile_flags "$compile_flags additional_flags=-maltivec"
1173 } elseif [test_compiler_info xlc*] {
1174 set compile_flags "$compile_flags additional_flags=-qaltivec"
1176 verbose "Could not compile with altivec support, returning 1" 2
1180 # Set up, compile, and execute a test program containing VMX instructions.
1181 # Include the current process ID in the file names to prevent conflicts
1182 # with invocations for multiple testsuites.
1186 set f [open $src "w"]
1187 puts $f "int main() {"
1188 puts $f "#ifdef __MACH__"
1189 puts $f " asm volatile (\"vor v0,v0,v0\");"
1191 puts $f " asm volatile (\"vor 0,0,0\");"
1193 puts $f " return 0; }"
1196 verbose "$me: compiling testfile $src" 2
1197 set lines [gdb_compile $src $exe executable $compile_flags]
1200 if ![string match "" $lines] then {
1201 verbose "$me: testfile compilation failed, returning 1" 2
1202 return [set skip_vmx_tests_saved 1]
1205 # No error message, compilation succeeded so now run it via gdb.
1209 gdb_reinitialize_dir $srcdir/$subdir
1213 -re ".*Illegal instruction.*${gdb_prompt} $" {
1214 verbose -log "\n$me altivec hardware not detected"
1215 set skip_vmx_tests_saved 1
1217 -re ".*Program exited normally.*${gdb_prompt} $" {
1218 verbose -log "\n$me: altivec hardware detected"
1219 set skip_vmx_tests_saved 0
1222 warning "\n$me: default case taken"
1223 set skip_vmx_tests_saved 1
1227 remote_file build delete $exe
1229 verbose "$me: returning $skip_vmx_tests_saved" 2
1230 return $skip_vmx_tests_saved
1233 # Skip all the tests in the file if you are not on an hppa running
1236 proc skip_hp_tests {} {
1237 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
1238 verbose "Skip hp tests is $skip_hp"
1242 set compiler_info "unknown"
1244 set hp_cc_compiler 0
1245 set hp_aCC_compiler 0
1247 # Figure out what compiler I am using.
1249 # BINFILE is a "compiler information" output file. This implementation
1250 # does not use BINFILE.
1252 # ARGS can be empty or "C++". If empty, "C" is assumed.
1254 # There are several ways to do this, with various problems.
1256 # [ gdb_compile -E $ifile -o $binfile.ci ]
1257 # source $binfile.ci
1259 # Single Unix Spec v3 says that "-E -o ..." together are not
1260 # specified. And in fact, the native compiler on hp-ux 11 (among
1261 # others) does not work with "-E -o ...". Most targets used to do
1262 # this, and it mostly worked, because it works with gcc.
1264 # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ]
1265 # source $binfile.ci
1267 # This avoids the problem with -E and -o together. This almost works
1268 # if the build machine is the same as the host machine, which is
1269 # usually true of the targets which are not gcc. But this code does
1270 # not figure which compiler to call, and it always ends up using the C
1271 # compiler. Not good for setting hp_aCC_compiler. Targets
1272 # hppa*-*-hpux* and mips*-*-irix* used to do this.
1274 # [ gdb_compile -E $ifile > $binfile.ci ]
1275 # source $binfile.ci
1277 # dejagnu target_compile says that it supports output redirection,
1278 # but the code is completely different from the normal path and I
1279 # don't want to sweep the mines from that path. So I didn't even try
1282 # set cppout [ gdb_compile $ifile "" preprocess $args quiet ]
1285 # I actually do this for all targets now. gdb_compile runs the right
1286 # compiler, and TCL captures the output, and I eval the output.
1288 # Unfortunately, expect logs the output of the command as it goes by,
1289 # and dejagnu helpfully prints a second copy of it right afterwards.
1290 # So I turn off expect logging for a moment.
1292 # [ gdb_compile $ifile $ciexe_file executable $args ]
1293 # [ remote_exec $ciexe_file ]
1294 # [ source $ci_file.out ]
1296 # I could give up on -E and just do this.
1297 # I didn't get desperate enough to try this.
1299 # -- chastain 2004-01-06
1301 proc get_compiler_info {binfile args} {
1302 # For compiler.c and compiler.cc
1305 # I am going to play with the log to keep noise out.
1309 # These come from compiler.c or compiler.cc
1310 global compiler_info
1312 # Legacy global data symbols.
1314 global hp_cc_compiler
1315 global hp_aCC_compiler
1317 # Choose which file to preprocess.
1318 set ifile "${srcdir}/lib/compiler.c"
1319 if { [llength $args] > 0 && [lindex $args 0] == "c++" } {
1320 set ifile "${srcdir}/lib/compiler.cc"
1323 # Run $ifile through the right preprocessor.
1324 # Toggle gdb.log to keep the compiler output out of the log.
1326 set cppout [ gdb_compile "${ifile}" "" preprocess [list "$args" quiet] ]
1327 log_file -a "$outdir/$tool.log"
1331 foreach cppline [ split "$cppout" "\n" ] {
1332 if { [ regexp "^#" "$cppline" ] } {
1334 } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } {
1336 } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } {
1338 verbose "get_compiler_info: $cppline" 2
1342 verbose -log "get_compiler_info: $cppline"
1347 # Reset to unknown compiler if any diagnostics happened.
1349 set compiler_info "unknown"
1352 # Set the legacy symbols.
1354 set hp_cc_compiler 0
1355 set hp_aCC_compiler 0
1356 if { [regexp "^gcc-1-" "$compiler_info" ] } { set gcc_compiled 1 }
1357 if { [regexp "^gcc-2-" "$compiler_info" ] } { set gcc_compiled 2 }
1358 if { [regexp "^gcc-3-" "$compiler_info" ] } { set gcc_compiled 3 }
1359 if { [regexp "^gcc-4-" "$compiler_info" ] } { set gcc_compiled 4 }
1360 if { [regexp "^gcc-5-" "$compiler_info" ] } { set gcc_compiled 5 }
1361 if { [regexp "^hpcc-" "$compiler_info" ] } { set hp_cc_compiler 1 }
1362 if { [regexp "^hpacc-" "$compiler_info" ] } { set hp_aCC_compiler 1 }
1364 # Log what happened.
1365 verbose -log "get_compiler_info: $compiler_info"
1367 # Most compilers will evaluate comparisons and other boolean
1368 # operations to 0 or 1.
1369 uplevel \#0 { set true 1 }
1370 uplevel \#0 { set false 0 }
1372 # Use of aCC results in boolean results being displayed as
1374 if { $hp_aCC_compiler } {
1375 uplevel \#0 { set true true }
1376 uplevel \#0 { set false false }
1382 proc test_compiler_info { {compiler ""} } {
1383 global compiler_info
1385 # if no arg, return the compiler_info string
1387 if [string match "" $compiler] {
1388 if [info exists compiler_info] {
1389 return $compiler_info
1391 perror "No compiler info found."
1395 return [string match $compiler $compiler_info]
1398 set gdb_wrapper_initialized 0
1400 proc gdb_wrapper_init { args } {
1401 global gdb_wrapper_initialized;
1402 global gdb_wrapper_file;
1403 global gdb_wrapper_flags;
1405 if { $gdb_wrapper_initialized == 1 } { return; }
1407 if {[target_info exists needs_status_wrapper] && \
1408 [target_info needs_status_wrapper] != "0"} {
1409 set result [build_wrapper "testglue.o"];
1410 if { $result != "" } {
1411 set gdb_wrapper_file [lindex $result 0];
1412 set gdb_wrapper_flags [lindex $result 1];
1414 warning "Status wrapper failed to build."
1417 set gdb_wrapper_initialized 1
1420 proc gdb_compile {source dest type options} {
1421 global GDB_TESTCASE_OPTIONS;
1422 global gdb_wrapper_file;
1423 global gdb_wrapper_flags;
1424 global gdb_wrapper_initialized;
1426 # Add platform-specific options if a shared library was specified using
1427 # "shlib=librarypath" in OPTIONS.
1430 foreach opt $options {
1431 if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] {
1432 if [test_compiler_info "xlc-*"] {
1433 # IBM xlc compiler doesn't accept shared library named other
1434 # than .so: use "-Wl," to bypass this
1435 lappend source "-Wl,$shlib_name"
1437 lappend source $shlib_name
1439 if {$shlib_found == 0} {
1441 if { ([test_compiler_info "gcc-*"]
1442 && ([istarget "powerpc*-*-aix*"]
1443 || [istarget "rs6000*-*-aix*"] )) } {
1444 lappend options "additional_flags=-L${objdir}/${subdir}"
1445 } elseif { [istarget "mips-sgi-irix*"] } {
1446 lappend options "additional_flags=-rpath ${objdir}/${subdir}"
1450 lappend new_options $opt
1453 set options $new_options
1455 if [target_info exists gdb_stub] {
1456 set options2 { "additional_flags=-Dusestubs" }
1457 lappend options "libs=[target_info gdb_stub]";
1458 set options [concat $options2 $options]
1460 if [target_info exists is_vxworks] {
1461 set options2 { "additional_flags=-Dvxworks" }
1462 lappend options "libs=[target_info gdb_stub]";
1463 set options [concat $options2 $options]
1465 if [info exists GDB_TESTCASE_OPTIONS] {
1466 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
1468 verbose "options are $options"
1469 verbose "source is $source $dest $type $options"
1471 if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init }
1473 if {[target_info exists needs_status_wrapper] && \
1474 [target_info needs_status_wrapper] != "0" && \
1475 [info exists gdb_wrapper_file]} {
1476 lappend options "libs=${gdb_wrapper_file}"
1477 lappend options "ldflags=${gdb_wrapper_flags}"
1480 set result [target_compile $source $dest $type $options];
1481 regsub "\[\r\n\]*$" "$result" "" result;
1482 regsub "^\[\r\n\]*" "$result" "" result;
1483 if { $result != "" && [lsearch $options quiet] == -1} {
1484 clone_output "gdb compile failed, $result"
1490 # This is just like gdb_compile, above, except that it tries compiling
1491 # against several different thread libraries, to see which one this
1493 proc gdb_compile_pthreads {source dest type options} {
1495 set why_msg "unrecognized error"
1496 foreach lib {-lpthreads -lpthread -lthread} {
1497 # This kind of wipes out whatever libs the caller may have
1498 # set. Or maybe theirs will override ours. How infelicitous.
1499 set options_with_lib [concat $options [list libs=$lib quiet]]
1500 set ccout [gdb_compile $source $dest $type $options_with_lib]
1501 switch -regexp -- $ccout {
1502 ".*no posix threads support.*" {
1503 set why_msg "missing threads include file"
1506 ".*cannot open -lpthread.*" {
1507 set why_msg "missing runtime threads library"
1509 ".*Can't find library for -lpthread.*" {
1510 set why_msg "missing runtime threads library"
1513 pass "successfully compiled posix threads test case"
1519 if {!$built_binfile} {
1520 unsupported "Couldn't compile $source: ${why_msg}"
1525 # Build a shared library from SOURCES. You must use get_compiler_info
1528 proc gdb_compile_shlib {sources dest options} {
1529 set obj_options $options
1531 switch -glob [test_compiler_info] {
1533 lappend obj_options "additional_flags=-qpic"
1536 if { !([istarget "powerpc*-*-aix*"]
1537 || [istarget "rs6000*-*-aix*"]) } {
1538 lappend obj_options "additional_flags=-fpic"
1542 switch -glob [istarget] {
1544 lappend obj_options "additional_flags=+z"
1547 # Disable SGI compiler's implicit -Dsgi
1548 lappend obj_options "additional_flags=-Usgi"
1551 # don't know what the compiler is...
1557 set outdir [file dirname $dest]
1559 foreach source $sources {
1560 set sourcebase [file tail $source]
1561 if {[gdb_compile $source "${outdir}/${sourcebase}.o" object $obj_options] != ""} {
1564 lappend objects ${outdir}/${sourcebase}.o
1567 if [istarget "hppa*-*-hpux*"] {
1568 remote_exec build "ld -b ${objects} -o ${dest}"
1570 set link_options $options
1571 if [test_compiler_info "xlc-*"] {
1572 lappend link_options "additional_flags=-qmkshrobj"
1574 lappend link_options "additional_flags=-shared"
1576 if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
1582 # This is just like gdb_compile_pthreads, above, except that we always add the
1583 # objc library for compiling Objective-C programs
1584 proc gdb_compile_objc {source dest type options} {
1586 set why_msg "unrecognized error"
1587 foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} {
1588 # This kind of wipes out whatever libs the caller may have
1589 # set. Or maybe theirs will override ours. How infelicitous.
1590 if { $lib == "solaris" } {
1591 set lib "-lpthread -lposix4"
1593 if { $lib != "-lobjc" } {
1594 set lib "-lobjc $lib"
1596 set options_with_lib [concat $options [list libs=$lib quiet]]
1597 set ccout [gdb_compile $source $dest $type $options_with_lib]
1598 switch -regexp -- $ccout {
1599 ".*no posix threads support.*" {
1600 set why_msg "missing threads include file"
1603 ".*cannot open -lpthread.*" {
1604 set why_msg "missing runtime threads library"
1606 ".*Can't find library for -lpthread.*" {
1607 set why_msg "missing runtime threads library"
1610 pass "successfully compiled objc with posix threads test case"
1616 if {!$built_binfile} {
1617 unsupported "Couldn't compile $source: ${why_msg}"
1622 proc send_gdb { string } {
1623 global suppress_flag;
1624 if { $suppress_flag } {
1625 return "suppressed";
1627 return [remote_send host "$string"];
1633 proc gdb_expect { args } {
1634 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
1635 set gtimeout [lindex $args 0];
1636 set expcode [list [lindex $args 1]];
1638 upvar timeout timeout;
1641 if [target_info exists gdb,timeout] {
1642 if [info exists timeout] {
1643 if { $timeout < [target_info gdb,timeout] } {
1644 set gtimeout [target_info gdb,timeout];
1646 set gtimeout $timeout;
1649 set gtimeout [target_info gdb,timeout];
1653 if ![info exists gtimeout] {
1655 if [info exists timeout] {
1656 set gtimeout $timeout;
1663 global suppress_flag;
1664 global remote_suppress_flag;
1665 if [info exists remote_suppress_flag] {
1666 set old_val $remote_suppress_flag;
1668 if [info exists suppress_flag] {
1669 if { $suppress_flag } {
1670 set remote_suppress_flag 1;
1674 {uplevel remote_expect host $gtimeout $expcode} string];
1675 if [info exists old_val] {
1676 set remote_suppress_flag $old_val;
1678 if [info exists remote_suppress_flag] {
1679 unset remote_suppress_flag;
1684 global errorInfo errorCode;
1686 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
1687 } elseif {$code == 2} {
1688 return -code return $string
1689 } elseif {$code == 3} {
1691 } elseif {$code > 4} {
1692 return -code $code $string
1696 # gdb_expect_list MESSAGE SENTINEL LIST -- expect a sequence of outputs
1698 # Check for long sequence of output by parts.
1699 # MESSAGE: is the test message to be printed with the test success/fail.
1700 # SENTINEL: Is the terminal pattern indicating that output has finished.
1701 # LIST: is the sequence of outputs to match.
1702 # If the sentinel is recognized early, it is considered an error.
1705 # 1 if the test failed,
1706 # 0 if the test passes,
1707 # -1 if there was an internal error.
1709 proc gdb_expect_list {test sentinel list} {
1711 global suppress_flag
1714 if { $suppress_flag } {
1716 unresolved "${test}"
1718 while { ${index} < [llength ${list}] } {
1719 set pattern [lindex ${list} ${index}]
1720 set index [expr ${index} + 1]
1721 if { ${index} == [llength ${list}] } {
1724 -re "${pattern}${sentinel}" {
1725 # pass "${test}, pattern ${index} + sentinel"
1728 fail "${test} (pattern ${index} + sentinel)"
1731 -re ".*A problem internal to GDB has been detected" {
1732 fail "${test} (GDB internal error)"
1734 gdb_internal_error_resync
1737 fail "${test} (pattern ${index} + sentinel) (timeout)"
1742 # unresolved "${test}, pattern ${index} + sentinel"
1748 # pass "${test}, pattern ${index}"
1751 fail "${test} (pattern ${index})"
1754 -re ".*A problem internal to GDB has been detected" {
1755 fail "${test} (GDB internal error)"
1757 gdb_internal_error_resync
1760 fail "${test} (pattern ${index}) (timeout)"
1765 # unresolved "${test}, pattern ${index}"
1779 proc gdb_suppress_entire_file { reason } {
1780 global suppress_flag;
1782 warning "$reason\n";
1783 set suppress_flag -1;
1787 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
1788 # gdb_expect to fail immediately (until the next call to
1789 # gdb_stop_suppressing_tests).
1791 proc gdb_suppress_tests { args } {
1792 global suppress_flag;
1794 return; # fnf - disable pending review of results where
1795 # testsuite ran better without this
1798 if { $suppress_flag == 1 } {
1799 if { [llength $args] > 0 } {
1800 warning "[lindex $args 0]\n";
1802 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
1808 # Clear suppress_flag.
1810 proc gdb_stop_suppressing_tests { } {
1811 global suppress_flag;
1813 if [info exists suppress_flag] {
1814 if { $suppress_flag > 0 } {
1815 set suppress_flag 0;
1816 clone_output "Tests restarted.\n";
1819 set suppress_flag 0;
1823 proc gdb_clear_suppressed { } {
1824 global suppress_flag;
1826 set suppress_flag 0;
1829 proc gdb_start { } {
1834 catch default_gdb_exit
1838 # gdb_load -- load a file into the debugger.
1839 # Many files in config/*.exp override this procedure.
1841 proc gdb_load { arg } {
1842 return [gdb_file_cmd $arg]
1845 proc gdb_continue { function } {
1848 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
1851 proc default_gdb_init { args } {
1852 global gdb_wrapper_initialized
1854 gdb_clear_suppressed;
1856 # Make sure that the wrapper is rebuilt
1857 # with the appropriate multilib option.
1858 set gdb_wrapper_initialized 0
1860 # Uh, this is lame. Really, really, really lame. But there's this *one*
1861 # testcase that will fail in random places if we don't increase this.
1864 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
1865 if { [llength $args] > 0 } {
1868 set file [lindex $args 0];
1870 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
1873 if [target_info exists gdb_prompt] {
1874 set gdb_prompt [target_info gdb_prompt];
1876 set gdb_prompt "\\(gdb\\)"
1880 proc gdb_init { args } {
1881 return [eval default_gdb_init $args];
1884 proc gdb_finish { } {
1889 set debug_format "unknown"
1891 # Run the gdb command "info source" and extract the debugging format
1892 # information from the output and save it in debug_format.
1894 proc get_debug_format { } {
1900 set debug_format "unknown"
1901 send_gdb "info source\n"
1903 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
1904 set debug_format $expect_out(1,string)
1905 verbose "debug format is $debug_format"
1908 -re "No current source file.\r\n$gdb_prompt $" {
1909 perror "get_debug_format used when no current source file"
1912 -re "$gdb_prompt $" {
1913 warning "couldn't check debug format (no valid response)."
1917 warning "couldn't check debug format (timed out)."
1923 # Return true if FORMAT matches the debug format the current test was
1924 # compiled with. FORMAT is a shell-style globbing pattern; it can use
1925 # `*', `[...]', and so on.
1927 # This function depends on variables set by `get_debug_format', above.
1929 proc test_debug_format {format} {
1932 return [expr [string match $format $debug_format] != 0]
1935 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
1936 # COFF, stabs, etc). If that format matches the format that the
1937 # current test was compiled with, then the next test is expected to
1938 # fail for any target. Returns 1 if the next test or set of tests is
1939 # expected to fail, 0 otherwise (or if it is unknown). Must have
1940 # previously called get_debug_format.
1941 proc setup_xfail_format { format } {
1942 set ret [test_debug_format $format];
1950 proc gdb_step_for_stub { } {
1953 if ![target_info exists gdb,use_breakpoint_for_stub] {
1954 if [target_info exists gdb_stub_step_command] {
1955 set command [target_info gdb_stub_step_command];
1959 send_gdb "${command}\n";
1962 -re "(main.* at |.*in .*start).*$gdb_prompt" {
1965 -re ".*$gdb_prompt" {
1967 if { $tries == 5 } {
1968 fail "stepping out of breakpoint function";
1971 send_gdb "${command}\n";
1975 fail "stepping out of breakpoint function";
1982 -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" {
1983 set file $expect_out(1,string);
1984 set linenum [expr $expect_out(2,string) + 1];
1985 set breakplace "${file}:${linenum}";
1989 send_gdb "break ${breakplace}\n";
1991 -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" {
1992 set breakpoint $expect_out(1,string);
1994 -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" {
1995 set breakpoint $expect_out(1,string);
1999 send_gdb "continue\n";
2001 -re "Breakpoint ${breakpoint},.*$gdb_prompt" {
2002 gdb_test "delete $breakpoint" ".*" "";
2009 # gdb_get_line_number TEXT [FILE]
2011 # Search the source file FILE, and return the line number of the
2012 # first line containing TEXT. If no match is found, return -1.
2014 # TEXT is a string literal, not a regular expression.
2016 # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is
2017 # specified, and does not start with "/", then it is assumed to be in
2018 # "$srcdir/$subdir". This is awkward, and can be fixed in the future,
2019 # by changing the callers and the interface at the same time.
2020 # In particular: gdb.base/break.exp, gdb.base/condbreak.exp,
2021 # gdb.base/ena-dis-br.exp.
2023 # Use this function to keep your test scripts independent of the
2024 # exact line numbering of the source file. Don't write:
2026 # send_gdb "break 20"
2028 # This means that if anyone ever edits your test's source file,
2029 # your test could break. Instead, put a comment like this on the
2030 # source file line you want to break at:
2032 # /* breakpoint spot: frotz.exp: test name */
2034 # and then write, in your test script (which we assume is named
2037 # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
2039 # (Yes, Tcl knows how to handle the nested quotes and brackets.
2042 # % puts "foo [lindex "bar baz" 1]"
2045 # Tcl is quite clever, for a little stringy language.)
2049 # The previous implementation of this procedure used the gdb search command.
2050 # This version is different:
2052 # . It works with MI, and it also works when gdb is not running.
2054 # . It operates on the build machine, not the host machine.
2056 # . For now, this implementation fakes a current directory of
2057 # $srcdir/$subdir to be compatible with the old implementation.
2058 # This will go away eventually and some callers will need to
2061 # . The TEXT argument is literal text and matches literally,
2062 # not a regular expression as it was before.
2064 # . State changes in gdb, such as changing the current file
2065 # and setting $_, no longer happen.
2067 # After a bit of time we can forget about the differences from the
2068 # old implementation.
2070 # --chastain 2004-08-05
2072 proc gdb_get_line_number { text { file "" } } {
2077 if { "$file" == "" } then {
2080 if { ! [regexp "^/" "$file"] } then {
2081 set file "$srcdir/$subdir/$file"
2084 if { [ catch { set fd [open "$file"] } message ] } then {
2090 for { set line 1 } { 1 } { incr line } {
2091 if { [ catch { set nchar [gets "$fd" body] } message ] } then {
2095 if { $nchar < 0 } then {
2098 if { [string first "$text" "$body"] >= 0 } then {
2104 if { [ catch { close "$fd" } message ] } then {
2112 # gdb_continue_to_end:
2113 # The case where the target uses stubs has to be handled specially. If a
2114 # stub is used, we set a breakpoint at exit because we cannot rely on
2115 # exit() behavior of a remote target.
2117 # mssg is the error message that gets printed.
2119 proc gdb_continue_to_end {mssg} {
2120 if [target_info exists use_gdb_stub] {
2121 if {![gdb_breakpoint "exit"]} {
2124 gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \
2125 "continue until exit at $mssg"
2127 # Continue until we exit. Should not stop again.
2128 # Don't bother to check the output of the program, that may be
2129 # extremely tough for some remote systems.
2130 gdb_test "continue"\
2131 "Continuing.\[\r\n0-9\]+(... EXIT code 0\[\r\n\]+|Program exited normally\\.).*"\
2132 "continue until exit at $mssg"
2136 proc rerun_to_main {} {
2139 if [target_info exists use_gdb_stub] {
2142 -re ".*Breakpoint .*main .*$gdb_prompt $"\
2143 {pass "rerun to main" ; return 0}
2144 -re "$gdb_prompt $"\
2145 {fail "rerun to main" ; return 0}
2146 timeout {fail "(timeout) rerun to main" ; return 0}
2151 -re "The program .* has been started already.*y or n. $" {
2155 -re "Starting program.*$gdb_prompt $"\
2156 {pass "rerun to main" ; return 0}
2157 -re "$gdb_prompt $"\
2158 {fail "rerun to main" ; return 0}
2159 timeout {fail "(timeout) rerun to main" ; return 0}
2164 # Print a message and return true if a test should be skipped
2165 # due to lack of floating point suport.
2167 proc gdb_skip_float_test { msg } {
2168 if [target_info exists gdb,skip_float_tests] {
2169 verbose "Skipping test '$msg': no float tests.";
2175 # Print a message and return true if a test should be skipped
2176 # due to lack of stdio support.
2178 proc gdb_skip_stdio_test { msg } {
2179 if [target_info exists gdb,noinferiorio] {
2180 verbose "Skipping test '$msg': no inferior i/o.";
2186 proc gdb_skip_bogus_test { msg } {
2191 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
2192 # ${binfile}.dbglnk, which is just like the executable ($binfile) but without
2193 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
2194 # the name of a idebuginfo only file. This file will be stored in the
2195 # gdb.base/.debug subdirectory.
2197 # Functions for separate debug info testing
2199 # starting with an executable:
2200 # foo --> original executable
2202 # at the end of the process we have:
2203 # foo.stripped --> foo w/o debug info
2204 # .debug/foo.debug --> foo's debug info
2205 # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug.
2207 # Return the name of the file in which we should stor EXEC's separated
2208 # debug info. EXEC contains the full path.
2209 proc separate_debug_filename { exec } {
2211 # In a .debug subdirectory off the same directory where the testcase
2212 # executable is going to be. Something like:
2213 # <your-path>/gdb/testsuite/gdb.base/.debug/blah.debug.
2214 # This is the default location where gdb expects to findi
2215 # the debug info file.
2217 set exec_dir [file dirname $exec]
2218 set exec_file [file tail $exec]
2219 set debug_dir [file join $exec_dir ".debug"]
2220 set debug_file [file join $debug_dir "${exec_file}.debug"]
2226 proc gdb_gnu_strip_debug { dest } {
2228 set debug_file [separate_debug_filename $dest]
2229 set strip_to_file_program strip
2230 set objcopy_program objcopy
2232 # Make sure the directory that will hold the separated debug
2233 # info actually exists.
2234 set debug_dir [file dirname $debug_file]
2235 if {! [file isdirectory $debug_dir]} {
2236 file mkdir $debug_dir
2239 set debug_link [file tail $debug_file]
2240 set stripped_file "${dest}.stripped"
2242 # Get rid of the debug info, and store result in stripped_file
2243 # something like gdb/testsuite/gdb.base/blah.stripped.
2244 set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
2245 verbose "result is $result"
2246 verbose "output is $output"
2251 # Get rid of everything but the debug info, and store result in debug_file
2252 # This will be in the .debug subdirectory, see above.
2253 set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
2254 verbose "result is $result"
2255 verbose "output is $output"
2260 # Link the two previous output files together, adding the .gnu_debuglink
2261 # section to the stripped_file, containing a pointer to the debug_file,
2262 # save the new file in dest.
2263 # This will be the regular executable filename, in the usual location.
2264 set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
2265 verbose "result is $result"
2266 verbose "output is $output"