1 # Copyright 1992-2014 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"
30 load_lib gdb-utils.exp
34 if [info exists TOOL_EXECUTABLE] {
35 set GDB $TOOL_EXECUTABLE
37 if ![info exists GDB] {
38 if ![is_remote host] {
39 set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]]
41 set GDB [transform gdb]
44 verbose "using GDB = $GDB" 2
46 # GDBFLAGS is available for the user to set on the command line.
47 # E.g. make check RUNTESTFLAGS=GDBFLAGS=mumble
48 # Testcases may use it to add additional flags, but they must:
49 # - append new flags, not overwrite
50 # - restore the original value when done
52 if ![info exists GDBFLAGS] {
55 verbose "using GDBFLAGS = $GDBFLAGS" 2
57 # Make the build data directory available to tests.
58 set BUILD_DATA_DIRECTORY "[pwd]/../data-directory"
60 # INTERNAL_GDBFLAGS contains flags that the testsuite requires.
61 global INTERNAL_GDBFLAGS
62 if ![info exists INTERNAL_GDBFLAGS] {
63 set INTERNAL_GDBFLAGS "-nw -nx -data-directory $BUILD_DATA_DIRECTORY"
66 # The variable gdb_prompt is a regexp which matches the gdb prompt.
67 # Set it if it is not already set. This is also set by default_gdb_init
68 # but it's not clear what removing one of them will break.
69 # See with_gdb_prompt for more details on prompt handling.
71 if ![info exists gdb_prompt] then {
72 set gdb_prompt "\\(gdb\\)"
75 # A regexp that matches the pagination prompt.
76 set pagination_prompt [string_to_regexp "---Type <return> to continue, or q <return> to quit---"]
78 # The variable fullname_syntax_POSIX is a regexp which matches a POSIX
79 # absolute path ie. /foo/
80 set fullname_syntax_POSIX {/[^\n]*/}
81 # The variable fullname_syntax_UNC is a regexp which matches a Windows
82 # UNC path ie. \\D\foo\
83 set fullname_syntax_UNC {\\\\[^\\]+\\[^\n]+\\}
84 # The variable fullname_syntax_DOS_CASE is a regexp which matches a
85 # particular DOS case that GDB most likely will output
86 # ie. \foo\, but don't match \\.*\
87 set fullname_syntax_DOS_CASE {\\[^\\][^\n]*\\}
88 # The variable fullname_syntax_DOS is a regexp which matches a DOS path
89 # ie. a:\foo\ && a:foo\
90 set fullname_syntax_DOS {[a-zA-Z]:[^\n]*\\}
91 # The variable fullname_syntax is a regexp which matches what GDB considers
92 # an absolute path. It is currently debatable if the Windows style paths
93 # d:foo and \abc should be considered valid as an absolute path.
94 # Also, the purpse of this regexp is not to recognize a well formed
95 # absolute path, but to say with certainty that a path is absolute.
96 set fullname_syntax "($fullname_syntax_POSIX|$fullname_syntax_UNC|$fullname_syntax_DOS_CASE|$fullname_syntax_DOS)"
98 # Needed for some tests under Cygwin.
102 if ![info exists env(EXEEXT)] {
105 set EXEEXT $env(EXEEXT)
110 set inferior_exited_re "(\\\[Inferior \[0-9\]+ \\(.*\\) exited)"
112 ### Only procedures should come after this point.
115 # gdb_version -- extract and print the version number of GDB
117 proc default_gdb_version {} {
119 global INTERNAL_GDBFLAGS GDBFLAGS
123 if {[info exists inotify_pid]} {
124 eval exec kill $inotify_pid
127 set output [remote_exec host "$GDB $INTERNAL_GDBFLAGS --version"]
128 set tmp [lindex $output 1]
130 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
131 if ![is_remote host] {
132 clone_output "[which $GDB] version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
134 clone_output "$GDB on remote host version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
138 proc gdb_version { } {
139 return [default_gdb_version]
143 # gdb_unload -- unload a file if one is loaded
144 # Return 0 on success, -1 on error.
153 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
154 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
155 -re "A program is being debugged already.*Are you sure you want to change the file.*y or n. $" {
159 -re "Discard symbol table from .*y or n.*$" {
163 -re "$gdb_prompt $" {}
165 perror "couldn't unload file in $GDB (timeout)."
172 # Many of the tests depend on setting breakpoints at various places and
173 # running until that breakpoint is reached. At times, we want to start
174 # with a clean-slate with respect to breakpoints, so this utility proc
175 # lets us do this without duplicating this code everywhere.
178 proc delete_breakpoints {} {
181 # we need a larger timeout value here or this thing just confuses
182 # itself. May need a better implementation if possible. - guo
184 send_gdb "delete breakpoints\n"
186 -re "Delete all breakpoints.*y or n.*$" {
190 -re "$gdb_prompt $" { # This happens if there were no breakpoints
192 timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
194 send_gdb "info breakpoints\n"
196 -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
197 -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
198 -re "Delete all breakpoints.*or n.*$" {
202 timeout { perror "info breakpoints (timeout)" ; return }
206 # Generic run command.
208 # The second pattern below matches up to the first newline *only*.
209 # Using ``.*$'' could swallow up output that we attempt to match
212 # N.B. This function does not wait for gdb to return to the prompt,
213 # that is the caller's responsibility.
215 proc gdb_run_cmd {args} {
216 global gdb_prompt use_gdb_stub
218 foreach command [gdb_init_commands] {
219 send_gdb "$command\n"
221 -re "$gdb_prompt $" { }
223 perror "gdb_init_command for target failed"
230 if [target_info exists gdb,do_reload_on_run] {
231 if { [gdb_reload] != 0 } {
234 send_gdb "continue\n"
236 -re "Continu\[^\r\n\]*\[\r\n\]" {}
242 if [target_info exists gdb,start_symbol] {
243 set start [target_info gdb,start_symbol]
247 send_gdb "jump *$start\n"
249 while { $start_attempt } {
250 # Cap (re)start attempts at three to ensure that this loop
251 # always eventually fails. Don't worry about trying to be
252 # clever and not send a command when it has failed.
253 if [expr $start_attempt > 3] {
254 perror "Jump to start() failed (retry count exceeded)"
257 set start_attempt [expr $start_attempt + 1]
259 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
262 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
263 perror "Can't find start symbol to run in gdb_run"
266 -re "No symbol \"start\" in current.*$gdb_prompt $" {
267 send_gdb "jump *_start\n"
269 -re "No symbol.*context.*$gdb_prompt $" {
272 -re "Line.* Jump anyway.*y or n. $" {
275 -re "The program is not being run.*$gdb_prompt $" {
276 if { [gdb_reload] != 0 } {
279 send_gdb "jump *$start\n"
282 perror "Jump to start() failed (timeout)"
290 if [target_info exists gdb,do_reload_on_run] {
291 if { [gdb_reload] != 0 } {
295 send_gdb "run $args\n"
296 # This doesn't work quite right yet.
297 # Use -notransfer here so that test cases (like chng-sym.exp)
298 # may test for additional start-up messages.
300 -re "The program .* has been started already.*y or n. $" {
304 -notransfer -re "Starting program: \[^\r\n\]*" {}
305 -notransfer -re "$gdb_prompt $" {
306 # There is no more input expected.
311 # Generic start command. Return 0 if we could start the program, -1
314 # N.B. This function does not wait for gdb to return to the prompt,
315 # that is the caller's responsibility.
317 proc gdb_start_cmd {args} {
318 global gdb_prompt use_gdb_stub
320 foreach command [gdb_init_commands] {
321 send_gdb "$command\n"
323 -re "$gdb_prompt $" { }
325 perror "gdb_init_command for target failed"
335 send_gdb "start $args\n"
336 # Use -notransfer here so that test cases (like chng-sym.exp)
337 # may test for additional start-up messages.
339 -re "The program .* has been started already.*y or n. $" {
343 -notransfer -re "Starting program: \[^\r\n\]*" {
350 # Set a breakpoint at FUNCTION. If there is an additional argument it is
351 # a list of options; the supported options are allow-pending, temporary,
352 # message, no-message, and passfail.
353 # The result is 1 for success, 0 for failure.
355 # Note: The handling of message vs no-message is messed up, but it's based
356 # on historical usage. By default this function does not print passes,
358 # no-message: turns off printing of fails (and passes, but they're already off)
359 # message: turns on printing of passes (and fails, but they're already on)
361 proc gdb_breakpoint { function args } {
365 set pending_response n
366 if {[lsearch -exact $args allow-pending] != -1} {
367 set pending_response y
370 set break_command "break"
371 set break_message "Breakpoint"
372 if {[lsearch -exact $args temporary] != -1} {
373 set break_command "tbreak"
374 set break_message "Temporary breakpoint"
379 set no_message_loc [lsearch -exact $args no-message]
380 set message_loc [lsearch -exact $args message]
381 # The last one to appear in args wins.
382 if { $no_message_loc > $message_loc } {
384 } elseif { $message_loc > $no_message_loc } {
388 set test_name "setting breakpoint at $function"
390 send_gdb "$break_command $function\n"
391 # The first two regexps are what we get with -g, the third is without -g.
393 -re "$break_message \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
394 -re "$break_message \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
395 -re "$break_message \[0-9\]* at .*$gdb_prompt $" {}
396 -re "$break_message \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" {
397 if {$pending_response == "n"} {
404 -re "Make breakpoint pending.*y or \\\[n\\\]. $" {
405 send_gdb "$pending_response\n"
408 -re "A problem internal to GDB has been detected" {
410 fail "$test_name (GDB internal error)"
412 gdb_internal_error_resync
415 -re "$gdb_prompt $" {
423 fail "$test_name (eof)"
429 fail "$test_name (timeout)"
440 # Set breakpoint at function and run gdb until it breaks there.
441 # Since this is the only breakpoint that will be set, if it stops
442 # at a breakpoint, we will assume it is the one we want. We can't
443 # just compare to "function" because it might be a fully qualified,
444 # single quoted C++ function specifier.
446 # If there are additional arguments, pass them to gdb_breakpoint.
447 # We recognize no-message/message ourselves.
448 # The default is no-message.
449 # no-message is messed up here, like gdb_breakpoint: to preserve
450 # historical usage fails are always printed by default.
451 # no-message: turns off printing of fails (and passes, but they're already off)
452 # message: turns on printing of passes (and fails, but they're already on)
454 proc runto { function args } {
460 # Default to "no-message".
461 set args "no-message $args"
465 set no_message_loc [lsearch -exact $args no-message]
466 set message_loc [lsearch -exact $args message]
467 # The last one to appear in args wins.
468 if { $no_message_loc > $message_loc } {
470 } elseif { $message_loc > $no_message_loc } {
474 set test_name "running to $function in runto"
476 # We need to use eval here to pass our varargs args to gdb_breakpoint
477 # which is also a varargs function.
478 # But we also have to be careful because $function may have multiple
479 # elements, and we don't want Tcl to move the remaining elements after
480 # the first to $args. That is why $function is wrapped in {}.
481 if ![eval gdb_breakpoint {$function} $args] {
487 # the "at foo.c:36" output we get with -g.
488 # the "in func" output we get without -g.
490 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
496 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
502 -re "The target does not support running in non-stop mode.\r\n$gdb_prompt $" {
504 unsupported "Non-stop mode not supported"
508 -re ".*A problem internal to GDB has been detected" {
510 fail "$test_name (GDB internal error)"
512 gdb_internal_error_resync
515 -re "$gdb_prompt $" {
523 fail "$test_name (eof)"
529 fail "$test_name (timeout)"
540 # Ask gdb to run until we hit a breakpoint at main.
542 # N.B. This function deletes all existing breakpoints.
543 # If you don't want that, use gdb_start_cmd.
545 proc runto_main { } {
546 return [runto main no-message]
549 ### Continue, and expect to hit a breakpoint.
550 ### Report a pass or fail, depending on whether it seems to have
551 ### worked. Use NAME as part of the test name; each call to
552 ### continue_to_breakpoint should use a NAME which is unique within
554 proc gdb_continue_to_breakpoint {name {location_pattern .*}} {
556 set full_name "continue to breakpoint: $name"
558 gdb_test_multiple "continue" $full_name {
559 -re "(?:Breakpoint|Temporary breakpoint) .* (at|in) $location_pattern\r\n$gdb_prompt $" {
566 # gdb_internal_error_resync:
568 # Answer the questions GDB asks after it reports an internal error
569 # until we get back to a GDB prompt. Decline to quit the debugging
570 # session, and decline to create a core file. Return non-zero if the
573 # This procedure just answers whatever questions come up until it sees
574 # a GDB prompt; it doesn't require you to have matched the input up to
575 # any specific point. However, it only answers questions it sees in
576 # the output itself, so if you've matched a question, you had better
577 # answer it yourself before calling this.
579 # You can use this function thus:
583 # -re ".*A problem internal to GDB has been detected" {
584 # gdb_internal_error_resync
589 proc gdb_internal_error_resync {} {
592 verbose -log "Resyncing due to internal error."
595 while {$count < 10} {
597 -re "Quit this debugging session\\? \\(y or n\\) $" {
601 -re "Create a core file of GDB\\? \\(y or n\\) $" {
605 -re "$gdb_prompt $" {
606 # We're resynchronized.
610 perror "Could not resync from internal error (timeout)"
615 perror "Could not resync from internal error (resync count exceeded)"
620 # gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS
621 # Send a command to gdb; test the result.
623 # COMMAND is the command to execute, send to GDB with send_gdb. If
624 # this is the null string no command is sent.
625 # MESSAGE is a message to be printed with the built-in failure patterns
626 # if one of them matches. If MESSAGE is empty COMMAND will be used.
627 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
628 # patterns. Pattern elements will be evaluated in the caller's
629 # context; action elements will be executed in the caller's context.
630 # Unlike patterns for gdb_test, these patterns should generally include
631 # the final newline and prompt.
634 # 1 if the test failed, according to a built-in failure pattern
635 # 0 if only user-supplied patterns matched
636 # -1 if there was an internal error.
638 # You can use this function thus:
640 # gdb_test_multiple "print foo" "test foo" {
641 # -re "expected output 1" {
644 # -re "expected output 2" {
649 # The standard patterns, such as "Inferior exited..." and "A problem
650 # ...", all being implicitly appended to that list.
652 proc gdb_test_multiple { command message user_code } {
653 global verbose use_gdb_stub
654 global gdb_prompt pagination_prompt
656 global inferior_exited_re
657 upvar timeout timeout
658 upvar expect_out expect_out
660 if { $message == "" } {
664 if [string match "*\[\r\n\]" $command] {
665 error "Invalid trailing newline in \"$message\" test"
668 if [string match "*\[\r\n\]*" $message] {
669 error "Invalid newline in \"$message\" test"
673 && [regexp -nocase {^\s*(r|run|star|start|at|att|atta|attac|attach)\M} \
675 error "gdbserver does not support $command without extended-remote"
678 # TCL/EXPECT WART ALERT
679 # Expect does something very strange when it receives a single braced
680 # argument. It splits it along word separators and performs substitutions.
681 # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
682 # evaluated as "\[ab\]". But that's not how TCL normally works; inside a
683 # double-quoted list item, "\[ab\]" is just a long way of representing
684 # "[ab]", because the backslashes will be removed by lindex.
686 # Unfortunately, there appears to be no easy way to duplicate the splitting
687 # that expect will do from within TCL. And many places make use of the
688 # "\[0-9\]" construct, so we need to support that; and some places make use
689 # of the "[func]" construct, so we need to support that too. In order to
690 # get this right we have to substitute quoted list elements differently
691 # from braced list elements.
693 # We do this roughly the same way that Expect does it. We have to use two
694 # lists, because if we leave unquoted newlines in the argument to uplevel
695 # they'll be treated as command separators, and if we escape newlines
696 # we mangle newlines inside of command blocks. This assumes that the
697 # input doesn't contain a pattern which contains actual embedded newlines
700 regsub -all {\n} ${user_code} { } subst_code
701 set subst_code [uplevel list $subst_code]
703 set processed_code ""
705 set expecting_action 0
707 foreach item $user_code subst_item $subst_code {
708 if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } {
709 lappend processed_code $item
712 if { $item == "-indices" || $item == "-re" || $item == "-ex" } {
713 lappend processed_code $item
716 if { $item == "-timeout" } {
718 lappend processed_code $item
721 if { $expecting_arg } {
723 lappend processed_code $item
726 if { $expecting_action } {
727 lappend processed_code "uplevel [list $item]"
728 set expecting_action 0
729 # Cosmetic, no effect on the list.
730 append processed_code "\n"
733 set expecting_action 1
734 lappend processed_code $subst_item
735 if {$patterns != ""} {
738 append patterns "\"$subst_item\""
741 # Also purely cosmetic.
742 regsub -all {\r} $patterns {\\r} patterns
743 regsub -all {\n} $patterns {\\n} patterns
746 send_user "Sending \"$command\" to gdb\n"
747 send_user "Looking to match \"$patterns\"\n"
748 send_user "Message is \"$message\"\n"
752 set string "${command}\n"
753 if { $command != "" } {
754 set multi_line_re "\[\r\n\] *>"
755 while { "$string" != "" } {
756 set foo [string first "\n" "$string"]
757 set len [string length "$string"]
758 if { $foo < [expr $len - 1] } {
759 set str [string range "$string" 0 $foo]
760 if { [send_gdb "$str"] != "" } {
763 if { ! $suppress_flag } {
764 perror "Couldn't send $command to GDB."
769 # since we're checking if each line of the multi-line
770 # command are 'accepted' by GDB here,
771 # we need to set -notransfer expect option so that
772 # command output is not lost for pattern matching
775 -notransfer -re "$multi_line_re$" { verbose "partial: match" 3 }
776 timeout { verbose "partial: timeout" 3 }
778 set string [string range "$string" [expr $foo + 1] end]
779 set multi_line_re "$multi_line_re.*\[\r\n\] *>"
784 if { "$string" != "" } {
785 if { [send_gdb "$string"] != "" } {
788 if { ! $suppress_flag } {
789 perror "Couldn't send $command to GDB."
798 -re ".*A problem internal to GDB has been detected" {
799 fail "$message (GDB internal error)"
800 gdb_internal_error_resync
802 -re "\\*\\*\\* DOSEXIT code.*" {
803 if { $message != "" } {
806 gdb_suppress_entire_file "GDB died"
810 append code $processed_code
812 -re "Ending remote debugging.*$gdb_prompt $" {
813 if ![isnative] then {
814 warning "Can`t communicate to remote target."
820 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
821 perror "Undefined command \"$command\"."
825 -re "Ambiguous command.*$gdb_prompt $" {
826 perror "\"$command\" is not a unique command name."
830 -re "$inferior_exited_re with code \[0-9\]+.*$gdb_prompt $" {
831 if ![string match "" $message] then {
832 set errmsg "$message (the program exited)"
834 set errmsg "$command (the program exited)"
839 -re "$inferior_exited_re normally.*$gdb_prompt $" {
840 if ![string match "" $message] then {
841 set errmsg "$message (the program exited)"
843 set errmsg "$command (the program exited)"
848 -re "The program is not being run.*$gdb_prompt $" {
849 if ![string match "" $message] then {
850 set errmsg "$message (the program is no longer running)"
852 set errmsg "$command (the program is no longer running)"
857 -re "\r\n$gdb_prompt $" {
858 if ![string match "" $message] then {
863 -re "$pagination_prompt" {
865 perror "Window too small."
869 -re "\\((y or n|y or \\\[n\\\]|\\\[y\\\] or n)\\) " {
871 gdb_expect -re "$gdb_prompt $"
872 fail "$message (got interactive prompt)"
875 -re "\\\[0\\\] cancel\r\n\\\[1\\\] all.*\r\n> $" {
877 gdb_expect -re "$gdb_prompt $"
878 fail "$message (got breakpoint menu)"
882 perror "Process no longer exists"
883 if { $message != "" } {
889 perror "internal buffer is full."
894 if ![string match "" $message] then {
895 fail "$message (timeout)"
902 set code [catch {gdb_expect $code} string]
904 global errorInfo errorCode
905 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
906 } elseif {$code > 1} {
907 return -code $code $string
912 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
913 # Send a command to gdb; test the result.
915 # COMMAND is the command to execute, send to GDB with send_gdb. If
916 # this is the null string no command is sent.
917 # PATTERN is the pattern to match for a PASS, and must NOT include
918 # the \r\n sequence immediately before the gdb prompt.
919 # MESSAGE is an optional message to be printed. If this is
920 # omitted, then the pass/fail messages use the command string as the
921 # message. (If this is the empty string, then sometimes we don't
922 # call pass or fail at all; I don't understand this at all.)
923 # QUESTION is a question GDB may ask in response to COMMAND, like
925 # RESPONSE is the response to send if QUESTION appears.
928 # 1 if the test failed,
929 # 0 if the test passes,
930 # -1 if there was an internal error.
932 proc gdb_test { args } {
936 upvar timeout timeout
938 if [llength $args]>2 then {
939 set message [lindex $args 2]
941 set message [lindex $args 0]
943 set command [lindex $args 0]
944 set pattern [lindex $args 1]
946 if [llength $args]==5 {
947 set question_string [lindex $args 3]
948 set response_string [lindex $args 4]
950 set question_string "^FOOBAR$"
953 return [gdb_test_multiple $command $message {
954 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
955 if ![string match "" $message] then {
959 -re "(${question_string})$" {
960 send_gdb "$response_string\n"
966 # gdb_test_no_output COMMAND MESSAGE
967 # Send a command to GDB and verify that this command generated no output.
969 # See gdb_test_multiple for a description of the COMMAND and MESSAGE
970 # parameters. If MESSAGE is ommitted, then COMMAND will be used as
971 # the message. (If MESSAGE is the empty string, then sometimes we do not
972 # call pass or fail at all; I don't understand this at all.)
974 proc gdb_test_no_output { args } {
976 set command [lindex $args 0]
977 if [llength $args]>1 then {
978 set message [lindex $args 1]
983 set command_regex [string_to_regexp $command]
984 gdb_test_multiple $command $message {
985 -re "^$command_regex\r\n$gdb_prompt $" {
986 if ![string match "" $message] then {
993 # Send a command and then wait for a sequence of outputs.
994 # This is useful when the sequence is long and contains ".*", a single
995 # regexp to match the entire output can get a timeout much easier.
997 # COMMAND is the command to send.
998 # TEST_NAME is passed to pass/fail. COMMAND is used if TEST_NAME is "".
999 # EXPECTED_OUTPUT_LIST is a list of regexps of expected output, which are
1000 # processed in order, and all must be present in the output.
1002 # It is unnecessary to specify ".*" at the beginning or end of any regexp,
1003 # there is an implicit ".*" between each element of EXPECTED_OUTPUT_LIST.
1004 # There is also an implicit ".*" between the last regexp and the gdb prompt.
1006 # Like gdb_test and gdb_test_multiple, the output is expected to end with the
1007 # gdb prompt, which must not be specified in EXPECTED_OUTPUT_LIST.
1010 # 1 if the test failed,
1011 # 0 if the test passes,
1012 # -1 if there was an internal error.
1014 proc gdb_test_sequence { command test_name expected_output_list } {
1016 if { $test_name == "" } {
1017 set test_name $command
1019 lappend expected_output_list ""; # implicit ".*" before gdb prompt
1020 send_gdb "$command\n"
1021 return [gdb_expect_list $test_name "$gdb_prompt $" $expected_output_list]
1025 # Test that a command gives an error. For pass or fail, return
1026 # a 1 to indicate that more tests can proceed. However a timeout
1027 # is a serious error, generates a special fail message, and causes
1028 # a 0 to be returned to indicate that more tests are likely to fail
1031 proc test_print_reject { args } {
1035 if [llength $args]==2 then {
1036 set expectthis [lindex $args 1]
1038 set expectthis "should never match this bogus string"
1040 set sendthis [lindex $args 0]
1041 if $verbose>2 then {
1042 send_user "Sending \"$sendthis\" to gdb\n"
1043 send_user "Looking to match \"$expectthis\"\n"
1045 send_gdb "$sendthis\n"
1046 #FIXME: Should add timeout as parameter.
1048 -re "A .* in expression.*\\.*$gdb_prompt $" {
1049 pass "reject $sendthis"
1052 -re "Invalid syntax in expression.*$gdb_prompt $" {
1053 pass "reject $sendthis"
1056 -re "Junk after end of expression.*$gdb_prompt $" {
1057 pass "reject $sendthis"
1060 -re "Invalid number.*$gdb_prompt $" {
1061 pass "reject $sendthis"
1064 -re "Invalid character constant.*$gdb_prompt $" {
1065 pass "reject $sendthis"
1068 -re "No symbol table is loaded.*$gdb_prompt $" {
1069 pass "reject $sendthis"
1072 -re "No symbol .* in current context.*$gdb_prompt $" {
1073 pass "reject $sendthis"
1076 -re "Unmatched single quote.*$gdb_prompt $" {
1077 pass "reject $sendthis"
1080 -re "A character constant must contain at least one character.*$gdb_prompt $" {
1081 pass "reject $sendthis"
1084 -re "$expectthis.*$gdb_prompt $" {
1085 pass "reject $sendthis"
1088 -re ".*$gdb_prompt $" {
1089 fail "reject $sendthis"
1093 fail "reject $sendthis (eof or timeout)"
1100 # Same as gdb_test, but the second parameter is not a regexp,
1101 # but a string that must match exactly.
1103 proc gdb_test_exact { args } {
1104 upvar timeout timeout
1106 set command [lindex $args 0]
1108 # This applies a special meaning to a null string pattern. Without
1109 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
1110 # messages from commands that should have no output except a new
1111 # prompt. With this, only results of a null string will match a null
1114 set pattern [lindex $args 1]
1115 if [string match $pattern ""] {
1116 set pattern [string_to_regexp [lindex $args 0]]
1118 set pattern [string_to_regexp [lindex $args 1]]
1121 # It is most natural to write the pattern argument with only
1122 # embedded \n's, especially if you are trying to avoid Tcl quoting
1123 # problems. But gdb_expect really wants to see \r\n in patterns. So
1124 # transform the pattern here. First transform \r\n back to \n, in
1125 # case some users of gdb_test_exact already do the right thing.
1126 regsub -all "\r\n" $pattern "\n" pattern
1127 regsub -all "\n" $pattern "\r\n" pattern
1128 if [llength $args]==3 then {
1129 set message [lindex $args 2]
1131 set message $command
1134 return [gdb_test $command $pattern $message]
1137 # Wrapper around gdb_test_multiple that looks for a list of expected
1138 # output elements, but which can appear in any order.
1139 # CMD is the gdb command.
1140 # NAME is the name of the test.
1141 # ELM_FIND_REGEXP specifies how to partition the output into elements to
1143 # ELM_EXTRACT_REGEXP specifies the part of ELM_FIND_REGEXP to compare.
1144 # RESULT_MATCH_LIST is a list of exact matches for each expected element.
1145 # All elements of RESULT_MATCH_LIST must appear for the test to pass.
1147 # A typical use of ELM_FIND_REGEXP/ELM_EXTRACT_REGEXP is to extract one line
1148 # of text per element and then strip trailing \r\n's.
1150 # gdb_test_list_exact "foo" "bar" \
1151 # "\[^\r\n\]+\[\r\n\]+" \
1154 # {expected result 1} \
1155 # {expected result 2} \
1158 proc gdb_test_list_exact { cmd name elm_find_regexp elm_extract_regexp result_match_list } {
1161 set matches [lsort $result_match_list]
1163 gdb_test_multiple $cmd $name {
1164 "$cmd\[\r\n\]" { exp_continue }
1165 -re $elm_find_regexp {
1166 set str $expect_out(0,string)
1167 verbose -log "seen: $str" 3
1168 regexp -- $elm_extract_regexp $str elm_seen
1169 verbose -log "extracted: $elm_seen" 3
1170 lappend seen $elm_seen
1173 -re "$gdb_prompt $" {
1175 foreach got [lsort $seen] have $matches {
1176 if {![string equal $got $have]} {
1181 if {[string length $failed] != 0} {
1182 fail "$name ($failed not found)"
1191 # Issue a PASS and return true if evaluating CONDITION in the caller's
1192 # frame returns true, and issue a FAIL and return false otherwise.
1193 # MESSAGE is the pass/fail message to be printed. If MESSAGE is
1194 # omitted or is empty, then the pass/fail messages use the condition
1195 # string as the message.
1197 proc gdb_assert { condition {message ""} } {
1198 if { $message == ""} {
1199 set message $condition
1202 set res [uplevel 1 expr $condition]
1211 proc gdb_reinitialize_dir { subdir } {
1214 if [is_remote host] {
1219 -re "Reinitialize source path to empty.*y or n. " {
1222 -re "Source directories searched.*$gdb_prompt $" {
1223 send_gdb "dir $subdir\n"
1225 -re "Source directories searched.*$gdb_prompt $" {
1226 verbose "Dir set to $subdir"
1228 -re "$gdb_prompt $" {
1229 perror "Dir \"$subdir\" failed."
1233 -re "$gdb_prompt $" {
1234 perror "Dir \"$subdir\" failed."
1238 -re "$gdb_prompt $" {
1239 perror "Dir \"$subdir\" failed."
1245 # gdb_exit -- exit the GDB, killing the target program if necessary
1247 proc default_gdb_exit {} {
1249 global INTERNAL_GDBFLAGS GDBFLAGS
1252 global inotify_log_file
1254 gdb_stop_suppressing_tests
1256 if ![info exists gdb_spawn_id] {
1260 verbose "Quitting $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1262 if {[info exists inotify_log_file] && [file exists $inotify_log_file]} {
1263 set fd [open $inotify_log_file]
1264 set data [read -nonewline $fd]
1267 if {[string compare $data ""] != 0} {
1268 warning "parallel-unsafe file creations noticed"
1271 set fd [open $inotify_log_file w]
1276 if { [is_remote host] && [board_info host exists fileid] } {
1283 -re "DOSEXIT code" { }
1288 if ![is_remote host] {
1294 # Load a file into the debugger.
1295 # The return value is 0 for success, -1 for failure.
1297 # This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO
1298 # to one of these values:
1300 # debug file was loaded successfully and has debug information
1301 # nodebug file was loaded successfully and has no debug information
1302 # lzma file was loaded, .gnu_debugdata found, but no LZMA support
1304 # fail file was not loaded
1306 # I tried returning this information as part of the return value,
1307 # but ran into a mess because of the many re-implementations of
1308 # gdb_load in config/*.exp.
1310 # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use
1311 # this if they can get more information set.
1313 proc gdb_file_cmd { arg } {
1317 global last_loaded_file
1319 # Save this for the benefit of gdbserver-support.exp.
1320 set last_loaded_file $arg
1322 # Set whether debug info was found.
1323 # Default to "fail".
1324 global gdb_file_cmd_debug_info
1325 set gdb_file_cmd_debug_info "fail"
1327 if [is_remote host] {
1328 set arg [remote_download host $arg]
1330 perror "download failed"
1335 # The file command used to kill the remote target. For the benefit
1336 # of the testsuite, preserve this behavior.
1339 -re "Kill the program being debugged. .y or n. $" {
1341 verbose "\t\tKilling previous program being debugged"
1344 -re "$gdb_prompt $" {
1349 send_gdb "file $arg\n"
1351 -re "Reading symbols from.*LZMA support was disabled.*done.*$gdb_prompt $" {
1352 verbose "\t\tLoaded $arg into $GDB; .gnu_debugdata found but no LZMA available"
1353 set gdb_file_cmd_debug_info "lzma"
1356 -re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" {
1357 verbose "\t\tLoaded $arg into $GDB with no debugging symbols"
1358 set gdb_file_cmd_debug_info "nodebug"
1361 -re "Reading symbols from.*done.*$gdb_prompt $" {
1362 verbose "\t\tLoaded $arg into $GDB"
1363 set gdb_file_cmd_debug_info "debug"
1366 -re "Load new symbol table from \".*\".*y or n. $" {
1369 -re "Reading symbols from.*done.*$gdb_prompt $" {
1370 verbose "\t\tLoaded $arg with new symbol table into $GDB"
1371 set gdb_file_cmd_debug_info "debug"
1375 perror "Couldn't load $arg, other program already loaded (timeout)."
1379 perror "Couldn't load $arg, other program already loaded (eof)."
1384 -re "No such file or directory.*$gdb_prompt $" {
1385 perror "($arg) No such file or directory"
1388 -re "A problem internal to GDB has been detected" {
1389 fail "($arg) (GDB internal error)"
1390 gdb_internal_error_resync
1393 -re "$gdb_prompt $" {
1394 perror "Couldn't load $arg into $GDB."
1398 perror "Couldn't load $arg into $GDB (timeout)."
1402 # This is an attempt to detect a core dump, but seems not to
1403 # work. Perhaps we need to match .* followed by eof, in which
1404 # gdb_expect does not seem to have a way to do that.
1405 perror "Couldn't load $arg into $GDB (eof)."
1411 # Default gdb_spawn procedure.
1413 proc default_gdb_spawn { } {
1416 global INTERNAL_GDBFLAGS GDBFLAGS
1419 gdb_stop_suppressing_tests
1421 # Set the default value, it may be overriden later by specific testfile.
1423 # Use `set_board_info use_gdb_stub' for the board file to flag the inferior
1424 # is already started after connecting and run/attach are not supported.
1425 # This is used for the "remote" protocol. After GDB starts you should
1426 # check global $use_gdb_stub instead of the board as the testfile may force
1427 # a specific different target protocol itself.
1428 set use_gdb_stub [target_info exists use_gdb_stub]
1430 verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1432 if [info exists gdb_spawn_id] {
1436 if ![is_remote host] {
1437 if { [which $GDB] == 0 } then {
1438 perror "$GDB does not exist."
1442 set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"]
1443 if { $res < 0 || $res == "" } {
1444 perror "Spawning $GDB failed."
1451 # Default gdb_start procedure.
1453 proc default_gdb_start { } {
1457 if [info exists gdb_spawn_id] {
1466 # When running over NFS, particularly if running many simultaneous
1467 # tests on different hosts all using the same server, things can
1468 # get really slow. Give gdb at least 3 minutes to start up.
1470 -re "\[\r\n\]$gdb_prompt $" {
1471 verbose "GDB initialized."
1473 -re "$gdb_prompt $" {
1474 perror "GDB never initialized."
1479 perror "(timeout) GDB never initialized after 10 seconds."
1486 # force the height to "unlimited", so no pagers get used
1488 send_gdb "set height 0\n"
1490 -re "$gdb_prompt $" {
1491 verbose "Setting height to 0." 2
1494 warning "Couldn't set the height to 0"
1497 # force the width to "unlimited", so no wraparound occurs
1498 send_gdb "set width 0\n"
1500 -re "$gdb_prompt $" {
1501 verbose "Setting width to 0." 2
1504 warning "Couldn't set the width to 0."
1510 # Examine the output of compilation to determine whether compilation
1511 # failed or not. If it failed determine whether it is due to missing
1512 # compiler or due to compiler error. Report pass, fail or unsupported
1515 proc gdb_compile_test {src output} {
1516 if { $output == "" } {
1517 pass "compilation [file tail $src]"
1518 } elseif { [regexp {^[a-zA-Z_0-9]+: Can't find [^ ]+\.$} $output] } {
1519 unsupported "compilation [file tail $src]"
1520 } elseif { [regexp {.*: command not found[\r|\n]*$} $output] } {
1521 unsupported "compilation [file tail $src]"
1522 } elseif { [regexp {.*: [^\r\n]*compiler not installed[^\r\n]*[\r|\n]*$} $output] } {
1523 unsupported "compilation [file tail $src]"
1525 verbose -log "compilation failed: $output" 2
1526 fail "compilation [file tail $src]"
1530 # Return a 1 for configurations for which we don't even want to try to
1533 proc skip_cplus_tests {} {
1534 if { [istarget "h8300-*-*"] } {
1538 # The C++ IO streams are too large for HC11/HC12 and are thus not
1539 # available. The gdb C++ tests use them and don't compile.
1540 if { [istarget "m6811-*-*"] } {
1543 if { [istarget "m6812-*-*"] } {
1549 # Return a 1 for configurations for which don't have both C++ and the STL.
1551 proc skip_stl_tests {} {
1552 # Symbian supports the C++ language, but the STL is missing
1553 # (both headers and libraries).
1554 if { [istarget "arm*-*-symbianelf*"] } {
1558 return [skip_cplus_tests]
1561 # Return a 1 if I don't even want to try to test FORTRAN.
1563 proc skip_fortran_tests {} {
1567 # Return a 1 if I don't even want to try to test ada.
1569 proc skip_ada_tests {} {
1573 # Return a 1 if I don't even want to try to test GO.
1575 proc skip_go_tests {} {
1579 # Return a 1 if I don't even want to try to test java.
1581 proc skip_java_tests {} {
1585 # Return a 1 if I don't even want to try to test D.
1587 proc skip_d_tests {} {
1591 # Return a 1 for configurations that do not support Python scripting.
1593 proc skip_python_tests {} {
1595 global gdb_py_is_py3k
1596 global gdb_py_is_py24
1598 gdb_test_multiple "python print ('test')" "verify python support" {
1599 -re "not supported.*$gdb_prompt $" {
1600 unsupported "Python support is disabled."
1603 -re "$gdb_prompt $" {}
1606 set gdb_py_is_py24 0
1607 gdb_test_multiple "python print (sys.version_info\[0\])" "check if python 3" {
1608 -re "3.*$gdb_prompt $" {
1609 set gdb_py_is_py3k 1
1611 -re ".*$gdb_prompt $" {
1612 set gdb_py_is_py3k 0
1615 if { $gdb_py_is_py3k == 0 } {
1616 gdb_test_multiple "python print (sys.version_info\[1\])" "check if python 2.4" {
1617 -re "\[45\].*$gdb_prompt $" {
1618 set gdb_py_is_py24 1
1620 -re ".*$gdb_prompt $" {
1621 set gdb_py_is_py24 0
1629 # Return a 1 if we should skip shared library tests.
1631 proc skip_shlib_tests {} {
1632 # Run the shared library tests on native systems.
1637 # An abbreviated list of remote targets where we should be able to
1638 # run shared library tests.
1639 if {([istarget *-*-linux*]
1640 || [istarget *-*-*bsd*]
1641 || [istarget *-*-solaris2*]
1642 || [istarget arm*-*-symbianelf*]
1643 || [istarget *-*-mingw*]
1644 || [istarget *-*-cygwin*]
1645 || [istarget *-*-pe*])} {
1652 # Test files shall make sure all the test result lines in gdb.sum are
1653 # unique in a test run, so that comparing the gdb.sum files of two
1654 # test runs gives correct results. Test files that exercise
1655 # variations of the same tests more than once, shall prefix the
1656 # different test invocations with different identifying strings in
1657 # order to make them unique.
1659 # About test prefixes:
1661 # $pf_prefix is the string that dejagnu prints after the result (FAIL,
1662 # PASS, etc.), and before the test message/name in gdb.sum. E.g., the
1663 # underlined substring in
1665 # PASS: gdb.base/mytest.exp: some test
1666 # ^^^^^^^^^^^^^^^^^^^^
1670 # The easiest way to adjust the test prefix is to append a test
1671 # variation prefix to the $pf_prefix, using the with_test_prefix
1674 # proc do_tests {} {
1675 # gdb_test ... ... "test foo"
1676 # gdb_test ... ... "test bar"
1678 # with_test_prefix "subvariation a" {
1679 # gdb_test ... ... "test x"
1682 # with_test_prefix "subvariation b" {
1683 # gdb_test ... ... "test x"
1687 # with_test_prefix "variation1" {
1688 # ...do setup for variation 1...
1692 # with_test_prefix "variation2" {
1693 # ...do setup for variation 2...
1699 # PASS: gdb.base/mytest.exp: variation1: test foo
1700 # PASS: gdb.base/mytest.exp: variation1: test bar
1701 # PASS: gdb.base/mytest.exp: variation1: subvariation a: test x
1702 # PASS: gdb.base/mytest.exp: variation1: subvariation b: test x
1703 # PASS: gdb.base/mytest.exp: variation2: test foo
1704 # PASS: gdb.base/mytest.exp: variation2: test bar
1705 # PASS: gdb.base/mytest.exp: variation2: subvariation a: test x
1706 # PASS: gdb.base/mytest.exp: variation2: subvariation b: test x
1708 # If for some reason more flexibility is necessary, one can also
1709 # manipulate the pf_prefix global directly, treating it as a string.
1713 # set saved_pf_prefix
1714 # append pf_prefix "${foo}: bar"
1715 # ... actual tests ...
1716 # set pf_prefix $saved_pf_prefix
1719 # Run BODY in the context of the caller, with the current test prefix
1720 # (pf_prefix) appended with one space, then PREFIX, and then a colon.
1721 # Returns the result of BODY.
1723 proc with_test_prefix { prefix body } {
1726 set saved $pf_prefix
1727 append pf_prefix " " $prefix ":"
1728 set code [catch {uplevel 1 $body} result]
1729 set pf_prefix $saved
1732 global errorInfo errorCode
1733 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
1735 return -code $code $result
1739 # Run tests in BODY with GDB prompt and variable $gdb_prompt set to
1740 # PROMPT. When BODY is finished, restore GDB prompt and variable
1742 # Returns the result of BODY.
1746 # 1) If you want to use, for example, "(foo)" as the prompt you must pass it
1747 # as "(foo)", and not the regexp form "\(foo\)" (expressed as "\\(foo\\)" in
1748 # TCL). PROMPT is internally converted to a suitable regexp for matching.
1749 # We do the conversion from "(foo)" to "\(foo\)" here for a few reasons:
1750 # a) It's more intuitive for callers to pass the plain text form.
1751 # b) We need two forms of the prompt:
1752 # - a regexp to use in output matching,
1753 # - a value to pass to the "set prompt" command.
1754 # c) It's easier to convert the plain text form to its regexp form.
1756 # 2) Don't add a trailing space, we do that here.
1758 proc with_gdb_prompt { prompt body } {
1761 # Convert "(foo)" to "\(foo\)".
1762 # We don't use string_to_regexp because while it works today it's not
1763 # clear it will work tomorrow: the value we need must work as both a
1764 # regexp *and* as the argument to the "set prompt" command, at least until
1765 # we start recording both forms separately instead of just $gdb_prompt.
1766 # The testsuite is pretty-much hardwired to interpret $gdb_prompt as the
1768 regsub -all {[]*+.|()^$\[\\]} $prompt {\\&} prompt
1770 set saved $gdb_prompt
1772 verbose -log "Setting gdb prompt to \"$prompt \"."
1773 set gdb_prompt $prompt
1774 gdb_test_no_output "set prompt $prompt " ""
1776 set code [catch {uplevel 1 $body} result]
1778 verbose -log "Restoring gdb prompt to \"$saved \"."
1779 set gdb_prompt $saved
1780 gdb_test_no_output "set prompt $saved " ""
1783 global errorInfo errorCode
1784 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
1786 return -code $code $result
1790 # Run tests in BODY with target-charset setting to TARGET_CHARSET. When
1791 # BODY is finished, restore target-charset.
1793 proc with_target_charset { target_charset body } {
1797 gdb_test_multiple "show target-charset" "" {
1798 -re "The target character set is \".*; currently (.*)\"\..*$gdb_prompt " {
1799 set saved $expect_out(1,string)
1801 -re "The target character set is \"(.*)\".*$gdb_prompt " {
1802 set saved $expect_out(1,string)
1804 -re ".*$gdb_prompt " {
1805 fail "get target-charset"
1809 gdb_test_no_output "set target-charset $target_charset" ""
1811 set code [catch {uplevel 1 $body} result]
1813 gdb_test_no_output "set target-charset $saved" ""
1816 global errorInfo errorCode
1817 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
1819 return -code $code $result
1823 # Return 1 if _Complex types are supported, otherwise, return 0.
1825 gdb_caching_proc support_complex_tests {
1826 # Set up, compile, and execute a test program containing _Complex types.
1827 # Include the current process ID in the file names to prevent conflicts
1828 # with invocations for multiple testsuites.
1829 set src [standard_temp_file complex[pid].c]
1830 set exe [standard_temp_file complex[pid].x]
1832 gdb_produce_source $src {
1836 _Complex long double cld;
1841 verbose "compiling testfile $src" 2
1842 set compile_flags {debug nowarnings quiet}
1843 set lines [gdb_compile $src $exe executable $compile_flags]
1847 if ![string match "" $lines] then {
1848 verbose "testfile compilation failed, returning 0" 2
1857 # Return 1 if target hardware or OS supports single stepping to signal
1858 # handler, otherwise, return 0.
1860 proc can_single_step_to_signal_handler {} {
1862 # Targets don't have hardware single step. On these targets, when
1863 # a signal is delivered during software single step, gdb is unable
1864 # to determine the next instruction addresses, because start of signal
1865 # handler is one of them.
1866 if { [istarget "arm*-*-*"] || [istarget "mips*-*-*"]
1867 || [istarget "tic6x-*-*"] || [istarget "sparc*-*-linux*"]
1868 || [istarget "nios2-*-*"] } {
1875 # Return 1 if target supports process record, otherwise return 0.
1877 proc supports_process_record {} {
1879 if [target_info exists gdb,use_precord] {
1880 return [target_info gdb,use_precord]
1883 if { [istarget "arm*-*-linux*"] || [istarget "x86_64-*-linux*"]
1884 || [istarget "i\[34567\]86-*-linux*"] } {
1891 # Return 1 if target supports reverse debugging, otherwise return 0.
1893 proc supports_reverse {} {
1895 if [target_info exists gdb,can_reverse] {
1896 return [target_info gdb,can_reverse]
1899 if { [istarget "arm*-*-linux*"] || [istarget "x86_64-*-linux*"]
1900 || [istarget "i\[34567\]86-*-linux*"] } {
1907 # Return 1 if readline library is used.
1909 proc readline_is_used { } {
1912 gdb_test_multiple "show editing" "" {
1913 -re ".*Editing of command lines as they are typed is on\..*$gdb_prompt $" {
1916 -re ".*$gdb_prompt $" {
1922 # Return 1 if target is ELF.
1923 gdb_caching_proc is_elf_target {
1924 set me "is_elf_target"
1926 set src [standard_temp_file is_elf_target[pid].c]
1927 set obj [standard_temp_file is_elf_target[pid].o]
1929 gdb_produce_source $src {
1930 int foo () {return 0;}
1933 verbose "$me: compiling testfile $src" 2
1934 set lines [gdb_compile $src $obj object {quiet}]
1938 if ![string match "" $lines] then {
1939 verbose "$me: testfile compilation failed, returning 0" 2
1943 set fp_obj [open $obj "r"]
1944 fconfigure $fp_obj -translation binary
1945 set data [read $fp_obj]
1950 set ELFMAG "\u007FELF"
1952 if {[string compare -length 4 $data $ELFMAG] != 0} {
1953 verbose "$me: returning 0" 2
1957 verbose "$me: returning 1" 2
1961 # Return 1 if the memory at address zero is readable.
1963 gdb_caching_proc is_address_zero_readable {
1967 gdb_test_multiple "x 0" "" {
1968 -re "Cannot access memory at address 0x0.*$gdb_prompt $" {
1971 -re ".*$gdb_prompt $" {
1979 # Produce source file NAME and write SOURCES into it.
1981 proc gdb_produce_source { name sources } {
1983 set f [open $name "w"]
1989 # Return 1 if target is ILP32.
1990 # This cannot be decided simply from looking at the target string,
1991 # as it might depend on externally passed compiler options like -m64.
1992 gdb_caching_proc is_ilp32_target {
1993 set me "is_ilp32_target"
1995 set src [standard_temp_file ilp32[pid].c]
1996 set obj [standard_temp_file ilp32[pid].o]
1998 gdb_produce_source $src {
1999 int dummy[sizeof (int) == 4
2000 && sizeof (void *) == 4
2001 && sizeof (long) == 4 ? 1 : -1];
2004 verbose "$me: compiling testfile $src" 2
2005 set lines [gdb_compile $src $obj object {quiet}]
2009 if ![string match "" $lines] then {
2010 verbose "$me: testfile compilation failed, returning 0" 2
2014 verbose "$me: returning 1" 2
2018 # Return 1 if target is LP64.
2019 # This cannot be decided simply from looking at the target string,
2020 # as it might depend on externally passed compiler options like -m64.
2021 gdb_caching_proc is_lp64_target {
2022 set me "is_lp64_target"
2024 set src [standard_temp_file lp64[pid].c]
2025 set obj [standard_temp_file lp64[pid].o]
2027 gdb_produce_source $src {
2028 int dummy[sizeof (int) == 4
2029 && sizeof (void *) == 8
2030 && sizeof (long) == 8 ? 1 : -1];
2033 verbose "$me: compiling testfile $src" 2
2034 set lines [gdb_compile $src $obj object {quiet}]
2038 if ![string match "" $lines] then {
2039 verbose "$me: testfile compilation failed, returning 0" 2
2043 verbose "$me: returning 1" 2
2047 # Return 1 if target has 64 bit addresses.
2048 # This cannot be decided simply from looking at the target string,
2049 # as it might depend on externally passed compiler options like -m64.
2050 gdb_caching_proc is_64_target {
2051 set me "is_64_target"
2053 set src [standard_temp_file is64[pid].c]
2054 set obj [standard_temp_file is64[pid].o]
2056 gdb_produce_source $src {
2057 int function(void) { return 3; }
2058 int dummy[sizeof (&function) == 8 ? 1 : -1];
2061 verbose "$me: compiling testfile $src" 2
2062 set lines [gdb_compile $src $obj object {quiet}]
2066 if ![string match "" $lines] then {
2067 verbose "$me: testfile compilation failed, returning 0" 2
2071 verbose "$me: returning 1" 2
2075 # Return 1 if target has x86_64 registers - either amd64 or x32.
2076 # x32 target identifies as x86_64-*-linux*, therefore it cannot be determined
2077 # just from the target string.
2078 gdb_caching_proc is_amd64_regs_target {
2079 if {![istarget "x86_64-*-*"] && ![istarget "i?86-*"]} {
2083 set me "is_amd64_regs_target"
2085 set src [standard_temp_file reg64[pid].s]
2086 set obj [standard_temp_file reg64[pid].o]
2090 {rax rbx rcx rdx rsi rdi rbp rsp r8 r9 r10 r11 r12 r13 r14 r15} {
2091 lappend list "\tincq %$reg"
2093 gdb_produce_source $src [join $list \n]
2095 verbose "$me: compiling testfile $src" 2
2096 set lines [gdb_compile $src $obj object {quiet}]
2100 if ![string match "" $lines] then {
2101 verbose "$me: testfile compilation failed, returning 0" 2
2105 verbose "$me: returning 1" 2
2109 # Return 1 if this target is an x86 or x86-64 with -m32.
2110 proc is_x86_like_target {} {
2111 if {![istarget "x86_64-*-*"] && ![istarget i?86-*]} {
2114 return [expr [is_ilp32_target] && ![is_amd64_regs_target]]
2117 # Return 1 if displaced stepping is supported on target, otherwise, return 0.
2118 proc support_displaced_stepping {} {
2120 if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"]
2121 || [istarget "arm*-*-linux*"] || [istarget "powerpc-*-linux*"]
2122 || [istarget "powerpc64-*-linux*"] || [istarget "s390*-*-*"] } {
2129 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
2130 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
2132 gdb_caching_proc skip_altivec_tests {
2133 global srcdir subdir gdb_prompt inferior_exited_re
2135 set me "skip_altivec_tests"
2137 # Some simulators are known to not support VMX instructions.
2138 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
2139 verbose "$me: target known to not support VMX, returning 1" 2
2143 # Make sure we have a compiler that understands altivec.
2144 set compile_flags {debug nowarnings}
2145 if [get_compiler_info] {
2146 warning "Could not get compiler info"
2149 if [test_compiler_info gcc*] {
2150 set compile_flags "$compile_flags additional_flags=-maltivec"
2151 } elseif [test_compiler_info xlc*] {
2152 set compile_flags "$compile_flags additional_flags=-qaltivec"
2154 verbose "Could not compile with altivec support, returning 1" 2
2158 # Set up, compile, and execute a test program containing VMX instructions.
2159 # Include the current process ID in the file names to prevent conflicts
2160 # with invocations for multiple testsuites.
2161 set src [standard_temp_file vmx[pid].c]
2162 set exe [standard_temp_file vmx[pid].x]
2164 gdb_produce_source $src {
2167 asm volatile ("vor v0,v0,v0");
2169 asm volatile ("vor 0,0,0");
2175 verbose "$me: compiling testfile $src" 2
2176 set lines [gdb_compile $src $exe executable $compile_flags]
2179 if ![string match "" $lines] then {
2180 verbose "$me: testfile compilation failed, returning 1" 2
2184 # No error message, compilation succeeded so now run it via gdb.
2188 gdb_reinitialize_dir $srcdir/$subdir
2192 -re ".*Illegal instruction.*${gdb_prompt} $" {
2193 verbose -log "\n$me altivec hardware not detected"
2194 set skip_vmx_tests 1
2196 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
2197 verbose -log "\n$me: altivec hardware detected"
2198 set skip_vmx_tests 0
2201 warning "\n$me: default case taken"
2202 set skip_vmx_tests 1
2206 remote_file build delete $exe
2208 verbose "$me: returning $skip_vmx_tests" 2
2209 return $skip_vmx_tests
2212 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
2213 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
2215 gdb_caching_proc skip_vsx_tests {
2216 global srcdir subdir gdb_prompt inferior_exited_re
2218 set me "skip_vsx_tests"
2220 # Some simulators are known to not support Altivec instructions, so
2221 # they won't support VSX instructions as well.
2222 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
2223 verbose "$me: target known to not support VSX, returning 1" 2
2227 # Make sure we have a compiler that understands altivec.
2228 set compile_flags {debug nowarnings quiet}
2229 if [get_compiler_info] {
2230 warning "Could not get compiler info"
2233 if [test_compiler_info gcc*] {
2234 set compile_flags "$compile_flags additional_flags=-mvsx"
2235 } elseif [test_compiler_info xlc*] {
2236 set compile_flags "$compile_flags additional_flags=-qasm=gcc"
2238 verbose "Could not compile with vsx support, returning 1" 2
2242 set src [standard_temp_file vsx[pid].c]
2243 set exe [standard_temp_file vsx[pid].x]
2245 gdb_produce_source $src {
2247 double a[2] = { 1.0, 2.0 };
2249 asm volatile ("lxvd2x v0,v0,%[addr]" : : [addr] "r" (a));
2251 asm volatile ("lxvd2x 0,0,%[addr]" : : [addr] "r" (a));
2257 verbose "$me: compiling testfile $src" 2
2258 set lines [gdb_compile $src $exe executable $compile_flags]
2261 if ![string match "" $lines] then {
2262 verbose "$me: testfile compilation failed, returning 1" 2
2266 # No error message, compilation succeeded so now run it via gdb.
2270 gdb_reinitialize_dir $srcdir/$subdir
2274 -re ".*Illegal instruction.*${gdb_prompt} $" {
2275 verbose -log "\n$me VSX hardware not detected"
2276 set skip_vsx_tests 1
2278 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
2279 verbose -log "\n$me: VSX hardware detected"
2280 set skip_vsx_tests 0
2283 warning "\n$me: default case taken"
2284 set skip_vsx_tests 1
2288 remote_file build delete $exe
2290 verbose "$me: returning $skip_vsx_tests" 2
2291 return $skip_vsx_tests
2294 # Run a test on the target to see if it supports btrace hardware. Return 0 if so,
2295 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
2297 gdb_caching_proc skip_btrace_tests {
2298 global srcdir subdir gdb_prompt inferior_exited_re
2300 set me "skip_btrace_tests"
2301 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
2302 verbose "$me: target does not support btrace, returning 1" 2
2306 # Set up, compile, and execute a test program.
2307 # Include the current process ID in the file names to prevent conflicts
2308 # with invocations for multiple testsuites.
2309 set src [standard_temp_file btrace[pid].c]
2310 set exe [standard_temp_file btrace[pid].x]
2312 gdb_produce_source $src {
2313 int main(void) { return 0; }
2316 verbose "$me: compiling testfile $src" 2
2317 set compile_flags {debug nowarnings quiet}
2318 set lines [gdb_compile $src $exe executable $compile_flags]
2320 if ![string match "" $lines] then {
2321 verbose "$me: testfile compilation failed, returning 1" 2
2326 # No error message, compilation succeeded so now run it via gdb.
2330 gdb_reinitialize_dir $srcdir/$subdir
2337 # In case of an unexpected output, we return 2 as a fail value.
2338 set skip_btrace_tests 2
2339 gdb_test_multiple "record btrace" "check btrace support" {
2340 -re "You can't do that when your target is.*\r\n$gdb_prompt $" {
2341 set skip_btrace_tests 1
2343 -re "Target does not support branch tracing.*\r\n$gdb_prompt $" {
2344 set skip_btrace_tests 1
2346 -re "Could not enable branch tracing.*\r\n$gdb_prompt $" {
2347 set skip_btrace_tests 1
2349 -re "^record btrace\r\n$gdb_prompt $" {
2350 set skip_btrace_tests 0
2354 remote_file build delete $exe
2356 verbose "$me: returning $skip_btrace_tests" 2
2357 return $skip_btrace_tests
2360 # Skip all the tests in the file if you are not on an hppa running
2363 proc skip_hp_tests {} {
2364 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
2365 verbose "Skip hp tests is $skip_hp"
2369 # Return whether we should skip tests for showing inlined functions in
2370 # backtraces. Requires get_compiler_info and get_debug_format.
2372 proc skip_inline_frame_tests {} {
2373 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
2374 if { ! [test_debug_format "DWARF 2"] } {
2378 # GCC before 4.1 does not emit DW_AT_call_file / DW_AT_call_line.
2379 if { ([test_compiler_info "gcc-2-*"]
2380 || [test_compiler_info "gcc-3-*"]
2381 || [test_compiler_info "gcc-4-0-*"]) } {
2388 # Return whether we should skip tests for showing variables from
2389 # inlined functions. Requires get_compiler_info and get_debug_format.
2391 proc skip_inline_var_tests {} {
2392 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
2393 if { ! [test_debug_format "DWARF 2"] } {
2400 # Return a 1 if we should skip tests that require hardware breakpoints
2402 proc skip_hw_breakpoint_tests {} {
2403 # Skip tests if requested by the board (note that no_hardware_watchpoints
2404 # disables both watchpoints and breakpoints)
2405 if { [target_info exists gdb,no_hardware_watchpoints]} {
2409 # These targets support hardware breakpoints natively
2410 if { [istarget "i?86-*-*"]
2411 || [istarget "x86_64-*-*"]
2412 || [istarget "ia64-*-*"]
2413 || [istarget "arm*-*-*"]} {
2420 # Return a 1 if we should skip tests that require hardware watchpoints
2422 proc skip_hw_watchpoint_tests {} {
2423 # Skip tests if requested by the board
2424 if { [target_info exists gdb,no_hardware_watchpoints]} {
2428 # These targets support hardware watchpoints natively
2429 if { [istarget "i?86-*-*"]
2430 || [istarget "x86_64-*-*"]
2431 || [istarget "ia64-*-*"]
2432 || [istarget "arm*-*-*"]
2433 || [istarget "powerpc*-*-linux*"]
2434 || [istarget "s390*-*-*"] } {
2441 # Return a 1 if we should skip tests that require *multiple* hardware
2442 # watchpoints to be active at the same time
2444 proc skip_hw_watchpoint_multi_tests {} {
2445 if { [skip_hw_watchpoint_tests] } {
2449 # These targets support just a single hardware watchpoint
2450 if { [istarget "arm*-*-*"]
2451 || [istarget "powerpc*-*-linux*"] } {
2458 # Return a 1 if we should skip tests that require read/access watchpoints
2460 proc skip_hw_watchpoint_access_tests {} {
2461 if { [skip_hw_watchpoint_tests] } {
2465 # These targets support just write watchpoints
2466 if { [istarget "s390*-*-*"] } {
2473 # Return 1 if we should skip tests that require the runtime unwinder
2474 # hook. This must be invoked while gdb is running, after shared
2475 # libraries have been loaded. This is needed because otherwise a
2476 # shared libgcc won't be visible.
2478 proc skip_unwinder_tests {} {
2482 gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook" {
2483 -re "= .*no debug info.*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
2485 -re "= .*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
2488 -re "No symbol .* in current context.\r\n$gdb_prompt $" {
2492 gdb_test_multiple "info probe" "check for stap probe in unwinder" {
2493 -re ".*libgcc.*unwind.*\r\n$gdb_prompt $" {
2496 -re "\r\n$gdb_prompt $" {
2503 # Return 0 if we should skip tests that require the libstdc++ stap
2504 # probes. This must be invoked while gdb is running, after shared
2505 # libraries have been loaded.
2507 proc skip_libstdcxx_probe_tests {} {
2511 gdb_test_multiple "info probe" "check for stap probe in libstdc++" {
2512 -re ".*libstdcxx.*catch.*\r\n$gdb_prompt $" {
2515 -re "\r\n$gdb_prompt $" {
2521 # Check whether we're testing with the remote or extended-remote
2524 proc gdb_is_target_remote {} {
2527 set test "probe for target remote"
2528 gdb_test_multiple "maint print target-stack" $test {
2529 -re ".*emote serial target in gdb-specific protocol.*$gdb_prompt $" {
2533 -re "$gdb_prompt $" {
2540 # Return 1 if the current remote target is an instance of our GDBserver, 0
2541 # otherwise. Return -1 if there was an error and we can't tell.
2543 gdb_caching_proc target_is_gdbserver {
2547 set test "Probing for GDBserver"
2549 gdb_test_multiple "monitor help" $test {
2550 -re "The following monitor commands are supported.*Quit GDBserver.*$gdb_prompt $" {
2553 -re "$gdb_prompt $" {
2558 if { $is_gdbserver == -1 } {
2559 verbose -log "Unable to tell whether we are using GDBserver or not."
2562 return $is_gdbserver
2565 set compiler_info "unknown"
2567 set hp_cc_compiler 0
2568 set hp_aCC_compiler 0
2570 # Figure out what compiler I am using.
2572 # ARG can be empty or "C++". If empty, "C" is assumed.
2574 # There are several ways to do this, with various problems.
2576 # [ gdb_compile -E $ifile -o $binfile.ci ]
2577 # source $binfile.ci
2579 # Single Unix Spec v3 says that "-E -o ..." together are not
2580 # specified. And in fact, the native compiler on hp-ux 11 (among
2581 # others) does not work with "-E -o ...". Most targets used to do
2582 # this, and it mostly worked, because it works with gcc.
2584 # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ]
2585 # source $binfile.ci
2587 # This avoids the problem with -E and -o together. This almost works
2588 # if the build machine is the same as the host machine, which is
2589 # usually true of the targets which are not gcc. But this code does
2590 # not figure which compiler to call, and it always ends up using the C
2591 # compiler. Not good for setting hp_aCC_compiler. Target
2592 # hppa*-*-hpux* used to do this.
2594 # [ gdb_compile -E $ifile > $binfile.ci ]
2595 # source $binfile.ci
2597 # dejagnu target_compile says that it supports output redirection,
2598 # but the code is completely different from the normal path and I
2599 # don't want to sweep the mines from that path. So I didn't even try
2602 # set cppout [ gdb_compile $ifile "" preprocess $args quiet ]
2605 # I actually do this for all targets now. gdb_compile runs the right
2606 # compiler, and TCL captures the output, and I eval the output.
2608 # Unfortunately, expect logs the output of the command as it goes by,
2609 # and dejagnu helpfully prints a second copy of it right afterwards.
2610 # So I turn off expect logging for a moment.
2612 # [ gdb_compile $ifile $ciexe_file executable $args ]
2613 # [ remote_exec $ciexe_file ]
2614 # [ source $ci_file.out ]
2616 # I could give up on -E and just do this.
2617 # I didn't get desperate enough to try this.
2619 # -- chastain 2004-01-06
2621 proc get_compiler_info {{arg ""}} {
2622 # For compiler.c and compiler.cc
2625 # I am going to play with the log to keep noise out.
2629 # These come from compiler.c or compiler.cc
2630 global compiler_info
2632 # Legacy global data symbols.
2634 global hp_cc_compiler
2635 global hp_aCC_compiler
2637 # Choose which file to preprocess.
2638 set ifile "${srcdir}/lib/compiler.c"
2639 if { $arg == "c++" } {
2640 set ifile "${srcdir}/lib/compiler.cc"
2643 # Run $ifile through the right preprocessor.
2644 # Toggle gdb.log to keep the compiler output out of the log.
2645 set saved_log [log_file -info]
2647 if [is_remote host] {
2648 # We have to use -E and -o together, despite the comments
2649 # above, because of how DejaGnu handles remote host testing.
2650 set ppout "$outdir/compiler.i"
2651 gdb_compile "${ifile}" "$ppout" preprocess [list "$arg" quiet]
2652 set file [open $ppout r]
2653 set cppout [read $file]
2656 set cppout [ gdb_compile "${ifile}" "" preprocess [list "$arg" quiet] ]
2658 eval log_file $saved_log
2662 foreach cppline [ split "$cppout" "\n" ] {
2663 if { [ regexp "^#" "$cppline" ] } {
2665 } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } {
2667 } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } {
2669 verbose "get_compiler_info: $cppline" 2
2673 verbose -log "get_compiler_info: $cppline"
2678 # Reset to unknown compiler if any diagnostics happened.
2680 set compiler_info "unknown"
2683 # Set the legacy symbols.
2685 set hp_cc_compiler 0
2686 set hp_aCC_compiler 0
2687 if { [regexp "^gcc-1-" "$compiler_info" ] } { set gcc_compiled 1 }
2688 if { [regexp "^gcc-2-" "$compiler_info" ] } { set gcc_compiled 2 }
2689 if { [regexp "^gcc-3-" "$compiler_info" ] } { set gcc_compiled 3 }
2690 if { [regexp "^gcc-4-" "$compiler_info" ] } { set gcc_compiled 4 }
2691 if { [regexp "^gcc-5-" "$compiler_info" ] } { set gcc_compiled 5 }
2692 if { [regexp "^hpcc-" "$compiler_info" ] } { set hp_cc_compiler 1 }
2693 if { [regexp "^hpacc-" "$compiler_info" ] } { set hp_aCC_compiler 1 }
2695 # Log what happened.
2696 verbose -log "get_compiler_info: $compiler_info"
2698 # Most compilers will evaluate comparisons and other boolean
2699 # operations to 0 or 1.
2700 uplevel \#0 { set true 1 }
2701 uplevel \#0 { set false 0 }
2703 # Use of aCC results in boolean results being displayed as
2705 if { $hp_aCC_compiler } {
2706 uplevel \#0 { set true true }
2707 uplevel \#0 { set false false }
2713 proc test_compiler_info { {compiler ""} } {
2714 global compiler_info
2716 # if no arg, return the compiler_info string
2718 if [string match "" $compiler] {
2719 if [info exists compiler_info] {
2720 return $compiler_info
2722 perror "No compiler info found."
2726 return [string match $compiler $compiler_info]
2729 proc current_target_name { } {
2731 if [info exists target_info(target,name)] {
2732 set answer $target_info(target,name)
2739 set gdb_wrapper_initialized 0
2740 set gdb_wrapper_target ""
2742 proc gdb_wrapper_init { args } {
2743 global gdb_wrapper_initialized
2744 global gdb_wrapper_file
2745 global gdb_wrapper_flags
2746 global gdb_wrapper_target
2748 if { $gdb_wrapper_initialized == 1 } { return; }
2750 if {[target_info exists needs_status_wrapper] && \
2751 [target_info needs_status_wrapper] != "0"} {
2752 set result [build_wrapper "testglue.o"]
2753 if { $result != "" } {
2754 set gdb_wrapper_file [lindex $result 0]
2755 set gdb_wrapper_flags [lindex $result 1]
2757 warning "Status wrapper failed to build."
2760 set gdb_wrapper_initialized 1
2761 set gdb_wrapper_target [current_target_name]
2764 # Some targets need to always link a special object in. Save its path here.
2765 global gdb_saved_set_unbuffered_mode_obj
2766 set gdb_saved_set_unbuffered_mode_obj ""
2768 proc gdb_compile {source dest type options} {
2769 global GDB_TESTCASE_OPTIONS
2770 global gdb_wrapper_file
2771 global gdb_wrapper_flags
2772 global gdb_wrapper_initialized
2775 global gdb_saved_set_unbuffered_mode_obj
2777 set outdir [file dirname $dest]
2779 # Add platform-specific options if a shared library was specified using
2780 # "shlib=librarypath" in OPTIONS.
2784 foreach opt $options {
2785 if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] {
2786 if [test_compiler_info "xlc-*"] {
2787 # IBM xlc compiler doesn't accept shared library named other
2788 # than .so: use "-Wl," to bypass this
2789 lappend source "-Wl,$shlib_name"
2790 } elseif { ([istarget "*-*-mingw*"]
2791 || [istarget *-*-cygwin*]
2792 || [istarget *-*-pe*])} {
2793 lappend source "${shlib_name}.a"
2795 lappend source $shlib_name
2797 if { $shlib_found == 0 } {
2799 if { ([istarget "*-*-mingw*"]
2800 || [istarget *-*-cygwin*]) } {
2801 lappend new_options "additional_flags=-Wl,--enable-auto-import"
2804 } elseif { $opt == "shlib_load" } {
2807 lappend new_options $opt
2811 # We typically link to shared libraries using an absolute path, and
2812 # that's how they are found at runtime. If we are going to
2813 # dynamically load one by basename, we must specify rpath. If we
2814 # are using a remote host, DejaGNU will link to the shared library
2815 # using a relative path, so again we must specify an rpath.
2816 if { $shlib_load || ($shlib_found && [is_remote target]) } {
2817 if { ([istarget "*-*-mingw*"]
2818 || [istarget *-*-cygwin*]
2819 || [istarget *-*-pe*]
2820 || [istarget hppa*-*-hpux*])} {
2821 # Do not need anything.
2822 } elseif { [istarget *-*-freebsd*] || [istarget *-*-openbsd*] } {
2823 lappend new_options "ldflags=-Wl,-rpath,${outdir}"
2824 } elseif { [istarget arm*-*-symbianelf*] } {
2825 if { $shlib_load } {
2826 lappend new_options "libs=-ldl"
2829 if { $shlib_load } {
2830 lappend new_options "libs=-ldl"
2832 lappend new_options "ldflags=-Wl,-rpath,\\\$ORIGIN"
2835 set options $new_options
2837 if [info exists GDB_TESTCASE_OPTIONS] {
2838 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS"
2840 verbose "options are $options"
2841 verbose "source is $source $dest $type $options"
2843 if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init }
2845 if {[target_info exists needs_status_wrapper] && \
2846 [target_info needs_status_wrapper] != "0" && \
2847 [info exists gdb_wrapper_file]} {
2848 lappend options "libs=${gdb_wrapper_file}"
2849 lappend options "ldflags=${gdb_wrapper_flags}"
2852 # Replace the "nowarnings" option with the appropriate additional_flags
2853 # to disable compiler warnings.
2854 set nowarnings [lsearch -exact $options nowarnings]
2855 if {$nowarnings != -1} {
2856 if [target_info exists gdb,nowarnings_flag] {
2857 set flag "additional_flags=[target_info gdb,nowarnings_flag]"
2859 set flag "additional_flags=-w"
2861 set options [lreplace $options $nowarnings $nowarnings $flag]
2864 if { $type == "executable" } {
2865 if { ([istarget "*-*-mingw*"]
2866 || [istarget "*-*-*djgpp"]
2867 || [istarget "*-*-cygwin*"])} {
2868 # Force output to unbuffered mode, by linking in an object file
2869 # with a global contructor that calls setvbuf.
2871 # Compile the special object seperatelly for two reasons:
2872 # 1) Insulate it from $options.
2873 # 2) Avoid compiling it for every gdb_compile invocation,
2874 # which is time consuming, especially if we're remote
2877 if { $gdb_saved_set_unbuffered_mode_obj == "" } {
2878 verbose "compiling gdb_saved_set_unbuffered_obj"
2879 set unbuf_src ${srcdir}/lib/set_unbuffered_mode.c
2880 set unbuf_obj ${objdir}/set_unbuffered_mode.o
2882 set result [gdb_compile "${unbuf_src}" "${unbuf_obj}" object {nowarnings}]
2883 if { $result != "" } {
2886 if {[is_remote host]} {
2887 set gdb_saved_set_unbuffered_mode_obj set_unbuffered_mode_saved.o
2889 set gdb_saved_set_unbuffered_mode_obj ${objdir}/set_unbuffered_mode_saved.o
2891 # Link a copy of the output object, because the
2892 # original may be automatically deleted.
2893 remote_download host $unbuf_obj $gdb_saved_set_unbuffered_mode_obj
2895 verbose "gdb_saved_set_unbuffered_obj already compiled"
2898 # Rely on the internal knowledge that the global ctors are ran in
2899 # reverse link order. In that case, we can use ldflags to
2900 # avoid copying the object file to the host multiple
2902 # This object can only be added if standard libraries are
2903 # used. Thus, we need to disable it if -nostdlib option is used
2904 if {[lsearch -regexp $options "-nostdlib"] < 0 } {
2905 lappend options "ldflags=$gdb_saved_set_unbuffered_mode_obj"
2910 set result [target_compile $source $dest $type $options]
2912 # Prune uninteresting compiler (and linker) output.
2913 regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result
2915 regsub "\[\r\n\]*$" "$result" "" result
2916 regsub "^\[\r\n\]*" "$result" "" result
2918 if {[lsearch $options quiet] < 0} {
2919 # We shall update this on a per language basis, to avoid
2920 # changing the entire testsuite in one go.
2921 if {[lsearch $options f77] >= 0} {
2922 gdb_compile_test $source $result
2923 } elseif { $result != "" } {
2924 clone_output "gdb compile failed, $result"
2931 # This is just like gdb_compile, above, except that it tries compiling
2932 # against several different thread libraries, to see which one this
2934 proc gdb_compile_pthreads {source dest type options} {
2936 set why_msg "unrecognized error"
2937 foreach lib {-lpthreads -lpthread -lthread ""} {
2938 # This kind of wipes out whatever libs the caller may have
2939 # set. Or maybe theirs will override ours. How infelicitous.
2940 set options_with_lib [concat $options [list libs=$lib quiet]]
2941 set ccout [gdb_compile $source $dest $type $options_with_lib]
2942 switch -regexp -- $ccout {
2943 ".*no posix threads support.*" {
2944 set why_msg "missing threads include file"
2947 ".*cannot open -lpthread.*" {
2948 set why_msg "missing runtime threads library"
2950 ".*Can't find library for -lpthread.*" {
2951 set why_msg "missing runtime threads library"
2954 pass "successfully compiled posix threads test case"
2960 if {!$built_binfile} {
2961 unsupported "Couldn't compile [file tail $source]: ${why_msg}"
2966 # Build a shared library from SOURCES.
2968 proc gdb_compile_shlib {sources dest options} {
2969 set obj_options $options
2972 if { [lsearch -exact $options "c++"] >= 0 } {
2973 set info_options "c++"
2975 if [get_compiler_info ${info_options}] {
2979 switch -glob [test_compiler_info] {
2981 lappend obj_options "additional_flags=-qpic"
2984 if { !([istarget "*-*-cygwin*"]
2985 || [istarget "*-*-mingw*"]) } {
2986 lappend obj_options "additional_flags=-fpic"
2990 if { !([istarget "powerpc*-*-aix*"]
2991 || [istarget "rs6000*-*-aix*"]
2992 || [istarget "*-*-cygwin*"]
2993 || [istarget "*-*-mingw*"]
2994 || [istarget "*-*-pe*"]) } {
2995 lappend obj_options "additional_flags=-fpic"
2999 switch -glob [istarget] {
3001 lappend obj_options "additional_flags=+z"
3004 # don't know what the compiler is...
3010 set outdir [file dirname $dest]
3012 foreach source $sources {
3013 set sourcebase [file tail $source]
3014 if {[gdb_compile $source "${outdir}/${sourcebase}.o" object $obj_options] != ""} {
3017 lappend objects ${outdir}/${sourcebase}.o
3020 if [istarget "hppa*-*-hpux*"] {
3021 remote_exec build "ld -b ${objects} -o ${dest}"
3023 set link_options $options
3024 if [test_compiler_info "xlc-*"] {
3025 lappend link_options "additional_flags=-qmkshrobj"
3027 lappend link_options "additional_flags=-shared"
3029 if { ([istarget "*-*-mingw*"]
3030 || [istarget *-*-cygwin*]
3031 || [istarget *-*-pe*]) } {
3032 if { [is_remote host] } {
3033 set name [file tail ${dest}]
3037 lappend link_options "additional_flags=-Wl,--out-implib,${name}.a"
3038 } elseif [is_remote target] {
3039 # By default, we do not set the soname. This causes the linker
3040 # on ELF systems to create a DT_NEEDED entry in the executable
3041 # refering to the full path name of the library. This is a
3042 # problem in remote testing if the library is in a different
3043 # directory there. To fix this, we set a soname of just the
3044 # base filename for the library, and add an appropriate -rpath
3045 # to the main executable (in gdb_compile).
3046 set destbase [file tail $dest]
3047 lappend link_options "additional_flags=-Wl,-soname,$destbase"
3050 if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
3053 if { [is_remote host]
3054 && ([istarget "*-*-mingw*"]
3055 || [istarget *-*-cygwin*]
3056 || [istarget *-*-pe*]) } {
3057 set dest_tail_name [file tail ${dest}]
3058 remote_upload host $dest_tail_name.a ${dest}.a
3059 remote_file host delete $dest_tail_name.a
3065 # This is just like gdb_compile_shlib, above, except that it tries compiling
3066 # against several different thread libraries, to see which one this
3068 proc gdb_compile_shlib_pthreads {sources dest options} {
3070 set why_msg "unrecognized error"
3071 foreach lib {-lpthreads -lpthread -lthread ""} {
3072 # This kind of wipes out whatever libs the caller may have
3073 # set. Or maybe theirs will override ours. How infelicitous.
3074 set options_with_lib [concat $options [list libs=$lib quiet]]
3075 set ccout [gdb_compile_shlib $sources $dest $options_with_lib]
3076 switch -regexp -- $ccout {
3077 ".*no posix threads support.*" {
3078 set why_msg "missing threads include file"
3081 ".*cannot open -lpthread.*" {
3082 set why_msg "missing runtime threads library"
3084 ".*Can't find library for -lpthread.*" {
3085 set why_msg "missing runtime threads library"
3088 pass "successfully compiled posix threads test case"
3094 if {!$built_binfile} {
3095 unsupported "Couldn't compile $sources: ${why_msg}"
3100 # This is just like gdb_compile_pthreads, above, except that we always add the
3101 # objc library for compiling Objective-C programs
3102 proc gdb_compile_objc {source dest type options} {
3104 set why_msg "unrecognized error"
3105 foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} {
3106 # This kind of wipes out whatever libs the caller may have
3107 # set. Or maybe theirs will override ours. How infelicitous.
3108 if { $lib == "solaris" } {
3109 set lib "-lpthread -lposix4"
3111 if { $lib != "-lobjc" } {
3112 set lib "-lobjc $lib"
3114 set options_with_lib [concat $options [list libs=$lib quiet]]
3115 set ccout [gdb_compile $source $dest $type $options_with_lib]
3116 switch -regexp -- $ccout {
3117 ".*no posix threads support.*" {
3118 set why_msg "missing threads include file"
3121 ".*cannot open -lpthread.*" {
3122 set why_msg "missing runtime threads library"
3124 ".*Can't find library for -lpthread.*" {
3125 set why_msg "missing runtime threads library"
3128 pass "successfully compiled objc with posix threads test case"
3134 if {!$built_binfile} {
3135 unsupported "Couldn't compile [file tail $source]: ${why_msg}"
3140 proc send_gdb { string } {
3141 global suppress_flag
3142 if { $suppress_flag } {
3145 return [remote_send host "$string"]
3151 proc gdb_expect { args } {
3152 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
3153 set atimeout [lindex $args 0]
3154 set expcode [list [lindex $args 1]]
3159 # A timeout argument takes precedence, otherwise of all the timeouts
3160 # select the largest.
3161 upvar #0 timeout gtimeout
3162 upvar timeout timeout
3163 if [info exists atimeout] {
3167 if [info exists timeout] {
3170 if { [info exists gtimeout] && $gtimeout > $tmt } {
3173 if { [target_info exists gdb,timeout]
3174 && [target_info gdb,timeout] > $tmt } {
3175 set tmt [target_info gdb,timeout]
3183 global suppress_flag
3184 global remote_suppress_flag
3185 if [info exists remote_suppress_flag] {
3186 set old_val $remote_suppress_flag
3188 if [info exists suppress_flag] {
3189 if { $suppress_flag } {
3190 set remote_suppress_flag 1
3194 {uplevel remote_expect host $tmt $expcode} string]
3195 if [info exists old_val] {
3196 set remote_suppress_flag $old_val
3198 if [info exists remote_suppress_flag] {
3199 unset remote_suppress_flag
3204 global errorInfo errorCode
3206 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
3208 return -code $code $string
3212 # gdb_expect_list TEST SENTINEL LIST -- expect a sequence of outputs
3214 # Check for long sequence of output by parts.
3215 # TEST: is the test message to be printed with the test success/fail.
3216 # SENTINEL: Is the terminal pattern indicating that output has finished.
3217 # LIST: is the sequence of outputs to match.
3218 # If the sentinel is recognized early, it is considered an error.
3221 # 1 if the test failed,
3222 # 0 if the test passes,
3223 # -1 if there was an internal error.
3225 proc gdb_expect_list {test sentinel list} {
3227 global suppress_flag
3230 if { $suppress_flag } {
3232 unresolved "${test}"
3234 while { ${index} < [llength ${list}] } {
3235 set pattern [lindex ${list} ${index}]
3236 set index [expr ${index} + 1]
3237 verbose -log "gdb_expect_list pattern: /$pattern/" 2
3238 if { ${index} == [llength ${list}] } {
3241 -re "${pattern}${sentinel}" {
3242 # pass "${test}, pattern ${index} + sentinel"
3245 fail "${test} (pattern ${index} + sentinel)"
3248 -re ".*A problem internal to GDB has been detected" {
3249 fail "${test} (GDB internal error)"
3251 gdb_internal_error_resync
3254 fail "${test} (pattern ${index} + sentinel) (timeout)"
3259 # unresolved "${test}, pattern ${index} + sentinel"
3265 # pass "${test}, pattern ${index}"
3268 fail "${test} (pattern ${index})"
3271 -re ".*A problem internal to GDB has been detected" {
3272 fail "${test} (GDB internal error)"
3274 gdb_internal_error_resync
3277 fail "${test} (pattern ${index}) (timeout)"
3282 # unresolved "${test}, pattern ${index}"
3296 proc gdb_suppress_entire_file { reason } {
3297 global suppress_flag
3300 set suppress_flag -1
3304 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
3305 # gdb_expect to fail immediately (until the next call to
3306 # gdb_stop_suppressing_tests).
3308 proc gdb_suppress_tests { args } {
3309 global suppress_flag
3311 return; # fnf - disable pending review of results where
3312 # testsuite ran better without this
3315 if { $suppress_flag == 1 } {
3316 if { [llength $args] > 0 } {
3317 warning "[lindex $args 0]\n"
3319 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n"
3325 # Clear suppress_flag.
3327 proc gdb_stop_suppressing_tests { } {
3328 global suppress_flag
3330 if [info exists suppress_flag] {
3331 if { $suppress_flag > 0 } {
3333 clone_output "Tests restarted.\n"
3340 proc gdb_clear_suppressed { } {
3341 global suppress_flag
3346 # Spawn the gdb process.
3348 # This doesn't expect any output or do any other initialization,
3349 # leaving those to the caller.
3351 # Overridable function -- you can override this function in your
3354 proc gdb_spawn { } {
3358 # Spawn GDB with CMDLINE_FLAGS appended to the GDBFLAGS global.
3360 proc gdb_spawn_with_cmdline_opts { cmdline_flags } {
3363 set saved_gdbflags $GDBFLAGS
3365 append GDBFLAGS $cmdline_flags
3369 set GDBFLAGS $saved_gdbflags
3374 # Start gdb running, wait for prompt, and disable the pagers.
3376 # Overridable function -- you can override this function in your
3379 proc gdb_start { } {
3384 catch default_gdb_exit
3387 # Start a set of programs running and then wait for a bit, to be sure
3388 # that they can be attached to. Return a list of the processes' PIDs.
3390 proc spawn_wait_for_attach { executable_list } {
3393 foreach {executable} $executable_list {
3394 lappend pid_list [eval exec $executable &]
3399 if { [istarget "*-*-cygwin*"] } {
3400 for {set i 0} {$i < [llength $pid_list]} {incr i} {
3401 # testpid is the Cygwin PID, GDB uses the Windows PID,
3402 # which might be different due to the way fork/exec works.
3403 set testpid [lindex $pid_list $i]
3404 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
3405 set pid_list [lreplace $pid_list $i $i $testpid]
3413 # gdb_load_cmd -- load a file into the debugger.
3414 # ARGS - additional args to load command.
3415 # return a -1 if anything goes wrong.
3417 proc gdb_load_cmd { args } {
3420 if [target_info exists gdb_load_timeout] {
3421 set loadtimeout [target_info gdb_load_timeout]
3423 set loadtimeout 1600
3425 send_gdb "load $args\n"
3426 verbose "Timeout is now $loadtimeout seconds" 2
3427 gdb_expect $loadtimeout {
3428 -re "Loading section\[^\r\]*\r\n" {
3431 -re "Start address\[\r\]*\r\n" {
3434 -re "Transfer rate\[\r\]*\r\n" {
3437 -re "Memory access error\[^\r\]*\r\n" {
3438 perror "Failed to load program"
3441 -re "$gdb_prompt $" {
3444 -re "(.*)\r\n$gdb_prompt " {
3445 perror "Unexpected reponse from 'load' -- $expect_out(1,string)"
3449 perror "Timed out trying to load $args."
3456 # Invoke "gcore". CORE is the name of the core file to write. TEST
3457 # is the name of the test case. This will return 1 if the core file
3458 # was created, 0 otherwise. If this fails to make a core file because
3459 # this configuration of gdb does not support making core files, it
3460 # will call "unsupported", not "fail". However, if this fails to make
3461 # a core file for some other reason, then it will call "fail".
3463 proc gdb_gcore_cmd {core test} {
3467 gdb_test_multiple "gcore $core" $test {
3468 -re "Saved corefile .*\[\r\n\]+$gdb_prompt $" {
3472 -re "(?:Can't create a corefile|Target does not support core file generation\\.)\[\r\n\]+$gdb_prompt $" {
3480 # Load core file CORE. TEST is the name of the test case.
3481 # This will record a pass/fail for loading the core file.
3483 # 1 - core file is successfully loaded
3484 # 0 - core file loaded but has a non fatal error
3485 # -1 - core file failed to load
3487 proc gdb_core_cmd { core test } {
3490 gdb_test_multiple "core $core" "$test" {
3491 -re "\\\[Thread debugging using \[^ \r\n\]* enabled\\\]\r\n" {
3494 -re " is not a core dump:.*\r\n$gdb_prompt $" {
3495 fail "$test (bad file format)"
3498 -re ": No such file or directory.*\r\n$gdb_prompt $" {
3499 fail "$test (file not found)"
3502 -re "Couldn't find .* registers in core file.*\r\n$gdb_prompt $" {
3503 fail "$test (incomplete note section)"
3506 -re "Core was generated by .*\r\n$gdb_prompt $" {
3510 -re ".*$gdb_prompt $" {
3515 fail "$test (timeout)"
3519 fail "unsupported output from 'core' command"
3523 # Return the filename to download to the target and load on the target
3524 # for this shared library. Normally just LIBNAME, unless shared libraries
3525 # for this target have separate link and load images.
3527 proc shlib_target_file { libname } {
3531 # Return the filename GDB will load symbols from when debugging this
3532 # shared library. Normally just LIBNAME, unless shared libraries for
3533 # this target have separate link and load images.
3535 proc shlib_symbol_file { libname } {
3539 # Return the filename to download to the target and load for this
3540 # executable. Normally just BINFILE unless it is renamed to something
3541 # else for this target.
3543 proc exec_target_file { binfile } {
3547 # Return the filename GDB will load symbols from when debugging this
3548 # executable. Normally just BINFILE unless executables for this target
3549 # have separate files for symbols.
3551 proc exec_symbol_file { binfile } {
3555 # Rename the executable file. Normally this is just BINFILE1 being renamed
3556 # to BINFILE2, but some targets require multiple binary files.
3557 proc gdb_rename_execfile { binfile1 binfile2 } {
3558 file rename -force [exec_target_file ${binfile1}] \
3559 [exec_target_file ${binfile2}]
3560 if { [exec_target_file ${binfile1}] != [exec_symbol_file ${binfile1}] } {
3561 file rename -force [exec_symbol_file ${binfile1}] \
3562 [exec_symbol_file ${binfile2}]
3566 # "Touch" the executable file to update the date. Normally this is just
3567 # BINFILE, but some targets require multiple files.
3568 proc gdb_touch_execfile { binfile } {
3569 set time [clock seconds]
3570 file mtime [exec_target_file ${binfile}] $time
3571 if { [exec_target_file ${binfile}] != [exec_symbol_file ${binfile}] } {
3572 file mtime [exec_symbol_file ${binfile}] $time
3576 # Like remote_download but provides a gdb-specific behavior. If DEST
3577 # is "host", and the host is not remote, and TOFILE is not specified,
3578 # then the [file tail] of FROMFILE is passed through
3579 # standard_output_file to compute the destination.
3581 proc gdb_remote_download {dest fromfile {tofile {}}} {
3582 if {$dest == "host" && ![is_remote host] && $tofile == ""} {
3583 set tofile [standard_output_file [file tail $fromfile]]
3586 if { $tofile == "" } {
3587 return [remote_download $dest $fromfile]
3589 return [remote_download $dest $fromfile $tofile]
3595 # Copy a file to the remote target and return its target filename.
3596 # Schedule the file to be deleted at the end of this test.
3598 proc gdb_download { filename } {
3601 set destname [remote_download target $filename]
3602 lappend cleanfiles $destname
3606 # gdb_load_shlibs LIB...
3608 # Copy the listed libraries to the target.
3610 proc gdb_load_shlibs { args } {
3611 if {![is_remote target]} {
3615 foreach file $args {
3616 gdb_download [shlib_target_file $file]
3619 # Even if the target supplies full paths for shared libraries,
3620 # they may not be paths for this system.
3621 gdb_test "set solib-search-path [file dirname [lindex $args 0]]" "" ""
3625 # gdb_load -- load a file into the debugger. Specifying no file
3626 # defaults to the executable currently being debugged.
3627 # Many files in config/*.exp override this procedure.
3629 proc gdb_load { arg } {
3631 return [gdb_file_cmd $arg]
3635 # gdb_reload -- load a file into the target. Called before "running",
3636 # either the first time or after already starting the program once,
3637 # for remote targets. Most files that override gdb_load should now
3638 # override this instead.
3640 proc gdb_reload { } {
3641 # For the benefit of existing configurations, default to gdb_load.
3642 # Specifying no file defaults to the executable currently being
3644 return [gdb_load ""]
3647 proc gdb_continue { function } {
3650 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"]
3653 proc default_gdb_init { test_file_name } {
3654 global gdb_wrapper_initialized
3655 global gdb_wrapper_target
3656 global gdb_test_file_name
3662 gdb_clear_suppressed
3664 set gdb_test_file_name [file rootname [file tail $test_file_name]]
3666 # Make sure that the wrapper is rebuilt
3667 # with the appropriate multilib option.
3668 if { $gdb_wrapper_target != [current_target_name] } {
3669 set gdb_wrapper_initialized 0
3672 # Unlike most tests, we have a small number of tests that generate
3673 # a very large amount of output. We therefore increase the expect
3674 # buffer size to be able to contain the entire test output. This
3675 # is especially needed by gdb.base/info-macros.exp.
3677 # Also set this value for the currently running GDB.
3678 match_max [match_max -d]
3680 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
3681 set pf_prefix "[file tail [file dirname $test_file_name]]/[file tail $test_file_name]:"
3684 if [target_info exists gdb_prompt] {
3685 set gdb_prompt [target_info gdb_prompt]
3687 set gdb_prompt "\\(gdb\\)"
3690 if [info exists use_gdb_stub] {
3695 # Turn BASENAME into a full file name in the standard output
3696 # directory. It is ok if BASENAME is the empty string; in this case
3697 # the directory is returned.
3699 proc standard_output_file {basename} {
3700 global objdir subdir gdb_test_file_name GDB_PARALLEL
3702 if {[info exists GDB_PARALLEL]} {
3703 set dir [file join $objdir outputs $subdir $gdb_test_file_name]
3705 return [file join $dir $basename]
3707 return [file join $objdir $subdir $basename]
3711 # Return the name of a file in our standard temporary directory.
3713 proc standard_temp_file {basename} {
3714 global objdir GDB_PARALLEL
3716 if {[info exists GDB_PARALLEL]} {
3717 return [file join $objdir temp $basename]
3723 # Set 'testfile', 'srcfile', and 'binfile'.
3725 # ARGS is a list of source file specifications.
3726 # Without any arguments, the .exp file's base name is used to
3727 # compute the source file name. The ".c" extension is added in this case.
3728 # If ARGS is not empty, each entry is a source file specification.
3729 # If the specification starts with a ".", it is treated as a suffix
3730 # to append to the .exp file's base name.
3731 # If the specification is the empty string, it is treated as if it
3733 # Otherwise it is a file name.
3734 # The first file in the list is used to set the 'srcfile' global.
3735 # Each subsequent name is used to set 'srcfile2', 'srcfile3', etc.
3737 # Most tests should call this without arguments.
3739 # If a completely different binary file name is needed, then it
3740 # should be handled in the .exp file with a suitable comment.
3742 proc standard_testfile {args} {
3743 global gdb_test_file_name
3745 global gdb_test_file_last_vars
3748 global testfile binfile
3750 set testfile $gdb_test_file_name
3751 set binfile [standard_output_file ${testfile}]
3753 if {[llength $args] == 0} {
3757 # Unset our previous output variables.
3758 # This can help catch hidden bugs.
3759 if {[info exists gdb_test_file_last_vars]} {
3760 foreach varname $gdb_test_file_last_vars {
3762 catch {unset $varname}
3765 # 'executable' is often set by tests.
3766 set gdb_test_file_last_vars {executable}
3770 set varname srcfile$suffix
3773 # Handle an extension.
3776 } elseif {[string range $arg 0 0] == "."} {
3777 set arg $testfile$arg
3781 lappend gdb_test_file_last_vars $varname
3783 if {$suffix == ""} {
3791 # The default timeout used when testing GDB commands. We want to use
3792 # the same timeout as the default dejagnu timeout, unless the user has
3793 # already provided a specific value (probably through a site.exp file).
3794 global gdb_test_timeout
3795 if ![info exists gdb_test_timeout] {
3796 set gdb_test_timeout $timeout
3799 # A list of global variables that GDB testcases should not use.
3800 # We try to prevent their use by monitoring write accesses and raising
3801 # an error when that happens.
3802 set banned_variables { bug_id prms_id }
3804 # A list of procedures that GDB testcases should not use.
3805 # We try to prevent their use by monitoring invocations and raising
3806 # an error when that happens.
3807 set banned_procedures { strace }
3809 # gdb_init is called by runtest at start, but also by several
3810 # tests directly; gdb_finish is only called from within runtest after
3811 # each test source execution.
3812 # Placing several traces by repetitive calls to gdb_init leads
3813 # to problems, as only one trace is removed in gdb_finish.
3814 # To overcome this possible problem, we add a variable that records
3815 # if the banned variables and procedures are already traced.
3818 proc gdb_init { test_file_name } {
3819 # Reset the timeout value to the default. This way, any testcase
3820 # that changes the timeout value without resetting it cannot affect
3821 # the timeout used in subsequent testcases.
3822 global gdb_test_timeout
3824 set timeout $gdb_test_timeout
3826 if { [regexp ".*gdb\.reverse\/.*" $test_file_name]
3827 && [target_info exists gdb_reverse_timeout] } {
3828 set timeout [target_info gdb_reverse_timeout]
3831 # If GDB_INOTIFY is given, check for writes to '.'. This is a
3832 # debugging tool to help confirm that the test suite is
3833 # parallel-safe. You need "inotifywait" from the
3834 # inotify-tools package to use this.
3835 global GDB_INOTIFY inotify_pid
3836 if {[info exists GDB_INOTIFY] && ![info exists inotify_pid]} {
3837 global outdir tool inotify_log_file
3839 set exclusions {outputs temp gdb[.](log|sum) cache}
3840 set exclusion_re ([join $exclusions |])
3842 set inotify_log_file [standard_temp_file inotify.out]
3843 set inotify_pid [exec inotifywait -r -m -e move,create,delete . \
3844 --exclude $exclusion_re \
3845 |& tee -a $outdir/$tool.log $inotify_log_file &]
3847 # Wait for the watches; hopefully this is long enough.
3850 # Clear the log so that we don't emit a warning the first time
3852 set fd [open $inotify_log_file w]
3856 # Block writes to all banned variables, and invocation of all
3857 # banned procedures...
3858 global banned_variables
3859 global banned_procedures
3860 global banned_traced
3861 if (!$banned_traced) {
3862 foreach banned_var $banned_variables {
3863 global "$banned_var"
3864 trace add variable "$banned_var" write error
3866 foreach banned_proc $banned_procedures {
3867 global "$banned_proc"
3868 trace add execution "$banned_proc" enter error
3873 # We set LC_ALL, LC_CTYPE, and LANG to C so that we get the same
3874 # messages as expected.
3879 # Don't let a .inputrc file or an existing setting of INPUTRC mess up
3880 # the test results. Even if /dev/null doesn't exist on the particular
3881 # platform, the readline library will use the default setting just by
3882 # failing to open the file. OTOH, opening /dev/null successfully will
3883 # also result in the default settings being used since nothing will be
3884 # read from this file.
3885 setenv INPUTRC "/dev/null"
3887 # The gdb.base/readline.exp arrow key test relies on the standard VT100
3888 # bindings, so make sure that an appropriate terminal is selected.
3889 # The same bug doesn't show up if we use ^P / ^N instead.
3892 # Some tests (for example gdb.base/maint.exp) shell out from gdb to use
3893 # grep. Clear GREP_OPTIONS to make the behavior predictable,
3894 # especially having color output turned on can cause tests to fail.
3895 setenv GREP_OPTIONS ""
3897 # Clear $gdbserver_reconnect_p.
3898 global gdbserver_reconnect_p
3899 set gdbserver_reconnect_p 1
3900 unset gdbserver_reconnect_p
3902 return [default_gdb_init $test_file_name]
3905 proc gdb_finish { } {
3906 global gdbserver_reconnect_p
3910 # Give persistent gdbserver a chance to terminate before GDB is killed.
3911 if {[info exists gdbserver_reconnect_p] && $gdbserver_reconnect_p
3912 && [info exists gdb_spawn_id]} {
3919 -re "$gdb_prompt $" {
3924 # Exit first, so that the files are no longer in use.
3927 if { [llength $cleanfiles] > 0 } {
3928 eval remote_file target delete $cleanfiles
3932 # Unblock write access to the banned variables. Dejagnu typically
3933 # resets some of them between testcases.
3934 global banned_variables
3935 global banned_procedures
3936 global banned_traced
3937 if ($banned_traced) {
3938 foreach banned_var $banned_variables {
3939 global "$banned_var"
3940 trace remove variable "$banned_var" write error
3942 foreach banned_proc $banned_procedures {
3943 global "$banned_proc"
3944 trace remove execution "$banned_proc" enter error
3951 set debug_format "unknown"
3953 # Run the gdb command "info source" and extract the debugging format
3954 # information from the output and save it in debug_format.
3956 proc get_debug_format { } {
3962 set debug_format "unknown"
3963 send_gdb "info source\n"
3965 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
3966 set debug_format $expect_out(1,string)
3967 verbose "debug format is $debug_format"
3970 -re "No current source file.\r\n$gdb_prompt $" {
3971 perror "get_debug_format used when no current source file"
3974 -re "$gdb_prompt $" {
3975 warning "couldn't check debug format (no valid response)."
3979 warning "couldn't check debug format (timeout)."
3985 # Return true if FORMAT matches the debug format the current test was
3986 # compiled with. FORMAT is a shell-style globbing pattern; it can use
3987 # `*', `[...]', and so on.
3989 # This function depends on variables set by `get_debug_format', above.
3991 proc test_debug_format {format} {
3994 return [expr [string match $format $debug_format] != 0]
3997 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
3998 # COFF, stabs, etc). If that format matches the format that the
3999 # current test was compiled with, then the next test is expected to
4000 # fail for any target. Returns 1 if the next test or set of tests is
4001 # expected to fail, 0 otherwise (or if it is unknown). Must have
4002 # previously called get_debug_format.
4003 proc setup_xfail_format { format } {
4004 set ret [test_debug_format $format]
4012 # gdb_get_line_number TEXT [FILE]
4014 # Search the source file FILE, and return the line number of the
4015 # first line containing TEXT. If no match is found, an error is thrown.
4017 # TEXT is a string literal, not a regular expression.
4019 # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is
4020 # specified, and does not start with "/", then it is assumed to be in
4021 # "$srcdir/$subdir". This is awkward, and can be fixed in the future,
4022 # by changing the callers and the interface at the same time.
4023 # In particular: gdb.base/break.exp, gdb.base/condbreak.exp,
4024 # gdb.base/ena-dis-br.exp.
4026 # Use this function to keep your test scripts independent of the
4027 # exact line numbering of the source file. Don't write:
4029 # send_gdb "break 20"
4031 # This means that if anyone ever edits your test's source file,
4032 # your test could break. Instead, put a comment like this on the
4033 # source file line you want to break at:
4035 # /* breakpoint spot: frotz.exp: test name */
4037 # and then write, in your test script (which we assume is named
4040 # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
4042 # (Yes, Tcl knows how to handle the nested quotes and brackets.
4045 # % puts "foo [lindex "bar baz" 1]"
4048 # Tcl is quite clever, for a little stringy language.)
4052 # The previous implementation of this procedure used the gdb search command.
4053 # This version is different:
4055 # . It works with MI, and it also works when gdb is not running.
4057 # . It operates on the build machine, not the host machine.
4059 # . For now, this implementation fakes a current directory of
4060 # $srcdir/$subdir to be compatible with the old implementation.
4061 # This will go away eventually and some callers will need to
4064 # . The TEXT argument is literal text and matches literally,
4065 # not a regular expression as it was before.
4067 # . State changes in gdb, such as changing the current file
4068 # and setting $_, no longer happen.
4070 # After a bit of time we can forget about the differences from the
4071 # old implementation.
4073 # --chastain 2004-08-05
4075 proc gdb_get_line_number { text { file "" } } {
4080 if { "$file" == "" } then {
4083 if { ! [regexp "^/" "$file"] } then {
4084 set file "$srcdir/$subdir/$file"
4087 if { [ catch { set fd [open "$file"] } message ] } then {
4092 for { set line 1 } { 1 } { incr line } {
4093 if { [ catch { set nchar [gets "$fd" body] } message ] } then {
4096 if { $nchar < 0 } then {
4099 if { [string first "$text" "$body"] >= 0 } then {
4105 if { [ catch { close "$fd" } message ] } then {
4110 error "undefined tag \"$text\""
4116 # Continue the program until it ends.
4118 # MSSG is the error message that gets printed. If not given, a
4120 # COMMAND is the command to invoke. If not given, "continue" is
4122 # ALLOW_EXTRA is a flag indicating whether the test should expect
4123 # extra output between the "Continuing." line and the program
4124 # exiting. By default it is zero; if nonzero, any extra output
4127 proc gdb_continue_to_end {{mssg ""} {command continue} {allow_extra 0}} {
4128 global inferior_exited_re use_gdb_stub
4131 set text "continue until exit"
4133 set text "continue until exit at $mssg"
4141 # By default, we don't rely on exit() behavior of remote stubs --
4142 # it's common for exit() to be implemented as a simple infinite
4143 # loop, or a forced crash/reset. For native targets, by default, we
4144 # assume process exit is reported as such. If a non-reliable target
4145 # is used, we set a breakpoint at exit, and continue to that.
4146 if { [target_info exists exit_is_reliable] } {
4147 set exit_is_reliable [target_info exit_is_reliable]
4149 set exit_is_reliable [expr ! $use_gdb_stub]
4152 if { ! $exit_is_reliable } {
4153 if {![gdb_breakpoint "exit"]} {
4156 gdb_test $command "Continuing..*Breakpoint .*exit.*" \
4159 # Continue until we exit. Should not stop again.
4160 # Don't bother to check the output of the program, that may be
4161 # extremely tough for some remote systems.
4163 "Continuing.\[\r\n0-9\]+${extra}(... EXIT code 0\[\r\n\]+|$inferior_exited_re normally).*"\
4168 proc rerun_to_main {} {
4169 global gdb_prompt use_gdb_stub
4174 -re ".*Breakpoint .*main .*$gdb_prompt $"\
4175 {pass "rerun to main" ; return 0}
4176 -re "$gdb_prompt $"\
4177 {fail "rerun to main" ; return 0}
4178 timeout {fail "(timeout) rerun to main" ; return 0}
4183 -re "The program .* has been started already.*y or n. $" {
4187 -re "Starting program.*$gdb_prompt $"\
4188 {pass "rerun to main" ; return 0}
4189 -re "$gdb_prompt $"\
4190 {fail "rerun to main" ; return 0}
4191 timeout {fail "(timeout) rerun to main" ; return 0}
4196 # Print a message and return true if a test should be skipped
4197 # due to lack of floating point suport.
4199 proc gdb_skip_float_test { msg } {
4200 if [target_info exists gdb,skip_float_tests] {
4201 verbose "Skipping test '$msg': no float tests."
4207 # Print a message and return true if a test should be skipped
4208 # due to lack of stdio support.
4210 proc gdb_skip_stdio_test { msg } {
4211 if [target_info exists gdb,noinferiorio] {
4212 verbose "Skipping test '$msg': no inferior i/o."
4218 proc gdb_skip_bogus_test { msg } {
4222 # Return true if a test should be skipped due to lack of XML support
4224 # NOTE: This must be called while gdb is *not* running.
4226 gdb_caching_proc gdb_skip_xml_test {
4230 set xml_file [gdb_remote_download host "${srcdir}/gdb.xml/trivial.xml"]
4234 gdb_test_multiple "set tdesc filename $xml_file" "" {
4235 -re ".*XML support was disabled at compile time.*$gdb_prompt $" {
4238 -re ".*$gdb_prompt $" { }
4244 # Return true if argv[0] is available.
4246 gdb_caching_proc gdb_has_argv0 {
4249 # Set up, compile, and execute a test program to check whether
4250 # argv[0] is available.
4251 set src [standard_temp_file has_argv0[pid].c]
4252 set exe [standard_temp_file has_argv0[pid].x]
4254 gdb_produce_source $src {
4255 int main (int argc, char **argv) {
4260 gdb_compile $src $exe executable {debug}
4263 proc gdb_has_argv0_1 { exe } {
4264 global srcdir subdir
4265 global gdb_prompt hex
4269 gdb_reinitialize_dir $srcdir/$subdir
4272 # Set breakpoint on main.
4273 gdb_test_multiple "break main" "break main" {
4274 -re "Breakpoint.*${gdb_prompt} $" {
4276 -re "${gdb_prompt} $" {
4283 gdb_test_multiple "" "run to main" {
4284 -re "Breakpoint.*${gdb_prompt} $" {
4286 -re "${gdb_prompt} $" {
4291 # Check whether argc is 1.
4292 gdb_test_multiple "p argc" "p argc" {
4293 -re " = 1\r\n${gdb_prompt} $" {
4295 gdb_test_multiple "p argv\[0\]" "p argv\[0\]" {
4296 -re " = $hex \".*[file tail $exe]\"\r\n${gdb_prompt} $" {
4299 -re "${gdb_prompt} $" {
4304 -re "${gdb_prompt} $" {
4311 set result [gdb_has_argv0_1 $exe]
4318 && ([istarget *-*-linux*]
4319 || [istarget *-*-freebsd*] || [istarget *-*-kfreebsd*]
4320 || [istarget *-*-netbsd*] || [istarget *-*-knetbsd*]
4321 || [istarget *-*-openbsd*]
4322 || [istarget *-*-darwin*]
4323 || [istarget *-*-solaris*]
4324 || [istarget *-*-aix*]
4325 || [istarget *-*-gnu*]
4326 || [istarget *-*-cygwin*] || [istarget *-*-mingw32*]
4327 || [istarget *-*-*djgpp*] || [istarget *-*-go32*]
4328 || [istarget *-wince-pe] || [istarget *-*-mingw32ce*]
4329 || [istarget *-*-symbianelf*]
4330 || [istarget *-*-osf*]
4331 || [istarget *-*-hpux*]
4332 || [istarget *-*-dicos*]
4333 || [istarget *-*-nto*]
4334 || [istarget *-*-*vms*]
4335 || [istarget *-*-lynx*178]) } {
4336 fail "argv\[0\] should be available on this target"
4342 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
4343 # ${binfile}.dbglnk, which is just like the executable ($binfile) but without
4344 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
4345 # the name of a debuginfo only file. This file will be stored in the same
4348 # Functions for separate debug info testing
4350 # starting with an executable:
4351 # foo --> original executable
4353 # at the end of the process we have:
4354 # foo.stripped --> foo w/o debug info
4355 # foo.debug --> foo's debug info
4356 # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug.
4358 # Fetch the build id from the file.
4359 # Returns "" if there is none.
4361 proc get_build_id { filename } {
4362 set tmp [standard_output_file "${filename}-tmp"]
4363 set objcopy_program [gdb_find_objcopy]
4365 set result [catch "exec $objcopy_program -j .note.gnu.build-id -O binary $filename $tmp" output]
4366 verbose "result is $result"
4367 verbose "output is $output"
4372 fconfigure $fi -translation binary
4373 # Skip the NOTE header.
4378 if ![string compare $data ""] then {
4381 # Convert it to hex.
4382 binary scan $data H* data
4386 # Return the build-id hex string (usually 160 bits as 40 hex characters)
4387 # converted to the form: .build-id/ab/cdef1234...89.debug
4388 # Return "" if no build-id found.
4389 proc build_id_debug_filename_get { filename } {
4390 set data [get_build_id $filename]
4391 if { $data == "" } {
4394 regsub {^..} $data {\0/} data
4395 return ".build-id/${data}.debug"
4398 # Create stripped files for DEST, replacing it. If ARGS is passed, it is a
4399 # list of optional flags. The only currently supported flag is no-main,
4400 # which removes the symbol entry for main from the separate debug file.
4402 # Function returns zero on success. Function will return non-zero failure code
4403 # on some targets not supporting separate debug info (such as i386-msdos).
4405 proc gdb_gnu_strip_debug { dest args } {
4407 # Use the first separate debug info file location searched by GDB so the
4408 # run cannot be broken by some stale file searched with higher precedence.
4409 set debug_file "${dest}.debug"
4411 set strip_to_file_program [transform strip]
4412 set objcopy_program [gdb_find_objcopy]
4414 set debug_link [file tail $debug_file]
4415 set stripped_file "${dest}.stripped"
4417 # Get rid of the debug info, and store result in stripped_file
4418 # something like gdb/testsuite/gdb.base/blah.stripped.
4419 set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
4420 verbose "result is $result"
4421 verbose "output is $output"
4426 # Workaround PR binutils/10802:
4427 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
4428 set perm [file attributes ${dest} -permissions]
4429 file attributes ${stripped_file} -permissions $perm
4431 # Get rid of everything but the debug info, and store result in debug_file
4432 # This will be in the .debug subdirectory, see above.
4433 set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
4434 verbose "result is $result"
4435 verbose "output is $output"
4440 # If no-main is passed, strip the symbol for main from the separate
4441 # file. This is to simulate the behavior of elfutils's eu-strip, which
4442 # leaves the symtab in the original file only. There's no way to get
4443 # objcopy or strip to remove the symbol table without also removing the
4444 # debugging sections, so this is as close as we can get.
4445 if { [llength $args] == 1 && [lindex $args 0] == "no-main" } {
4446 set result [catch "exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp" output]
4447 verbose "result is $result"
4448 verbose "output is $output"
4452 file delete "${debug_file}"
4453 file rename "${debug_file}-tmp" "${debug_file}"
4456 # Link the two previous output files together, adding the .gnu_debuglink
4457 # section to the stripped_file, containing a pointer to the debug_file,
4458 # save the new file in dest.
4459 # This will be the regular executable filename, in the usual location.
4460 set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
4461 verbose "result is $result"
4462 verbose "output is $output"
4467 # Workaround PR binutils/10802:
4468 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
4469 set perm [file attributes ${stripped_file} -permissions]
4470 file attributes ${dest} -permissions $perm
4475 # Test the output of GDB_COMMAND matches the pattern obtained
4476 # by concatenating all elements of EXPECTED_LINES. This makes
4477 # it possible to split otherwise very long string into pieces.
4478 # If third argument is not empty, it's used as the name of the
4479 # test to be printed on pass/fail.
4480 proc help_test_raw { gdb_command expected_lines args } {
4481 set message $gdb_command
4482 if [llength $args]>0 then {
4483 set message [lindex $args 0]
4485 set expected_output [join $expected_lines ""]
4486 gdb_test "${gdb_command}" "${expected_output}" $message
4489 # Test the output of "help COMMAND_CLASS". EXPECTED_INITIAL_LINES
4490 # are regular expressions that should match the beginning of output,
4491 # before the list of commands in that class. The presence of
4492 # command list and standard epilogue will be tested automatically.
4493 proc test_class_help { command_class expected_initial_lines args } {
4495 "List of commands\:.*\[\r\n\]+"
4496 "Type \"help\" followed by command name for full documentation\.\[\r\n\]+"
4497 "Type \"apropos word\" to search for commands related to \"word\"\.[\r\n\]+"
4498 "Command name abbreviations are allowed if unambiguous\."
4500 set l_entire_body [concat $expected_initial_lines $l_stock_body]
4502 eval [list help_test_raw "help ${command_class}" $l_entire_body] $args
4505 # COMMAND_LIST should have either one element -- command to test, or
4506 # two elements -- abbreviated command to test, and full command the first
4507 # element is abbreviation of.
4508 # The command must be a prefix command. EXPECTED_INITIAL_LINES
4509 # are regular expressions that should match the beginning of output,
4510 # before the list of subcommands. The presence of
4511 # subcommand list and standard epilogue will be tested automatically.
4512 proc test_prefix_command_help { command_list expected_initial_lines args } {
4513 set command [lindex $command_list 0]
4514 if {[llength $command_list]>1} {
4515 set full_command [lindex $command_list 1]
4517 set full_command $command
4519 # Use 'list' and not just {} because we want variables to
4520 # be expanded in this list.
4521 set l_stock_body [list\
4522 "List of $full_command subcommands\:.*\[\r\n\]+"\
4523 "Type \"help $full_command\" followed by $full_command subcommand name for full documentation\.\[\r\n\]+"\
4524 "Type \"apropos word\" to search for commands related to \"word\"\.\[\r\n\]+"\
4525 "Command name abbreviations are allowed if unambiguous\."]
4526 set l_entire_body [concat $expected_initial_lines $l_stock_body]
4527 if {[llength $args]>0} {
4528 help_test_raw "help ${command}" $l_entire_body [lindex $args 0]
4530 help_test_raw "help ${command}" $l_entire_body
4534 # Build executable named EXECUTABLE from specifications that allow
4535 # different options to be passed to different sub-compilations.
4536 # TESTNAME is the name of the test; this is passed to 'untested' if
4538 # OPTIONS is passed to the final link, using gdb_compile. If OPTIONS
4539 # contains the option "pthreads", then gdb_compile_pthreads is used.
4540 # ARGS is a flat list of source specifications, of the form:
4541 # { SOURCE1 OPTIONS1 [ SOURCE2 OPTIONS2 ]... }
4542 # Each SOURCE is compiled to an object file using its OPTIONS,
4543 # using gdb_compile.
4544 # Returns 0 on success, -1 on failure.
4545 proc build_executable_from_specs {testname executable options args} {
4549 set binfile [standard_output_file $executable]
4552 if { [lsearch -exact $options "c++"] >= 0 } {
4553 set info_options "c++"
4555 if [get_compiler_info ${info_options}] {
4559 set func gdb_compile
4560 set func_index [lsearch -regexp $options {^(pthreads|shlib|shlib_pthreads)$}]
4561 if {$func_index != -1} {
4562 set func "${func}_[lindex $options $func_index]"
4565 # gdb_compile_shlib and gdb_compile_shlib_pthreads do not use the 3rd
4566 # parameter. They also requires $sources while gdb_compile and
4567 # gdb_compile_pthreads require $objects. Moreover they ignore any options.
4568 if [string match gdb_compile_shlib* $func] {
4570 foreach {s local_options} $args {
4571 if { [regexp "^/" "$s"] } then {
4572 lappend sources_path "$s"
4574 lappend sources_path "$srcdir/$subdir/$s"
4577 set ret [$func $sources_path "${binfile}" $options]
4581 foreach {s local_options} $args {
4582 if { ! [regexp "^/" "$s"] } then {
4583 set s "$srcdir/$subdir/$s"
4585 if { [gdb_compile "${s}" "${binfile}${i}.o" object $local_options] != "" } {
4589 lappend objects "${binfile}${i}.o"
4592 set ret [$func $objects "${binfile}" executable $options]
4602 # Build executable named EXECUTABLE, from SOURCES. If SOURCES are not
4603 # provided, uses $EXECUTABLE.c. The TESTNAME paramer is the name of test
4604 # to pass to untested, if something is wrong. OPTIONS are passed
4605 # to gdb_compile directly.
4606 proc build_executable { testname executable {sources ""} {options {debug}} } {
4607 if {[llength $sources]==0} {
4608 set sources ${executable}.c
4611 set arglist [list $testname $executable $options]
4612 foreach source $sources {
4613 lappend arglist $source $options
4616 return [eval build_executable_from_specs $arglist]
4619 # Starts fresh GDB binary and loads EXECUTABLE into GDB. EXECUTABLE is
4620 # the basename of the binary.
4621 proc clean_restart { executable } {
4624 set binfile [standard_output_file ${executable}]
4628 gdb_reinitialize_dir $srcdir/$subdir
4632 # Prepares for testing by calling build_executable_full, then
4634 # TESTNAME is the name of the test.
4635 # Each element in ARGS is a list of the form
4636 # { EXECUTABLE OPTIONS SOURCE_SPEC... }
4637 # These are passed to build_executable_from_specs, which see.
4638 # The last EXECUTABLE is passed to clean_restart.
4639 # Returns 0 on success, non-zero on failure.
4640 proc prepare_for_testing_full {testname args} {
4641 foreach spec $args {
4642 if {[eval build_executable_from_specs [list $testname] $spec] == -1} {
4645 set executable [lindex $spec 0]
4647 clean_restart $executable
4651 # Prepares for testing, by calling build_executable, and then clean_restart.
4652 # Please refer to build_executable for parameter description.
4653 proc prepare_for_testing { testname executable {sources ""} {options {debug}}} {
4655 if {[build_executable $testname $executable $sources $options] == -1} {
4658 clean_restart $executable
4663 proc get_valueof { fmt exp default } {
4666 set test "get valueof \"${exp}\""
4668 gdb_test_multiple "print${fmt} ${exp}" "$test" {
4669 -re "\\$\[0-9\]* = (.*)\[\r\n\]*$gdb_prompt $" {
4670 set val $expect_out(1,string)
4674 fail "$test (timeout)"
4680 proc get_integer_valueof { exp default } {
4683 set test "get integer valueof \"${exp}\""
4685 gdb_test_multiple "print /d ${exp}" "$test" {
4686 -re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" {
4687 set val $expect_out(1,string)
4691 fail "$test (timeout)"
4697 proc get_hexadecimal_valueof { exp default } {
4699 send_gdb "print /x ${exp}\n"
4700 set test "get hexadecimal valueof \"${exp}\""
4702 -re "\\$\[0-9\]* = (0x\[0-9a-zA-Z\]+).*$gdb_prompt $" {
4703 set val $expect_out(1,string)
4708 fail "$test (timeout)"
4714 proc get_sizeof { type default } {
4715 return [get_integer_valueof "sizeof (${type})" $default]
4718 proc get_target_charset { } {
4721 gdb_test_multiple "show target-charset" "" {
4722 -re "The target character set is \"auto; currently (\[^\"\]*)\".*$gdb_prompt $" {
4723 return $expect_out(1,string)
4725 -re "The target character set is \"(\[^\"\]*)\".*$gdb_prompt $" {
4726 return $expect_out(1,string)
4730 # Pick a reasonable default.
4731 warning "Unable to read target-charset."
4735 # Get the current value for remotetimeout and return it.
4736 proc get_remotetimeout { } {
4740 gdb_test_multiple "show remotetimeout" "" {
4741 -re "Timeout limit to wait for target to respond is ($decimal).*$gdb_prompt $" {
4742 return $expect_out(1,string)
4746 # Pick the default that gdb uses
4747 warning "Unable to read remotetimeout"
4751 # Set the remotetimeout to the specified timeout. Nothing is returned.
4752 proc set_remotetimeout { timeout } {
4755 gdb_test_multiple "set remotetimeout $timeout" "" {
4756 -re "$gdb_prompt $" {
4757 verbose "Set remotetimeout to $timeout\n"
4762 # ROOT and FULL are file names. Returns the relative path from ROOT
4763 # to FULL. Note that FULL must be in a subdirectory of ROOT.
4764 # For example, given ROOT = /usr/bin and FULL = /usr/bin/ls, this
4767 proc relative_filename {root full} {
4768 set root_split [file split $root]
4769 set full_split [file split $full]
4771 set len [llength $root_split]
4773 if {[eval file join $root_split]
4774 != [eval file join [lrange $full_split 0 [expr {$len - 1}]]]} {
4775 error "$full not a subdir of $root"
4778 return [eval file join [lrange $full_split $len end]]
4781 # Log gdb command line and script if requested.
4782 if {[info exists TRANSCRIPT]} {
4783 rename send_gdb real_send_gdb
4784 rename remote_spawn real_remote_spawn
4785 rename remote_close real_remote_close
4787 global gdb_transcript
4788 set gdb_transcript ""
4790 global gdb_trans_count
4791 set gdb_trans_count 1
4793 proc remote_spawn {args} {
4794 global gdb_transcript gdb_trans_count outdir
4796 if {$gdb_transcript != ""} {
4797 close $gdb_transcript
4799 set gdb_transcript [open [file join $outdir transcript.$gdb_trans_count] w]
4800 puts $gdb_transcript [lindex $args 1]
4801 incr gdb_trans_count
4803 return [uplevel real_remote_spawn $args]
4806 proc remote_close {args} {
4807 global gdb_transcript
4809 if {$gdb_transcript != ""} {
4810 close $gdb_transcript
4811 set gdb_transcript ""
4814 return [uplevel real_remote_close $args]
4817 proc send_gdb {args} {
4818 global gdb_transcript
4820 if {$gdb_transcript != ""} {
4821 puts -nonewline $gdb_transcript [lindex $args 0]
4824 return [uplevel real_send_gdb $args]
4828 # If GDB_PARALLEL exists, then set up the parallel-mode directories.
4829 if {[info exists GDB_PARALLEL]} {
4830 if {[is_remote host]} {
4833 file mkdir outputs temp cache
4837 proc core_find {binfile {deletefiles {}} {arg ""}} {
4838 global objdir subdir
4840 set destcore "$binfile.core"
4841 file delete $destcore
4843 # Create a core file named "$destcore" rather than just "core", to
4844 # avoid problems with sys admin types that like to regularly prune all
4845 # files named "core" from the system.
4847 # Arbitrarily try setting the core size limit to "unlimited" since
4848 # this does not hurt on systems where the command does not work and
4849 # allows us to generate a core on systems where it does.
4851 # Some systems append "core" to the name of the program; others append
4852 # the name of the program to "core"; still others (like Linux, as of
4853 # May 2003) create cores named "core.PID". In the latter case, we
4854 # could have many core files lying around, and it may be difficult to
4855 # tell which one is ours, so let's run the program in a subdirectory.
4857 set coredir [standard_output_file coredir.[getpid]]
4859 catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile} ${arg}; true) >/dev/null 2>&1\""
4860 # remote_exec host "${binfile}"
4861 foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
4862 if [remote_file build exists $i] {
4863 remote_exec build "mv $i $destcore"
4867 # Check for "core.PID".
4868 if { $found == 0 } {
4869 set names [glob -nocomplain -directory $coredir core.*]
4870 if {[llength $names] == 1} {
4871 set corefile [file join $coredir [lindex $names 0]]
4872 remote_exec build "mv $corefile $destcore"
4876 if { $found == 0 } {
4877 # The braindamaged HPUX shell quits after the ulimit -c above
4878 # without executing ${binfile}. So we try again without the
4879 # ulimit here if we didn't find a core file above.
4880 # Oh, I should mention that any "braindamaged" non-Unix system has
4881 # the same problem. I like the cd bit too, it's really neat'n stuff.
4882 catch "system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\""
4883 foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" {
4884 if [remote_file build exists $i] {
4885 remote_exec build "mv $i $destcore"
4891 # Try to clean up after ourselves.
4892 foreach deletefile $deletefiles {
4893 remote_file build delete [file join $coredir $deletefile]
4895 remote_exec build "rmdir $coredir"
4897 if { $found == 0 } {
4898 warning "can't generate a core file - core tests suppressed - check ulimit -c"
4904 # gdb_target_symbol_prefix_flags returns a string that can be added
4905 # to gdb_compile options to define SYMBOL_PREFIX macro value
4906 # symbol_prefix_flags returns a string that can be added
4907 # for targets that use underscore as symbol prefix.
4908 # TODO: find out automatically if the target needs this.
4910 proc gdb_target_symbol_prefix_flags {} {
4911 if { [istarget "*-*-cygwin*"] || [istarget "i?86-*-mingw*"]
4912 || [istarget "*-*-msdosdjgpp*"] || [istarget "*-*-go32*"] } {
4913 return "additional_flags=-DSYMBOL_PREFIX=\"_\""
4919 # A wrapper for 'remote_exec host' that passes or fails a test.
4920 # Returns 0 if all went well, nonzero on failure.
4921 # TEST is the name of the test, other arguments are as for remote_exec.
4923 proc run_on_host { test program args } {
4924 verbose -log "run_on_host: $program $args"
4925 # remote_exec doesn't work properly if the output is set but the
4926 # input is the empty string -- so replace an empty input with
4928 if {[llength $args] > 1 && [lindex $args 1] == ""} {
4929 set args [lreplace $args 1 1 "/dev/null"]
4931 set result [eval remote_exec host [list $program] $args]
4932 verbose "result is $result"
4933 set status [lindex $result 0]
4934 set output [lindex $result 1]
4939 verbose -log "run_on_host failed: $output"
4945 # Return non-zero if "board_info debug_flags" mentions Fission.
4946 # http://gcc.gnu.org/wiki/DebugFission
4947 # Fission doesn't support everything yet.
4948 # This supports working around bug 15954.
4950 proc using_fission { } {
4951 set debug_flags [board_info [target_info name] debug_flags]
4952 return [regexp -- "-gsplit-dwarf" $debug_flags]
4955 # Search the caller's ARGS list and set variables according to the list of
4956 # valid options described by ARGSET.
4958 # The first member of each one- or two-element list in ARGSET defines the
4959 # name of a variable that will be added to the caller's scope.
4961 # If only one element is given to describe an option, it the value is
4962 # 0 if the option is not present in (the caller's) ARGS or 1 if
4965 # If two elements are given, the second element is the default value of
4966 # the variable. This is then overwritten if the option exists in ARGS.
4968 # Any parse_args elements in (the caller's) ARGS will be removed, leaving
4969 # any optional components.
4972 # proc myproc {foo args} {
4973 # parse_args {{bar} {baz "abc"} {qux}}
4976 # myproc ABC -bar -baz DEF peanut butter
4977 # will define the following variables in myproc:
4978 # foo (=ABC), bar (=1), baz (=DEF), and qux (=0)
4979 # args will be the list {peanut butter}
4981 proc parse_args { argset } {
4984 foreach argument $argset {
4985 if {[llength $argument] == 1} {
4986 # No default specified, so we assume that we should set
4987 # the value to 1 if the arg is present and 0 if it's not.
4988 # It is assumed that no value is given with the argument.
4989 set result [lsearch -exact $args "-$argument"]
4990 if {$result != -1} then {
4991 uplevel 1 [list set $argument 1]
4992 set args [lreplace $args $result $result]
4994 uplevel 1 [list set $argument 0]
4996 } elseif {[llength $argument] == 2} {
4997 # There are two items in the argument. The second is a
4998 # default value to use if the item is not present.
4999 # Otherwise, the variable is set to whatever is provided
5000 # after the item in the args.
5001 set arg [lindex $argument 0]
5002 set result [lsearch -exact $args "-[lindex $arg 0]"]
5003 if {$result != -1} then {
5004 uplevel 1 [list set $arg [lindex $args [expr $result+1]]]
5005 set args [lreplace $args $result [expr $result+1]]
5007 uplevel 1 [list set $arg [lindex $argument 1]]
5010 error "Badly formatted argument \"$argument\" in argument set"
5014 # The remaining args should be checked to see that they match the
5015 # number of items expected to be passed into the procedure...
5018 # Capture the output of COMMAND in a string ignoring PREFIX; return that string.
5019 proc capture_command_output { command prefix } {
5023 set output_string ""
5024 gdb_test_multiple "$command" "capture_command_output for $command" {
5025 -re "${command}\[\r\n\]+${prefix}(.*)\[\r\n\]+$gdb_prompt $" {
5026 set output_string $expect_out(1,string)
5029 return $output_string
5032 # Always load compatibility stuff.