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 fileid [open "gdb_cmd" w];
110 set cmdfile [remote_download host "gdb_cmd"];
111 set output [remote_exec host "$GDB $INTERNAL_GDBFLAGS --command $cmdfile"]
112 remote_file build delete "gdb_cmd";
113 remote_file host delete "$cmdfile";
114 set tmp [lindex $output 1];
116 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
117 if ![is_remote host] {
118 clone_output "[which $GDB] version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
120 clone_output "$GDB on remote host version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
124 proc gdb_version { } {
125 return [default_gdb_version];
129 # gdb_unload -- unload a file if one is loaded
138 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
139 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
140 -re "A program is being debugged already..*Kill it.*y or n. $"\
142 verbose "\t\tKilling previous program being debugged"
145 -re "Discard symbol table from .*y or n.*$" {
149 -re "$gdb_prompt $" {}
151 perror "couldn't unload file in $GDB (timed out)."
157 # Many of the tests depend on setting breakpoints at various places and
158 # running until that breakpoint is reached. At times, we want to start
159 # with a clean-slate with respect to breakpoints, so this utility proc
160 # lets us do this without duplicating this code everywhere.
163 proc delete_breakpoints {} {
166 # we need a larger timeout value here or this thing just confuses
167 # itself. May need a better implementation if possible. - guo
169 send_gdb "delete breakpoints\n"
171 -re "Delete all breakpoints.*y or n.*$" {
175 -re "$gdb_prompt $" { # This happens if there were no breakpoints
177 timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
179 send_gdb "info breakpoints\n"
181 -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
182 -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
183 -re "Delete all breakpoints.*or n.*$" {
187 timeout { perror "info breakpoints (timeout)" ; return }
193 # Generic run command.
195 # The second pattern below matches up to the first newline *only*.
196 # Using ``.*$'' could swallow up output that we attempt to match
199 proc gdb_run_cmd {args} {
202 if [target_info exists gdb_init_command] {
203 send_gdb "[target_info gdb_init_command]\n";
205 -re "$gdb_prompt $" { }
207 perror "gdb_init_command for target failed";
213 if [target_info exists use_gdb_stub] {
214 if [target_info exists gdb,do_reload_on_run] {
215 if { [gdb_reload] != 0 } {
218 send_gdb "continue\n";
220 -re "Continu\[^\r\n\]*\[\r\n\]" {}
226 if [target_info exists gdb,start_symbol] {
227 set start [target_info gdb,start_symbol];
231 send_gdb "jump *$start\n"
233 while { $start_attempt } {
234 # Cap (re)start attempts at three to ensure that this loop
235 # always eventually fails. Don't worry about trying to be
236 # clever and not send a command when it has failed.
237 if [expr $start_attempt > 3] {
238 perror "Jump to start() failed (retry count exceeded)";
241 set start_attempt [expr $start_attempt + 1];
243 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
246 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
247 perror "Can't find start symbol to run in gdb_run";
250 -re "No symbol \"start\" in current.*$gdb_prompt $" {
251 send_gdb "jump *_start\n";
253 -re "No symbol.*context.*$gdb_prompt $" {
256 -re "Line.* Jump anyway.*y or n. $" {
259 -re "The program is not being run.*$gdb_prompt $" {
260 if { [gdb_reload] != 0 } {
263 send_gdb "jump *$start\n";
266 perror "Jump to start() failed (timeout)";
271 if [target_info exists gdb_stub] {
273 -re "$gdb_prompt $" {
274 send_gdb "continue\n"
281 if [target_info exists gdb,do_reload_on_run] {
282 if { [gdb_reload] != 0 } {
286 send_gdb "run $args\n"
287 # This doesn't work quite right yet.
288 # Use -notransfer here so that test cases (like chng-sym.exp)
289 # may test for additional start-up messages.
291 -re "The program .* has been started already.*y or n. $" {
295 -notransfer -re "Starting program: \[^\r\n\]*" {}
299 # Generic start command. Return 0 if we could start the program, -1
302 proc gdb_start_cmd {args} {
305 if [target_info exists gdb_init_command] {
306 send_gdb "[target_info gdb_init_command]\n";
308 -re "$gdb_prompt $" { }
310 perror "gdb_init_command for target failed";
316 if [target_info exists use_gdb_stub] {
320 send_gdb "start $args\n"
322 -re "The program .* has been started already.*y or n. $" {
326 # Use -notransfer here so that test cases (like chng-sym.exp)
327 # may test for additional start-up messages.
328 -notransfer -re "Starting program: \[^\r\n\]*" {
335 # Set a breakpoint at FUNCTION. If there is an additional argument it is
336 # a list of options; the supported options are allow-pending, temporary,
339 proc gdb_breakpoint { function args } {
343 set pending_response n
344 if {[lsearch -exact [lindex $args 0] allow-pending] != -1} {
345 set pending_response y
348 set break_command "break"
349 set break_message "Breakpoint"
350 if {[lsearch -exact [lindex $args 0] temporary] != -1} {
351 set break_command "tbreak"
352 set break_message "Temporary breakpoint"
356 if {[lsearch -exact [lindex $args 0] no-message] != -1} {
360 send_gdb "$break_command $function\n"
361 # The first two regexps are what we get with -g, the third is without -g.
363 -re "$break_message \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
364 -re "$break_message \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
365 -re "$break_message \[0-9\]* at .*$gdb_prompt $" {}
366 -re "$break_message \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" {
367 if {$pending_response == "n"} {
368 if { $no_message == 0 } {
369 fail "setting breakpoint at $function"
374 -re "Make breakpoint pending.*y or \\\[n\\\]. $" {
375 send_gdb "$pending_response\n"
378 -re "$gdb_prompt $" {
379 if { $no_message == 0 } {
380 fail "setting breakpoint at $function"
385 if { $no_message == 0 } {
386 fail "setting breakpoint at $function (timeout)"
394 # Set breakpoint at function and run gdb until it breaks there.
395 # Since this is the only breakpoint that will be set, if it stops
396 # at a breakpoint, we will assume it is the one we want. We can't
397 # just compare to "function" because it might be a fully qualified,
398 # single quoted C++ function specifier. If there's an additional argument,
399 # pass it to gdb_breakpoint.
401 proc runto { function args } {
407 if ![gdb_breakpoint $function [lindex $args 0]] {
413 # the "at foo.c:36" output we get with -g.
414 # the "in func" output we get without -g.
416 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
419 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
422 -re "$gdb_prompt $" {
423 fail "running to $function in runto"
427 fail "running to $function in runto (timeout)"
435 # runto_main -- ask gdb to run until we hit a breakpoint at main.
436 # The case where the target uses stubs has to be handled
437 # specially--if it uses stubs, assuming we hit
438 # breakpoint() and just step out of the function.
440 proc runto_main { } {
444 if ![target_info exists gdb_stub] {
456 ### Continue, and expect to hit a breakpoint.
457 ### Report a pass or fail, depending on whether it seems to have
458 ### worked. Use NAME as part of the test name; each call to
459 ### continue_to_breakpoint should use a NAME which is unique within
461 proc gdb_continue_to_breakpoint {name {location_pattern .*}} {
463 set full_name "continue to breakpoint: $name"
465 send_gdb "continue\n"
467 -re "Breakpoint .* (at|in) $location_pattern\r\n$gdb_prompt $" {
470 -re ".*$gdb_prompt $" {
474 fail "$full_name (timeout)"
480 # gdb_internal_error_resync:
482 # Answer the questions GDB asks after it reports an internal error
483 # until we get back to a GDB prompt. Decline to quit the debugging
484 # session, and decline to create a core file. Return non-zero if the
487 # This procedure just answers whatever questions come up until it sees
488 # a GDB prompt; it doesn't require you to have matched the input up to
489 # any specific point. However, it only answers questions it sees in
490 # the output itself, so if you've matched a question, you had better
491 # answer it yourself before calling this.
493 # You can use this function thus:
497 # -re ".*A problem internal to GDB has been detected" {
498 # gdb_internal_error_resync
503 proc gdb_internal_error_resync {} {
507 while {$count < 10} {
509 -re "Quit this debugging session\\? \\(y or n\\) $" {
513 -re "Create a core file of GDB\\? \\(y or n\\) $" {
517 -re "$gdb_prompt $" {
518 # We're resynchronized.
522 perror "Could not resync from internal error (timeout)"
527 perror "Could not resync from internal error (resync count exceeded)"
532 # gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS
533 # Send a command to gdb; test the result.
535 # COMMAND is the command to execute, send to GDB with send_gdb. If
536 # this is the null string no command is sent.
537 # MESSAGE is a message to be printed with the built-in failure patterns
538 # if one of them matches. If MESSAGE is empty COMMAND will be used.
539 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
540 # patterns. Pattern elements will be evaluated in the caller's
541 # context; action elements will be executed in the caller's context.
542 # Unlike patterns for gdb_test, these patterns should generally include
543 # the final newline and prompt.
546 # 1 if the test failed, according to a built-in failure pattern
547 # 0 if only user-supplied patterns matched
548 # -1 if there was an internal error.
550 # You can use this function thus:
552 # gdb_test_multiple "print foo" "test foo" {
553 # -re "expected output 1" {
556 # -re "expected output 2" {
561 # The standard patterns, such as "Program exited..." and "A problem
562 # ...", all being implicitly appended to that list.
564 proc gdb_test_multiple { command message user_code } {
568 upvar timeout timeout
569 upvar expect_out expect_out
571 if { $message == "" } {
575 # TCL/EXPECT WART ALERT
576 # Expect does something very strange when it receives a single braced
577 # argument. It splits it along word separators and performs substitutions.
578 # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
579 # evaluated as "\[ab\]". But that's not how TCL normally works; inside a
580 # double-quoted list item, "\[ab\]" is just a long way of representing
581 # "[ab]", because the backslashes will be removed by lindex.
583 # Unfortunately, there appears to be no easy way to duplicate the splitting
584 # that expect will do from within TCL. And many places make use of the
585 # "\[0-9\]" construct, so we need to support that; and some places make use
586 # of the "[func]" construct, so we need to support that too. In order to
587 # get this right we have to substitute quoted list elements differently
588 # from braced list elements.
590 # We do this roughly the same way that Expect does it. We have to use two
591 # lists, because if we leave unquoted newlines in the argument to uplevel
592 # they'll be treated as command separators, and if we escape newlines
593 # we mangle newlines inside of command blocks. This assumes that the
594 # input doesn't contain a pattern which contains actual embedded newlines
597 regsub -all {\n} ${user_code} { } subst_code
598 set subst_code [uplevel list $subst_code]
600 set processed_code ""
602 set expecting_action 0
603 foreach item $user_code subst_item $subst_code {
604 if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } {
605 lappend processed_code $item
608 if {$item == "-indices" || $item == "-re" || $item == "-ex"} {
609 lappend processed_code $item
612 if { $expecting_action } {
613 lappend processed_code "uplevel [list $item]"
614 set expecting_action 0
615 # Cosmetic, no effect on the list.
616 append processed_code "\n"
619 set expecting_action 1
620 lappend processed_code $subst_item
621 if {$patterns != ""} {
624 append patterns "\"$subst_item\""
627 # Also purely cosmetic.
628 regsub -all {\r} $patterns {\\r} patterns
629 regsub -all {\n} $patterns {\\n} patterns
632 send_user "Sending \"$command\" to gdb\n"
633 send_user "Looking to match \"$patterns\"\n"
634 send_user "Message is \"$message\"\n"
638 set string "${command}\n";
639 if { $command != "" } {
640 while { "$string" != "" } {
641 set foo [string first "\n" "$string"];
642 set len [string length "$string"];
643 if { $foo < [expr $len - 1] } {
644 set str [string range "$string" 0 $foo];
645 if { [send_gdb "$str"] != "" } {
646 global suppress_flag;
648 if { ! $suppress_flag } {
649 perror "Couldn't send $command to GDB.";
654 # since we're checking if each line of the multi-line
655 # command are 'accepted' by GDB here,
656 # we need to set -notransfer expect option so that
657 # command output is not lost for pattern matching
660 -notransfer -re "\[\r\n\]" { verbose "partial: match" 3 }
661 timeout { verbose "partial: timeout" 3 }
663 set string [string range "$string" [expr $foo + 1] end];
668 if { "$string" != "" } {
669 if { [send_gdb "$string"] != "" } {
670 global suppress_flag;
672 if { ! $suppress_flag } {
673 perror "Couldn't send $command to GDB.";
681 if [target_info exists gdb,timeout] {
682 set tmt [target_info gdb,timeout];
684 if [info exists timeout] {
688 if [info exists timeout] {
697 -re ".*A problem internal to GDB has been detected" {
698 fail "$message (GDB internal error)"
699 gdb_internal_error_resync
701 -re "\\*\\*\\* DOSEXIT code.*" {
702 if { $message != "" } {
705 gdb_suppress_entire_file "GDB died";
709 append code $processed_code
711 -re "Ending remote debugging.*$gdb_prompt $" {
712 if ![isnative] then {
713 warning "Can`t communicate to remote target."
719 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
720 perror "Undefined command \"$command\"."
724 -re "Ambiguous command.*$gdb_prompt $" {
725 perror "\"$command\" is not a unique command name."
729 -re "Program exited with code \[0-9\]+.*$gdb_prompt $" {
730 if ![string match "" $message] then {
731 set errmsg "$message (the program exited)"
733 set errmsg "$command (the program exited)"
738 -re "EXIT code \[0-9\r\n\]+Program exited normally.*$gdb_prompt $" {
739 if ![string match "" $message] then {
740 set errmsg "$message (the program exited)"
742 set errmsg "$command (the program exited)"
747 -re "The program is not being run.*$gdb_prompt $" {
748 if ![string match "" $message] then {
749 set errmsg "$message (the program is no longer running)"
751 set errmsg "$command (the program is no longer running)"
756 -re "\r\n$gdb_prompt $" {
757 if ![string match "" $message] then {
764 perror "Window too small."
768 -re "\\(y or n\\) " {
770 perror "Got interactive prompt."
775 perror "Process no longer exists"
776 if { $message != "" } {
782 perror "internal buffer is full."
787 if ![string match "" $message] then {
788 fail "$message (timeout)"
795 set code [catch {gdb_expect $tmt $code} string]
797 global errorInfo errorCode;
798 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
799 } elseif {$code == 2} {
800 return -code return $string
801 } elseif {$code == 3} {
803 } elseif {$code > 4} {
804 return -code $code $string
809 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
810 # Send a command to gdb; test the result.
812 # COMMAND is the command to execute, send to GDB with send_gdb. If
813 # this is the null string no command is sent.
814 # PATTERN is the pattern to match for a PASS, and must NOT include
815 # the \r\n sequence immediately before the gdb prompt.
816 # MESSAGE is an optional message to be printed. If this is
817 # omitted, then the pass/fail messages use the command string as the
818 # message. (If this is the empty string, then sometimes we don't
819 # call pass or fail at all; I don't understand this at all.)
820 # QUESTION is a question GDB may ask in response to COMMAND, like
822 # RESPONSE is the response to send if QUESTION appears.
825 # 1 if the test failed,
826 # 0 if the test passes,
827 # -1 if there was an internal error.
829 proc gdb_test { args } {
833 upvar timeout timeout
835 if [llength $args]>2 then {
836 set message [lindex $args 2]
838 set message [lindex $args 0]
840 set command [lindex $args 0]
841 set pattern [lindex $args 1]
843 if [llength $args]==5 {
844 set question_string [lindex $args 3];
845 set response_string [lindex $args 4];
847 set question_string "^FOOBAR$"
850 return [gdb_test_multiple $command $message {
851 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
852 if ![string match "" $message] then {
856 -re "(${question_string})$" {
857 send_gdb "$response_string\n";
863 # Test that a command gives an error. For pass or fail, return
864 # a 1 to indicate that more tests can proceed. However a timeout
865 # is a serious error, generates a special fail message, and causes
866 # a 0 to be returned to indicate that more tests are likely to fail
869 proc test_print_reject { args } {
873 if [llength $args]==2 then {
874 set expectthis [lindex $args 1]
876 set expectthis "should never match this bogus string"
878 set sendthis [lindex $args 0]
880 send_user "Sending \"$sendthis\" to gdb\n"
881 send_user "Looking to match \"$expectthis\"\n"
883 send_gdb "$sendthis\n"
884 #FIXME: Should add timeout as parameter.
886 -re "A .* in expression.*\\.*$gdb_prompt $" {
887 pass "reject $sendthis"
890 -re "Invalid syntax in expression.*$gdb_prompt $" {
891 pass "reject $sendthis"
894 -re "Junk after end of expression.*$gdb_prompt $" {
895 pass "reject $sendthis"
898 -re "Invalid number.*$gdb_prompt $" {
899 pass "reject $sendthis"
902 -re "Invalid character constant.*$gdb_prompt $" {
903 pass "reject $sendthis"
906 -re "No symbol table is loaded.*$gdb_prompt $" {
907 pass "reject $sendthis"
910 -re "No symbol .* in current context.*$gdb_prompt $" {
911 pass "reject $sendthis"
914 -re "Unmatched single quote.*$gdb_prompt $" {
915 pass "reject $sendthis"
918 -re "A character constant must contain at least one character.*$gdb_prompt $" {
919 pass "reject $sendthis"
922 -re "$expectthis.*$gdb_prompt $" {
923 pass "reject $sendthis"
926 -re ".*$gdb_prompt $" {
927 fail "reject $sendthis"
931 fail "reject $sendthis (eof or timeout)"
937 # Given an input string, adds backslashes as needed to create a
938 # regexp that will match the string.
940 proc string_to_regexp {str} {
942 regsub -all {[]*+.|()^$\[\\]} $str {\\&} result
946 # Same as gdb_test, but the second parameter is not a regexp,
947 # but a string that must match exactly.
949 proc gdb_test_exact { args } {
950 upvar timeout timeout
952 set command [lindex $args 0]
954 # This applies a special meaning to a null string pattern. Without
955 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
956 # messages from commands that should have no output except a new
957 # prompt. With this, only results of a null string will match a null
960 set pattern [lindex $args 1]
961 if [string match $pattern ""] {
962 set pattern [string_to_regexp [lindex $args 0]]
964 set pattern [string_to_regexp [lindex $args 1]]
967 # It is most natural to write the pattern argument with only
968 # embedded \n's, especially if you are trying to avoid Tcl quoting
969 # problems. But gdb_expect really wants to see \r\n in patterns. So
970 # transform the pattern here. First transform \r\n back to \n, in
971 # case some users of gdb_test_exact already do the right thing.
972 regsub -all "\r\n" $pattern "\n" pattern
973 regsub -all "\n" $pattern "\r\n" pattern
974 if [llength $args]==3 then {
975 set message [lindex $args 2]
980 return [gdb_test $command $pattern $message]
983 proc gdb_reinitialize_dir { subdir } {
986 if [is_remote host] {
991 -re "Reinitialize source path to empty.*y or n. " {
994 -re "Source directories searched.*$gdb_prompt $" {
995 send_gdb "dir $subdir\n"
997 -re "Source directories searched.*$gdb_prompt $" {
998 verbose "Dir set to $subdir"
1000 -re "$gdb_prompt $" {
1001 perror "Dir \"$subdir\" failed."
1005 -re "$gdb_prompt $" {
1006 perror "Dir \"$subdir\" failed."
1010 -re "$gdb_prompt $" {
1011 perror "Dir \"$subdir\" failed."
1017 # gdb_exit -- exit the GDB, killing the target program if necessary
1019 proc default_gdb_exit {} {
1021 global INTERNAL_GDBFLAGS GDBFLAGS
1023 global gdb_spawn_id;
1025 gdb_stop_suppressing_tests;
1027 if ![info exists gdb_spawn_id] {
1031 verbose "Quitting $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1033 if { [is_remote host] && [board_info host exists fileid] } {
1040 -re "DOSEXIT code" { }
1045 if ![is_remote host] {
1051 # Load a file into the debugger.
1052 # The return value is 0 for success, -1 for failure.
1054 # This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO
1055 # to one of these values:
1057 # debug file was loaded successfully and has debug information
1058 # nodebug file was loaded successfully and has no debug information
1059 # fail file was not loaded
1061 # I tried returning this information as part of the return value,
1062 # but ran into a mess because of the many re-implementations of
1063 # gdb_load in config/*.exp.
1065 # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use
1066 # this if they can get more information set.
1068 proc gdb_file_cmd { arg } {
1072 global last_loaded_file
1074 set last_loaded_file $arg
1076 # Set whether debug info was found.
1077 # Default to "fail".
1078 global gdb_file_cmd_debug_info
1079 set gdb_file_cmd_debug_info "fail"
1081 if [is_remote host] {
1082 set arg [remote_download host $arg]
1084 perror "download failed"
1089 # The file command used to kill the remote target. For the benefit
1090 # of the testsuite, preserve this behavior.
1093 -re "Kill the program being debugged. .y or n. $" {
1095 verbose "\t\tKilling previous program being debugged"
1098 -re "$gdb_prompt $" {
1103 send_gdb "file $arg\n"
1105 -re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" {
1106 verbose "\t\tLoaded $arg into the $GDB with no debugging symbols"
1107 set gdb_file_cmd_debug_info "nodebug"
1110 -re "Reading symbols from.*done.*$gdb_prompt $" {
1111 verbose "\t\tLoaded $arg into the $GDB"
1112 set gdb_file_cmd_debug_info "debug"
1115 -re "Load new symbol table from \".*\".*y or n. $" {
1118 -re "Reading symbols from.*done.*$gdb_prompt $" {
1119 verbose "\t\tLoaded $arg with new symbol table into $GDB"
1120 set gdb_file_cmd_debug_info "debug"
1124 perror "(timeout) Couldn't load $arg, other program already loaded."
1129 -re "No such file or directory.*$gdb_prompt $" {
1130 perror "($arg) No such file or directory"
1133 -re "$gdb_prompt $" {
1134 perror "couldn't load $arg into $GDB."
1138 perror "couldn't load $arg into $GDB (timed out)."
1142 # This is an attempt to detect a core dump, but seems not to
1143 # work. Perhaps we need to match .* followed by eof, in which
1144 # gdb_expect does not seem to have a way to do that.
1145 perror "couldn't load $arg into $GDB (end of file)."
1152 # start gdb -- start gdb running, default procedure
1154 # When running over NFS, particularly if running many simultaneous
1155 # tests on different hosts all using the same server, things can
1156 # get really slow. Give gdb at least 3 minutes to start up.
1158 proc default_gdb_start { } {
1161 global INTERNAL_GDBFLAGS GDBFLAGS
1164 global gdb_spawn_id;
1166 gdb_stop_suppressing_tests;
1168 verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1170 if [info exists gdb_spawn_id] {
1174 if ![is_remote host] {
1175 if { [which $GDB] == 0 } then {
1176 perror "$GDB does not exist."
1180 set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"];
1181 if { $res < 0 || $res == "" } {
1182 perror "Spawning $GDB failed."
1186 -re "\[\r\n\]$gdb_prompt $" {
1187 verbose "GDB initialized."
1189 -re "$gdb_prompt $" {
1190 perror "GDB never initialized."
1194 perror "(timeout) GDB never initialized after 10 seconds."
1199 set gdb_spawn_id -1;
1200 # force the height to "unlimited", so no pagers get used
1202 send_gdb "set height 0\n"
1204 -re "$gdb_prompt $" {
1205 verbose "Setting height to 0." 2
1208 warning "Couldn't set the height to 0"
1211 # force the width to "unlimited", so no wraparound occurs
1212 send_gdb "set width 0\n"
1214 -re "$gdb_prompt $" {
1215 verbose "Setting width to 0." 2
1218 warning "Couldn't set the width to 0."
1224 # Return a 1 for configurations for which we don't even want to try to
1227 proc skip_cplus_tests {} {
1228 if { [istarget "h8300-*-*"] } {
1232 # The C++ IO streams are too large for HC11/HC12 and are thus not
1233 # available. The gdb C++ tests use them and don't compile.
1234 if { [istarget "m6811-*-*"] } {
1237 if { [istarget "m6812-*-*"] } {
1243 # Return a 1 if I don't even want to try to test FORTRAN.
1245 proc skip_fortran_tests {} {
1249 # Return a 1 if we should skip shared library tests.
1251 proc skip_shlib_tests {} {
1252 # Run the shared library tests on native systems.
1257 # An abbreviated list of remote targets where we should be able to
1258 # run shared library tests.
1259 if {([istarget *-*-linux*]
1260 || [istarget *-*-*bsd*]
1261 || [istarget *-*-solaris2*]
1262 || [istarget arm*-*-symbianelf*]
1263 || [istarget *-*-mingw*]
1264 || [istarget *-*-cygwin*]
1265 || [istarget *-*-pe*])} {
1272 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
1273 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
1275 proc skip_altivec_tests {} {
1276 global skip_vmx_tests_saved
1277 global srcdir subdir gdb_prompt
1279 # Use the cached value, if it exists.
1280 set me "skip_altivec_tests"
1281 if [info exists skip_vmx_tests_saved] {
1282 verbose "$me: returning saved $skip_vmx_tests_saved" 2
1283 return $skip_vmx_tests_saved
1286 # Some simulators are known to not support VMX instructions.
1287 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1288 verbose "$me: target known to not support VMX, returning 1" 2
1289 return [set skip_vmx_tests_saved 1]
1292 # Make sure we have a compiler that understands altivec.
1293 set compile_flags {debug nowarnings}
1294 if [get_compiler_info not-used] {
1295 warning "Could not get compiler info"
1298 if [test_compiler_info gcc*] {
1299 set compile_flags "$compile_flags additional_flags=-maltivec"
1300 } elseif [test_compiler_info xlc*] {
1301 set compile_flags "$compile_flags additional_flags=-qaltivec"
1303 verbose "Could not compile with altivec support, returning 1" 2
1307 # Set up, compile, and execute a test program containing VMX instructions.
1308 # Include the current process ID in the file names to prevent conflicts
1309 # with invocations for multiple testsuites.
1313 set f [open $src "w"]
1314 puts $f "int main() {"
1315 puts $f "#ifdef __MACH__"
1316 puts $f " asm volatile (\"vor v0,v0,v0\");"
1318 puts $f " asm volatile (\"vor 0,0,0\");"
1320 puts $f " return 0; }"
1323 verbose "$me: compiling testfile $src" 2
1324 set lines [gdb_compile $src $exe executable $compile_flags]
1327 if ![string match "" $lines] then {
1328 verbose "$me: testfile compilation failed, returning 1" 2
1329 return [set skip_vmx_tests_saved 1]
1332 # No error message, compilation succeeded so now run it via gdb.
1336 gdb_reinitialize_dir $srcdir/$subdir
1340 -re ".*Illegal instruction.*${gdb_prompt} $" {
1341 verbose -log "\n$me altivec hardware not detected"
1342 set skip_vmx_tests_saved 1
1344 -re ".*Program exited normally.*${gdb_prompt} $" {
1345 verbose -log "\n$me: altivec hardware detected"
1346 set skip_vmx_tests_saved 0
1349 warning "\n$me: default case taken"
1350 set skip_vmx_tests_saved 1
1354 remote_file build delete $exe
1356 verbose "$me: returning $skip_vmx_tests_saved" 2
1357 return $skip_vmx_tests_saved
1360 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
1361 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
1363 proc skip_vsx_tests {} {
1364 global skip_vsx_tests_saved
1365 global srcdir subdir gdb_prompt
1367 # Use the cached value, if it exists.
1368 set me "skip_vsx_tests"
1369 if [info exists skip_vsx_tests_saved] {
1370 verbose "$me: returning saved $skip_vsx_tests_saved" 2
1371 return $skip_vsx_tests_saved
1374 # Some simulators are known to not support Altivec instructions, so
1375 # they won't support VSX instructions as well.
1376 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1377 verbose "$me: target known to not support VSX, returning 1" 2
1378 return [set skip_vsx_tests_saved 1]
1381 # Make sure we have a compiler that understands altivec.
1382 set compile_flags {debug nowarnings quiet}
1383 if [get_compiler_info not-used] {
1384 warning "Could not get compiler info"
1387 if [test_compiler_info gcc*] {
1388 set compile_flags "$compile_flags additional_flags=-mvsx"
1389 } elseif [test_compiler_info xlc*] {
1390 set compile_flags "$compile_flags additional_flags=-qvsx"
1392 verbose "Could not compile with vsx support, returning 1" 2
1399 set f [open $src "w"]
1400 puts $f "int main() {"
1401 puts $f "#ifdef __MACH__"
1402 puts $f " asm volatile (\"lxvd2x v0,v0,v0\");"
1404 puts $f " asm volatile (\"lxvd2x 0,0,0\");"
1406 puts $f " return 0; }"
1409 verbose "$me: compiling testfile $src" 2
1410 set lines [gdb_compile $src $exe executable $compile_flags]
1413 if ![string match "" $lines] then {
1414 verbose "$me: testfile compilation failed, returning 1" 2
1415 return [set skip_vsx_tests_saved 1]
1418 # No error message, compilation succeeded so now run it via gdb.
1422 gdb_reinitialize_dir $srcdir/$subdir
1426 -re ".*Illegal instruction.*${gdb_prompt} $" {
1427 verbose -log "\n$me VSX hardware not detected"
1428 set skip_vsx_tests_saved 1
1430 -re ".*Program exited normally.*${gdb_prompt} $" {
1431 verbose -log "\n$me: VSX hardware detected"
1432 set skip_vsx_tests_saved 0
1435 warning "\n$me: default case taken"
1436 set skip_vsx_tests_saved 1
1440 remote_file build delete $exe
1442 verbose "$me: returning $skip_vsx_tests_saved" 2
1443 return $skip_vsx_tests_saved
1446 # Skip all the tests in the file if you are not on an hppa running
1449 proc skip_hp_tests {} {
1450 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
1451 verbose "Skip hp tests is $skip_hp"
1455 set compiler_info "unknown"
1457 set hp_cc_compiler 0
1458 set hp_aCC_compiler 0
1460 # Figure out what compiler I am using.
1462 # BINFILE is a "compiler information" output file. This implementation
1463 # does not use BINFILE.
1465 # ARGS can be empty or "C++". If empty, "C" is assumed.
1467 # There are several ways to do this, with various problems.
1469 # [ gdb_compile -E $ifile -o $binfile.ci ]
1470 # source $binfile.ci
1472 # Single Unix Spec v3 says that "-E -o ..." together are not
1473 # specified. And in fact, the native compiler on hp-ux 11 (among
1474 # others) does not work with "-E -o ...". Most targets used to do
1475 # this, and it mostly worked, because it works with gcc.
1477 # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ]
1478 # source $binfile.ci
1480 # This avoids the problem with -E and -o together. This almost works
1481 # if the build machine is the same as the host machine, which is
1482 # usually true of the targets which are not gcc. But this code does
1483 # not figure which compiler to call, and it always ends up using the C
1484 # compiler. Not good for setting hp_aCC_compiler. Targets
1485 # hppa*-*-hpux* and mips*-*-irix* used to do this.
1487 # [ gdb_compile -E $ifile > $binfile.ci ]
1488 # source $binfile.ci
1490 # dejagnu target_compile says that it supports output redirection,
1491 # but the code is completely different from the normal path and I
1492 # don't want to sweep the mines from that path. So I didn't even try
1495 # set cppout [ gdb_compile $ifile "" preprocess $args quiet ]
1498 # I actually do this for all targets now. gdb_compile runs the right
1499 # compiler, and TCL captures the output, and I eval the output.
1501 # Unfortunately, expect logs the output of the command as it goes by,
1502 # and dejagnu helpfully prints a second copy of it right afterwards.
1503 # So I turn off expect logging for a moment.
1505 # [ gdb_compile $ifile $ciexe_file executable $args ]
1506 # [ remote_exec $ciexe_file ]
1507 # [ source $ci_file.out ]
1509 # I could give up on -E and just do this.
1510 # I didn't get desperate enough to try this.
1512 # -- chastain 2004-01-06
1514 proc get_compiler_info {binfile args} {
1515 # For compiler.c and compiler.cc
1518 # I am going to play with the log to keep noise out.
1522 # These come from compiler.c or compiler.cc
1523 global compiler_info
1525 # Legacy global data symbols.
1527 global hp_cc_compiler
1528 global hp_aCC_compiler
1530 # Choose which file to preprocess.
1531 set ifile "${srcdir}/lib/compiler.c"
1532 if { [llength $args] > 0 && [lindex $args 0] == "c++" } {
1533 set ifile "${srcdir}/lib/compiler.cc"
1536 # Run $ifile through the right preprocessor.
1537 # Toggle gdb.log to keep the compiler output out of the log.
1539 set cppout [ gdb_compile "${ifile}" "" preprocess [list "$args" quiet] ]
1540 log_file -a "$outdir/$tool.log"
1544 foreach cppline [ split "$cppout" "\n" ] {
1545 if { [ regexp "^#" "$cppline" ] } {
1547 } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } {
1549 } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } {
1551 verbose "get_compiler_info: $cppline" 2
1555 verbose -log "get_compiler_info: $cppline"
1560 # Reset to unknown compiler if any diagnostics happened.
1562 set compiler_info "unknown"
1565 # Set the legacy symbols.
1567 set hp_cc_compiler 0
1568 set hp_aCC_compiler 0
1569 if { [regexp "^gcc-1-" "$compiler_info" ] } { set gcc_compiled 1 }
1570 if { [regexp "^gcc-2-" "$compiler_info" ] } { set gcc_compiled 2 }
1571 if { [regexp "^gcc-3-" "$compiler_info" ] } { set gcc_compiled 3 }
1572 if { [regexp "^gcc-4-" "$compiler_info" ] } { set gcc_compiled 4 }
1573 if { [regexp "^gcc-5-" "$compiler_info" ] } { set gcc_compiled 5 }
1574 if { [regexp "^hpcc-" "$compiler_info" ] } { set hp_cc_compiler 1 }
1575 if { [regexp "^hpacc-" "$compiler_info" ] } { set hp_aCC_compiler 1 }
1577 # Log what happened.
1578 verbose -log "get_compiler_info: $compiler_info"
1580 # Most compilers will evaluate comparisons and other boolean
1581 # operations to 0 or 1.
1582 uplevel \#0 { set true 1 }
1583 uplevel \#0 { set false 0 }
1585 # Use of aCC results in boolean results being displayed as
1587 if { $hp_aCC_compiler } {
1588 uplevel \#0 { set true true }
1589 uplevel \#0 { set false false }
1595 proc test_compiler_info { {compiler ""} } {
1596 global compiler_info
1598 # if no arg, return the compiler_info string
1600 if [string match "" $compiler] {
1601 if [info exists compiler_info] {
1602 return $compiler_info
1604 perror "No compiler info found."
1608 return [string match $compiler $compiler_info]
1611 set gdb_wrapper_initialized 0
1613 proc gdb_wrapper_init { args } {
1614 global gdb_wrapper_initialized;
1615 global gdb_wrapper_file;
1616 global gdb_wrapper_flags;
1618 if { $gdb_wrapper_initialized == 1 } { return; }
1620 if {[target_info exists needs_status_wrapper] && \
1621 [target_info needs_status_wrapper] != "0"} {
1622 set result [build_wrapper "testglue.o"];
1623 if { $result != "" } {
1624 set gdb_wrapper_file [lindex $result 0];
1625 set gdb_wrapper_flags [lindex $result 1];
1627 warning "Status wrapper failed to build."
1630 set gdb_wrapper_initialized 1
1633 # Some targets need to always link a special object in. Save its path here.
1634 global gdb_saved_set_unbuffered_mode_obj
1635 set gdb_saved_set_unbuffered_mode_obj ""
1637 proc gdb_compile {source dest type options} {
1638 global GDB_TESTCASE_OPTIONS;
1639 global gdb_wrapper_file;
1640 global gdb_wrapper_flags;
1641 global gdb_wrapper_initialized;
1644 global gdb_saved_set_unbuffered_mode_obj
1646 set outdir [file dirname $dest]
1648 # Add platform-specific options if a shared library was specified using
1649 # "shlib=librarypath" in OPTIONS.
1652 foreach opt $options {
1653 if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] {
1654 if [test_compiler_info "xlc-*"] {
1655 # IBM xlc compiler doesn't accept shared library named other
1656 # than .so: use "-Wl," to bypass this
1657 lappend source "-Wl,$shlib_name"
1658 } elseif { ([istarget "*-*-mingw*"]
1659 || [istarget *-*-cygwin*]
1660 || [istarget *-*-pe*])} {
1661 lappend source "${shlib_name}.a"
1663 lappend source $shlib_name
1665 if {$shlib_found == 0} {
1667 if { ([test_compiler_info "gcc-*"]
1668 && ([istarget "powerpc*-*-aix*"]
1669 || [istarget "rs6000*-*-aix*"] )) } {
1670 lappend options "additional_flags=-L${outdir}"
1671 } elseif { [istarget "mips-sgi-irix*"] } {
1672 lappend options "additional_flags=-rpath ${outdir}"
1675 } elseif { $opt == "shlib_load" } {
1676 if { ([istarget "*-*-mingw*"]
1677 || [istarget *-*-cygwin*]
1678 || [istarget *-*-pe*]
1679 || [istarget arm*-*-symbianelf*]
1680 || [istarget hppa*-*-hpux*])} {
1681 # Do not need anything.
1682 } elseif { [istarget *-*-openbsd*] } {
1683 lappend new_options "additional_flags=-Wl,-rpath,${outdir}"
1685 lappend new_options "libs=-ldl"
1686 lappend new_options "additional_flags=-Wl,-rpath,\\\$ORIGIN"
1689 lappend new_options $opt
1692 set options $new_options
1694 if [target_info exists gdb_stub] {
1695 set options2 { "additional_flags=-Dusestubs" }
1696 lappend options "libs=[target_info gdb_stub]";
1697 set options [concat $options2 $options]
1699 if [target_info exists is_vxworks] {
1700 set options2 { "additional_flags=-Dvxworks" }
1701 lappend options "libs=[target_info gdb_stub]";
1702 set options [concat $options2 $options]
1704 if [info exists GDB_TESTCASE_OPTIONS] {
1705 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
1707 verbose "options are $options"
1708 verbose "source is $source $dest $type $options"
1710 if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init }
1712 if {[target_info exists needs_status_wrapper] && \
1713 [target_info needs_status_wrapper] != "0" && \
1714 [info exists gdb_wrapper_file]} {
1715 lappend options "libs=${gdb_wrapper_file}"
1716 lappend options "ldflags=${gdb_wrapper_flags}"
1719 # Replace the "nowarnings" option with the appropriate additional_flags
1720 # to disable compiler warnings.
1721 set nowarnings [lsearch -exact $options nowarnings]
1722 if {$nowarnings != -1} {
1723 if [target_info exists gdb,nowarnings_flag] {
1724 set flag "additional_flags=[target_info gdb,nowarnings_flag]"
1726 set flag "additional_flags=-w"
1728 set options [lreplace $options $nowarnings $nowarnings $flag]
1731 if { $type == "executable" } {
1732 if { ([istarget "*-*-mingw*"]
1733 || [istarget "*-*-cygwin*"])} {
1734 # Force output to unbuffered mode, by linking in an object file
1735 # with a global contructor that calls setvbuf.
1737 # Compile the special object seperatelly for two reasons:
1738 # 1) Insulate it from $options.
1739 # 2) Avoid compiling it for every gdb_compile invocation,
1740 # which is time consuming, especially if we're remote
1743 if { $gdb_saved_set_unbuffered_mode_obj == "" } {
1744 verbose "compiling gdb_saved_set_unbuffered_obj"
1745 set unbuf_src ${srcdir}/lib/set_unbuffered_mode.c
1746 set unbuf_obj ${objdir}/set_unbuffered_mode.o
1748 set result [gdb_compile "${unbuf_src}" "${unbuf_obj}" object {nowarnings}]
1749 if { $result != "" } {
1753 set gdb_saved_set_unbuffered_mode_obj ${objdir}/set_unbuffered_mode_saved.o
1754 # Link a copy of the output object, because the
1755 # original may be automatically deleted.
1756 remote_exec host "cp -f $unbuf_obj $gdb_saved_set_unbuffered_mode_obj"
1758 verbose "gdb_saved_set_unbuffered_obj already compiled"
1761 # Rely on the internal knowledge that the global ctors are ran in
1762 # reverse link order. In that case, we can use ldflags to
1763 # avoid copying the object file to the host multiple
1765 lappend options "ldflags=$gdb_saved_set_unbuffered_mode_obj"
1769 set result [target_compile $source $dest $type $options];
1771 # Prune uninteresting compiler (and linker) output.
1772 regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result
1774 regsub "\[\r\n\]*$" "$result" "" result;
1775 regsub "^\[\r\n\]*" "$result" "" result;
1777 if { $result != "" && [lsearch $options quiet] == -1} {
1778 clone_output "gdb compile failed, $result"
1784 # This is just like gdb_compile, above, except that it tries compiling
1785 # against several different thread libraries, to see which one this
1787 proc gdb_compile_pthreads {source dest type options} {
1789 set why_msg "unrecognized error"
1790 foreach lib {-lpthreads -lpthread -lthread} {
1791 # This kind of wipes out whatever libs the caller may have
1792 # set. Or maybe theirs will override ours. How infelicitous.
1793 set options_with_lib [concat $options [list libs=$lib quiet]]
1794 set ccout [gdb_compile $source $dest $type $options_with_lib]
1795 switch -regexp -- $ccout {
1796 ".*no posix threads support.*" {
1797 set why_msg "missing threads include file"
1800 ".*cannot open -lpthread.*" {
1801 set why_msg "missing runtime threads library"
1803 ".*Can't find library for -lpthread.*" {
1804 set why_msg "missing runtime threads library"
1807 pass "successfully compiled posix threads test case"
1813 if {!$built_binfile} {
1814 unsupported "Couldn't compile $source: ${why_msg}"
1819 # Build a shared library from SOURCES. You must use get_compiler_info
1822 proc gdb_compile_shlib {sources dest options} {
1823 set obj_options $options
1825 switch -glob [test_compiler_info] {
1827 lappend obj_options "additional_flags=-qpic"
1830 if { !([istarget "powerpc*-*-aix*"]
1831 || [istarget "rs6000*-*-aix*"]
1832 || [istarget "*-*-cygwin*"]
1833 || [istarget "*-*-mingw*"]
1834 || [istarget "*-*-pe*"]) } {
1835 lappend obj_options "additional_flags=-fpic"
1839 switch -glob [istarget] {
1841 lappend obj_options "additional_flags=+z"
1844 # Disable SGI compiler's implicit -Dsgi
1845 lappend obj_options "additional_flags=-Usgi"
1848 # don't know what the compiler is...
1854 set outdir [file dirname $dest]
1856 foreach source $sources {
1857 set sourcebase [file tail $source]
1858 if {[gdb_compile $source "${outdir}/${sourcebase}.o" object $obj_options] != ""} {
1861 lappend objects ${outdir}/${sourcebase}.o
1864 if [istarget "hppa*-*-hpux*"] {
1865 remote_exec build "ld -b ${objects} -o ${dest}"
1867 set link_options $options
1868 if [test_compiler_info "xlc-*"] {
1869 lappend link_options "additional_flags=-qmkshrobj"
1871 lappend link_options "additional_flags=-shared"
1873 if { ([istarget "*-*-mingw*"]
1874 || [istarget *-*-cygwin*]
1875 || [istarget *-*-pe*])} {
1876 lappend link_options "additional_flags=-Wl,--out-implib,${dest}.a"
1879 if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
1885 # This is just like gdb_compile_pthreads, above, except that we always add the
1886 # objc library for compiling Objective-C programs
1887 proc gdb_compile_objc {source dest type options} {
1889 set why_msg "unrecognized error"
1890 foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} {
1891 # This kind of wipes out whatever libs the caller may have
1892 # set. Or maybe theirs will override ours. How infelicitous.
1893 if { $lib == "solaris" } {
1894 set lib "-lpthread -lposix4"
1896 if { $lib != "-lobjc" } {
1897 set lib "-lobjc $lib"
1899 set options_with_lib [concat $options [list libs=$lib quiet]]
1900 set ccout [gdb_compile $source $dest $type $options_with_lib]
1901 switch -regexp -- $ccout {
1902 ".*no posix threads support.*" {
1903 set why_msg "missing threads include file"
1906 ".*cannot open -lpthread.*" {
1907 set why_msg "missing runtime threads library"
1909 ".*Can't find library for -lpthread.*" {
1910 set why_msg "missing runtime threads library"
1913 pass "successfully compiled objc with posix threads test case"
1919 if {!$built_binfile} {
1920 unsupported "Couldn't compile $source: ${why_msg}"
1925 proc send_gdb { string } {
1926 global suppress_flag;
1927 if { $suppress_flag } {
1928 return "suppressed";
1930 return [remote_send host "$string"];
1936 proc gdb_expect { args } {
1937 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
1938 set atimeout [lindex $args 0];
1939 set expcode [list [lindex $args 1]];
1944 upvar timeout timeout;
1946 if [target_info exists gdb,timeout] {
1947 if [info exists timeout] {
1948 if { $timeout < [target_info gdb,timeout] } {
1949 set gtimeout [target_info gdb,timeout];
1951 set gtimeout $timeout;
1954 set gtimeout [target_info gdb,timeout];
1958 if ![info exists gtimeout] {
1960 if [info exists timeout] {
1961 set gtimeout $timeout;
1965 if [info exists atimeout] {
1966 if { ![info exists gtimeout] || $gtimeout < $atimeout } {
1967 set $gtimeout $atimeout;
1970 if ![info exists gtimeout] {
1976 global suppress_flag;
1977 global remote_suppress_flag;
1978 if [info exists remote_suppress_flag] {
1979 set old_val $remote_suppress_flag;
1981 if [info exists suppress_flag] {
1982 if { $suppress_flag } {
1983 set remote_suppress_flag 1;
1987 {uplevel remote_expect host $gtimeout $expcode} string];
1988 if [info exists old_val] {
1989 set remote_suppress_flag $old_val;
1991 if [info exists remote_suppress_flag] {
1992 unset remote_suppress_flag;
1997 global errorInfo errorCode;
1999 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
2000 } elseif {$code == 2} {
2001 return -code return $string
2002 } elseif {$code == 3} {
2004 } elseif {$code > 4} {
2005 return -code $code $string
2009 # gdb_expect_list MESSAGE SENTINEL LIST -- expect a sequence of outputs
2011 # Check for long sequence of output by parts.
2012 # MESSAGE: is the test message to be printed with the test success/fail.
2013 # SENTINEL: Is the terminal pattern indicating that output has finished.
2014 # LIST: is the sequence of outputs to match.
2015 # If the sentinel is recognized early, it is considered an error.
2018 # 1 if the test failed,
2019 # 0 if the test passes,
2020 # -1 if there was an internal error.
2022 proc gdb_expect_list {test sentinel list} {
2024 global suppress_flag
2027 if { $suppress_flag } {
2029 unresolved "${test}"
2031 while { ${index} < [llength ${list}] } {
2032 set pattern [lindex ${list} ${index}]
2033 set index [expr ${index} + 1]
2034 if { ${index} == [llength ${list}] } {
2037 -re "${pattern}${sentinel}" {
2038 # pass "${test}, pattern ${index} + sentinel"
2041 fail "${test} (pattern ${index} + sentinel)"
2044 -re ".*A problem internal to GDB has been detected" {
2045 fail "${test} (GDB internal error)"
2047 gdb_internal_error_resync
2050 fail "${test} (pattern ${index} + sentinel) (timeout)"
2055 # unresolved "${test}, pattern ${index} + sentinel"
2061 # pass "${test}, pattern ${index}"
2064 fail "${test} (pattern ${index})"
2067 -re ".*A problem internal to GDB has been detected" {
2068 fail "${test} (GDB internal error)"
2070 gdb_internal_error_resync
2073 fail "${test} (pattern ${index}) (timeout)"
2078 # unresolved "${test}, pattern ${index}"
2092 proc gdb_suppress_entire_file { reason } {
2093 global suppress_flag;
2095 warning "$reason\n";
2096 set suppress_flag -1;
2100 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
2101 # gdb_expect to fail immediately (until the next call to
2102 # gdb_stop_suppressing_tests).
2104 proc gdb_suppress_tests { args } {
2105 global suppress_flag;
2107 return; # fnf - disable pending review of results where
2108 # testsuite ran better without this
2111 if { $suppress_flag == 1 } {
2112 if { [llength $args] > 0 } {
2113 warning "[lindex $args 0]\n";
2115 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
2121 # Clear suppress_flag.
2123 proc gdb_stop_suppressing_tests { } {
2124 global suppress_flag;
2126 if [info exists suppress_flag] {
2127 if { $suppress_flag > 0 } {
2128 set suppress_flag 0;
2129 clone_output "Tests restarted.\n";
2132 set suppress_flag 0;
2136 proc gdb_clear_suppressed { } {
2137 global suppress_flag;
2139 set suppress_flag 0;
2142 proc gdb_start { } {
2147 catch default_gdb_exit
2151 # gdb_load_cmd -- load a file into the debugger.
2152 # ARGS - additional args to load command.
2153 # return a -1 if anything goes wrong.
2155 proc gdb_load_cmd { args } {
2158 if [target_info exists gdb_load_timeout] {
2159 set loadtimeout [target_info gdb_load_timeout]
2161 set loadtimeout 1600
2163 send_gdb "load $args\n"
2164 verbose "Timeout is now $loadtimeout seconds" 2
2165 gdb_expect $loadtimeout {
2166 -re "Loading section\[^\r\]*\r\n" {
2169 -re "Start address\[\r\]*\r\n" {
2172 -re "Transfer rate\[\r\]*\r\n" {
2175 -re "Memory access error\[^\r\]*\r\n" {
2176 perror "Failed to load program"
2179 -re "$gdb_prompt $" {
2182 -re "(.*)\r\n$gdb_prompt " {
2183 perror "Unexpected reponse from 'load' -- $expect_out(1,string)"
2187 perror "Timed out trying to load $args."
2196 # Copy a file to the remote target and return its target filename.
2197 # Schedule the file to be deleted at the end of this test.
2199 proc gdb_download { filename } {
2202 set destname [remote_download target $filename]
2203 lappend cleanfiles $destname
2207 # gdb_load_shlibs LIB...
2209 # Copy the listed libraries to the target.
2211 proc gdb_load_shlibs { args } {
2212 if {![is_remote target]} {
2216 foreach file $args {
2220 # Even if the target supplies full paths for shared libraries,
2221 # they may not be paths for this system.
2222 gdb_test "set solib-search-path [file dirname [lindex $args 0]]" "" ""
2226 # gdb_load -- load a file into the debugger.
2227 # Many files in config/*.exp override this procedure.
2229 proc gdb_load { arg } {
2230 return [gdb_file_cmd $arg]
2233 # gdb_reload -- load a file into the target. Called before "running",
2234 # either the first time or after already starting the program once,
2235 # for remote targets. Most files that override gdb_load should now
2236 # override this instead.
2238 proc gdb_reload { } {
2239 # For the benefit of existing configurations, default to gdb_load.
2240 # Specifying no file defaults to the executable currently being
2242 return [gdb_load ""]
2245 proc gdb_continue { function } {
2248 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
2251 proc default_gdb_init { args } {
2252 global gdb_wrapper_initialized
2257 gdb_clear_suppressed;
2259 # Make sure that the wrapper is rebuilt
2260 # with the appropriate multilib option.
2261 set gdb_wrapper_initialized 0
2263 # Unlike most tests, we have a small number of tests that generate
2264 # a very large amount of output. We therefore increase the expect
2265 # buffer size to be able to contain the entire test output.
2268 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
2269 if { [llength $args] > 0 } {
2272 set file [lindex $args 0];
2274 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
2277 if [target_info exists gdb_prompt] {
2278 set gdb_prompt [target_info gdb_prompt];
2280 set gdb_prompt "\\(gdb\\)"
2284 proc gdb_init { args } {
2285 return [eval default_gdb_init $args];
2288 proc gdb_finish { } {
2291 # Exit first, so that the files are no longer in use.
2294 if { [llength $cleanfiles] > 0 } {
2295 eval remote_file target delete $cleanfiles
2301 set debug_format "unknown"
2303 # Run the gdb command "info source" and extract the debugging format
2304 # information from the output and save it in debug_format.
2306 proc get_debug_format { } {
2312 set debug_format "unknown"
2313 send_gdb "info source\n"
2315 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
2316 set debug_format $expect_out(1,string)
2317 verbose "debug format is $debug_format"
2320 -re "No current source file.\r\n$gdb_prompt $" {
2321 perror "get_debug_format used when no current source file"
2324 -re "$gdb_prompt $" {
2325 warning "couldn't check debug format (no valid response)."
2329 warning "couldn't check debug format (timed out)."
2335 # Return true if FORMAT matches the debug format the current test was
2336 # compiled with. FORMAT is a shell-style globbing pattern; it can use
2337 # `*', `[...]', and so on.
2339 # This function depends on variables set by `get_debug_format', above.
2341 proc test_debug_format {format} {
2344 return [expr [string match $format $debug_format] != 0]
2347 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
2348 # COFF, stabs, etc). If that format matches the format that the
2349 # current test was compiled with, then the next test is expected to
2350 # fail for any target. Returns 1 if the next test or set of tests is
2351 # expected to fail, 0 otherwise (or if it is unknown). Must have
2352 # previously called get_debug_format.
2353 proc setup_xfail_format { format } {
2354 set ret [test_debug_format $format];
2362 proc gdb_step_for_stub { } {
2365 if ![target_info exists gdb,use_breakpoint_for_stub] {
2366 if [target_info exists gdb_stub_step_command] {
2367 set command [target_info gdb_stub_step_command];
2371 send_gdb "${command}\n";
2374 -re "(main.* at |.*in .*start).*$gdb_prompt" {
2377 -re ".*$gdb_prompt" {
2379 if { $tries == 5 } {
2380 fail "stepping out of breakpoint function";
2383 send_gdb "${command}\n";
2387 fail "stepping out of breakpoint function";
2394 -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" {
2395 set file $expect_out(1,string);
2396 set linenum [expr $expect_out(2,string) + 1];
2397 set breakplace "${file}:${linenum}";
2401 send_gdb "break ${breakplace}\n";
2403 -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" {
2404 set breakpoint $expect_out(1,string);
2406 -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" {
2407 set breakpoint $expect_out(1,string);
2411 send_gdb "continue\n";
2413 -re "Breakpoint ${breakpoint},.*$gdb_prompt" {
2414 gdb_test "delete $breakpoint" ".*" "";
2421 # gdb_get_line_number TEXT [FILE]
2423 # Search the source file FILE, and return the line number of the
2424 # first line containing TEXT. If no match is found, return -1.
2426 # TEXT is a string literal, not a regular expression.
2428 # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is
2429 # specified, and does not start with "/", then it is assumed to be in
2430 # "$srcdir/$subdir". This is awkward, and can be fixed in the future,
2431 # by changing the callers and the interface at the same time.
2432 # In particular: gdb.base/break.exp, gdb.base/condbreak.exp,
2433 # gdb.base/ena-dis-br.exp.
2435 # Use this function to keep your test scripts independent of the
2436 # exact line numbering of the source file. Don't write:
2438 # send_gdb "break 20"
2440 # This means that if anyone ever edits your test's source file,
2441 # your test could break. Instead, put a comment like this on the
2442 # source file line you want to break at:
2444 # /* breakpoint spot: frotz.exp: test name */
2446 # and then write, in your test script (which we assume is named
2449 # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
2451 # (Yes, Tcl knows how to handle the nested quotes and brackets.
2454 # % puts "foo [lindex "bar baz" 1]"
2457 # Tcl is quite clever, for a little stringy language.)
2461 # The previous implementation of this procedure used the gdb search command.
2462 # This version is different:
2464 # . It works with MI, and it also works when gdb is not running.
2466 # . It operates on the build machine, not the host machine.
2468 # . For now, this implementation fakes a current directory of
2469 # $srcdir/$subdir to be compatible with the old implementation.
2470 # This will go away eventually and some callers will need to
2473 # . The TEXT argument is literal text and matches literally,
2474 # not a regular expression as it was before.
2476 # . State changes in gdb, such as changing the current file
2477 # and setting $_, no longer happen.
2479 # After a bit of time we can forget about the differences from the
2480 # old implementation.
2482 # --chastain 2004-08-05
2484 proc gdb_get_line_number { text { file "" } } {
2489 if { "$file" == "" } then {
2492 if { ! [regexp "^/" "$file"] } then {
2493 set file "$srcdir/$subdir/$file"
2496 if { [ catch { set fd [open "$file"] } message ] } then {
2502 for { set line 1 } { 1 } { incr line } {
2503 if { [ catch { set nchar [gets "$fd" body] } message ] } then {
2507 if { $nchar < 0 } then {
2510 if { [string first "$text" "$body"] >= 0 } then {
2516 if { [ catch { close "$fd" } message ] } then {
2524 # gdb_continue_to_end:
2525 # The case where the target uses stubs has to be handled specially. If a
2526 # stub is used, we set a breakpoint at exit because we cannot rely on
2527 # exit() behavior of a remote target.
2529 # mssg is the error message that gets printed.
2531 proc gdb_continue_to_end {mssg} {
2532 if [target_info exists use_gdb_stub] {
2533 if {![gdb_breakpoint "exit"]} {
2536 gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \
2537 "continue until exit at $mssg"
2539 # Continue until we exit. Should not stop again.
2540 # Don't bother to check the output of the program, that may be
2541 # extremely tough for some remote systems.
2542 gdb_test "continue"\
2543 "Continuing.\[\r\n0-9\]+(... EXIT code 0\[\r\n\]+|Program exited normally\\.).*"\
2544 "continue until exit at $mssg"
2548 proc rerun_to_main {} {
2551 if [target_info exists use_gdb_stub] {
2554 -re ".*Breakpoint .*main .*$gdb_prompt $"\
2555 {pass "rerun to main" ; return 0}
2556 -re "$gdb_prompt $"\
2557 {fail "rerun to main" ; return 0}
2558 timeout {fail "(timeout) rerun to main" ; return 0}
2563 -re "The program .* has been started already.*y or n. $" {
2567 -re "Starting program.*$gdb_prompt $"\
2568 {pass "rerun to main" ; return 0}
2569 -re "$gdb_prompt $"\
2570 {fail "rerun to main" ; return 0}
2571 timeout {fail "(timeout) rerun to main" ; return 0}
2576 # Print a message and return true if a test should be skipped
2577 # due to lack of floating point suport.
2579 proc gdb_skip_float_test { msg } {
2580 if [target_info exists gdb,skip_float_tests] {
2581 verbose "Skipping test '$msg': no float tests.";
2587 # Print a message and return true if a test should be skipped
2588 # due to lack of stdio support.
2590 proc gdb_skip_stdio_test { msg } {
2591 if [target_info exists gdb,noinferiorio] {
2592 verbose "Skipping test '$msg': no inferior i/o.";
2598 proc gdb_skip_bogus_test { msg } {
2602 # Return true if a test should be skipped due to lack of XML support
2605 proc gdb_skip_xml_test { } {
2608 global xml_missing_cached
2610 if {[info exists xml_missing_cached]} {
2611 return $xml_missing_cached
2615 set xml_missing_cached 0
2616 gdb_test_multiple "set tdesc filename ${srcdir}/gdb.xml/trivial.xml" "" {
2617 -re ".*XML support was disabled at compile time.*$gdb_prompt $" {
2618 set xml_missing_cached 1
2620 -re ".*$gdb_prompt $" { }
2623 return $xml_missing_cached
2626 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
2627 # ${binfile}.dbglnk, which is just like the executable ($binfile) but without
2628 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
2629 # the name of a debuginfo only file. This file will be stored in the
2630 # gdb.base/.debug subdirectory.
2632 # Functions for separate debug info testing
2634 # starting with an executable:
2635 # foo --> original executable
2637 # at the end of the process we have:
2638 # foo.stripped --> foo w/o debug info
2639 # .debug/foo.debug --> foo's debug info
2640 # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug.
2642 # Return the name of the file in which we should stor EXEC's separated
2643 # debug info. EXEC contains the full path.
2644 proc separate_debug_filename { exec } {
2646 # In a .debug subdirectory off the same directory where the testcase
2647 # executable is going to be. Something like:
2648 # <your-path>/gdb/testsuite/gdb.base/.debug/blah.debug.
2649 # This is the default location where gdb expects to findi
2650 # the debug info file.
2652 set exec_dir [file dirname $exec]
2653 set exec_file [file tail $exec]
2654 set debug_dir [file join $exec_dir ".debug"]
2655 set debug_file [file join $debug_dir "${exec_file}.debug"]
2660 # Return the build-id hex string (usually 160 bits as 40 hex characters)
2661 # converted to the form: .build-id/ab/cdef1234...89.debug
2662 # Return "" if no build-id found.
2663 proc build_id_debug_filename_get { exec } {
2664 set tmp "${exec}-tmp"
2665 set objcopy_program [transform objcopy]
2667 set result [catch "exec $objcopy_program -j .note.gnu.build-id -O binary $exec $tmp" output]
2668 verbose "result is $result"
2669 verbose "output is $output"
2674 fconfigure $fi -translation binary
2675 # Skip the NOTE header.
2680 if ![string compare $data ""] then {
2683 # Convert it to hex.
2684 binary scan $data H* data
2685 set data [regsub {^..} $data {\0/}]
2686 return ".build-id/${data}.debug";
2689 # Create stripped files for DEST, replacing it. If ARGS is passed, it is a
2690 # list of optional flags. The only currently supported flag is no-main,
2691 # which removes the symbol entry for main from the separate debug file.
2693 proc gdb_gnu_strip_debug { dest args } {
2695 set debug_file [separate_debug_filename $dest]
2696 set strip_to_file_program [transform strip]
2697 set objcopy_program [transform objcopy]
2699 # Make sure the directory that will hold the separated debug
2700 # info actually exists.
2701 set debug_dir [file dirname $debug_file]
2702 if {! [file isdirectory $debug_dir]} {
2703 file mkdir $debug_dir
2706 set debug_link [file tail $debug_file]
2707 set stripped_file "${dest}.stripped"
2709 # Get rid of the debug info, and store result in stripped_file
2710 # something like gdb/testsuite/gdb.base/blah.stripped.
2711 set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
2712 verbose "result is $result"
2713 verbose "output is $output"
2718 # Get rid of everything but the debug info, and store result in debug_file
2719 # This will be in the .debug subdirectory, see above.
2720 set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
2721 verbose "result is $result"
2722 verbose "output is $output"
2727 # If no-main is passed, strip the symbol for main from the separate
2728 # file. This is to simulate the behavior of elfutils's eu-strip, which
2729 # leaves the symtab in the original file only. There's no way to get
2730 # objcopy or strip to remove the symbol table without also removing the
2731 # debugging sections, so this is as close as we can get.
2732 if { [llength $args] == 1 && [lindex $args 0] == "no-main" } {
2733 set result [catch "exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp" output]
2734 verbose "result is $result"
2735 verbose "output is $output"
2739 file delete "${debug_file}"
2740 file rename "${debug_file}-tmp" "${debug_file}"
2743 # Link the two previous output files together, adding the .gnu_debuglink
2744 # section to the stripped_file, containing a pointer to the debug_file,
2745 # save the new file in dest.
2746 # This will be the regular executable filename, in the usual location.
2747 set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
2748 verbose "result is $result"
2749 verbose "output is $output"
2757 # Test the output of GDB_COMMAND matches the pattern obtained
2758 # by concatenating all elements of EXPECTED_LINES. This makes
2759 # it possible to split otherwise very long string into pieces.
2760 # If third argument is not empty, it's used as the name of the
2761 # test to be printed on pass/fail.
2762 proc help_test_raw { gdb_command expected_lines args } {
2763 set message $gdb_command
2764 if [llength $args]>0 then {
2765 set message [lindex $args 0]
2767 set expected_output [join $expected_lines ""]
2768 gdb_test "${gdb_command}" "${expected_output}" $message
2771 # Test the output of "help COMMNAD_CLASS". EXPECTED_INITIAL_LINES
2772 # are regular expressions that should match the beginning of output,
2773 # before the list of commands in that class. The presence of
2774 # command list and standard epilogue will be tested automatically.
2775 proc test_class_help { command_class expected_initial_lines args } {
2777 "List of commands\:.*\[\r\n\]+"
2778 "Type \"help\" followed by command name for full documentation\.\[\r\n\]+"
2779 "Type \"apropos word\" to search for commands related to \"word\"\.[\r\n\]+"
2780 "Command name abbreviations are allowed if unambiguous\."
2782 set l_entire_body [concat $expected_initial_lines $l_stock_body]
2784 eval [list help_test_raw "help ${command_class}" $l_entire_body] $args
2787 # COMMAND_LIST should have either one element -- command to test, or
2788 # two elements -- abbreviated command to test, and full command the first
2789 # element is abbreviation of.
2790 # The command must be a prefix command. EXPECTED_INITIAL_LINES
2791 # are regular expressions that should match the beginning of output,
2792 # before the list of subcommands. The presence of
2793 # subcommand list and standard epilogue will be tested automatically.
2794 proc test_prefix_command_help { command_list expected_initial_lines args } {
2795 set command [lindex $command_list 0]
2796 if {[llength $command_list]>1} {
2797 set full_command [lindex $command_list 1]
2799 set full_command $command
2801 # Use 'list' and not just {} because we want variables to
2802 # be expanded in this list.
2803 set l_stock_body [list\
2804 "List of $full_command subcommands\:.*\[\r\n\]+"\
2805 "Type \"help $full_command\" followed by $full_command subcommand name for full documentation\.\[\r\n\]+"\
2806 "Type \"apropos word\" to search for commands related to \"word\"\.\[\r\n\]+"\
2807 "Command name abbreviations are allowed if unambiguous\."]
2808 set l_entire_body [concat $expected_initial_lines $l_stock_body]
2809 if {[llength $args]>0} {
2810 help_test_raw "help ${command}" $l_entire_body [lindex $args 0]
2812 help_test_raw "help ${command}" $l_entire_body
2816 # Build executable named EXECUTABLE, from SOURCES. If SOURCES are not
2817 # provided, uses $EXECUTABLE.c. The TESTNAME paramer is the name of test
2818 # to pass to untested, if something is wrong. OPTIONS are passed
2819 # to gdb_compile directly.
2820 proc build_executable { testname executable {sources ""} {options {debug}} } {
2825 if {[llength $sources]==0} {
2826 set sources ${executable}.c
2829 set binfile ${objdir}/${subdir}/${executable}
2832 for {set i 0} "\$i<[llength $sources]" {incr i} {
2833 set s [lindex $sources $i]
2834 if { [gdb_compile "${srcdir}/${subdir}/${s}" "${binfile}${i}.o" object $options] != "" } {
2838 lappend objects "${binfile}${i}.o"
2841 if { [gdb_compile $objects "${binfile}" executable $options] != "" } {
2846 if [get_compiler_info ${binfile}] {
2852 # Starts fresh GDB binary and loads EXECUTABLE into GDB. EXECUTABLE is
2853 # the name of binary in ${objdir}/${subdir}.
2854 proc clean_restart { executable } {
2858 set binfile ${objdir}/${subdir}/${executable}
2862 gdb_reinitialize_dir $srcdir/$subdir
2865 if [target_info exists gdb_stub] {
2870 # Prepares for testing, by calling build_executable, and then clean_restart.
2871 # Please refer to build_executable for parameter description.
2872 proc prepare_for_testing { testname executable {sources ""} {options {debug}}} {
2874 if {[build_executable $testname $executable $sources $options] == -1} {
2877 clean_restart $executable