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
139 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
140 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
141 -re "A program is being debugged already.*Are you sure you want to change the file.*y or n. $" {
145 -re "Discard symbol table from .*y or n.*$" {
149 -re "$gdb_prompt $" {}
151 perror "couldn't unload file in $GDB (timeout)."
157 # Many of the tests depend on setting breakpoints at various places and
158 # running until that breakpoint is reached. At times, we want to start
159 # with a clean-slate with respect to breakpoints, so this utility proc
160 # lets us do this without duplicating this code everywhere.
163 proc delete_breakpoints {} {
166 # we need a larger timeout value here or this thing just confuses
167 # itself. May need a better implementation if possible. - guo
169 send_gdb "delete breakpoints\n"
171 -re "Delete all breakpoints.*y or n.*$" {
175 -re "$gdb_prompt $" { # This happens if there were no breakpoints
177 timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
179 send_gdb "info breakpoints\n"
181 -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
182 -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
183 -re "Delete all breakpoints.*or n.*$" {
187 timeout { perror "info breakpoints (timeout)" ; return }
191 # Generic run command.
193 # The second pattern below matches up to the first newline *only*.
194 # Using ``.*$'' could swallow up output that we attempt to match
197 # N.B. This function does not wait for gdb to return to the prompt,
198 # that is the caller's responsibility.
200 proc gdb_run_cmd {args} {
201 global gdb_prompt use_gdb_stub
203 if [target_info exists gdb_init_command] {
204 send_gdb "[target_info gdb_init_command]\n";
206 -re "$gdb_prompt $" { }
208 perror "gdb_init_command for target failed";
215 if [target_info exists gdb,do_reload_on_run] {
216 if { [gdb_reload] != 0 } {
219 send_gdb "continue\n";
221 -re "Continu\[^\r\n\]*\[\r\n\]" {}
227 if [target_info exists gdb,start_symbol] {
228 set start [target_info gdb,start_symbol];
232 send_gdb "jump *$start\n"
234 while { $start_attempt } {
235 # Cap (re)start attempts at three to ensure that this loop
236 # always eventually fails. Don't worry about trying to be
237 # clever and not send a command when it has failed.
238 if [expr $start_attempt > 3] {
239 perror "Jump to start() failed (retry count exceeded)";
242 set start_attempt [expr $start_attempt + 1];
244 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
247 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
248 perror "Can't find start symbol to run in gdb_run";
251 -re "No symbol \"start\" in current.*$gdb_prompt $" {
252 send_gdb "jump *_start\n";
254 -re "No symbol.*context.*$gdb_prompt $" {
257 -re "Line.* Jump anyway.*y or n. $" {
260 -re "The program is not being run.*$gdb_prompt $" {
261 if { [gdb_reload] != 0 } {
264 send_gdb "jump *$start\n";
267 perror "Jump to start() failed (timeout)";
275 if [target_info exists gdb,do_reload_on_run] {
276 if { [gdb_reload] != 0 } {
280 send_gdb "run $args\n"
281 # This doesn't work quite right yet.
282 # Use -notransfer here so that test cases (like chng-sym.exp)
283 # may test for additional start-up messages.
285 -re "The program .* has been started already.*y or n. $" {
289 -notransfer -re "Starting program: \[^\r\n\]*" {}
290 -notransfer -re "$gdb_prompt $" {
291 # There is no more input expected.
296 # Generic start command. Return 0 if we could start the program, -1
299 # N.B. This function does not wait for gdb to return to the prompt,
300 # that is the caller's responsibility.
302 proc gdb_start_cmd {args} {
303 global gdb_prompt use_gdb_stub
305 if [target_info exists gdb_init_command] {
306 send_gdb "[target_info gdb_init_command]\n";
308 -re "$gdb_prompt $" { }
310 perror "gdb_init_command for target failed";
320 send_gdb "start $args\n"
321 # Use -notransfer here so that test cases (like chng-sym.exp)
322 # may test for additional start-up messages.
324 -re "The program .* has been started already.*y or n. $" {
328 -notransfer -re "Starting program: \[^\r\n\]*" {
335 # Set a breakpoint at FUNCTION. If there is an additional argument it is
336 # a list of options; the supported options are allow-pending, temporary,
337 # message, no-message, and passfail.
338 # The result is 1 for success, 0 for failure.
340 # Note: The handling of message vs no-message is messed up, but it's based
341 # on historical usage. By default this function does not print passes,
343 # no-message: turns off printing of fails (and passes, but they're already off)
344 # message: turns on printing of passes (and fails, but they're already on)
346 proc gdb_breakpoint { function args } {
350 set pending_response n
351 if {[lsearch -exact $args allow-pending] != -1} {
352 set pending_response y
355 set break_command "break"
356 set break_message "Breakpoint"
357 if {[lsearch -exact $args temporary] != -1} {
358 set break_command "tbreak"
359 set break_message "Temporary breakpoint"
364 set no_message_loc [lsearch -exact $args no-message]
365 set message_loc [lsearch -exact $args message]
366 # The last one to appear in args wins.
367 if { $no_message_loc > $message_loc } {
369 } elseif { $message_loc > $no_message_loc } {
373 set test_name "setting breakpoint at $function"
375 send_gdb "$break_command $function\n"
376 # The first two regexps are what we get with -g, the third is without -g.
378 -re "$break_message \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
379 -re "$break_message \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
380 -re "$break_message \[0-9\]* at .*$gdb_prompt $" {}
381 -re "$break_message \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" {
382 if {$pending_response == "n"} {
389 -re "Make breakpoint pending.*y or \\\[n\\\]. $" {
390 send_gdb "$pending_response\n"
393 -re "A problem internal to GDB has been detected" {
395 fail "$test_name (GDB internal error)"
397 gdb_internal_error_resync
400 -re "$gdb_prompt $" {
408 fail "$test_name (eof)"
414 fail "$test_name (timeout)"
425 # Set breakpoint at function and run gdb until it breaks there.
426 # Since this is the only breakpoint that will be set, if it stops
427 # at a breakpoint, we will assume it is the one we want. We can't
428 # just compare to "function" because it might be a fully qualified,
429 # single quoted C++ function specifier.
431 # If there are additional arguments, pass them to gdb_breakpoint.
432 # We recognize no-message/message ourselves.
433 # The default is no-message.
434 # no-message is messed up here, like gdb_breakpoint: to preserve
435 # historical usage fails are always printed by default.
436 # no-message: turns off printing of fails (and passes, but they're already off)
437 # message: turns on printing of passes (and fails, but they're already on)
439 proc runto { function args } {
445 # Default to "no-message".
446 set args "no-message $args"
450 set no_message_loc [lsearch -exact $args no-message]
451 set message_loc [lsearch -exact $args message]
452 # The last one to appear in args wins.
453 if { $no_message_loc > $message_loc } {
455 } elseif { $message_loc > $no_message_loc } {
459 set test_name "running to $function in runto"
461 # We need to use eval here to pass our varargs args to gdb_breakpoint
462 # which is also a varargs function.
463 if ![eval gdb_breakpoint $function $args] {
469 # the "at foo.c:36" output we get with -g.
470 # the "in func" output we get without -g.
472 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
478 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
484 -re "The target does not support running in non-stop mode.\r\n$gdb_prompt $" {
486 unsupported "Non-stop mode not supported"
490 -re ".*A problem internal to GDB has been detected" {
492 fail "$test_name (GDB internal error)"
494 gdb_internal_error_resync
497 -re "$gdb_prompt $" {
505 fail "$test_name (eof)"
511 fail "$test_name (timeout)"
522 # Ask gdb to run until we hit a breakpoint at main.
524 # N.B. This function deletes all existing breakpoints.
525 # If you don't want that, use gdb_start_cmd.
527 proc runto_main { } {
528 return [runto main no-message]
531 ### Continue, and expect to hit a breakpoint.
532 ### Report a pass or fail, depending on whether it seems to have
533 ### worked. Use NAME as part of the test name; each call to
534 ### continue_to_breakpoint should use a NAME which is unique within
536 proc gdb_continue_to_breakpoint {name {location_pattern .*}} {
538 set full_name "continue to breakpoint: $name"
540 send_gdb "continue\n"
542 -re "(?:Breakpoint|Temporary breakpoint) .* (at|in) $location_pattern\r\n$gdb_prompt $" {
545 -re ".*$gdb_prompt $" {
549 fail "$full_name (timeout)"
555 # gdb_internal_error_resync:
557 # Answer the questions GDB asks after it reports an internal error
558 # until we get back to a GDB prompt. Decline to quit the debugging
559 # session, and decline to create a core file. Return non-zero if the
562 # This procedure just answers whatever questions come up until it sees
563 # a GDB prompt; it doesn't require you to have matched the input up to
564 # any specific point. However, it only answers questions it sees in
565 # the output itself, so if you've matched a question, you had better
566 # answer it yourself before calling this.
568 # You can use this function thus:
572 # -re ".*A problem internal to GDB has been detected" {
573 # gdb_internal_error_resync
578 proc gdb_internal_error_resync {} {
581 verbose -log "Resyncing due to internal error."
584 while {$count < 10} {
586 -re "Quit this debugging session\\? \\(y or n\\) $" {
590 -re "Create a core file of GDB\\? \\(y or n\\) $" {
594 -re "$gdb_prompt $" {
595 # We're resynchronized.
599 perror "Could not resync from internal error (timeout)"
604 perror "Could not resync from internal error (resync count exceeded)"
609 # gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS
610 # Send a command to gdb; test the result.
612 # COMMAND is the command to execute, send to GDB with send_gdb. If
613 # this is the null string no command is sent.
614 # MESSAGE is a message to be printed with the built-in failure patterns
615 # if one of them matches. If MESSAGE is empty COMMAND will be used.
616 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
617 # patterns. Pattern elements will be evaluated in the caller's
618 # context; action elements will be executed in the caller's context.
619 # Unlike patterns for gdb_test, these patterns should generally include
620 # the final newline and prompt.
623 # 1 if the test failed, according to a built-in failure pattern
624 # 0 if only user-supplied patterns matched
625 # -1 if there was an internal error.
627 # You can use this function thus:
629 # gdb_test_multiple "print foo" "test foo" {
630 # -re "expected output 1" {
633 # -re "expected output 2" {
638 # The standard patterns, such as "Inferior exited..." and "A problem
639 # ...", all being implicitly appended to that list.
641 proc gdb_test_multiple { command message user_code } {
642 global verbose use_gdb_stub
645 global inferior_exited_re
646 upvar timeout timeout
647 upvar expect_out expect_out
649 if { $message == "" } {
653 if [string match "*\[\r\n\]" $command] {
654 error "Invalid trailing newline in \"$message\" test"
657 if [string match "*\[\r\n\]*" $message] {
658 error "Invalid newline in \"$message\" test"
662 && [regexp -nocase {^\s*(r|run|star|start|at|att|atta|attac|attach)\M} \
664 error "gdbserver does not support $command without extended-remote"
667 # TCL/EXPECT WART ALERT
668 # Expect does something very strange when it receives a single braced
669 # argument. It splits it along word separators and performs substitutions.
670 # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
671 # evaluated as "\[ab\]". But that's not how TCL normally works; inside a
672 # double-quoted list item, "\[ab\]" is just a long way of representing
673 # "[ab]", because the backslashes will be removed by lindex.
675 # Unfortunately, there appears to be no easy way to duplicate the splitting
676 # that expect will do from within TCL. And many places make use of the
677 # "\[0-9\]" construct, so we need to support that; and some places make use
678 # of the "[func]" construct, so we need to support that too. In order to
679 # get this right we have to substitute quoted list elements differently
680 # from braced list elements.
682 # We do this roughly the same way that Expect does it. We have to use two
683 # lists, because if we leave unquoted newlines in the argument to uplevel
684 # they'll be treated as command separators, and if we escape newlines
685 # we mangle newlines inside of command blocks. This assumes that the
686 # input doesn't contain a pattern which contains actual embedded newlines
689 regsub -all {\n} ${user_code} { } subst_code
690 set subst_code [uplevel list $subst_code]
692 set processed_code ""
694 set expecting_action 0
696 foreach item $user_code subst_item $subst_code {
697 if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } {
698 lappend processed_code $item
701 if { $item == "-indices" || $item == "-re" || $item == "-ex" } {
702 lappend processed_code $item
705 if { $item == "-timeout" } {
707 lappend processed_code $item
710 if { $expecting_arg } {
712 lappend processed_code $item
715 if { $expecting_action } {
716 lappend processed_code "uplevel [list $item]"
717 set expecting_action 0
718 # Cosmetic, no effect on the list.
719 append processed_code "\n"
722 set expecting_action 1
723 lappend processed_code $subst_item
724 if {$patterns != ""} {
727 append patterns "\"$subst_item\""
730 # Also purely cosmetic.
731 regsub -all {\r} $patterns {\\r} patterns
732 regsub -all {\n} $patterns {\\n} patterns
735 send_user "Sending \"$command\" to gdb\n"
736 send_user "Looking to match \"$patterns\"\n"
737 send_user "Message is \"$message\"\n"
741 set string "${command}\n";
742 if { $command != "" } {
743 set multi_line_re "\[\r\n\] *>"
744 while { "$string" != "" } {
745 set foo [string first "\n" "$string"];
746 set len [string length "$string"];
747 if { $foo < [expr $len - 1] } {
748 set str [string range "$string" 0 $foo];
749 if { [send_gdb "$str"] != "" } {
750 global suppress_flag;
752 if { ! $suppress_flag } {
753 perror "Couldn't send $command to GDB.";
758 # since we're checking if each line of the multi-line
759 # command are 'accepted' by GDB here,
760 # we need to set -notransfer expect option so that
761 # command output is not lost for pattern matching
764 -notransfer -re "$multi_line_re$" { verbose "partial: match" 3 }
765 timeout { verbose "partial: timeout" 3 }
767 set string [string range "$string" [expr $foo + 1] end];
768 set multi_line_re "$multi_line_re.*\[\r\n\] *>"
773 if { "$string" != "" } {
774 if { [send_gdb "$string"] != "" } {
775 global suppress_flag;
777 if { ! $suppress_flag } {
778 perror "Couldn't send $command to GDB.";
786 if [target_info exists gdb,timeout] {
787 set tmt [target_info gdb,timeout];
789 if [info exists timeout] {
793 if [info exists timeout] {
802 -re ".*A problem internal to GDB has been detected" {
803 fail "$message (GDB internal error)"
804 gdb_internal_error_resync
806 -re "\\*\\*\\* DOSEXIT code.*" {
807 if { $message != "" } {
810 gdb_suppress_entire_file "GDB died";
814 append code $processed_code
816 -re "Ending remote debugging.*$gdb_prompt $" {
817 if ![isnative] then {
818 warning "Can`t communicate to remote target."
824 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
825 perror "Undefined command \"$command\"."
829 -re "Ambiguous command.*$gdb_prompt $" {
830 perror "\"$command\" is not a unique command name."
834 -re "$inferior_exited_re with code \[0-9\]+.*$gdb_prompt $" {
835 if ![string match "" $message] then {
836 set errmsg "$message (the program exited)"
838 set errmsg "$command (the program exited)"
843 -re "$inferior_exited_re normally.*$gdb_prompt $" {
844 if ![string match "" $message] then {
845 set errmsg "$message (the program exited)"
847 set errmsg "$command (the program exited)"
852 -re "The program is not being run.*$gdb_prompt $" {
853 if ![string match "" $message] then {
854 set errmsg "$message (the program is no longer running)"
856 set errmsg "$command (the program is no longer running)"
861 -re "\r\n$gdb_prompt $" {
862 if ![string match "" $message] then {
869 perror "Window too small."
873 -re "\\((y or n|y or \\\[n\\\]|\\\[y\\\] or n)\\) " {
875 gdb_expect -re "$gdb_prompt $"
876 fail "$message (got interactive prompt)"
879 -re "\\\[0\\\] cancel\r\n\\\[1\\\] all.*\r\n> $" {
881 gdb_expect -re "$gdb_prompt $"
882 fail "$message (got breakpoint menu)"
886 perror "Process no longer exists"
887 if { $message != "" } {
893 perror "internal buffer is full."
898 if ![string match "" $message] then {
899 fail "$message (timeout)"
906 set code [catch {gdb_expect $tmt $code} string]
908 global errorInfo errorCode;
909 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
910 } elseif {$code > 1} {
911 return -code $code $string
916 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
917 # Send a command to gdb; test the result.
919 # COMMAND is the command to execute, send to GDB with send_gdb. If
920 # this is the null string no command is sent.
921 # PATTERN is the pattern to match for a PASS, and must NOT include
922 # the \r\n sequence immediately before the gdb prompt.
923 # MESSAGE is an optional message to be printed. If this is
924 # omitted, then the pass/fail messages use the command string as the
925 # message. (If this is the empty string, then sometimes we don't
926 # call pass or fail at all; I don't understand this at all.)
927 # QUESTION is a question GDB may ask in response to COMMAND, like
929 # RESPONSE is the response to send if QUESTION appears.
932 # 1 if the test failed,
933 # 0 if the test passes,
934 # -1 if there was an internal error.
936 proc gdb_test { args } {
940 upvar timeout timeout
942 if [llength $args]>2 then {
943 set message [lindex $args 2]
945 set message [lindex $args 0]
947 set command [lindex $args 0]
948 set pattern [lindex $args 1]
950 if [llength $args]==5 {
951 set question_string [lindex $args 3];
952 set response_string [lindex $args 4];
954 set question_string "^FOOBAR$"
957 return [gdb_test_multiple $command $message {
958 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
959 if ![string match "" $message] then {
963 -re "(${question_string})$" {
964 send_gdb "$response_string\n";
970 # gdb_test_no_output COMMAND MESSAGE
971 # Send a command to GDB and verify that this command generated no output.
973 # See gdb_test_multiple for a description of the COMMAND and MESSAGE
974 # parameters. If MESSAGE is ommitted, then COMMAND will be used as
975 # the message. (If MESSAGE is the empty string, then sometimes we do not
976 # call pass or fail at all; I don't understand this at all.)
978 proc gdb_test_no_output { args } {
980 set command [lindex $args 0]
981 if [llength $args]>1 then {
982 set message [lindex $args 1]
987 set command_regex [string_to_regexp $command]
988 gdb_test_multiple $command $message {
989 -re "^$command_regex\r\n$gdb_prompt $" {
990 if ![string match "" $message] then {
997 # Send a command and then wait for a sequence of outputs.
998 # This is useful when the sequence is long and contains ".*", a single
999 # regexp to match the entire output can get a timeout much easier.
1001 # COMMAND is the command to send.
1002 # TEST_NAME is passed to pass/fail. COMMAND is used if TEST_NAME is "".
1003 # EXPECTED_OUTPUT_LIST is a list of regexps of expected output, which are
1004 # processed in order, and all must be present in the output.
1006 # It is unnecessary to specify ".*" at the beginning or end of any regexp,
1007 # there is an implicit ".*" between each element of EXPECTED_OUTPUT_LIST.
1008 # There is also an implicit ".*" between the last regexp and the gdb prompt.
1010 # Like gdb_test and gdb_test_multiple, the output is expected to end with the
1011 # gdb prompt, which must not be specified in EXPECTED_OUTPUT_LIST.
1014 # 1 if the test failed,
1015 # 0 if the test passes,
1016 # -1 if there was an internal error.
1018 proc gdb_test_sequence { command test_name expected_output_list } {
1020 if { $test_name == "" } {
1021 set test_name $command
1023 lappend expected_output_list ""; # implicit ".*" before gdb prompt
1024 send_gdb "$command\n"
1025 return [gdb_expect_list $test_name "$gdb_prompt $" $expected_output_list]
1029 # Test that a command gives an error. For pass or fail, return
1030 # a 1 to indicate that more tests can proceed. However a timeout
1031 # is a serious error, generates a special fail message, and causes
1032 # a 0 to be returned to indicate that more tests are likely to fail
1035 proc test_print_reject { args } {
1039 if [llength $args]==2 then {
1040 set expectthis [lindex $args 1]
1042 set expectthis "should never match this bogus string"
1044 set sendthis [lindex $args 0]
1045 if $verbose>2 then {
1046 send_user "Sending \"$sendthis\" to gdb\n"
1047 send_user "Looking to match \"$expectthis\"\n"
1049 send_gdb "$sendthis\n"
1050 #FIXME: Should add timeout as parameter.
1052 -re "A .* in expression.*\\.*$gdb_prompt $" {
1053 pass "reject $sendthis"
1056 -re "Invalid syntax in expression.*$gdb_prompt $" {
1057 pass "reject $sendthis"
1060 -re "Junk after end of expression.*$gdb_prompt $" {
1061 pass "reject $sendthis"
1064 -re "Invalid number.*$gdb_prompt $" {
1065 pass "reject $sendthis"
1068 -re "Invalid character constant.*$gdb_prompt $" {
1069 pass "reject $sendthis"
1072 -re "No symbol table is loaded.*$gdb_prompt $" {
1073 pass "reject $sendthis"
1076 -re "No symbol .* in current context.*$gdb_prompt $" {
1077 pass "reject $sendthis"
1080 -re "Unmatched single quote.*$gdb_prompt $" {
1081 pass "reject $sendthis"
1084 -re "A character constant must contain at least one character.*$gdb_prompt $" {
1085 pass "reject $sendthis"
1088 -re "$expectthis.*$gdb_prompt $" {
1089 pass "reject $sendthis"
1092 -re ".*$gdb_prompt $" {
1093 fail "reject $sendthis"
1097 fail "reject $sendthis (eof or timeout)"
1103 # Given an input string, adds backslashes as needed to create a
1104 # regexp that will match the string.
1106 proc string_to_regexp {str} {
1108 regsub -all {[]*+.|()^$\[\\]} $str {\\&} result
1112 # Same as gdb_test, but the second parameter is not a regexp,
1113 # but a string that must match exactly.
1115 proc gdb_test_exact { args } {
1116 upvar timeout timeout
1118 set command [lindex $args 0]
1120 # This applies a special meaning to a null string pattern. Without
1121 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
1122 # messages from commands that should have no output except a new
1123 # prompt. With this, only results of a null string will match a null
1126 set pattern [lindex $args 1]
1127 if [string match $pattern ""] {
1128 set pattern [string_to_regexp [lindex $args 0]]
1130 set pattern [string_to_regexp [lindex $args 1]]
1133 # It is most natural to write the pattern argument with only
1134 # embedded \n's, especially if you are trying to avoid Tcl quoting
1135 # problems. But gdb_expect really wants to see \r\n in patterns. So
1136 # transform the pattern here. First transform \r\n back to \n, in
1137 # case some users of gdb_test_exact already do the right thing.
1138 regsub -all "\r\n" $pattern "\n" pattern
1139 regsub -all "\n" $pattern "\r\n" pattern
1140 if [llength $args]==3 then {
1141 set message [lindex $args 2]
1143 set message $command
1146 return [gdb_test $command $pattern $message]
1149 # Wrapper around gdb_test_multiple that looks for a list of expected
1150 # output elements, but which can appear in any order.
1151 # CMD is the gdb command.
1152 # NAME is the name of the test.
1153 # ELM_FIND_REGEXP specifies how to partition the output into elements to
1155 # ELM_EXTRACT_REGEXP specifies the part of ELM_FIND_REGEXP to compare.
1156 # RESULT_MATCH_LIST is a list of exact matches for each expected element.
1157 # All elements of RESULT_MATCH_LIST must appear for the test to pass.
1159 # A typical use of ELM_FIND_REGEXP/ELM_EXTRACT_REGEXP is to extract one line
1160 # of text per element and then strip trailing \r\n's.
1162 # gdb_test_list_exact "foo" "bar" \
1163 # "\[^\r\n\]+\[\r\n\]+" \
1166 # {expected result 1} \
1167 # {expected result 2} \
1170 proc gdb_test_list_exact { cmd name elm_find_regexp elm_extract_regexp result_match_list } {
1173 set matches [lsort $result_match_list]
1175 gdb_test_multiple $cmd $name {
1176 "$cmd\[\r\n\]" { exp_continue }
1177 -re $elm_find_regexp {
1178 set str $expect_out(0,string)
1179 verbose -log "seen: $str" 3
1180 regexp -- $elm_extract_regexp $str elm_seen
1181 verbose -log "extracted: $elm_seen" 3
1182 lappend seen $elm_seen
1185 -re "$gdb_prompt $" {
1187 foreach got [lsort $seen] have $matches {
1188 if {![string equal $got $have]} {
1193 if {[string length $failed] != 0} {
1194 fail "$name ($failed not found)"
1202 proc gdb_reinitialize_dir { subdir } {
1205 if [is_remote host] {
1210 -re "Reinitialize source path to empty.*y or n. " {
1213 -re "Source directories searched.*$gdb_prompt $" {
1214 send_gdb "dir $subdir\n"
1216 -re "Source directories searched.*$gdb_prompt $" {
1217 verbose "Dir set to $subdir"
1219 -re "$gdb_prompt $" {
1220 perror "Dir \"$subdir\" failed."
1224 -re "$gdb_prompt $" {
1225 perror "Dir \"$subdir\" failed."
1229 -re "$gdb_prompt $" {
1230 perror "Dir \"$subdir\" failed."
1236 # gdb_exit -- exit the GDB, killing the target program if necessary
1238 proc default_gdb_exit {} {
1240 global INTERNAL_GDBFLAGS GDBFLAGS
1242 global gdb_spawn_id;
1244 gdb_stop_suppressing_tests;
1246 if ![info exists gdb_spawn_id] {
1250 verbose "Quitting $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1252 if { [is_remote host] && [board_info host exists fileid] } {
1259 -re "DOSEXIT code" { }
1264 if ![is_remote host] {
1270 # Load a file into the debugger.
1271 # The return value is 0 for success, -1 for failure.
1273 # This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO
1274 # to one of these values:
1276 # debug file was loaded successfully and has debug information
1277 # nodebug file was loaded successfully and has no debug information
1278 # fail file was not loaded
1280 # I tried returning this information as part of the return value,
1281 # but ran into a mess because of the many re-implementations of
1282 # gdb_load in config/*.exp.
1284 # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use
1285 # this if they can get more information set.
1287 proc gdb_file_cmd { arg } {
1291 global last_loaded_file
1293 # Save this for the benefit of gdbserver-support.exp.
1294 set last_loaded_file $arg
1296 # Set whether debug info was found.
1297 # Default to "fail".
1298 global gdb_file_cmd_debug_info
1299 set gdb_file_cmd_debug_info "fail"
1301 if [is_remote host] {
1302 set arg [remote_download host $arg]
1304 perror "download failed"
1309 # The file command used to kill the remote target. For the benefit
1310 # of the testsuite, preserve this behavior.
1313 -re "Kill the program being debugged. .y or n. $" {
1315 verbose "\t\tKilling previous program being debugged"
1318 -re "$gdb_prompt $" {
1323 send_gdb "file $arg\n"
1325 -re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" {
1326 verbose "\t\tLoaded $arg into $GDB with no debugging symbols"
1327 set gdb_file_cmd_debug_info "nodebug"
1330 -re "Reading symbols from.*done.*$gdb_prompt $" {
1331 verbose "\t\tLoaded $arg into $GDB"
1332 set gdb_file_cmd_debug_info "debug"
1335 -re "Load new symbol table from \".*\".*y or n. $" {
1338 -re "Reading symbols from.*done.*$gdb_prompt $" {
1339 verbose "\t\tLoaded $arg with new symbol table into $GDB"
1340 set gdb_file_cmd_debug_info "debug"
1344 perror "Couldn't load $arg, other program already loaded (timeout)."
1348 perror "Couldn't load $arg, other program already loaded (eof)."
1353 -re "No such file or directory.*$gdb_prompt $" {
1354 perror "($arg) No such file or directory"
1357 -re "A problem internal to GDB has been detected" {
1358 fail "($arg) (GDB internal error)"
1359 gdb_internal_error_resync
1362 -re "$gdb_prompt $" {
1363 perror "Couldn't load $arg into $GDB."
1367 perror "Couldn't load $arg into $GDB (timeout)."
1371 # This is an attempt to detect a core dump, but seems not to
1372 # work. Perhaps we need to match .* followed by eof, in which
1373 # gdb_expect does not seem to have a way to do that.
1374 perror "Couldn't load $arg into $GDB (eof)."
1381 # start gdb -- start gdb running, default procedure
1383 # When running over NFS, particularly if running many simultaneous
1384 # tests on different hosts all using the same server, things can
1385 # get really slow. Give gdb at least 3 minutes to start up.
1387 proc default_gdb_start { } {
1388 global verbose use_gdb_stub
1390 global INTERNAL_GDBFLAGS GDBFLAGS
1393 global gdb_spawn_id;
1395 gdb_stop_suppressing_tests;
1397 # Set the default value, it may be overriden later by specific testfile.
1399 # Use `set_board_info use_gdb_stub' for the board file to flag the inferior
1400 # is already started after connecting and run/attach are not supported.
1401 # This is used for the "remote" protocol. After GDB starts you should
1402 # check global $use_gdb_stub instead of the board as the testfile may force
1403 # a specific different target protocol itself.
1404 set use_gdb_stub [target_info exists use_gdb_stub]
1406 verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1408 if [info exists gdb_spawn_id] {
1412 if ![is_remote host] {
1413 if { [which $GDB] == 0 } then {
1414 perror "$GDB does not exist."
1418 set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"];
1419 if { $res < 0 || $res == "" } {
1420 perror "Spawning $GDB failed."
1424 -re "\[\r\n\]$gdb_prompt $" {
1425 verbose "GDB initialized."
1427 -re "$gdb_prompt $" {
1428 perror "GDB never initialized."
1432 perror "(timeout) GDB never initialized after 10 seconds."
1437 set gdb_spawn_id -1;
1438 # force the height to "unlimited", so no pagers get used
1440 send_gdb "set height 0\n"
1442 -re "$gdb_prompt $" {
1443 verbose "Setting height to 0." 2
1446 warning "Couldn't set the height to 0"
1449 # force the width to "unlimited", so no wraparound occurs
1450 send_gdb "set width 0\n"
1452 -re "$gdb_prompt $" {
1453 verbose "Setting width to 0." 2
1456 warning "Couldn't set the width to 0."
1462 # Examine the output of compilation to determine whether compilation
1463 # failed or not. If it failed determine whether it is due to missing
1464 # compiler or due to compiler error. Report pass, fail or unsupported
1467 proc gdb_compile_test {src output} {
1468 if { $output == "" } {
1469 pass "compilation [file tail $src]"
1470 } elseif { [regexp {^[a-zA-Z_0-9]+: Can't find [^ ]+\.$} $output] } {
1471 unsupported "compilation [file tail $src]"
1472 } elseif { [regexp {.*: command not found[\r|\n]*$} $output] } {
1473 unsupported "compilation [file tail $src]"
1474 } elseif { [regexp {.*: [^\r\n]*compiler not installed[^\r\n]*[\r|\n]*$} $output] } {
1475 unsupported "compilation [file tail $src]"
1477 verbose -log "compilation failed: $output" 2
1478 fail "compilation [file tail $src]"
1482 # Return a 1 for configurations for which we don't even want to try to
1485 proc skip_cplus_tests {} {
1486 if { [istarget "h8300-*-*"] } {
1490 # The C++ IO streams are too large for HC11/HC12 and are thus not
1491 # available. The gdb C++ tests use them and don't compile.
1492 if { [istarget "m6811-*-*"] } {
1495 if { [istarget "m6812-*-*"] } {
1501 # Return a 1 for configurations for which don't have both C++ and the STL.
1503 proc skip_stl_tests {} {
1504 # Symbian supports the C++ language, but the STL is missing
1505 # (both headers and libraries).
1506 if { [istarget "arm*-*-symbianelf*"] } {
1510 return [skip_cplus_tests]
1513 # Return a 1 if I don't even want to try to test FORTRAN.
1515 proc skip_fortran_tests {} {
1519 # Return a 1 if I don't even want to try to test ada.
1521 proc skip_ada_tests {} {
1525 # Return a 1 if I don't even want to try to test GO.
1527 proc skip_go_tests {} {
1531 # Return a 1 if I don't even want to try to test java.
1533 proc skip_java_tests {} {
1537 # Return a 1 for configurations that do not support Python scripting.
1539 proc skip_python_tests {} {
1541 gdb_test_multiple "python print 'test'" "verify python support" {
1542 -re "not supported.*$gdb_prompt $" {
1543 unsupported "Python support is disabled."
1546 -re "$gdb_prompt $" {}
1552 # Return a 1 if we should skip shared library tests.
1554 proc skip_shlib_tests {} {
1555 # Run the shared library tests on native systems.
1560 # An abbreviated list of remote targets where we should be able to
1561 # run shared library tests.
1562 if {([istarget *-*-linux*]
1563 || [istarget *-*-*bsd*]
1564 || [istarget *-*-solaris2*]
1565 || [istarget arm*-*-symbianelf*]
1566 || [istarget *-*-mingw*]
1567 || [istarget *-*-cygwin*]
1568 || [istarget *-*-pe*])} {
1575 # Test files shall make sure all the test result lines in gdb.sum are
1576 # unique in a test run, so that comparing the gdb.sum files of two
1577 # test runs gives correct results. Test files that exercise
1578 # variations of the same tests more than once, shall prefix the
1579 # different test invocations with different identifying strings in
1580 # order to make them unique.
1582 # About test prefixes:
1584 # $pf_prefix is the string that dejagnu prints after the result (FAIL,
1585 # PASS, etc.), and before the test message/name in gdb.sum. E.g., the
1586 # underlined substring in
1588 # PASS: gdb.base/mytest.exp: some test
1589 # ^^^^^^^^^^^^^^^^^^^^
1593 # The easiest way to adjust the test prefix is to append a test
1594 # variation prefix to the $pf_prefix, using the with_test_prefix
1597 # proc do_tests {} {
1598 # gdb_test ... ... "test foo"
1599 # gdb_test ... ... "test bar"
1601 # with_test_prefix "subvariation a" {
1602 # gdb_test ... ... "test x"
1605 # with_test_prefix "subvariation b" {
1606 # gdb_test ... ... "test x"
1610 # with_test_prefix "variation1" {
1611 # ...do setup for variation 1...
1615 # with_test_prefix "variation2" {
1616 # ...do setup for variation 2...
1622 # PASS: gdb.base/mytest.exp: variation1: test foo
1623 # PASS: gdb.base/mytest.exp: variation1: test bar
1624 # PASS: gdb.base/mytest.exp: variation1: subvariation a: test x
1625 # PASS: gdb.base/mytest.exp: variation1: subvariation b: test x
1626 # PASS: gdb.base/mytest.exp: variation2: test foo
1627 # PASS: gdb.base/mytest.exp: variation2: test bar
1628 # PASS: gdb.base/mytest.exp: variation2: subvariation a: test x
1629 # PASS: gdb.base/mytest.exp: variation2: subvariation b: test x
1631 # If for some reason more flexibility is necessary, one can also
1632 # manipulate the pf_prefix global directly, treating it as a string.
1636 # set saved_pf_prefix
1637 # append pf_prefix "${foo}: bar"
1638 # ... actual tests ...
1639 # set pf_prefix $saved_pf_prefix
1642 # Run BODY in the context of the caller, with the current test prefix
1643 # (pf_prefix) appended with one space, then PREFIX, and then a colon.
1644 # Returns the result of BODY.
1646 proc with_test_prefix { prefix body } {
1649 set saved $pf_prefix
1650 append pf_prefix " " $prefix ":"
1651 set code [catch {uplevel 1 $body} result]
1652 set pf_prefix $saved
1655 global errorInfo errorCode
1656 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
1658 return -code $code $result
1662 # Return 1 if _Complex types are supported, otherwise, return 0.
1664 proc support_complex_tests {} {
1665 global support_complex_tests_saved
1667 # Use the cached value, if it exists.
1668 if [info exists support_complex_tests_saved] {
1669 verbose "returning saved $support_complex_tests_saved" 2
1670 return $support_complex_tests_saved
1673 # Set up, compile, and execute a test program containing _Complex types.
1674 # Include the current process ID in the file names to prevent conflicts
1675 # with invocations for multiple testsuites.
1676 set src complex[pid].c
1677 set exe complex[pid].x
1679 set f [open $src "w"]
1680 puts $f "int main() {"
1681 puts $f "_Complex float cf;"
1682 puts $f "_Complex double cd;"
1683 puts $f "_Complex long double cld;"
1684 puts $f " return 0; }"
1687 verbose "compiling testfile $src" 2
1688 set compile_flags {debug nowarnings quiet}
1689 set lines [gdb_compile $src $exe executable $compile_flags]
1693 if ![string match "" $lines] then {
1694 verbose "testfile compilation failed, returning 0" 2
1695 set support_complex_tests_saved 0
1697 set support_complex_tests_saved 1
1700 return $support_complex_tests_saved
1703 # Return 1 if target hardware or OS supports single stepping to signal
1704 # handler, otherwise, return 0.
1706 proc can_single_step_to_signal_handler {} {
1708 # Targets don't have hardware single step. On these targets, when
1709 # a signal is delivered during software single step, gdb is unable
1710 # to determine the next instruction addresses, because start of signal
1711 # handler is one of them.
1712 if { [istarget "arm*-*-*"] || [istarget "mips*-*-*"]
1713 || [istarget "tic6x-*-*"] || [istarget "sparc*-*-linux*"] } {
1720 # Return 1 if target supports process record, otherwise return 0.
1722 proc supports_process_record {} {
1724 if [target_info exists gdb,use_precord] {
1725 return [target_info gdb,use_precord]
1728 if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"] } {
1735 # Return 1 if target supports reverse debugging, otherwise return 0.
1737 proc supports_reverse {} {
1739 if [target_info exists gdb,can_reverse] {
1740 return [target_info gdb,can_reverse]
1743 if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"] } {
1750 # Return 1 if target is ILP32.
1751 # This cannot be decided simply from looking at the target string,
1752 # as it might depend on externally passed compiler options like -m64.
1753 proc is_ilp32_target {} {
1754 global is_ilp32_target_saved
1756 # Use the cached value, if it exists. Cache value per "board" to handle
1757 # runs with multiple options (e.g. unix/{-m32,-64}) correctly.
1758 set me "is_ilp32_target"
1759 set board [target_info name]
1760 if [info exists is_ilp32_target_saved($board)] {
1761 verbose "$me: returning saved $is_ilp32_target_saved($board)" 2
1762 return $is_ilp32_target_saved($board)
1766 set src ilp32[pid].c
1767 set obj ilp32[pid].o
1769 set f [open $src "w"]
1770 puts $f "int dummy\[sizeof (int) == 4"
1771 puts $f " && sizeof (void *) == 4"
1772 puts $f " && sizeof (long) == 4 ? 1 : -1\];"
1775 verbose "$me: compiling testfile $src" 2
1776 set lines [gdb_compile $src $obj object {quiet}]
1780 if ![string match "" $lines] then {
1781 verbose "$me: testfile compilation failed, returning 0" 2
1782 return [set is_ilp32_target_saved($board) 0]
1785 verbose "$me: returning 1" 2
1786 return [set is_ilp32_target_saved($board) 1]
1789 # Return 1 if target is LP64.
1790 # This cannot be decided simply from looking at the target string,
1791 # as it might depend on externally passed compiler options like -m64.
1792 proc is_lp64_target {} {
1793 global is_lp64_target_saved
1795 # Use the cached value, if it exists. Cache value per "board" to handle
1796 # runs with multiple options (e.g. unix/{-m32,-64}) correctly.
1797 set me "is_lp64_target"
1798 set board [target_info name]
1799 if [info exists is_lp64_target_saved($board)] {
1800 verbose "$me: returning saved $is_lp64_target_saved($board)" 2
1801 return $is_lp64_target_saved($board)
1807 set f [open $src "w"]
1808 puts $f "int dummy\[sizeof (int) == 4"
1809 puts $f " && sizeof (void *) == 8"
1810 puts $f " && sizeof (long) == 8 ? 1 : -1\];"
1813 verbose "$me: compiling testfile $src" 2
1814 set lines [gdb_compile $src $obj object {quiet}]
1818 if ![string match "" $lines] then {
1819 verbose "$me: testfile compilation failed, returning 0" 2
1820 return [set is_lp64_target_saved($board) 0]
1823 verbose "$me: returning 1" 2
1824 return [set is_lp64_target_saved($board) 1]
1827 # Return 1 if target has x86_64 registers - either amd64 or x32.
1828 # x32 target identifies as x86_64-*-linux*, therefore it cannot be determined
1829 # just from the target string.
1830 proc is_amd64_regs_target {} {
1831 global is_amd64_regs_target_saved
1833 if {![istarget "x86_64-*-*"] && ![istarget "i?86-*"]} {
1837 # Use the cached value, if it exists. Cache value per "board" to handle
1838 # runs with multiple options (e.g. unix/{-m32,-64}) correctly.
1839 set me "is_amd64_regs_target"
1840 set board [target_info name]
1841 if [info exists is_amd64_regs_target_saved($board)] {
1842 verbose "$me: returning saved $is_amd64_regs_target_saved($board)" 2
1843 return $is_amd64_regs_target_saved($board)
1846 set src reg64[pid].s
1847 set obj reg64[pid].o
1849 set f [open $src "w"]
1851 {rax rbx rcx rdx rsi rdi rbp rsp r8 r9 r10 r11 r12 r13 r14 r15} {
1852 puts $f "\tincq %$reg"
1856 verbose "$me: compiling testfile $src" 2
1857 set lines [gdb_compile $src $obj object {quiet}]
1861 if ![string match "" $lines] then {
1862 verbose "$me: testfile compilation failed, returning 0" 2
1863 return [set is_amd64_regs_target_saved($board) 0]
1866 verbose "$me: returning 1" 2
1867 return [set is_amd64_regs_target_saved($board) 1]
1870 # Return 1 if this target is an x86 or x86-64 with -m32.
1871 proc is_x86_like_target {} {
1872 if {![istarget "x86_64-*-*"] && ![istarget i?86-*]} {
1875 return [expr [is_ilp32_target] && ![is_amd64_regs_target]]
1878 # Return 1 if displaced stepping is supported on target, otherwise, return 0.
1879 proc support_displaced_stepping {} {
1881 if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"]
1882 || [istarget "arm*-*-linux*"] || [istarget "powerpc-*-linux*"]
1883 || [istarget "powerpc64-*-linux*"] || [istarget "s390*-*-*"] } {
1890 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
1891 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
1893 proc skip_altivec_tests {} {
1894 global skip_vmx_tests_saved
1895 global srcdir subdir gdb_prompt inferior_exited_re
1897 # Use the cached value, if it exists.
1898 set me "skip_altivec_tests"
1899 if [info exists skip_vmx_tests_saved] {
1900 verbose "$me: returning saved $skip_vmx_tests_saved" 2
1901 return $skip_vmx_tests_saved
1904 # Some simulators are known to not support VMX instructions.
1905 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1906 verbose "$me: target known to not support VMX, returning 1" 2
1907 return [set skip_vmx_tests_saved 1]
1910 # Make sure we have a compiler that understands altivec.
1911 set compile_flags {debug nowarnings}
1912 if [get_compiler_info] {
1913 warning "Could not get compiler info"
1916 if [test_compiler_info gcc*] {
1917 set compile_flags "$compile_flags additional_flags=-maltivec"
1918 } elseif [test_compiler_info xlc*] {
1919 set compile_flags "$compile_flags additional_flags=-qaltivec"
1921 verbose "Could not compile with altivec support, returning 1" 2
1925 # Set up, compile, and execute a test program containing VMX instructions.
1926 # Include the current process ID in the file names to prevent conflicts
1927 # with invocations for multiple testsuites.
1931 set f [open $src "w"]
1932 puts $f "int main() {"
1933 puts $f "#ifdef __MACH__"
1934 puts $f " asm volatile (\"vor v0,v0,v0\");"
1936 puts $f " asm volatile (\"vor 0,0,0\");"
1938 puts $f " return 0; }"
1941 verbose "$me: compiling testfile $src" 2
1942 set lines [gdb_compile $src $exe executable $compile_flags]
1945 if ![string match "" $lines] then {
1946 verbose "$me: testfile compilation failed, returning 1" 2
1947 return [set skip_vmx_tests_saved 1]
1950 # No error message, compilation succeeded so now run it via gdb.
1954 gdb_reinitialize_dir $srcdir/$subdir
1958 -re ".*Illegal instruction.*${gdb_prompt} $" {
1959 verbose -log "\n$me altivec hardware not detected"
1960 set skip_vmx_tests_saved 1
1962 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
1963 verbose -log "\n$me: altivec hardware detected"
1964 set skip_vmx_tests_saved 0
1967 warning "\n$me: default case taken"
1968 set skip_vmx_tests_saved 1
1972 remote_file build delete $exe
1974 verbose "$me: returning $skip_vmx_tests_saved" 2
1975 return $skip_vmx_tests_saved
1978 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
1979 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
1981 proc skip_vsx_tests {} {
1982 global skip_vsx_tests_saved
1983 global srcdir subdir gdb_prompt inferior_exited_re
1985 # Use the cached value, if it exists.
1986 set me "skip_vsx_tests"
1987 if [info exists skip_vsx_tests_saved] {
1988 verbose "$me: returning saved $skip_vsx_tests_saved" 2
1989 return $skip_vsx_tests_saved
1992 # Some simulators are known to not support Altivec instructions, so
1993 # they won't support VSX instructions as well.
1994 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1995 verbose "$me: target known to not support VSX, returning 1" 2
1996 return [set skip_vsx_tests_saved 1]
1999 # Make sure we have a compiler that understands altivec.
2000 set compile_flags {debug nowarnings quiet}
2001 if [get_compiler_info] {
2002 warning "Could not get compiler info"
2005 if [test_compiler_info gcc*] {
2006 set compile_flags "$compile_flags additional_flags=-mvsx"
2007 } elseif [test_compiler_info xlc*] {
2008 set compile_flags "$compile_flags additional_flags=-qasm=gcc"
2010 verbose "Could not compile with vsx support, returning 1" 2
2017 set f [open $src "w"]
2018 puts $f "int main() {"
2019 puts $f " double a\[2\] = { 1.0, 2.0 };"
2020 puts $f "#ifdef __MACH__"
2021 puts $f " asm volatile (\"lxvd2x v0,v0,%\[addr\]\" : : \[addr\] \"r\" (a));"
2023 puts $f " asm volatile (\"lxvd2x 0,0,%\[addr\]\" : : \[addr\] \"r\" (a));"
2025 puts $f " return 0; }"
2028 verbose "$me: compiling testfile $src" 2
2029 set lines [gdb_compile $src $exe executable $compile_flags]
2032 if ![string match "" $lines] then {
2033 verbose "$me: testfile compilation failed, returning 1" 2
2034 return [set skip_vsx_tests_saved 1]
2037 # No error message, compilation succeeded so now run it via gdb.
2041 gdb_reinitialize_dir $srcdir/$subdir
2045 -re ".*Illegal instruction.*${gdb_prompt} $" {
2046 verbose -log "\n$me VSX hardware not detected"
2047 set skip_vsx_tests_saved 1
2049 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
2050 verbose -log "\n$me: VSX hardware detected"
2051 set skip_vsx_tests_saved 0
2054 warning "\n$me: default case taken"
2055 set skip_vsx_tests_saved 1
2059 remote_file build delete $exe
2061 verbose "$me: returning $skip_vsx_tests_saved" 2
2062 return $skip_vsx_tests_saved
2065 # Skip all the tests in the file if you are not on an hppa running
2068 proc skip_hp_tests {} {
2069 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
2070 verbose "Skip hp tests is $skip_hp"
2074 # Return whether we should skip tests for showing inlined functions in
2075 # backtraces. Requires get_compiler_info and get_debug_format.
2077 proc skip_inline_frame_tests {} {
2078 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
2079 if { ! [test_debug_format "DWARF 2"] } {
2083 # GCC before 4.1 does not emit DW_AT_call_file / DW_AT_call_line.
2084 if { ([test_compiler_info "gcc-2-*"]
2085 || [test_compiler_info "gcc-3-*"]
2086 || [test_compiler_info "gcc-4-0-*"]) } {
2093 # Return whether we should skip tests for showing variables from
2094 # inlined functions. Requires get_compiler_info and get_debug_format.
2096 proc skip_inline_var_tests {} {
2097 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
2098 if { ! [test_debug_format "DWARF 2"] } {
2105 # Return a 1 if we should skip tests that require hardware breakpoints
2107 proc skip_hw_breakpoint_tests {} {
2108 # Skip tests if requested by the board (note that no_hardware_watchpoints
2109 # disables both watchpoints and breakpoints)
2110 if { [target_info exists gdb,no_hardware_watchpoints]} {
2114 # These targets support hardware breakpoints natively
2115 if { [istarget "i?86-*-*"]
2116 || [istarget "x86_64-*-*"]
2117 || [istarget "ia64-*-*"]
2118 || [istarget "arm*-*-*"]} {
2125 # Return a 1 if we should skip tests that require hardware watchpoints
2127 proc skip_hw_watchpoint_tests {} {
2128 # Skip tests if requested by the board
2129 if { [target_info exists gdb,no_hardware_watchpoints]} {
2133 # These targets support hardware watchpoints natively
2134 if { [istarget "i?86-*-*"]
2135 || [istarget "x86_64-*-*"]
2136 || [istarget "ia64-*-*"]
2137 || [istarget "arm*-*-*"]
2138 || [istarget "powerpc*-*-linux*"]
2139 || [istarget "s390*-*-*"] } {
2146 # Return a 1 if we should skip tests that require *multiple* hardware
2147 # watchpoints to be active at the same time
2149 proc skip_hw_watchpoint_multi_tests {} {
2150 if { [skip_hw_watchpoint_tests] } {
2154 # These targets support just a single hardware watchpoint
2155 if { [istarget "arm*-*-*"]
2156 || [istarget "powerpc*-*-linux*"] } {
2163 # Return a 1 if we should skip tests that require read/access watchpoints
2165 proc skip_hw_watchpoint_access_tests {} {
2166 if { [skip_hw_watchpoint_tests] } {
2170 # These targets support just write watchpoints
2171 if { [istarget "s390*-*-*"] } {
2178 # Return 1 if we should skip tests that require the runtime unwinder
2179 # hook. This must be invoked while gdb is running, after shared
2180 # libraries have been loaded. This is needed because otherwise a
2181 # shared libgcc won't be visible.
2183 proc skip_unwinder_tests {} {
2187 gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook" {
2188 -re "= .*no debug info.*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
2190 -re "= .*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
2193 -re "No symbol .* in current context.\r\n$gdb_prompt $" {
2197 gdb_test_multiple "info probe" "check for stap probe in unwinder" {
2198 -re ".*libgcc.*unwind.*\r\n$gdb_prompt $" {
2201 -re "\r\n$gdb_prompt $" {
2208 set compiler_info "unknown"
2210 set hp_cc_compiler 0
2211 set hp_aCC_compiler 0
2213 # Figure out what compiler I am using.
2215 # ARG can be empty or "C++". If empty, "C" is assumed.
2217 # There are several ways to do this, with various problems.
2219 # [ gdb_compile -E $ifile -o $binfile.ci ]
2220 # source $binfile.ci
2222 # Single Unix Spec v3 says that "-E -o ..." together are not
2223 # specified. And in fact, the native compiler on hp-ux 11 (among
2224 # others) does not work with "-E -o ...". Most targets used to do
2225 # this, and it mostly worked, because it works with gcc.
2227 # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ]
2228 # source $binfile.ci
2230 # This avoids the problem with -E and -o together. This almost works
2231 # if the build machine is the same as the host machine, which is
2232 # usually true of the targets which are not gcc. But this code does
2233 # not figure which compiler to call, and it always ends up using the C
2234 # compiler. Not good for setting hp_aCC_compiler. Targets
2235 # hppa*-*-hpux* and mips*-*-irix* used to do this.
2237 # [ gdb_compile -E $ifile > $binfile.ci ]
2238 # source $binfile.ci
2240 # dejagnu target_compile says that it supports output redirection,
2241 # but the code is completely different from the normal path and I
2242 # don't want to sweep the mines from that path. So I didn't even try
2245 # set cppout [ gdb_compile $ifile "" preprocess $args quiet ]
2248 # I actually do this for all targets now. gdb_compile runs the right
2249 # compiler, and TCL captures the output, and I eval the output.
2251 # Unfortunately, expect logs the output of the command as it goes by,
2252 # and dejagnu helpfully prints a second copy of it right afterwards.
2253 # So I turn off expect logging for a moment.
2255 # [ gdb_compile $ifile $ciexe_file executable $args ]
2256 # [ remote_exec $ciexe_file ]
2257 # [ source $ci_file.out ]
2259 # I could give up on -E and just do this.
2260 # I didn't get desperate enough to try this.
2262 # -- chastain 2004-01-06
2264 proc get_compiler_info {{arg ""}} {
2265 # For compiler.c and compiler.cc
2268 # I am going to play with the log to keep noise out.
2272 # These come from compiler.c or compiler.cc
2273 global compiler_info
2275 # Legacy global data symbols.
2277 global hp_cc_compiler
2278 global hp_aCC_compiler
2280 # Choose which file to preprocess.
2281 set ifile "${srcdir}/lib/compiler.c"
2282 if { $arg == "c++" } {
2283 set ifile "${srcdir}/lib/compiler.cc"
2286 # Run $ifile through the right preprocessor.
2287 # Toggle gdb.log to keep the compiler output out of the log.
2289 if [is_remote host] {
2290 # We have to use -E and -o together, despite the comments
2291 # above, because of how DejaGnu handles remote host testing.
2292 set ppout "$outdir/compiler.i"
2293 gdb_compile "${ifile}" "$ppout" preprocess [list "$arg" quiet]
2294 set file [open $ppout r]
2295 set cppout [read $file]
2298 set cppout [ gdb_compile "${ifile}" "" preprocess [list "$arg" quiet] ]
2300 log_file -a "$outdir/$tool.log"
2304 foreach cppline [ split "$cppout" "\n" ] {
2305 if { [ regexp "^#" "$cppline" ] } {
2307 } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } {
2309 } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } {
2311 verbose "get_compiler_info: $cppline" 2
2315 verbose -log "get_compiler_info: $cppline"
2320 # Reset to unknown compiler if any diagnostics happened.
2322 set compiler_info "unknown"
2325 # Set the legacy symbols.
2327 set hp_cc_compiler 0
2328 set hp_aCC_compiler 0
2329 if { [regexp "^gcc-1-" "$compiler_info" ] } { set gcc_compiled 1 }
2330 if { [regexp "^gcc-2-" "$compiler_info" ] } { set gcc_compiled 2 }
2331 if { [regexp "^gcc-3-" "$compiler_info" ] } { set gcc_compiled 3 }
2332 if { [regexp "^gcc-4-" "$compiler_info" ] } { set gcc_compiled 4 }
2333 if { [regexp "^gcc-5-" "$compiler_info" ] } { set gcc_compiled 5 }
2334 if { [regexp "^hpcc-" "$compiler_info" ] } { set hp_cc_compiler 1 }
2335 if { [regexp "^hpacc-" "$compiler_info" ] } { set hp_aCC_compiler 1 }
2337 # Log what happened.
2338 verbose -log "get_compiler_info: $compiler_info"
2340 # Most compilers will evaluate comparisons and other boolean
2341 # operations to 0 or 1.
2342 uplevel \#0 { set true 1 }
2343 uplevel \#0 { set false 0 }
2345 # Use of aCC results in boolean results being displayed as
2347 if { $hp_aCC_compiler } {
2348 uplevel \#0 { set true true }
2349 uplevel \#0 { set false false }
2355 proc test_compiler_info { {compiler ""} } {
2356 global compiler_info
2358 # if no arg, return the compiler_info string
2360 if [string match "" $compiler] {
2361 if [info exists compiler_info] {
2362 return $compiler_info
2364 perror "No compiler info found."
2368 return [string match $compiler $compiler_info]
2371 proc current_target_name { } {
2373 if [info exists target_info(target,name)] {
2374 set answer $target_info(target,name)
2381 set gdb_wrapper_initialized 0
2382 set gdb_wrapper_target ""
2384 proc gdb_wrapper_init { args } {
2385 global gdb_wrapper_initialized;
2386 global gdb_wrapper_file;
2387 global gdb_wrapper_flags;
2388 global gdb_wrapper_target
2390 if { $gdb_wrapper_initialized == 1 } { return; }
2392 if {[target_info exists needs_status_wrapper] && \
2393 [target_info needs_status_wrapper] != "0"} {
2394 set result [build_wrapper "testglue.o"];
2395 if { $result != "" } {
2396 set gdb_wrapper_file [lindex $result 0];
2397 set gdb_wrapper_flags [lindex $result 1];
2399 warning "Status wrapper failed to build."
2402 set gdb_wrapper_initialized 1
2403 set gdb_wrapper_target [current_target_name]
2406 # Some targets need to always link a special object in. Save its path here.
2407 global gdb_saved_set_unbuffered_mode_obj
2408 set gdb_saved_set_unbuffered_mode_obj ""
2410 proc gdb_compile {source dest type options} {
2411 global GDB_TESTCASE_OPTIONS;
2412 global gdb_wrapper_file;
2413 global gdb_wrapper_flags;
2414 global gdb_wrapper_initialized;
2417 global gdb_saved_set_unbuffered_mode_obj
2419 set outdir [file dirname $dest]
2421 # Add platform-specific options if a shared library was specified using
2422 # "shlib=librarypath" in OPTIONS.
2426 foreach opt $options {
2427 if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] {
2428 if [test_compiler_info "xlc-*"] {
2429 # IBM xlc compiler doesn't accept shared library named other
2430 # than .so: use "-Wl," to bypass this
2431 lappend source "-Wl,$shlib_name"
2432 } elseif { ([istarget "*-*-mingw*"]
2433 || [istarget *-*-cygwin*]
2434 || [istarget *-*-pe*])} {
2435 lappend source "${shlib_name}.a"
2437 lappend source $shlib_name
2439 if { $shlib_found == 0 } {
2441 if { ([istarget "*-*-mingw*"]
2442 || [istarget *-*-cygwin*]) } {
2443 lappend new_options "additional_flags=-Wl,--enable-auto-import"
2446 } elseif { $opt == "shlib_load" } {
2449 lappend new_options $opt
2453 # We typically link to shared libraries using an absolute path, and
2454 # that's how they are found at runtime. If we are going to
2455 # dynamically load one by basename, we must specify rpath. If we
2456 # are using a remote host, DejaGNU will link to the shared library
2457 # using a relative path, so again we must specify an rpath.
2458 if { $shlib_load || ($shlib_found && [is_remote target]) } {
2459 if { ([istarget "*-*-mingw*"]
2460 || [istarget *-*-cygwin*]
2461 || [istarget *-*-pe*]
2462 || [istarget hppa*-*-hpux*])} {
2463 # Do not need anything.
2464 } elseif { [istarget *-*-freebsd*] || [istarget *-*-openbsd*] } {
2465 lappend new_options "ldflags=-Wl,-rpath,${outdir}"
2466 } elseif { [istarget arm*-*-symbianelf*] } {
2467 if { $shlib_load } {
2468 lappend new_options "libs=-ldl"
2471 if { $shlib_load } {
2472 lappend new_options "libs=-ldl"
2474 lappend new_options "ldflags=-Wl,-rpath,\\\$ORIGIN"
2477 set options $new_options
2479 if [target_info exists is_vxworks] {
2480 set options2 { "additional_flags=-Dvxworks" }
2481 set options [concat $options2 $options]
2483 if [info exists GDB_TESTCASE_OPTIONS] {
2484 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
2486 verbose "options are $options"
2487 verbose "source is $source $dest $type $options"
2489 if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init }
2491 if {[target_info exists needs_status_wrapper] && \
2492 [target_info needs_status_wrapper] != "0" && \
2493 [info exists gdb_wrapper_file]} {
2494 lappend options "libs=${gdb_wrapper_file}"
2495 lappend options "ldflags=${gdb_wrapper_flags}"
2498 # Replace the "nowarnings" option with the appropriate additional_flags
2499 # to disable compiler warnings.
2500 set nowarnings [lsearch -exact $options nowarnings]
2501 if {$nowarnings != -1} {
2502 if [target_info exists gdb,nowarnings_flag] {
2503 set flag "additional_flags=[target_info gdb,nowarnings_flag]"
2505 set flag "additional_flags=-w"
2507 set options [lreplace $options $nowarnings $nowarnings $flag]
2510 if { $type == "executable" } {
2511 if { ([istarget "*-*-mingw*"]
2512 || [istarget "*-*-*djgpp"]
2513 || [istarget "*-*-cygwin*"])} {
2514 # Force output to unbuffered mode, by linking in an object file
2515 # with a global contructor that calls setvbuf.
2517 # Compile the special object seperatelly for two reasons:
2518 # 1) Insulate it from $options.
2519 # 2) Avoid compiling it for every gdb_compile invocation,
2520 # which is time consuming, especially if we're remote
2523 if { $gdb_saved_set_unbuffered_mode_obj == "" } {
2524 verbose "compiling gdb_saved_set_unbuffered_obj"
2525 set unbuf_src ${srcdir}/lib/set_unbuffered_mode.c
2526 set unbuf_obj ${objdir}/set_unbuffered_mode.o
2528 set result [gdb_compile "${unbuf_src}" "${unbuf_obj}" object {nowarnings}]
2529 if { $result != "" } {
2533 set gdb_saved_set_unbuffered_mode_obj ${objdir}/set_unbuffered_mode_saved.o
2534 # Link a copy of the output object, because the
2535 # original may be automatically deleted.
2536 remote_exec host "cp -f $unbuf_obj $gdb_saved_set_unbuffered_mode_obj"
2538 verbose "gdb_saved_set_unbuffered_obj already compiled"
2541 # Rely on the internal knowledge that the global ctors are ran in
2542 # reverse link order. In that case, we can use ldflags to
2543 # avoid copying the object file to the host multiple
2545 # This object can only be added if standard libraries are
2546 # used. Thus, we need to disable it if -nostdlib option is used
2547 if {[lsearch -regexp $options "-nostdlib"] < 0 } {
2548 lappend options "ldflags=$gdb_saved_set_unbuffered_mode_obj"
2553 set result [target_compile $source $dest $type $options];
2555 # Prune uninteresting compiler (and linker) output.
2556 regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result
2558 regsub "\[\r\n\]*$" "$result" "" result;
2559 regsub "^\[\r\n\]*" "$result" "" result;
2561 if {[lsearch $options quiet] < 0} {
2562 # We shall update this on a per language basis, to avoid
2563 # changing the entire testsuite in one go.
2564 if {[lsearch $options f77] >= 0} {
2565 gdb_compile_test $source $result
2566 } elseif { $result != "" } {
2567 clone_output "gdb compile failed, $result"
2574 # This is just like gdb_compile, above, except that it tries compiling
2575 # against several different thread libraries, to see which one this
2577 proc gdb_compile_pthreads {source dest type options} {
2579 set why_msg "unrecognized error"
2580 foreach lib {-lpthreads -lpthread -lthread ""} {
2581 # This kind of wipes out whatever libs the caller may have
2582 # set. Or maybe theirs will override ours. How infelicitous.
2583 set options_with_lib [concat $options [list libs=$lib quiet]]
2584 set ccout [gdb_compile $source $dest $type $options_with_lib]
2585 switch -regexp -- $ccout {
2586 ".*no posix threads support.*" {
2587 set why_msg "missing threads include file"
2590 ".*cannot open -lpthread.*" {
2591 set why_msg "missing runtime threads library"
2593 ".*Can't find library for -lpthread.*" {
2594 set why_msg "missing runtime threads library"
2597 pass "successfully compiled posix threads test case"
2603 if {!$built_binfile} {
2604 unsupported "Couldn't compile $source: ${why_msg}"
2609 # Build a shared library from SOURCES. You must use get_compiler_info
2612 proc gdb_compile_shlib {sources dest options} {
2613 set obj_options $options
2615 switch -glob [test_compiler_info] {
2617 lappend obj_options "additional_flags=-qpic"
2620 if { !([istarget "powerpc*-*-aix*"]
2621 || [istarget "rs6000*-*-aix*"]
2622 || [istarget "*-*-cygwin*"]
2623 || [istarget "*-*-mingw*"]
2624 || [istarget "*-*-pe*"]) } {
2625 lappend obj_options "additional_flags=-fpic"
2629 switch -glob [istarget] {
2631 lappend obj_options "additional_flags=+z"
2634 # Disable SGI compiler's implicit -Dsgi
2635 lappend obj_options "additional_flags=-Usgi"
2638 # don't know what the compiler is...
2644 set outdir [file dirname $dest]
2646 foreach source $sources {
2647 set sourcebase [file tail $source]
2648 if {[gdb_compile $source "${outdir}/${sourcebase}.o" object $obj_options] != ""} {
2651 lappend objects ${outdir}/${sourcebase}.o
2654 if [istarget "hppa*-*-hpux*"] {
2655 remote_exec build "ld -b ${objects} -o ${dest}"
2657 set link_options $options
2658 if [test_compiler_info "xlc-*"] {
2659 lappend link_options "additional_flags=-qmkshrobj"
2661 lappend link_options "additional_flags=-shared"
2663 if { ([istarget "*-*-mingw*"]
2664 || [istarget *-*-cygwin*]
2665 || [istarget *-*-pe*])} {
2666 lappend link_options "additional_flags=-Wl,--out-implib,${dest}.a"
2667 } elseif [is_remote target] {
2668 # By default, we do not set the soname. This causes the linker
2669 # on ELF systems to create a DT_NEEDED entry in the executable
2670 # refering to the full path name of the library. This is a
2671 # problem in remote testing if the library is in a different
2672 # directory there. To fix this, we set a soname of just the
2673 # base filename for the library, and add an appropriate -rpath
2674 # to the main executable (in gdb_compile).
2675 set destbase [file tail $dest]
2676 lappend link_options "additional_flags=-Wl,-soname,$destbase"
2679 if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
2685 # This is just like gdb_compile_shlib, above, except that it tries compiling
2686 # against several different thread libraries, to see which one this
2688 proc gdb_compile_shlib_pthreads {sources dest options} {
2690 set why_msg "unrecognized error"
2691 foreach lib {-lpthreads -lpthread -lthread ""} {
2692 # This kind of wipes out whatever libs the caller may have
2693 # set. Or maybe theirs will override ours. How infelicitous.
2694 set options_with_lib [concat $options [list libs=$lib quiet]]
2695 set ccout [gdb_compile_shlib $sources $dest $options_with_lib]
2696 switch -regexp -- $ccout {
2697 ".*no posix threads support.*" {
2698 set why_msg "missing threads include file"
2701 ".*cannot open -lpthread.*" {
2702 set why_msg "missing runtime threads library"
2704 ".*Can't find library for -lpthread.*" {
2705 set why_msg "missing runtime threads library"
2708 pass "successfully compiled posix threads test case"
2714 if {!$built_binfile} {
2715 unsupported "Couldn't compile $sources: ${why_msg}"
2720 # This is just like gdb_compile_pthreads, above, except that we always add the
2721 # objc library for compiling Objective-C programs
2722 proc gdb_compile_objc {source dest type options} {
2724 set why_msg "unrecognized error"
2725 foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} {
2726 # This kind of wipes out whatever libs the caller may have
2727 # set. Or maybe theirs will override ours. How infelicitous.
2728 if { $lib == "solaris" } {
2729 set lib "-lpthread -lposix4"
2731 if { $lib != "-lobjc" } {
2732 set lib "-lobjc $lib"
2734 set options_with_lib [concat $options [list libs=$lib quiet]]
2735 set ccout [gdb_compile $source $dest $type $options_with_lib]
2736 switch -regexp -- $ccout {
2737 ".*no posix threads support.*" {
2738 set why_msg "missing threads include file"
2741 ".*cannot open -lpthread.*" {
2742 set why_msg "missing runtime threads library"
2744 ".*Can't find library for -lpthread.*" {
2745 set why_msg "missing runtime threads library"
2748 pass "successfully compiled objc with posix threads test case"
2754 if {!$built_binfile} {
2755 unsupported "Couldn't compile $source: ${why_msg}"
2760 proc send_gdb { string } {
2761 global suppress_flag;
2762 if { $suppress_flag } {
2763 return "suppressed";
2765 return [remote_send host "$string"];
2771 proc gdb_expect { args } {
2772 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
2773 set atimeout [lindex $args 0];
2774 set expcode [list [lindex $args 1]];
2779 upvar timeout timeout;
2781 if [target_info exists gdb,timeout] {
2782 if [info exists timeout] {
2783 if { $timeout < [target_info gdb,timeout] } {
2784 set gtimeout [target_info gdb,timeout];
2786 set gtimeout $timeout;
2789 set gtimeout [target_info gdb,timeout];
2793 if ![info exists gtimeout] {
2795 if [info exists timeout] {
2796 set gtimeout $timeout;
2800 if [info exists atimeout] {
2801 if { ![info exists gtimeout] || $gtimeout < $atimeout } {
2802 set gtimeout $atimeout;
2805 if ![info exists gtimeout] {
2811 global suppress_flag;
2812 global remote_suppress_flag;
2813 if [info exists remote_suppress_flag] {
2814 set old_val $remote_suppress_flag;
2816 if [info exists suppress_flag] {
2817 if { $suppress_flag } {
2818 set remote_suppress_flag 1;
2822 {uplevel remote_expect host $gtimeout $expcode} string];
2823 if [info exists old_val] {
2824 set remote_suppress_flag $old_val;
2826 if [info exists remote_suppress_flag] {
2827 unset remote_suppress_flag;
2832 global errorInfo errorCode;
2834 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
2836 return -code $code $string
2840 # gdb_expect_list TEST SENTINEL LIST -- expect a sequence of outputs
2842 # Check for long sequence of output by parts.
2843 # TEST: is the test message to be printed with the test success/fail.
2844 # SENTINEL: Is the terminal pattern indicating that output has finished.
2845 # LIST: is the sequence of outputs to match.
2846 # If the sentinel is recognized early, it is considered an error.
2849 # 1 if the test failed,
2850 # 0 if the test passes,
2851 # -1 if there was an internal error.
2853 proc gdb_expect_list {test sentinel list} {
2855 global suppress_flag
2858 if { $suppress_flag } {
2860 unresolved "${test}"
2862 while { ${index} < [llength ${list}] } {
2863 set pattern [lindex ${list} ${index}]
2864 set index [expr ${index} + 1]
2865 verbose -log "gdb_expect_list pattern: /$pattern/" 2
2866 if { ${index} == [llength ${list}] } {
2869 -re "${pattern}${sentinel}" {
2870 # pass "${test}, pattern ${index} + sentinel"
2873 fail "${test} (pattern ${index} + sentinel)"
2876 -re ".*A problem internal to GDB has been detected" {
2877 fail "${test} (GDB internal error)"
2879 gdb_internal_error_resync
2882 fail "${test} (pattern ${index} + sentinel) (timeout)"
2887 # unresolved "${test}, pattern ${index} + sentinel"
2893 # pass "${test}, pattern ${index}"
2896 fail "${test} (pattern ${index})"
2899 -re ".*A problem internal to GDB has been detected" {
2900 fail "${test} (GDB internal error)"
2902 gdb_internal_error_resync
2905 fail "${test} (pattern ${index}) (timeout)"
2910 # unresolved "${test}, pattern ${index}"
2924 proc gdb_suppress_entire_file { reason } {
2925 global suppress_flag;
2927 warning "$reason\n";
2928 set suppress_flag -1;
2932 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
2933 # gdb_expect to fail immediately (until the next call to
2934 # gdb_stop_suppressing_tests).
2936 proc gdb_suppress_tests { args } {
2937 global suppress_flag;
2939 return; # fnf - disable pending review of results where
2940 # testsuite ran better without this
2943 if { $suppress_flag == 1 } {
2944 if { [llength $args] > 0 } {
2945 warning "[lindex $args 0]\n";
2947 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
2953 # Clear suppress_flag.
2955 proc gdb_stop_suppressing_tests { } {
2956 global suppress_flag;
2958 if [info exists suppress_flag] {
2959 if { $suppress_flag > 0 } {
2960 set suppress_flag 0;
2961 clone_output "Tests restarted.\n";
2964 set suppress_flag 0;
2968 proc gdb_clear_suppressed { } {
2969 global suppress_flag;
2971 set suppress_flag 0;
2974 proc gdb_start { } {
2979 catch default_gdb_exit
2983 # gdb_load_cmd -- load a file into the debugger.
2984 # ARGS - additional args to load command.
2985 # return a -1 if anything goes wrong.
2987 proc gdb_load_cmd { args } {
2990 if [target_info exists gdb_load_timeout] {
2991 set loadtimeout [target_info gdb_load_timeout]
2993 set loadtimeout 1600
2995 send_gdb "load $args\n"
2996 verbose "Timeout is now $loadtimeout seconds" 2
2997 gdb_expect $loadtimeout {
2998 -re "Loading section\[^\r\]*\r\n" {
3001 -re "Start address\[\r\]*\r\n" {
3004 -re "Transfer rate\[\r\]*\r\n" {
3007 -re "Memory access error\[^\r\]*\r\n" {
3008 perror "Failed to load program"
3011 -re "$gdb_prompt $" {
3014 -re "(.*)\r\n$gdb_prompt " {
3015 perror "Unexpected reponse from 'load' -- $expect_out(1,string)"
3019 perror "Timed out trying to load $args."
3026 # Return the filename to download to the target and load on the target
3027 # for this shared library. Normally just LIBNAME, unless shared libraries
3028 # for this target have separate link and load images.
3030 proc shlib_target_file { libname } {
3034 # Return the filename GDB will load symbols from when debugging this
3035 # shared library. Normally just LIBNAME, unless shared libraries for
3036 # this target have separate link and load images.
3038 proc shlib_symbol_file { libname } {
3042 # Return the filename to download to the target and load for this
3043 # executable. Normally just BINFILE unless it is renamed to something
3044 # else for this target.
3046 proc exec_target_file { binfile } {
3050 # Return the filename GDB will load symbols from when debugging this
3051 # executable. Normally just BINFILE unless executables for this target
3052 # have separate files for symbols.
3054 proc exec_symbol_file { binfile } {
3058 # Rename the executable file. Normally this is just BINFILE1 being renamed
3059 # to BINFILE2, but some targets require multiple binary files.
3060 proc gdb_rename_execfile { binfile1 binfile2 } {
3061 file rename -force [exec_target_file ${binfile1}] \
3062 [exec_target_file ${binfile2}]
3063 if { [exec_target_file ${binfile1}] != [exec_symbol_file ${binfile1}] } {
3064 file rename -force [exec_symbol_file ${binfile1}] \
3065 [exec_symbol_file ${binfile2}]
3069 # "Touch" the executable file to update the date. Normally this is just
3070 # BINFILE, but some targets require multiple files.
3071 proc gdb_touch_execfile { binfile } {
3072 set time [clock seconds]
3073 file mtime [exec_target_file ${binfile}] $time
3074 if { [exec_target_file ${binfile}] != [exec_symbol_file ${binfile}] } {
3075 file mtime [exec_symbol_file ${binfile}] $time
3081 # Copy a file to the remote target and return its target filename.
3082 # Schedule the file to be deleted at the end of this test.
3084 proc gdb_download { filename } {
3087 set destname [remote_download target $filename]
3088 lappend cleanfiles $destname
3092 # gdb_load_shlibs LIB...
3094 # Copy the listed libraries to the target.
3096 proc gdb_load_shlibs { args } {
3097 if {![is_remote target]} {
3101 foreach file $args {
3102 gdb_download [shlib_target_file $file]
3105 # Even if the target supplies full paths for shared libraries,
3106 # they may not be paths for this system.
3107 gdb_test "set solib-search-path [file dirname [lindex $args 0]]" "" ""
3111 # gdb_load -- load a file into the debugger.
3112 # Many files in config/*.exp override this procedure.
3114 proc gdb_load { arg } {
3115 return [gdb_file_cmd $arg]
3118 # gdb_reload -- load a file into the target. Called before "running",
3119 # either the first time or after already starting the program once,
3120 # for remote targets. Most files that override gdb_load should now
3121 # override this instead.
3123 proc gdb_reload { } {
3124 # For the benefit of existing configurations, default to gdb_load.
3125 # Specifying no file defaults to the executable currently being
3127 return [gdb_load ""]
3130 proc gdb_continue { function } {
3133 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
3136 proc default_gdb_init { args } {
3137 global gdb_wrapper_initialized
3138 global gdb_wrapper_target
3139 global gdb_test_file_name
3144 gdb_clear_suppressed;
3146 set gdb_test_file_name [file rootname [file tail [lindex $args 0]]]
3148 # Make sure that the wrapper is rebuilt
3149 # with the appropriate multilib option.
3150 if { $gdb_wrapper_target != [current_target_name] } {
3151 set gdb_wrapper_initialized 0
3154 # Unlike most tests, we have a small number of tests that generate
3155 # a very large amount of output. We therefore increase the expect
3156 # buffer size to be able to contain the entire test output.
3158 # Also set this value for the currently running GDB.
3159 match_max [match_max -d]
3161 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
3162 if { [llength $args] > 0 } {
3165 set file [lindex $args 0];
3167 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
3170 if [target_info exists gdb_prompt] {
3171 set gdb_prompt [target_info gdb_prompt];
3173 set gdb_prompt "\\(gdb\\)"
3176 if [info exists use_gdb_stub] {
3181 # Turn BASENAME into a full file name in the standard output
3182 # directory. It is ok if BASENAME is the empty string; in this case
3183 # the directory is returned.
3185 proc standard_output_file {basename} {
3186 global objdir subdir
3188 return [file join $objdir $subdir $basename]
3191 # Set 'testfile', 'srcfile', and 'binfile'.
3193 # ARGS is a list of source file specifications.
3194 # Without any arguments, the .exp file's base name is used to
3195 # compute the source file name. The ".c" extension is added in this case.
3196 # If ARGS is not empty, each entry is a source file specification.
3197 # If the specification starts with a ".", it is treated as a suffix
3198 # to append to the .exp file's base name.
3199 # If the specification is the empty string, it is treated as if it
3201 # Otherwise it is a file name.
3202 # The first file in the list is used to set the 'srcfile' global.
3203 # Each subsequent name is used to set 'srcfile2', 'srcfile3', etc.
3205 # Most tests should call this without arguments.
3207 # If a completely different binary file name is needed, then it
3208 # should be handled in the .exp file with a suitable comment.
3210 proc standard_testfile {args} {
3211 global gdb_test_file_name
3213 global gdb_test_file_last_vars
3216 global testfile binfile
3218 set testfile $gdb_test_file_name
3219 set binfile [standard_output_file ${testfile}]
3221 if {[llength $args] == 0} {
3225 # Unset our previous output variables.
3226 # This can help catch hidden bugs.
3227 if {[info exists gdb_test_file_last_vars]} {
3228 foreach varname $gdb_test_file_last_vars {
3230 catch {unset $varname}
3233 # 'executable' is often set by tests.
3234 set gdb_test_file_last_vars {executable}
3238 set varname srcfile$suffix
3241 # Handle an extension.
3244 } elseif {[string range $arg 0 0] == "."} {
3245 set arg $testfile$arg
3249 lappend gdb_test_file_last_vars $varname
3251 if {$suffix == ""} {
3259 # The default timeout used when testing GDB commands. We want to use
3260 # the same timeout as the default dejagnu timeout, unless the user has
3261 # already provided a specific value (probably through a site.exp file).
3262 global gdb_test_timeout
3263 if ![info exists gdb_test_timeout] {
3264 set gdb_test_timeout $timeout
3267 # A list of global variables that GDB testcases should not use.
3268 # We try to prevent their use by monitoring write accesses and raising
3269 # an error when that happens.
3270 set banned_variables { bug_id prms_id }
3272 # A list of procedures that GDB testcases should not use.
3273 # We try to prevent their use by monitoring invocations and raising
3274 # an error when that happens.
3275 set banned_procedures { strace }
3277 # gdb_init is called by runtest at start, but also by several
3278 # tests directly; gdb_finish is only called from within runtest after
3279 # each test source execution.
3280 # Placing several traces by repetitive calls to gdb_init leads
3281 # to problems, as only one trace is removed in gdb_finish.
3282 # To overcome this possible problem, we add a variable that records
3283 # if the banned variables and procedures are already traced.
3286 proc gdb_init { args } {
3287 # Reset the timeout value to the default. This way, any testcase
3288 # that changes the timeout value without resetting it cannot affect
3289 # the timeout used in subsequent testcases.
3290 global gdb_test_timeout
3292 set timeout $gdb_test_timeout
3294 # Block writes to all banned variables, and invocation of all
3295 # banned procedures...
3296 global banned_variables
3297 global banned_procedures
3298 global banned_traced
3299 if (!$banned_traced) {
3300 foreach banned_var $banned_variables {
3301 global "$banned_var"
3302 trace add variable "$banned_var" write error
3304 foreach banned_proc $banned_procedures {
3305 global "$banned_proc"
3306 trace add execution "$banned_proc" enter error
3311 # We set LC_ALL, LC_CTYPE, and LANG to C so that we get the same
3312 # messages as expected.
3317 # Don't let a .inputrc file or an existing setting of INPUTRC mess up
3318 # the test results. Even if /dev/null doesn't exist on the particular
3319 # platform, the readline library will use the default setting just by
3320 # failing to open the file. OTOH, opening /dev/null successfully will
3321 # also result in the default settings being used since nothing will be
3322 # read from this file.
3323 setenv INPUTRC "/dev/null"
3325 # The gdb.base/readline.exp arrow key test relies on the standard VT100
3326 # bindings, so make sure that an appropriate terminal is selected.
3327 # The same bug doesn't show up if we use ^P / ^N instead.
3330 # Some tests (for example gdb.base/maint.exp) shell out from gdb to use
3331 # grep. Clear GREP_OPTIONS to make the behavoiur predictable,
3332 # especially having color output turned on can cause tests to fail.
3333 setenv GREP_OPTIONS ""
3335 # Clear $gdbserver_reconnect_p.
3336 global gdbserver_reconnect_p
3337 set gdbserver_reconnect_p 1
3338 unset gdbserver_reconnect_p
3340 return [eval default_gdb_init $args];
3343 proc gdb_finish { } {
3346 # Exit first, so that the files are no longer in use.
3349 if { [llength $cleanfiles] > 0 } {
3350 eval remote_file target delete $cleanfiles
3354 # Unblock write access to the banned variables. Dejagnu typically
3355 # resets some of them between testcases.
3356 global banned_variables
3357 global banned_procedures
3358 global banned_traced
3359 if ($banned_traced) {
3360 foreach banned_var $banned_variables {
3361 global "$banned_var"
3362 trace remove variable "$banned_var" write error
3364 foreach banned_proc $banned_procedures {
3365 global "$banned_proc"
3366 trace remove execution "$banned_proc" enter error
3373 set debug_format "unknown"
3375 # Run the gdb command "info source" and extract the debugging format
3376 # information from the output and save it in debug_format.
3378 proc get_debug_format { } {
3384 set debug_format "unknown"
3385 send_gdb "info source\n"
3387 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
3388 set debug_format $expect_out(1,string)
3389 verbose "debug format is $debug_format"
3392 -re "No current source file.\r\n$gdb_prompt $" {
3393 perror "get_debug_format used when no current source file"
3396 -re "$gdb_prompt $" {
3397 warning "couldn't check debug format (no valid response)."
3401 warning "couldn't check debug format (timeout)."
3407 # Return true if FORMAT matches the debug format the current test was
3408 # compiled with. FORMAT is a shell-style globbing pattern; it can use
3409 # `*', `[...]', and so on.
3411 # This function depends on variables set by `get_debug_format', above.
3413 proc test_debug_format {format} {
3416 return [expr [string match $format $debug_format] != 0]
3419 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
3420 # COFF, stabs, etc). If that format matches the format that the
3421 # current test was compiled with, then the next test is expected to
3422 # fail for any target. Returns 1 if the next test or set of tests is
3423 # expected to fail, 0 otherwise (or if it is unknown). Must have
3424 # previously called get_debug_format.
3425 proc setup_xfail_format { format } {
3426 set ret [test_debug_format $format];
3434 # Like setup_kfail, but only call setup_kfail conditionally if
3435 # istarget[TARGET] returns true.
3436 proc setup_kfail_for_target { PR target } {
3437 if { [istarget $target] } {
3438 setup_kfail $PR $target
3442 # gdb_get_line_number TEXT [FILE]
3444 # Search the source file FILE, and return the line number of the
3445 # first line containing TEXT. If no match is found, an error is thrown.
3447 # TEXT is a string literal, not a regular expression.
3449 # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is
3450 # specified, and does not start with "/", then it is assumed to be in
3451 # "$srcdir/$subdir". This is awkward, and can be fixed in the future,
3452 # by changing the callers and the interface at the same time.
3453 # In particular: gdb.base/break.exp, gdb.base/condbreak.exp,
3454 # gdb.base/ena-dis-br.exp.
3456 # Use this function to keep your test scripts independent of the
3457 # exact line numbering of the source file. Don't write:
3459 # send_gdb "break 20"
3461 # This means that if anyone ever edits your test's source file,
3462 # your test could break. Instead, put a comment like this on the
3463 # source file line you want to break at:
3465 # /* breakpoint spot: frotz.exp: test name */
3467 # and then write, in your test script (which we assume is named
3470 # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
3472 # (Yes, Tcl knows how to handle the nested quotes and brackets.
3475 # % puts "foo [lindex "bar baz" 1]"
3478 # Tcl is quite clever, for a little stringy language.)
3482 # The previous implementation of this procedure used the gdb search command.
3483 # This version is different:
3485 # . It works with MI, and it also works when gdb is not running.
3487 # . It operates on the build machine, not the host machine.
3489 # . For now, this implementation fakes a current directory of
3490 # $srcdir/$subdir to be compatible with the old implementation.
3491 # This will go away eventually and some callers will need to
3494 # . The TEXT argument is literal text and matches literally,
3495 # not a regular expression as it was before.
3497 # . State changes in gdb, such as changing the current file
3498 # and setting $_, no longer happen.
3500 # After a bit of time we can forget about the differences from the
3501 # old implementation.
3503 # --chastain 2004-08-05
3505 proc gdb_get_line_number { text { file "" } } {
3510 if { "$file" == "" } then {
3513 if { ! [regexp "^/" "$file"] } then {
3514 set file "$srcdir/$subdir/$file"
3517 if { [ catch { set fd [open "$file"] } message ] } then {
3522 for { set line 1 } { 1 } { incr line } {
3523 if { [ catch { set nchar [gets "$fd" body] } message ] } then {
3526 if { $nchar < 0 } then {
3529 if { [string first "$text" "$body"] >= 0 } then {
3535 if { [ catch { close "$fd" } message ] } then {
3540 error "undefined tag \"$text\""
3546 # gdb_continue_to_end:
3547 # The case where the target uses stubs has to be handled specially. If a
3548 # stub is used, we set a breakpoint at exit because we cannot rely on
3549 # exit() behavior of a remote target.
3551 # MSSG is the error message that gets printed. If not given, a
3553 # COMMAND is the command to invoke. If not given, "continue" is
3555 # ALLOW_EXTRA is a flag indicating whether the test should expect
3556 # extra output between the "Continuing." line and the program
3557 # exiting. By default it is zero; if nonzero, any extra output
3560 proc gdb_continue_to_end {{mssg ""} {command continue} {allow_extra 0}} {
3561 global inferior_exited_re use_gdb_stub
3564 set text "continue until exit"
3566 set text "continue until exit at $mssg"
3574 if {![gdb_breakpoint "exit"]} {
3577 gdb_test $command "Continuing..*Breakpoint .*exit.*" \
3580 # Continue until we exit. Should not stop again.
3581 # Don't bother to check the output of the program, that may be
3582 # extremely tough for some remote systems.
3584 "Continuing.\[\r\n0-9\]+${extra}(... EXIT code 0\[\r\n\]+|$inferior_exited_re normally).*"\
3589 proc rerun_to_main {} {
3590 global gdb_prompt use_gdb_stub
3595 -re ".*Breakpoint .*main .*$gdb_prompt $"\
3596 {pass "rerun to main" ; return 0}
3597 -re "$gdb_prompt $"\
3598 {fail "rerun to main" ; return 0}
3599 timeout {fail "(timeout) rerun to main" ; return 0}
3604 -re "The program .* has been started already.*y or n. $" {
3608 -re "Starting program.*$gdb_prompt $"\
3609 {pass "rerun to main" ; return 0}
3610 -re "$gdb_prompt $"\
3611 {fail "rerun to main" ; return 0}
3612 timeout {fail "(timeout) rerun to main" ; return 0}
3617 # Print a message and return true if a test should be skipped
3618 # due to lack of floating point suport.
3620 proc gdb_skip_float_test { msg } {
3621 if [target_info exists gdb,skip_float_tests] {
3622 verbose "Skipping test '$msg': no float tests.";
3628 # Print a message and return true if a test should be skipped
3629 # due to lack of stdio support.
3631 proc gdb_skip_stdio_test { msg } {
3632 if [target_info exists gdb,noinferiorio] {
3633 verbose "Skipping test '$msg': no inferior i/o.";
3639 proc gdb_skip_bogus_test { msg } {
3643 # Return true if a test should be skipped due to lack of XML support
3645 # NOTE: This must be called while gdb is *not* running.
3647 proc gdb_skip_xml_test { } {
3650 global xml_missing_cached
3652 if {[info exists xml_missing_cached]} {
3653 return $xml_missing_cached
3657 set xml_missing_cached 0
3658 gdb_test_multiple "set tdesc filename ${srcdir}/gdb.xml/trivial.xml" "" {
3659 -re ".*XML support was disabled at compile time.*$gdb_prompt $" {
3660 set xml_missing_cached 1
3662 -re ".*$gdb_prompt $" { }
3665 return $xml_missing_cached
3668 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
3669 # ${binfile}.dbglnk, which is just like the executable ($binfile) but without
3670 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
3671 # the name of a debuginfo only file. This file will be stored in the same
3674 # Functions for separate debug info testing
3676 # starting with an executable:
3677 # foo --> original executable
3679 # at the end of the process we have:
3680 # foo.stripped --> foo w/o debug info
3681 # foo.debug --> foo's debug info
3682 # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug.
3684 # Return the build-id hex string (usually 160 bits as 40 hex characters)
3685 # converted to the form: .build-id/ab/cdef1234...89.debug
3686 # Return "" if no build-id found.
3687 proc build_id_debug_filename_get { exec } {
3688 set tmp "${exec}-tmp"
3689 set objcopy_program [transform objcopy]
3691 set result [catch "exec $objcopy_program -j .note.gnu.build-id -O binary $exec $tmp" output]
3692 verbose "result is $result"
3693 verbose "output is $output"
3698 fconfigure $fi -translation binary
3699 # Skip the NOTE header.
3704 if ![string compare $data ""] then {
3707 # Convert it to hex.
3708 binary scan $data H* data
3709 regsub {^..} $data {\0/} data
3710 return ".build-id/${data}.debug";
3713 # Create stripped files for DEST, replacing it. If ARGS is passed, it is a
3714 # list of optional flags. The only currently supported flag is no-main,
3715 # which removes the symbol entry for main from the separate debug file.
3717 # Function returns zero on success. Function will return non-zero failure code
3718 # on some targets not supporting separate debug info (such as i386-msdos).
3720 proc gdb_gnu_strip_debug { dest args } {
3722 # Use the first separate debug info file location searched by GDB so the
3723 # run cannot be broken by some stale file searched with higher precedence.
3724 set debug_file "${dest}.debug"
3726 set strip_to_file_program [transform strip]
3727 set objcopy_program [transform objcopy]
3729 set debug_link [file tail $debug_file]
3730 set stripped_file "${dest}.stripped"
3732 # Get rid of the debug info, and store result in stripped_file
3733 # something like gdb/testsuite/gdb.base/blah.stripped.
3734 set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
3735 verbose "result is $result"
3736 verbose "output is $output"
3741 # Workaround PR binutils/10802:
3742 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
3743 set perm [file attributes ${dest} -permissions]
3744 file attributes ${stripped_file} -permissions $perm
3746 # Get rid of everything but the debug info, and store result in debug_file
3747 # This will be in the .debug subdirectory, see above.
3748 set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
3749 verbose "result is $result"
3750 verbose "output is $output"
3755 # If no-main is passed, strip the symbol for main from the separate
3756 # file. This is to simulate the behavior of elfutils's eu-strip, which
3757 # leaves the symtab in the original file only. There's no way to get
3758 # objcopy or strip to remove the symbol table without also removing the
3759 # debugging sections, so this is as close as we can get.
3760 if { [llength $args] == 1 && [lindex $args 0] == "no-main" } {
3761 set result [catch "exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp" output]
3762 verbose "result is $result"
3763 verbose "output is $output"
3767 file delete "${debug_file}"
3768 file rename "${debug_file}-tmp" "${debug_file}"
3771 # Link the two previous output files together, adding the .gnu_debuglink
3772 # section to the stripped_file, containing a pointer to the debug_file,
3773 # save the new file in dest.
3774 # This will be the regular executable filename, in the usual location.
3775 set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
3776 verbose "result is $result"
3777 verbose "output is $output"
3782 # Workaround PR binutils/10802:
3783 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
3784 set perm [file attributes ${stripped_file} -permissions]
3785 file attributes ${dest} -permissions $perm
3790 # Test the output of GDB_COMMAND matches the pattern obtained
3791 # by concatenating all elements of EXPECTED_LINES. This makes
3792 # it possible to split otherwise very long string into pieces.
3793 # If third argument is not empty, it's used as the name of the
3794 # test to be printed on pass/fail.
3795 proc help_test_raw { gdb_command expected_lines args } {
3796 set message $gdb_command
3797 if [llength $args]>0 then {
3798 set message [lindex $args 0]
3800 set expected_output [join $expected_lines ""]
3801 gdb_test "${gdb_command}" "${expected_output}" $message
3804 # Test the output of "help COMMAND_CLASS". EXPECTED_INITIAL_LINES
3805 # are regular expressions that should match the beginning of output,
3806 # before the list of commands in that class. The presence of
3807 # command list and standard epilogue will be tested automatically.
3808 proc test_class_help { command_class expected_initial_lines args } {
3810 "List of commands\:.*\[\r\n\]+"
3811 "Type \"help\" followed by command name for full documentation\.\[\r\n\]+"
3812 "Type \"apropos word\" to search for commands related to \"word\"\.[\r\n\]+"
3813 "Command name abbreviations are allowed if unambiguous\."
3815 set l_entire_body [concat $expected_initial_lines $l_stock_body]
3817 eval [list help_test_raw "help ${command_class}" $l_entire_body] $args
3820 # COMMAND_LIST should have either one element -- command to test, or
3821 # two elements -- abbreviated command to test, and full command the first
3822 # element is abbreviation of.
3823 # The command must be a prefix command. EXPECTED_INITIAL_LINES
3824 # are regular expressions that should match the beginning of output,
3825 # before the list of subcommands. The presence of
3826 # subcommand list and standard epilogue will be tested automatically.
3827 proc test_prefix_command_help { command_list expected_initial_lines args } {
3828 set command [lindex $command_list 0]
3829 if {[llength $command_list]>1} {
3830 set full_command [lindex $command_list 1]
3832 set full_command $command
3834 # Use 'list' and not just {} because we want variables to
3835 # be expanded in this list.
3836 set l_stock_body [list\
3837 "List of $full_command subcommands\:.*\[\r\n\]+"\
3838 "Type \"help $full_command\" followed by $full_command subcommand name for full documentation\.\[\r\n\]+"\
3839 "Type \"apropos word\" to search for commands related to \"word\"\.\[\r\n\]+"\
3840 "Command name abbreviations are allowed if unambiguous\."]
3841 set l_entire_body [concat $expected_initial_lines $l_stock_body]
3842 if {[llength $args]>0} {
3843 help_test_raw "help ${command}" $l_entire_body [lindex $args 0]
3845 help_test_raw "help ${command}" $l_entire_body
3849 # Build executable named EXECUTABLE from specifications that allow
3850 # different options to be passed to different sub-compilations.
3851 # TESTNAME is the name of the test; this is passed to 'untested' if
3853 # OPTIONS is passed to the final link, using gdb_compile.
3854 # ARGS is a flat list of source specifications, of the form:
3855 # { SOURCE1 OPTIONS1 [ SOURCE2 OPTIONS2 ]... }
3856 # Each SOURCE is compiled to an object file using its OPTIONS,
3857 # using gdb_compile.
3858 # Returns 0 on success, -1 on failure.
3859 proc build_executable_from_specs {testname executable options args} {
3863 set binfile [standard_output_file $executable]
3867 foreach {s local_options} $args {
3868 if { [gdb_compile "${srcdir}/${subdir}/${s}" "${binfile}${i}.o" object $local_options] != "" } {
3872 lappend objects "${binfile}${i}.o"
3876 if { [gdb_compile $objects "${binfile}" executable $options] != "" } {
3882 if { [lsearch -exact $options "c++"] >= 0 } {
3883 set info_options "c++"
3885 if [get_compiler_info ${info_options}] {
3891 # Build executable named EXECUTABLE, from SOURCES. If SOURCES are not
3892 # provided, uses $EXECUTABLE.c. The TESTNAME paramer is the name of test
3893 # to pass to untested, if something is wrong. OPTIONS are passed
3894 # to gdb_compile directly.
3895 proc build_executable { testname executable {sources ""} {options {debug}} } {
3896 if {[llength $sources]==0} {
3897 set sources ${executable}.c
3900 set arglist [list $testname $executable $options]
3901 foreach source $sources {
3902 lappend arglist $source $options
3905 return [eval build_executable_from_specs $arglist]
3908 # Starts fresh GDB binary and loads EXECUTABLE into GDB. EXECUTABLE is
3909 # the basename of the binary.
3910 proc clean_restart { executable } {
3913 set binfile [standard_output_file ${executable}]
3917 gdb_reinitialize_dir $srcdir/$subdir
3921 # Prepares for testing by calling build_executable_full, then
3923 # TESTNAME is the name of the test.
3924 # Each element in ARGS is a list of the form
3925 # { EXECUTABLE OPTIONS SOURCE_SPEC... }
3926 # These are passed to build_executable_from_specs, which see.
3927 # The last EXECUTABLE is passed to clean_restart.
3928 # Returns 0 on success, non-zero on failure.
3929 proc prepare_for_testing_full {testname args} {
3930 foreach spec $args {
3931 if {[eval build_executable_from_specs [list $testname] $spec] == -1} {
3934 set executable [lindex $spec 0]
3936 clean_restart $executable
3940 # Prepares for testing, by calling build_executable, and then clean_restart.
3941 # Please refer to build_executable for parameter description.
3942 proc prepare_for_testing { testname executable {sources ""} {options {debug}}} {
3944 if {[build_executable $testname $executable $sources $options] == -1} {
3947 clean_restart $executable
3952 proc get_valueof { fmt exp default } {
3955 set test "get valueof \"${exp}\""
3957 gdb_test_multiple "print${fmt} ${exp}" "$test" {
3958 -re "\\$\[0-9\]* = (.*)\[\r\n\]*$gdb_prompt $" {
3959 set val $expect_out(1,string)
3963 fail "$test (timeout)"
3969 proc get_integer_valueof { exp default } {
3972 set test "get integer valueof \"${exp}\""
3974 gdb_test_multiple "print /d ${exp}" "$test" {
3975 -re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" {
3976 set val $expect_out(1,string)
3980 fail "$test (timeout)"
3986 proc get_hexadecimal_valueof { exp default } {
3988 send_gdb "print /x ${exp}\n"
3989 set test "get hexadecimal valueof \"${exp}\""
3991 -re "\\$\[0-9\]* = (0x\[0-9a-zA-Z\]+).*$gdb_prompt $" {
3992 set val $expect_out(1,string)
3997 fail "$test (timeout)"
4003 proc get_sizeof { type default } {
4004 return [get_integer_valueof "sizeof (${type})" $default]
4007 # Get the current value for remotetimeout and return it.
4008 proc get_remotetimeout { } {
4012 gdb_test_multiple "show remotetimeout" "" {
4013 -re "Timeout limit to wait for target to respond is ($decimal).*$gdb_prompt $" {
4014 return $expect_out(1,string);
4018 # Pick the default that gdb uses
4019 warning "Unable to read remotetimeout"
4023 # Set the remotetimeout to the specified timeout. Nothing is returned.
4024 proc set_remotetimeout { timeout } {
4027 gdb_test_multiple "set remotetimeout $timeout" "" {
4028 -re "$gdb_prompt $" {
4029 verbose "Set remotetimeout to $timeout\n"
4034 # Log gdb command line and script if requested.
4035 if {[info exists TRANSCRIPT]} {
4036 rename send_gdb real_send_gdb
4037 rename remote_spawn real_remote_spawn
4038 rename remote_close real_remote_close
4040 global gdb_transcript
4041 set gdb_transcript ""
4043 global gdb_trans_count
4044 set gdb_trans_count 1
4046 proc remote_spawn {args} {
4047 global gdb_transcript gdb_trans_count outdir
4049 if {$gdb_transcript != ""} {
4050 close $gdb_transcript
4052 set gdb_transcript [open [file join $outdir transcript.$gdb_trans_count] w]
4053 puts $gdb_transcript [lindex $args 1]
4054 incr gdb_trans_count
4056 return [uplevel real_remote_spawn $args]
4059 proc remote_close {args} {
4060 global gdb_transcript
4062 if {$gdb_transcript != ""} {
4063 close $gdb_transcript
4064 set gdb_transcript ""
4067 return [uplevel real_remote_close $args]
4070 proc send_gdb {args} {
4071 global gdb_transcript
4073 if {$gdb_transcript != ""} {
4074 puts -nonewline $gdb_transcript [lindex $args 0]
4077 return [uplevel real_send_gdb $args]
4081 proc core_find {binfile {deletefiles {}} {arg ""}} {
4082 global objdir subdir
4084 set destcore "$binfile.core"
4085 file delete $destcore
4087 # Create a core file named "$destcore" rather than just "core", to
4088 # avoid problems with sys admin types that like to regularly prune all
4089 # files named "core" from the system.
4091 # Arbitrarily try setting the core size limit to "unlimited" since
4092 # this does not hurt on systems where the command does not work and
4093 # allows us to generate a core on systems where it does.
4095 # Some systems append "core" to the name of the program; others append
4096 # the name of the program to "core"; still others (like Linux, as of
4097 # May 2003) create cores named "core.PID". In the latter case, we
4098 # could have many core files lying around, and it may be difficult to
4099 # tell which one is ours, so let's run the program in a subdirectory.
4101 set coredir [standard_output_file coredir.[getpid]]
4103 catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile} ${arg}; true) >/dev/null 2>&1\""
4104 # remote_exec host "${binfile}"
4105 foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
4106 if [remote_file build exists $i] {
4107 remote_exec build "mv $i $destcore"
4111 # Check for "core.PID".
4112 if { $found == 0 } {
4113 set names [glob -nocomplain -directory $coredir core.*]
4114 if {[llength $names] == 1} {
4115 set corefile [file join $coredir [lindex $names 0]]
4116 remote_exec build "mv $corefile $destcore"
4120 if { $found == 0 } {
4121 # The braindamaged HPUX shell quits after the ulimit -c above
4122 # without executing ${binfile}. So we try again without the
4123 # ulimit here if we didn't find a core file above.
4124 # Oh, I should mention that any "braindamaged" non-Unix system has
4125 # the same problem. I like the cd bit too, it's really neat'n stuff.
4126 catch "system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\""
4127 foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" {
4128 if [remote_file build exists $i] {
4129 remote_exec build "mv $i $destcore"
4135 # Try to clean up after ourselves.
4136 foreach deletefile $deletefiles {
4137 remote_file build delete [file join $coredir $deletefile]
4139 remote_exec build "rmdir $coredir"
4141 if { $found == 0 } {
4142 warning "can't generate a core file - core tests suppressed - check ulimit -c"
4148 # gdb_target_symbol_prefix_flags returns a string that can be added
4149 # to gdb_compile options to define SYMBOL_PREFIX macro value
4150 # symbol_prefix_flags returns a string that can be added
4151 # for targets that use underscore as symbol prefix.
4152 # TODO: find out automatically if the target needs this.
4154 proc gdb_target_symbol_prefix_flags {} {
4155 if { [istarget "*-*-cygwin*"] || [istarget "i?86-*-mingw*"]
4156 || [istarget "*-*-msdosdjgpp*"] || [istarget "*-*-go32*"] } {
4157 return "additional_flags=-DSYMBOL_PREFIX=\"_\""
4163 # Always load compatibility stuff.