1 # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
2 # 2003, 2004, 2005, 2007, 2008, 2009 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 3 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, see <http://www.gnu.org/licenses/>.
17 # This file was written by Fred Fish. (fnf@cygnus.com)
19 # Generic gdb subroutines that should work for any target. If these
20 # need to be modified for any target, it can be done with a variable
21 # or by passing arguments.
24 # Tests would fail, logs on get_compiler_info() would be missing.
25 send_error "`site.exp' not found, run `make site.exp'!\n"
33 if [info exists TOOL_EXECUTABLE] {
34 set GDB $TOOL_EXECUTABLE;
36 if ![info exists GDB] {
37 if ![is_remote host] {
38 set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]]
40 set GDB [transform gdb];
43 verbose "using GDB = $GDB" 2
45 # GDBFLAGS is available for the user to set on the command line.
46 # E.g. make check RUNTESTFLAGS=GDBFLAGS=mumble
47 # Testcases may use it to add additional flags, but they must:
48 # - append new flags, not overwrite
49 # - restore the original value when done
51 if ![info exists GDBFLAGS] {
54 verbose "using GDBFLAGS = $GDBFLAGS" 2
56 # INTERNAL_GDBFLAGS contains flags that the testsuite requires.
57 set INTERNAL_GDBFLAGS "-nw -nx"
59 # The variable gdb_prompt is a regexp which matches the gdb prompt.
60 # Set it if it is not already set.
62 if ![info exists gdb_prompt] then {
63 set gdb_prompt "\[(\]gdb\[)\]"
66 # The variable fullname_syntax_POSIX is a regexp which matches a POSIX
67 # absolute path ie. /foo/
68 set fullname_syntax_POSIX {/[^\n]*/}
69 # The variable fullname_syntax_UNC is a regexp which matches a Windows
70 # UNC path ie. \\D\foo\
71 set fullname_syntax_UNC {\\\\[^\\]+\\[^\n]+\\}
72 # The variable fullname_syntax_DOS_CASE is a regexp which matches a
73 # particular DOS case that GDB most likely will output
74 # ie. \foo\, but don't match \\.*\
75 set fullname_syntax_DOS_CASE {\\[^\\][^\n]*\\}
76 # The variable fullname_syntax_DOS is a regexp which matches a DOS path
77 # ie. a:\foo\ && a:foo\
78 set fullname_syntax_DOS {[a-zA-Z]:[^\n]*\\}
79 # The variable fullname_syntax is a regexp which matches what GDB considers
80 # an absolute path. It is currently debatable if the Windows style paths
81 # d:foo and \abc should be considered valid as an absolute path.
82 # Also, the purpse of this regexp is not to recognize a well formed
83 # absolute path, but to say with certainty that a path is absolute.
84 set fullname_syntax "($fullname_syntax_POSIX|$fullname_syntax_UNC|$fullname_syntax_DOS_CASE|$fullname_syntax_DOS)"
86 # Needed for some tests under Cygwin.
90 if ![info exists env(EXEEXT)] {
93 set EXEEXT $env(EXEEXT)
98 ### Only procedures should come after this point.
101 # gdb_version -- extract and print the version number of GDB
103 proc default_gdb_version {} {
105 global INTERNAL_GDBFLAGS GDBFLAGS
107 set output [remote_exec host "$GDB $INTERNAL_GDBFLAGS --version"]
108 set tmp [lindex $output 1];
110 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
111 if ![is_remote host] {
112 clone_output "[which $GDB] version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
114 clone_output "$GDB on remote host version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
118 proc gdb_version { } {
119 return [default_gdb_version];
123 # gdb_unload -- unload a file if one is loaded
132 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
133 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
134 -re "A program is being debugged already..*Kill it.*y or n. $"\
136 verbose "\t\tKilling previous program being debugged"
139 -re "Discard symbol table from .*y or n.*$" {
143 -re "$gdb_prompt $" {}
145 perror "couldn't unload file in $GDB (timed out)."
151 # Many of the tests depend on setting breakpoints at various places and
152 # running until that breakpoint is reached. At times, we want to start
153 # with a clean-slate with respect to breakpoints, so this utility proc
154 # lets us do this without duplicating this code everywhere.
157 proc delete_breakpoints {} {
160 # we need a larger timeout value here or this thing just confuses
161 # itself. May need a better implementation if possible. - guo
163 send_gdb "delete breakpoints\n"
165 -re "Delete all breakpoints.*y or n.*$" {
169 -re "$gdb_prompt $" { # This happens if there were no breakpoints
171 timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
173 send_gdb "info breakpoints\n"
175 -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
176 -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
177 -re "Delete all breakpoints.*or n.*$" {
181 timeout { perror "info breakpoints (timeout)" ; return }
187 # Generic run command.
189 # The second pattern below matches up to the first newline *only*.
190 # Using ``.*$'' could swallow up output that we attempt to match
193 proc gdb_run_cmd {args} {
196 if [target_info exists gdb_init_command] {
197 send_gdb "[target_info gdb_init_command]\n";
199 -re "$gdb_prompt $" { }
201 perror "gdb_init_command for target failed";
207 if [target_info exists use_gdb_stub] {
208 if [target_info exists gdb,do_reload_on_run] {
209 if { [gdb_reload] != 0 } {
212 send_gdb "continue\n";
214 -re "Continu\[^\r\n\]*\[\r\n\]" {}
220 if [target_info exists gdb,start_symbol] {
221 set start [target_info gdb,start_symbol];
225 send_gdb "jump *$start\n"
227 while { $start_attempt } {
228 # Cap (re)start attempts at three to ensure that this loop
229 # always eventually fails. Don't worry about trying to be
230 # clever and not send a command when it has failed.
231 if [expr $start_attempt > 3] {
232 perror "Jump to start() failed (retry count exceeded)";
235 set start_attempt [expr $start_attempt + 1];
237 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
240 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
241 perror "Can't find start symbol to run in gdb_run";
244 -re "No symbol \"start\" in current.*$gdb_prompt $" {
245 send_gdb "jump *_start\n";
247 -re "No symbol.*context.*$gdb_prompt $" {
250 -re "Line.* Jump anyway.*y or n. $" {
253 -re "The program is not being run.*$gdb_prompt $" {
254 if { [gdb_reload] != 0 } {
257 send_gdb "jump *$start\n";
260 perror "Jump to start() failed (timeout)";
265 if [target_info exists gdb_stub] {
267 -re "$gdb_prompt $" {
268 send_gdb "continue\n"
275 if [target_info exists gdb,do_reload_on_run] {
276 if { [gdb_reload] != 0 } {
280 send_gdb "run $args\n"
281 # This doesn't work quite right yet.
282 # Use -notransfer here so that test cases (like chng-sym.exp)
283 # may test for additional start-up messages.
285 -re "The program .* has been started already.*y or n. $" {
289 -notransfer -re "Starting program: \[^\r\n\]*" {}
293 # Generic start command. Return 0 if we could start the program, -1
296 proc gdb_start_cmd {args} {
299 if [target_info exists gdb_init_command] {
300 send_gdb "[target_info gdb_init_command]\n";
302 -re "$gdb_prompt $" { }
304 perror "gdb_init_command for target failed";
310 if [target_info exists use_gdb_stub] {
314 send_gdb "start $args\n"
316 -re "The program .* has been started already.*y or n. $" {
320 # Use -notransfer here so that test cases (like chng-sym.exp)
321 # may test for additional start-up messages.
322 -notransfer -re "Starting program: \[^\r\n\]*" {
329 # Set a breakpoint at FUNCTION. If there is an additional argument it is
330 # a list of options; the supported options are allow-pending, temporary,
333 proc gdb_breakpoint { function args } {
337 set pending_response n
338 if {[lsearch -exact [lindex $args 0] allow-pending] != -1} {
339 set pending_response y
342 set break_command "break"
343 set break_message "Breakpoint"
344 if {[lsearch -exact [lindex $args 0] temporary] != -1} {
345 set break_command "tbreak"
346 set break_message "Temporary breakpoint"
350 if {[lsearch -exact [lindex $args 0] no-message] != -1} {
354 send_gdb "$break_command $function\n"
355 # The first two regexps are what we get with -g, the third is without -g.
357 -re "$break_message \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
358 -re "$break_message \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
359 -re "$break_message \[0-9\]* at .*$gdb_prompt $" {}
360 -re "$break_message \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" {
361 if {$pending_response == "n"} {
362 if { $no_message == 0 } {
363 fail "setting breakpoint at $function"
368 -re "Make breakpoint pending.*y or \\\[n\\\]. $" {
369 send_gdb "$pending_response\n"
372 -re "$gdb_prompt $" {
373 if { $no_message == 0 } {
374 fail "setting breakpoint at $function"
379 if { $no_message == 0 } {
380 fail "setting breakpoint at $function (timeout)"
388 # Set breakpoint at function and run gdb until it breaks there.
389 # Since this is the only breakpoint that will be set, if it stops
390 # at a breakpoint, we will assume it is the one we want. We can't
391 # just compare to "function" because it might be a fully qualified,
392 # single quoted C++ function specifier. If there's an additional argument,
393 # pass it to gdb_breakpoint.
395 proc runto { function args } {
401 if ![gdb_breakpoint $function [lindex $args 0]] {
407 # the "at foo.c:36" output we get with -g.
408 # the "in func" output we get without -g.
410 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
413 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
416 -re "$gdb_prompt $" {
417 fail "running to $function in runto"
421 fail "running to $function in runto (end of file)"
425 fail "running to $function in runto (timeout)"
433 # runto_main -- ask gdb to run until we hit a breakpoint at main.
434 # The case where the target uses stubs has to be handled
435 # specially--if it uses stubs, assuming we hit
436 # breakpoint() and just step out of the function.
438 proc runto_main { } {
442 if ![target_info exists gdb_stub] {
454 ### Continue, and expect to hit a breakpoint.
455 ### Report a pass or fail, depending on whether it seems to have
456 ### worked. Use NAME as part of the test name; each call to
457 ### continue_to_breakpoint should use a NAME which is unique within
459 proc gdb_continue_to_breakpoint {name {location_pattern .*}} {
461 set full_name "continue to breakpoint: $name"
463 send_gdb "continue\n"
465 -re "Breakpoint .* (at|in) $location_pattern\r\n$gdb_prompt $" {
468 -re ".*$gdb_prompt $" {
472 fail "$full_name (timeout)"
478 # gdb_internal_error_resync:
480 # Answer the questions GDB asks after it reports an internal error
481 # until we get back to a GDB prompt. Decline to quit the debugging
482 # session, and decline to create a core file. Return non-zero if the
485 # This procedure just answers whatever questions come up until it sees
486 # a GDB prompt; it doesn't require you to have matched the input up to
487 # any specific point. However, it only answers questions it sees in
488 # the output itself, so if you've matched a question, you had better
489 # answer it yourself before calling this.
491 # You can use this function thus:
495 # -re ".*A problem internal to GDB has been detected" {
496 # gdb_internal_error_resync
501 proc gdb_internal_error_resync {} {
505 while {$count < 10} {
507 -re "Quit this debugging session\\? \\(y or n\\) $" {
511 -re "Create a core file of GDB\\? \\(y or n\\) $" {
515 -re "$gdb_prompt $" {
516 # We're resynchronized.
520 perror "Could not resync from internal error (timeout)"
525 perror "Could not resync from internal error (resync count exceeded)"
530 # gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS
531 # Send a command to gdb; test the result.
533 # COMMAND is the command to execute, send to GDB with send_gdb. If
534 # this is the null string no command is sent.
535 # MESSAGE is a message to be printed with the built-in failure patterns
536 # if one of them matches. If MESSAGE is empty COMMAND will be used.
537 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
538 # patterns. Pattern elements will be evaluated in the caller's
539 # context; action elements will be executed in the caller's context.
540 # Unlike patterns for gdb_test, these patterns should generally include
541 # the final newline and prompt.
544 # 1 if the test failed, according to a built-in failure pattern
545 # 0 if only user-supplied patterns matched
546 # -1 if there was an internal error.
548 # You can use this function thus:
550 # gdb_test_multiple "print foo" "test foo" {
551 # -re "expected output 1" {
554 # -re "expected output 2" {
559 # The standard patterns, such as "Program exited..." and "A problem
560 # ...", all being implicitly appended to that list.
562 proc gdb_test_multiple { command message user_code } {
566 upvar timeout timeout
567 upvar expect_out expect_out
569 if { $message == "" } {
573 # TCL/EXPECT WART ALERT
574 # Expect does something very strange when it receives a single braced
575 # argument. It splits it along word separators and performs substitutions.
576 # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
577 # evaluated as "\[ab\]". But that's not how TCL normally works; inside a
578 # double-quoted list item, "\[ab\]" is just a long way of representing
579 # "[ab]", because the backslashes will be removed by lindex.
581 # Unfortunately, there appears to be no easy way to duplicate the splitting
582 # that expect will do from within TCL. And many places make use of the
583 # "\[0-9\]" construct, so we need to support that; and some places make use
584 # of the "[func]" construct, so we need to support that too. In order to
585 # get this right we have to substitute quoted list elements differently
586 # from braced list elements.
588 # We do this roughly the same way that Expect does it. We have to use two
589 # lists, because if we leave unquoted newlines in the argument to uplevel
590 # they'll be treated as command separators, and if we escape newlines
591 # we mangle newlines inside of command blocks. This assumes that the
592 # input doesn't contain a pattern which contains actual embedded newlines
595 regsub -all {\n} ${user_code} { } subst_code
596 set subst_code [uplevel list $subst_code]
598 set processed_code ""
600 set expecting_action 0
601 foreach item $user_code subst_item $subst_code {
602 if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } {
603 lappend processed_code $item
606 if {$item == "-indices" || $item == "-re" || $item == "-ex"} {
607 lappend processed_code $item
610 if { $expecting_action } {
611 lappend processed_code "uplevel [list $item]"
612 set expecting_action 0
613 # Cosmetic, no effect on the list.
614 append processed_code "\n"
617 set expecting_action 1
618 lappend processed_code $subst_item
619 if {$patterns != ""} {
622 append patterns "\"$subst_item\""
625 # Also purely cosmetic.
626 regsub -all {\r} $patterns {\\r} patterns
627 regsub -all {\n} $patterns {\\n} patterns
630 send_user "Sending \"$command\" to gdb\n"
631 send_user "Looking to match \"$patterns\"\n"
632 send_user "Message is \"$message\"\n"
636 set string "${command}\n";
637 if { $command != "" } {
638 while { "$string" != "" } {
639 set foo [string first "\n" "$string"];
640 set len [string length "$string"];
641 if { $foo < [expr $len - 1] } {
642 set str [string range "$string" 0 $foo];
643 if { [send_gdb "$str"] != "" } {
644 global suppress_flag;
646 if { ! $suppress_flag } {
647 perror "Couldn't send $command to GDB.";
652 # since we're checking if each line of the multi-line
653 # command are 'accepted' by GDB here,
654 # we need to set -notransfer expect option so that
655 # command output is not lost for pattern matching
658 -notransfer -re "\[\r\n\]" { verbose "partial: match" 3 }
659 timeout { verbose "partial: timeout" 3 }
661 set string [string range "$string" [expr $foo + 1] end];
666 if { "$string" != "" } {
667 if { [send_gdb "$string"] != "" } {
668 global suppress_flag;
670 if { ! $suppress_flag } {
671 perror "Couldn't send $command to GDB.";
679 if [target_info exists gdb,timeout] {
680 set tmt [target_info gdb,timeout];
682 if [info exists timeout] {
686 if [info exists timeout] {
695 -re ".*A problem internal to GDB has been detected" {
696 fail "$message (GDB internal error)"
697 gdb_internal_error_resync
699 -re "\\*\\*\\* DOSEXIT code.*" {
700 if { $message != "" } {
703 gdb_suppress_entire_file "GDB died";
707 append code $processed_code
709 -re "Ending remote debugging.*$gdb_prompt $" {
710 if ![isnative] then {
711 warning "Can`t communicate to remote target."
717 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
718 perror "Undefined command \"$command\"."
722 -re "Ambiguous command.*$gdb_prompt $" {
723 perror "\"$command\" is not a unique command name."
727 -re "Program exited with code \[0-9\]+.*$gdb_prompt $" {
728 if ![string match "" $message] then {
729 set errmsg "$message (the program exited)"
731 set errmsg "$command (the program exited)"
736 -re "EXIT code \[0-9\r\n\]+Program exited normally.*$gdb_prompt $" {
737 if ![string match "" $message] then {
738 set errmsg "$message (the program exited)"
740 set errmsg "$command (the program exited)"
745 -re "The program is not being run.*$gdb_prompt $" {
746 if ![string match "" $message] then {
747 set errmsg "$message (the program is no longer running)"
749 set errmsg "$command (the program is no longer running)"
754 -re "\r\n$gdb_prompt $" {
755 if ![string match "" $message] then {
762 perror "Window too small."
766 -re "\\(y or n\\) " {
768 perror "Got interactive prompt."
773 perror "Process no longer exists"
774 if { $message != "" } {
780 perror "internal buffer is full."
785 if ![string match "" $message] then {
786 fail "$message (timeout)"
793 set code [catch {gdb_expect $tmt $code} string]
795 global errorInfo errorCode;
796 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
797 } elseif {$code == 2} {
798 return -code return $string
799 } elseif {$code == 3} {
801 } elseif {$code > 4} {
802 return -code $code $string
807 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
808 # Send a command to gdb; test the result.
810 # COMMAND is the command to execute, send to GDB with send_gdb. If
811 # this is the null string no command is sent.
812 # PATTERN is the pattern to match for a PASS, and must NOT include
813 # the \r\n sequence immediately before the gdb prompt.
814 # MESSAGE is an optional message to be printed. If this is
815 # omitted, then the pass/fail messages use the command string as the
816 # message. (If this is the empty string, then sometimes we don't
817 # call pass or fail at all; I don't understand this at all.)
818 # QUESTION is a question GDB may ask in response to COMMAND, like
820 # RESPONSE is the response to send if QUESTION appears.
823 # 1 if the test failed,
824 # 0 if the test passes,
825 # -1 if there was an internal error.
827 proc gdb_test { args } {
831 upvar timeout timeout
833 if [llength $args]>2 then {
834 set message [lindex $args 2]
836 set message [lindex $args 0]
838 set command [lindex $args 0]
839 set pattern [lindex $args 1]
841 if [llength $args]==5 {
842 set question_string [lindex $args 3];
843 set response_string [lindex $args 4];
845 set question_string "^FOOBAR$"
848 return [gdb_test_multiple $command $message {
849 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
850 if ![string match "" $message] then {
854 -re "(${question_string})$" {
855 send_gdb "$response_string\n";
861 # Test that a command gives an error. For pass or fail, return
862 # a 1 to indicate that more tests can proceed. However a timeout
863 # is a serious error, generates a special fail message, and causes
864 # a 0 to be returned to indicate that more tests are likely to fail
867 proc test_print_reject { args } {
871 if [llength $args]==2 then {
872 set expectthis [lindex $args 1]
874 set expectthis "should never match this bogus string"
876 set sendthis [lindex $args 0]
878 send_user "Sending \"$sendthis\" to gdb\n"
879 send_user "Looking to match \"$expectthis\"\n"
881 send_gdb "$sendthis\n"
882 #FIXME: Should add timeout as parameter.
884 -re "A .* in expression.*\\.*$gdb_prompt $" {
885 pass "reject $sendthis"
888 -re "Invalid syntax in expression.*$gdb_prompt $" {
889 pass "reject $sendthis"
892 -re "Junk after end of expression.*$gdb_prompt $" {
893 pass "reject $sendthis"
896 -re "Invalid number.*$gdb_prompt $" {
897 pass "reject $sendthis"
900 -re "Invalid character constant.*$gdb_prompt $" {
901 pass "reject $sendthis"
904 -re "No symbol table is loaded.*$gdb_prompt $" {
905 pass "reject $sendthis"
908 -re "No symbol .* in current context.*$gdb_prompt $" {
909 pass "reject $sendthis"
912 -re "Unmatched single quote.*$gdb_prompt $" {
913 pass "reject $sendthis"
916 -re "A character constant must contain at least one character.*$gdb_prompt $" {
917 pass "reject $sendthis"
920 -re "$expectthis.*$gdb_prompt $" {
921 pass "reject $sendthis"
924 -re ".*$gdb_prompt $" {
925 fail "reject $sendthis"
929 fail "reject $sendthis (eof or timeout)"
935 # Given an input string, adds backslashes as needed to create a
936 # regexp that will match the string.
938 proc string_to_regexp {str} {
940 regsub -all {[]*+.|()^$\[\\]} $str {\\&} result
944 # Same as gdb_test, but the second parameter is not a regexp,
945 # but a string that must match exactly.
947 proc gdb_test_exact { args } {
948 upvar timeout timeout
950 set command [lindex $args 0]
952 # This applies a special meaning to a null string pattern. Without
953 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
954 # messages from commands that should have no output except a new
955 # prompt. With this, only results of a null string will match a null
958 set pattern [lindex $args 1]
959 if [string match $pattern ""] {
960 set pattern [string_to_regexp [lindex $args 0]]
962 set pattern [string_to_regexp [lindex $args 1]]
965 # It is most natural to write the pattern argument with only
966 # embedded \n's, especially if you are trying to avoid Tcl quoting
967 # problems. But gdb_expect really wants to see \r\n in patterns. So
968 # transform the pattern here. First transform \r\n back to \n, in
969 # case some users of gdb_test_exact already do the right thing.
970 regsub -all "\r\n" $pattern "\n" pattern
971 regsub -all "\n" $pattern "\r\n" pattern
972 if [llength $args]==3 then {
973 set message [lindex $args 2]
978 return [gdb_test $command $pattern $message]
981 proc gdb_reinitialize_dir { subdir } {
984 if [is_remote host] {
989 -re "Reinitialize source path to empty.*y or n. " {
992 -re "Source directories searched.*$gdb_prompt $" {
993 send_gdb "dir $subdir\n"
995 -re "Source directories searched.*$gdb_prompt $" {
996 verbose "Dir set to $subdir"
998 -re "$gdb_prompt $" {
999 perror "Dir \"$subdir\" failed."
1003 -re "$gdb_prompt $" {
1004 perror "Dir \"$subdir\" failed."
1008 -re "$gdb_prompt $" {
1009 perror "Dir \"$subdir\" failed."
1015 # gdb_exit -- exit the GDB, killing the target program if necessary
1017 proc default_gdb_exit {} {
1019 global INTERNAL_GDBFLAGS GDBFLAGS
1021 global gdb_spawn_id;
1023 gdb_stop_suppressing_tests;
1025 if ![info exists gdb_spawn_id] {
1029 verbose "Quitting $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1031 if { [is_remote host] && [board_info host exists fileid] } {
1038 -re "DOSEXIT code" { }
1043 if ![is_remote host] {
1049 # Load a file into the debugger.
1050 # The return value is 0 for success, -1 for failure.
1052 # This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO
1053 # to one of these values:
1055 # debug file was loaded successfully and has debug information
1056 # nodebug file was loaded successfully and has no debug information
1057 # fail file was not loaded
1059 # I tried returning this information as part of the return value,
1060 # but ran into a mess because of the many re-implementations of
1061 # gdb_load in config/*.exp.
1063 # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use
1064 # this if they can get more information set.
1066 proc gdb_file_cmd { arg } {
1070 global last_loaded_file
1072 set last_loaded_file $arg
1074 # Set whether debug info was found.
1075 # Default to "fail".
1076 global gdb_file_cmd_debug_info
1077 set gdb_file_cmd_debug_info "fail"
1079 if [is_remote host] {
1080 set arg [remote_download host $arg]
1082 perror "download failed"
1087 # The file command used to kill the remote target. For the benefit
1088 # of the testsuite, preserve this behavior.
1091 -re "Kill the program being debugged. .y or n. $" {
1093 verbose "\t\tKilling previous program being debugged"
1096 -re "$gdb_prompt $" {
1101 send_gdb "file $arg\n"
1103 -re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" {
1104 verbose "\t\tLoaded $arg into the $GDB with no debugging symbols"
1105 set gdb_file_cmd_debug_info "nodebug"
1108 -re "Reading symbols from.*done.*$gdb_prompt $" {
1109 verbose "\t\tLoaded $arg into the $GDB"
1110 set gdb_file_cmd_debug_info "debug"
1113 -re "Load new symbol table from \".*\".*y or n. $" {
1116 -re "Reading symbols from.*done.*$gdb_prompt $" {
1117 verbose "\t\tLoaded $arg with new symbol table into $GDB"
1118 set gdb_file_cmd_debug_info "debug"
1122 perror "(timeout) Couldn't load $arg, other program already loaded."
1127 -re "No such file or directory.*$gdb_prompt $" {
1128 perror "($arg) No such file or directory"
1131 -re "$gdb_prompt $" {
1132 perror "couldn't load $arg into $GDB."
1136 perror "couldn't load $arg into $GDB (timed out)."
1140 # This is an attempt to detect a core dump, but seems not to
1141 # work. Perhaps we need to match .* followed by eof, in which
1142 # gdb_expect does not seem to have a way to do that.
1143 perror "couldn't load $arg into $GDB (end of file)."
1150 # start gdb -- start gdb running, default procedure
1152 # When running over NFS, particularly if running many simultaneous
1153 # tests on different hosts all using the same server, things can
1154 # get really slow. Give gdb at least 3 minutes to start up.
1156 proc default_gdb_start { } {
1159 global INTERNAL_GDBFLAGS GDBFLAGS
1162 global gdb_spawn_id;
1165 gdb_stop_suppressing_tests;
1169 # Don't let a .inputrc file or an existing setting of INPUTRC mess up
1170 # the test results. Even if /dev/null doesn't exist on the particular
1171 # platform, the readline library will use the default setting just by
1172 # failing to open the file. OTOH, opening /dev/null successfully will
1173 # also result in the default settings being used since nothing will be
1174 # read from this file.
1175 set env(INPUTRC) "/dev/null"
1177 # The gdb.base/readline.exp arrow key test relies on the standard VT100
1178 # bindings, so make sure that an appropriate terminal is selected.
1179 # The same bug doesn't show up if we use ^P / ^N instead.
1180 set env(TERM) "vt100"
1182 verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1184 if [info exists gdb_spawn_id] {
1188 if ![is_remote host] {
1189 if { [which $GDB] == 0 } then {
1190 perror "$GDB does not exist."
1194 set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"];
1195 if { $res < 0 || $res == "" } {
1196 perror "Spawning $GDB failed."
1200 -re "\[\r\n\]$gdb_prompt $" {
1201 verbose "GDB initialized."
1203 -re "$gdb_prompt $" {
1204 perror "GDB never initialized."
1208 perror "(timeout) GDB never initialized after 10 seconds."
1213 set gdb_spawn_id -1;
1214 # force the height to "unlimited", so no pagers get used
1216 send_gdb "set height 0\n"
1218 -re "$gdb_prompt $" {
1219 verbose "Setting height to 0." 2
1222 warning "Couldn't set the height to 0"
1225 # force the width to "unlimited", so no wraparound occurs
1226 send_gdb "set width 0\n"
1228 -re "$gdb_prompt $" {
1229 verbose "Setting width to 0." 2
1232 warning "Couldn't set the width to 0."
1238 # Examine the output of compilation to determine whether compilation
1239 # failed or not. If it failed determine whether it is due to missing
1240 # compiler or due to compiler error. Report pass, fail or unsupported
1243 proc gdb_compile_test {src output} {
1244 if { $output == "" } {
1245 pass "compilation [file tail $src]"
1246 } elseif { [regexp {^[a-zA-Z_0-9]+: Can't find [^ ]+\.$} $output] } {
1247 unsupported "compilation [file tail $src]"
1248 } elseif { [regexp {.*: command not found[\r|\n]*$} $output] } {
1249 unsupported "compilation [file tail $src]"
1251 verbose -log "compilation failed: $output" 2
1252 fail "compilation [file tail $src]"
1256 # Return a 1 for configurations for which we don't even want to try to
1259 proc skip_cplus_tests {} {
1260 if { [istarget "h8300-*-*"] } {
1264 # The C++ IO streams are too large for HC11/HC12 and are thus not
1265 # available. The gdb C++ tests use them and don't compile.
1266 if { [istarget "m6811-*-*"] } {
1269 if { [istarget "m6812-*-*"] } {
1275 # Return a 1 if I don't even want to try to test FORTRAN.
1277 proc skip_fortran_tests {} {
1281 # Return a 1 if I don't even want to try to test ada.
1283 proc skip_ada_tests {} {
1287 # Return a 1 if I don't even want to try to test java.
1289 proc skip_java_tests {} {
1293 # Return a 1 if we should skip shared library tests.
1295 proc skip_shlib_tests {} {
1296 # Run the shared library tests on native systems.
1301 # An abbreviated list of remote targets where we should be able to
1302 # run shared library tests.
1303 if {([istarget *-*-linux*]
1304 || [istarget *-*-*bsd*]
1305 || [istarget *-*-solaris2*]
1306 || [istarget arm*-*-symbianelf*]
1307 || [istarget *-*-mingw*]
1308 || [istarget *-*-cygwin*]
1309 || [istarget *-*-pe*])} {
1316 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
1317 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
1319 proc skip_altivec_tests {} {
1320 global skip_vmx_tests_saved
1321 global srcdir subdir gdb_prompt
1323 # Use the cached value, if it exists.
1324 set me "skip_altivec_tests"
1325 if [info exists skip_vmx_tests_saved] {
1326 verbose "$me: returning saved $skip_vmx_tests_saved" 2
1327 return $skip_vmx_tests_saved
1330 # Some simulators are known to not support VMX instructions.
1331 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1332 verbose "$me: target known to not support VMX, returning 1" 2
1333 return [set skip_vmx_tests_saved 1]
1336 # Make sure we have a compiler that understands altivec.
1337 set compile_flags {debug nowarnings}
1338 if [get_compiler_info not-used] {
1339 warning "Could not get compiler info"
1342 if [test_compiler_info gcc*] {
1343 set compile_flags "$compile_flags additional_flags=-maltivec"
1344 } elseif [test_compiler_info xlc*] {
1345 set compile_flags "$compile_flags additional_flags=-qaltivec"
1347 verbose "Could not compile with altivec support, returning 1" 2
1351 # Set up, compile, and execute a test program containing VMX instructions.
1352 # Include the current process ID in the file names to prevent conflicts
1353 # with invocations for multiple testsuites.
1357 set f [open $src "w"]
1358 puts $f "int main() {"
1359 puts $f "#ifdef __MACH__"
1360 puts $f " asm volatile (\"vor v0,v0,v0\");"
1362 puts $f " asm volatile (\"vor 0,0,0\");"
1364 puts $f " return 0; }"
1367 verbose "$me: compiling testfile $src" 2
1368 set lines [gdb_compile $src $exe executable $compile_flags]
1371 if ![string match "" $lines] then {
1372 verbose "$me: testfile compilation failed, returning 1" 2
1373 return [set skip_vmx_tests_saved 1]
1376 # No error message, compilation succeeded so now run it via gdb.
1380 gdb_reinitialize_dir $srcdir/$subdir
1384 -re ".*Illegal instruction.*${gdb_prompt} $" {
1385 verbose -log "\n$me altivec hardware not detected"
1386 set skip_vmx_tests_saved 1
1388 -re ".*Program exited normally.*${gdb_prompt} $" {
1389 verbose -log "\n$me: altivec hardware detected"
1390 set skip_vmx_tests_saved 0
1393 warning "\n$me: default case taken"
1394 set skip_vmx_tests_saved 1
1398 remote_file build delete $exe
1400 verbose "$me: returning $skip_vmx_tests_saved" 2
1401 return $skip_vmx_tests_saved
1404 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
1405 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
1407 proc skip_vsx_tests {} {
1408 global skip_vsx_tests_saved
1409 global srcdir subdir gdb_prompt
1411 # Use the cached value, if it exists.
1412 set me "skip_vsx_tests"
1413 if [info exists skip_vsx_tests_saved] {
1414 verbose "$me: returning saved $skip_vsx_tests_saved" 2
1415 return $skip_vsx_tests_saved
1418 # Some simulators are known to not support Altivec instructions, so
1419 # they won't support VSX instructions as well.
1420 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1421 verbose "$me: target known to not support VSX, returning 1" 2
1422 return [set skip_vsx_tests_saved 1]
1425 # Make sure we have a compiler that understands altivec.
1426 set compile_flags {debug nowarnings quiet}
1427 if [get_compiler_info not-used] {
1428 warning "Could not get compiler info"
1431 if [test_compiler_info gcc*] {
1432 set compile_flags "$compile_flags additional_flags=-mvsx"
1433 } elseif [test_compiler_info xlc*] {
1434 set compile_flags "$compile_flags additional_flags=-qvsx"
1436 verbose "Could not compile with vsx support, returning 1" 2
1443 set f [open $src "w"]
1444 puts $f "int main() {"
1445 puts $f "#ifdef __MACH__"
1446 puts $f " asm volatile (\"lxvd2x v0,v0,v0\");"
1448 puts $f " asm volatile (\"lxvd2x 0,0,0\");"
1450 puts $f " return 0; }"
1453 verbose "$me: compiling testfile $src" 2
1454 set lines [gdb_compile $src $exe executable $compile_flags]
1457 if ![string match "" $lines] then {
1458 verbose "$me: testfile compilation failed, returning 1" 2
1459 return [set skip_vsx_tests_saved 1]
1462 # No error message, compilation succeeded so now run it via gdb.
1466 gdb_reinitialize_dir $srcdir/$subdir
1470 -re ".*Illegal instruction.*${gdb_prompt} $" {
1471 verbose -log "\n$me VSX hardware not detected"
1472 set skip_vsx_tests_saved 1
1474 -re ".*Program exited normally.*${gdb_prompt} $" {
1475 verbose -log "\n$me: VSX hardware detected"
1476 set skip_vsx_tests_saved 0
1479 warning "\n$me: default case taken"
1480 set skip_vsx_tests_saved 1
1484 remote_file build delete $exe
1486 verbose "$me: returning $skip_vsx_tests_saved" 2
1487 return $skip_vsx_tests_saved
1490 # Skip all the tests in the file if you are not on an hppa running
1493 proc skip_hp_tests {} {
1494 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
1495 verbose "Skip hp tests is $skip_hp"
1499 # Return whether we should skip tests for showing inlined functions in
1500 # backtraces. Requires get_compiler_info and get_debug_format.
1502 proc skip_inline_frame_tests {} {
1503 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
1504 if { ! [test_debug_format "DWARF 2"] } {
1508 # GCC before 4.1 does not emit DW_AT_call_file / DW_AT_call_line.
1509 if { ([test_compiler_info "gcc-2-*"]
1510 || [test_compiler_info "gcc-3-*"]
1511 || [test_compiler_info "gcc-4-0-*"]) } {
1518 # Return whether we should skip tests for showing variables from
1519 # inlined functions. Requires get_compiler_info and get_debug_format.
1521 proc skip_inline_var_tests {} {
1522 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
1523 if { ! [test_debug_format "DWARF 2"] } {
1530 set compiler_info "unknown"
1532 set hp_cc_compiler 0
1533 set hp_aCC_compiler 0
1535 # Figure out what compiler I am using.
1537 # BINFILE is a "compiler information" output file. This implementation
1538 # does not use BINFILE.
1540 # ARGS can be empty or "C++". If empty, "C" is assumed.
1542 # There are several ways to do this, with various problems.
1544 # [ gdb_compile -E $ifile -o $binfile.ci ]
1545 # source $binfile.ci
1547 # Single Unix Spec v3 says that "-E -o ..." together are not
1548 # specified. And in fact, the native compiler on hp-ux 11 (among
1549 # others) does not work with "-E -o ...". Most targets used to do
1550 # this, and it mostly worked, because it works with gcc.
1552 # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ]
1553 # source $binfile.ci
1555 # This avoids the problem with -E and -o together. This almost works
1556 # if the build machine is the same as the host machine, which is
1557 # usually true of the targets which are not gcc. But this code does
1558 # not figure which compiler to call, and it always ends up using the C
1559 # compiler. Not good for setting hp_aCC_compiler. Targets
1560 # hppa*-*-hpux* and mips*-*-irix* used to do this.
1562 # [ gdb_compile -E $ifile > $binfile.ci ]
1563 # source $binfile.ci
1565 # dejagnu target_compile says that it supports output redirection,
1566 # but the code is completely different from the normal path and I
1567 # don't want to sweep the mines from that path. So I didn't even try
1570 # set cppout [ gdb_compile $ifile "" preprocess $args quiet ]
1573 # I actually do this for all targets now. gdb_compile runs the right
1574 # compiler, and TCL captures the output, and I eval the output.
1576 # Unfortunately, expect logs the output of the command as it goes by,
1577 # and dejagnu helpfully prints a second copy of it right afterwards.
1578 # So I turn off expect logging for a moment.
1580 # [ gdb_compile $ifile $ciexe_file executable $args ]
1581 # [ remote_exec $ciexe_file ]
1582 # [ source $ci_file.out ]
1584 # I could give up on -E and just do this.
1585 # I didn't get desperate enough to try this.
1587 # -- chastain 2004-01-06
1589 proc get_compiler_info {binfile args} {
1590 # For compiler.c and compiler.cc
1593 # I am going to play with the log to keep noise out.
1597 # These come from compiler.c or compiler.cc
1598 global compiler_info
1600 # Legacy global data symbols.
1602 global hp_cc_compiler
1603 global hp_aCC_compiler
1605 # Choose which file to preprocess.
1606 set ifile "${srcdir}/lib/compiler.c"
1607 if { [llength $args] > 0 && [lindex $args 0] == "c++" } {
1608 set ifile "${srcdir}/lib/compiler.cc"
1611 # Run $ifile through the right preprocessor.
1612 # Toggle gdb.log to keep the compiler output out of the log.
1614 if [is_remote host] {
1615 # We have to use -E and -o together, despite the comments
1616 # above, because of how DejaGnu handles remote host testing.
1617 set ppout "$outdir/compiler.i"
1618 gdb_compile "${ifile}" "$ppout" preprocess [list "$args" quiet]
1619 set file [open $ppout r]
1620 set cppout [read $file]
1623 set cppout [ gdb_compile "${ifile}" "" preprocess [list "$args" quiet] ]
1625 log_file -a "$outdir/$tool.log"
1629 foreach cppline [ split "$cppout" "\n" ] {
1630 if { [ regexp "^#" "$cppline" ] } {
1632 } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } {
1634 } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } {
1636 verbose "get_compiler_info: $cppline" 2
1640 verbose -log "get_compiler_info: $cppline"
1645 # Reset to unknown compiler if any diagnostics happened.
1647 set compiler_info "unknown"
1650 # Set the legacy symbols.
1652 set hp_cc_compiler 0
1653 set hp_aCC_compiler 0
1654 if { [regexp "^gcc-1-" "$compiler_info" ] } { set gcc_compiled 1 }
1655 if { [regexp "^gcc-2-" "$compiler_info" ] } { set gcc_compiled 2 }
1656 if { [regexp "^gcc-3-" "$compiler_info" ] } { set gcc_compiled 3 }
1657 if { [regexp "^gcc-4-" "$compiler_info" ] } { set gcc_compiled 4 }
1658 if { [regexp "^gcc-5-" "$compiler_info" ] } { set gcc_compiled 5 }
1659 if { [regexp "^hpcc-" "$compiler_info" ] } { set hp_cc_compiler 1 }
1660 if { [regexp "^hpacc-" "$compiler_info" ] } { set hp_aCC_compiler 1 }
1662 # Log what happened.
1663 verbose -log "get_compiler_info: $compiler_info"
1665 # Most compilers will evaluate comparisons and other boolean
1666 # operations to 0 or 1.
1667 uplevel \#0 { set true 1 }
1668 uplevel \#0 { set false 0 }
1670 # Use of aCC results in boolean results being displayed as
1672 if { $hp_aCC_compiler } {
1673 uplevel \#0 { set true true }
1674 uplevel \#0 { set false false }
1680 proc test_compiler_info { {compiler ""} } {
1681 global compiler_info
1683 # if no arg, return the compiler_info string
1685 if [string match "" $compiler] {
1686 if [info exists compiler_info] {
1687 return $compiler_info
1689 perror "No compiler info found."
1693 return [string match $compiler $compiler_info]
1696 set gdb_wrapper_initialized 0
1698 proc gdb_wrapper_init { args } {
1699 global gdb_wrapper_initialized;
1700 global gdb_wrapper_file;
1701 global gdb_wrapper_flags;
1703 if { $gdb_wrapper_initialized == 1 } { return; }
1705 if {[target_info exists needs_status_wrapper] && \
1706 [target_info needs_status_wrapper] != "0"} {
1707 set result [build_wrapper "testglue.o"];
1708 if { $result != "" } {
1709 set gdb_wrapper_file [lindex $result 0];
1710 set gdb_wrapper_flags [lindex $result 1];
1712 warning "Status wrapper failed to build."
1715 set gdb_wrapper_initialized 1
1718 # Some targets need to always link a special object in. Save its path here.
1719 global gdb_saved_set_unbuffered_mode_obj
1720 set gdb_saved_set_unbuffered_mode_obj ""
1722 proc gdb_compile {source dest type options} {
1723 global GDB_TESTCASE_OPTIONS;
1724 global gdb_wrapper_file;
1725 global gdb_wrapper_flags;
1726 global gdb_wrapper_initialized;
1729 global gdb_saved_set_unbuffered_mode_obj
1731 set outdir [file dirname $dest]
1733 # Add platform-specific options if a shared library was specified using
1734 # "shlib=librarypath" in OPTIONS.
1738 foreach opt $options {
1739 if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] {
1740 if [test_compiler_info "xlc-*"] {
1741 # IBM xlc compiler doesn't accept shared library named other
1742 # than .so: use "-Wl," to bypass this
1743 lappend source "-Wl,$shlib_name"
1744 } elseif { ([istarget "*-*-mingw*"]
1745 || [istarget *-*-cygwin*]
1746 || [istarget *-*-pe*])} {
1747 lappend source "${shlib_name}.a"
1749 lappend source $shlib_name
1751 if { $shlib_found == 0 } {
1753 if { ([istarget "*-*-mingw*"]
1754 || [istarget *-*-cygwin*]) } {
1755 lappend new_options "additional_flags=-Wl,--enable-auto-import"
1758 } elseif { $opt == "shlib_load" } {
1761 lappend new_options $opt
1765 # We typically link to shared libraries using an absolute path, and
1766 # that's how they are found at runtime. If we are going to
1767 # dynamically load one by basename, we must specify rpath. If we
1768 # are using a remote host, DejaGNU will link to the shared library
1769 # using a relative path, so again we must specify an rpath.
1770 if { $shlib_load || ($shlib_found && [is_remote host]) } {
1771 if { ([istarget "*-*-mingw*"]
1772 || [istarget *-*-cygwin*]
1773 || [istarget *-*-pe*]
1774 || [istarget arm*-*-symbianelf*]
1775 || [istarget hppa*-*-hpux*])} {
1776 # Do not need anything.
1777 } elseif { [istarget *-*-openbsd*] } {
1778 lappend new_options "additional_flags=-Wl,-rpath,${outdir}"
1780 if { $shlib_load } {
1781 lappend new_options "libs=-ldl"
1783 lappend new_options "additional_flags=-Wl,-rpath,\\\$ORIGIN"
1786 set options $new_options
1788 if [target_info exists gdb_stub] {
1789 set options2 { "additional_flags=-Dusestubs" }
1790 lappend options "libs=[target_info gdb_stub]";
1791 set options [concat $options2 $options]
1793 if [target_info exists is_vxworks] {
1794 set options2 { "additional_flags=-Dvxworks" }
1795 lappend options "libs=[target_info gdb_stub]";
1796 set options [concat $options2 $options]
1798 if [info exists GDB_TESTCASE_OPTIONS] {
1799 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
1801 verbose "options are $options"
1802 verbose "source is $source $dest $type $options"
1804 if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init }
1806 if {[target_info exists needs_status_wrapper] && \
1807 [target_info needs_status_wrapper] != "0" && \
1808 [info exists gdb_wrapper_file]} {
1809 lappend options "libs=${gdb_wrapper_file}"
1810 lappend options "ldflags=${gdb_wrapper_flags}"
1813 # Replace the "nowarnings" option with the appropriate additional_flags
1814 # to disable compiler warnings.
1815 set nowarnings [lsearch -exact $options nowarnings]
1816 if {$nowarnings != -1} {
1817 if [target_info exists gdb,nowarnings_flag] {
1818 set flag "additional_flags=[target_info gdb,nowarnings_flag]"
1820 set flag "additional_flags=-w"
1822 set options [lreplace $options $nowarnings $nowarnings $flag]
1825 if { $type == "executable" } {
1826 if { ([istarget "*-*-mingw*"]
1827 || [istarget "*-*-*djgpp"]
1828 || [istarget "*-*-cygwin*"])} {
1829 # Force output to unbuffered mode, by linking in an object file
1830 # with a global contructor that calls setvbuf.
1832 # Compile the special object seperatelly for two reasons:
1833 # 1) Insulate it from $options.
1834 # 2) Avoid compiling it for every gdb_compile invocation,
1835 # which is time consuming, especially if we're remote
1838 if { $gdb_saved_set_unbuffered_mode_obj == "" } {
1839 verbose "compiling gdb_saved_set_unbuffered_obj"
1840 set unbuf_src ${srcdir}/lib/set_unbuffered_mode.c
1841 set unbuf_obj ${objdir}/set_unbuffered_mode.o
1843 set result [gdb_compile "${unbuf_src}" "${unbuf_obj}" object {nowarnings}]
1844 if { $result != "" } {
1848 set gdb_saved_set_unbuffered_mode_obj ${objdir}/set_unbuffered_mode_saved.o
1849 # Link a copy of the output object, because the
1850 # original may be automatically deleted.
1851 remote_exec host "cp -f $unbuf_obj $gdb_saved_set_unbuffered_mode_obj"
1853 verbose "gdb_saved_set_unbuffered_obj already compiled"
1856 # Rely on the internal knowledge that the global ctors are ran in
1857 # reverse link order. In that case, we can use ldflags to
1858 # avoid copying the object file to the host multiple
1860 # This object can only be added if standard libraries are
1861 # used. Thus, we need to disable it if -nostdlib option is used
1862 if {[lsearch -regexp $options "-nostdlib"] < 0 } {
1863 lappend options "ldflags=$gdb_saved_set_unbuffered_mode_obj"
1868 set result [target_compile $source $dest $type $options];
1870 # Prune uninteresting compiler (and linker) output.
1871 regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result
1873 regsub "\[\r\n\]*$" "$result" "" result;
1874 regsub "^\[\r\n\]*" "$result" "" result;
1876 if {[lsearch $options quiet] < 0} {
1877 # We shall update this on a per language basis, to avoid
1878 # changing the entire testsuite in one go.
1879 if {[lsearch $options f77] >= 0} {
1880 gdb_compile_test $source $result
1881 } elseif { $result != "" } {
1882 clone_output "gdb compile failed, $result"
1889 # This is just like gdb_compile, above, except that it tries compiling
1890 # against several different thread libraries, to see which one this
1892 proc gdb_compile_pthreads {source dest type options} {
1894 set why_msg "unrecognized error"
1895 foreach lib {-lpthreads -lpthread -lthread} {
1896 # This kind of wipes out whatever libs the caller may have
1897 # set. Or maybe theirs will override ours. How infelicitous.
1898 set options_with_lib [concat $options [list libs=$lib quiet]]
1899 set ccout [gdb_compile $source $dest $type $options_with_lib]
1900 switch -regexp -- $ccout {
1901 ".*no posix threads support.*" {
1902 set why_msg "missing threads include file"
1905 ".*cannot open -lpthread.*" {
1906 set why_msg "missing runtime threads library"
1908 ".*Can't find library for -lpthread.*" {
1909 set why_msg "missing runtime threads library"
1912 pass "successfully compiled posix threads test case"
1918 if {!$built_binfile} {
1919 unsupported "Couldn't compile $source: ${why_msg}"
1924 # Build a shared library from SOURCES. You must use get_compiler_info
1927 proc gdb_compile_shlib {sources dest options} {
1928 set obj_options $options
1930 switch -glob [test_compiler_info] {
1932 lappend obj_options "additional_flags=-qpic"
1935 if { !([istarget "powerpc*-*-aix*"]
1936 || [istarget "rs6000*-*-aix*"]
1937 || [istarget "*-*-cygwin*"]
1938 || [istarget "*-*-mingw*"]
1939 || [istarget "*-*-pe*"]) } {
1940 lappend obj_options "additional_flags=-fpic"
1944 switch -glob [istarget] {
1946 lappend obj_options "additional_flags=+z"
1949 # Disable SGI compiler's implicit -Dsgi
1950 lappend obj_options "additional_flags=-Usgi"
1953 # don't know what the compiler is...
1959 set outdir [file dirname $dest]
1961 foreach source $sources {
1962 set sourcebase [file tail $source]
1963 if {[gdb_compile $source "${outdir}/${sourcebase}.o" object $obj_options] != ""} {
1966 lappend objects ${outdir}/${sourcebase}.o
1969 if [istarget "hppa*-*-hpux*"] {
1970 remote_exec build "ld -b ${objects} -o ${dest}"
1972 set link_options $options
1973 if [test_compiler_info "xlc-*"] {
1974 lappend link_options "additional_flags=-qmkshrobj"
1976 lappend link_options "additional_flags=-shared"
1978 if { ([istarget "*-*-mingw*"]
1979 || [istarget *-*-cygwin*]
1980 || [istarget *-*-pe*])} {
1981 lappend link_options "additional_flags=-Wl,--out-implib,${dest}.a"
1984 if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
1990 # This is just like gdb_compile_pthreads, above, except that we always add the
1991 # objc library for compiling Objective-C programs
1992 proc gdb_compile_objc {source dest type options} {
1994 set why_msg "unrecognized error"
1995 foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} {
1996 # This kind of wipes out whatever libs the caller may have
1997 # set. Or maybe theirs will override ours. How infelicitous.
1998 if { $lib == "solaris" } {
1999 set lib "-lpthread -lposix4"
2001 if { $lib != "-lobjc" } {
2002 set lib "-lobjc $lib"
2004 set options_with_lib [concat $options [list libs=$lib quiet]]
2005 set ccout [gdb_compile $source $dest $type $options_with_lib]
2006 switch -regexp -- $ccout {
2007 ".*no posix threads support.*" {
2008 set why_msg "missing threads include file"
2011 ".*cannot open -lpthread.*" {
2012 set why_msg "missing runtime threads library"
2014 ".*Can't find library for -lpthread.*" {
2015 set why_msg "missing runtime threads library"
2018 pass "successfully compiled objc with posix threads test case"
2024 if {!$built_binfile} {
2025 unsupported "Couldn't compile $source: ${why_msg}"
2030 proc send_gdb { string } {
2031 global suppress_flag;
2032 if { $suppress_flag } {
2033 return "suppressed";
2035 return [remote_send host "$string"];
2041 proc gdb_expect { args } {
2042 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
2043 set atimeout [lindex $args 0];
2044 set expcode [list [lindex $args 1]];
2049 upvar timeout timeout;
2051 if [target_info exists gdb,timeout] {
2052 if [info exists timeout] {
2053 if { $timeout < [target_info gdb,timeout] } {
2054 set gtimeout [target_info gdb,timeout];
2056 set gtimeout $timeout;
2059 set gtimeout [target_info gdb,timeout];
2063 if ![info exists gtimeout] {
2065 if [info exists timeout] {
2066 set gtimeout $timeout;
2070 if [info exists atimeout] {
2071 if { ![info exists gtimeout] || $gtimeout < $atimeout } {
2072 set gtimeout $atimeout;
2075 if ![info exists gtimeout] {
2081 global suppress_flag;
2082 global remote_suppress_flag;
2083 if [info exists remote_suppress_flag] {
2084 set old_val $remote_suppress_flag;
2086 if [info exists suppress_flag] {
2087 if { $suppress_flag } {
2088 set remote_suppress_flag 1;
2092 {uplevel remote_expect host $gtimeout $expcode} string];
2093 if [info exists old_val] {
2094 set remote_suppress_flag $old_val;
2096 if [info exists remote_suppress_flag] {
2097 unset remote_suppress_flag;
2102 global errorInfo errorCode;
2104 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
2105 } elseif {$code == 2} {
2106 return -code return $string
2107 } elseif {$code == 3} {
2109 } elseif {$code > 4} {
2110 return -code $code $string
2114 # gdb_expect_list MESSAGE SENTINEL LIST -- expect a sequence of outputs
2116 # Check for long sequence of output by parts.
2117 # MESSAGE: is the test message to be printed with the test success/fail.
2118 # SENTINEL: Is the terminal pattern indicating that output has finished.
2119 # LIST: is the sequence of outputs to match.
2120 # If the sentinel is recognized early, it is considered an error.
2123 # 1 if the test failed,
2124 # 0 if the test passes,
2125 # -1 if there was an internal error.
2127 proc gdb_expect_list {test sentinel list} {
2129 global suppress_flag
2132 if { $suppress_flag } {
2134 unresolved "${test}"
2136 while { ${index} < [llength ${list}] } {
2137 set pattern [lindex ${list} ${index}]
2138 set index [expr ${index} + 1]
2139 if { ${index} == [llength ${list}] } {
2142 -re "${pattern}${sentinel}" {
2143 # pass "${test}, pattern ${index} + sentinel"
2146 fail "${test} (pattern ${index} + sentinel)"
2149 -re ".*A problem internal to GDB has been detected" {
2150 fail "${test} (GDB internal error)"
2152 gdb_internal_error_resync
2155 fail "${test} (pattern ${index} + sentinel) (timeout)"
2160 # unresolved "${test}, pattern ${index} + sentinel"
2166 # pass "${test}, pattern ${index}"
2169 fail "${test} (pattern ${index})"
2172 -re ".*A problem internal to GDB has been detected" {
2173 fail "${test} (GDB internal error)"
2175 gdb_internal_error_resync
2178 fail "${test} (pattern ${index}) (timeout)"
2183 # unresolved "${test}, pattern ${index}"
2197 proc gdb_suppress_entire_file { reason } {
2198 global suppress_flag;
2200 warning "$reason\n";
2201 set suppress_flag -1;
2205 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
2206 # gdb_expect to fail immediately (until the next call to
2207 # gdb_stop_suppressing_tests).
2209 proc gdb_suppress_tests { args } {
2210 global suppress_flag;
2212 return; # fnf - disable pending review of results where
2213 # testsuite ran better without this
2216 if { $suppress_flag == 1 } {
2217 if { [llength $args] > 0 } {
2218 warning "[lindex $args 0]\n";
2220 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
2226 # Clear suppress_flag.
2228 proc gdb_stop_suppressing_tests { } {
2229 global suppress_flag;
2231 if [info exists suppress_flag] {
2232 if { $suppress_flag > 0 } {
2233 set suppress_flag 0;
2234 clone_output "Tests restarted.\n";
2237 set suppress_flag 0;
2241 proc gdb_clear_suppressed { } {
2242 global suppress_flag;
2244 set suppress_flag 0;
2247 proc gdb_start { } {
2252 catch default_gdb_exit
2256 # gdb_load_cmd -- load a file into the debugger.
2257 # ARGS - additional args to load command.
2258 # return a -1 if anything goes wrong.
2260 proc gdb_load_cmd { args } {
2263 if [target_info exists gdb_load_timeout] {
2264 set loadtimeout [target_info gdb_load_timeout]
2266 set loadtimeout 1600
2268 send_gdb "load $args\n"
2269 verbose "Timeout is now $loadtimeout seconds" 2
2270 gdb_expect $loadtimeout {
2271 -re "Loading section\[^\r\]*\r\n" {
2274 -re "Start address\[\r\]*\r\n" {
2277 -re "Transfer rate\[\r\]*\r\n" {
2280 -re "Memory access error\[^\r\]*\r\n" {
2281 perror "Failed to load program"
2284 -re "$gdb_prompt $" {
2287 -re "(.*)\r\n$gdb_prompt " {
2288 perror "Unexpected reponse from 'load' -- $expect_out(1,string)"
2292 perror "Timed out trying to load $args."
2301 # Copy a file to the remote target and return its target filename.
2302 # Schedule the file to be deleted at the end of this test.
2304 proc gdb_download { filename } {
2307 set destname [remote_download target $filename]
2308 lappend cleanfiles $destname
2312 # gdb_load_shlibs LIB...
2314 # Copy the listed libraries to the target.
2316 proc gdb_load_shlibs { args } {
2317 if {![is_remote target]} {
2321 foreach file $args {
2325 # Even if the target supplies full paths for shared libraries,
2326 # they may not be paths for this system.
2327 gdb_test "set solib-search-path [file dirname [lindex $args 0]]" "" ""
2331 # gdb_load -- load a file into the debugger.
2332 # Many files in config/*.exp override this procedure.
2334 proc gdb_load { arg } {
2335 return [gdb_file_cmd $arg]
2338 # gdb_reload -- load a file into the target. Called before "running",
2339 # either the first time or after already starting the program once,
2340 # for remote targets. Most files that override gdb_load should now
2341 # override this instead.
2343 proc gdb_reload { } {
2344 # For the benefit of existing configurations, default to gdb_load.
2345 # Specifying no file defaults to the executable currently being
2347 return [gdb_load ""]
2350 proc gdb_continue { function } {
2353 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
2356 proc default_gdb_init { args } {
2357 global gdb_wrapper_initialized
2362 gdb_clear_suppressed;
2364 # Make sure that the wrapper is rebuilt
2365 # with the appropriate multilib option.
2366 set gdb_wrapper_initialized 0
2368 # Unlike most tests, we have a small number of tests that generate
2369 # a very large amount of output. We therefore increase the expect
2370 # buffer size to be able to contain the entire test output.
2372 # Also set this value for the currently running GDB.
2373 match_max [match_max -d]
2375 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
2376 if { [llength $args] > 0 } {
2379 set file [lindex $args 0];
2381 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
2384 if [target_info exists gdb_prompt] {
2385 set gdb_prompt [target_info gdb_prompt];
2387 set gdb_prompt "\\(gdb\\)"
2391 proc gdb_init { args } {
2392 return [eval default_gdb_init $args];
2395 proc gdb_finish { } {
2398 # Exit first, so that the files are no longer in use.
2401 if { [llength $cleanfiles] > 0 } {
2402 eval remote_file target delete $cleanfiles
2408 set debug_format "unknown"
2410 # Run the gdb command "info source" and extract the debugging format
2411 # information from the output and save it in debug_format.
2413 proc get_debug_format { } {
2419 set debug_format "unknown"
2420 send_gdb "info source\n"
2422 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
2423 set debug_format $expect_out(1,string)
2424 verbose "debug format is $debug_format"
2427 -re "No current source file.\r\n$gdb_prompt $" {
2428 perror "get_debug_format used when no current source file"
2431 -re "$gdb_prompt $" {
2432 warning "couldn't check debug format (no valid response)."
2436 warning "couldn't check debug format (timed out)."
2442 # Return true if FORMAT matches the debug format the current test was
2443 # compiled with. FORMAT is a shell-style globbing pattern; it can use
2444 # `*', `[...]', and so on.
2446 # This function depends on variables set by `get_debug_format', above.
2448 proc test_debug_format {format} {
2451 return [expr [string match $format $debug_format] != 0]
2454 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
2455 # COFF, stabs, etc). If that format matches the format that the
2456 # current test was compiled with, then the next test is expected to
2457 # fail for any target. Returns 1 if the next test or set of tests is
2458 # expected to fail, 0 otherwise (or if it is unknown). Must have
2459 # previously called get_debug_format.
2460 proc setup_xfail_format { format } {
2461 set ret [test_debug_format $format];
2469 proc gdb_step_for_stub { } {
2472 if ![target_info exists gdb,use_breakpoint_for_stub] {
2473 if [target_info exists gdb_stub_step_command] {
2474 set command [target_info gdb_stub_step_command];
2478 send_gdb "${command}\n";
2481 -re "(main.* at |.*in .*start).*$gdb_prompt" {
2484 -re ".*$gdb_prompt" {
2486 if { $tries == 5 } {
2487 fail "stepping out of breakpoint function";
2490 send_gdb "${command}\n";
2494 fail "stepping out of breakpoint function";
2501 -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" {
2502 set file $expect_out(1,string);
2503 set linenum [expr $expect_out(2,string) + 1];
2504 set breakplace "${file}:${linenum}";
2508 send_gdb "break ${breakplace}\n";
2510 -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" {
2511 set breakpoint $expect_out(1,string);
2513 -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" {
2514 set breakpoint $expect_out(1,string);
2518 send_gdb "continue\n";
2520 -re "Breakpoint ${breakpoint},.*$gdb_prompt" {
2521 gdb_test "delete $breakpoint" ".*" "";
2528 # gdb_get_line_number TEXT [FILE]
2530 # Search the source file FILE, and return the line number of the
2531 # first line containing TEXT. If no match is found, return -1.
2533 # TEXT is a string literal, not a regular expression.
2535 # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is
2536 # specified, and does not start with "/", then it is assumed to be in
2537 # "$srcdir/$subdir". This is awkward, and can be fixed in the future,
2538 # by changing the callers and the interface at the same time.
2539 # In particular: gdb.base/break.exp, gdb.base/condbreak.exp,
2540 # gdb.base/ena-dis-br.exp.
2542 # Use this function to keep your test scripts independent of the
2543 # exact line numbering of the source file. Don't write:
2545 # send_gdb "break 20"
2547 # This means that if anyone ever edits your test's source file,
2548 # your test could break. Instead, put a comment like this on the
2549 # source file line you want to break at:
2551 # /* breakpoint spot: frotz.exp: test name */
2553 # and then write, in your test script (which we assume is named
2556 # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
2558 # (Yes, Tcl knows how to handle the nested quotes and brackets.
2561 # % puts "foo [lindex "bar baz" 1]"
2564 # Tcl is quite clever, for a little stringy language.)
2568 # The previous implementation of this procedure used the gdb search command.
2569 # This version is different:
2571 # . It works with MI, and it also works when gdb is not running.
2573 # . It operates on the build machine, not the host machine.
2575 # . For now, this implementation fakes a current directory of
2576 # $srcdir/$subdir to be compatible with the old implementation.
2577 # This will go away eventually and some callers will need to
2580 # . The TEXT argument is literal text and matches literally,
2581 # not a regular expression as it was before.
2583 # . State changes in gdb, such as changing the current file
2584 # and setting $_, no longer happen.
2586 # After a bit of time we can forget about the differences from the
2587 # old implementation.
2589 # --chastain 2004-08-05
2591 proc gdb_get_line_number { text { file "" } } {
2596 if { "$file" == "" } then {
2599 if { ! [regexp "^/" "$file"] } then {
2600 set file "$srcdir/$subdir/$file"
2603 if { [ catch { set fd [open "$file"] } message ] } then {
2609 for { set line 1 } { 1 } { incr line } {
2610 if { [ catch { set nchar [gets "$fd" body] } message ] } then {
2614 if { $nchar < 0 } then {
2617 if { [string first "$text" "$body"] >= 0 } then {
2623 if { [ catch { close "$fd" } message ] } then {
2631 # gdb_continue_to_end:
2632 # The case where the target uses stubs has to be handled specially. If a
2633 # stub is used, we set a breakpoint at exit because we cannot rely on
2634 # exit() behavior of a remote target.
2636 # mssg is the error message that gets printed.
2638 proc gdb_continue_to_end {mssg} {
2639 if [target_info exists use_gdb_stub] {
2640 if {![gdb_breakpoint "exit"]} {
2643 gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \
2644 "continue until exit at $mssg"
2646 # Continue until we exit. Should not stop again.
2647 # Don't bother to check the output of the program, that may be
2648 # extremely tough for some remote systems.
2649 gdb_test "continue"\
2650 "Continuing.\[\r\n0-9\]+(... EXIT code 0\[\r\n\]+|Program exited normally\\.).*"\
2651 "continue until exit at $mssg"
2655 proc rerun_to_main {} {
2658 if [target_info exists use_gdb_stub] {
2661 -re ".*Breakpoint .*main .*$gdb_prompt $"\
2662 {pass "rerun to main" ; return 0}
2663 -re "$gdb_prompt $"\
2664 {fail "rerun to main" ; return 0}
2665 timeout {fail "(timeout) rerun to main" ; return 0}
2670 -re "The program .* has been started already.*y or n. $" {
2674 -re "Starting program.*$gdb_prompt $"\
2675 {pass "rerun to main" ; return 0}
2676 -re "$gdb_prompt $"\
2677 {fail "rerun to main" ; return 0}
2678 timeout {fail "(timeout) rerun to main" ; return 0}
2683 # Print a message and return true if a test should be skipped
2684 # due to lack of floating point suport.
2686 proc gdb_skip_float_test { msg } {
2687 if [target_info exists gdb,skip_float_tests] {
2688 verbose "Skipping test '$msg': no float tests.";
2694 # Print a message and return true if a test should be skipped
2695 # due to lack of stdio support.
2697 proc gdb_skip_stdio_test { msg } {
2698 if [target_info exists gdb,noinferiorio] {
2699 verbose "Skipping test '$msg': no inferior i/o.";
2705 proc gdb_skip_bogus_test { msg } {
2709 # Return true if a test should be skipped due to lack of XML support
2712 proc gdb_skip_xml_test { } {
2715 global xml_missing_cached
2717 if {[info exists xml_missing_cached]} {
2718 return $xml_missing_cached
2722 set xml_missing_cached 0
2723 gdb_test_multiple "set tdesc filename ${srcdir}/gdb.xml/trivial.xml" "" {
2724 -re ".*XML support was disabled at compile time.*$gdb_prompt $" {
2725 set xml_missing_cached 1
2727 -re ".*$gdb_prompt $" { }
2730 return $xml_missing_cached
2733 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
2734 # ${binfile}.dbglnk, which is just like the executable ($binfile) but without
2735 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
2736 # the name of a debuginfo only file. This file will be stored in the
2737 # gdb.base/.debug subdirectory.
2739 # Functions for separate debug info testing
2741 # starting with an executable:
2742 # foo --> original executable
2744 # at the end of the process we have:
2745 # foo.stripped --> foo w/o debug info
2746 # .debug/foo.debug --> foo's debug info
2747 # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug.
2749 # Return the name of the file in which we should stor EXEC's separated
2750 # debug info. EXEC contains the full path.
2751 proc separate_debug_filename { exec } {
2753 # In a .debug subdirectory off the same directory where the testcase
2754 # executable is going to be. Something like:
2755 # <your-path>/gdb/testsuite/gdb.base/.debug/blah.debug.
2756 # This is the default location where gdb expects to findi
2757 # the debug info file.
2759 set exec_dir [file dirname $exec]
2760 set exec_file [file tail $exec]
2761 set debug_dir [file join $exec_dir ".debug"]
2762 set debug_file [file join $debug_dir "${exec_file}.debug"]
2767 # Return the build-id hex string (usually 160 bits as 40 hex characters)
2768 # converted to the form: .build-id/ab/cdef1234...89.debug
2769 # Return "" if no build-id found.
2770 proc build_id_debug_filename_get { exec } {
2771 set tmp "${exec}-tmp"
2772 set objcopy_program [transform objcopy]
2774 set result [catch "exec $objcopy_program -j .note.gnu.build-id -O binary $exec $tmp" output]
2775 verbose "result is $result"
2776 verbose "output is $output"
2781 fconfigure $fi -translation binary
2782 # Skip the NOTE header.
2787 if ![string compare $data ""] then {
2790 # Convert it to hex.
2791 binary scan $data H* data
2792 set data [regsub {^..} $data {\0/}]
2793 return ".build-id/${data}.debug";
2796 # Create stripped files for DEST, replacing it. If ARGS is passed, it is a
2797 # list of optional flags. The only currently supported flag is no-main,
2798 # which removes the symbol entry for main from the separate debug file.
2800 proc gdb_gnu_strip_debug { dest args } {
2802 set debug_file [separate_debug_filename $dest]
2803 set strip_to_file_program [transform strip]
2804 set objcopy_program [transform objcopy]
2806 # Make sure the directory that will hold the separated debug
2807 # info actually exists.
2808 set debug_dir [file dirname $debug_file]
2809 if {! [file isdirectory $debug_dir]} {
2810 file mkdir $debug_dir
2813 set debug_link [file tail $debug_file]
2814 set stripped_file "${dest}.stripped"
2816 # Get rid of the debug info, and store result in stripped_file
2817 # something like gdb/testsuite/gdb.base/blah.stripped.
2818 set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
2819 verbose "result is $result"
2820 verbose "output is $output"
2825 # Get rid of everything but the debug info, and store result in debug_file
2826 # This will be in the .debug subdirectory, see above.
2827 set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
2828 verbose "result is $result"
2829 verbose "output is $output"
2834 # If no-main is passed, strip the symbol for main from the separate
2835 # file. This is to simulate the behavior of elfutils's eu-strip, which
2836 # leaves the symtab in the original file only. There's no way to get
2837 # objcopy or strip to remove the symbol table without also removing the
2838 # debugging sections, so this is as close as we can get.
2839 if { [llength $args] == 1 && [lindex $args 0] == "no-main" } {
2840 set result [catch "exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp" output]
2841 verbose "result is $result"
2842 verbose "output is $output"
2846 file delete "${debug_file}"
2847 file rename "${debug_file}-tmp" "${debug_file}"
2850 # Link the two previous output files together, adding the .gnu_debuglink
2851 # section to the stripped_file, containing a pointer to the debug_file,
2852 # save the new file in dest.
2853 # This will be the regular executable filename, in the usual location.
2854 set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
2855 verbose "result is $result"
2856 verbose "output is $output"
2864 # Test the output of GDB_COMMAND matches the pattern obtained
2865 # by concatenating all elements of EXPECTED_LINES. This makes
2866 # it possible to split otherwise very long string into pieces.
2867 # If third argument is not empty, it's used as the name of the
2868 # test to be printed on pass/fail.
2869 proc help_test_raw { gdb_command expected_lines args } {
2870 set message $gdb_command
2871 if [llength $args]>0 then {
2872 set message [lindex $args 0]
2874 set expected_output [join $expected_lines ""]
2875 gdb_test "${gdb_command}" "${expected_output}" $message
2878 # Test the output of "help COMMNAD_CLASS". EXPECTED_INITIAL_LINES
2879 # are regular expressions that should match the beginning of output,
2880 # before the list of commands in that class. The presence of
2881 # command list and standard epilogue will be tested automatically.
2882 proc test_class_help { command_class expected_initial_lines args } {
2884 "List of commands\:.*\[\r\n\]+"
2885 "Type \"help\" followed by command name for full documentation\.\[\r\n\]+"
2886 "Type \"apropos word\" to search for commands related to \"word\"\.[\r\n\]+"
2887 "Command name abbreviations are allowed if unambiguous\."
2889 set l_entire_body [concat $expected_initial_lines $l_stock_body]
2891 eval [list help_test_raw "help ${command_class}" $l_entire_body] $args
2894 # COMMAND_LIST should have either one element -- command to test, or
2895 # two elements -- abbreviated command to test, and full command the first
2896 # element is abbreviation of.
2897 # The command must be a prefix command. EXPECTED_INITIAL_LINES
2898 # are regular expressions that should match the beginning of output,
2899 # before the list of subcommands. The presence of
2900 # subcommand list and standard epilogue will be tested automatically.
2901 proc test_prefix_command_help { command_list expected_initial_lines args } {
2902 set command [lindex $command_list 0]
2903 if {[llength $command_list]>1} {
2904 set full_command [lindex $command_list 1]
2906 set full_command $command
2908 # Use 'list' and not just {} because we want variables to
2909 # be expanded in this list.
2910 set l_stock_body [list\
2911 "List of $full_command subcommands\:.*\[\r\n\]+"\
2912 "Type \"help $full_command\" followed by $full_command subcommand name for full documentation\.\[\r\n\]+"\
2913 "Type \"apropos word\" to search for commands related to \"word\"\.\[\r\n\]+"\
2914 "Command name abbreviations are allowed if unambiguous\."]
2915 set l_entire_body [concat $expected_initial_lines $l_stock_body]
2916 if {[llength $args]>0} {
2917 help_test_raw "help ${command}" $l_entire_body [lindex $args 0]
2919 help_test_raw "help ${command}" $l_entire_body
2923 # Build executable named EXECUTABLE, from SOURCES. If SOURCES are not
2924 # provided, uses $EXECUTABLE.c. The TESTNAME paramer is the name of test
2925 # to pass to untested, if something is wrong. OPTIONS are passed
2926 # to gdb_compile directly.
2927 proc build_executable { testname executable {sources ""} {options {debug}} } {
2932 if {[llength $sources]==0} {
2933 set sources ${executable}.c
2936 set binfile ${objdir}/${subdir}/${executable}
2939 for {set i 0} "\$i<[llength $sources]" {incr i} {
2940 set s [lindex $sources $i]
2941 if { [gdb_compile "${srcdir}/${subdir}/${s}" "${binfile}${i}.o" object $options] != "" } {
2945 lappend objects "${binfile}${i}.o"
2948 if { [gdb_compile $objects "${binfile}" executable $options] != "" } {
2953 if [get_compiler_info ${binfile}] {
2959 # Starts fresh GDB binary and loads EXECUTABLE into GDB. EXECUTABLE is
2960 # the name of binary in ${objdir}/${subdir}.
2961 proc clean_restart { executable } {
2965 set binfile ${objdir}/${subdir}/${executable}
2969 gdb_reinitialize_dir $srcdir/$subdir
2972 if [target_info exists gdb_stub] {
2977 # Prepares for testing, by calling build_executable, and then clean_restart.
2978 # Please refer to build_executable for parameter description.
2979 proc prepare_for_testing { testname executable {sources ""} {options {debug}}} {
2981 if {[build_executable $testname $executable $sources $options] == -1} {
2984 clean_restart $executable
2989 proc get_valueof { fmt exp default } {
2992 set test "get valueof \"${exp}\""
2994 gdb_test_multiple "print${fmt} ${exp}" "$test" {
2995 -re "\\$\[0-9\]* = (.*)\[\r\n\]*$gdb_prompt $" {
2996 set val $expect_out(1,string)
3000 fail "$test (timeout)"
3006 proc get_integer_valueof { exp default } {
3009 set test "get integer valueof \"${exp}\""
3011 gdb_test_multiple "print /d ${exp}" "$test" {
3012 -re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" {
3013 set val $expect_out(1,string)
3017 fail "$test (timeout)"
3023 proc get_hexadecimal_valueof { exp default } {
3025 send_gdb "print /x ${exp}\n"
3026 set test "get hexadecimal valueof \"${exp}\""
3028 -re "\\$\[0-9\]* = (0x\[0-9a-zA-Z\]+).*$gdb_prompt $" {
3029 set val $expect_out(1,string)
3034 fail "$test (timeout)"
3040 proc get_sizeof { type default } {
3041 return [get_integer_valueof "sizeof (${type})" $default]
3044 # Log gdb command line and script if requested.
3045 if {[info exists TRANSCRIPT]} {
3046 rename send_gdb real_send_gdb
3047 rename remote_spawn real_remote_spawn
3048 rename remote_close real_remote_close
3050 global gdb_transcript
3051 set gdb_transcript ""
3053 global gdb_trans_count
3054 set gdb_trans_count 1
3056 proc remote_spawn {args} {
3057 global gdb_transcript gdb_trans_count outdir
3059 if {$gdb_transcript != ""} {
3060 close $gdb_transcript
3062 set gdb_transcript [open [file join $outdir transcript.$gdb_trans_count] w]
3063 puts $gdb_transcript [lindex $args 1]
3064 incr gdb_trans_count
3066 return [uplevel real_remote_spawn $args]
3069 proc remote_close {args} {
3070 global gdb_transcript
3072 if {$gdb_transcript != ""} {
3073 close $gdb_transcript
3074 set gdb_transcript ""
3077 return [uplevel real_remote_close $args]
3080 proc send_gdb {args} {
3081 global gdb_transcript
3083 if {$gdb_transcript != ""} {
3084 puts -nonewline $gdb_transcript [lindex $args 0]
3087 return [uplevel real_send_gdb $args]