1 # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
2 # 2003, 2004, 2005, 2007, 2008, 2009, 2010 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 global INTERNAL_GDBFLAGS
58 if ![info exists INTERNAL_GDBFLAGS] {
59 set INTERNAL_GDBFLAGS "-nw -nx"
62 # The variable gdb_prompt is a regexp which matches the gdb prompt.
63 # Set it if it is not already set.
65 if ![info exists gdb_prompt] then {
66 set gdb_prompt "\[(\]gdb\[)\]"
69 # The variable fullname_syntax_POSIX is a regexp which matches a POSIX
70 # absolute path ie. /foo/
71 set fullname_syntax_POSIX {/[^\n]*/}
72 # The variable fullname_syntax_UNC is a regexp which matches a Windows
73 # UNC path ie. \\D\foo\
74 set fullname_syntax_UNC {\\\\[^\\]+\\[^\n]+\\}
75 # The variable fullname_syntax_DOS_CASE is a regexp which matches a
76 # particular DOS case that GDB most likely will output
77 # ie. \foo\, but don't match \\.*\
78 set fullname_syntax_DOS_CASE {\\[^\\][^\n]*\\}
79 # The variable fullname_syntax_DOS is a regexp which matches a DOS path
80 # ie. a:\foo\ && a:foo\
81 set fullname_syntax_DOS {[a-zA-Z]:[^\n]*\\}
82 # The variable fullname_syntax is a regexp which matches what GDB considers
83 # an absolute path. It is currently debatable if the Windows style paths
84 # d:foo and \abc should be considered valid as an absolute path.
85 # Also, the purpse of this regexp is not to recognize a well formed
86 # absolute path, but to say with certainty that a path is absolute.
87 set fullname_syntax "($fullname_syntax_POSIX|$fullname_syntax_UNC|$fullname_syntax_DOS_CASE|$fullname_syntax_DOS)"
89 # Needed for some tests under Cygwin.
93 if ![info exists env(EXEEXT)] {
96 set EXEEXT $env(EXEEXT)
101 ### Only procedures should come after this point.
104 # gdb_version -- extract and print the version number of GDB
106 proc default_gdb_version {} {
108 global INTERNAL_GDBFLAGS GDBFLAGS
110 set output [remote_exec host "$GDB $INTERNAL_GDBFLAGS --version"]
111 set tmp [lindex $output 1];
113 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
114 if ![is_remote host] {
115 clone_output "[which $GDB] version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
117 clone_output "$GDB on remote host version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
121 proc gdb_version { } {
122 return [default_gdb_version];
126 # gdb_unload -- unload a file if one is loaded
135 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
136 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
137 -re "A program is being debugged already..*Kill it.*y or n. $"\
139 verbose "\t\tKilling previous program being debugged"
142 -re "Discard symbol table from .*y or n.*$" {
146 -re "$gdb_prompt $" {}
148 perror "couldn't unload file in $GDB (timed out)."
154 # Many of the tests depend on setting breakpoints at various places and
155 # running until that breakpoint is reached. At times, we want to start
156 # with a clean-slate with respect to breakpoints, so this utility proc
157 # lets us do this without duplicating this code everywhere.
160 proc delete_breakpoints {} {
163 # we need a larger timeout value here or this thing just confuses
164 # itself. May need a better implementation if possible. - guo
166 send_gdb "delete breakpoints\n"
168 -re "Delete all breakpoints.*y or n.*$" {
172 -re "$gdb_prompt $" { # This happens if there were no breakpoints
174 timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
176 send_gdb "info breakpoints\n"
178 -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
179 -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
180 -re "Delete all breakpoints.*or n.*$" {
184 timeout { perror "info breakpoints (timeout)" ; return }
190 # Generic run command.
192 # The second pattern below matches up to the first newline *only*.
193 # Using ``.*$'' could swallow up output that we attempt to match
196 proc gdb_run_cmd {args} {
199 if [target_info exists gdb_init_command] {
200 send_gdb "[target_info gdb_init_command]\n";
202 -re "$gdb_prompt $" { }
204 perror "gdb_init_command for target failed";
210 if [target_info exists use_gdb_stub] {
211 if [target_info exists gdb,do_reload_on_run] {
212 if { [gdb_reload] != 0 } {
215 send_gdb "continue\n";
217 -re "Continu\[^\r\n\]*\[\r\n\]" {}
223 if [target_info exists gdb,start_symbol] {
224 set start [target_info gdb,start_symbol];
228 send_gdb "jump *$start\n"
230 while { $start_attempt } {
231 # Cap (re)start attempts at three to ensure that this loop
232 # always eventually fails. Don't worry about trying to be
233 # clever and not send a command when it has failed.
234 if [expr $start_attempt > 3] {
235 perror "Jump to start() failed (retry count exceeded)";
238 set start_attempt [expr $start_attempt + 1];
240 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
243 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
244 perror "Can't find start symbol to run in gdb_run";
247 -re "No symbol \"start\" in current.*$gdb_prompt $" {
248 send_gdb "jump *_start\n";
250 -re "No symbol.*context.*$gdb_prompt $" {
253 -re "Line.* Jump anyway.*y or n. $" {
256 -re "The program is not being run.*$gdb_prompt $" {
257 if { [gdb_reload] != 0 } {
260 send_gdb "jump *$start\n";
263 perror "Jump to start() failed (timeout)";
268 if [target_info exists gdb_stub] {
270 -re "$gdb_prompt $" {
271 send_gdb "continue\n"
278 if [target_info exists gdb,do_reload_on_run] {
279 if { [gdb_reload] != 0 } {
283 send_gdb "run $args\n"
284 # This doesn't work quite right yet.
285 # Use -notransfer here so that test cases (like chng-sym.exp)
286 # may test for additional start-up messages.
288 -re "The program .* has been started already.*y or n. $" {
292 -notransfer -re "Starting program: \[^\r\n\]*" {}
293 -notransfer -re "$gdb_prompt $" {
294 # There is no more input expected.
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"
321 # Use -notransfer here so that test cases (like chng-sym.exp)
322 # may test for additional start-up messages.
324 -re "The program .* has been started already.*y or n. $" {
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 "The target does not support running in non-stop mode.\r\n$gdb_prompt $" {
423 unsupported "Non-stop mode not supported"
426 -re ".*A problem internal to GDB has been detected" {
427 fail "running to $function in runto (GDB internal error)"
428 gdb_internal_error_resync
431 -re "$gdb_prompt $" {
432 fail "running to $function in runto"
436 fail "running to $function in runto (end of file)"
440 fail "running to $function in runto (timeout)"
448 # runto_main -- ask gdb to run until we hit a breakpoint at main.
449 # The case where the target uses stubs has to be handled
450 # specially--if it uses stubs, assuming we hit
451 # breakpoint() and just step out of the function.
453 proc runto_main { } {
457 if ![target_info exists gdb_stub] {
469 ### Continue, and expect to hit a breakpoint.
470 ### Report a pass or fail, depending on whether it seems to have
471 ### worked. Use NAME as part of the test name; each call to
472 ### continue_to_breakpoint should use a NAME which is unique within
474 proc gdb_continue_to_breakpoint {name {location_pattern .*}} {
476 set full_name "continue to breakpoint: $name"
478 send_gdb "continue\n"
480 -re "Breakpoint .* (at|in) $location_pattern\r\n$gdb_prompt $" {
483 -re ".*$gdb_prompt $" {
487 fail "$full_name (timeout)"
493 # gdb_internal_error_resync:
495 # Answer the questions GDB asks after it reports an internal error
496 # until we get back to a GDB prompt. Decline to quit the debugging
497 # session, and decline to create a core file. Return non-zero if the
500 # This procedure just answers whatever questions come up until it sees
501 # a GDB prompt; it doesn't require you to have matched the input up to
502 # any specific point. However, it only answers questions it sees in
503 # the output itself, so if you've matched a question, you had better
504 # answer it yourself before calling this.
506 # You can use this function thus:
510 # -re ".*A problem internal to GDB has been detected" {
511 # gdb_internal_error_resync
516 proc gdb_internal_error_resync {} {
520 while {$count < 10} {
522 -re "Quit this debugging session\\? \\(y or n\\) $" {
526 -re "Create a core file of GDB\\? \\(y or n\\) $" {
530 -re "$gdb_prompt $" {
531 # We're resynchronized.
535 perror "Could not resync from internal error (timeout)"
540 perror "Could not resync from internal error (resync count exceeded)"
545 # gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS
546 # Send a command to gdb; test the result.
548 # COMMAND is the command to execute, send to GDB with send_gdb. If
549 # this is the null string no command is sent.
550 # MESSAGE is a message to be printed with the built-in failure patterns
551 # if one of them matches. If MESSAGE is empty COMMAND will be used.
552 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
553 # patterns. Pattern elements will be evaluated in the caller's
554 # context; action elements will be executed in the caller's context.
555 # Unlike patterns for gdb_test, these patterns should generally include
556 # the final newline and prompt.
559 # 1 if the test failed, according to a built-in failure pattern
560 # 0 if only user-supplied patterns matched
561 # -1 if there was an internal error.
563 # You can use this function thus:
565 # gdb_test_multiple "print foo" "test foo" {
566 # -re "expected output 1" {
569 # -re "expected output 2" {
574 # The standard patterns, such as "Program exited..." and "A problem
575 # ...", all being implicitly appended to that list.
577 proc gdb_test_multiple { command message user_code } {
581 upvar timeout timeout
582 upvar expect_out expect_out
584 if { $message == "" } {
588 if [string match "*\[\r\n\]" $command] {
589 error "Invalid trailing newline in \"$message\" test"
592 # TCL/EXPECT WART ALERT
593 # Expect does something very strange when it receives a single braced
594 # argument. It splits it along word separators and performs substitutions.
595 # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
596 # evaluated as "\[ab\]". But that's not how TCL normally works; inside a
597 # double-quoted list item, "\[ab\]" is just a long way of representing
598 # "[ab]", because the backslashes will be removed by lindex.
600 # Unfortunately, there appears to be no easy way to duplicate the splitting
601 # that expect will do from within TCL. And many places make use of the
602 # "\[0-9\]" construct, so we need to support that; and some places make use
603 # of the "[func]" construct, so we need to support that too. In order to
604 # get this right we have to substitute quoted list elements differently
605 # from braced list elements.
607 # We do this roughly the same way that Expect does it. We have to use two
608 # lists, because if we leave unquoted newlines in the argument to uplevel
609 # they'll be treated as command separators, and if we escape newlines
610 # we mangle newlines inside of command blocks. This assumes that the
611 # input doesn't contain a pattern which contains actual embedded newlines
614 regsub -all {\n} ${user_code} { } subst_code
615 set subst_code [uplevel list $subst_code]
617 set processed_code ""
619 set expecting_action 0
621 foreach item $user_code subst_item $subst_code {
622 if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } {
623 lappend processed_code $item
626 if { $item == "-indices" || $item == "-re" || $item == "-ex" } {
627 lappend processed_code $item
630 if { $item == "-timeout" } {
632 lappend processed_code $item
635 if { $expecting_arg } {
637 lappend processed_code $item
640 if { $expecting_action } {
641 lappend processed_code "uplevel [list $item]"
642 set expecting_action 0
643 # Cosmetic, no effect on the list.
644 append processed_code "\n"
647 set expecting_action 1
648 lappend processed_code $subst_item
649 if {$patterns != ""} {
652 append patterns "\"$subst_item\""
655 # Also purely cosmetic.
656 regsub -all {\r} $patterns {\\r} patterns
657 regsub -all {\n} $patterns {\\n} patterns
660 send_user "Sending \"$command\" to gdb\n"
661 send_user "Looking to match \"$patterns\"\n"
662 send_user "Message is \"$message\"\n"
666 set string "${command}\n";
667 if { $command != "" } {
668 while { "$string" != "" } {
669 set foo [string first "\n" "$string"];
670 set len [string length "$string"];
671 if { $foo < [expr $len - 1] } {
672 set str [string range "$string" 0 $foo];
673 if { [send_gdb "$str"] != "" } {
674 global suppress_flag;
676 if { ! $suppress_flag } {
677 perror "Couldn't send $command to GDB.";
682 # since we're checking if each line of the multi-line
683 # command are 'accepted' by GDB here,
684 # we need to set -notransfer expect option so that
685 # command output is not lost for pattern matching
688 -notransfer -re "\[\r\n\]" { verbose "partial: match" 3 }
689 timeout { verbose "partial: timeout" 3 }
691 set string [string range "$string" [expr $foo + 1] end];
696 if { "$string" != "" } {
697 if { [send_gdb "$string"] != "" } {
698 global suppress_flag;
700 if { ! $suppress_flag } {
701 perror "Couldn't send $command to GDB.";
709 if [target_info exists gdb,timeout] {
710 set tmt [target_info gdb,timeout];
712 if [info exists timeout] {
716 if [info exists timeout] {
725 -re ".*A problem internal to GDB has been detected" {
726 fail "$message (GDB internal error)"
727 gdb_internal_error_resync
729 -re "\\*\\*\\* DOSEXIT code.*" {
730 if { $message != "" } {
733 gdb_suppress_entire_file "GDB died";
737 append code $processed_code
739 -re "Ending remote debugging.*$gdb_prompt $" {
740 if ![isnative] then {
741 warning "Can`t communicate to remote target."
747 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
748 perror "Undefined command \"$command\"."
752 -re "Ambiguous command.*$gdb_prompt $" {
753 perror "\"$command\" is not a unique command name."
757 -re "Program exited with code \[0-9\]+.*$gdb_prompt $" {
758 if ![string match "" $message] then {
759 set errmsg "$message (the program exited)"
761 set errmsg "$command (the program exited)"
766 -re "Program exited normally.*$gdb_prompt $" {
767 if ![string match "" $message] then {
768 set errmsg "$message (the program exited)"
770 set errmsg "$command (the program exited)"
775 -re "The program is not being run.*$gdb_prompt $" {
776 if ![string match "" $message] then {
777 set errmsg "$message (the program is no longer running)"
779 set errmsg "$command (the program is no longer running)"
784 -re "\r\n$gdb_prompt $" {
785 if ![string match "" $message] then {
792 perror "Window too small."
796 -re "\\((y or n|y or \\\[n\\\]|\\\[y\\\] or n)\\) " {
798 gdb_expect -re "$gdb_prompt $"
799 fail "$message (got interactive prompt)"
802 -re "\\\[0\\\] cancel\r\n\\\[1\\\] all.*\r\n> $" {
804 gdb_expect -re "$gdb_prompt $"
805 fail "$message (got breakpoint menu)"
809 perror "Process no longer exists"
810 if { $message != "" } {
816 perror "internal buffer is full."
821 if ![string match "" $message] then {
822 fail "$message (timeout)"
829 set code [catch {gdb_expect $tmt $code} string]
831 global errorInfo errorCode;
832 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
833 } elseif {$code == 2} {
834 return -code return $string
835 } elseif {$code == 3} {
837 } elseif {$code > 4} {
838 return -code $code $string
843 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
844 # Send a command to gdb; test the result.
846 # COMMAND is the command to execute, send to GDB with send_gdb. If
847 # this is the null string no command is sent.
848 # PATTERN is the pattern to match for a PASS, and must NOT include
849 # the \r\n sequence immediately before the gdb prompt.
850 # MESSAGE is an optional message to be printed. If this is
851 # omitted, then the pass/fail messages use the command string as the
852 # message. (If this is the empty string, then sometimes we don't
853 # call pass or fail at all; I don't understand this at all.)
854 # QUESTION is a question GDB may ask in response to COMMAND, like
856 # RESPONSE is the response to send if QUESTION appears.
859 # 1 if the test failed,
860 # 0 if the test passes,
861 # -1 if there was an internal error.
863 proc gdb_test { args } {
867 upvar timeout timeout
869 if [llength $args]>2 then {
870 set message [lindex $args 2]
872 set message [lindex $args 0]
874 set command [lindex $args 0]
875 set pattern [lindex $args 1]
877 if [llength $args]==5 {
878 set question_string [lindex $args 3];
879 set response_string [lindex $args 4];
881 set question_string "^FOOBAR$"
884 return [gdb_test_multiple $command $message {
885 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
886 if ![string match "" $message] then {
890 -re "(${question_string})$" {
891 send_gdb "$response_string\n";
897 # gdb_test_no_output COMMAND MESSAGE
898 # Send a command to GDB and verify that this command generated no output.
900 # See gdb_test_multiple for a description of the COMMAND and MESSAGE
901 # parameters. If MESSAGE is ommitted, then COMMAND will be used as
902 # the message. (If MESSAGE is the empty string, then sometimes we do not
903 # call pass or fail at all; I don't understand this at all.)
905 proc gdb_test_no_output { args } {
907 set command [lindex $args 0]
908 if [llength $args]>1 then {
909 set message [lindex $args 1]
914 set command_regex [string_to_regexp $command]
915 gdb_test_multiple $command $message {
916 -re "^$command_regex\r\n$gdb_prompt $" {
917 if ![string match "" $message] then {
924 # Send a command and then wait for a sequence of outputs.
925 # This is useful when the sequence is long and contains ".*", a single
926 # regexp to match the entire output can get a timeout much easier.
928 # COMMAND is the command to send.
929 # TEST_NAME is passed to pass/fail. COMMAND is used if TEST_NAME is "".
930 # EXPECTED_OUTPUT_LIST is a list of regexps of expected output, which are
931 # processed in order, and all must be present in the output.
933 # It is unnecessary to specify ".*" at the beginning or end of any regexp,
934 # there is an implicit ".*" between each element of EXPECTED_OUTPUT_LIST.
935 # There is also an implicit ".*" between the last regexp and the gdb prompt.
937 # Like gdb_test and gdb_test_multiple, the output is expected to end with the
938 # gdb prompt, which must not be specified in EXPECTED_OUTPUT_LIST.
940 proc gdb_test_sequence { command test_name expected_output_list } {
942 if { $test_name == "" } {
943 set test_name $command
945 lappend expected_output_list ""; # implicit ".*" before gdb prompt
946 send_gdb "$command\n"
947 gdb_expect_list $test_name "$gdb_prompt $" $expected_output_list
951 # Test that a command gives an error. For pass or fail, return
952 # a 1 to indicate that more tests can proceed. However a timeout
953 # is a serious error, generates a special fail message, and causes
954 # a 0 to be returned to indicate that more tests are likely to fail
957 proc test_print_reject { args } {
961 if [llength $args]==2 then {
962 set expectthis [lindex $args 1]
964 set expectthis "should never match this bogus string"
966 set sendthis [lindex $args 0]
968 send_user "Sending \"$sendthis\" to gdb\n"
969 send_user "Looking to match \"$expectthis\"\n"
971 send_gdb "$sendthis\n"
972 #FIXME: Should add timeout as parameter.
974 -re "A .* in expression.*\\.*$gdb_prompt $" {
975 pass "reject $sendthis"
978 -re "Invalid syntax in expression.*$gdb_prompt $" {
979 pass "reject $sendthis"
982 -re "Junk after end of expression.*$gdb_prompt $" {
983 pass "reject $sendthis"
986 -re "Invalid number.*$gdb_prompt $" {
987 pass "reject $sendthis"
990 -re "Invalid character constant.*$gdb_prompt $" {
991 pass "reject $sendthis"
994 -re "No symbol table is loaded.*$gdb_prompt $" {
995 pass "reject $sendthis"
998 -re "No symbol .* in current context.*$gdb_prompt $" {
999 pass "reject $sendthis"
1002 -re "Unmatched single quote.*$gdb_prompt $" {
1003 pass "reject $sendthis"
1006 -re "A character constant must contain at least one character.*$gdb_prompt $" {
1007 pass "reject $sendthis"
1010 -re "$expectthis.*$gdb_prompt $" {
1011 pass "reject $sendthis"
1014 -re ".*$gdb_prompt $" {
1015 fail "reject $sendthis"
1019 fail "reject $sendthis (eof or timeout)"
1025 # Given an input string, adds backslashes as needed to create a
1026 # regexp that will match the string.
1028 proc string_to_regexp {str} {
1030 regsub -all {[]*+.|()^$\[\\]} $str {\\&} result
1034 # Same as gdb_test, but the second parameter is not a regexp,
1035 # but a string that must match exactly.
1037 proc gdb_test_exact { args } {
1038 upvar timeout timeout
1040 set command [lindex $args 0]
1042 # This applies a special meaning to a null string pattern. Without
1043 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
1044 # messages from commands that should have no output except a new
1045 # prompt. With this, only results of a null string will match a null
1048 set pattern [lindex $args 1]
1049 if [string match $pattern ""] {
1050 set pattern [string_to_regexp [lindex $args 0]]
1052 set pattern [string_to_regexp [lindex $args 1]]
1055 # It is most natural to write the pattern argument with only
1056 # embedded \n's, especially if you are trying to avoid Tcl quoting
1057 # problems. But gdb_expect really wants to see \r\n in patterns. So
1058 # transform the pattern here. First transform \r\n back to \n, in
1059 # case some users of gdb_test_exact already do the right thing.
1060 regsub -all "\r\n" $pattern "\n" pattern
1061 regsub -all "\n" $pattern "\r\n" pattern
1062 if [llength $args]==3 then {
1063 set message [lindex $args 2]
1065 set message $command
1068 return [gdb_test $command $pattern $message]
1071 # Wrapper around gdb_test_multiple that looks for a list of expected
1072 # output elements, but which can appear in any order.
1073 # CMD is the gdb command.
1074 # NAME is the name of the test.
1075 # ELM_FIND_REGEXP specifies how to partition the output into elements to
1077 # ELM_EXTRACT_REGEXP specifies the part of ELM_FIND_REGEXP to compare.
1078 # RESULT_MATCH_LIST is a list of exact matches for each expected element.
1079 # All elements of RESULT_MATCH_LIST must appear for the test to pass.
1081 # A typical use of ELM_FIND_REGEXP/ELM_EXTRACT_REGEXP is to extract one line
1082 # of text per element and then strip trailing \r\n's.
1084 # gdb_test_list_exact "foo" "bar" \
1085 # {[^\r\n]+[\r\n]+} \
1088 # {expected result 1} \
1089 # {expected result 2} \
1092 proc gdb_test_list_exact { cmd name elm_find_regexp elm_extract_regexp result_match_list } {
1095 set matches [lsort $result_match_list]
1097 gdb_test_multiple $cmd $name {
1098 "$cmd\[\r\n\]" { exp_continue }
1099 -re $elm_find_regexp {
1100 set str $expect_out(0,string)
1101 verbose -log "seen: $str" 3
1102 regexp -- $elm_extract_regexp $str elm_seen
1103 verbose -log "extracted: $elm_seen" 3
1104 lappend seen $elm_seen
1107 -re "$gdb_prompt $" {
1109 foreach got [lsort $seen] have $matches {
1110 if {![string equal $got $have]} {
1115 if {[string length $failed] != 0} {
1116 fail "$name ($failed not found)"
1124 proc gdb_reinitialize_dir { subdir } {
1127 if [is_remote host] {
1132 -re "Reinitialize source path to empty.*y or n. " {
1135 -re "Source directories searched.*$gdb_prompt $" {
1136 send_gdb "dir $subdir\n"
1138 -re "Source directories searched.*$gdb_prompt $" {
1139 verbose "Dir set to $subdir"
1141 -re "$gdb_prompt $" {
1142 perror "Dir \"$subdir\" failed."
1146 -re "$gdb_prompt $" {
1147 perror "Dir \"$subdir\" failed."
1151 -re "$gdb_prompt $" {
1152 perror "Dir \"$subdir\" failed."
1158 # gdb_exit -- exit the GDB, killing the target program if necessary
1160 proc default_gdb_exit {} {
1162 global INTERNAL_GDBFLAGS GDBFLAGS
1164 global gdb_spawn_id;
1166 gdb_stop_suppressing_tests;
1168 if ![info exists gdb_spawn_id] {
1172 verbose "Quitting $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1174 if { [is_remote host] && [board_info host exists fileid] } {
1181 -re "DOSEXIT code" { }
1186 if ![is_remote host] {
1192 # Load a file into the debugger.
1193 # The return value is 0 for success, -1 for failure.
1195 # This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO
1196 # to one of these values:
1198 # debug file was loaded successfully and has debug information
1199 # nodebug file was loaded successfully and has no debug information
1200 # fail file was not loaded
1202 # I tried returning this information as part of the return value,
1203 # but ran into a mess because of the many re-implementations of
1204 # gdb_load in config/*.exp.
1206 # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use
1207 # this if they can get more information set.
1209 proc gdb_file_cmd { arg } {
1213 global last_loaded_file
1215 set last_loaded_file $arg
1217 # Set whether debug info was found.
1218 # Default to "fail".
1219 global gdb_file_cmd_debug_info
1220 set gdb_file_cmd_debug_info "fail"
1222 if [is_remote host] {
1223 set arg [remote_download host $arg]
1225 perror "download failed"
1230 # The file command used to kill the remote target. For the benefit
1231 # of the testsuite, preserve this behavior.
1234 -re "Kill the program being debugged. .y or n. $" {
1236 verbose "\t\tKilling previous program being debugged"
1239 -re "$gdb_prompt $" {
1244 send_gdb "file $arg\n"
1246 -re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" {
1247 verbose "\t\tLoaded $arg into the $GDB with no debugging symbols"
1248 set gdb_file_cmd_debug_info "nodebug"
1251 -re "Reading symbols from.*done.*$gdb_prompt $" {
1252 verbose "\t\tLoaded $arg into the $GDB"
1253 set gdb_file_cmd_debug_info "debug"
1256 -re "Load new symbol table from \".*\".*y or n. $" {
1259 -re "Reading symbols from.*done.*$gdb_prompt $" {
1260 verbose "\t\tLoaded $arg with new symbol table into $GDB"
1261 set gdb_file_cmd_debug_info "debug"
1265 perror "(timeout) Couldn't load $arg, other program already loaded."
1270 -re "No such file or directory.*$gdb_prompt $" {
1271 perror "($arg) No such file or directory"
1274 -re "$gdb_prompt $" {
1275 perror "couldn't load $arg into $GDB."
1279 perror "couldn't load $arg into $GDB (timed out)."
1283 # This is an attempt to detect a core dump, but seems not to
1284 # work. Perhaps we need to match .* followed by eof, in which
1285 # gdb_expect does not seem to have a way to do that.
1286 perror "couldn't load $arg into $GDB (end of file)."
1293 # start gdb -- start gdb running, default procedure
1295 # When running over NFS, particularly if running many simultaneous
1296 # tests on different hosts all using the same server, things can
1297 # get really slow. Give gdb at least 3 minutes to start up.
1299 proc default_gdb_start { } {
1302 global INTERNAL_GDBFLAGS GDBFLAGS
1305 global gdb_spawn_id;
1308 gdb_stop_suppressing_tests;
1312 # Don't let a .inputrc file or an existing setting of INPUTRC mess up
1313 # the test results. Even if /dev/null doesn't exist on the particular
1314 # platform, the readline library will use the default setting just by
1315 # failing to open the file. OTOH, opening /dev/null successfully will
1316 # also result in the default settings being used since nothing will be
1317 # read from this file.
1318 set env(INPUTRC) "/dev/null"
1320 # The gdb.base/readline.exp arrow key test relies on the standard VT100
1321 # bindings, so make sure that an appropriate terminal is selected.
1322 # The same bug doesn't show up if we use ^P / ^N instead.
1323 set env(TERM) "vt100"
1325 verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1327 if [info exists gdb_spawn_id] {
1331 if ![is_remote host] {
1332 if { [which $GDB] == 0 } then {
1333 perror "$GDB does not exist."
1337 set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"];
1338 if { $res < 0 || $res == "" } {
1339 perror "Spawning $GDB failed."
1343 -re "\[\r\n\]$gdb_prompt $" {
1344 verbose "GDB initialized."
1346 -re "$gdb_prompt $" {
1347 perror "GDB never initialized."
1351 perror "(timeout) GDB never initialized after 10 seconds."
1356 set gdb_spawn_id -1;
1357 # force the height to "unlimited", so no pagers get used
1359 send_gdb "set height 0\n"
1361 -re "$gdb_prompt $" {
1362 verbose "Setting height to 0." 2
1365 warning "Couldn't set the height to 0"
1368 # force the width to "unlimited", so no wraparound occurs
1369 send_gdb "set width 0\n"
1371 -re "$gdb_prompt $" {
1372 verbose "Setting width to 0." 2
1375 warning "Couldn't set the width to 0."
1381 # Examine the output of compilation to determine whether compilation
1382 # failed or not. If it failed determine whether it is due to missing
1383 # compiler or due to compiler error. Report pass, fail or unsupported
1386 proc gdb_compile_test {src output} {
1387 if { $output == "" } {
1388 pass "compilation [file tail $src]"
1389 } elseif { [regexp {^[a-zA-Z_0-9]+: Can't find [^ ]+\.$} $output] } {
1390 unsupported "compilation [file tail $src]"
1391 } elseif { [regexp {.*: command not found[\r|\n]*$} $output] } {
1392 unsupported "compilation [file tail $src]"
1393 } elseif { [regexp {.*: [^\r\n]*compiler not installed[^\r\n]*[\r|\n]*$} $output] } {
1394 unsupported "compilation [file tail $src]"
1396 verbose -log "compilation failed: $output" 2
1397 fail "compilation [file tail $src]"
1401 # Return a 1 for configurations for which we don't even want to try to
1404 proc skip_cplus_tests {} {
1405 if { [istarget "h8300-*-*"] } {
1409 # The C++ IO streams are too large for HC11/HC12 and are thus not
1410 # available. The gdb C++ tests use them and don't compile.
1411 if { [istarget "m6811-*-*"] } {
1414 if { [istarget "m6812-*-*"] } {
1420 # Return a 1 for configurations for which don't have both C++ and the STL.
1422 proc skip_stl_tests {} {
1423 # Symbian supports the C++ language, but the STL is missing
1424 # (both headers and libraries).
1425 if { [istarget "arm*-*-symbianelf*"] } {
1429 return [skip_cplus_tests]
1432 # Return a 1 if I don't even want to try to test FORTRAN.
1434 proc skip_fortran_tests {} {
1438 # Return a 1 if I don't even want to try to test ada.
1440 proc skip_ada_tests {} {
1444 # Return a 1 if I don't even want to try to test java.
1446 proc skip_java_tests {} {
1450 # Return a 1 for configurations that do not support Python scripting.
1452 proc skip_python_tests {} {
1454 gdb_test_multiple "python print 'test'" "verify python support" {
1455 -re "not supported.*$gdb_prompt $" {
1456 unsupported "Python support is disabled."
1459 -re "$gdb_prompt $" {}
1465 # Return a 1 if we should skip shared library tests.
1467 proc skip_shlib_tests {} {
1468 # Run the shared library tests on native systems.
1473 # An abbreviated list of remote targets where we should be able to
1474 # run shared library tests.
1475 if {([istarget *-*-linux*]
1476 || [istarget *-*-*bsd*]
1477 || [istarget *-*-solaris2*]
1478 || [istarget arm*-*-symbianelf*]
1479 || [istarget *-*-mingw*]
1480 || [istarget *-*-cygwin*]
1481 || [istarget *-*-pe*])} {
1488 # Return 1 if target is ILP32.
1489 # This cannot be decided simply from looking at the target string,
1490 # as it might depend on externally passed compiler options like -m64.
1491 proc is_ilp32_target {} {
1492 global is_ilp32_target_saved
1494 # Use the cached value, if it exists. Cache value per "board" to handle
1495 # runs with multiple options (e.g. unix/{-m32,-64}) correctly.
1496 set me "is_ilp32_target"
1497 set board [target_info name]
1498 if [info exists is_ilp32_target_saved($board)] {
1499 verbose "$me: returning saved $is_ilp32_target_saved($board)" 2
1500 return $is_ilp32_target_saved($board)
1504 set src ilp32[pid].c
1505 set obj ilp32[pid].o
1507 set f [open $src "w"]
1508 puts $f "int dummy\[sizeof (int) == 4"
1509 puts $f " && sizeof (void *) == 4"
1510 puts $f " && sizeof (long) == 4 ? 1 : -1\];"
1513 verbose "$me: compiling testfile $src" 2
1514 set lines [gdb_compile $src $obj object {quiet}]
1518 if ![string match "" $lines] then {
1519 verbose "$me: testfile compilation failed, returning 0" 2
1520 return [set is_ilp32_target_saved($board) 0]
1523 verbose "$me: returning 1" 2
1524 return [set is_ilp32_target_saved($board) 1]
1527 # Return 1 if target is LP64.
1528 # This cannot be decided simply from looking at the target string,
1529 # as it might depend on externally passed compiler options like -m64.
1530 proc is_lp64_target {} {
1531 global is_lp64_target_saved
1533 # Use the cached value, if it exists. Cache value per "board" to handle
1534 # runs with multiple options (e.g. unix/{-m32,-64}) correctly.
1535 set me "is_lp64_target"
1536 set board [target_info name]
1537 if [info exists is_lp64_target_saved($board)] {
1538 verbose "$me: returning saved $is_lp64_target_saved($board)" 2
1539 return $is_lp64_target_saved($board)
1545 set f [open $src "w"]
1546 puts $f "int dummy\[sizeof (int) == 4"
1547 puts $f " && sizeof (void *) == 8"
1548 puts $f " && sizeof (long) == 8 ? 1 : -1\];"
1551 verbose "$me: compiling testfile $src" 2
1552 set lines [gdb_compile $src $obj object {quiet}]
1556 if ![string match "" $lines] then {
1557 verbose "$me: testfile compilation failed, returning 0" 2
1558 return [set is_lp64_target_saved($board) 0]
1561 verbose "$me: returning 1" 2
1562 return [set is_lp64_target_saved($board) 1]
1565 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
1566 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
1568 proc skip_altivec_tests {} {
1569 global skip_vmx_tests_saved
1570 global srcdir subdir gdb_prompt
1572 # Use the cached value, if it exists.
1573 set me "skip_altivec_tests"
1574 if [info exists skip_vmx_tests_saved] {
1575 verbose "$me: returning saved $skip_vmx_tests_saved" 2
1576 return $skip_vmx_tests_saved
1579 # Some simulators are known to not support VMX instructions.
1580 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1581 verbose "$me: target known to not support VMX, returning 1" 2
1582 return [set skip_vmx_tests_saved 1]
1585 # Make sure we have a compiler that understands altivec.
1586 set compile_flags {debug nowarnings}
1587 if [get_compiler_info not-used] {
1588 warning "Could not get compiler info"
1591 if [test_compiler_info gcc*] {
1592 set compile_flags "$compile_flags additional_flags=-maltivec"
1593 } elseif [test_compiler_info xlc*] {
1594 set compile_flags "$compile_flags additional_flags=-qaltivec"
1596 verbose "Could not compile with altivec support, returning 1" 2
1600 # Set up, compile, and execute a test program containing VMX instructions.
1601 # Include the current process ID in the file names to prevent conflicts
1602 # with invocations for multiple testsuites.
1606 set f [open $src "w"]
1607 puts $f "int main() {"
1608 puts $f "#ifdef __MACH__"
1609 puts $f " asm volatile (\"vor v0,v0,v0\");"
1611 puts $f " asm volatile (\"vor 0,0,0\");"
1613 puts $f " return 0; }"
1616 verbose "$me: compiling testfile $src" 2
1617 set lines [gdb_compile $src $exe executable $compile_flags]
1620 if ![string match "" $lines] then {
1621 verbose "$me: testfile compilation failed, returning 1" 2
1622 return [set skip_vmx_tests_saved 1]
1625 # No error message, compilation succeeded so now run it via gdb.
1629 gdb_reinitialize_dir $srcdir/$subdir
1633 -re ".*Illegal instruction.*${gdb_prompt} $" {
1634 verbose -log "\n$me altivec hardware not detected"
1635 set skip_vmx_tests_saved 1
1637 -re ".*Program exited normally.*${gdb_prompt} $" {
1638 verbose -log "\n$me: altivec hardware detected"
1639 set skip_vmx_tests_saved 0
1642 warning "\n$me: default case taken"
1643 set skip_vmx_tests_saved 1
1647 remote_file build delete $exe
1649 verbose "$me: returning $skip_vmx_tests_saved" 2
1650 return $skip_vmx_tests_saved
1653 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
1654 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
1656 proc skip_vsx_tests {} {
1657 global skip_vsx_tests_saved
1658 global srcdir subdir gdb_prompt
1660 # Use the cached value, if it exists.
1661 set me "skip_vsx_tests"
1662 if [info exists skip_vsx_tests_saved] {
1663 verbose "$me: returning saved $skip_vsx_tests_saved" 2
1664 return $skip_vsx_tests_saved
1667 # Some simulators are known to not support Altivec instructions, so
1668 # they won't support VSX instructions as well.
1669 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1670 verbose "$me: target known to not support VSX, returning 1" 2
1671 return [set skip_vsx_tests_saved 1]
1674 # Make sure we have a compiler that understands altivec.
1675 set compile_flags {debug nowarnings quiet}
1676 if [get_compiler_info not-used] {
1677 warning "Could not get compiler info"
1680 if [test_compiler_info gcc*] {
1681 set compile_flags "$compile_flags additional_flags=-mvsx"
1682 } elseif [test_compiler_info xlc*] {
1683 set compile_flags "$compile_flags additional_flags=-qvsx"
1685 verbose "Could not compile with vsx support, returning 1" 2
1692 set f [open $src "w"]
1693 puts $f "int main() {"
1694 puts $f "#ifdef __MACH__"
1695 puts $f " asm volatile (\"lxvd2x v0,v0,v0\");"
1697 puts $f " asm volatile (\"lxvd2x 0,0,0\");"
1699 puts $f " return 0; }"
1702 verbose "$me: compiling testfile $src" 2
1703 set lines [gdb_compile $src $exe executable $compile_flags]
1706 if ![string match "" $lines] then {
1707 verbose "$me: testfile compilation failed, returning 1" 2
1708 return [set skip_vsx_tests_saved 1]
1711 # No error message, compilation succeeded so now run it via gdb.
1715 gdb_reinitialize_dir $srcdir/$subdir
1719 -re ".*Illegal instruction.*${gdb_prompt} $" {
1720 verbose -log "\n$me VSX hardware not detected"
1721 set skip_vsx_tests_saved 1
1723 -re ".*Program exited normally.*${gdb_prompt} $" {
1724 verbose -log "\n$me: VSX hardware detected"
1725 set skip_vsx_tests_saved 0
1728 warning "\n$me: default case taken"
1729 set skip_vsx_tests_saved 1
1733 remote_file build delete $exe
1735 verbose "$me: returning $skip_vsx_tests_saved" 2
1736 return $skip_vsx_tests_saved
1739 # Skip all the tests in the file if you are not on an hppa running
1742 proc skip_hp_tests {} {
1743 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
1744 verbose "Skip hp tests is $skip_hp"
1748 # Return whether we should skip tests for showing inlined functions in
1749 # backtraces. Requires get_compiler_info and get_debug_format.
1751 proc skip_inline_frame_tests {} {
1752 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
1753 if { ! [test_debug_format "DWARF 2"] } {
1757 # GCC before 4.1 does not emit DW_AT_call_file / DW_AT_call_line.
1758 if { ([test_compiler_info "gcc-2-*"]
1759 || [test_compiler_info "gcc-3-*"]
1760 || [test_compiler_info "gcc-4-0-*"]) } {
1767 # Return whether we should skip tests for showing variables from
1768 # inlined functions. Requires get_compiler_info and get_debug_format.
1770 proc skip_inline_var_tests {} {
1771 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
1772 if { ! [test_debug_format "DWARF 2"] } {
1779 set compiler_info "unknown"
1781 set hp_cc_compiler 0
1782 set hp_aCC_compiler 0
1784 # Figure out what compiler I am using.
1786 # BINFILE is a "compiler information" output file. This implementation
1787 # does not use BINFILE.
1789 # ARGS can be empty or "C++". If empty, "C" is assumed.
1791 # There are several ways to do this, with various problems.
1793 # [ gdb_compile -E $ifile -o $binfile.ci ]
1794 # source $binfile.ci
1796 # Single Unix Spec v3 says that "-E -o ..." together are not
1797 # specified. And in fact, the native compiler on hp-ux 11 (among
1798 # others) does not work with "-E -o ...". Most targets used to do
1799 # this, and it mostly worked, because it works with gcc.
1801 # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ]
1802 # source $binfile.ci
1804 # This avoids the problem with -E and -o together. This almost works
1805 # if the build machine is the same as the host machine, which is
1806 # usually true of the targets which are not gcc. But this code does
1807 # not figure which compiler to call, and it always ends up using the C
1808 # compiler. Not good for setting hp_aCC_compiler. Targets
1809 # hppa*-*-hpux* and mips*-*-irix* used to do this.
1811 # [ gdb_compile -E $ifile > $binfile.ci ]
1812 # source $binfile.ci
1814 # dejagnu target_compile says that it supports output redirection,
1815 # but the code is completely different from the normal path and I
1816 # don't want to sweep the mines from that path. So I didn't even try
1819 # set cppout [ gdb_compile $ifile "" preprocess $args quiet ]
1822 # I actually do this for all targets now. gdb_compile runs the right
1823 # compiler, and TCL captures the output, and I eval the output.
1825 # Unfortunately, expect logs the output of the command as it goes by,
1826 # and dejagnu helpfully prints a second copy of it right afterwards.
1827 # So I turn off expect logging for a moment.
1829 # [ gdb_compile $ifile $ciexe_file executable $args ]
1830 # [ remote_exec $ciexe_file ]
1831 # [ source $ci_file.out ]
1833 # I could give up on -E and just do this.
1834 # I didn't get desperate enough to try this.
1836 # -- chastain 2004-01-06
1838 proc get_compiler_info {binfile args} {
1839 # For compiler.c and compiler.cc
1842 # I am going to play with the log to keep noise out.
1846 # These come from compiler.c or compiler.cc
1847 global compiler_info
1849 # Legacy global data symbols.
1851 global hp_cc_compiler
1852 global hp_aCC_compiler
1854 # Choose which file to preprocess.
1855 set ifile "${srcdir}/lib/compiler.c"
1856 if { [llength $args] > 0 && [lindex $args 0] == "c++" } {
1857 set ifile "${srcdir}/lib/compiler.cc"
1860 # Run $ifile through the right preprocessor.
1861 # Toggle gdb.log to keep the compiler output out of the log.
1863 if [is_remote host] {
1864 # We have to use -E and -o together, despite the comments
1865 # above, because of how DejaGnu handles remote host testing.
1866 set ppout "$outdir/compiler.i"
1867 gdb_compile "${ifile}" "$ppout" preprocess [list "$args" quiet]
1868 set file [open $ppout r]
1869 set cppout [read $file]
1872 set cppout [ gdb_compile "${ifile}" "" preprocess [list "$args" quiet] ]
1874 log_file -a "$outdir/$tool.log"
1878 foreach cppline [ split "$cppout" "\n" ] {
1879 if { [ regexp "^#" "$cppline" ] } {
1881 } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } {
1883 } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } {
1885 verbose "get_compiler_info: $cppline" 2
1889 verbose -log "get_compiler_info: $cppline"
1894 # Reset to unknown compiler if any diagnostics happened.
1896 set compiler_info "unknown"
1899 # Set the legacy symbols.
1901 set hp_cc_compiler 0
1902 set hp_aCC_compiler 0
1903 if { [regexp "^gcc-1-" "$compiler_info" ] } { set gcc_compiled 1 }
1904 if { [regexp "^gcc-2-" "$compiler_info" ] } { set gcc_compiled 2 }
1905 if { [regexp "^gcc-3-" "$compiler_info" ] } { set gcc_compiled 3 }
1906 if { [regexp "^gcc-4-" "$compiler_info" ] } { set gcc_compiled 4 }
1907 if { [regexp "^gcc-5-" "$compiler_info" ] } { set gcc_compiled 5 }
1908 if { [regexp "^hpcc-" "$compiler_info" ] } { set hp_cc_compiler 1 }
1909 if { [regexp "^hpacc-" "$compiler_info" ] } { set hp_aCC_compiler 1 }
1911 # Log what happened.
1912 verbose -log "get_compiler_info: $compiler_info"
1914 # Most compilers will evaluate comparisons and other boolean
1915 # operations to 0 or 1.
1916 uplevel \#0 { set true 1 }
1917 uplevel \#0 { set false 0 }
1919 # Use of aCC results in boolean results being displayed as
1921 if { $hp_aCC_compiler } {
1922 uplevel \#0 { set true true }
1923 uplevel \#0 { set false false }
1929 proc test_compiler_info { {compiler ""} } {
1930 global compiler_info
1932 # if no arg, return the compiler_info string
1934 if [string match "" $compiler] {
1935 if [info exists compiler_info] {
1936 return $compiler_info
1938 perror "No compiler info found."
1942 return [string match $compiler $compiler_info]
1945 proc current_target_name { } {
1947 if [info exists target_info(target,name)] {
1948 set answer $target_info(target,name)
1955 set gdb_wrapper_initialized 0
1956 set gdb_wrapper_target ""
1958 proc gdb_wrapper_init { args } {
1959 global gdb_wrapper_initialized;
1960 global gdb_wrapper_file;
1961 global gdb_wrapper_flags;
1962 global gdb_wrapper_target
1964 if { $gdb_wrapper_initialized == 1 } { return; }
1966 if {[target_info exists needs_status_wrapper] && \
1967 [target_info needs_status_wrapper] != "0"} {
1968 set result [build_wrapper "testglue.o"];
1969 if { $result != "" } {
1970 set gdb_wrapper_file [lindex $result 0];
1971 set gdb_wrapper_flags [lindex $result 1];
1973 warning "Status wrapper failed to build."
1976 set gdb_wrapper_initialized 1
1977 set gdb_wrapper_target [current_target_name]
1980 # Some targets need to always link a special object in. Save its path here.
1981 global gdb_saved_set_unbuffered_mode_obj
1982 set gdb_saved_set_unbuffered_mode_obj ""
1984 proc gdb_compile {source dest type options} {
1985 global GDB_TESTCASE_OPTIONS;
1986 global gdb_wrapper_file;
1987 global gdb_wrapper_flags;
1988 global gdb_wrapper_initialized;
1991 global gdb_saved_set_unbuffered_mode_obj
1993 set outdir [file dirname $dest]
1995 # Add platform-specific options if a shared library was specified using
1996 # "shlib=librarypath" in OPTIONS.
2000 foreach opt $options {
2001 if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] {
2002 if [test_compiler_info "xlc-*"] {
2003 # IBM xlc compiler doesn't accept shared library named other
2004 # than .so: use "-Wl," to bypass this
2005 lappend source "-Wl,$shlib_name"
2006 } elseif { ([istarget "*-*-mingw*"]
2007 || [istarget *-*-cygwin*]
2008 || [istarget *-*-pe*])} {
2009 lappend source "${shlib_name}.a"
2011 lappend source $shlib_name
2013 if { $shlib_found == 0 } {
2015 if { ([istarget "*-*-mingw*"]
2016 || [istarget *-*-cygwin*]) } {
2017 lappend new_options "additional_flags=-Wl,--enable-auto-import"
2020 } elseif { $opt == "shlib_load" } {
2023 lappend new_options $opt
2027 # We typically link to shared libraries using an absolute path, and
2028 # that's how they are found at runtime. If we are going to
2029 # dynamically load one by basename, we must specify rpath. If we
2030 # are using a remote host, DejaGNU will link to the shared library
2031 # using a relative path, so again we must specify an rpath.
2032 if { $shlib_load || ($shlib_found && [is_remote host]) } {
2033 if { ([istarget "*-*-mingw*"]
2034 || [istarget *-*-cygwin*]
2035 || [istarget *-*-pe*]
2036 || [istarget hppa*-*-hpux*])} {
2037 # Do not need anything.
2038 } elseif { [istarget *-*-openbsd*] } {
2039 lappend new_options "ldflags=-Wl,-rpath,${outdir}"
2040 } elseif { [istarget arm*-*-symbianelf*] } {
2041 if { $shlib_load } {
2042 lappend new_options "libs=-ldl"
2045 if { $shlib_load } {
2046 lappend new_options "libs=-ldl"
2048 lappend new_options "ldflags=-Wl,-rpath,\\\$ORIGIN"
2051 set options $new_options
2053 if [target_info exists gdb_stub] {
2054 set options2 { "additional_flags=-Dusestubs" }
2055 lappend options "libs=[target_info gdb_stub]";
2056 set options [concat $options2 $options]
2058 if [target_info exists is_vxworks] {
2059 set options2 { "additional_flags=-Dvxworks" }
2060 lappend options "libs=[target_info gdb_stub]";
2061 set options [concat $options2 $options]
2063 if [info exists GDB_TESTCASE_OPTIONS] {
2064 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
2066 verbose "options are $options"
2067 verbose "source is $source $dest $type $options"
2069 if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init }
2071 if {[target_info exists needs_status_wrapper] && \
2072 [target_info needs_status_wrapper] != "0" && \
2073 [info exists gdb_wrapper_file]} {
2074 lappend options "libs=${gdb_wrapper_file}"
2075 lappend options "ldflags=${gdb_wrapper_flags}"
2078 # Replace the "nowarnings" option with the appropriate additional_flags
2079 # to disable compiler warnings.
2080 set nowarnings [lsearch -exact $options nowarnings]
2081 if {$nowarnings != -1} {
2082 if [target_info exists gdb,nowarnings_flag] {
2083 set flag "additional_flags=[target_info gdb,nowarnings_flag]"
2085 set flag "additional_flags=-w"
2087 set options [lreplace $options $nowarnings $nowarnings $flag]
2090 if { $type == "executable" } {
2091 if { ([istarget "*-*-mingw*"]
2092 || [istarget "*-*-*djgpp"]
2093 || [istarget "*-*-cygwin*"])} {
2094 # Force output to unbuffered mode, by linking in an object file
2095 # with a global contructor that calls setvbuf.
2097 # Compile the special object seperatelly for two reasons:
2098 # 1) Insulate it from $options.
2099 # 2) Avoid compiling it for every gdb_compile invocation,
2100 # which is time consuming, especially if we're remote
2103 if { $gdb_saved_set_unbuffered_mode_obj == "" } {
2104 verbose "compiling gdb_saved_set_unbuffered_obj"
2105 set unbuf_src ${srcdir}/lib/set_unbuffered_mode.c
2106 set unbuf_obj ${objdir}/set_unbuffered_mode.o
2108 set result [gdb_compile "${unbuf_src}" "${unbuf_obj}" object {nowarnings}]
2109 if { $result != "" } {
2113 set gdb_saved_set_unbuffered_mode_obj ${objdir}/set_unbuffered_mode_saved.o
2114 # Link a copy of the output object, because the
2115 # original may be automatically deleted.
2116 remote_exec host "cp -f $unbuf_obj $gdb_saved_set_unbuffered_mode_obj"
2118 verbose "gdb_saved_set_unbuffered_obj already compiled"
2121 # Rely on the internal knowledge that the global ctors are ran in
2122 # reverse link order. In that case, we can use ldflags to
2123 # avoid copying the object file to the host multiple
2125 # This object can only be added if standard libraries are
2126 # used. Thus, we need to disable it if -nostdlib option is used
2127 if {[lsearch -regexp $options "-nostdlib"] < 0 } {
2128 lappend options "ldflags=$gdb_saved_set_unbuffered_mode_obj"
2133 set result [target_compile $source $dest $type $options];
2135 # Prune uninteresting compiler (and linker) output.
2136 regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result
2138 regsub "\[\r\n\]*$" "$result" "" result;
2139 regsub "^\[\r\n\]*" "$result" "" result;
2141 if {[lsearch $options quiet] < 0} {
2142 # We shall update this on a per language basis, to avoid
2143 # changing the entire testsuite in one go.
2144 if {[lsearch $options f77] >= 0} {
2145 gdb_compile_test $source $result
2146 } elseif { $result != "" } {
2147 clone_output "gdb compile failed, $result"
2154 # This is just like gdb_compile, above, except that it tries compiling
2155 # against several different thread libraries, to see which one this
2157 proc gdb_compile_pthreads {source dest type options} {
2159 set why_msg "unrecognized error"
2160 foreach lib {-lpthreads -lpthread -lthread ""} {
2161 # This kind of wipes out whatever libs the caller may have
2162 # set. Or maybe theirs will override ours. How infelicitous.
2163 set options_with_lib [concat $options [list libs=$lib quiet]]
2164 set ccout [gdb_compile $source $dest $type $options_with_lib]
2165 switch -regexp -- $ccout {
2166 ".*no posix threads support.*" {
2167 set why_msg "missing threads include file"
2170 ".*cannot open -lpthread.*" {
2171 set why_msg "missing runtime threads library"
2173 ".*Can't find library for -lpthread.*" {
2174 set why_msg "missing runtime threads library"
2177 pass "successfully compiled posix threads test case"
2183 if {!$built_binfile} {
2184 unsupported "Couldn't compile $source: ${why_msg}"
2189 # Build a shared library from SOURCES. You must use get_compiler_info
2192 proc gdb_compile_shlib {sources dest options} {
2193 set obj_options $options
2195 switch -glob [test_compiler_info] {
2197 lappend obj_options "additional_flags=-qpic"
2200 if { !([istarget "powerpc*-*-aix*"]
2201 || [istarget "rs6000*-*-aix*"]
2202 || [istarget "*-*-cygwin*"]
2203 || [istarget "*-*-mingw*"]
2204 || [istarget "*-*-pe*"]) } {
2205 lappend obj_options "additional_flags=-fpic"
2209 switch -glob [istarget] {
2211 lappend obj_options "additional_flags=+z"
2214 # Disable SGI compiler's implicit -Dsgi
2215 lappend obj_options "additional_flags=-Usgi"
2218 # don't know what the compiler is...
2224 set outdir [file dirname $dest]
2226 foreach source $sources {
2227 set sourcebase [file tail $source]
2228 if {[gdb_compile $source "${outdir}/${sourcebase}.o" object $obj_options] != ""} {
2231 lappend objects ${outdir}/${sourcebase}.o
2234 if [istarget "hppa*-*-hpux*"] {
2235 remote_exec build "ld -b ${objects} -o ${dest}"
2237 set link_options $options
2238 if [test_compiler_info "xlc-*"] {
2239 lappend link_options "additional_flags=-qmkshrobj"
2241 lappend link_options "additional_flags=-shared"
2243 if { ([istarget "*-*-mingw*"]
2244 || [istarget *-*-cygwin*]
2245 || [istarget *-*-pe*])} {
2246 lappend link_options "additional_flags=-Wl,--out-implib,${dest}.a"
2249 if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
2255 # This is just like gdb_compile_pthreads, above, except that we always add the
2256 # objc library for compiling Objective-C programs
2257 proc gdb_compile_objc {source dest type options} {
2259 set why_msg "unrecognized error"
2260 foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} {
2261 # This kind of wipes out whatever libs the caller may have
2262 # set. Or maybe theirs will override ours. How infelicitous.
2263 if { $lib == "solaris" } {
2264 set lib "-lpthread -lposix4"
2266 if { $lib != "-lobjc" } {
2267 set lib "-lobjc $lib"
2269 set options_with_lib [concat $options [list libs=$lib quiet]]
2270 set ccout [gdb_compile $source $dest $type $options_with_lib]
2271 switch -regexp -- $ccout {
2272 ".*no posix threads support.*" {
2273 set why_msg "missing threads include file"
2276 ".*cannot open -lpthread.*" {
2277 set why_msg "missing runtime threads library"
2279 ".*Can't find library for -lpthread.*" {
2280 set why_msg "missing runtime threads library"
2283 pass "successfully compiled objc with posix threads test case"
2289 if {!$built_binfile} {
2290 unsupported "Couldn't compile $source: ${why_msg}"
2295 proc send_gdb { string } {
2296 global suppress_flag;
2297 if { $suppress_flag } {
2298 return "suppressed";
2300 return [remote_send host "$string"];
2306 proc gdb_expect { args } {
2307 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
2308 set atimeout [lindex $args 0];
2309 set expcode [list [lindex $args 1]];
2314 upvar timeout timeout;
2316 if [target_info exists gdb,timeout] {
2317 if [info exists timeout] {
2318 if { $timeout < [target_info gdb,timeout] } {
2319 set gtimeout [target_info gdb,timeout];
2321 set gtimeout $timeout;
2324 set gtimeout [target_info gdb,timeout];
2328 if ![info exists gtimeout] {
2330 if [info exists timeout] {
2331 set gtimeout $timeout;
2335 if [info exists atimeout] {
2336 if { ![info exists gtimeout] || $gtimeout < $atimeout } {
2337 set gtimeout $atimeout;
2340 if ![info exists gtimeout] {
2346 global suppress_flag;
2347 global remote_suppress_flag;
2348 if [info exists remote_suppress_flag] {
2349 set old_val $remote_suppress_flag;
2351 if [info exists suppress_flag] {
2352 if { $suppress_flag } {
2353 set remote_suppress_flag 1;
2357 {uplevel remote_expect host $gtimeout $expcode} string];
2358 if [info exists old_val] {
2359 set remote_suppress_flag $old_val;
2361 if [info exists remote_suppress_flag] {
2362 unset remote_suppress_flag;
2367 global errorInfo errorCode;
2369 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
2370 } elseif {$code == 2} {
2371 return -code return $string
2372 } elseif {$code == 3} {
2374 } elseif {$code > 4} {
2375 return -code $code $string
2379 # gdb_expect_list MESSAGE SENTINEL LIST -- expect a sequence of outputs
2381 # Check for long sequence of output by parts.
2382 # MESSAGE: is the test message to be printed with the test success/fail.
2383 # SENTINEL: Is the terminal pattern indicating that output has finished.
2384 # LIST: is the sequence of outputs to match.
2385 # If the sentinel is recognized early, it is considered an error.
2388 # 1 if the test failed,
2389 # 0 if the test passes,
2390 # -1 if there was an internal error.
2392 proc gdb_expect_list {test sentinel list} {
2394 global suppress_flag
2397 if { $suppress_flag } {
2399 unresolved "${test}"
2401 while { ${index} < [llength ${list}] } {
2402 set pattern [lindex ${list} ${index}]
2403 set index [expr ${index} + 1]
2404 verbose -log "gdb_expect_list pattern: /$pattern/" 2
2405 if { ${index} == [llength ${list}] } {
2408 -re "${pattern}${sentinel}" {
2409 # pass "${test}, pattern ${index} + sentinel"
2412 fail "${test} (pattern ${index} + sentinel)"
2415 -re ".*A problem internal to GDB has been detected" {
2416 fail "${test} (GDB internal error)"
2418 gdb_internal_error_resync
2421 fail "${test} (pattern ${index} + sentinel) (timeout)"
2426 # unresolved "${test}, pattern ${index} + sentinel"
2432 # pass "${test}, pattern ${index}"
2435 fail "${test} (pattern ${index})"
2438 -re ".*A problem internal to GDB has been detected" {
2439 fail "${test} (GDB internal error)"
2441 gdb_internal_error_resync
2444 fail "${test} (pattern ${index}) (timeout)"
2449 # unresolved "${test}, pattern ${index}"
2463 proc gdb_suppress_entire_file { reason } {
2464 global suppress_flag;
2466 warning "$reason\n";
2467 set suppress_flag -1;
2471 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
2472 # gdb_expect to fail immediately (until the next call to
2473 # gdb_stop_suppressing_tests).
2475 proc gdb_suppress_tests { args } {
2476 global suppress_flag;
2478 return; # fnf - disable pending review of results where
2479 # testsuite ran better without this
2482 if { $suppress_flag == 1 } {
2483 if { [llength $args] > 0 } {
2484 warning "[lindex $args 0]\n";
2486 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
2492 # Clear suppress_flag.
2494 proc gdb_stop_suppressing_tests { } {
2495 global suppress_flag;
2497 if [info exists suppress_flag] {
2498 if { $suppress_flag > 0 } {
2499 set suppress_flag 0;
2500 clone_output "Tests restarted.\n";
2503 set suppress_flag 0;
2507 proc gdb_clear_suppressed { } {
2508 global suppress_flag;
2510 set suppress_flag 0;
2513 proc gdb_start { } {
2518 catch default_gdb_exit
2522 # gdb_load_cmd -- load a file into the debugger.
2523 # ARGS - additional args to load command.
2524 # return a -1 if anything goes wrong.
2526 proc gdb_load_cmd { args } {
2529 if [target_info exists gdb_load_timeout] {
2530 set loadtimeout [target_info gdb_load_timeout]
2532 set loadtimeout 1600
2534 send_gdb "load $args\n"
2535 verbose "Timeout is now $loadtimeout seconds" 2
2536 gdb_expect $loadtimeout {
2537 -re "Loading section\[^\r\]*\r\n" {
2540 -re "Start address\[\r\]*\r\n" {
2543 -re "Transfer rate\[\r\]*\r\n" {
2546 -re "Memory access error\[^\r\]*\r\n" {
2547 perror "Failed to load program"
2550 -re "$gdb_prompt $" {
2553 -re "(.*)\r\n$gdb_prompt " {
2554 perror "Unexpected reponse from 'load' -- $expect_out(1,string)"
2558 perror "Timed out trying to load $args."
2565 # Return the filename to download to the target and load on the target
2566 # for this shared library. Normally just LIBNAME, unless shared libraries
2567 # for this target have separate link and load images.
2569 proc shlib_target_file { libname } {
2573 # Return the filename GDB will load symbols from when debugging this
2574 # shared library. Normally just LIBNAME, unless shared libraries for
2575 # this target have separate link and load images.
2577 proc shlib_symbol_file { libname } {
2583 # Copy a file to the remote target and return its target filename.
2584 # Schedule the file to be deleted at the end of this test.
2586 proc gdb_download { filename } {
2589 set destname [remote_download target $filename]
2590 lappend cleanfiles $destname
2594 # gdb_load_shlibs LIB...
2596 # Copy the listed libraries to the target.
2598 proc gdb_load_shlibs { args } {
2599 if {![is_remote target]} {
2603 foreach file $args {
2604 gdb_download [shlib_target_file $file]
2607 # Even if the target supplies full paths for shared libraries,
2608 # they may not be paths for this system.
2609 gdb_test "set solib-search-path [file dirname [lindex $args 0]]" "" ""
2613 # gdb_load -- load a file into the debugger.
2614 # Many files in config/*.exp override this procedure.
2616 proc gdb_load { arg } {
2617 return [gdb_file_cmd $arg]
2620 # gdb_reload -- load a file into the target. Called before "running",
2621 # either the first time or after already starting the program once,
2622 # for remote targets. Most files that override gdb_load should now
2623 # override this instead.
2625 proc gdb_reload { } {
2626 # For the benefit of existing configurations, default to gdb_load.
2627 # Specifying no file defaults to the executable currently being
2629 return [gdb_load ""]
2632 proc gdb_continue { function } {
2635 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
2638 proc default_gdb_init { args } {
2639 global gdb_wrapper_initialized
2640 global gdb_wrapper_target
2645 gdb_clear_suppressed;
2647 # Make sure that the wrapper is rebuilt
2648 # with the appropriate multilib option.
2649 if { $gdb_wrapper_target != [current_target_name] } {
2650 set gdb_wrapper_initialized 0
2653 # Unlike most tests, we have a small number of tests that generate
2654 # a very large amount of output. We therefore increase the expect
2655 # buffer size to be able to contain the entire test output.
2657 # Also set this value for the currently running GDB.
2658 match_max [match_max -d]
2660 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
2661 if { [llength $args] > 0 } {
2664 set file [lindex $args 0];
2666 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
2669 if [target_info exists gdb_prompt] {
2670 set gdb_prompt [target_info gdb_prompt];
2672 set gdb_prompt "\\(gdb\\)"
2676 # The default timeout used when testing GDB commands. We want to use
2677 # the same timeout as the default dejagnu timeout, unless the user has
2678 # already provided a specific value (probably through a site.exp file).
2679 global gdb_test_timeout
2680 if ![info exists gdb_test_timeout] {
2681 set gdb_test_timeout $timeout
2684 # A list of global variables that GDB testcases should not use.
2685 # We try to prevent their use by monitoring write accesses and raising
2686 # an error when that happens.
2687 set banned_variables { bug_id prms_id }
2689 # gdb_init is called by runtest at start, but also by several
2690 # tests directly; gdb_finish is only called from within runtest after
2691 # each test source execution.
2692 # Placing several traces by repetitive calls to gdb_init leads
2693 # to problems, as only one trace is removed in gdb_finish.
2694 # To overcome this possible problem, we add a variable that records
2695 # if the banned variables are traced.
2696 set banned_variables_traced 0
2698 proc gdb_init { args } {
2699 # Reset the timeout value to the default. This way, any testcase
2700 # that changes the timeout value without resetting it cannot affect
2701 # the timeout used in subsequent testcases.
2702 global gdb_test_timeout
2704 set timeout $gdb_test_timeout
2706 # Block writes to all banned variables...
2707 global banned_variables
2708 global banned_variables_traced
2709 if (!$banned_variables_traced) {
2710 foreach banned_var $banned_variables {
2711 global "$banned_var"
2712 trace add variable "$banned_var" write error
2714 set banned_variables_traced 1
2717 # We set LC_ALL and LANG to C so that we get the same messages as
2722 return [eval default_gdb_init $args];
2725 proc gdb_finish { } {
2728 # Exit first, so that the files are no longer in use.
2731 if { [llength $cleanfiles] > 0 } {
2732 eval remote_file target delete $cleanfiles
2736 # Unblock write access to the banned variables. Dejagnu typically
2737 # resets some of them between testcases.
2738 global banned_variables
2739 global banned_variables_traced
2740 if ($banned_variables_traced) {
2741 foreach banned_var $banned_variables {
2742 global "$banned_var"
2743 trace remove variable "$banned_var" write error
2745 set banned_variables_traced 0
2750 set debug_format "unknown"
2752 # Run the gdb command "info source" and extract the debugging format
2753 # information from the output and save it in debug_format.
2755 proc get_debug_format { } {
2761 set debug_format "unknown"
2762 send_gdb "info source\n"
2764 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
2765 set debug_format $expect_out(1,string)
2766 verbose "debug format is $debug_format"
2769 -re "No current source file.\r\n$gdb_prompt $" {
2770 perror "get_debug_format used when no current source file"
2773 -re "$gdb_prompt $" {
2774 warning "couldn't check debug format (no valid response)."
2778 warning "couldn't check debug format (timed out)."
2784 # Return true if FORMAT matches the debug format the current test was
2785 # compiled with. FORMAT is a shell-style globbing pattern; it can use
2786 # `*', `[...]', and so on.
2788 # This function depends on variables set by `get_debug_format', above.
2790 proc test_debug_format {format} {
2793 return [expr [string match $format $debug_format] != 0]
2796 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
2797 # COFF, stabs, etc). If that format matches the format that the
2798 # current test was compiled with, then the next test is expected to
2799 # fail for any target. Returns 1 if the next test or set of tests is
2800 # expected to fail, 0 otherwise (or if it is unknown). Must have
2801 # previously called get_debug_format.
2802 proc setup_xfail_format { format } {
2803 set ret [test_debug_format $format];
2811 proc gdb_step_for_stub { } {
2814 if ![target_info exists gdb,use_breakpoint_for_stub] {
2815 if [target_info exists gdb_stub_step_command] {
2816 set command [target_info gdb_stub_step_command];
2820 send_gdb "${command}\n";
2823 -re "(main.* at |.*in .*start).*$gdb_prompt" {
2826 -re ".*$gdb_prompt" {
2828 if { $tries == 5 } {
2829 fail "stepping out of breakpoint function";
2832 send_gdb "${command}\n";
2836 fail "stepping out of breakpoint function";
2843 -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" {
2844 set file $expect_out(1,string);
2845 set linenum [expr $expect_out(2,string) + 1];
2846 set breakplace "${file}:${linenum}";
2850 send_gdb "break ${breakplace}\n";
2852 -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" {
2853 set breakpoint $expect_out(1,string);
2855 -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" {
2856 set breakpoint $expect_out(1,string);
2860 send_gdb "continue\n";
2862 -re "Breakpoint ${breakpoint},.*$gdb_prompt" {
2863 gdb_test "delete $breakpoint" ".*" "";
2870 # gdb_get_line_number TEXT [FILE]
2872 # Search the source file FILE, and return the line number of the
2873 # first line containing TEXT. If no match is found, return -1.
2875 # TEXT is a string literal, not a regular expression.
2877 # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is
2878 # specified, and does not start with "/", then it is assumed to be in
2879 # "$srcdir/$subdir". This is awkward, and can be fixed in the future,
2880 # by changing the callers and the interface at the same time.
2881 # In particular: gdb.base/break.exp, gdb.base/condbreak.exp,
2882 # gdb.base/ena-dis-br.exp.
2884 # Use this function to keep your test scripts independent of the
2885 # exact line numbering of the source file. Don't write:
2887 # send_gdb "break 20"
2889 # This means that if anyone ever edits your test's source file,
2890 # your test could break. Instead, put a comment like this on the
2891 # source file line you want to break at:
2893 # /* breakpoint spot: frotz.exp: test name */
2895 # and then write, in your test script (which we assume is named
2898 # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
2900 # (Yes, Tcl knows how to handle the nested quotes and brackets.
2903 # % puts "foo [lindex "bar baz" 1]"
2906 # Tcl is quite clever, for a little stringy language.)
2910 # The previous implementation of this procedure used the gdb search command.
2911 # This version is different:
2913 # . It works with MI, and it also works when gdb is not running.
2915 # . It operates on the build machine, not the host machine.
2917 # . For now, this implementation fakes a current directory of
2918 # $srcdir/$subdir to be compatible with the old implementation.
2919 # This will go away eventually and some callers will need to
2922 # . The TEXT argument is literal text and matches literally,
2923 # not a regular expression as it was before.
2925 # . State changes in gdb, such as changing the current file
2926 # and setting $_, no longer happen.
2928 # After a bit of time we can forget about the differences from the
2929 # old implementation.
2931 # --chastain 2004-08-05
2933 proc gdb_get_line_number { text { file "" } } {
2938 if { "$file" == "" } then {
2941 if { ! [regexp "^/" "$file"] } then {
2942 set file "$srcdir/$subdir/$file"
2945 if { [ catch { set fd [open "$file"] } message ] } then {
2951 for { set line 1 } { 1 } { incr line } {
2952 if { [ catch { set nchar [gets "$fd" body] } message ] } then {
2956 if { $nchar < 0 } then {
2959 if { [string first "$text" "$body"] >= 0 } then {
2965 if { [ catch { close "$fd" } message ] } then {
2973 # gdb_continue_to_end:
2974 # The case where the target uses stubs has to be handled specially. If a
2975 # stub is used, we set a breakpoint at exit because we cannot rely on
2976 # exit() behavior of a remote target.
2978 # mssg is the error message that gets printed.
2980 proc gdb_continue_to_end {mssg} {
2981 if [target_info exists use_gdb_stub] {
2982 if {![gdb_breakpoint "exit"]} {
2985 gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \
2986 "continue until exit at $mssg"
2988 # Continue until we exit. Should not stop again.
2989 # Don't bother to check the output of the program, that may be
2990 # extremely tough for some remote systems.
2991 gdb_test "continue"\
2992 "Continuing.\[\r\n0-9\]+(... EXIT code 0\[\r\n\]+|Program exited normally\\.).*"\
2993 "continue until exit at $mssg"
2997 proc rerun_to_main {} {
3000 if [target_info exists use_gdb_stub] {
3003 -re ".*Breakpoint .*main .*$gdb_prompt $"\
3004 {pass "rerun to main" ; return 0}
3005 -re "$gdb_prompt $"\
3006 {fail "rerun to main" ; return 0}
3007 timeout {fail "(timeout) rerun to main" ; return 0}
3012 -re "The program .* has been started already.*y or n. $" {
3016 -re "Starting program.*$gdb_prompt $"\
3017 {pass "rerun to main" ; return 0}
3018 -re "$gdb_prompt $"\
3019 {fail "rerun to main" ; return 0}
3020 timeout {fail "(timeout) rerun to main" ; return 0}
3025 # Print a message and return true if a test should be skipped
3026 # due to lack of floating point suport.
3028 proc gdb_skip_float_test { msg } {
3029 if [target_info exists gdb,skip_float_tests] {
3030 verbose "Skipping test '$msg': no float tests.";
3036 # Print a message and return true if a test should be skipped
3037 # due to lack of stdio support.
3039 proc gdb_skip_stdio_test { msg } {
3040 if [target_info exists gdb,noinferiorio] {
3041 verbose "Skipping test '$msg': no inferior i/o.";
3047 proc gdb_skip_bogus_test { msg } {
3051 # Return true if a test should be skipped due to lack of XML support
3053 # NOTE: This must be called while gdb is *not* running.
3055 proc gdb_skip_xml_test { } {
3058 global xml_missing_cached
3060 if {[info exists xml_missing_cached]} {
3061 return $xml_missing_cached
3065 set xml_missing_cached 0
3066 gdb_test_multiple "set tdesc filename ${srcdir}/gdb.xml/trivial.xml" "" {
3067 -re ".*XML support was disabled at compile time.*$gdb_prompt $" {
3068 set xml_missing_cached 1
3070 -re ".*$gdb_prompt $" { }
3073 return $xml_missing_cached
3076 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
3077 # ${binfile}.dbglnk, which is just like the executable ($binfile) but without
3078 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
3079 # the name of a debuginfo only file. This file will be stored in the same
3082 # Functions for separate debug info testing
3084 # starting with an executable:
3085 # foo --> original executable
3087 # at the end of the process we have:
3088 # foo.stripped --> foo w/o debug info
3089 # foo.debug --> foo's debug info
3090 # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug.
3092 # Return the build-id hex string (usually 160 bits as 40 hex characters)
3093 # converted to the form: .build-id/ab/cdef1234...89.debug
3094 # Return "" if no build-id found.
3095 proc build_id_debug_filename_get { exec } {
3096 set tmp "${exec}-tmp"
3097 set objcopy_program [transform objcopy]
3099 set result [catch "exec $objcopy_program -j .note.gnu.build-id -O binary $exec $tmp" output]
3100 verbose "result is $result"
3101 verbose "output is $output"
3106 fconfigure $fi -translation binary
3107 # Skip the NOTE header.
3112 if ![string compare $data ""] then {
3115 # Convert it to hex.
3116 binary scan $data H* data
3117 regsub {^..} $data {\0/} data
3118 return ".build-id/${data}.debug";
3121 # Create stripped files for DEST, replacing it. If ARGS is passed, it is a
3122 # list of optional flags. The only currently supported flag is no-main,
3123 # which removes the symbol entry for main from the separate debug file.
3125 # Function returns zero on success. Function will return non-zero failure code
3126 # on some targets not supporting separate debug info (such as i386-msdos).
3128 proc gdb_gnu_strip_debug { dest args } {
3130 # Use the first separate debug info file location searched by GDB so the
3131 # run cannot be broken by some stale file searched with higher precedence.
3132 set debug_file "${dest}.debug"
3134 set strip_to_file_program [transform strip]
3135 set objcopy_program [transform objcopy]
3137 set debug_link [file tail $debug_file]
3138 set stripped_file "${dest}.stripped"
3140 # Get rid of the debug info, and store result in stripped_file
3141 # something like gdb/testsuite/gdb.base/blah.stripped.
3142 set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
3143 verbose "result is $result"
3144 verbose "output is $output"
3149 # Workaround PR binutils/10802:
3150 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
3151 set perm [file attributes ${dest} -permissions]
3152 file attributes ${stripped_file} -permissions $perm
3154 # Get rid of everything but the debug info, and store result in debug_file
3155 # This will be in the .debug subdirectory, see above.
3156 set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
3157 verbose "result is $result"
3158 verbose "output is $output"
3163 # If no-main is passed, strip the symbol for main from the separate
3164 # file. This is to simulate the behavior of elfutils's eu-strip, which
3165 # leaves the symtab in the original file only. There's no way to get
3166 # objcopy or strip to remove the symbol table without also removing the
3167 # debugging sections, so this is as close as we can get.
3168 if { [llength $args] == 1 && [lindex $args 0] == "no-main" } {
3169 set result [catch "exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp" output]
3170 verbose "result is $result"
3171 verbose "output is $output"
3175 file delete "${debug_file}"
3176 file rename "${debug_file}-tmp" "${debug_file}"
3179 # Link the two previous output files together, adding the .gnu_debuglink
3180 # section to the stripped_file, containing a pointer to the debug_file,
3181 # save the new file in dest.
3182 # This will be the regular executable filename, in the usual location.
3183 set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
3184 verbose "result is $result"
3185 verbose "output is $output"
3190 # Workaround PR binutils/10802:
3191 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
3192 set perm [file attributes ${stripped_file} -permissions]
3193 file attributes ${dest} -permissions $perm
3198 # Test the output of GDB_COMMAND matches the pattern obtained
3199 # by concatenating all elements of EXPECTED_LINES. This makes
3200 # it possible to split otherwise very long string into pieces.
3201 # If third argument is not empty, it's used as the name of the
3202 # test to be printed on pass/fail.
3203 proc help_test_raw { gdb_command expected_lines args } {
3204 set message $gdb_command
3205 if [llength $args]>0 then {
3206 set message [lindex $args 0]
3208 set expected_output [join $expected_lines ""]
3209 gdb_test "${gdb_command}" "${expected_output}" $message
3212 # Test the output of "help COMMNAD_CLASS". EXPECTED_INITIAL_LINES
3213 # are regular expressions that should match the beginning of output,
3214 # before the list of commands in that class. The presence of
3215 # command list and standard epilogue will be tested automatically.
3216 proc test_class_help { command_class expected_initial_lines args } {
3218 "List of commands\:.*\[\r\n\]+"
3219 "Type \"help\" followed by command name for full documentation\.\[\r\n\]+"
3220 "Type \"apropos word\" to search for commands related to \"word\"\.[\r\n\]+"
3221 "Command name abbreviations are allowed if unambiguous\."
3223 set l_entire_body [concat $expected_initial_lines $l_stock_body]
3225 eval [list help_test_raw "help ${command_class}" $l_entire_body] $args
3228 # COMMAND_LIST should have either one element -- command to test, or
3229 # two elements -- abbreviated command to test, and full command the first
3230 # element is abbreviation of.
3231 # The command must be a prefix command. EXPECTED_INITIAL_LINES
3232 # are regular expressions that should match the beginning of output,
3233 # before the list of subcommands. The presence of
3234 # subcommand list and standard epilogue will be tested automatically.
3235 proc test_prefix_command_help { command_list expected_initial_lines args } {
3236 set command [lindex $command_list 0]
3237 if {[llength $command_list]>1} {
3238 set full_command [lindex $command_list 1]
3240 set full_command $command
3242 # Use 'list' and not just {} because we want variables to
3243 # be expanded in this list.
3244 set l_stock_body [list\
3245 "List of $full_command subcommands\:.*\[\r\n\]+"\
3246 "Type \"help $full_command\" followed by $full_command subcommand name for full documentation\.\[\r\n\]+"\
3247 "Type \"apropos word\" to search for commands related to \"word\"\.\[\r\n\]+"\
3248 "Command name abbreviations are allowed if unambiguous\."]
3249 set l_entire_body [concat $expected_initial_lines $l_stock_body]
3250 if {[llength $args]>0} {
3251 help_test_raw "help ${command}" $l_entire_body [lindex $args 0]
3253 help_test_raw "help ${command}" $l_entire_body
3257 # Build executable named EXECUTABLE, from SOURCES. If SOURCES are not
3258 # provided, uses $EXECUTABLE.c. The TESTNAME paramer is the name of test
3259 # to pass to untested, if something is wrong. OPTIONS are passed
3260 # to gdb_compile directly.
3261 proc build_executable { testname executable {sources ""} {options {debug}} } {
3266 if {[llength $sources]==0} {
3267 set sources ${executable}.c
3270 set binfile ${objdir}/${subdir}/${executable}
3273 for {set i 0} "\$i<[llength $sources]" {incr i} {
3274 set s [lindex $sources $i]
3275 if { [gdb_compile "${srcdir}/${subdir}/${s}" "${binfile}${i}.o" object $options] != "" } {
3279 lappend objects "${binfile}${i}.o"
3282 if { [gdb_compile $objects "${binfile}" executable $options] != "" } {
3288 if { [lsearch -exact $options "c++"] >= 0 } {
3289 set info_options "c++"
3291 if [get_compiler_info ${binfile} ${info_options}] {
3297 # Starts fresh GDB binary and loads EXECUTABLE into GDB. EXECUTABLE is
3298 # the name of binary in ${objdir}/${subdir}.
3299 proc clean_restart { executable } {
3303 set binfile ${objdir}/${subdir}/${executable}
3307 gdb_reinitialize_dir $srcdir/$subdir
3310 if [target_info exists gdb_stub] {
3315 # Prepares for testing, by calling build_executable, and then clean_restart.
3316 # Please refer to build_executable for parameter description.
3317 proc prepare_for_testing { testname executable {sources ""} {options {debug}}} {
3319 if {[build_executable $testname $executable $sources $options] == -1} {
3322 clean_restart $executable
3327 proc get_valueof { fmt exp default } {
3330 set test "get valueof \"${exp}\""
3332 gdb_test_multiple "print${fmt} ${exp}" "$test" {
3333 -re "\\$\[0-9\]* = (.*)\[\r\n\]*$gdb_prompt $" {
3334 set val $expect_out(1,string)
3338 fail "$test (timeout)"
3344 proc get_integer_valueof { exp default } {
3347 set test "get integer valueof \"${exp}\""
3349 gdb_test_multiple "print /d ${exp}" "$test" {
3350 -re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" {
3351 set val $expect_out(1,string)
3355 fail "$test (timeout)"
3361 proc get_hexadecimal_valueof { exp default } {
3363 send_gdb "print /x ${exp}\n"
3364 set test "get hexadecimal valueof \"${exp}\""
3366 -re "\\$\[0-9\]* = (0x\[0-9a-zA-Z\]+).*$gdb_prompt $" {
3367 set val $expect_out(1,string)
3372 fail "$test (timeout)"
3378 proc get_sizeof { type default } {
3379 return [get_integer_valueof "sizeof (${type})" $default]
3382 # Log gdb command line and script if requested.
3383 if {[info exists TRANSCRIPT]} {
3384 rename send_gdb real_send_gdb
3385 rename remote_spawn real_remote_spawn
3386 rename remote_close real_remote_close
3388 global gdb_transcript
3389 set gdb_transcript ""
3391 global gdb_trans_count
3392 set gdb_trans_count 1
3394 proc remote_spawn {args} {
3395 global gdb_transcript gdb_trans_count outdir
3397 if {$gdb_transcript != ""} {
3398 close $gdb_transcript
3400 set gdb_transcript [open [file join $outdir transcript.$gdb_trans_count] w]
3401 puts $gdb_transcript [lindex $args 1]
3402 incr gdb_trans_count
3404 return [uplevel real_remote_spawn $args]
3407 proc remote_close {args} {
3408 global gdb_transcript
3410 if {$gdb_transcript != ""} {
3411 close $gdb_transcript
3412 set gdb_transcript ""
3415 return [uplevel real_remote_close $args]
3418 proc send_gdb {args} {
3419 global gdb_transcript
3421 if {$gdb_transcript != ""} {
3422 puts -nonewline $gdb_transcript [lindex $args 0]
3425 return [uplevel real_send_gdb $args]
3429 proc core_find {binfile {deletefiles {}} {arg ""}} {
3430 global objdir subdir
3432 set destcore "$binfile.core"
3433 file delete $destcore
3435 # Create a core file named "$destcore" rather than just "core", to
3436 # avoid problems with sys admin types that like to regularly prune all
3437 # files named "core" from the system.
3439 # Arbitrarily try setting the core size limit to "unlimited" since
3440 # this does not hurt on systems where the command does not work and
3441 # allows us to generate a core on systems where it does.
3443 # Some systems append "core" to the name of the program; others append
3444 # the name of the program to "core"; still others (like Linux, as of
3445 # May 2003) create cores named "core.PID". In the latter case, we
3446 # could have many core files lying around, and it may be difficult to
3447 # tell which one is ours, so let's run the program in a subdirectory.
3449 set coredir "${objdir}/${subdir}/coredir.[getpid]"
3451 catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile} ${arg}; true) >/dev/null 2>&1\""
3452 # remote_exec host "${binfile}"
3453 foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
3454 if [remote_file build exists $i] {
3455 remote_exec build "mv $i $destcore"
3459 # Check for "core.PID".
3460 if { $found == 0 } {
3461 set names [glob -nocomplain -directory $coredir core.*]
3462 if {[llength $names] == 1} {
3463 set corefile [file join $coredir [lindex $names 0]]
3464 remote_exec build "mv $corefile $destcore"
3468 if { $found == 0 } {
3469 # The braindamaged HPUX shell quits after the ulimit -c above
3470 # without executing ${binfile}. So we try again without the
3471 # ulimit here if we didn't find a core file above.
3472 # Oh, I should mention that any "braindamaged" non-Unix system has
3473 # the same problem. I like the cd bit too, it's really neat'n stuff.
3474 catch "system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\""
3475 foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" {
3476 if [remote_file build exists $i] {
3477 remote_exec build "mv $i $destcore"
3483 # Try to clean up after ourselves.
3484 foreach deletefile $deletefiles {
3485 remote_file build delete [file join $coredir $deletefile]
3487 remote_exec build "rmdir $coredir"
3489 if { $found == 0 } {
3490 warning "can't generate a core file - core tests suppressed - check ulimit -c"