1 # Copyright 1992-2005, 2007-2012 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # This file was written by Fred Fish. (fnf@cygnus.com)
18 # Generic gdb subroutines that should work for any target. If these
19 # need to be modified for any target, it can be done with a variable
20 # or by passing arguments.
23 # Tests would fail, logs on get_compiler_info() would be missing.
24 send_error "`site.exp' not found, run `make site.exp'!\n"
32 if [info exists TOOL_EXECUTABLE] {
33 set GDB $TOOL_EXECUTABLE;
35 if ![info exists GDB] {
36 if ![is_remote host] {
37 set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]]
39 set GDB [transform gdb];
42 verbose "using GDB = $GDB" 2
44 # GDBFLAGS is available for the user to set on the command line.
45 # E.g. make check RUNTESTFLAGS=GDBFLAGS=mumble
46 # Testcases may use it to add additional flags, but they must:
47 # - append new flags, not overwrite
48 # - restore the original value when done
50 if ![info exists GDBFLAGS] {
53 verbose "using GDBFLAGS = $GDBFLAGS" 2
55 # Make the build data directory available to tests.
56 set BUILD_DATA_DIRECTORY "[pwd]/../data-directory"
58 # INTERNAL_GDBFLAGS contains flags that the testsuite requires.
59 global INTERNAL_GDBFLAGS
60 if ![info exists INTERNAL_GDBFLAGS] {
61 set INTERNAL_GDBFLAGS "-nw -nx -data-directory $BUILD_DATA_DIRECTORY"
64 # The variable gdb_prompt is a regexp which matches the gdb prompt.
65 # Set it if it is not already set.
67 if ![info exists gdb_prompt] then {
68 set gdb_prompt "\[(\]gdb\[)\]"
71 # The variable fullname_syntax_POSIX is a regexp which matches a POSIX
72 # absolute path ie. /foo/
73 set fullname_syntax_POSIX {/[^\n]*/}
74 # The variable fullname_syntax_UNC is a regexp which matches a Windows
75 # UNC path ie. \\D\foo\
76 set fullname_syntax_UNC {\\\\[^\\]+\\[^\n]+\\}
77 # The variable fullname_syntax_DOS_CASE is a regexp which matches a
78 # particular DOS case that GDB most likely will output
79 # ie. \foo\, but don't match \\.*\
80 set fullname_syntax_DOS_CASE {\\[^\\][^\n]*\\}
81 # The variable fullname_syntax_DOS is a regexp which matches a DOS path
82 # ie. a:\foo\ && a:foo\
83 set fullname_syntax_DOS {[a-zA-Z]:[^\n]*\\}
84 # The variable fullname_syntax is a regexp which matches what GDB considers
85 # an absolute path. It is currently debatable if the Windows style paths
86 # d:foo and \abc should be considered valid as an absolute path.
87 # Also, the purpse of this regexp is not to recognize a well formed
88 # absolute path, but to say with certainty that a path is absolute.
89 set fullname_syntax "($fullname_syntax_POSIX|$fullname_syntax_UNC|$fullname_syntax_DOS_CASE|$fullname_syntax_DOS)"
91 # Needed for some tests under Cygwin.
95 if ![info exists env(EXEEXT)] {
98 set EXEEXT $env(EXEEXT)
103 set inferior_exited_re "(\\\[Inferior \[0-9\]+ \\(.*\\) exited)"
105 ### Only procedures should come after this point.
108 # gdb_version -- extract and print the version number of GDB
110 proc default_gdb_version {} {
112 global INTERNAL_GDBFLAGS GDBFLAGS
114 set output [remote_exec host "$GDB $INTERNAL_GDBFLAGS --version"]
115 set tmp [lindex $output 1];
117 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
118 if ![is_remote host] {
119 clone_output "[which $GDB] version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
121 clone_output "$GDB on remote host version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
125 proc gdb_version { } {
126 return [default_gdb_version];
130 # gdb_unload -- unload a file if one is loaded
131 # Return 0 on success, -1 on error.
140 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
141 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
142 -re "A program is being debugged already.*Are you sure you want to change the file.*y or n. $" {
146 -re "Discard symbol table from .*y or n.*$" {
150 -re "$gdb_prompt $" {}
152 perror "couldn't unload file in $GDB (timeout)."
159 # Many of the tests depend on setting breakpoints at various places and
160 # running until that breakpoint is reached. At times, we want to start
161 # with a clean-slate with respect to breakpoints, so this utility proc
162 # lets us do this without duplicating this code everywhere.
165 proc delete_breakpoints {} {
168 # we need a larger timeout value here or this thing just confuses
169 # itself. May need a better implementation if possible. - guo
171 send_gdb "delete breakpoints\n"
173 -re "Delete all breakpoints.*y or n.*$" {
177 -re "$gdb_prompt $" { # This happens if there were no breakpoints
179 timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
181 send_gdb "info breakpoints\n"
183 -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
184 -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
185 -re "Delete all breakpoints.*or n.*$" {
189 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 # N.B. This function does not wait for gdb to return to the prompt,
200 # that is the caller's responsibility.
202 proc gdb_run_cmd {args} {
203 global gdb_prompt use_gdb_stub
205 if [target_info exists gdb_init_command] {
206 send_gdb "[target_info gdb_init_command]\n";
208 -re "$gdb_prompt $" { }
210 perror "gdb_init_command for target failed";
217 if [target_info exists gdb,do_reload_on_run] {
218 if { [gdb_reload] != 0 } {
221 send_gdb "continue\n";
223 -re "Continu\[^\r\n\]*\[\r\n\]" {}
229 if [target_info exists gdb,start_symbol] {
230 set start [target_info gdb,start_symbol];
234 send_gdb "jump *$start\n"
236 while { $start_attempt } {
237 # Cap (re)start attempts at three to ensure that this loop
238 # always eventually fails. Don't worry about trying to be
239 # clever and not send a command when it has failed.
240 if [expr $start_attempt > 3] {
241 perror "Jump to start() failed (retry count exceeded)";
244 set start_attempt [expr $start_attempt + 1];
246 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
249 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
250 perror "Can't find start symbol to run in gdb_run";
253 -re "No symbol \"start\" in current.*$gdb_prompt $" {
254 send_gdb "jump *_start\n";
256 -re "No symbol.*context.*$gdb_prompt $" {
259 -re "Line.* Jump anyway.*y or n. $" {
262 -re "The program is not being run.*$gdb_prompt $" {
263 if { [gdb_reload] != 0 } {
266 send_gdb "jump *$start\n";
269 perror "Jump to start() failed (timeout)";
277 if [target_info exists gdb,do_reload_on_run] {
278 if { [gdb_reload] != 0 } {
282 send_gdb "run $args\n"
283 # This doesn't work quite right yet.
284 # Use -notransfer here so that test cases (like chng-sym.exp)
285 # may test for additional start-up messages.
287 -re "The program .* has been started already.*y or n. $" {
291 -notransfer -re "Starting program: \[^\r\n\]*" {}
292 -notransfer -re "$gdb_prompt $" {
293 # There is no more input expected.
298 # Generic start command. Return 0 if we could start the program, -1
301 # N.B. This function does not wait for gdb to return to the prompt,
302 # that is the caller's responsibility.
304 proc gdb_start_cmd {args} {
305 global gdb_prompt use_gdb_stub
307 if [target_info exists gdb_init_command] {
308 send_gdb "[target_info gdb_init_command]\n";
310 -re "$gdb_prompt $" { }
312 perror "gdb_init_command for target failed";
322 send_gdb "start $args\n"
323 # Use -notransfer here so that test cases (like chng-sym.exp)
324 # may test for additional start-up messages.
326 -re "The program .* has been started already.*y or n. $" {
330 -notransfer -re "Starting program: \[^\r\n\]*" {
337 # Set a breakpoint at FUNCTION. If there is an additional argument it is
338 # a list of options; the supported options are allow-pending, temporary,
339 # message, no-message, and passfail.
340 # The result is 1 for success, 0 for failure.
342 # Note: The handling of message vs no-message is messed up, but it's based
343 # on historical usage. By default this function does not print passes,
345 # no-message: turns off printing of fails (and passes, but they're already off)
346 # message: turns on printing of passes (and fails, but they're already on)
348 proc gdb_breakpoint { function args } {
352 set pending_response n
353 if {[lsearch -exact $args allow-pending] != -1} {
354 set pending_response y
357 set break_command "break"
358 set break_message "Breakpoint"
359 if {[lsearch -exact $args temporary] != -1} {
360 set break_command "tbreak"
361 set break_message "Temporary breakpoint"
366 set no_message_loc [lsearch -exact $args no-message]
367 set message_loc [lsearch -exact $args message]
368 # The last one to appear in args wins.
369 if { $no_message_loc > $message_loc } {
371 } elseif { $message_loc > $no_message_loc } {
375 set test_name "setting breakpoint at $function"
377 send_gdb "$break_command $function\n"
378 # The first two regexps are what we get with -g, the third is without -g.
380 -re "$break_message \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
381 -re "$break_message \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
382 -re "$break_message \[0-9\]* at .*$gdb_prompt $" {}
383 -re "$break_message \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" {
384 if {$pending_response == "n"} {
391 -re "Make breakpoint pending.*y or \\\[n\\\]. $" {
392 send_gdb "$pending_response\n"
395 -re "A problem internal to GDB has been detected" {
397 fail "$test_name (GDB internal error)"
399 gdb_internal_error_resync
402 -re "$gdb_prompt $" {
410 fail "$test_name (eof)"
416 fail "$test_name (timeout)"
427 # Set breakpoint at function and run gdb until it breaks there.
428 # Since this is the only breakpoint that will be set, if it stops
429 # at a breakpoint, we will assume it is the one we want. We can't
430 # just compare to "function" because it might be a fully qualified,
431 # single quoted C++ function specifier.
433 # If there are additional arguments, pass them to gdb_breakpoint.
434 # We recognize no-message/message ourselves.
435 # The default is no-message.
436 # no-message is messed up here, like gdb_breakpoint: to preserve
437 # historical usage fails are always printed by default.
438 # no-message: turns off printing of fails (and passes, but they're already off)
439 # message: turns on printing of passes (and fails, but they're already on)
441 proc runto { function args } {
447 # Default to "no-message".
448 set args "no-message $args"
452 set no_message_loc [lsearch -exact $args no-message]
453 set message_loc [lsearch -exact $args message]
454 # The last one to appear in args wins.
455 if { $no_message_loc > $message_loc } {
457 } elseif { $message_loc > $no_message_loc } {
461 set test_name "running to $function in runto"
463 # We need to use eval here to pass our varargs args to gdb_breakpoint
464 # which is also a varargs function.
465 # But we also have to be careful because $function may have multiple
466 # elements, and we don't want Tcl to move the remaining elements after
467 # the first to $args. That is why $function is wrapped in {}.
468 if ![eval gdb_breakpoint {$function} $args] {
474 # the "at foo.c:36" output we get with -g.
475 # the "in func" output we get without -g.
477 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
483 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
489 -re "The target does not support running in non-stop mode.\r\n$gdb_prompt $" {
491 unsupported "Non-stop mode not supported"
495 -re ".*A problem internal to GDB has been detected" {
497 fail "$test_name (GDB internal error)"
499 gdb_internal_error_resync
502 -re "$gdb_prompt $" {
510 fail "$test_name (eof)"
516 fail "$test_name (timeout)"
527 # Ask gdb to run until we hit a breakpoint at main.
529 # N.B. This function deletes all existing breakpoints.
530 # If you don't want that, use gdb_start_cmd.
532 proc runto_main { } {
533 return [runto main no-message]
536 ### Continue, and expect to hit a breakpoint.
537 ### Report a pass or fail, depending on whether it seems to have
538 ### worked. Use NAME as part of the test name; each call to
539 ### continue_to_breakpoint should use a NAME which is unique within
541 proc gdb_continue_to_breakpoint {name {location_pattern .*}} {
543 set full_name "continue to breakpoint: $name"
545 send_gdb "continue\n"
547 -re "(?:Breakpoint|Temporary breakpoint) .* (at|in) $location_pattern\r\n$gdb_prompt $" {
550 -re ".*$gdb_prompt $" {
554 fail "$full_name (timeout)"
560 # gdb_internal_error_resync:
562 # Answer the questions GDB asks after it reports an internal error
563 # until we get back to a GDB prompt. Decline to quit the debugging
564 # session, and decline to create a core file. Return non-zero if the
567 # This procedure just answers whatever questions come up until it sees
568 # a GDB prompt; it doesn't require you to have matched the input up to
569 # any specific point. However, it only answers questions it sees in
570 # the output itself, so if you've matched a question, you had better
571 # answer it yourself before calling this.
573 # You can use this function thus:
577 # -re ".*A problem internal to GDB has been detected" {
578 # gdb_internal_error_resync
583 proc gdb_internal_error_resync {} {
586 verbose -log "Resyncing due to internal error."
589 while {$count < 10} {
591 -re "Quit this debugging session\\? \\(y or n\\) $" {
595 -re "Create a core file of GDB\\? \\(y or n\\) $" {
599 -re "$gdb_prompt $" {
600 # We're resynchronized.
604 perror "Could not resync from internal error (timeout)"
609 perror "Could not resync from internal error (resync count exceeded)"
614 # gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS
615 # Send a command to gdb; test the result.
617 # COMMAND is the command to execute, send to GDB with send_gdb. If
618 # this is the null string no command is sent.
619 # MESSAGE is a message to be printed with the built-in failure patterns
620 # if one of them matches. If MESSAGE is empty COMMAND will be used.
621 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
622 # patterns. Pattern elements will be evaluated in the caller's
623 # context; action elements will be executed in the caller's context.
624 # Unlike patterns for gdb_test, these patterns should generally include
625 # the final newline and prompt.
628 # 1 if the test failed, according to a built-in failure pattern
629 # 0 if only user-supplied patterns matched
630 # -1 if there was an internal error.
632 # You can use this function thus:
634 # gdb_test_multiple "print foo" "test foo" {
635 # -re "expected output 1" {
638 # -re "expected output 2" {
643 # The standard patterns, such as "Inferior exited..." and "A problem
644 # ...", all being implicitly appended to that list.
646 proc gdb_test_multiple { command message user_code } {
647 global verbose use_gdb_stub
650 global inferior_exited_re
651 upvar timeout timeout
652 upvar expect_out expect_out
654 if { $message == "" } {
658 if [string match "*\[\r\n\]" $command] {
659 error "Invalid trailing newline in \"$message\" test"
662 if [string match "*\[\r\n\]*" $message] {
663 error "Invalid newline in \"$message\" test"
667 && [regexp -nocase {^\s*(r|run|star|start|at|att|atta|attac|attach)\M} \
669 error "gdbserver does not support $command without extended-remote"
672 # TCL/EXPECT WART ALERT
673 # Expect does something very strange when it receives a single braced
674 # argument. It splits it along word separators and performs substitutions.
675 # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
676 # evaluated as "\[ab\]". But that's not how TCL normally works; inside a
677 # double-quoted list item, "\[ab\]" is just a long way of representing
678 # "[ab]", because the backslashes will be removed by lindex.
680 # Unfortunately, there appears to be no easy way to duplicate the splitting
681 # that expect will do from within TCL. And many places make use of the
682 # "\[0-9\]" construct, so we need to support that; and some places make use
683 # of the "[func]" construct, so we need to support that too. In order to
684 # get this right we have to substitute quoted list elements differently
685 # from braced list elements.
687 # We do this roughly the same way that Expect does it. We have to use two
688 # lists, because if we leave unquoted newlines in the argument to uplevel
689 # they'll be treated as command separators, and if we escape newlines
690 # we mangle newlines inside of command blocks. This assumes that the
691 # input doesn't contain a pattern which contains actual embedded newlines
694 regsub -all {\n} ${user_code} { } subst_code
695 set subst_code [uplevel list $subst_code]
697 set processed_code ""
699 set expecting_action 0
701 foreach item $user_code subst_item $subst_code {
702 if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } {
703 lappend processed_code $item
706 if { $item == "-indices" || $item == "-re" || $item == "-ex" } {
707 lappend processed_code $item
710 if { $item == "-timeout" } {
712 lappend processed_code $item
715 if { $expecting_arg } {
717 lappend processed_code $item
720 if { $expecting_action } {
721 lappend processed_code "uplevel [list $item]"
722 set expecting_action 0
723 # Cosmetic, no effect on the list.
724 append processed_code "\n"
727 set expecting_action 1
728 lappend processed_code $subst_item
729 if {$patterns != ""} {
732 append patterns "\"$subst_item\""
735 # Also purely cosmetic.
736 regsub -all {\r} $patterns {\\r} patterns
737 regsub -all {\n} $patterns {\\n} patterns
740 send_user "Sending \"$command\" to gdb\n"
741 send_user "Looking to match \"$patterns\"\n"
742 send_user "Message is \"$message\"\n"
746 set string "${command}\n";
747 if { $command != "" } {
748 set multi_line_re "\[\r\n\] *>"
749 while { "$string" != "" } {
750 set foo [string first "\n" "$string"];
751 set len [string length "$string"];
752 if { $foo < [expr $len - 1] } {
753 set str [string range "$string" 0 $foo];
754 if { [send_gdb "$str"] != "" } {
755 global suppress_flag;
757 if { ! $suppress_flag } {
758 perror "Couldn't send $command to GDB.";
763 # since we're checking if each line of the multi-line
764 # command are 'accepted' by GDB here,
765 # we need to set -notransfer expect option so that
766 # command output is not lost for pattern matching
769 -notransfer -re "$multi_line_re$" { verbose "partial: match" 3 }
770 timeout { verbose "partial: timeout" 3 }
772 set string [string range "$string" [expr $foo + 1] end];
773 set multi_line_re "$multi_line_re.*\[\r\n\] *>"
778 if { "$string" != "" } {
779 if { [send_gdb "$string"] != "" } {
780 global suppress_flag;
782 if { ! $suppress_flag } {
783 perror "Couldn't send $command to GDB.";
791 if [target_info exists gdb,timeout] {
792 set tmt [target_info gdb,timeout];
794 if [info exists timeout] {
798 if [info exists timeout] {
807 -re ".*A problem internal to GDB has been detected" {
808 fail "$message (GDB internal error)"
809 gdb_internal_error_resync
811 -re "\\*\\*\\* DOSEXIT code.*" {
812 if { $message != "" } {
815 gdb_suppress_entire_file "GDB died";
819 append code $processed_code
821 -re "Ending remote debugging.*$gdb_prompt $" {
822 if ![isnative] then {
823 warning "Can`t communicate to remote target."
829 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
830 perror "Undefined command \"$command\"."
834 -re "Ambiguous command.*$gdb_prompt $" {
835 perror "\"$command\" is not a unique command name."
839 -re "$inferior_exited_re with code \[0-9\]+.*$gdb_prompt $" {
840 if ![string match "" $message] then {
841 set errmsg "$message (the program exited)"
843 set errmsg "$command (the program exited)"
848 -re "$inferior_exited_re normally.*$gdb_prompt $" {
849 if ![string match "" $message] then {
850 set errmsg "$message (the program exited)"
852 set errmsg "$command (the program exited)"
857 -re "The program is not being run.*$gdb_prompt $" {
858 if ![string match "" $message] then {
859 set errmsg "$message (the program is no longer running)"
861 set errmsg "$command (the program is no longer running)"
866 -re "\r\n$gdb_prompt $" {
867 if ![string match "" $message] then {
874 perror "Window too small."
878 -re "\\((y or n|y or \\\[n\\\]|\\\[y\\\] or n)\\) " {
880 gdb_expect -re "$gdb_prompt $"
881 fail "$message (got interactive prompt)"
884 -re "\\\[0\\\] cancel\r\n\\\[1\\\] all.*\r\n> $" {
886 gdb_expect -re "$gdb_prompt $"
887 fail "$message (got breakpoint menu)"
891 perror "Process no longer exists"
892 if { $message != "" } {
898 perror "internal buffer is full."
903 if ![string match "" $message] then {
904 fail "$message (timeout)"
911 set code [catch {gdb_expect $tmt $code} string]
913 global errorInfo errorCode;
914 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
915 } elseif {$code > 1} {
916 return -code $code $string
921 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
922 # Send a command to gdb; test the result.
924 # COMMAND is the command to execute, send to GDB with send_gdb. If
925 # this is the null string no command is sent.
926 # PATTERN is the pattern to match for a PASS, and must NOT include
927 # the \r\n sequence immediately before the gdb prompt.
928 # MESSAGE is an optional message to be printed. If this is
929 # omitted, then the pass/fail messages use the command string as the
930 # message. (If this is the empty string, then sometimes we don't
931 # call pass or fail at all; I don't understand this at all.)
932 # QUESTION is a question GDB may ask in response to COMMAND, like
934 # RESPONSE is the response to send if QUESTION appears.
937 # 1 if the test failed,
938 # 0 if the test passes,
939 # -1 if there was an internal error.
941 proc gdb_test { args } {
945 upvar timeout timeout
947 if [llength $args]>2 then {
948 set message [lindex $args 2]
950 set message [lindex $args 0]
952 set command [lindex $args 0]
953 set pattern [lindex $args 1]
955 if [llength $args]==5 {
956 set question_string [lindex $args 3];
957 set response_string [lindex $args 4];
959 set question_string "^FOOBAR$"
962 return [gdb_test_multiple $command $message {
963 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
964 if ![string match "" $message] then {
968 -re "(${question_string})$" {
969 send_gdb "$response_string\n";
975 # gdb_test_no_output COMMAND MESSAGE
976 # Send a command to GDB and verify that this command generated no output.
978 # See gdb_test_multiple for a description of the COMMAND and MESSAGE
979 # parameters. If MESSAGE is ommitted, then COMMAND will be used as
980 # the message. (If MESSAGE is the empty string, then sometimes we do not
981 # call pass or fail at all; I don't understand this at all.)
983 proc gdb_test_no_output { args } {
985 set command [lindex $args 0]
986 if [llength $args]>1 then {
987 set message [lindex $args 1]
992 set command_regex [string_to_regexp $command]
993 gdb_test_multiple $command $message {
994 -re "^$command_regex\r\n$gdb_prompt $" {
995 if ![string match "" $message] then {
1002 # Send a command and then wait for a sequence of outputs.
1003 # This is useful when the sequence is long and contains ".*", a single
1004 # regexp to match the entire output can get a timeout much easier.
1006 # COMMAND is the command to send.
1007 # TEST_NAME is passed to pass/fail. COMMAND is used if TEST_NAME is "".
1008 # EXPECTED_OUTPUT_LIST is a list of regexps of expected output, which are
1009 # processed in order, and all must be present in the output.
1011 # It is unnecessary to specify ".*" at the beginning or end of any regexp,
1012 # there is an implicit ".*" between each element of EXPECTED_OUTPUT_LIST.
1013 # There is also an implicit ".*" between the last regexp and the gdb prompt.
1015 # Like gdb_test and gdb_test_multiple, the output is expected to end with the
1016 # gdb prompt, which must not be specified in EXPECTED_OUTPUT_LIST.
1019 # 1 if the test failed,
1020 # 0 if the test passes,
1021 # -1 if there was an internal error.
1023 proc gdb_test_sequence { command test_name expected_output_list } {
1025 if { $test_name == "" } {
1026 set test_name $command
1028 lappend expected_output_list ""; # implicit ".*" before gdb prompt
1029 send_gdb "$command\n"
1030 return [gdb_expect_list $test_name "$gdb_prompt $" $expected_output_list]
1034 # Test that a command gives an error. For pass or fail, return
1035 # a 1 to indicate that more tests can proceed. However a timeout
1036 # is a serious error, generates a special fail message, and causes
1037 # a 0 to be returned to indicate that more tests are likely to fail
1040 proc test_print_reject { args } {
1044 if [llength $args]==2 then {
1045 set expectthis [lindex $args 1]
1047 set expectthis "should never match this bogus string"
1049 set sendthis [lindex $args 0]
1050 if $verbose>2 then {
1051 send_user "Sending \"$sendthis\" to gdb\n"
1052 send_user "Looking to match \"$expectthis\"\n"
1054 send_gdb "$sendthis\n"
1055 #FIXME: Should add timeout as parameter.
1057 -re "A .* in expression.*\\.*$gdb_prompt $" {
1058 pass "reject $sendthis"
1061 -re "Invalid syntax in expression.*$gdb_prompt $" {
1062 pass "reject $sendthis"
1065 -re "Junk after end of expression.*$gdb_prompt $" {
1066 pass "reject $sendthis"
1069 -re "Invalid number.*$gdb_prompt $" {
1070 pass "reject $sendthis"
1073 -re "Invalid character constant.*$gdb_prompt $" {
1074 pass "reject $sendthis"
1077 -re "No symbol table is loaded.*$gdb_prompt $" {
1078 pass "reject $sendthis"
1081 -re "No symbol .* in current context.*$gdb_prompt $" {
1082 pass "reject $sendthis"
1085 -re "Unmatched single quote.*$gdb_prompt $" {
1086 pass "reject $sendthis"
1089 -re "A character constant must contain at least one character.*$gdb_prompt $" {
1090 pass "reject $sendthis"
1093 -re "$expectthis.*$gdb_prompt $" {
1094 pass "reject $sendthis"
1097 -re ".*$gdb_prompt $" {
1098 fail "reject $sendthis"
1102 fail "reject $sendthis (eof or timeout)"
1108 # Given an input string, adds backslashes as needed to create a
1109 # regexp that will match the string.
1111 proc string_to_regexp {str} {
1113 regsub -all {[]*+.|()^$\[\\]} $str {\\&} result
1117 # Same as gdb_test, but the second parameter is not a regexp,
1118 # but a string that must match exactly.
1120 proc gdb_test_exact { args } {
1121 upvar timeout timeout
1123 set command [lindex $args 0]
1125 # This applies a special meaning to a null string pattern. Without
1126 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
1127 # messages from commands that should have no output except a new
1128 # prompt. With this, only results of a null string will match a null
1131 set pattern [lindex $args 1]
1132 if [string match $pattern ""] {
1133 set pattern [string_to_regexp [lindex $args 0]]
1135 set pattern [string_to_regexp [lindex $args 1]]
1138 # It is most natural to write the pattern argument with only
1139 # embedded \n's, especially if you are trying to avoid Tcl quoting
1140 # problems. But gdb_expect really wants to see \r\n in patterns. So
1141 # transform the pattern here. First transform \r\n back to \n, in
1142 # case some users of gdb_test_exact already do the right thing.
1143 regsub -all "\r\n" $pattern "\n" pattern
1144 regsub -all "\n" $pattern "\r\n" pattern
1145 if [llength $args]==3 then {
1146 set message [lindex $args 2]
1148 set message $command
1151 return [gdb_test $command $pattern $message]
1154 # Wrapper around gdb_test_multiple that looks for a list of expected
1155 # output elements, but which can appear in any order.
1156 # CMD is the gdb command.
1157 # NAME is the name of the test.
1158 # ELM_FIND_REGEXP specifies how to partition the output into elements to
1160 # ELM_EXTRACT_REGEXP specifies the part of ELM_FIND_REGEXP to compare.
1161 # RESULT_MATCH_LIST is a list of exact matches for each expected element.
1162 # All elements of RESULT_MATCH_LIST must appear for the test to pass.
1164 # A typical use of ELM_FIND_REGEXP/ELM_EXTRACT_REGEXP is to extract one line
1165 # of text per element and then strip trailing \r\n's.
1167 # gdb_test_list_exact "foo" "bar" \
1168 # "\[^\r\n\]+\[\r\n\]+" \
1171 # {expected result 1} \
1172 # {expected result 2} \
1175 proc gdb_test_list_exact { cmd name elm_find_regexp elm_extract_regexp result_match_list } {
1178 set matches [lsort $result_match_list]
1180 gdb_test_multiple $cmd $name {
1181 "$cmd\[\r\n\]" { exp_continue }
1182 -re $elm_find_regexp {
1183 set str $expect_out(0,string)
1184 verbose -log "seen: $str" 3
1185 regexp -- $elm_extract_regexp $str elm_seen
1186 verbose -log "extracted: $elm_seen" 3
1187 lappend seen $elm_seen
1190 -re "$gdb_prompt $" {
1192 foreach got [lsort $seen] have $matches {
1193 if {![string equal $got $have]} {
1198 if {[string length $failed] != 0} {
1199 fail "$name ($failed not found)"
1207 proc gdb_reinitialize_dir { subdir } {
1210 if [is_remote host] {
1215 -re "Reinitialize source path to empty.*y or n. " {
1218 -re "Source directories searched.*$gdb_prompt $" {
1219 send_gdb "dir $subdir\n"
1221 -re "Source directories searched.*$gdb_prompt $" {
1222 verbose "Dir set to $subdir"
1224 -re "$gdb_prompt $" {
1225 perror "Dir \"$subdir\" failed."
1229 -re "$gdb_prompt $" {
1230 perror "Dir \"$subdir\" failed."
1234 -re "$gdb_prompt $" {
1235 perror "Dir \"$subdir\" failed."
1241 # gdb_exit -- exit the GDB, killing the target program if necessary
1243 proc default_gdb_exit {} {
1245 global INTERNAL_GDBFLAGS GDBFLAGS
1247 global gdb_spawn_id;
1249 gdb_stop_suppressing_tests;
1251 if ![info exists gdb_spawn_id] {
1255 verbose "Quitting $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1257 if { [is_remote host] && [board_info host exists fileid] } {
1264 -re "DOSEXIT code" { }
1269 if ![is_remote host] {
1275 # Load a file into the debugger.
1276 # The return value is 0 for success, -1 for failure.
1278 # This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO
1279 # to one of these values:
1281 # debug file was loaded successfully and has debug information
1282 # nodebug file was loaded successfully and has no debug information
1283 # lzma file was loaded, .gnu_debugdata found, but no LZMA support
1285 # fail file was not loaded
1287 # I tried returning this information as part of the return value,
1288 # but ran into a mess because of the many re-implementations of
1289 # gdb_load in config/*.exp.
1291 # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use
1292 # this if they can get more information set.
1294 proc gdb_file_cmd { arg } {
1298 global last_loaded_file
1300 # Save this for the benefit of gdbserver-support.exp.
1301 set last_loaded_file $arg
1303 # Set whether debug info was found.
1304 # Default to "fail".
1305 global gdb_file_cmd_debug_info
1306 set gdb_file_cmd_debug_info "fail"
1308 if [is_remote host] {
1309 set arg [remote_download host $arg]
1311 perror "download failed"
1316 # The file command used to kill the remote target. For the benefit
1317 # of the testsuite, preserve this behavior.
1320 -re "Kill the program being debugged. .y or n. $" {
1322 verbose "\t\tKilling previous program being debugged"
1325 -re "$gdb_prompt $" {
1330 send_gdb "file $arg\n"
1332 -re "Reading symbols from.*LZMA support was disabled.*done.*$gdb_prompt $" {
1333 verbose "\t\tLoaded $arg into $GDB; .gnu_debugdata found but no LZMA available"
1334 set gdb_file_cmd_debug_info "lzma"
1337 -re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" {
1338 verbose "\t\tLoaded $arg into $GDB with no debugging symbols"
1339 set gdb_file_cmd_debug_info "nodebug"
1342 -re "Reading symbols from.*done.*$gdb_prompt $" {
1343 verbose "\t\tLoaded $arg into $GDB"
1344 set gdb_file_cmd_debug_info "debug"
1347 -re "Load new symbol table from \".*\".*y or n. $" {
1350 -re "Reading symbols from.*done.*$gdb_prompt $" {
1351 verbose "\t\tLoaded $arg with new symbol table into $GDB"
1352 set gdb_file_cmd_debug_info "debug"
1356 perror "Couldn't load $arg, other program already loaded (timeout)."
1360 perror "Couldn't load $arg, other program already loaded (eof)."
1365 -re "No such file or directory.*$gdb_prompt $" {
1366 perror "($arg) No such file or directory"
1369 -re "A problem internal to GDB has been detected" {
1370 fail "($arg) (GDB internal error)"
1371 gdb_internal_error_resync
1374 -re "$gdb_prompt $" {
1375 perror "Couldn't load $arg into $GDB."
1379 perror "Couldn't load $arg into $GDB (timeout)."
1383 # This is an attempt to detect a core dump, but seems not to
1384 # work. Perhaps we need to match .* followed by eof, in which
1385 # gdb_expect does not seem to have a way to do that.
1386 perror "Couldn't load $arg into $GDB (eof)."
1393 # start gdb -- start gdb running, default procedure
1395 # When running over NFS, particularly if running many simultaneous
1396 # tests on different hosts all using the same server, things can
1397 # get really slow. Give gdb at least 3 minutes to start up.
1399 proc default_gdb_start { } {
1400 global verbose use_gdb_stub
1402 global INTERNAL_GDBFLAGS GDBFLAGS
1405 global gdb_spawn_id;
1407 gdb_stop_suppressing_tests;
1409 # Set the default value, it may be overriden later by specific testfile.
1411 # Use `set_board_info use_gdb_stub' for the board file to flag the inferior
1412 # is already started after connecting and run/attach are not supported.
1413 # This is used for the "remote" protocol. After GDB starts you should
1414 # check global $use_gdb_stub instead of the board as the testfile may force
1415 # a specific different target protocol itself.
1416 set use_gdb_stub [target_info exists use_gdb_stub]
1418 verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1420 if [info exists gdb_spawn_id] {
1424 if ![is_remote host] {
1425 if { [which $GDB] == 0 } then {
1426 perror "$GDB does not exist."
1430 set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"];
1431 if { $res < 0 || $res == "" } {
1432 perror "Spawning $GDB failed."
1436 -re "\[\r\n\]$gdb_prompt $" {
1437 verbose "GDB initialized."
1439 -re "$gdb_prompt $" {
1440 perror "GDB never initialized."
1444 perror "(timeout) GDB never initialized after 10 seconds."
1449 set gdb_spawn_id -1;
1450 # force the height to "unlimited", so no pagers get used
1452 send_gdb "set height 0\n"
1454 -re "$gdb_prompt $" {
1455 verbose "Setting height to 0." 2
1458 warning "Couldn't set the height to 0"
1461 # force the width to "unlimited", so no wraparound occurs
1462 send_gdb "set width 0\n"
1464 -re "$gdb_prompt $" {
1465 verbose "Setting width to 0." 2
1468 warning "Couldn't set the width to 0."
1474 # Examine the output of compilation to determine whether compilation
1475 # failed or not. If it failed determine whether it is due to missing
1476 # compiler or due to compiler error. Report pass, fail or unsupported
1479 proc gdb_compile_test {src output} {
1480 if { $output == "" } {
1481 pass "compilation [file tail $src]"
1482 } elseif { [regexp {^[a-zA-Z_0-9]+: Can't find [^ ]+\.$} $output] } {
1483 unsupported "compilation [file tail $src]"
1484 } elseif { [regexp {.*: command not found[\r|\n]*$} $output] } {
1485 unsupported "compilation [file tail $src]"
1486 } elseif { [regexp {.*: [^\r\n]*compiler not installed[^\r\n]*[\r|\n]*$} $output] } {
1487 unsupported "compilation [file tail $src]"
1489 verbose -log "compilation failed: $output" 2
1490 fail "compilation [file tail $src]"
1494 # Return a 1 for configurations for which we don't even want to try to
1497 proc skip_cplus_tests {} {
1498 if { [istarget "h8300-*-*"] } {
1502 # The C++ IO streams are too large for HC11/HC12 and are thus not
1503 # available. The gdb C++ tests use them and don't compile.
1504 if { [istarget "m6811-*-*"] } {
1507 if { [istarget "m6812-*-*"] } {
1513 # Return a 1 for configurations for which don't have both C++ and the STL.
1515 proc skip_stl_tests {} {
1516 # Symbian supports the C++ language, but the STL is missing
1517 # (both headers and libraries).
1518 if { [istarget "arm*-*-symbianelf*"] } {
1522 return [skip_cplus_tests]
1525 # Return a 1 if I don't even want to try to test FORTRAN.
1527 proc skip_fortran_tests {} {
1531 # Return a 1 if I don't even want to try to test ada.
1533 proc skip_ada_tests {} {
1537 # Return a 1 if I don't even want to try to test GO.
1539 proc skip_go_tests {} {
1543 # Return a 1 if I don't even want to try to test java.
1545 proc skip_java_tests {} {
1549 # Return a 1 for configurations that do not support Python scripting.
1551 proc skip_python_tests {} {
1553 gdb_test_multiple "python print 'test'" "verify python support" {
1554 -re "not supported.*$gdb_prompt $" {
1555 unsupported "Python support is disabled."
1558 -re "$gdb_prompt $" {}
1564 # Return a 1 if we should skip shared library tests.
1566 proc skip_shlib_tests {} {
1567 # Run the shared library tests on native systems.
1572 # An abbreviated list of remote targets where we should be able to
1573 # run shared library tests.
1574 if {([istarget *-*-linux*]
1575 || [istarget *-*-*bsd*]
1576 || [istarget *-*-solaris2*]
1577 || [istarget arm*-*-symbianelf*]
1578 || [istarget *-*-mingw*]
1579 || [istarget *-*-cygwin*]
1580 || [istarget *-*-pe*])} {
1587 # Test files shall make sure all the test result lines in gdb.sum are
1588 # unique in a test run, so that comparing the gdb.sum files of two
1589 # test runs gives correct results. Test files that exercise
1590 # variations of the same tests more than once, shall prefix the
1591 # different test invocations with different identifying strings in
1592 # order to make them unique.
1594 # About test prefixes:
1596 # $pf_prefix is the string that dejagnu prints after the result (FAIL,
1597 # PASS, etc.), and before the test message/name in gdb.sum. E.g., the
1598 # underlined substring in
1600 # PASS: gdb.base/mytest.exp: some test
1601 # ^^^^^^^^^^^^^^^^^^^^
1605 # The easiest way to adjust the test prefix is to append a test
1606 # variation prefix to the $pf_prefix, using the with_test_prefix
1609 # proc do_tests {} {
1610 # gdb_test ... ... "test foo"
1611 # gdb_test ... ... "test bar"
1613 # with_test_prefix "subvariation a" {
1614 # gdb_test ... ... "test x"
1617 # with_test_prefix "subvariation b" {
1618 # gdb_test ... ... "test x"
1622 # with_test_prefix "variation1" {
1623 # ...do setup for variation 1...
1627 # with_test_prefix "variation2" {
1628 # ...do setup for variation 2...
1634 # PASS: gdb.base/mytest.exp: variation1: test foo
1635 # PASS: gdb.base/mytest.exp: variation1: test bar
1636 # PASS: gdb.base/mytest.exp: variation1: subvariation a: test x
1637 # PASS: gdb.base/mytest.exp: variation1: subvariation b: test x
1638 # PASS: gdb.base/mytest.exp: variation2: test foo
1639 # PASS: gdb.base/mytest.exp: variation2: test bar
1640 # PASS: gdb.base/mytest.exp: variation2: subvariation a: test x
1641 # PASS: gdb.base/mytest.exp: variation2: subvariation b: test x
1643 # If for some reason more flexibility is necessary, one can also
1644 # manipulate the pf_prefix global directly, treating it as a string.
1648 # set saved_pf_prefix
1649 # append pf_prefix "${foo}: bar"
1650 # ... actual tests ...
1651 # set pf_prefix $saved_pf_prefix
1654 # Run BODY in the context of the caller, with the current test prefix
1655 # (pf_prefix) appended with one space, then PREFIX, and then a colon.
1656 # Returns the result of BODY.
1658 proc with_test_prefix { prefix body } {
1661 set saved $pf_prefix
1662 append pf_prefix " " $prefix ":"
1663 set code [catch {uplevel 1 $body} result]
1664 set pf_prefix $saved
1667 global errorInfo errorCode
1668 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
1670 return -code $code $result
1674 # Return 1 if _Complex types are supported, otherwise, return 0.
1676 proc support_complex_tests {} {
1677 global support_complex_tests_saved
1679 # Use the cached value, if it exists.
1680 if [info exists support_complex_tests_saved] {
1681 verbose "returning saved $support_complex_tests_saved" 2
1682 return $support_complex_tests_saved
1685 # Set up, compile, and execute a test program containing _Complex types.
1686 # Include the current process ID in the file names to prevent conflicts
1687 # with invocations for multiple testsuites.
1688 set src complex[pid].c
1689 set exe complex[pid].x
1691 set f [open $src "w"]
1692 puts $f "int main() {"
1693 puts $f "_Complex float cf;"
1694 puts $f "_Complex double cd;"
1695 puts $f "_Complex long double cld;"
1696 puts $f " return 0; }"
1699 verbose "compiling testfile $src" 2
1700 set compile_flags {debug nowarnings quiet}
1701 set lines [gdb_compile $src $exe executable $compile_flags]
1705 if ![string match "" $lines] then {
1706 verbose "testfile compilation failed, returning 0" 2
1707 set support_complex_tests_saved 0
1709 set support_complex_tests_saved 1
1712 return $support_complex_tests_saved
1715 # Return 1 if target hardware or OS supports single stepping to signal
1716 # handler, otherwise, return 0.
1718 proc can_single_step_to_signal_handler {} {
1720 # Targets don't have hardware single step. On these targets, when
1721 # a signal is delivered during software single step, gdb is unable
1722 # to determine the next instruction addresses, because start of signal
1723 # handler is one of them.
1724 if { [istarget "arm*-*-*"] || [istarget "mips*-*-*"]
1725 || [istarget "tic6x-*-*"] || [istarget "sparc*-*-linux*"] } {
1732 # Return 1 if target supports process record, otherwise return 0.
1734 proc supports_process_record {} {
1736 if [target_info exists gdb,use_precord] {
1737 return [target_info gdb,use_precord]
1740 if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"] } {
1747 # Return 1 if target supports reverse debugging, otherwise return 0.
1749 proc supports_reverse {} {
1751 if [target_info exists gdb,can_reverse] {
1752 return [target_info gdb,can_reverse]
1755 if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"] } {
1762 # Return 1 if target is ILP32.
1763 # This cannot be decided simply from looking at the target string,
1764 # as it might depend on externally passed compiler options like -m64.
1765 proc is_ilp32_target {} {
1766 global is_ilp32_target_saved
1768 # Use the cached value, if it exists. Cache value per "board" to handle
1769 # runs with multiple options (e.g. unix/{-m32,-64}) correctly.
1770 set me "is_ilp32_target"
1771 set board [target_info name]
1772 if [info exists is_ilp32_target_saved($board)] {
1773 verbose "$me: returning saved $is_ilp32_target_saved($board)" 2
1774 return $is_ilp32_target_saved($board)
1778 set src ilp32[pid].c
1779 set obj ilp32[pid].o
1781 set f [open $src "w"]
1782 puts $f "int dummy\[sizeof (int) == 4"
1783 puts $f " && sizeof (void *) == 4"
1784 puts $f " && sizeof (long) == 4 ? 1 : -1\];"
1787 verbose "$me: compiling testfile $src" 2
1788 set lines [gdb_compile $src $obj object {quiet}]
1792 if ![string match "" $lines] then {
1793 verbose "$me: testfile compilation failed, returning 0" 2
1794 return [set is_ilp32_target_saved($board) 0]
1797 verbose "$me: returning 1" 2
1798 return [set is_ilp32_target_saved($board) 1]
1801 # Return 1 if target is LP64.
1802 # This cannot be decided simply from looking at the target string,
1803 # as it might depend on externally passed compiler options like -m64.
1804 proc is_lp64_target {} {
1805 global is_lp64_target_saved
1807 # Use the cached value, if it exists. Cache value per "board" to handle
1808 # runs with multiple options (e.g. unix/{-m32,-64}) correctly.
1809 set me "is_lp64_target"
1810 set board [target_info name]
1811 if [info exists is_lp64_target_saved($board)] {
1812 verbose "$me: returning saved $is_lp64_target_saved($board)" 2
1813 return $is_lp64_target_saved($board)
1819 set f [open $src "w"]
1820 puts $f "int dummy\[sizeof (int) == 4"
1821 puts $f " && sizeof (void *) == 8"
1822 puts $f " && sizeof (long) == 8 ? 1 : -1\];"
1825 verbose "$me: compiling testfile $src" 2
1826 set lines [gdb_compile $src $obj object {quiet}]
1830 if ![string match "" $lines] then {
1831 verbose "$me: testfile compilation failed, returning 0" 2
1832 return [set is_lp64_target_saved($board) 0]
1835 verbose "$me: returning 1" 2
1836 return [set is_lp64_target_saved($board) 1]
1839 # Return 1 if target has x86_64 registers - either amd64 or x32.
1840 # x32 target identifies as x86_64-*-linux*, therefore it cannot be determined
1841 # just from the target string.
1842 proc is_amd64_regs_target {} {
1843 global is_amd64_regs_target_saved
1845 if {![istarget "x86_64-*-*"] && ![istarget "i?86-*"]} {
1849 # Use the cached value, if it exists. Cache value per "board" to handle
1850 # runs with multiple options (e.g. unix/{-m32,-64}) correctly.
1851 set me "is_amd64_regs_target"
1852 set board [target_info name]
1853 if [info exists is_amd64_regs_target_saved($board)] {
1854 verbose "$me: returning saved $is_amd64_regs_target_saved($board)" 2
1855 return $is_amd64_regs_target_saved($board)
1858 set src reg64[pid].s
1859 set obj reg64[pid].o
1861 set f [open $src "w"]
1863 {rax rbx rcx rdx rsi rdi rbp rsp r8 r9 r10 r11 r12 r13 r14 r15} {
1864 puts $f "\tincq %$reg"
1868 verbose "$me: compiling testfile $src" 2
1869 set lines [gdb_compile $src $obj object {quiet}]
1873 if ![string match "" $lines] then {
1874 verbose "$me: testfile compilation failed, returning 0" 2
1875 return [set is_amd64_regs_target_saved($board) 0]
1878 verbose "$me: returning 1" 2
1879 return [set is_amd64_regs_target_saved($board) 1]
1882 # Return 1 if this target is an x86 or x86-64 with -m32.
1883 proc is_x86_like_target {} {
1884 if {![istarget "x86_64-*-*"] && ![istarget i?86-*]} {
1887 return [expr [is_ilp32_target] && ![is_amd64_regs_target]]
1890 # Return 1 if displaced stepping is supported on target, otherwise, return 0.
1891 proc support_displaced_stepping {} {
1893 if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"]
1894 || [istarget "arm*-*-linux*"] || [istarget "powerpc-*-linux*"]
1895 || [istarget "powerpc64-*-linux*"] || [istarget "s390*-*-*"] } {
1902 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
1903 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
1905 proc skip_altivec_tests {} {
1906 global skip_vmx_tests_saved
1907 global srcdir subdir gdb_prompt inferior_exited_re
1909 # Use the cached value, if it exists.
1910 set me "skip_altivec_tests"
1911 if [info exists skip_vmx_tests_saved] {
1912 verbose "$me: returning saved $skip_vmx_tests_saved" 2
1913 return $skip_vmx_tests_saved
1916 # Some simulators are known to not support VMX instructions.
1917 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1918 verbose "$me: target known to not support VMX, returning 1" 2
1919 return [set skip_vmx_tests_saved 1]
1922 # Make sure we have a compiler that understands altivec.
1923 set compile_flags {debug nowarnings}
1924 if [get_compiler_info] {
1925 warning "Could not get compiler info"
1928 if [test_compiler_info gcc*] {
1929 set compile_flags "$compile_flags additional_flags=-maltivec"
1930 } elseif [test_compiler_info xlc*] {
1931 set compile_flags "$compile_flags additional_flags=-qaltivec"
1933 verbose "Could not compile with altivec support, returning 1" 2
1937 # Set up, compile, and execute a test program containing VMX instructions.
1938 # Include the current process ID in the file names to prevent conflicts
1939 # with invocations for multiple testsuites.
1943 set f [open $src "w"]
1944 puts $f "int main() {"
1945 puts $f "#ifdef __MACH__"
1946 puts $f " asm volatile (\"vor v0,v0,v0\");"
1948 puts $f " asm volatile (\"vor 0,0,0\");"
1950 puts $f " return 0; }"
1953 verbose "$me: compiling testfile $src" 2
1954 set lines [gdb_compile $src $exe executable $compile_flags]
1957 if ![string match "" $lines] then {
1958 verbose "$me: testfile compilation failed, returning 1" 2
1959 return [set skip_vmx_tests_saved 1]
1962 # No error message, compilation succeeded so now run it via gdb.
1966 gdb_reinitialize_dir $srcdir/$subdir
1970 -re ".*Illegal instruction.*${gdb_prompt} $" {
1971 verbose -log "\n$me altivec hardware not detected"
1972 set skip_vmx_tests_saved 1
1974 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
1975 verbose -log "\n$me: altivec hardware detected"
1976 set skip_vmx_tests_saved 0
1979 warning "\n$me: default case taken"
1980 set skip_vmx_tests_saved 1
1984 remote_file build delete $exe
1986 verbose "$me: returning $skip_vmx_tests_saved" 2
1987 return $skip_vmx_tests_saved
1990 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
1991 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
1993 proc skip_vsx_tests {} {
1994 global skip_vsx_tests_saved
1995 global srcdir subdir gdb_prompt inferior_exited_re
1997 # Use the cached value, if it exists.
1998 set me "skip_vsx_tests"
1999 if [info exists skip_vsx_tests_saved] {
2000 verbose "$me: returning saved $skip_vsx_tests_saved" 2
2001 return $skip_vsx_tests_saved
2004 # Some simulators are known to not support Altivec instructions, so
2005 # they won't support VSX instructions as well.
2006 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
2007 verbose "$me: target known to not support VSX, returning 1" 2
2008 return [set skip_vsx_tests_saved 1]
2011 # Make sure we have a compiler that understands altivec.
2012 set compile_flags {debug nowarnings quiet}
2013 if [get_compiler_info] {
2014 warning "Could not get compiler info"
2017 if [test_compiler_info gcc*] {
2018 set compile_flags "$compile_flags additional_flags=-mvsx"
2019 } elseif [test_compiler_info xlc*] {
2020 set compile_flags "$compile_flags additional_flags=-qasm=gcc"
2022 verbose "Could not compile with vsx support, returning 1" 2
2029 set f [open $src "w"]
2030 puts $f "int main() {"
2031 puts $f " double a\[2\] = { 1.0, 2.0 };"
2032 puts $f "#ifdef __MACH__"
2033 puts $f " asm volatile (\"lxvd2x v0,v0,%\[addr\]\" : : \[addr\] \"r\" (a));"
2035 puts $f " asm volatile (\"lxvd2x 0,0,%\[addr\]\" : : \[addr\] \"r\" (a));"
2037 puts $f " return 0; }"
2040 verbose "$me: compiling testfile $src" 2
2041 set lines [gdb_compile $src $exe executable $compile_flags]
2044 if ![string match "" $lines] then {
2045 verbose "$me: testfile compilation failed, returning 1" 2
2046 return [set skip_vsx_tests_saved 1]
2049 # No error message, compilation succeeded so now run it via gdb.
2053 gdb_reinitialize_dir $srcdir/$subdir
2057 -re ".*Illegal instruction.*${gdb_prompt} $" {
2058 verbose -log "\n$me VSX hardware not detected"
2059 set skip_vsx_tests_saved 1
2061 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
2062 verbose -log "\n$me: VSX hardware detected"
2063 set skip_vsx_tests_saved 0
2066 warning "\n$me: default case taken"
2067 set skip_vsx_tests_saved 1
2071 remote_file build delete $exe
2073 verbose "$me: returning $skip_vsx_tests_saved" 2
2074 return $skip_vsx_tests_saved
2077 # Skip all the tests in the file if you are not on an hppa running
2080 proc skip_hp_tests {} {
2081 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
2082 verbose "Skip hp tests is $skip_hp"
2086 # Return whether we should skip tests for showing inlined functions in
2087 # backtraces. Requires get_compiler_info and get_debug_format.
2089 proc skip_inline_frame_tests {} {
2090 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
2091 if { ! [test_debug_format "DWARF 2"] } {
2095 # GCC before 4.1 does not emit DW_AT_call_file / DW_AT_call_line.
2096 if { ([test_compiler_info "gcc-2-*"]
2097 || [test_compiler_info "gcc-3-*"]
2098 || [test_compiler_info "gcc-4-0-*"]) } {
2105 # Return whether we should skip tests for showing variables from
2106 # inlined functions. Requires get_compiler_info and get_debug_format.
2108 proc skip_inline_var_tests {} {
2109 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
2110 if { ! [test_debug_format "DWARF 2"] } {
2117 # Return a 1 if we should skip tests that require hardware breakpoints
2119 proc skip_hw_breakpoint_tests {} {
2120 # Skip tests if requested by the board (note that no_hardware_watchpoints
2121 # disables both watchpoints and breakpoints)
2122 if { [target_info exists gdb,no_hardware_watchpoints]} {
2126 # These targets support hardware breakpoints natively
2127 if { [istarget "i?86-*-*"]
2128 || [istarget "x86_64-*-*"]
2129 || [istarget "ia64-*-*"]
2130 || [istarget "arm*-*-*"]} {
2137 # Return a 1 if we should skip tests that require hardware watchpoints
2139 proc skip_hw_watchpoint_tests {} {
2140 # Skip tests if requested by the board
2141 if { [target_info exists gdb,no_hardware_watchpoints]} {
2145 # These targets support hardware watchpoints natively
2146 if { [istarget "i?86-*-*"]
2147 || [istarget "x86_64-*-*"]
2148 || [istarget "ia64-*-*"]
2149 || [istarget "arm*-*-*"]
2150 || [istarget "powerpc*-*-linux*"]
2151 || [istarget "s390*-*-*"] } {
2158 # Return a 1 if we should skip tests that require *multiple* hardware
2159 # watchpoints to be active at the same time
2161 proc skip_hw_watchpoint_multi_tests {} {
2162 if { [skip_hw_watchpoint_tests] } {
2166 # These targets support just a single hardware watchpoint
2167 if { [istarget "arm*-*-*"]
2168 || [istarget "powerpc*-*-linux*"] } {
2175 # Return a 1 if we should skip tests that require read/access watchpoints
2177 proc skip_hw_watchpoint_access_tests {} {
2178 if { [skip_hw_watchpoint_tests] } {
2182 # These targets support just write watchpoints
2183 if { [istarget "s390*-*-*"] } {
2190 # Return 1 if we should skip tests that require the runtime unwinder
2191 # hook. This must be invoked while gdb is running, after shared
2192 # libraries have been loaded. This is needed because otherwise a
2193 # shared libgcc won't be visible.
2195 proc skip_unwinder_tests {} {
2199 gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook" {
2200 -re "= .*no debug info.*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
2202 -re "= .*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
2205 -re "No symbol .* in current context.\r\n$gdb_prompt $" {
2209 gdb_test_multiple "info probe" "check for stap probe in unwinder" {
2210 -re ".*libgcc.*unwind.*\r\n$gdb_prompt $" {
2213 -re "\r\n$gdb_prompt $" {
2220 set compiler_info "unknown"
2222 set hp_cc_compiler 0
2223 set hp_aCC_compiler 0
2225 # Figure out what compiler I am using.
2227 # ARG can be empty or "C++". If empty, "C" is assumed.
2229 # There are several ways to do this, with various problems.
2231 # [ gdb_compile -E $ifile -o $binfile.ci ]
2232 # source $binfile.ci
2234 # Single Unix Spec v3 says that "-E -o ..." together are not
2235 # specified. And in fact, the native compiler on hp-ux 11 (among
2236 # others) does not work with "-E -o ...". Most targets used to do
2237 # this, and it mostly worked, because it works with gcc.
2239 # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ]
2240 # source $binfile.ci
2242 # This avoids the problem with -E and -o together. This almost works
2243 # if the build machine is the same as the host machine, which is
2244 # usually true of the targets which are not gcc. But this code does
2245 # not figure which compiler to call, and it always ends up using the C
2246 # compiler. Not good for setting hp_aCC_compiler. Targets
2247 # hppa*-*-hpux* and mips*-*-irix* used to do this.
2249 # [ gdb_compile -E $ifile > $binfile.ci ]
2250 # source $binfile.ci
2252 # dejagnu target_compile says that it supports output redirection,
2253 # but the code is completely different from the normal path and I
2254 # don't want to sweep the mines from that path. So I didn't even try
2257 # set cppout [ gdb_compile $ifile "" preprocess $args quiet ]
2260 # I actually do this for all targets now. gdb_compile runs the right
2261 # compiler, and TCL captures the output, and I eval the output.
2263 # Unfortunately, expect logs the output of the command as it goes by,
2264 # and dejagnu helpfully prints a second copy of it right afterwards.
2265 # So I turn off expect logging for a moment.
2267 # [ gdb_compile $ifile $ciexe_file executable $args ]
2268 # [ remote_exec $ciexe_file ]
2269 # [ source $ci_file.out ]
2271 # I could give up on -E and just do this.
2272 # I didn't get desperate enough to try this.
2274 # -- chastain 2004-01-06
2276 proc get_compiler_info {{arg ""}} {
2277 # For compiler.c and compiler.cc
2280 # I am going to play with the log to keep noise out.
2284 # These come from compiler.c or compiler.cc
2285 global compiler_info
2287 # Legacy global data symbols.
2289 global hp_cc_compiler
2290 global hp_aCC_compiler
2292 # Choose which file to preprocess.
2293 set ifile "${srcdir}/lib/compiler.c"
2294 if { $arg == "c++" } {
2295 set ifile "${srcdir}/lib/compiler.cc"
2298 # Run $ifile through the right preprocessor.
2299 # Toggle gdb.log to keep the compiler output out of the log.
2301 if [is_remote host] {
2302 # We have to use -E and -o together, despite the comments
2303 # above, because of how DejaGnu handles remote host testing.
2304 set ppout "$outdir/compiler.i"
2305 gdb_compile "${ifile}" "$ppout" preprocess [list "$arg" quiet]
2306 set file [open $ppout r]
2307 set cppout [read $file]
2310 set cppout [ gdb_compile "${ifile}" "" preprocess [list "$arg" quiet] ]
2312 log_file -a "$outdir/$tool.log"
2316 foreach cppline [ split "$cppout" "\n" ] {
2317 if { [ regexp "^#" "$cppline" ] } {
2319 } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } {
2321 } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } {
2323 verbose "get_compiler_info: $cppline" 2
2327 verbose -log "get_compiler_info: $cppline"
2332 # Reset to unknown compiler if any diagnostics happened.
2334 set compiler_info "unknown"
2337 # Set the legacy symbols.
2339 set hp_cc_compiler 0
2340 set hp_aCC_compiler 0
2341 if { [regexp "^gcc-1-" "$compiler_info" ] } { set gcc_compiled 1 }
2342 if { [regexp "^gcc-2-" "$compiler_info" ] } { set gcc_compiled 2 }
2343 if { [regexp "^gcc-3-" "$compiler_info" ] } { set gcc_compiled 3 }
2344 if { [regexp "^gcc-4-" "$compiler_info" ] } { set gcc_compiled 4 }
2345 if { [regexp "^gcc-5-" "$compiler_info" ] } { set gcc_compiled 5 }
2346 if { [regexp "^hpcc-" "$compiler_info" ] } { set hp_cc_compiler 1 }
2347 if { [regexp "^hpacc-" "$compiler_info" ] } { set hp_aCC_compiler 1 }
2349 # Log what happened.
2350 verbose -log "get_compiler_info: $compiler_info"
2352 # Most compilers will evaluate comparisons and other boolean
2353 # operations to 0 or 1.
2354 uplevel \#0 { set true 1 }
2355 uplevel \#0 { set false 0 }
2357 # Use of aCC results in boolean results being displayed as
2359 if { $hp_aCC_compiler } {
2360 uplevel \#0 { set true true }
2361 uplevel \#0 { set false false }
2367 proc test_compiler_info { {compiler ""} } {
2368 global compiler_info
2370 # if no arg, return the compiler_info string
2372 if [string match "" $compiler] {
2373 if [info exists compiler_info] {
2374 return $compiler_info
2376 perror "No compiler info found."
2380 return [string match $compiler $compiler_info]
2383 proc current_target_name { } {
2385 if [info exists target_info(target,name)] {
2386 set answer $target_info(target,name)
2393 set gdb_wrapper_initialized 0
2394 set gdb_wrapper_target ""
2396 proc gdb_wrapper_init { args } {
2397 global gdb_wrapper_initialized;
2398 global gdb_wrapper_file;
2399 global gdb_wrapper_flags;
2400 global gdb_wrapper_target
2402 if { $gdb_wrapper_initialized == 1 } { return; }
2404 if {[target_info exists needs_status_wrapper] && \
2405 [target_info needs_status_wrapper] != "0"} {
2406 set result [build_wrapper "testglue.o"];
2407 if { $result != "" } {
2408 set gdb_wrapper_file [lindex $result 0];
2409 set gdb_wrapper_flags [lindex $result 1];
2411 warning "Status wrapper failed to build."
2414 set gdb_wrapper_initialized 1
2415 set gdb_wrapper_target [current_target_name]
2418 # Some targets need to always link a special object in. Save its path here.
2419 global gdb_saved_set_unbuffered_mode_obj
2420 set gdb_saved_set_unbuffered_mode_obj ""
2422 proc gdb_compile {source dest type options} {
2423 global GDB_TESTCASE_OPTIONS;
2424 global gdb_wrapper_file;
2425 global gdb_wrapper_flags;
2426 global gdb_wrapper_initialized;
2429 global gdb_saved_set_unbuffered_mode_obj
2431 set outdir [file dirname $dest]
2433 # Add platform-specific options if a shared library was specified using
2434 # "shlib=librarypath" in OPTIONS.
2438 foreach opt $options {
2439 if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] {
2440 if [test_compiler_info "xlc-*"] {
2441 # IBM xlc compiler doesn't accept shared library named other
2442 # than .so: use "-Wl," to bypass this
2443 lappend source "-Wl,$shlib_name"
2444 } elseif { ([istarget "*-*-mingw*"]
2445 || [istarget *-*-cygwin*]
2446 || [istarget *-*-pe*])} {
2447 lappend source "${shlib_name}.a"
2449 lappend source $shlib_name
2451 if { $shlib_found == 0 } {
2453 if { ([istarget "*-*-mingw*"]
2454 || [istarget *-*-cygwin*]) } {
2455 lappend new_options "additional_flags=-Wl,--enable-auto-import"
2458 } elseif { $opt == "shlib_load" } {
2461 lappend new_options $opt
2465 # We typically link to shared libraries using an absolute path, and
2466 # that's how they are found at runtime. If we are going to
2467 # dynamically load one by basename, we must specify rpath. If we
2468 # are using a remote host, DejaGNU will link to the shared library
2469 # using a relative path, so again we must specify an rpath.
2470 if { $shlib_load || ($shlib_found && [is_remote target]) } {
2471 if { ([istarget "*-*-mingw*"]
2472 || [istarget *-*-cygwin*]
2473 || [istarget *-*-pe*]
2474 || [istarget hppa*-*-hpux*])} {
2475 # Do not need anything.
2476 } elseif { [istarget *-*-freebsd*] || [istarget *-*-openbsd*] } {
2477 lappend new_options "ldflags=-Wl,-rpath,${outdir}"
2478 } elseif { [istarget arm*-*-symbianelf*] } {
2479 if { $shlib_load } {
2480 lappend new_options "libs=-ldl"
2483 if { $shlib_load } {
2484 lappend new_options "libs=-ldl"
2486 lappend new_options "ldflags=-Wl,-rpath,\\\$ORIGIN"
2489 set options $new_options
2491 if [target_info exists is_vxworks] {
2492 set options2 { "additional_flags=-Dvxworks" }
2493 set options [concat $options2 $options]
2495 if [info exists GDB_TESTCASE_OPTIONS] {
2496 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
2498 verbose "options are $options"
2499 verbose "source is $source $dest $type $options"
2501 if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init }
2503 if {[target_info exists needs_status_wrapper] && \
2504 [target_info needs_status_wrapper] != "0" && \
2505 [info exists gdb_wrapper_file]} {
2506 lappend options "libs=${gdb_wrapper_file}"
2507 lappend options "ldflags=${gdb_wrapper_flags}"
2510 # Replace the "nowarnings" option with the appropriate additional_flags
2511 # to disable compiler warnings.
2512 set nowarnings [lsearch -exact $options nowarnings]
2513 if {$nowarnings != -1} {
2514 if [target_info exists gdb,nowarnings_flag] {
2515 set flag "additional_flags=[target_info gdb,nowarnings_flag]"
2517 set flag "additional_flags=-w"
2519 set options [lreplace $options $nowarnings $nowarnings $flag]
2522 if { $type == "executable" } {
2523 if { ([istarget "*-*-mingw*"]
2524 || [istarget "*-*-*djgpp"]
2525 || [istarget "*-*-cygwin*"])} {
2526 # Force output to unbuffered mode, by linking in an object file
2527 # with a global contructor that calls setvbuf.
2529 # Compile the special object seperatelly for two reasons:
2530 # 1) Insulate it from $options.
2531 # 2) Avoid compiling it for every gdb_compile invocation,
2532 # which is time consuming, especially if we're remote
2535 if { $gdb_saved_set_unbuffered_mode_obj == "" } {
2536 verbose "compiling gdb_saved_set_unbuffered_obj"
2537 set unbuf_src ${srcdir}/lib/set_unbuffered_mode.c
2538 set unbuf_obj ${objdir}/set_unbuffered_mode.o
2540 set result [gdb_compile "${unbuf_src}" "${unbuf_obj}" object {nowarnings}]
2541 if { $result != "" } {
2545 set gdb_saved_set_unbuffered_mode_obj ${objdir}/set_unbuffered_mode_saved.o
2546 # Link a copy of the output object, because the
2547 # original may be automatically deleted.
2548 remote_exec host "cp -f $unbuf_obj $gdb_saved_set_unbuffered_mode_obj"
2550 verbose "gdb_saved_set_unbuffered_obj already compiled"
2553 # Rely on the internal knowledge that the global ctors are ran in
2554 # reverse link order. In that case, we can use ldflags to
2555 # avoid copying the object file to the host multiple
2557 # This object can only be added if standard libraries are
2558 # used. Thus, we need to disable it if -nostdlib option is used
2559 if {[lsearch -regexp $options "-nostdlib"] < 0 } {
2560 lappend options "ldflags=$gdb_saved_set_unbuffered_mode_obj"
2565 set result [target_compile $source $dest $type $options];
2567 # Prune uninteresting compiler (and linker) output.
2568 regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result
2570 regsub "\[\r\n\]*$" "$result" "" result;
2571 regsub "^\[\r\n\]*" "$result" "" result;
2573 if {[lsearch $options quiet] < 0} {
2574 # We shall update this on a per language basis, to avoid
2575 # changing the entire testsuite in one go.
2576 if {[lsearch $options f77] >= 0} {
2577 gdb_compile_test $source $result
2578 } elseif { $result != "" } {
2579 clone_output "gdb compile failed, $result"
2586 # This is just like gdb_compile, above, except that it tries compiling
2587 # against several different thread libraries, to see which one this
2589 proc gdb_compile_pthreads {source dest type options} {
2591 set why_msg "unrecognized error"
2592 foreach lib {-lpthreads -lpthread -lthread ""} {
2593 # This kind of wipes out whatever libs the caller may have
2594 # set. Or maybe theirs will override ours. How infelicitous.
2595 set options_with_lib [concat $options [list libs=$lib quiet]]
2596 set ccout [gdb_compile $source $dest $type $options_with_lib]
2597 switch -regexp -- $ccout {
2598 ".*no posix threads support.*" {
2599 set why_msg "missing threads include file"
2602 ".*cannot open -lpthread.*" {
2603 set why_msg "missing runtime threads library"
2605 ".*Can't find library for -lpthread.*" {
2606 set why_msg "missing runtime threads library"
2609 pass "successfully compiled posix threads test case"
2615 if {!$built_binfile} {
2616 unsupported "Couldn't compile $source: ${why_msg}"
2621 # Build a shared library from SOURCES. You must use get_compiler_info
2624 proc gdb_compile_shlib {sources dest options} {
2625 set obj_options $options
2627 switch -glob [test_compiler_info] {
2629 lappend obj_options "additional_flags=-qpic"
2632 if { !([istarget "powerpc*-*-aix*"]
2633 || [istarget "rs6000*-*-aix*"]
2634 || [istarget "*-*-cygwin*"]
2635 || [istarget "*-*-mingw*"]
2636 || [istarget "*-*-pe*"]) } {
2637 lappend obj_options "additional_flags=-fpic"
2641 switch -glob [istarget] {
2643 lappend obj_options "additional_flags=+z"
2646 # Disable SGI compiler's implicit -Dsgi
2647 lappend obj_options "additional_flags=-Usgi"
2650 # don't know what the compiler is...
2656 set outdir [file dirname $dest]
2658 foreach source $sources {
2659 set sourcebase [file tail $source]
2660 if {[gdb_compile $source "${outdir}/${sourcebase}.o" object $obj_options] != ""} {
2663 lappend objects ${outdir}/${sourcebase}.o
2666 if [istarget "hppa*-*-hpux*"] {
2667 remote_exec build "ld -b ${objects} -o ${dest}"
2669 set link_options $options
2670 if [test_compiler_info "xlc-*"] {
2671 lappend link_options "additional_flags=-qmkshrobj"
2673 lappend link_options "additional_flags=-shared"
2675 if { ([istarget "*-*-mingw*"]
2676 || [istarget *-*-cygwin*]
2677 || [istarget *-*-pe*])} {
2678 lappend link_options "additional_flags=-Wl,--out-implib,${dest}.a"
2679 } elseif [is_remote target] {
2680 # By default, we do not set the soname. This causes the linker
2681 # on ELF systems to create a DT_NEEDED entry in the executable
2682 # refering to the full path name of the library. This is a
2683 # problem in remote testing if the library is in a different
2684 # directory there. To fix this, we set a soname of just the
2685 # base filename for the library, and add an appropriate -rpath
2686 # to the main executable (in gdb_compile).
2687 set destbase [file tail $dest]
2688 lappend link_options "additional_flags=-Wl,-soname,$destbase"
2691 if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
2697 # This is just like gdb_compile_shlib, above, except that it tries compiling
2698 # against several different thread libraries, to see which one this
2700 proc gdb_compile_shlib_pthreads {sources dest options} {
2702 set why_msg "unrecognized error"
2703 foreach lib {-lpthreads -lpthread -lthread ""} {
2704 # This kind of wipes out whatever libs the caller may have
2705 # set. Or maybe theirs will override ours. How infelicitous.
2706 set options_with_lib [concat $options [list libs=$lib quiet]]
2707 set ccout [gdb_compile_shlib $sources $dest $options_with_lib]
2708 switch -regexp -- $ccout {
2709 ".*no posix threads support.*" {
2710 set why_msg "missing threads include file"
2713 ".*cannot open -lpthread.*" {
2714 set why_msg "missing runtime threads library"
2716 ".*Can't find library for -lpthread.*" {
2717 set why_msg "missing runtime threads library"
2720 pass "successfully compiled posix threads test case"
2726 if {!$built_binfile} {
2727 unsupported "Couldn't compile $sources: ${why_msg}"
2732 # This is just like gdb_compile_pthreads, above, except that we always add the
2733 # objc library for compiling Objective-C programs
2734 proc gdb_compile_objc {source dest type options} {
2736 set why_msg "unrecognized error"
2737 foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} {
2738 # This kind of wipes out whatever libs the caller may have
2739 # set. Or maybe theirs will override ours. How infelicitous.
2740 if { $lib == "solaris" } {
2741 set lib "-lpthread -lposix4"
2743 if { $lib != "-lobjc" } {
2744 set lib "-lobjc $lib"
2746 set options_with_lib [concat $options [list libs=$lib quiet]]
2747 set ccout [gdb_compile $source $dest $type $options_with_lib]
2748 switch -regexp -- $ccout {
2749 ".*no posix threads support.*" {
2750 set why_msg "missing threads include file"
2753 ".*cannot open -lpthread.*" {
2754 set why_msg "missing runtime threads library"
2756 ".*Can't find library for -lpthread.*" {
2757 set why_msg "missing runtime threads library"
2760 pass "successfully compiled objc with posix threads test case"
2766 if {!$built_binfile} {
2767 unsupported "Couldn't compile $source: ${why_msg}"
2772 proc send_gdb { string } {
2773 global suppress_flag;
2774 if { $suppress_flag } {
2775 return "suppressed";
2777 return [remote_send host "$string"];
2783 proc gdb_expect { args } {
2784 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
2785 set atimeout [lindex $args 0];
2786 set expcode [list [lindex $args 1]];
2791 upvar timeout timeout;
2793 if [target_info exists gdb,timeout] {
2794 if [info exists timeout] {
2795 if { $timeout < [target_info gdb,timeout] } {
2796 set gtimeout [target_info gdb,timeout];
2798 set gtimeout $timeout;
2801 set gtimeout [target_info gdb,timeout];
2805 if ![info exists gtimeout] {
2807 if [info exists timeout] {
2808 set gtimeout $timeout;
2812 if [info exists atimeout] {
2813 if { ![info exists gtimeout] || $gtimeout < $atimeout } {
2814 set gtimeout $atimeout;
2817 if ![info exists gtimeout] {
2823 global suppress_flag;
2824 global remote_suppress_flag;
2825 if [info exists remote_suppress_flag] {
2826 set old_val $remote_suppress_flag;
2828 if [info exists suppress_flag] {
2829 if { $suppress_flag } {
2830 set remote_suppress_flag 1;
2834 {uplevel remote_expect host $gtimeout $expcode} string];
2835 if [info exists old_val] {
2836 set remote_suppress_flag $old_val;
2838 if [info exists remote_suppress_flag] {
2839 unset remote_suppress_flag;
2844 global errorInfo errorCode;
2846 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
2848 return -code $code $string
2852 # gdb_expect_list TEST SENTINEL LIST -- expect a sequence of outputs
2854 # Check for long sequence of output by parts.
2855 # TEST: is the test message to be printed with the test success/fail.
2856 # SENTINEL: Is the terminal pattern indicating that output has finished.
2857 # LIST: is the sequence of outputs to match.
2858 # If the sentinel is recognized early, it is considered an error.
2861 # 1 if the test failed,
2862 # 0 if the test passes,
2863 # -1 if there was an internal error.
2865 proc gdb_expect_list {test sentinel list} {
2867 global suppress_flag
2870 if { $suppress_flag } {
2872 unresolved "${test}"
2874 while { ${index} < [llength ${list}] } {
2875 set pattern [lindex ${list} ${index}]
2876 set index [expr ${index} + 1]
2877 verbose -log "gdb_expect_list pattern: /$pattern/" 2
2878 if { ${index} == [llength ${list}] } {
2881 -re "${pattern}${sentinel}" {
2882 # pass "${test}, pattern ${index} + sentinel"
2885 fail "${test} (pattern ${index} + sentinel)"
2888 -re ".*A problem internal to GDB has been detected" {
2889 fail "${test} (GDB internal error)"
2891 gdb_internal_error_resync
2894 fail "${test} (pattern ${index} + sentinel) (timeout)"
2899 # unresolved "${test}, pattern ${index} + sentinel"
2905 # pass "${test}, pattern ${index}"
2908 fail "${test} (pattern ${index})"
2911 -re ".*A problem internal to GDB has been detected" {
2912 fail "${test} (GDB internal error)"
2914 gdb_internal_error_resync
2917 fail "${test} (pattern ${index}) (timeout)"
2922 # unresolved "${test}, pattern ${index}"
2936 proc gdb_suppress_entire_file { reason } {
2937 global suppress_flag;
2939 warning "$reason\n";
2940 set suppress_flag -1;
2944 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
2945 # gdb_expect to fail immediately (until the next call to
2946 # gdb_stop_suppressing_tests).
2948 proc gdb_suppress_tests { args } {
2949 global suppress_flag;
2951 return; # fnf - disable pending review of results where
2952 # testsuite ran better without this
2955 if { $suppress_flag == 1 } {
2956 if { [llength $args] > 0 } {
2957 warning "[lindex $args 0]\n";
2959 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
2965 # Clear suppress_flag.
2967 proc gdb_stop_suppressing_tests { } {
2968 global suppress_flag;
2970 if [info exists suppress_flag] {
2971 if { $suppress_flag > 0 } {
2972 set suppress_flag 0;
2973 clone_output "Tests restarted.\n";
2976 set suppress_flag 0;
2980 proc gdb_clear_suppressed { } {
2981 global suppress_flag;
2983 set suppress_flag 0;
2986 proc gdb_start { } {
2991 catch default_gdb_exit
2995 # gdb_load_cmd -- load a file into the debugger.
2996 # ARGS - additional args to load command.
2997 # return a -1 if anything goes wrong.
2999 proc gdb_load_cmd { args } {
3002 if [target_info exists gdb_load_timeout] {
3003 set loadtimeout [target_info gdb_load_timeout]
3005 set loadtimeout 1600
3007 send_gdb "load $args\n"
3008 verbose "Timeout is now $loadtimeout seconds" 2
3009 gdb_expect $loadtimeout {
3010 -re "Loading section\[^\r\]*\r\n" {
3013 -re "Start address\[\r\]*\r\n" {
3016 -re "Transfer rate\[\r\]*\r\n" {
3019 -re "Memory access error\[^\r\]*\r\n" {
3020 perror "Failed to load program"
3023 -re "$gdb_prompt $" {
3026 -re "(.*)\r\n$gdb_prompt " {
3027 perror "Unexpected reponse from 'load' -- $expect_out(1,string)"
3031 perror "Timed out trying to load $args."
3038 # Invoke "gcore". CORE is the name of the core file to write. TEST
3039 # is the name of the test case. This will return 1 if the core file
3040 # was created, 0 otherwise. If this fails to make a core file because
3041 # this configuration of gdb does not support making core files, it
3042 # will call "unsupported", not "fail". However, if this fails to make
3043 # a core file for some other reason, then it will call "fail".
3045 proc gdb_gcore_cmd {core test} {
3049 gdb_test_multiple "gcore $core" $test {
3050 -re "Saved corefile .*\[\r\n\]+$gdb_prompt $" {
3055 -re "Undefined command.*$gdb_prompt $" {
3057 verbose -log "'gcore' command undefined in gdb_gcore_cmd"
3060 -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
3068 # Return the filename to download to the target and load on the target
3069 # for this shared library. Normally just LIBNAME, unless shared libraries
3070 # for this target have separate link and load images.
3072 proc shlib_target_file { libname } {
3076 # Return the filename GDB will load symbols from when debugging this
3077 # shared library. Normally just LIBNAME, unless shared libraries for
3078 # this target have separate link and load images.
3080 proc shlib_symbol_file { libname } {
3084 # Return the filename to download to the target and load for this
3085 # executable. Normally just BINFILE unless it is renamed to something
3086 # else for this target.
3088 proc exec_target_file { binfile } {
3092 # Return the filename GDB will load symbols from when debugging this
3093 # executable. Normally just BINFILE unless executables for this target
3094 # have separate files for symbols.
3096 proc exec_symbol_file { binfile } {
3100 # Rename the executable file. Normally this is just BINFILE1 being renamed
3101 # to BINFILE2, but some targets require multiple binary files.
3102 proc gdb_rename_execfile { binfile1 binfile2 } {
3103 file rename -force [exec_target_file ${binfile1}] \
3104 [exec_target_file ${binfile2}]
3105 if { [exec_target_file ${binfile1}] != [exec_symbol_file ${binfile1}] } {
3106 file rename -force [exec_symbol_file ${binfile1}] \
3107 [exec_symbol_file ${binfile2}]
3111 # "Touch" the executable file to update the date. Normally this is just
3112 # BINFILE, but some targets require multiple files.
3113 proc gdb_touch_execfile { binfile } {
3114 set time [clock seconds]
3115 file mtime [exec_target_file ${binfile}] $time
3116 if { [exec_target_file ${binfile}] != [exec_symbol_file ${binfile}] } {
3117 file mtime [exec_symbol_file ${binfile}] $time
3123 # Copy a file to the remote target and return its target filename.
3124 # Schedule the file to be deleted at the end of this test.
3126 proc gdb_download { filename } {
3129 set destname [remote_download target $filename]
3130 lappend cleanfiles $destname
3134 # gdb_load_shlibs LIB...
3136 # Copy the listed libraries to the target.
3138 proc gdb_load_shlibs { args } {
3139 if {![is_remote target]} {
3143 foreach file $args {
3144 gdb_download [shlib_target_file $file]
3147 # Even if the target supplies full paths for shared libraries,
3148 # they may not be paths for this system.
3149 gdb_test "set solib-search-path [file dirname [lindex $args 0]]" "" ""
3153 # gdb_load -- load a file into the debugger.
3154 # Many files in config/*.exp override this procedure.
3156 proc gdb_load { arg } {
3157 return [gdb_file_cmd $arg]
3160 # gdb_reload -- load a file into the target. Called before "running",
3161 # either the first time or after already starting the program once,
3162 # for remote targets. Most files that override gdb_load should now
3163 # override this instead.
3165 proc gdb_reload { } {
3166 # For the benefit of existing configurations, default to gdb_load.
3167 # Specifying no file defaults to the executable currently being
3169 return [gdb_load ""]
3172 proc gdb_continue { function } {
3175 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
3178 proc default_gdb_init { args } {
3179 global gdb_wrapper_initialized
3180 global gdb_wrapper_target
3181 global gdb_test_file_name
3186 gdb_clear_suppressed;
3188 set gdb_test_file_name [file rootname [file tail [lindex $args 0]]]
3190 # Make sure that the wrapper is rebuilt
3191 # with the appropriate multilib option.
3192 if { $gdb_wrapper_target != [current_target_name] } {
3193 set gdb_wrapper_initialized 0
3196 # Unlike most tests, we have a small number of tests that generate
3197 # a very large amount of output. We therefore increase the expect
3198 # buffer size to be able to contain the entire test output.
3200 # Also set this value for the currently running GDB.
3201 match_max [match_max -d]
3203 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
3204 if { [llength $args] > 0 } {
3207 set file [lindex $args 0];
3209 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
3212 if [target_info exists gdb_prompt] {
3213 set gdb_prompt [target_info gdb_prompt];
3215 set gdb_prompt "\\(gdb\\)"
3218 if [info exists use_gdb_stub] {
3223 # Turn BASENAME into a full file name in the standard output
3224 # directory. It is ok if BASENAME is the empty string; in this case
3225 # the directory is returned.
3227 proc standard_output_file {basename} {
3228 global objdir subdir
3230 return [file join $objdir $subdir $basename]
3233 # Set 'testfile', 'srcfile', and 'binfile'.
3235 # ARGS is a list of source file specifications.
3236 # Without any arguments, the .exp file's base name is used to
3237 # compute the source file name. The ".c" extension is added in this case.
3238 # If ARGS is not empty, each entry is a source file specification.
3239 # If the specification starts with a ".", it is treated as a suffix
3240 # to append to the .exp file's base name.
3241 # If the specification is the empty string, it is treated as if it
3243 # Otherwise it is a file name.
3244 # The first file in the list is used to set the 'srcfile' global.
3245 # Each subsequent name is used to set 'srcfile2', 'srcfile3', etc.
3247 # Most tests should call this without arguments.
3249 # If a completely different binary file name is needed, then it
3250 # should be handled in the .exp file with a suitable comment.
3252 proc standard_testfile {args} {
3253 global gdb_test_file_name
3255 global gdb_test_file_last_vars
3258 global testfile binfile
3260 set testfile $gdb_test_file_name
3261 set binfile [standard_output_file ${testfile}]
3263 if {[llength $args] == 0} {
3267 # Unset our previous output variables.
3268 # This can help catch hidden bugs.
3269 if {[info exists gdb_test_file_last_vars]} {
3270 foreach varname $gdb_test_file_last_vars {
3272 catch {unset $varname}
3275 # 'executable' is often set by tests.
3276 set gdb_test_file_last_vars {executable}
3280 set varname srcfile$suffix
3283 # Handle an extension.
3286 } elseif {[string range $arg 0 0] == "."} {
3287 set arg $testfile$arg
3291 lappend gdb_test_file_last_vars $varname
3293 if {$suffix == ""} {
3301 # The default timeout used when testing GDB commands. We want to use
3302 # the same timeout as the default dejagnu timeout, unless the user has
3303 # already provided a specific value (probably through a site.exp file).
3304 global gdb_test_timeout
3305 if ![info exists gdb_test_timeout] {
3306 set gdb_test_timeout $timeout
3309 # A list of global variables that GDB testcases should not use.
3310 # We try to prevent their use by monitoring write accesses and raising
3311 # an error when that happens.
3312 set banned_variables { bug_id prms_id }
3314 # A list of procedures that GDB testcases should not use.
3315 # We try to prevent their use by monitoring invocations and raising
3316 # an error when that happens.
3317 set banned_procedures { strace }
3319 # gdb_init is called by runtest at start, but also by several
3320 # tests directly; gdb_finish is only called from within runtest after
3321 # each test source execution.
3322 # Placing several traces by repetitive calls to gdb_init leads
3323 # to problems, as only one trace is removed in gdb_finish.
3324 # To overcome this possible problem, we add a variable that records
3325 # if the banned variables and procedures are already traced.
3328 proc gdb_init { args } {
3329 # Reset the timeout value to the default. This way, any testcase
3330 # that changes the timeout value without resetting it cannot affect
3331 # the timeout used in subsequent testcases.
3332 global gdb_test_timeout
3334 set timeout $gdb_test_timeout
3336 # Block writes to all banned variables, and invocation of all
3337 # banned procedures...
3338 global banned_variables
3339 global banned_procedures
3340 global banned_traced
3341 if (!$banned_traced) {
3342 foreach banned_var $banned_variables {
3343 global "$banned_var"
3344 trace add variable "$banned_var" write error
3346 foreach banned_proc $banned_procedures {
3347 global "$banned_proc"
3348 trace add execution "$banned_proc" enter error
3353 # We set LC_ALL, LC_CTYPE, and LANG to C so that we get the same
3354 # messages as expected.
3359 # Don't let a .inputrc file or an existing setting of INPUTRC mess up
3360 # the test results. Even if /dev/null doesn't exist on the particular
3361 # platform, the readline library will use the default setting just by
3362 # failing to open the file. OTOH, opening /dev/null successfully will
3363 # also result in the default settings being used since nothing will be
3364 # read from this file.
3365 setenv INPUTRC "/dev/null"
3367 # The gdb.base/readline.exp arrow key test relies on the standard VT100
3368 # bindings, so make sure that an appropriate terminal is selected.
3369 # The same bug doesn't show up if we use ^P / ^N instead.
3372 # Some tests (for example gdb.base/maint.exp) shell out from gdb to use
3373 # grep. Clear GREP_OPTIONS to make the behavoiur predictable,
3374 # especially having color output turned on can cause tests to fail.
3375 setenv GREP_OPTIONS ""
3377 # Clear $gdbserver_reconnect_p.
3378 global gdbserver_reconnect_p
3379 set gdbserver_reconnect_p 1
3380 unset gdbserver_reconnect_p
3382 return [eval default_gdb_init $args];
3385 proc gdb_finish { } {
3388 # Exit first, so that the files are no longer in use.
3391 if { [llength $cleanfiles] > 0 } {
3392 eval remote_file target delete $cleanfiles
3396 # Unblock write access to the banned variables. Dejagnu typically
3397 # resets some of them between testcases.
3398 global banned_variables
3399 global banned_procedures
3400 global banned_traced
3401 if ($banned_traced) {
3402 foreach banned_var $banned_variables {
3403 global "$banned_var"
3404 trace remove variable "$banned_var" write error
3406 foreach banned_proc $banned_procedures {
3407 global "$banned_proc"
3408 trace remove execution "$banned_proc" enter error
3415 set debug_format "unknown"
3417 # Run the gdb command "info source" and extract the debugging format
3418 # information from the output and save it in debug_format.
3420 proc get_debug_format { } {
3426 set debug_format "unknown"
3427 send_gdb "info source\n"
3429 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
3430 set debug_format $expect_out(1,string)
3431 verbose "debug format is $debug_format"
3434 -re "No current source file.\r\n$gdb_prompt $" {
3435 perror "get_debug_format used when no current source file"
3438 -re "$gdb_prompt $" {
3439 warning "couldn't check debug format (no valid response)."
3443 warning "couldn't check debug format (timeout)."
3449 # Return true if FORMAT matches the debug format the current test was
3450 # compiled with. FORMAT is a shell-style globbing pattern; it can use
3451 # `*', `[...]', and so on.
3453 # This function depends on variables set by `get_debug_format', above.
3455 proc test_debug_format {format} {
3458 return [expr [string match $format $debug_format] != 0]
3461 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
3462 # COFF, stabs, etc). If that format matches the format that the
3463 # current test was compiled with, then the next test is expected to
3464 # fail for any target. Returns 1 if the next test or set of tests is
3465 # expected to fail, 0 otherwise (or if it is unknown). Must have
3466 # previously called get_debug_format.
3467 proc setup_xfail_format { format } {
3468 set ret [test_debug_format $format];
3476 # gdb_get_line_number TEXT [FILE]
3478 # Search the source file FILE, and return the line number of the
3479 # first line containing TEXT. If no match is found, an error is thrown.
3481 # TEXT is a string literal, not a regular expression.
3483 # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is
3484 # specified, and does not start with "/", then it is assumed to be in
3485 # "$srcdir/$subdir". This is awkward, and can be fixed in the future,
3486 # by changing the callers and the interface at the same time.
3487 # In particular: gdb.base/break.exp, gdb.base/condbreak.exp,
3488 # gdb.base/ena-dis-br.exp.
3490 # Use this function to keep your test scripts independent of the
3491 # exact line numbering of the source file. Don't write:
3493 # send_gdb "break 20"
3495 # This means that if anyone ever edits your test's source file,
3496 # your test could break. Instead, put a comment like this on the
3497 # source file line you want to break at:
3499 # /* breakpoint spot: frotz.exp: test name */
3501 # and then write, in your test script (which we assume is named
3504 # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
3506 # (Yes, Tcl knows how to handle the nested quotes and brackets.
3509 # % puts "foo [lindex "bar baz" 1]"
3512 # Tcl is quite clever, for a little stringy language.)
3516 # The previous implementation of this procedure used the gdb search command.
3517 # This version is different:
3519 # . It works with MI, and it also works when gdb is not running.
3521 # . It operates on the build machine, not the host machine.
3523 # . For now, this implementation fakes a current directory of
3524 # $srcdir/$subdir to be compatible with the old implementation.
3525 # This will go away eventually and some callers will need to
3528 # . The TEXT argument is literal text and matches literally,
3529 # not a regular expression as it was before.
3531 # . State changes in gdb, such as changing the current file
3532 # and setting $_, no longer happen.
3534 # After a bit of time we can forget about the differences from the
3535 # old implementation.
3537 # --chastain 2004-08-05
3539 proc gdb_get_line_number { text { file "" } } {
3544 if { "$file" == "" } then {
3547 if { ! [regexp "^/" "$file"] } then {
3548 set file "$srcdir/$subdir/$file"
3551 if { [ catch { set fd [open "$file"] } message ] } then {
3556 for { set line 1 } { 1 } { incr line } {
3557 if { [ catch { set nchar [gets "$fd" body] } message ] } then {
3560 if { $nchar < 0 } then {
3563 if { [string first "$text" "$body"] >= 0 } then {
3569 if { [ catch { close "$fd" } message ] } then {
3574 error "undefined tag \"$text\""
3580 # gdb_continue_to_end:
3581 # The case where the target uses stubs has to be handled specially. If a
3582 # stub is used, we set a breakpoint at exit because we cannot rely on
3583 # exit() behavior of a remote target.
3585 # MSSG is the error message that gets printed. If not given, a
3587 # COMMAND is the command to invoke. If not given, "continue" is
3589 # ALLOW_EXTRA is a flag indicating whether the test should expect
3590 # extra output between the "Continuing." line and the program
3591 # exiting. By default it is zero; if nonzero, any extra output
3594 proc gdb_continue_to_end {{mssg ""} {command continue} {allow_extra 0}} {
3595 global inferior_exited_re use_gdb_stub
3598 set text "continue until exit"
3600 set text "continue until exit at $mssg"
3608 if {![gdb_breakpoint "exit"]} {
3611 gdb_test $command "Continuing..*Breakpoint .*exit.*" \
3614 # Continue until we exit. Should not stop again.
3615 # Don't bother to check the output of the program, that may be
3616 # extremely tough for some remote systems.
3618 "Continuing.\[\r\n0-9\]+${extra}(... EXIT code 0\[\r\n\]+|$inferior_exited_re normally).*"\
3623 proc rerun_to_main {} {
3624 global gdb_prompt use_gdb_stub
3629 -re ".*Breakpoint .*main .*$gdb_prompt $"\
3630 {pass "rerun to main" ; return 0}
3631 -re "$gdb_prompt $"\
3632 {fail "rerun to main" ; return 0}
3633 timeout {fail "(timeout) rerun to main" ; return 0}
3638 -re "The program .* has been started already.*y or n. $" {
3642 -re "Starting program.*$gdb_prompt $"\
3643 {pass "rerun to main" ; return 0}
3644 -re "$gdb_prompt $"\
3645 {fail "rerun to main" ; return 0}
3646 timeout {fail "(timeout) rerun to main" ; return 0}
3651 # Print a message and return true if a test should be skipped
3652 # due to lack of floating point suport.
3654 proc gdb_skip_float_test { msg } {
3655 if [target_info exists gdb,skip_float_tests] {
3656 verbose "Skipping test '$msg': no float tests.";
3662 # Print a message and return true if a test should be skipped
3663 # due to lack of stdio support.
3665 proc gdb_skip_stdio_test { msg } {
3666 if [target_info exists gdb,noinferiorio] {
3667 verbose "Skipping test '$msg': no inferior i/o.";
3673 proc gdb_skip_bogus_test { msg } {
3677 # Return true if a test should be skipped due to lack of XML support
3679 # NOTE: This must be called while gdb is *not* running.
3681 proc gdb_skip_xml_test { } {
3684 global xml_missing_cached
3686 if {[info exists xml_missing_cached]} {
3687 return $xml_missing_cached
3691 set xml_missing_cached 0
3692 gdb_test_multiple "set tdesc filename ${srcdir}/gdb.xml/trivial.xml" "" {
3693 -re ".*XML support was disabled at compile time.*$gdb_prompt $" {
3694 set xml_missing_cached 1
3696 -re ".*$gdb_prompt $" { }
3699 return $xml_missing_cached
3702 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
3703 # ${binfile}.dbglnk, which is just like the executable ($binfile) but without
3704 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
3705 # the name of a debuginfo only file. This file will be stored in the same
3708 # Functions for separate debug info testing
3710 # starting with an executable:
3711 # foo --> original executable
3713 # at the end of the process we have:
3714 # foo.stripped --> foo w/o debug info
3715 # foo.debug --> foo's debug info
3716 # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug.
3718 # Return the build-id hex string (usually 160 bits as 40 hex characters)
3719 # converted to the form: .build-id/ab/cdef1234...89.debug
3720 # Return "" if no build-id found.
3721 proc build_id_debug_filename_get { exec } {
3722 set tmp "${exec}-tmp"
3723 set objcopy_program [transform objcopy]
3725 set result [catch "exec $objcopy_program -j .note.gnu.build-id -O binary $exec $tmp" output]
3726 verbose "result is $result"
3727 verbose "output is $output"
3732 fconfigure $fi -translation binary
3733 # Skip the NOTE header.
3738 if ![string compare $data ""] then {
3741 # Convert it to hex.
3742 binary scan $data H* data
3743 regsub {^..} $data {\0/} data
3744 return ".build-id/${data}.debug";
3747 # Create stripped files for DEST, replacing it. If ARGS is passed, it is a
3748 # list of optional flags. The only currently supported flag is no-main,
3749 # which removes the symbol entry for main from the separate debug file.
3751 # Function returns zero on success. Function will return non-zero failure code
3752 # on some targets not supporting separate debug info (such as i386-msdos).
3754 proc gdb_gnu_strip_debug { dest args } {
3756 # Use the first separate debug info file location searched by GDB so the
3757 # run cannot be broken by some stale file searched with higher precedence.
3758 set debug_file "${dest}.debug"
3760 set strip_to_file_program [transform strip]
3761 set objcopy_program [transform objcopy]
3763 set debug_link [file tail $debug_file]
3764 set stripped_file "${dest}.stripped"
3766 # Get rid of the debug info, and store result in stripped_file
3767 # something like gdb/testsuite/gdb.base/blah.stripped.
3768 set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
3769 verbose "result is $result"
3770 verbose "output is $output"
3775 # Workaround PR binutils/10802:
3776 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
3777 set perm [file attributes ${dest} -permissions]
3778 file attributes ${stripped_file} -permissions $perm
3780 # Get rid of everything but the debug info, and store result in debug_file
3781 # This will be in the .debug subdirectory, see above.
3782 set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
3783 verbose "result is $result"
3784 verbose "output is $output"
3789 # If no-main is passed, strip the symbol for main from the separate
3790 # file. This is to simulate the behavior of elfutils's eu-strip, which
3791 # leaves the symtab in the original file only. There's no way to get
3792 # objcopy or strip to remove the symbol table without also removing the
3793 # debugging sections, so this is as close as we can get.
3794 if { [llength $args] == 1 && [lindex $args 0] == "no-main" } {
3795 set result [catch "exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp" output]
3796 verbose "result is $result"
3797 verbose "output is $output"
3801 file delete "${debug_file}"
3802 file rename "${debug_file}-tmp" "${debug_file}"
3805 # Link the two previous output files together, adding the .gnu_debuglink
3806 # section to the stripped_file, containing a pointer to the debug_file,
3807 # save the new file in dest.
3808 # This will be the regular executable filename, in the usual location.
3809 set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
3810 verbose "result is $result"
3811 verbose "output is $output"
3816 # Workaround PR binutils/10802:
3817 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
3818 set perm [file attributes ${stripped_file} -permissions]
3819 file attributes ${dest} -permissions $perm
3824 # Test the output of GDB_COMMAND matches the pattern obtained
3825 # by concatenating all elements of EXPECTED_LINES. This makes
3826 # it possible to split otherwise very long string into pieces.
3827 # If third argument is not empty, it's used as the name of the
3828 # test to be printed on pass/fail.
3829 proc help_test_raw { gdb_command expected_lines args } {
3830 set message $gdb_command
3831 if [llength $args]>0 then {
3832 set message [lindex $args 0]
3834 set expected_output [join $expected_lines ""]
3835 gdb_test "${gdb_command}" "${expected_output}" $message
3838 # Test the output of "help COMMAND_CLASS". EXPECTED_INITIAL_LINES
3839 # are regular expressions that should match the beginning of output,
3840 # before the list of commands in that class. The presence of
3841 # command list and standard epilogue will be tested automatically.
3842 proc test_class_help { command_class expected_initial_lines args } {
3844 "List of commands\:.*\[\r\n\]+"
3845 "Type \"help\" followed by command name for full documentation\.\[\r\n\]+"
3846 "Type \"apropos word\" to search for commands related to \"word\"\.[\r\n\]+"
3847 "Command name abbreviations are allowed if unambiguous\."
3849 set l_entire_body [concat $expected_initial_lines $l_stock_body]
3851 eval [list help_test_raw "help ${command_class}" $l_entire_body] $args
3854 # COMMAND_LIST should have either one element -- command to test, or
3855 # two elements -- abbreviated command to test, and full command the first
3856 # element is abbreviation of.
3857 # The command must be a prefix command. EXPECTED_INITIAL_LINES
3858 # are regular expressions that should match the beginning of output,
3859 # before the list of subcommands. The presence of
3860 # subcommand list and standard epilogue will be tested automatically.
3861 proc test_prefix_command_help { command_list expected_initial_lines args } {
3862 set command [lindex $command_list 0]
3863 if {[llength $command_list]>1} {
3864 set full_command [lindex $command_list 1]
3866 set full_command $command
3868 # Use 'list' and not just {} because we want variables to
3869 # be expanded in this list.
3870 set l_stock_body [list\
3871 "List of $full_command subcommands\:.*\[\r\n\]+"\
3872 "Type \"help $full_command\" followed by $full_command subcommand name for full documentation\.\[\r\n\]+"\
3873 "Type \"apropos word\" to search for commands related to \"word\"\.\[\r\n\]+"\
3874 "Command name abbreviations are allowed if unambiguous\."]
3875 set l_entire_body [concat $expected_initial_lines $l_stock_body]
3876 if {[llength $args]>0} {
3877 help_test_raw "help ${command}" $l_entire_body [lindex $args 0]
3879 help_test_raw "help ${command}" $l_entire_body
3883 # Build executable named EXECUTABLE from specifications that allow
3884 # different options to be passed to different sub-compilations.
3885 # TESTNAME is the name of the test; this is passed to 'untested' if
3887 # OPTIONS is passed to the final link, using gdb_compile.
3888 # ARGS is a flat list of source specifications, of the form:
3889 # { SOURCE1 OPTIONS1 [ SOURCE2 OPTIONS2 ]... }
3890 # Each SOURCE is compiled to an object file using its OPTIONS,
3891 # using gdb_compile.
3892 # Returns 0 on success, -1 on failure.
3893 proc build_executable_from_specs {testname executable options args} {
3897 set binfile [standard_output_file $executable]
3901 foreach {s local_options} $args {
3902 if { [gdb_compile "${srcdir}/${subdir}/${s}" "${binfile}${i}.o" object $local_options] != "" } {
3906 lappend objects "${binfile}${i}.o"
3910 if { [gdb_compile $objects "${binfile}" executable $options] != "" } {
3916 if { [lsearch -exact $options "c++"] >= 0 } {
3917 set info_options "c++"
3919 if [get_compiler_info ${info_options}] {
3925 # Build executable named EXECUTABLE, from SOURCES. If SOURCES are not
3926 # provided, uses $EXECUTABLE.c. The TESTNAME paramer is the name of test
3927 # to pass to untested, if something is wrong. OPTIONS are passed
3928 # to gdb_compile directly.
3929 proc build_executable { testname executable {sources ""} {options {debug}} } {
3930 if {[llength $sources]==0} {
3931 set sources ${executable}.c
3934 set arglist [list $testname $executable $options]
3935 foreach source $sources {
3936 lappend arglist $source $options
3939 return [eval build_executable_from_specs $arglist]
3942 # Starts fresh GDB binary and loads EXECUTABLE into GDB. EXECUTABLE is
3943 # the basename of the binary.
3944 proc clean_restart { executable } {
3947 set binfile [standard_output_file ${executable}]
3951 gdb_reinitialize_dir $srcdir/$subdir
3955 # Prepares for testing by calling build_executable_full, then
3957 # TESTNAME is the name of the test.
3958 # Each element in ARGS is a list of the form
3959 # { EXECUTABLE OPTIONS SOURCE_SPEC... }
3960 # These are passed to build_executable_from_specs, which see.
3961 # The last EXECUTABLE is passed to clean_restart.
3962 # Returns 0 on success, non-zero on failure.
3963 proc prepare_for_testing_full {testname args} {
3964 foreach spec $args {
3965 if {[eval build_executable_from_specs [list $testname] $spec] == -1} {
3968 set executable [lindex $spec 0]
3970 clean_restart $executable
3974 # Prepares for testing, by calling build_executable, and then clean_restart.
3975 # Please refer to build_executable for parameter description.
3976 proc prepare_for_testing { testname executable {sources ""} {options {debug}}} {
3978 if {[build_executable $testname $executable $sources $options] == -1} {
3981 clean_restart $executable
3986 proc get_valueof { fmt exp default } {
3989 set test "get valueof \"${exp}\""
3991 gdb_test_multiple "print${fmt} ${exp}" "$test" {
3992 -re "\\$\[0-9\]* = (.*)\[\r\n\]*$gdb_prompt $" {
3993 set val $expect_out(1,string)
3997 fail "$test (timeout)"
4003 proc get_integer_valueof { exp default } {
4006 set test "get integer valueof \"${exp}\""
4008 gdb_test_multiple "print /d ${exp}" "$test" {
4009 -re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" {
4010 set val $expect_out(1,string)
4014 fail "$test (timeout)"
4020 proc get_hexadecimal_valueof { exp default } {
4022 send_gdb "print /x ${exp}\n"
4023 set test "get hexadecimal valueof \"${exp}\""
4025 -re "\\$\[0-9\]* = (0x\[0-9a-zA-Z\]+).*$gdb_prompt $" {
4026 set val $expect_out(1,string)
4031 fail "$test (timeout)"
4037 proc get_sizeof { type default } {
4038 return [get_integer_valueof "sizeof (${type})" $default]
4041 # Get the current value for remotetimeout and return it.
4042 proc get_remotetimeout { } {
4046 gdb_test_multiple "show remotetimeout" "" {
4047 -re "Timeout limit to wait for target to respond is ($decimal).*$gdb_prompt $" {
4048 return $expect_out(1,string);
4052 # Pick the default that gdb uses
4053 warning "Unable to read remotetimeout"
4057 # Set the remotetimeout to the specified timeout. Nothing is returned.
4058 proc set_remotetimeout { timeout } {
4061 gdb_test_multiple "set remotetimeout $timeout" "" {
4062 -re "$gdb_prompt $" {
4063 verbose "Set remotetimeout to $timeout\n"
4068 # Log gdb command line and script if requested.
4069 if {[info exists TRANSCRIPT]} {
4070 rename send_gdb real_send_gdb
4071 rename remote_spawn real_remote_spawn
4072 rename remote_close real_remote_close
4074 global gdb_transcript
4075 set gdb_transcript ""
4077 global gdb_trans_count
4078 set gdb_trans_count 1
4080 proc remote_spawn {args} {
4081 global gdb_transcript gdb_trans_count outdir
4083 if {$gdb_transcript != ""} {
4084 close $gdb_transcript
4086 set gdb_transcript [open [file join $outdir transcript.$gdb_trans_count] w]
4087 puts $gdb_transcript [lindex $args 1]
4088 incr gdb_trans_count
4090 return [uplevel real_remote_spawn $args]
4093 proc remote_close {args} {
4094 global gdb_transcript
4096 if {$gdb_transcript != ""} {
4097 close $gdb_transcript
4098 set gdb_transcript ""
4101 return [uplevel real_remote_close $args]
4104 proc send_gdb {args} {
4105 global gdb_transcript
4107 if {$gdb_transcript != ""} {
4108 puts -nonewline $gdb_transcript [lindex $args 0]
4111 return [uplevel real_send_gdb $args]
4115 proc core_find {binfile {deletefiles {}} {arg ""}} {
4116 global objdir subdir
4118 set destcore "$binfile.core"
4119 file delete $destcore
4121 # Create a core file named "$destcore" rather than just "core", to
4122 # avoid problems with sys admin types that like to regularly prune all
4123 # files named "core" from the system.
4125 # Arbitrarily try setting the core size limit to "unlimited" since
4126 # this does not hurt on systems where the command does not work and
4127 # allows us to generate a core on systems where it does.
4129 # Some systems append "core" to the name of the program; others append
4130 # the name of the program to "core"; still others (like Linux, as of
4131 # May 2003) create cores named "core.PID". In the latter case, we
4132 # could have many core files lying around, and it may be difficult to
4133 # tell which one is ours, so let's run the program in a subdirectory.
4135 set coredir [standard_output_file coredir.[getpid]]
4137 catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile} ${arg}; true) >/dev/null 2>&1\""
4138 # remote_exec host "${binfile}"
4139 foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
4140 if [remote_file build exists $i] {
4141 remote_exec build "mv $i $destcore"
4145 # Check for "core.PID".
4146 if { $found == 0 } {
4147 set names [glob -nocomplain -directory $coredir core.*]
4148 if {[llength $names] == 1} {
4149 set corefile [file join $coredir [lindex $names 0]]
4150 remote_exec build "mv $corefile $destcore"
4154 if { $found == 0 } {
4155 # The braindamaged HPUX shell quits after the ulimit -c above
4156 # without executing ${binfile}. So we try again without the
4157 # ulimit here if we didn't find a core file above.
4158 # Oh, I should mention that any "braindamaged" non-Unix system has
4159 # the same problem. I like the cd bit too, it's really neat'n stuff.
4160 catch "system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\""
4161 foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" {
4162 if [remote_file build exists $i] {
4163 remote_exec build "mv $i $destcore"
4169 # Try to clean up after ourselves.
4170 foreach deletefile $deletefiles {
4171 remote_file build delete [file join $coredir $deletefile]
4173 remote_exec build "rmdir $coredir"
4175 if { $found == 0 } {
4176 warning "can't generate a core file - core tests suppressed - check ulimit -c"
4182 # gdb_target_symbol_prefix_flags returns a string that can be added
4183 # to gdb_compile options to define SYMBOL_PREFIX macro value
4184 # symbol_prefix_flags returns a string that can be added
4185 # for targets that use underscore as symbol prefix.
4186 # TODO: find out automatically if the target needs this.
4188 proc gdb_target_symbol_prefix_flags {} {
4189 if { [istarget "*-*-cygwin*"] || [istarget "i?86-*-mingw*"]
4190 || [istarget "*-*-msdosdjgpp*"] || [istarget "*-*-go32*"] } {
4191 return "additional_flags=-DSYMBOL_PREFIX=\"_\""
4197 # Always load compatibility stuff.