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"
33 if [info exists TOOL_EXECUTABLE] {
34 set GDB $TOOL_EXECUTABLE
36 if ![info exists GDB] {
37 if ![is_remote host] {
38 set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]]
40 set GDB [transform gdb]
43 verbose "using GDB = $GDB" 2
45 # GDBFLAGS is available for the user to set on the command line.
46 # E.g. make check RUNTESTFLAGS=GDBFLAGS=mumble
47 # Testcases may use it to add additional flags, but they must:
48 # - append new flags, not overwrite
49 # - restore the original value when done
51 if ![info exists GDBFLAGS] {
54 verbose "using GDBFLAGS = $GDBFLAGS" 2
56 # Make the build data directory available to tests.
57 set BUILD_DATA_DIRECTORY "[pwd]/../data-directory"
59 # INTERNAL_GDBFLAGS contains flags that the testsuite requires.
60 global INTERNAL_GDBFLAGS
61 if ![info exists INTERNAL_GDBFLAGS] {
62 set INTERNAL_GDBFLAGS "-nw -nx -data-directory $BUILD_DATA_DIRECTORY"
65 # The variable gdb_prompt is a regexp which matches the gdb prompt.
66 # Set it if it is not already set.
68 if ![info exists gdb_prompt] then {
69 set gdb_prompt "\[(\]gdb\[)\]"
72 # The variable fullname_syntax_POSIX is a regexp which matches a POSIX
73 # absolute path ie. /foo/
74 set fullname_syntax_POSIX {/[^\n]*/}
75 # The variable fullname_syntax_UNC is a regexp which matches a Windows
76 # UNC path ie. \\D\foo\
77 set fullname_syntax_UNC {\\\\[^\\]+\\[^\n]+\\}
78 # The variable fullname_syntax_DOS_CASE is a regexp which matches a
79 # particular DOS case that GDB most likely will output
80 # ie. \foo\, but don't match \\.*\
81 set fullname_syntax_DOS_CASE {\\[^\\][^\n]*\\}
82 # The variable fullname_syntax_DOS is a regexp which matches a DOS path
83 # ie. a:\foo\ && a:foo\
84 set fullname_syntax_DOS {[a-zA-Z]:[^\n]*\\}
85 # The variable fullname_syntax is a regexp which matches what GDB considers
86 # an absolute path. It is currently debatable if the Windows style paths
87 # d:foo and \abc should be considered valid as an absolute path.
88 # Also, the purpse of this regexp is not to recognize a well formed
89 # absolute path, but to say with certainty that a path is absolute.
90 set fullname_syntax "($fullname_syntax_POSIX|$fullname_syntax_UNC|$fullname_syntax_DOS_CASE|$fullname_syntax_DOS)"
92 # Needed for some tests under Cygwin.
96 if ![info exists env(EXEEXT)] {
99 set EXEEXT $env(EXEEXT)
104 set inferior_exited_re "(\\\[Inferior \[0-9\]+ \\(.*\\) exited)"
106 ### Only procedures should come after this point.
109 # gdb_version -- extract and print the version number of GDB
111 proc default_gdb_version {} {
113 global INTERNAL_GDBFLAGS GDBFLAGS
117 if {[info exists inotify_pid]} {
118 eval exec kill $inotify_pid
121 set output [remote_exec host "$GDB $INTERNAL_GDBFLAGS --version"]
122 set tmp [lindex $output 1]
124 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
125 if ![is_remote host] {
126 clone_output "[which $GDB] version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
128 clone_output "$GDB on remote host version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
132 proc gdb_version { } {
133 return [default_gdb_version]
137 # gdb_unload -- unload a file if one is loaded
138 # Return 0 on success, -1 on error.
147 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
148 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
149 -re "A program is being debugged already.*Are you sure you want to change the file.*y or n. $" {
153 -re "Discard symbol table from .*y or n.*$" {
157 -re "$gdb_prompt $" {}
159 perror "couldn't unload file in $GDB (timeout)."
166 # Many of the tests depend on setting breakpoints at various places and
167 # running until that breakpoint is reached. At times, we want to start
168 # with a clean-slate with respect to breakpoints, so this utility proc
169 # lets us do this without duplicating this code everywhere.
172 proc delete_breakpoints {} {
175 # we need a larger timeout value here or this thing just confuses
176 # itself. May need a better implementation if possible. - guo
178 send_gdb "delete breakpoints\n"
180 -re "Delete all breakpoints.*y or n.*$" {
184 -re "$gdb_prompt $" { # This happens if there were no breakpoints
186 timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
188 send_gdb "info breakpoints\n"
190 -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
191 -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
192 -re "Delete all breakpoints.*or n.*$" {
196 timeout { perror "info breakpoints (timeout)" ; return }
200 # Generic run command.
202 # The second pattern below matches up to the first newline *only*.
203 # Using ``.*$'' could swallow up output that we attempt to match
206 # N.B. This function does not wait for gdb to return to the prompt,
207 # that is the caller's responsibility.
209 proc gdb_run_cmd {args} {
210 global gdb_prompt use_gdb_stub
212 if [target_info exists gdb_init_command] {
213 send_gdb "[target_info gdb_init_command]\n"
215 -re "$gdb_prompt $" { }
217 perror "gdb_init_command for target failed"
224 if [target_info exists gdb,do_reload_on_run] {
225 if { [gdb_reload] != 0 } {
228 send_gdb "continue\n"
230 -re "Continu\[^\r\n\]*\[\r\n\]" {}
236 if [target_info exists gdb,start_symbol] {
237 set start [target_info gdb,start_symbol]
241 send_gdb "jump *$start\n"
243 while { $start_attempt } {
244 # Cap (re)start attempts at three to ensure that this loop
245 # always eventually fails. Don't worry about trying to be
246 # clever and not send a command when it has failed.
247 if [expr $start_attempt > 3] {
248 perror "Jump to start() failed (retry count exceeded)"
251 set start_attempt [expr $start_attempt + 1]
253 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
256 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
257 perror "Can't find start symbol to run in gdb_run"
260 -re "No symbol \"start\" in current.*$gdb_prompt $" {
261 send_gdb "jump *_start\n"
263 -re "No symbol.*context.*$gdb_prompt $" {
266 -re "Line.* Jump anyway.*y or n. $" {
269 -re "The program is not being run.*$gdb_prompt $" {
270 if { [gdb_reload] != 0 } {
273 send_gdb "jump *$start\n"
276 perror "Jump to start() failed (timeout)"
284 if [target_info exists gdb,do_reload_on_run] {
285 if { [gdb_reload] != 0 } {
289 send_gdb "run $args\n"
290 # This doesn't work quite right yet.
291 # Use -notransfer here so that test cases (like chng-sym.exp)
292 # may test for additional start-up messages.
294 -re "The program .* has been started already.*y or n. $" {
298 -notransfer -re "Starting program: \[^\r\n\]*" {}
299 -notransfer -re "$gdb_prompt $" {
300 # There is no more input expected.
305 # Generic start command. Return 0 if we could start the program, -1
308 # N.B. This function does not wait for gdb to return to the prompt,
309 # that is the caller's responsibility.
311 proc gdb_start_cmd {args} {
312 global gdb_prompt use_gdb_stub
314 if [target_info exists gdb_init_command] {
315 send_gdb "[target_info gdb_init_command]\n"
317 -re "$gdb_prompt $" { }
319 perror "gdb_init_command for target failed"
329 send_gdb "start $args\n"
330 # Use -notransfer here so that test cases (like chng-sym.exp)
331 # may test for additional start-up messages.
333 -re "The program .* has been started already.*y or n. $" {
337 -notransfer -re "Starting program: \[^\r\n\]*" {
344 # Set a breakpoint at FUNCTION. If there is an additional argument it is
345 # a list of options; the supported options are allow-pending, temporary,
346 # message, no-message, and passfail.
347 # The result is 1 for success, 0 for failure.
349 # Note: The handling of message vs no-message is messed up, but it's based
350 # on historical usage. By default this function does not print passes,
352 # no-message: turns off printing of fails (and passes, but they're already off)
353 # message: turns on printing of passes (and fails, but they're already on)
355 proc gdb_breakpoint { function args } {
359 set pending_response n
360 if {[lsearch -exact $args allow-pending] != -1} {
361 set pending_response y
364 set break_command "break"
365 set break_message "Breakpoint"
366 if {[lsearch -exact $args temporary] != -1} {
367 set break_command "tbreak"
368 set break_message "Temporary breakpoint"
373 set no_message_loc [lsearch -exact $args no-message]
374 set message_loc [lsearch -exact $args message]
375 # The last one to appear in args wins.
376 if { $no_message_loc > $message_loc } {
378 } elseif { $message_loc > $no_message_loc } {
382 set test_name "setting breakpoint at $function"
384 send_gdb "$break_command $function\n"
385 # The first two regexps are what we get with -g, the third is without -g.
387 -re "$break_message \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
388 -re "$break_message \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
389 -re "$break_message \[0-9\]* at .*$gdb_prompt $" {}
390 -re "$break_message \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" {
391 if {$pending_response == "n"} {
398 -re "Make breakpoint pending.*y or \\\[n\\\]. $" {
399 send_gdb "$pending_response\n"
402 -re "A problem internal to GDB has been detected" {
404 fail "$test_name (GDB internal error)"
406 gdb_internal_error_resync
409 -re "$gdb_prompt $" {
417 fail "$test_name (eof)"
423 fail "$test_name (timeout)"
434 # Set breakpoint at function and run gdb until it breaks there.
435 # Since this is the only breakpoint that will be set, if it stops
436 # at a breakpoint, we will assume it is the one we want. We can't
437 # just compare to "function" because it might be a fully qualified,
438 # single quoted C++ function specifier.
440 # If there are additional arguments, pass them to gdb_breakpoint.
441 # We recognize no-message/message ourselves.
442 # The default is no-message.
443 # no-message is messed up here, like gdb_breakpoint: to preserve
444 # historical usage fails are always printed by default.
445 # no-message: turns off printing of fails (and passes, but they're already off)
446 # message: turns on printing of passes (and fails, but they're already on)
448 proc runto { function args } {
454 # Default to "no-message".
455 set args "no-message $args"
459 set no_message_loc [lsearch -exact $args no-message]
460 set message_loc [lsearch -exact $args message]
461 # The last one to appear in args wins.
462 if { $no_message_loc > $message_loc } {
464 } elseif { $message_loc > $no_message_loc } {
468 set test_name "running to $function in runto"
470 # We need to use eval here to pass our varargs args to gdb_breakpoint
471 # which is also a varargs function.
472 # But we also have to be careful because $function may have multiple
473 # elements, and we don't want Tcl to move the remaining elements after
474 # the first to $args. That is why $function is wrapped in {}.
475 if ![eval gdb_breakpoint {$function} $args] {
481 # the "at foo.c:36" output we get with -g.
482 # the "in func" output we get without -g.
484 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
490 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
496 -re "The target does not support running in non-stop mode.\r\n$gdb_prompt $" {
498 unsupported "Non-stop mode not supported"
502 -re ".*A problem internal to GDB has been detected" {
504 fail "$test_name (GDB internal error)"
506 gdb_internal_error_resync
509 -re "$gdb_prompt $" {
517 fail "$test_name (eof)"
523 fail "$test_name (timeout)"
534 # Ask gdb to run until we hit a breakpoint at main.
536 # N.B. This function deletes all existing breakpoints.
537 # If you don't want that, use gdb_start_cmd.
539 proc runto_main { } {
540 return [runto main no-message]
543 ### Continue, and expect to hit a breakpoint.
544 ### Report a pass or fail, depending on whether it seems to have
545 ### worked. Use NAME as part of the test name; each call to
546 ### continue_to_breakpoint should use a NAME which is unique within
548 proc gdb_continue_to_breakpoint {name {location_pattern .*}} {
550 set full_name "continue to breakpoint: $name"
552 gdb_test_multiple "continue" $full_name {
553 -re "(?:Breakpoint|Temporary breakpoint) .* (at|in) $location_pattern\r\n$gdb_prompt $" {
560 # gdb_internal_error_resync:
562 # Answer the questions GDB asks after it reports an internal error
563 # until we get back to a GDB prompt. Decline to quit the debugging
564 # session, and decline to create a core file. Return non-zero if the
567 # This procedure just answers whatever questions come up until it sees
568 # a GDB prompt; it doesn't require you to have matched the input up to
569 # any specific point. However, it only answers questions it sees in
570 # the output itself, so if you've matched a question, you had better
571 # answer it yourself before calling this.
573 # You can use this function thus:
577 # -re ".*A problem internal to GDB has been detected" {
578 # gdb_internal_error_resync
583 proc gdb_internal_error_resync {} {
586 verbose -log "Resyncing due to internal error."
589 while {$count < 10} {
591 -re "Quit this debugging session\\? \\(y or n\\) $" {
595 -re "Create a core file of GDB\\? \\(y or n\\) $" {
599 -re "$gdb_prompt $" {
600 # We're resynchronized.
604 perror "Could not resync from internal error (timeout)"
609 perror "Could not resync from internal error (resync count exceeded)"
614 # gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS
615 # Send a command to gdb; test the result.
617 # COMMAND is the command to execute, send to GDB with send_gdb. If
618 # this is the null string no command is sent.
619 # MESSAGE is a message to be printed with the built-in failure patterns
620 # if one of them matches. If MESSAGE is empty COMMAND will be used.
621 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
622 # patterns. Pattern elements will be evaluated in the caller's
623 # context; action elements will be executed in the caller's context.
624 # Unlike patterns for gdb_test, these patterns should generally include
625 # the final newline and prompt.
628 # 1 if the test failed, according to a built-in failure pattern
629 # 0 if only user-supplied patterns matched
630 # -1 if there was an internal error.
632 # You can use this function thus:
634 # gdb_test_multiple "print foo" "test foo" {
635 # -re "expected output 1" {
638 # -re "expected output 2" {
643 # The standard patterns, such as "Inferior exited..." and "A problem
644 # ...", all being implicitly appended to that list.
646 proc gdb_test_multiple { command message user_code } {
647 global verbose use_gdb_stub
650 global inferior_exited_re
651 upvar timeout timeout
652 upvar expect_out expect_out
654 if { $message == "" } {
658 if [string match "*\[\r\n\]" $command] {
659 error "Invalid trailing newline in \"$message\" test"
662 if [string match "*\[\r\n\]*" $message] {
663 error "Invalid newline in \"$message\" test"
667 && [regexp -nocase {^\s*(r|run|star|start|at|att|atta|attac|attach)\M} \
669 error "gdbserver does not support $command without extended-remote"
672 # TCL/EXPECT WART ALERT
673 # Expect does something very strange when it receives a single braced
674 # argument. It splits it along word separators and performs substitutions.
675 # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
676 # evaluated as "\[ab\]". But that's not how TCL normally works; inside a
677 # double-quoted list item, "\[ab\]" is just a long way of representing
678 # "[ab]", because the backslashes will be removed by lindex.
680 # Unfortunately, there appears to be no easy way to duplicate the splitting
681 # that expect will do from within TCL. And many places make use of the
682 # "\[0-9\]" construct, so we need to support that; and some places make use
683 # of the "[func]" construct, so we need to support that too. In order to
684 # get this right we have to substitute quoted list elements differently
685 # from braced list elements.
687 # We do this roughly the same way that Expect does it. We have to use two
688 # lists, because if we leave unquoted newlines in the argument to uplevel
689 # they'll be treated as command separators, and if we escape newlines
690 # we mangle newlines inside of command blocks. This assumes that the
691 # input doesn't contain a pattern which contains actual embedded newlines
694 regsub -all {\n} ${user_code} { } subst_code
695 set subst_code [uplevel list $subst_code]
697 set processed_code ""
699 set expecting_action 0
701 foreach item $user_code subst_item $subst_code {
702 if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } {
703 lappend processed_code $item
706 if { $item == "-indices" || $item == "-re" || $item == "-ex" } {
707 lappend processed_code $item
710 if { $item == "-timeout" } {
712 lappend processed_code $item
715 if { $expecting_arg } {
717 lappend processed_code $item
720 if { $expecting_action } {
721 lappend processed_code "uplevel [list $item]"
722 set expecting_action 0
723 # Cosmetic, no effect on the list.
724 append processed_code "\n"
727 set expecting_action 1
728 lappend processed_code $subst_item
729 if {$patterns != ""} {
732 append patterns "\"$subst_item\""
735 # Also purely cosmetic.
736 regsub -all {\r} $patterns {\\r} patterns
737 regsub -all {\n} $patterns {\\n} patterns
740 send_user "Sending \"$command\" to gdb\n"
741 send_user "Looking to match \"$patterns\"\n"
742 send_user "Message is \"$message\"\n"
746 set string "${command}\n"
747 if { $command != "" } {
748 set multi_line_re "\[\r\n\] *>"
749 while { "$string" != "" } {
750 set foo [string first "\n" "$string"]
751 set len [string length "$string"]
752 if { $foo < [expr $len - 1] } {
753 set str [string range "$string" 0 $foo]
754 if { [send_gdb "$str"] != "" } {
757 if { ! $suppress_flag } {
758 perror "Couldn't send $command to GDB."
763 # since we're checking if each line of the multi-line
764 # command are 'accepted' by GDB here,
765 # we need to set -notransfer expect option so that
766 # command output is not lost for pattern matching
769 -notransfer -re "$multi_line_re$" { verbose "partial: match" 3 }
770 timeout { verbose "partial: timeout" 3 }
772 set string [string range "$string" [expr $foo + 1] end]
773 set multi_line_re "$multi_line_re.*\[\r\n\] *>"
778 if { "$string" != "" } {
779 if { [send_gdb "$string"] != "" } {
782 if { ! $suppress_flag } {
783 perror "Couldn't send $command to GDB."
791 if [target_info exists gdb,timeout] {
792 set tmt [target_info gdb,timeout]
794 if [info exists timeout] {
798 if [info exists timeout] {
807 -re ".*A problem internal to GDB has been detected" {
808 fail "$message (GDB internal error)"
809 gdb_internal_error_resync
811 -re "\\*\\*\\* DOSEXIT code.*" {
812 if { $message != "" } {
815 gdb_suppress_entire_file "GDB died"
819 append code $processed_code
821 -re "Ending remote debugging.*$gdb_prompt $" {
822 if ![isnative] then {
823 warning "Can`t communicate to remote target."
829 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
830 perror "Undefined command \"$command\"."
834 -re "Ambiguous command.*$gdb_prompt $" {
835 perror "\"$command\" is not a unique command name."
839 -re "$inferior_exited_re with code \[0-9\]+.*$gdb_prompt $" {
840 if ![string match "" $message] then {
841 set errmsg "$message (the program exited)"
843 set errmsg "$command (the program exited)"
848 -re "$inferior_exited_re normally.*$gdb_prompt $" {
849 if ![string match "" $message] then {
850 set errmsg "$message (the program exited)"
852 set errmsg "$command (the program exited)"
857 -re "The program is not being run.*$gdb_prompt $" {
858 if ![string match "" $message] then {
859 set errmsg "$message (the program is no longer running)"
861 set errmsg "$command (the program is no longer running)"
866 -re "\r\n$gdb_prompt $" {
867 if ![string match "" $message] then {
874 perror "Window too small."
878 -re "\\((y or n|y or \\\[n\\\]|\\\[y\\\] or n)\\) " {
880 gdb_expect -re "$gdb_prompt $"
881 fail "$message (got interactive prompt)"
884 -re "\\\[0\\\] cancel\r\n\\\[1\\\] all.*\r\n> $" {
886 gdb_expect -re "$gdb_prompt $"
887 fail "$message (got breakpoint menu)"
891 perror "Process no longer exists"
892 if { $message != "" } {
898 perror "internal buffer is full."
903 if ![string match "" $message] then {
904 fail "$message (timeout)"
911 set code [catch {gdb_expect $tmt $code} string]
913 global errorInfo errorCode
914 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
915 } elseif {$code > 1} {
916 return -code $code $string
921 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
922 # Send a command to gdb; test the result.
924 # COMMAND is the command to execute, send to GDB with send_gdb. If
925 # this is the null string no command is sent.
926 # PATTERN is the pattern to match for a PASS, and must NOT include
927 # the \r\n sequence immediately before the gdb prompt.
928 # MESSAGE is an optional message to be printed. If this is
929 # omitted, then the pass/fail messages use the command string as the
930 # message. (If this is the empty string, then sometimes we don't
931 # call pass or fail at all; I don't understand this at all.)
932 # QUESTION is a question GDB may ask in response to COMMAND, like
934 # RESPONSE is the response to send if QUESTION appears.
937 # 1 if the test failed,
938 # 0 if the test passes,
939 # -1 if there was an internal error.
941 proc gdb_test { args } {
945 upvar timeout timeout
947 if [llength $args]>2 then {
948 set message [lindex $args 2]
950 set message [lindex $args 0]
952 set command [lindex $args 0]
953 set pattern [lindex $args 1]
955 if [llength $args]==5 {
956 set question_string [lindex $args 3]
957 set response_string [lindex $args 4]
959 set question_string "^FOOBAR$"
962 return [gdb_test_multiple $command $message {
963 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
964 if ![string match "" $message] then {
968 -re "(${question_string})$" {
969 send_gdb "$response_string\n"
975 # gdb_test_no_output COMMAND MESSAGE
976 # Send a command to GDB and verify that this command generated no output.
978 # See gdb_test_multiple for a description of the COMMAND and MESSAGE
979 # parameters. If MESSAGE is ommitted, then COMMAND will be used as
980 # the message. (If MESSAGE is the empty string, then sometimes we do not
981 # call pass or fail at all; I don't understand this at all.)
983 proc gdb_test_no_output { args } {
985 set command [lindex $args 0]
986 if [llength $args]>1 then {
987 set message [lindex $args 1]
992 set command_regex [string_to_regexp $command]
993 gdb_test_multiple $command $message {
994 -re "^$command_regex\r\n$gdb_prompt $" {
995 if ![string match "" $message] then {
1002 # Send a command and then wait for a sequence of outputs.
1003 # This is useful when the sequence is long and contains ".*", a single
1004 # regexp to match the entire output can get a timeout much easier.
1006 # COMMAND is the command to send.
1007 # TEST_NAME is passed to pass/fail. COMMAND is used if TEST_NAME is "".
1008 # EXPECTED_OUTPUT_LIST is a list of regexps of expected output, which are
1009 # processed in order, and all must be present in the output.
1011 # It is unnecessary to specify ".*" at the beginning or end of any regexp,
1012 # there is an implicit ".*" between each element of EXPECTED_OUTPUT_LIST.
1013 # There is also an implicit ".*" between the last regexp and the gdb prompt.
1015 # Like gdb_test and gdb_test_multiple, the output is expected to end with the
1016 # gdb prompt, which must not be specified in EXPECTED_OUTPUT_LIST.
1019 # 1 if the test failed,
1020 # 0 if the test passes,
1021 # -1 if there was an internal error.
1023 proc gdb_test_sequence { command test_name expected_output_list } {
1025 if { $test_name == "" } {
1026 set test_name $command
1028 lappend expected_output_list ""; # implicit ".*" before gdb prompt
1029 send_gdb "$command\n"
1030 return [gdb_expect_list $test_name "$gdb_prompt $" $expected_output_list]
1034 # Test that a command gives an error. For pass or fail, return
1035 # a 1 to indicate that more tests can proceed. However a timeout
1036 # is a serious error, generates a special fail message, and causes
1037 # a 0 to be returned to indicate that more tests are likely to fail
1040 proc test_print_reject { args } {
1044 if [llength $args]==2 then {
1045 set expectthis [lindex $args 1]
1047 set expectthis "should never match this bogus string"
1049 set sendthis [lindex $args 0]
1050 if $verbose>2 then {
1051 send_user "Sending \"$sendthis\" to gdb\n"
1052 send_user "Looking to match \"$expectthis\"\n"
1054 send_gdb "$sendthis\n"
1055 #FIXME: Should add timeout as parameter.
1057 -re "A .* in expression.*\\.*$gdb_prompt $" {
1058 pass "reject $sendthis"
1061 -re "Invalid syntax in expression.*$gdb_prompt $" {
1062 pass "reject $sendthis"
1065 -re "Junk after end of expression.*$gdb_prompt $" {
1066 pass "reject $sendthis"
1069 -re "Invalid number.*$gdb_prompt $" {
1070 pass "reject $sendthis"
1073 -re "Invalid character constant.*$gdb_prompt $" {
1074 pass "reject $sendthis"
1077 -re "No symbol table is loaded.*$gdb_prompt $" {
1078 pass "reject $sendthis"
1081 -re "No symbol .* in current context.*$gdb_prompt $" {
1082 pass "reject $sendthis"
1085 -re "Unmatched single quote.*$gdb_prompt $" {
1086 pass "reject $sendthis"
1089 -re "A character constant must contain at least one character.*$gdb_prompt $" {
1090 pass "reject $sendthis"
1093 -re "$expectthis.*$gdb_prompt $" {
1094 pass "reject $sendthis"
1097 -re ".*$gdb_prompt $" {
1098 fail "reject $sendthis"
1102 fail "reject $sendthis (eof or timeout)"
1108 # Given an input string, adds backslashes as needed to create a
1109 # regexp that will match the string.
1111 proc string_to_regexp {str} {
1113 regsub -all {[]*+.|()^$\[\\]} $str {\\&} result
1117 # Same as gdb_test, but the second parameter is not a regexp,
1118 # but a string that must match exactly.
1120 proc gdb_test_exact { args } {
1121 upvar timeout timeout
1123 set command [lindex $args 0]
1125 # This applies a special meaning to a null string pattern. Without
1126 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
1127 # messages from commands that should have no output except a new
1128 # prompt. With this, only results of a null string will match a null
1131 set pattern [lindex $args 1]
1132 if [string match $pattern ""] {
1133 set pattern [string_to_regexp [lindex $args 0]]
1135 set pattern [string_to_regexp [lindex $args 1]]
1138 # It is most natural to write the pattern argument with only
1139 # embedded \n's, especially if you are trying to avoid Tcl quoting
1140 # problems. But gdb_expect really wants to see \r\n in patterns. So
1141 # transform the pattern here. First transform \r\n back to \n, in
1142 # case some users of gdb_test_exact already do the right thing.
1143 regsub -all "\r\n" $pattern "\n" pattern
1144 regsub -all "\n" $pattern "\r\n" pattern
1145 if [llength $args]==3 then {
1146 set message [lindex $args 2]
1148 set message $command
1151 return [gdb_test $command $pattern $message]
1154 # Wrapper around gdb_test_multiple that looks for a list of expected
1155 # output elements, but which can appear in any order.
1156 # CMD is the gdb command.
1157 # NAME is the name of the test.
1158 # ELM_FIND_REGEXP specifies how to partition the output into elements to
1160 # ELM_EXTRACT_REGEXP specifies the part of ELM_FIND_REGEXP to compare.
1161 # RESULT_MATCH_LIST is a list of exact matches for each expected element.
1162 # All elements of RESULT_MATCH_LIST must appear for the test to pass.
1164 # A typical use of ELM_FIND_REGEXP/ELM_EXTRACT_REGEXP is to extract one line
1165 # of text per element and then strip trailing \r\n's.
1167 # gdb_test_list_exact "foo" "bar" \
1168 # "\[^\r\n\]+\[\r\n\]+" \
1171 # {expected result 1} \
1172 # {expected result 2} \
1175 proc gdb_test_list_exact { cmd name elm_find_regexp elm_extract_regexp result_match_list } {
1178 set matches [lsort $result_match_list]
1180 gdb_test_multiple $cmd $name {
1181 "$cmd\[\r\n\]" { exp_continue }
1182 -re $elm_find_regexp {
1183 set str $expect_out(0,string)
1184 verbose -log "seen: $str" 3
1185 regexp -- $elm_extract_regexp $str elm_seen
1186 verbose -log "extracted: $elm_seen" 3
1187 lappend seen $elm_seen
1190 -re "$gdb_prompt $" {
1192 foreach got [lsort $seen] have $matches {
1193 if {![string equal $got $have]} {
1198 if {[string length $failed] != 0} {
1199 fail "$name ($failed not found)"
1207 proc gdb_reinitialize_dir { subdir } {
1210 if [is_remote host] {
1215 -re "Reinitialize source path to empty.*y or n. " {
1218 -re "Source directories searched.*$gdb_prompt $" {
1219 send_gdb "dir $subdir\n"
1221 -re "Source directories searched.*$gdb_prompt $" {
1222 verbose "Dir set to $subdir"
1224 -re "$gdb_prompt $" {
1225 perror "Dir \"$subdir\" failed."
1229 -re "$gdb_prompt $" {
1230 perror "Dir \"$subdir\" failed."
1234 -re "$gdb_prompt $" {
1235 perror "Dir \"$subdir\" failed."
1241 # gdb_exit -- exit the GDB, killing the target program if necessary
1243 proc default_gdb_exit {} {
1245 global INTERNAL_GDBFLAGS GDBFLAGS
1248 global inotify_log_file
1250 gdb_stop_suppressing_tests
1252 if ![info exists gdb_spawn_id] {
1256 verbose "Quitting $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1258 if {[info exists inotify_log_file] && [file exists $inotify_log_file]} {
1259 set fd [open $inotify_log_file]
1260 set data [read -nonewline $fd]
1263 if {[string compare $data ""] != 0} {
1264 warning "parallel-unsafe file creations noticed"
1267 set fd [open $inotify_log_file w]
1272 if { [is_remote host] && [board_info host exists fileid] } {
1279 -re "DOSEXIT code" { }
1284 if ![is_remote host] {
1290 # Load a file into the debugger.
1291 # The return value is 0 for success, -1 for failure.
1293 # This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO
1294 # to one of these values:
1296 # debug file was loaded successfully and has debug information
1297 # nodebug file was loaded successfully and has no debug information
1298 # lzma file was loaded, .gnu_debugdata found, but no LZMA support
1300 # fail file was not loaded
1302 # I tried returning this information as part of the return value,
1303 # but ran into a mess because of the many re-implementations of
1304 # gdb_load in config/*.exp.
1306 # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use
1307 # this if they can get more information set.
1309 proc gdb_file_cmd { arg } {
1313 global last_loaded_file
1315 # Save this for the benefit of gdbserver-support.exp.
1316 set last_loaded_file $arg
1318 # Set whether debug info was found.
1319 # Default to "fail".
1320 global gdb_file_cmd_debug_info
1321 set gdb_file_cmd_debug_info "fail"
1323 if [is_remote host] {
1324 set arg [remote_download host $arg]
1326 perror "download failed"
1331 # The file command used to kill the remote target. For the benefit
1332 # of the testsuite, preserve this behavior.
1335 -re "Kill the program being debugged. .y or n. $" {
1337 verbose "\t\tKilling previous program being debugged"
1340 -re "$gdb_prompt $" {
1345 send_gdb "file $arg\n"
1347 -re "Reading symbols from.*LZMA support was disabled.*done.*$gdb_prompt $" {
1348 verbose "\t\tLoaded $arg into $GDB; .gnu_debugdata found but no LZMA available"
1349 set gdb_file_cmd_debug_info "lzma"
1352 -re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" {
1353 verbose "\t\tLoaded $arg into $GDB with no debugging symbols"
1354 set gdb_file_cmd_debug_info "nodebug"
1357 -re "Reading symbols from.*done.*$gdb_prompt $" {
1358 verbose "\t\tLoaded $arg into $GDB"
1359 set gdb_file_cmd_debug_info "debug"
1362 -re "Load new symbol table from \".*\".*y or n. $" {
1365 -re "Reading symbols from.*done.*$gdb_prompt $" {
1366 verbose "\t\tLoaded $arg with new symbol table into $GDB"
1367 set gdb_file_cmd_debug_info "debug"
1371 perror "Couldn't load $arg, other program already loaded (timeout)."
1375 perror "Couldn't load $arg, other program already loaded (eof)."
1380 -re "No such file or directory.*$gdb_prompt $" {
1381 perror "($arg) No such file or directory"
1384 -re "A problem internal to GDB has been detected" {
1385 fail "($arg) (GDB internal error)"
1386 gdb_internal_error_resync
1389 -re "$gdb_prompt $" {
1390 perror "Couldn't load $arg into $GDB."
1394 perror "Couldn't load $arg into $GDB (timeout)."
1398 # This is an attempt to detect a core dump, but seems not to
1399 # work. Perhaps we need to match .* followed by eof, in which
1400 # gdb_expect does not seem to have a way to do that.
1401 perror "Couldn't load $arg into $GDB (eof)."
1408 # start gdb -- start gdb running, default procedure
1410 # When running over NFS, particularly if running many simultaneous
1411 # tests on different hosts all using the same server, things can
1412 # get really slow. Give gdb at least 3 minutes to start up.
1414 proc default_gdb_start { } {
1415 global verbose use_gdb_stub
1417 global INTERNAL_GDBFLAGS GDBFLAGS
1422 gdb_stop_suppressing_tests
1424 # Set the default value, it may be overriden later by specific testfile.
1426 # Use `set_board_info use_gdb_stub' for the board file to flag the inferior
1427 # is already started after connecting and run/attach are not supported.
1428 # This is used for the "remote" protocol. After GDB starts you should
1429 # check global $use_gdb_stub instead of the board as the testfile may force
1430 # a specific different target protocol itself.
1431 set use_gdb_stub [target_info exists use_gdb_stub]
1433 verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1435 if [info exists gdb_spawn_id] {
1439 if ![is_remote host] {
1440 if { [which $GDB] == 0 } then {
1441 perror "$GDB does not exist."
1445 set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"]
1446 if { $res < 0 || $res == "" } {
1447 perror "Spawning $GDB failed."
1451 -re "\[\r\n\]$gdb_prompt $" {
1452 verbose "GDB initialized."
1454 -re "$gdb_prompt $" {
1455 perror "GDB never initialized."
1459 perror "(timeout) GDB never initialized after 10 seconds."
1465 # force the height to "unlimited", so no pagers get used
1467 send_gdb "set height 0\n"
1469 -re "$gdb_prompt $" {
1470 verbose "Setting height to 0." 2
1473 warning "Couldn't set the height to 0"
1476 # force the width to "unlimited", so no wraparound occurs
1477 send_gdb "set width 0\n"
1479 -re "$gdb_prompt $" {
1480 verbose "Setting width to 0." 2
1483 warning "Couldn't set the width to 0."
1489 # Examine the output of compilation to determine whether compilation
1490 # failed or not. If it failed determine whether it is due to missing
1491 # compiler or due to compiler error. Report pass, fail or unsupported
1494 proc gdb_compile_test {src output} {
1495 if { $output == "" } {
1496 pass "compilation [file tail $src]"
1497 } elseif { [regexp {^[a-zA-Z_0-9]+: Can't find [^ ]+\.$} $output] } {
1498 unsupported "compilation [file tail $src]"
1499 } elseif { [regexp {.*: command not found[\r|\n]*$} $output] } {
1500 unsupported "compilation [file tail $src]"
1501 } elseif { [regexp {.*: [^\r\n]*compiler not installed[^\r\n]*[\r|\n]*$} $output] } {
1502 unsupported "compilation [file tail $src]"
1504 verbose -log "compilation failed: $output" 2
1505 fail "compilation [file tail $src]"
1509 # Return a 1 for configurations for which we don't even want to try to
1512 proc skip_cplus_tests {} {
1513 if { [istarget "h8300-*-*"] } {
1517 # The C++ IO streams are too large for HC11/HC12 and are thus not
1518 # available. The gdb C++ tests use them and don't compile.
1519 if { [istarget "m6811-*-*"] } {
1522 if { [istarget "m6812-*-*"] } {
1528 # Return a 1 for configurations for which don't have both C++ and the STL.
1530 proc skip_stl_tests {} {
1531 # Symbian supports the C++ language, but the STL is missing
1532 # (both headers and libraries).
1533 if { [istarget "arm*-*-symbianelf*"] } {
1537 return [skip_cplus_tests]
1540 # Return a 1 if I don't even want to try to test FORTRAN.
1542 proc skip_fortran_tests {} {
1546 # Return a 1 if I don't even want to try to test ada.
1548 proc skip_ada_tests {} {
1552 # Return a 1 if I don't even want to try to test GO.
1554 proc skip_go_tests {} {
1558 # Return a 1 if I don't even want to try to test java.
1560 proc skip_java_tests {} {
1564 # Return a 1 if I don't even want to try to test D.
1566 proc skip_d_tests {} {
1570 # Return a 1 for configurations that do not support Python scripting.
1572 proc skip_python_tests {} {
1574 global gdb_py_is_py3k
1575 global gdb_py_is_py24
1577 gdb_test_multiple "python print ('test')" "verify python support" {
1578 -re "not supported.*$gdb_prompt $" {
1579 unsupported "Python support is disabled."
1582 -re "$gdb_prompt $" {}
1585 set gdb_py_is_py24 0
1586 gdb_test_multiple "python print (sys.version_info\[0\])" "check if python 3" {
1587 -re "3.*$gdb_prompt $" {
1588 set gdb_py_is_py3k 1
1590 -re ".*$gdb_prompt $" {
1591 set gdb_py_is_py3k 0
1594 if { $gdb_py_is_py3k == 0 } {
1595 gdb_test_multiple "python print (sys.version_info\[1\])" "check if python 2.4" {
1596 -re "\[45\].*$gdb_prompt $" {
1597 set gdb_py_is_py24 1
1599 -re ".*$gdb_prompt $" {
1600 set gdb_py_is_py24 0
1608 # Return a 1 if we should skip shared library tests.
1610 proc skip_shlib_tests {} {
1611 # Run the shared library tests on native systems.
1616 # An abbreviated list of remote targets where we should be able to
1617 # run shared library tests.
1618 if {([istarget *-*-linux*]
1619 || [istarget *-*-*bsd*]
1620 || [istarget *-*-solaris2*]
1621 || [istarget arm*-*-symbianelf*]
1622 || [istarget *-*-mingw*]
1623 || [istarget *-*-cygwin*]
1624 || [istarget *-*-pe*])} {
1631 # Test files shall make sure all the test result lines in gdb.sum are
1632 # unique in a test run, so that comparing the gdb.sum files of two
1633 # test runs gives correct results. Test files that exercise
1634 # variations of the same tests more than once, shall prefix the
1635 # different test invocations with different identifying strings in
1636 # order to make them unique.
1638 # About test prefixes:
1640 # $pf_prefix is the string that dejagnu prints after the result (FAIL,
1641 # PASS, etc.), and before the test message/name in gdb.sum. E.g., the
1642 # underlined substring in
1644 # PASS: gdb.base/mytest.exp: some test
1645 # ^^^^^^^^^^^^^^^^^^^^
1649 # The easiest way to adjust the test prefix is to append a test
1650 # variation prefix to the $pf_prefix, using the with_test_prefix
1653 # proc do_tests {} {
1654 # gdb_test ... ... "test foo"
1655 # gdb_test ... ... "test bar"
1657 # with_test_prefix "subvariation a" {
1658 # gdb_test ... ... "test x"
1661 # with_test_prefix "subvariation b" {
1662 # gdb_test ... ... "test x"
1666 # with_test_prefix "variation1" {
1667 # ...do setup for variation 1...
1671 # with_test_prefix "variation2" {
1672 # ...do setup for variation 2...
1678 # PASS: gdb.base/mytest.exp: variation1: test foo
1679 # PASS: gdb.base/mytest.exp: variation1: test bar
1680 # PASS: gdb.base/mytest.exp: variation1: subvariation a: test x
1681 # PASS: gdb.base/mytest.exp: variation1: subvariation b: test x
1682 # PASS: gdb.base/mytest.exp: variation2: test foo
1683 # PASS: gdb.base/mytest.exp: variation2: test bar
1684 # PASS: gdb.base/mytest.exp: variation2: subvariation a: test x
1685 # PASS: gdb.base/mytest.exp: variation2: subvariation b: test x
1687 # If for some reason more flexibility is necessary, one can also
1688 # manipulate the pf_prefix global directly, treating it as a string.
1692 # set saved_pf_prefix
1693 # append pf_prefix "${foo}: bar"
1694 # ... actual tests ...
1695 # set pf_prefix $saved_pf_prefix
1698 # Run BODY in the context of the caller, with the current test prefix
1699 # (pf_prefix) appended with one space, then PREFIX, and then a colon.
1700 # Returns the result of BODY.
1702 proc with_test_prefix { prefix body } {
1705 set saved $pf_prefix
1706 append pf_prefix " " $prefix ":"
1707 set code [catch {uplevel 1 $body} result]
1708 set pf_prefix $saved
1711 global errorInfo errorCode
1712 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
1714 return -code $code $result
1718 # Run tests in BODY with GDB prompt and variable $gdb_prompt set to
1719 # PROMPT. When BODY is finished, restore GDB prompt and variable
1721 # Returns the result of BODY.
1723 proc with_gdb_prompt { prompt body } {
1726 set saved $gdb_prompt
1728 set gdb_prompt $prompt
1729 gdb_test_no_output "set prompt $prompt " ""
1731 set code [catch {uplevel 1 $body} result]
1733 set gdb_prompt $saved
1734 gdb_test_no_output "set prompt $saved " ""
1737 global errorInfo errorCode
1738 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
1740 return -code $code $result
1744 # Run tests in BODY with target-charset setting to TARGET_CHARSET. When
1745 # BODY is finished, restore target-charset.
1747 proc with_target_charset { target_charset body } {
1751 gdb_test_multiple "show target-charset" "" {
1752 -re "The target character set is \".*; currently (.*)\"\..*$gdb_prompt " {
1753 set saved $expect_out(1,string)
1755 -re "The target character set is \"(.*)\".*$gdb_prompt " {
1756 set saved $expect_out(1,string)
1758 -re ".*$gdb_prompt " {
1759 fail "get target-charset"
1763 gdb_test_no_output "set target-charset $target_charset" ""
1765 set code [catch {uplevel 1 $body} result]
1767 gdb_test_no_output "set target-charset $saved" ""
1770 global errorInfo errorCode
1771 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
1773 return -code $code $result
1777 # Return 1 if _Complex types are supported, otherwise, return 0.
1779 gdb_caching_proc support_complex_tests {
1780 # Set up, compile, and execute a test program containing _Complex types.
1781 # Include the current process ID in the file names to prevent conflicts
1782 # with invocations for multiple testsuites.
1783 set src [standard_temp_file complex[pid].c]
1784 set exe [standard_temp_file complex[pid].x]
1786 gdb_produce_source $src {
1790 _Complex long double cld;
1795 verbose "compiling testfile $src" 2
1796 set compile_flags {debug nowarnings quiet}
1797 set lines [gdb_compile $src $exe executable $compile_flags]
1801 if ![string match "" $lines] then {
1802 verbose "testfile compilation failed, returning 0" 2
1811 # Return 1 if target hardware or OS supports single stepping to signal
1812 # handler, otherwise, return 0.
1814 proc can_single_step_to_signal_handler {} {
1816 # Targets don't have hardware single step. On these targets, when
1817 # a signal is delivered during software single step, gdb is unable
1818 # to determine the next instruction addresses, because start of signal
1819 # handler is one of them.
1820 if { [istarget "arm*-*-*"] || [istarget "mips*-*-*"]
1821 || [istarget "tic6x-*-*"] || [istarget "sparc*-*-linux*"]
1822 || [istarget "nios2-*-*"] } {
1829 # Return 1 if target supports process record, otherwise return 0.
1831 proc supports_process_record {} {
1833 if [target_info exists gdb,use_precord] {
1834 return [target_info gdb,use_precord]
1837 if { [istarget "arm*-*-linux*"] || [istarget "x86_64-*-linux*"]
1838 || [istarget "i\[34567\]86-*-linux*"] } {
1845 # Return 1 if target supports reverse debugging, otherwise return 0.
1847 proc supports_reverse {} {
1849 if [target_info exists gdb,can_reverse] {
1850 return [target_info gdb,can_reverse]
1853 if { [istarget "arm*-*-linux*"] || [istarget "x86_64-*-linux*"]
1854 || [istarget "i\[34567\]86-*-linux*"] } {
1861 # Return 1 if readline library is used.
1863 proc readline_is_used { } {
1866 gdb_test_multiple "show editing" "" {
1867 -re ".*Editing of command lines as they are typed is on\..*$gdb_prompt $" {
1870 -re ".*$gdb_prompt $" {
1876 # Return 1 if target is ELF.
1877 gdb_caching_proc is_elf_target {
1878 set me "is_elf_target"
1880 set src [standard_temp_file is_elf_target[pid].c]
1881 set obj [standard_temp_file is_elf_target[pid].o]
1883 gdb_produce_source $src {
1884 int foo () {return 0;}
1887 verbose "$me: compiling testfile $src" 2
1888 set lines [gdb_compile $src $obj object {quiet}]
1892 if ![string match "" $lines] then {
1893 verbose "$me: testfile compilation failed, returning 0" 2
1897 set fp_obj [open $obj "r"]
1898 fconfigure $fp_obj -translation binary
1899 set data [read $fp_obj]
1904 set ELFMAG "\u007FELF"
1906 if {[string compare -length 4 $data $ELFMAG] != 0} {
1907 verbose "$me: returning 0" 2
1911 verbose "$me: returning 1" 2
1915 # Produce source file NAME and write SOURCES into it.
1917 proc gdb_produce_source { name sources } {
1919 set f [open $name "w"]
1925 # Return 1 if target is ILP32.
1926 # This cannot be decided simply from looking at the target string,
1927 # as it might depend on externally passed compiler options like -m64.
1928 gdb_caching_proc is_ilp32_target {
1929 set me "is_ilp32_target"
1931 set src [standard_temp_file ilp32[pid].c]
1932 set obj [standard_temp_file ilp32[pid].o]
1934 gdb_produce_source $src {
1935 int dummy[sizeof (int) == 4
1936 && sizeof (void *) == 4
1937 && sizeof (long) == 4 ? 1 : -1];
1940 verbose "$me: compiling testfile $src" 2
1941 set lines [gdb_compile $src $obj object {quiet}]
1945 if ![string match "" $lines] then {
1946 verbose "$me: testfile compilation failed, returning 0" 2
1950 verbose "$me: returning 1" 2
1954 # Return 1 if target is LP64.
1955 # This cannot be decided simply from looking at the target string,
1956 # as it might depend on externally passed compiler options like -m64.
1957 gdb_caching_proc is_lp64_target {
1958 set me "is_lp64_target"
1960 set src [standard_temp_file lp64[pid].c]
1961 set obj [standard_temp_file lp64[pid].o]
1963 gdb_produce_source $src {
1964 int dummy[sizeof (int) == 4
1965 && sizeof (void *) == 8
1966 && sizeof (long) == 8 ? 1 : -1];
1969 verbose "$me: compiling testfile $src" 2
1970 set lines [gdb_compile $src $obj object {quiet}]
1974 if ![string match "" $lines] then {
1975 verbose "$me: testfile compilation failed, returning 0" 2
1979 verbose "$me: returning 1" 2
1983 # Return 1 if target has 64 bit addresses.
1984 # This cannot be decided simply from looking at the target string,
1985 # as it might depend on externally passed compiler options like -m64.
1986 gdb_caching_proc is_64_target {
1987 set me "is_64_target"
1989 set src [standard_temp_file is64[pid].c]
1990 set obj [standard_temp_file is64[pid].o]
1992 gdb_produce_source $src {
1993 int function(void) { return 3; }
1994 int dummy[sizeof (&function) == 8 ? 1 : -1];
1997 verbose "$me: compiling testfile $src" 2
1998 set lines [gdb_compile $src $obj object {quiet}]
2002 if ![string match "" $lines] then {
2003 verbose "$me: testfile compilation failed, returning 0" 2
2007 verbose "$me: returning 1" 2
2011 # Return 1 if target has x86_64 registers - either amd64 or x32.
2012 # x32 target identifies as x86_64-*-linux*, therefore it cannot be determined
2013 # just from the target string.
2014 gdb_caching_proc is_amd64_regs_target {
2015 if {![istarget "x86_64-*-*"] && ![istarget "i?86-*"]} {
2019 set me "is_amd64_regs_target"
2021 set src [standard_temp_file reg64[pid].s]
2022 set obj [standard_temp_file reg64[pid].o]
2026 {rax rbx rcx rdx rsi rdi rbp rsp r8 r9 r10 r11 r12 r13 r14 r15} {
2027 lappend list "\tincq %$reg"
2029 gdb_produce_source $src [join $list \n]
2031 verbose "$me: compiling testfile $src" 2
2032 set lines [gdb_compile $src $obj object {quiet}]
2036 if ![string match "" $lines] then {
2037 verbose "$me: testfile compilation failed, returning 0" 2
2041 verbose "$me: returning 1" 2
2045 # Return 1 if this target is an x86 or x86-64 with -m32.
2046 proc is_x86_like_target {} {
2047 if {![istarget "x86_64-*-*"] && ![istarget i?86-*]} {
2050 return [expr [is_ilp32_target] && ![is_amd64_regs_target]]
2053 # Return 1 if displaced stepping is supported on target, otherwise, return 0.
2054 proc support_displaced_stepping {} {
2056 if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"]
2057 || [istarget "arm*-*-linux*"] || [istarget "powerpc-*-linux*"]
2058 || [istarget "powerpc64-*-linux*"] || [istarget "s390*-*-*"] } {
2065 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
2066 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
2068 gdb_caching_proc skip_altivec_tests {
2069 global srcdir subdir gdb_prompt inferior_exited_re
2071 set me "skip_altivec_tests"
2073 # Some simulators are known to not support VMX instructions.
2074 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
2075 verbose "$me: target known to not support VMX, returning 1" 2
2079 # Make sure we have a compiler that understands altivec.
2080 set compile_flags {debug nowarnings}
2081 if [get_compiler_info] {
2082 warning "Could not get compiler info"
2085 if [test_compiler_info gcc*] {
2086 set compile_flags "$compile_flags additional_flags=-maltivec"
2087 } elseif [test_compiler_info xlc*] {
2088 set compile_flags "$compile_flags additional_flags=-qaltivec"
2090 verbose "Could not compile with altivec support, returning 1" 2
2094 # Set up, compile, and execute a test program containing VMX instructions.
2095 # Include the current process ID in the file names to prevent conflicts
2096 # with invocations for multiple testsuites.
2097 set src [standard_temp_file vmx[pid].c]
2098 set exe [standard_temp_file vmx[pid].x]
2100 gdb_produce_source $src {
2103 asm volatile ("vor v0,v0,v0");
2105 asm volatile ("vor 0,0,0");
2111 verbose "$me: compiling testfile $src" 2
2112 set lines [gdb_compile $src $exe executable $compile_flags]
2115 if ![string match "" $lines] then {
2116 verbose "$me: testfile compilation failed, returning 1" 2
2120 # No error message, compilation succeeded so now run it via gdb.
2124 gdb_reinitialize_dir $srcdir/$subdir
2128 -re ".*Illegal instruction.*${gdb_prompt} $" {
2129 verbose -log "\n$me altivec hardware not detected"
2130 set skip_vmx_tests 1
2132 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
2133 verbose -log "\n$me: altivec hardware detected"
2134 set skip_vmx_tests 0
2137 warning "\n$me: default case taken"
2138 set skip_vmx_tests 1
2142 remote_file build delete $exe
2144 verbose "$me: returning $skip_vmx_tests" 2
2145 return $skip_vmx_tests
2148 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
2149 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
2151 gdb_caching_proc skip_vsx_tests {
2152 global srcdir subdir gdb_prompt inferior_exited_re
2154 set me "skip_vsx_tests"
2156 # Some simulators are known to not support Altivec instructions, so
2157 # they won't support VSX instructions as well.
2158 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
2159 verbose "$me: target known to not support VSX, returning 1" 2
2163 # Make sure we have a compiler that understands altivec.
2164 set compile_flags {debug nowarnings quiet}
2165 if [get_compiler_info] {
2166 warning "Could not get compiler info"
2169 if [test_compiler_info gcc*] {
2170 set compile_flags "$compile_flags additional_flags=-mvsx"
2171 } elseif [test_compiler_info xlc*] {
2172 set compile_flags "$compile_flags additional_flags=-qasm=gcc"
2174 verbose "Could not compile with vsx support, returning 1" 2
2178 set src [standard_temp_file vsx[pid].c]
2179 set exe [standard_temp_file vsx[pid].x]
2181 gdb_produce_source $src {
2183 double a[2] = { 1.0, 2.0 };
2185 asm volatile ("lxvd2x v0,v0,%[addr]" : : [addr] "r" (a));
2187 asm volatile ("lxvd2x 0,0,%[addr]" : : [addr] "r" (a));
2193 verbose "$me: compiling testfile $src" 2
2194 set lines [gdb_compile $src $exe executable $compile_flags]
2197 if ![string match "" $lines] then {
2198 verbose "$me: testfile compilation failed, returning 1" 2
2202 # No error message, compilation succeeded so now run it via gdb.
2206 gdb_reinitialize_dir $srcdir/$subdir
2210 -re ".*Illegal instruction.*${gdb_prompt} $" {
2211 verbose -log "\n$me VSX hardware not detected"
2212 set skip_vsx_tests 1
2214 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
2215 verbose -log "\n$me: VSX hardware detected"
2216 set skip_vsx_tests 0
2219 warning "\n$me: default case taken"
2220 set skip_vsx_tests 1
2224 remote_file build delete $exe
2226 verbose "$me: returning $skip_vsx_tests" 2
2227 return $skip_vsx_tests
2230 # Run a test on the target to see if it supports btrace hardware. Return 0 if so,
2231 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
2233 gdb_caching_proc skip_btrace_tests {
2234 global srcdir subdir gdb_prompt inferior_exited_re
2236 set me "skip_btrace_tests"
2237 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
2238 verbose "$me: target does not support btrace, returning 1" 2
2242 # Set up, compile, and execute a test program.
2243 # Include the current process ID in the file names to prevent conflicts
2244 # with invocations for multiple testsuites.
2245 set src [standard_temp_file btrace[pid].c]
2246 set exe [standard_temp_file btrace[pid].x]
2248 gdb_produce_source $src {
2249 int main(void) { return 0; }
2252 verbose "$me: compiling testfile $src" 2
2253 set compile_flags {debug nowarnings quiet}
2254 set lines [gdb_compile $src $exe executable $compile_flags]
2256 if ![string match "" $lines] then {
2257 verbose "$me: testfile compilation failed, returning 1" 2
2262 # No error message, compilation succeeded so now run it via gdb.
2266 gdb_reinitialize_dir $srcdir/$subdir
2273 # In case of an unexpected output, we return 2 as a fail value.
2274 set skip_btrace_tests 2
2275 gdb_test_multiple "record btrace" "check btrace support" {
2276 -re "You can't do that when your target is.*\r\n$gdb_prompt $" {
2277 set skip_btrace_tests 1
2279 -re "Target does not support branch tracing.*\r\n$gdb_prompt $" {
2280 set skip_btrace_tests 1
2282 -re "Could not enable branch tracing.*\r\n$gdb_prompt $" {
2283 set skip_btrace_tests 1
2285 -re "^record btrace\r\n$gdb_prompt $" {
2286 set skip_btrace_tests 0
2290 remote_file build delete $exe
2292 verbose "$me: returning $skip_btrace_tests" 2
2293 return $skip_btrace_tests
2296 # Skip all the tests in the file if you are not on an hppa running
2299 proc skip_hp_tests {} {
2300 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
2301 verbose "Skip hp tests is $skip_hp"
2305 # Return whether we should skip tests for showing inlined functions in
2306 # backtraces. Requires get_compiler_info and get_debug_format.
2308 proc skip_inline_frame_tests {} {
2309 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
2310 if { ! [test_debug_format "DWARF 2"] } {
2314 # GCC before 4.1 does not emit DW_AT_call_file / DW_AT_call_line.
2315 if { ([test_compiler_info "gcc-2-*"]
2316 || [test_compiler_info "gcc-3-*"]
2317 || [test_compiler_info "gcc-4-0-*"]) } {
2324 # Return whether we should skip tests for showing variables from
2325 # inlined functions. Requires get_compiler_info and get_debug_format.
2327 proc skip_inline_var_tests {} {
2328 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
2329 if { ! [test_debug_format "DWARF 2"] } {
2336 # Return a 1 if we should skip tests that require hardware breakpoints
2338 proc skip_hw_breakpoint_tests {} {
2339 # Skip tests if requested by the board (note that no_hardware_watchpoints
2340 # disables both watchpoints and breakpoints)
2341 if { [target_info exists gdb,no_hardware_watchpoints]} {
2345 # These targets support hardware breakpoints natively
2346 if { [istarget "i?86-*-*"]
2347 || [istarget "x86_64-*-*"]
2348 || [istarget "ia64-*-*"]
2349 || [istarget "arm*-*-*"]} {
2356 # Return a 1 if we should skip tests that require hardware watchpoints
2358 proc skip_hw_watchpoint_tests {} {
2359 # Skip tests if requested by the board
2360 if { [target_info exists gdb,no_hardware_watchpoints]} {
2364 # These targets support hardware watchpoints natively
2365 if { [istarget "i?86-*-*"]
2366 || [istarget "x86_64-*-*"]
2367 || [istarget "ia64-*-*"]
2368 || [istarget "arm*-*-*"]
2369 || [istarget "powerpc*-*-linux*"]
2370 || [istarget "s390*-*-*"] } {
2377 # Return a 1 if we should skip tests that require *multiple* hardware
2378 # watchpoints to be active at the same time
2380 proc skip_hw_watchpoint_multi_tests {} {
2381 if { [skip_hw_watchpoint_tests] } {
2385 # These targets support just a single hardware watchpoint
2386 if { [istarget "arm*-*-*"]
2387 || [istarget "powerpc*-*-linux*"] } {
2394 # Return a 1 if we should skip tests that require read/access watchpoints
2396 proc skip_hw_watchpoint_access_tests {} {
2397 if { [skip_hw_watchpoint_tests] } {
2401 # These targets support just write watchpoints
2402 if { [istarget "s390*-*-*"] } {
2409 # Return 1 if we should skip tests that require the runtime unwinder
2410 # hook. This must be invoked while gdb is running, after shared
2411 # libraries have been loaded. This is needed because otherwise a
2412 # shared libgcc won't be visible.
2414 proc skip_unwinder_tests {} {
2418 gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook" {
2419 -re "= .*no debug info.*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
2421 -re "= .*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
2424 -re "No symbol .* in current context.\r\n$gdb_prompt $" {
2428 gdb_test_multiple "info probe" "check for stap probe in unwinder" {
2429 -re ".*libgcc.*unwind.*\r\n$gdb_prompt $" {
2432 -re "\r\n$gdb_prompt $" {
2439 # Return 0 if we should skip tests that require the libstdc++ stap
2440 # probes. This must be invoked while gdb is running, after shared
2441 # libraries have been loaded.
2443 proc skip_libstdcxx_probe_tests {} {
2447 gdb_test_multiple "info probe" "check for stap probe in libstdc++" {
2448 -re ".*libstdcxx.*catch.*\r\n$gdb_prompt $" {
2451 -re "\r\n$gdb_prompt $" {
2457 # Check whether we're testing with the remote or extended-remote
2460 proc gdb_is_target_remote {} {
2463 set test "probe for target remote"
2464 gdb_test_multiple "maint print target-stack" $test {
2465 -re ".*emote serial target in gdb-specific protocol.*$gdb_prompt $" {
2469 -re "$gdb_prompt $" {
2476 set compiler_info "unknown"
2478 set hp_cc_compiler 0
2479 set hp_aCC_compiler 0
2481 # Figure out what compiler I am using.
2483 # ARG can be empty or "C++". If empty, "C" is assumed.
2485 # There are several ways to do this, with various problems.
2487 # [ gdb_compile -E $ifile -o $binfile.ci ]
2488 # source $binfile.ci
2490 # Single Unix Spec v3 says that "-E -o ..." together are not
2491 # specified. And in fact, the native compiler on hp-ux 11 (among
2492 # others) does not work with "-E -o ...". Most targets used to do
2493 # this, and it mostly worked, because it works with gcc.
2495 # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ]
2496 # source $binfile.ci
2498 # This avoids the problem with -E and -o together. This almost works
2499 # if the build machine is the same as the host machine, which is
2500 # usually true of the targets which are not gcc. But this code does
2501 # not figure which compiler to call, and it always ends up using the C
2502 # compiler. Not good for setting hp_aCC_compiler. Targets
2503 # hppa*-*-hpux* and mips*-*-irix* used to do this.
2505 # [ gdb_compile -E $ifile > $binfile.ci ]
2506 # source $binfile.ci
2508 # dejagnu target_compile says that it supports output redirection,
2509 # but the code is completely different from the normal path and I
2510 # don't want to sweep the mines from that path. So I didn't even try
2513 # set cppout [ gdb_compile $ifile "" preprocess $args quiet ]
2516 # I actually do this for all targets now. gdb_compile runs the right
2517 # compiler, and TCL captures the output, and I eval the output.
2519 # Unfortunately, expect logs the output of the command as it goes by,
2520 # and dejagnu helpfully prints a second copy of it right afterwards.
2521 # So I turn off expect logging for a moment.
2523 # [ gdb_compile $ifile $ciexe_file executable $args ]
2524 # [ remote_exec $ciexe_file ]
2525 # [ source $ci_file.out ]
2527 # I could give up on -E and just do this.
2528 # I didn't get desperate enough to try this.
2530 # -- chastain 2004-01-06
2532 proc get_compiler_info {{arg ""}} {
2533 # For compiler.c and compiler.cc
2536 # I am going to play with the log to keep noise out.
2540 # These come from compiler.c or compiler.cc
2541 global compiler_info
2543 # Legacy global data symbols.
2545 global hp_cc_compiler
2546 global hp_aCC_compiler
2548 # Choose which file to preprocess.
2549 set ifile "${srcdir}/lib/compiler.c"
2550 if { $arg == "c++" } {
2551 set ifile "${srcdir}/lib/compiler.cc"
2554 # Run $ifile through the right preprocessor.
2555 # Toggle gdb.log to keep the compiler output out of the log.
2556 set saved_log [log_file -info]
2558 if [is_remote host] {
2559 # We have to use -E and -o together, despite the comments
2560 # above, because of how DejaGnu handles remote host testing.
2561 set ppout "$outdir/compiler.i"
2562 gdb_compile "${ifile}" "$ppout" preprocess [list "$arg" quiet]
2563 set file [open $ppout r]
2564 set cppout [read $file]
2567 set cppout [ gdb_compile "${ifile}" "" preprocess [list "$arg" quiet] ]
2569 eval log_file $saved_log
2573 foreach cppline [ split "$cppout" "\n" ] {
2574 if { [ regexp "^#" "$cppline" ] } {
2576 } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } {
2578 } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } {
2580 verbose "get_compiler_info: $cppline" 2
2584 verbose -log "get_compiler_info: $cppline"
2589 # Reset to unknown compiler if any diagnostics happened.
2591 set compiler_info "unknown"
2594 # Set the legacy symbols.
2596 set hp_cc_compiler 0
2597 set hp_aCC_compiler 0
2598 if { [regexp "^gcc-1-" "$compiler_info" ] } { set gcc_compiled 1 }
2599 if { [regexp "^gcc-2-" "$compiler_info" ] } { set gcc_compiled 2 }
2600 if { [regexp "^gcc-3-" "$compiler_info" ] } { set gcc_compiled 3 }
2601 if { [regexp "^gcc-4-" "$compiler_info" ] } { set gcc_compiled 4 }
2602 if { [regexp "^gcc-5-" "$compiler_info" ] } { set gcc_compiled 5 }
2603 if { [regexp "^hpcc-" "$compiler_info" ] } { set hp_cc_compiler 1 }
2604 if { [regexp "^hpacc-" "$compiler_info" ] } { set hp_aCC_compiler 1 }
2606 # Log what happened.
2607 verbose -log "get_compiler_info: $compiler_info"
2609 # Most compilers will evaluate comparisons and other boolean
2610 # operations to 0 or 1.
2611 uplevel \#0 { set true 1 }
2612 uplevel \#0 { set false 0 }
2614 # Use of aCC results in boolean results being displayed as
2616 if { $hp_aCC_compiler } {
2617 uplevel \#0 { set true true }
2618 uplevel \#0 { set false false }
2624 proc test_compiler_info { {compiler ""} } {
2625 global compiler_info
2627 # if no arg, return the compiler_info string
2629 if [string match "" $compiler] {
2630 if [info exists compiler_info] {
2631 return $compiler_info
2633 perror "No compiler info found."
2637 return [string match $compiler $compiler_info]
2640 proc current_target_name { } {
2642 if [info exists target_info(target,name)] {
2643 set answer $target_info(target,name)
2650 set gdb_wrapper_initialized 0
2651 set gdb_wrapper_target ""
2653 proc gdb_wrapper_init { args } {
2654 global gdb_wrapper_initialized
2655 global gdb_wrapper_file
2656 global gdb_wrapper_flags
2657 global gdb_wrapper_target
2659 if { $gdb_wrapper_initialized == 1 } { return; }
2661 if {[target_info exists needs_status_wrapper] && \
2662 [target_info needs_status_wrapper] != "0"} {
2663 set result [build_wrapper "testglue.o"]
2664 if { $result != "" } {
2665 set gdb_wrapper_file [lindex $result 0]
2666 set gdb_wrapper_flags [lindex $result 1]
2668 warning "Status wrapper failed to build."
2671 set gdb_wrapper_initialized 1
2672 set gdb_wrapper_target [current_target_name]
2675 # Some targets need to always link a special object in. Save its path here.
2676 global gdb_saved_set_unbuffered_mode_obj
2677 set gdb_saved_set_unbuffered_mode_obj ""
2679 proc gdb_compile {source dest type options} {
2680 global GDB_TESTCASE_OPTIONS
2681 global gdb_wrapper_file
2682 global gdb_wrapper_flags
2683 global gdb_wrapper_initialized
2686 global gdb_saved_set_unbuffered_mode_obj
2688 set outdir [file dirname $dest]
2690 # Add platform-specific options if a shared library was specified using
2691 # "shlib=librarypath" in OPTIONS.
2695 foreach opt $options {
2696 if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] {
2697 if [test_compiler_info "xlc-*"] {
2698 # IBM xlc compiler doesn't accept shared library named other
2699 # than .so: use "-Wl," to bypass this
2700 lappend source "-Wl,$shlib_name"
2701 } elseif { ([istarget "*-*-mingw*"]
2702 || [istarget *-*-cygwin*]
2703 || [istarget *-*-pe*])} {
2704 lappend source "${shlib_name}.a"
2706 lappend source $shlib_name
2708 if { $shlib_found == 0 } {
2710 if { ([istarget "*-*-mingw*"]
2711 || [istarget *-*-cygwin*]) } {
2712 lappend new_options "additional_flags=-Wl,--enable-auto-import"
2715 } elseif { $opt == "shlib_load" } {
2718 lappend new_options $opt
2722 # We typically link to shared libraries using an absolute path, and
2723 # that's how they are found at runtime. If we are going to
2724 # dynamically load one by basename, we must specify rpath. If we
2725 # are using a remote host, DejaGNU will link to the shared library
2726 # using a relative path, so again we must specify an rpath.
2727 if { $shlib_load || ($shlib_found && [is_remote target]) } {
2728 if { ([istarget "*-*-mingw*"]
2729 || [istarget *-*-cygwin*]
2730 || [istarget *-*-pe*]
2731 || [istarget hppa*-*-hpux*])} {
2732 # Do not need anything.
2733 } elseif { [istarget *-*-freebsd*] || [istarget *-*-openbsd*] } {
2734 lappend new_options "ldflags=-Wl,-rpath,${outdir}"
2735 } elseif { [istarget arm*-*-symbianelf*] } {
2736 if { $shlib_load } {
2737 lappend new_options "libs=-ldl"
2740 if { $shlib_load } {
2741 lappend new_options "libs=-ldl"
2743 lappend new_options "ldflags=-Wl,-rpath,\\\$ORIGIN"
2746 set options $new_options
2748 if [target_info exists is_vxworks] {
2749 set options2 { "additional_flags=-Dvxworks" }
2750 set options [concat $options2 $options]
2752 if [info exists GDB_TESTCASE_OPTIONS] {
2753 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS"
2755 verbose "options are $options"
2756 verbose "source is $source $dest $type $options"
2758 if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init }
2760 if {[target_info exists needs_status_wrapper] && \
2761 [target_info needs_status_wrapper] != "0" && \
2762 [info exists gdb_wrapper_file]} {
2763 lappend options "libs=${gdb_wrapper_file}"
2764 lappend options "ldflags=${gdb_wrapper_flags}"
2767 # Replace the "nowarnings" option with the appropriate additional_flags
2768 # to disable compiler warnings.
2769 set nowarnings [lsearch -exact $options nowarnings]
2770 if {$nowarnings != -1} {
2771 if [target_info exists gdb,nowarnings_flag] {
2772 set flag "additional_flags=[target_info gdb,nowarnings_flag]"
2774 set flag "additional_flags=-w"
2776 set options [lreplace $options $nowarnings $nowarnings $flag]
2779 if { $type == "executable" } {
2780 if { ([istarget "*-*-mingw*"]
2781 || [istarget "*-*-*djgpp"]
2782 || [istarget "*-*-cygwin*"])} {
2783 # Force output to unbuffered mode, by linking in an object file
2784 # with a global contructor that calls setvbuf.
2786 # Compile the special object seperatelly for two reasons:
2787 # 1) Insulate it from $options.
2788 # 2) Avoid compiling it for every gdb_compile invocation,
2789 # which is time consuming, especially if we're remote
2792 if { $gdb_saved_set_unbuffered_mode_obj == "" } {
2793 verbose "compiling gdb_saved_set_unbuffered_obj"
2794 set unbuf_src ${srcdir}/lib/set_unbuffered_mode.c
2795 set unbuf_obj ${objdir}/set_unbuffered_mode.o
2797 set result [gdb_compile "${unbuf_src}" "${unbuf_obj}" object {nowarnings}]
2798 if { $result != "" } {
2801 if {[is_remote host]} {
2802 set gdb_saved_set_unbuffered_mode_obj set_unbuffered_mode_saved.o
2804 set gdb_saved_set_unbuffered_mode_obj ${objdir}/set_unbuffered_mode_saved.o
2806 # Link a copy of the output object, because the
2807 # original may be automatically deleted.
2808 remote_download host $unbuf_obj $gdb_saved_set_unbuffered_mode_obj
2810 verbose "gdb_saved_set_unbuffered_obj already compiled"
2813 # Rely on the internal knowledge that the global ctors are ran in
2814 # reverse link order. In that case, we can use ldflags to
2815 # avoid copying the object file to the host multiple
2817 # This object can only be added if standard libraries are
2818 # used. Thus, we need to disable it if -nostdlib option is used
2819 if {[lsearch -regexp $options "-nostdlib"] < 0 } {
2820 lappend options "ldflags=$gdb_saved_set_unbuffered_mode_obj"
2825 set result [target_compile $source $dest $type $options]
2827 # Prune uninteresting compiler (and linker) output.
2828 regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result
2830 regsub "\[\r\n\]*$" "$result" "" result
2831 regsub "^\[\r\n\]*" "$result" "" result
2833 if {[lsearch $options quiet] < 0} {
2834 # We shall update this on a per language basis, to avoid
2835 # changing the entire testsuite in one go.
2836 if {[lsearch $options f77] >= 0} {
2837 gdb_compile_test $source $result
2838 } elseif { $result != "" } {
2839 clone_output "gdb compile failed, $result"
2846 # This is just like gdb_compile, above, except that it tries compiling
2847 # against several different thread libraries, to see which one this
2849 proc gdb_compile_pthreads {source dest type options} {
2851 set why_msg "unrecognized error"
2852 foreach lib {-lpthreads -lpthread -lthread ""} {
2853 # This kind of wipes out whatever libs the caller may have
2854 # set. Or maybe theirs will override ours. How infelicitous.
2855 set options_with_lib [concat $options [list libs=$lib quiet]]
2856 set ccout [gdb_compile $source $dest $type $options_with_lib]
2857 switch -regexp -- $ccout {
2858 ".*no posix threads support.*" {
2859 set why_msg "missing threads include file"
2862 ".*cannot open -lpthread.*" {
2863 set why_msg "missing runtime threads library"
2865 ".*Can't find library for -lpthread.*" {
2866 set why_msg "missing runtime threads library"
2869 pass "successfully compiled posix threads test case"
2875 if {!$built_binfile} {
2876 unsupported "Couldn't compile [file tail $source]: ${why_msg}"
2881 # Build a shared library from SOURCES.
2883 proc gdb_compile_shlib {sources dest options} {
2884 set obj_options $options
2887 if { [lsearch -exact $options "c++"] >= 0 } {
2888 set info_options "c++"
2890 if [get_compiler_info ${info_options}] {
2894 switch -glob [test_compiler_info] {
2896 lappend obj_options "additional_flags=-qpic"
2899 if { !([istarget "powerpc*-*-aix*"]
2900 || [istarget "rs6000*-*-aix*"]
2901 || [istarget "*-*-cygwin*"]
2902 || [istarget "*-*-mingw*"]
2903 || [istarget "*-*-pe*"]) } {
2904 lappend obj_options "additional_flags=-fpic"
2908 switch -glob [istarget] {
2910 lappend obj_options "additional_flags=+z"
2913 # Disable SGI compiler's implicit -Dsgi
2914 lappend obj_options "additional_flags=-Usgi"
2917 # don't know what the compiler is...
2923 set outdir [file dirname $dest]
2925 foreach source $sources {
2926 set sourcebase [file tail $source]
2927 if {[gdb_compile $source "${outdir}/${sourcebase}.o" object $obj_options] != ""} {
2930 lappend objects ${outdir}/${sourcebase}.o
2933 if [istarget "hppa*-*-hpux*"] {
2934 remote_exec build "ld -b ${objects} -o ${dest}"
2936 set link_options $options
2937 if [test_compiler_info "xlc-*"] {
2938 lappend link_options "additional_flags=-qmkshrobj"
2940 lappend link_options "additional_flags=-shared"
2942 if { ([istarget "*-*-mingw*"]
2943 || [istarget *-*-cygwin*]
2944 || [istarget *-*-pe*]) } {
2945 if { [is_remote host] } {
2946 set name [file tail ${dest}]
2950 lappend link_options "additional_flags=-Wl,--out-implib,${name}.a"
2951 } elseif [is_remote target] {
2952 # By default, we do not set the soname. This causes the linker
2953 # on ELF systems to create a DT_NEEDED entry in the executable
2954 # refering to the full path name of the library. This is a
2955 # problem in remote testing if the library is in a different
2956 # directory there. To fix this, we set a soname of just the
2957 # base filename for the library, and add an appropriate -rpath
2958 # to the main executable (in gdb_compile).
2959 set destbase [file tail $dest]
2960 lappend link_options "additional_flags=-Wl,-soname,$destbase"
2963 if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
2966 if { [is_remote host]
2967 && ([istarget "*-*-mingw*"]
2968 || [istarget *-*-cygwin*]
2969 || [istarget *-*-pe*]) } {
2970 set dest_tail_name [file tail ${dest}]
2971 remote_upload host $dest_tail_name.a ${dest}.a
2972 remote_file host delete $dest_tail_name.a
2978 # This is just like gdb_compile_shlib, above, except that it tries compiling
2979 # against several different thread libraries, to see which one this
2981 proc gdb_compile_shlib_pthreads {sources dest options} {
2983 set why_msg "unrecognized error"
2984 foreach lib {-lpthreads -lpthread -lthread ""} {
2985 # This kind of wipes out whatever libs the caller may have
2986 # set. Or maybe theirs will override ours. How infelicitous.
2987 set options_with_lib [concat $options [list libs=$lib quiet]]
2988 set ccout [gdb_compile_shlib $sources $dest $options_with_lib]
2989 switch -regexp -- $ccout {
2990 ".*no posix threads support.*" {
2991 set why_msg "missing threads include file"
2994 ".*cannot open -lpthread.*" {
2995 set why_msg "missing runtime threads library"
2997 ".*Can't find library for -lpthread.*" {
2998 set why_msg "missing runtime threads library"
3001 pass "successfully compiled posix threads test case"
3007 if {!$built_binfile} {
3008 unsupported "Couldn't compile $sources: ${why_msg}"
3013 # This is just like gdb_compile_pthreads, above, except that we always add the
3014 # objc library for compiling Objective-C programs
3015 proc gdb_compile_objc {source dest type options} {
3017 set why_msg "unrecognized error"
3018 foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} {
3019 # This kind of wipes out whatever libs the caller may have
3020 # set. Or maybe theirs will override ours. How infelicitous.
3021 if { $lib == "solaris" } {
3022 set lib "-lpthread -lposix4"
3024 if { $lib != "-lobjc" } {
3025 set lib "-lobjc $lib"
3027 set options_with_lib [concat $options [list libs=$lib quiet]]
3028 set ccout [gdb_compile $source $dest $type $options_with_lib]
3029 switch -regexp -- $ccout {
3030 ".*no posix threads support.*" {
3031 set why_msg "missing threads include file"
3034 ".*cannot open -lpthread.*" {
3035 set why_msg "missing runtime threads library"
3037 ".*Can't find library for -lpthread.*" {
3038 set why_msg "missing runtime threads library"
3041 pass "successfully compiled objc with posix threads test case"
3047 if {!$built_binfile} {
3048 unsupported "Couldn't compile [file tail $source]: ${why_msg}"
3053 proc send_gdb { string } {
3054 global suppress_flag
3055 if { $suppress_flag } {
3058 return [remote_send host "$string"]
3064 proc gdb_expect { args } {
3065 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
3066 set atimeout [lindex $args 0]
3067 set expcode [list [lindex $args 1]]
3072 upvar timeout timeout
3074 if [target_info exists gdb,timeout] {
3075 if [info exists timeout] {
3076 if { $timeout < [target_info gdb,timeout] } {
3077 set gtimeout [target_info gdb,timeout]
3079 set gtimeout $timeout
3082 set gtimeout [target_info gdb,timeout]
3086 if ![info exists gtimeout] {
3088 if [info exists timeout] {
3089 set gtimeout $timeout
3093 if [info exists atimeout] {
3094 if { ![info exists gtimeout] || $gtimeout < $atimeout } {
3095 set gtimeout $atimeout
3098 if ![info exists gtimeout] {
3104 global suppress_flag
3105 global remote_suppress_flag
3106 if [info exists remote_suppress_flag] {
3107 set old_val $remote_suppress_flag
3109 if [info exists suppress_flag] {
3110 if { $suppress_flag } {
3111 set remote_suppress_flag 1
3115 {uplevel remote_expect host $gtimeout $expcode} string]
3116 if [info exists old_val] {
3117 set remote_suppress_flag $old_val
3119 if [info exists remote_suppress_flag] {
3120 unset remote_suppress_flag
3125 global errorInfo errorCode
3127 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
3129 return -code $code $string
3133 # gdb_expect_list TEST SENTINEL LIST -- expect a sequence of outputs
3135 # Check for long sequence of output by parts.
3136 # TEST: is the test message to be printed with the test success/fail.
3137 # SENTINEL: Is the terminal pattern indicating that output has finished.
3138 # LIST: is the sequence of outputs to match.
3139 # If the sentinel is recognized early, it is considered an error.
3142 # 1 if the test failed,
3143 # 0 if the test passes,
3144 # -1 if there was an internal error.
3146 proc gdb_expect_list {test sentinel list} {
3148 global suppress_flag
3151 if { $suppress_flag } {
3153 unresolved "${test}"
3155 while { ${index} < [llength ${list}] } {
3156 set pattern [lindex ${list} ${index}]
3157 set index [expr ${index} + 1]
3158 verbose -log "gdb_expect_list pattern: /$pattern/" 2
3159 if { ${index} == [llength ${list}] } {
3162 -re "${pattern}${sentinel}" {
3163 # pass "${test}, pattern ${index} + sentinel"
3166 fail "${test} (pattern ${index} + sentinel)"
3169 -re ".*A problem internal to GDB has been detected" {
3170 fail "${test} (GDB internal error)"
3172 gdb_internal_error_resync
3175 fail "${test} (pattern ${index} + sentinel) (timeout)"
3180 # unresolved "${test}, pattern ${index} + sentinel"
3186 # pass "${test}, pattern ${index}"
3189 fail "${test} (pattern ${index})"
3192 -re ".*A problem internal to GDB has been detected" {
3193 fail "${test} (GDB internal error)"
3195 gdb_internal_error_resync
3198 fail "${test} (pattern ${index}) (timeout)"
3203 # unresolved "${test}, pattern ${index}"
3217 proc gdb_suppress_entire_file { reason } {
3218 global suppress_flag
3221 set suppress_flag -1
3225 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
3226 # gdb_expect to fail immediately (until the next call to
3227 # gdb_stop_suppressing_tests).
3229 proc gdb_suppress_tests { args } {
3230 global suppress_flag
3232 return; # fnf - disable pending review of results where
3233 # testsuite ran better without this
3236 if { $suppress_flag == 1 } {
3237 if { [llength $args] > 0 } {
3238 warning "[lindex $args 0]\n"
3240 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n"
3246 # Clear suppress_flag.
3248 proc gdb_stop_suppressing_tests { } {
3249 global suppress_flag
3251 if [info exists suppress_flag] {
3252 if { $suppress_flag > 0 } {
3254 clone_output "Tests restarted.\n"
3261 proc gdb_clear_suppressed { } {
3262 global suppress_flag
3267 proc gdb_start { } {
3272 catch default_gdb_exit
3276 # gdb_load_cmd -- load a file into the debugger.
3277 # ARGS - additional args to load command.
3278 # return a -1 if anything goes wrong.
3280 proc gdb_load_cmd { args } {
3283 if [target_info exists gdb_load_timeout] {
3284 set loadtimeout [target_info gdb_load_timeout]
3286 set loadtimeout 1600
3288 send_gdb "load $args\n"
3289 verbose "Timeout is now $loadtimeout seconds" 2
3290 gdb_expect $loadtimeout {
3291 -re "Loading section\[^\r\]*\r\n" {
3294 -re "Start address\[\r\]*\r\n" {
3297 -re "Transfer rate\[\r\]*\r\n" {
3300 -re "Memory access error\[^\r\]*\r\n" {
3301 perror "Failed to load program"
3304 -re "$gdb_prompt $" {
3307 -re "(.*)\r\n$gdb_prompt " {
3308 perror "Unexpected reponse from 'load' -- $expect_out(1,string)"
3312 perror "Timed out trying to load $args."
3319 # Invoke "gcore". CORE is the name of the core file to write. TEST
3320 # is the name of the test case. This will return 1 if the core file
3321 # was created, 0 otherwise. If this fails to make a core file because
3322 # this configuration of gdb does not support making core files, it
3323 # will call "unsupported", not "fail". However, if this fails to make
3324 # a core file for some other reason, then it will call "fail".
3326 proc gdb_gcore_cmd {core test} {
3330 gdb_test_multiple "gcore $core" $test {
3331 -re "Saved corefile .*\[\r\n\]+$gdb_prompt $" {
3336 -re "Undefined command.*$gdb_prompt $" {
3338 verbose -log "'gcore' command undefined in gdb_gcore_cmd"
3341 -re "(?:Can't create a corefile|Target does not support core file generation\\.)\[\r\n\]+$gdb_prompt $" {
3349 # Load core file CORE. TEST is the name of the test case.
3350 # This will record a pass/fail for loading the core file.
3352 # 1 - core file is successfully loaded
3353 # 0 - core file loaded but has a non fatal error
3354 # -1 - core file failed to load
3356 proc gdb_core_cmd { core test } {
3359 gdb_test_multiple "core $core" "$test" {
3360 -re "\\\[Thread debugging using \[^ \r\n\]* enabled\\\]\r\n" {
3363 -re " is not a core dump:.*\r\n$gdb_prompt $" {
3364 fail "$test (bad file format)"
3367 -re ": No such file or directory.*\r\n$gdb_prompt $" {
3368 fail "$test (file not found)"
3371 -re "Couldn't find .* registers in core file.*\r\n$gdb_prompt $" {
3372 fail "$test (incomplete note section)"
3375 -re "Core was generated by .*\r\n$gdb_prompt $" {
3379 -re ".*$gdb_prompt $" {
3384 fail "$test (timeout)"
3388 fail "unsupported output from 'core' command"
3392 # Return the filename to download to the target and load on the target
3393 # for this shared library. Normally just LIBNAME, unless shared libraries
3394 # for this target have separate link and load images.
3396 proc shlib_target_file { libname } {
3400 # Return the filename GDB will load symbols from when debugging this
3401 # shared library. Normally just LIBNAME, unless shared libraries for
3402 # this target have separate link and load images.
3404 proc shlib_symbol_file { libname } {
3408 # Return the filename to download to the target and load for this
3409 # executable. Normally just BINFILE unless it is renamed to something
3410 # else for this target.
3412 proc exec_target_file { binfile } {
3416 # Return the filename GDB will load symbols from when debugging this
3417 # executable. Normally just BINFILE unless executables for this target
3418 # have separate files for symbols.
3420 proc exec_symbol_file { binfile } {
3424 # Rename the executable file. Normally this is just BINFILE1 being renamed
3425 # to BINFILE2, but some targets require multiple binary files.
3426 proc gdb_rename_execfile { binfile1 binfile2 } {
3427 file rename -force [exec_target_file ${binfile1}] \
3428 [exec_target_file ${binfile2}]
3429 if { [exec_target_file ${binfile1}] != [exec_symbol_file ${binfile1}] } {
3430 file rename -force [exec_symbol_file ${binfile1}] \
3431 [exec_symbol_file ${binfile2}]
3435 # "Touch" the executable file to update the date. Normally this is just
3436 # BINFILE, but some targets require multiple files.
3437 proc gdb_touch_execfile { binfile } {
3438 set time [clock seconds]
3439 file mtime [exec_target_file ${binfile}] $time
3440 if { [exec_target_file ${binfile}] != [exec_symbol_file ${binfile}] } {
3441 file mtime [exec_symbol_file ${binfile}] $time
3445 # Like remote_download but provides a gdb-specific behavior. If DEST
3446 # is "host", and the host is not remote, and TOFILE is not specified,
3447 # then the [file tail] of FROMFILE is passed through
3448 # standard_output_file to compute the destination.
3450 proc gdb_remote_download {dest fromfile {tofile {}}} {
3451 if {$dest == "host" && ![is_remote host] && $tofile == ""} {
3452 set tofile [standard_output_file [file tail $fromfile]]
3455 if { $tofile == "" } {
3456 return [remote_download $dest $fromfile]
3458 return [remote_download $dest $fromfile $tofile]
3464 # Copy a file to the remote target and return its target filename.
3465 # Schedule the file to be deleted at the end of this test.
3467 proc gdb_download { filename } {
3470 set destname [remote_download target $filename]
3471 lappend cleanfiles $destname
3475 # gdb_load_shlibs LIB...
3477 # Copy the listed libraries to the target.
3479 proc gdb_load_shlibs { args } {
3480 if {![is_remote target]} {
3484 foreach file $args {
3485 gdb_download [shlib_target_file $file]
3488 # Even if the target supplies full paths for shared libraries,
3489 # they may not be paths for this system.
3490 gdb_test "set solib-search-path [file dirname [lindex $args 0]]" "" ""
3494 # gdb_load -- load a file into the debugger.
3495 # Many files in config/*.exp override this procedure.
3497 proc gdb_load { arg } {
3498 return [gdb_file_cmd $arg]
3501 # gdb_reload -- load a file into the target. Called before "running",
3502 # either the first time or after already starting the program once,
3503 # for remote targets. Most files that override gdb_load should now
3504 # override this instead.
3506 proc gdb_reload { } {
3507 # For the benefit of existing configurations, default to gdb_load.
3508 # Specifying no file defaults to the executable currently being
3510 return [gdb_load ""]
3513 proc gdb_continue { function } {
3516 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"]
3519 proc default_gdb_init { args } {
3520 global gdb_wrapper_initialized
3521 global gdb_wrapper_target
3522 global gdb_test_file_name
3527 gdb_clear_suppressed
3529 set gdb_test_file_name [file rootname [file tail [lindex $args 0]]]
3531 # Make sure that the wrapper is rebuilt
3532 # with the appropriate multilib option.
3533 if { $gdb_wrapper_target != [current_target_name] } {
3534 set gdb_wrapper_initialized 0
3537 # Unlike most tests, we have a small number of tests that generate
3538 # a very large amount of output. We therefore increase the expect
3539 # buffer size to be able to contain the entire test output.
3541 # Also set this value for the currently running GDB.
3542 match_max [match_max -d]
3544 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
3545 if { [llength $args] > 0 } {
3548 set file [lindex $args 0]
3550 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:"
3553 if [target_info exists gdb_prompt] {
3554 set gdb_prompt [target_info gdb_prompt]
3556 set gdb_prompt "\\(gdb\\)"
3559 if [info exists use_gdb_stub] {
3564 # Turn BASENAME into a full file name in the standard output
3565 # directory. It is ok if BASENAME is the empty string; in this case
3566 # the directory is returned.
3568 proc standard_output_file {basename} {
3569 global objdir subdir gdb_test_file_name GDB_PARALLEL
3571 if {[info exists GDB_PARALLEL]} {
3572 set dir [file join $objdir outputs $subdir $gdb_test_file_name]
3574 return [file join $dir $basename]
3576 return [file join $objdir $subdir $basename]
3580 # Return the name of a file in our standard temporary directory.
3582 proc standard_temp_file {basename} {
3583 global objdir GDB_PARALLEL
3585 if {[info exists GDB_PARALLEL]} {
3586 return [file join $objdir temp $basename]
3592 # Set 'testfile', 'srcfile', and 'binfile'.
3594 # ARGS is a list of source file specifications.
3595 # Without any arguments, the .exp file's base name is used to
3596 # compute the source file name. The ".c" extension is added in this case.
3597 # If ARGS is not empty, each entry is a source file specification.
3598 # If the specification starts with a ".", it is treated as a suffix
3599 # to append to the .exp file's base name.
3600 # If the specification is the empty string, it is treated as if it
3602 # Otherwise it is a file name.
3603 # The first file in the list is used to set the 'srcfile' global.
3604 # Each subsequent name is used to set 'srcfile2', 'srcfile3', etc.
3606 # Most tests should call this without arguments.
3608 # If a completely different binary file name is needed, then it
3609 # should be handled in the .exp file with a suitable comment.
3611 proc standard_testfile {args} {
3612 global gdb_test_file_name
3614 global gdb_test_file_last_vars
3617 global testfile binfile
3619 set testfile $gdb_test_file_name
3620 set binfile [standard_output_file ${testfile}]
3622 if {[llength $args] == 0} {
3626 # Unset our previous output variables.
3627 # This can help catch hidden bugs.
3628 if {[info exists gdb_test_file_last_vars]} {
3629 foreach varname $gdb_test_file_last_vars {
3631 catch {unset $varname}
3634 # 'executable' is often set by tests.
3635 set gdb_test_file_last_vars {executable}
3639 set varname srcfile$suffix
3642 # Handle an extension.
3645 } elseif {[string range $arg 0 0] == "."} {
3646 set arg $testfile$arg
3650 lappend gdb_test_file_last_vars $varname
3652 if {$suffix == ""} {
3660 # The default timeout used when testing GDB commands. We want to use
3661 # the same timeout as the default dejagnu timeout, unless the user has
3662 # already provided a specific value (probably through a site.exp file).
3663 global gdb_test_timeout
3664 if ![info exists gdb_test_timeout] {
3665 set gdb_test_timeout $timeout
3668 # A list of global variables that GDB testcases should not use.
3669 # We try to prevent their use by monitoring write accesses and raising
3670 # an error when that happens.
3671 set banned_variables { bug_id prms_id }
3673 # A list of procedures that GDB testcases should not use.
3674 # We try to prevent their use by monitoring invocations and raising
3675 # an error when that happens.
3676 set banned_procedures { strace }
3678 # gdb_init is called by runtest at start, but also by several
3679 # tests directly; gdb_finish is only called from within runtest after
3680 # each test source execution.
3681 # Placing several traces by repetitive calls to gdb_init leads
3682 # to problems, as only one trace is removed in gdb_finish.
3683 # To overcome this possible problem, we add a variable that records
3684 # if the banned variables and procedures are already traced.
3687 proc gdb_init { args } {
3688 # Reset the timeout value to the default. This way, any testcase
3689 # that changes the timeout value without resetting it cannot affect
3690 # the timeout used in subsequent testcases.
3691 global gdb_test_timeout
3693 set timeout $gdb_test_timeout
3695 # If GDB_INOTIFY is given, check for writes to '.'. This is a
3696 # debugging tool to help confirm that the test suite is
3697 # parallel-safe. You need "inotifywait" from the
3698 # inotify-tools package to use this.
3699 global GDB_INOTIFY inotify_pid
3700 if {[info exists GDB_INOTIFY] && ![info exists inotify_pid]} {
3701 global outdir tool inotify_log_file
3703 set exclusions {outputs temp gdb[.](log|sum) cache}
3704 set exclusion_re ([join $exclusions |])
3706 set inotify_log_file [standard_temp_file inotify.out]
3707 set inotify_pid [exec inotifywait -r -m -e move,create,delete . \
3708 --exclude $exclusion_re \
3709 |& tee -a $outdir/$tool.log $inotify_log_file &]
3711 # Wait for the watches; hopefully this is long enough.
3714 # Clear the log so that we don't emit a warning the first time
3716 set fd [open $inotify_log_file w]
3720 # Block writes to all banned variables, and invocation of all
3721 # banned procedures...
3722 global banned_variables
3723 global banned_procedures
3724 global banned_traced
3725 if (!$banned_traced) {
3726 foreach banned_var $banned_variables {
3727 global "$banned_var"
3728 trace add variable "$banned_var" write error
3730 foreach banned_proc $banned_procedures {
3731 global "$banned_proc"
3732 trace add execution "$banned_proc" enter error
3737 # We set LC_ALL, LC_CTYPE, and LANG to C so that we get the same
3738 # messages as expected.
3743 # Don't let a .inputrc file or an existing setting of INPUTRC mess up
3744 # the test results. Even if /dev/null doesn't exist on the particular
3745 # platform, the readline library will use the default setting just by
3746 # failing to open the file. OTOH, opening /dev/null successfully will
3747 # also result in the default settings being used since nothing will be
3748 # read from this file.
3749 setenv INPUTRC "/dev/null"
3751 # The gdb.base/readline.exp arrow key test relies on the standard VT100
3752 # bindings, so make sure that an appropriate terminal is selected.
3753 # The same bug doesn't show up if we use ^P / ^N instead.
3756 # Some tests (for example gdb.base/maint.exp) shell out from gdb to use
3757 # grep. Clear GREP_OPTIONS to make the behavior predictable,
3758 # especially having color output turned on can cause tests to fail.
3759 setenv GREP_OPTIONS ""
3761 # Clear $gdbserver_reconnect_p.
3762 global gdbserver_reconnect_p
3763 set gdbserver_reconnect_p 1
3764 unset gdbserver_reconnect_p
3766 return [eval default_gdb_init $args]
3769 proc gdb_finish { } {
3770 global gdbserver_reconnect_p
3774 # Give persistent gdbserver a chance to terminate before GDB is killed.
3775 if {[info exists gdbserver_reconnect_p] && $gdbserver_reconnect_p
3776 && [info exists gdb_spawn_id]} {
3783 -re "$gdb_prompt $" {
3788 # Exit first, so that the files are no longer in use.
3791 if { [llength $cleanfiles] > 0 } {
3792 eval remote_file target delete $cleanfiles
3796 # Unblock write access to the banned variables. Dejagnu typically
3797 # resets some of them between testcases.
3798 global banned_variables
3799 global banned_procedures
3800 global banned_traced
3801 if ($banned_traced) {
3802 foreach banned_var $banned_variables {
3803 global "$banned_var"
3804 trace remove variable "$banned_var" write error
3806 foreach banned_proc $banned_procedures {
3807 global "$banned_proc"
3808 trace remove execution "$banned_proc" enter error
3815 set debug_format "unknown"
3817 # Run the gdb command "info source" and extract the debugging format
3818 # information from the output and save it in debug_format.
3820 proc get_debug_format { } {
3826 set debug_format "unknown"
3827 send_gdb "info source\n"
3829 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
3830 set debug_format $expect_out(1,string)
3831 verbose "debug format is $debug_format"
3834 -re "No current source file.\r\n$gdb_prompt $" {
3835 perror "get_debug_format used when no current source file"
3838 -re "$gdb_prompt $" {
3839 warning "couldn't check debug format (no valid response)."
3843 warning "couldn't check debug format (timeout)."
3849 # Return true if FORMAT matches the debug format the current test was
3850 # compiled with. FORMAT is a shell-style globbing pattern; it can use
3851 # `*', `[...]', and so on.
3853 # This function depends on variables set by `get_debug_format', above.
3855 proc test_debug_format {format} {
3858 return [expr [string match $format $debug_format] != 0]
3861 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
3862 # COFF, stabs, etc). If that format matches the format that the
3863 # current test was compiled with, then the next test is expected to
3864 # fail for any target. Returns 1 if the next test or set of tests is
3865 # expected to fail, 0 otherwise (or if it is unknown). Must have
3866 # previously called get_debug_format.
3867 proc setup_xfail_format { format } {
3868 set ret [test_debug_format $format]
3876 # gdb_get_line_number TEXT [FILE]
3878 # Search the source file FILE, and return the line number of the
3879 # first line containing TEXT. If no match is found, an error is thrown.
3881 # TEXT is a string literal, not a regular expression.
3883 # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is
3884 # specified, and does not start with "/", then it is assumed to be in
3885 # "$srcdir/$subdir". This is awkward, and can be fixed in the future,
3886 # by changing the callers and the interface at the same time.
3887 # In particular: gdb.base/break.exp, gdb.base/condbreak.exp,
3888 # gdb.base/ena-dis-br.exp.
3890 # Use this function to keep your test scripts independent of the
3891 # exact line numbering of the source file. Don't write:
3893 # send_gdb "break 20"
3895 # This means that if anyone ever edits your test's source file,
3896 # your test could break. Instead, put a comment like this on the
3897 # source file line you want to break at:
3899 # /* breakpoint spot: frotz.exp: test name */
3901 # and then write, in your test script (which we assume is named
3904 # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
3906 # (Yes, Tcl knows how to handle the nested quotes and brackets.
3909 # % puts "foo [lindex "bar baz" 1]"
3912 # Tcl is quite clever, for a little stringy language.)
3916 # The previous implementation of this procedure used the gdb search command.
3917 # This version is different:
3919 # . It works with MI, and it also works when gdb is not running.
3921 # . It operates on the build machine, not the host machine.
3923 # . For now, this implementation fakes a current directory of
3924 # $srcdir/$subdir to be compatible with the old implementation.
3925 # This will go away eventually and some callers will need to
3928 # . The TEXT argument is literal text and matches literally,
3929 # not a regular expression as it was before.
3931 # . State changes in gdb, such as changing the current file
3932 # and setting $_, no longer happen.
3934 # After a bit of time we can forget about the differences from the
3935 # old implementation.
3937 # --chastain 2004-08-05
3939 proc gdb_get_line_number { text { file "" } } {
3944 if { "$file" == "" } then {
3947 if { ! [regexp "^/" "$file"] } then {
3948 set file "$srcdir/$subdir/$file"
3951 if { [ catch { set fd [open "$file"] } message ] } then {
3956 for { set line 1 } { 1 } { incr line } {
3957 if { [ catch { set nchar [gets "$fd" body] } message ] } then {
3960 if { $nchar < 0 } then {
3963 if { [string first "$text" "$body"] >= 0 } then {
3969 if { [ catch { close "$fd" } message ] } then {
3974 error "undefined tag \"$text\""
3980 # Continue the program until it ends.
3982 # MSSG is the error message that gets printed. If not given, a
3984 # COMMAND is the command to invoke. If not given, "continue" is
3986 # ALLOW_EXTRA is a flag indicating whether the test should expect
3987 # extra output between the "Continuing." line and the program
3988 # exiting. By default it is zero; if nonzero, any extra output
3991 proc gdb_continue_to_end {{mssg ""} {command continue} {allow_extra 0}} {
3992 global inferior_exited_re use_gdb_stub
3995 set text "continue until exit"
3997 set text "continue until exit at $mssg"
4005 # By default, we don't rely on exit() behavior of remote stubs --
4006 # it's common for exit() to be implemented as a simple infinite
4007 # loop, or a forced crash/reset. For native targets, by default, we
4008 # assume process exit is reported as such. If a non-reliable target
4009 # is used, we set a breakpoint at exit, and continue to that.
4010 if { [target_info exists exit_is_reliable] } {
4011 set exit_is_reliable [target_info exit_is_reliable]
4013 set exit_is_reliable [expr ! $use_gdb_stub]
4016 if { ! $exit_is_reliable } {
4017 if {![gdb_breakpoint "exit"]} {
4020 gdb_test $command "Continuing..*Breakpoint .*exit.*" \
4023 # Continue until we exit. Should not stop again.
4024 # Don't bother to check the output of the program, that may be
4025 # extremely tough for some remote systems.
4027 "Continuing.\[\r\n0-9\]+${extra}(... EXIT code 0\[\r\n\]+|$inferior_exited_re normally).*"\
4032 proc rerun_to_main {} {
4033 global gdb_prompt use_gdb_stub
4038 -re ".*Breakpoint .*main .*$gdb_prompt $"\
4039 {pass "rerun to main" ; return 0}
4040 -re "$gdb_prompt $"\
4041 {fail "rerun to main" ; return 0}
4042 timeout {fail "(timeout) rerun to main" ; return 0}
4047 -re "The program .* has been started already.*y or n. $" {
4051 -re "Starting program.*$gdb_prompt $"\
4052 {pass "rerun to main" ; return 0}
4053 -re "$gdb_prompt $"\
4054 {fail "rerun to main" ; return 0}
4055 timeout {fail "(timeout) rerun to main" ; return 0}
4060 # Print a message and return true if a test should be skipped
4061 # due to lack of floating point suport.
4063 proc gdb_skip_float_test { msg } {
4064 if [target_info exists gdb,skip_float_tests] {
4065 verbose "Skipping test '$msg': no float tests."
4071 # Print a message and return true if a test should be skipped
4072 # due to lack of stdio support.
4074 proc gdb_skip_stdio_test { msg } {
4075 if [target_info exists gdb,noinferiorio] {
4076 verbose "Skipping test '$msg': no inferior i/o."
4082 proc gdb_skip_bogus_test { msg } {
4086 # Return true if a test should be skipped due to lack of XML support
4088 # NOTE: This must be called while gdb is *not* running.
4090 gdb_caching_proc gdb_skip_xml_test {
4096 gdb_test_multiple "set tdesc filename ${srcdir}/gdb.xml/trivial.xml" "" {
4097 -re ".*XML support was disabled at compile time.*$gdb_prompt $" {
4100 -re ".*$gdb_prompt $" { }
4106 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
4107 # ${binfile}.dbglnk, which is just like the executable ($binfile) but without
4108 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
4109 # the name of a debuginfo only file. This file will be stored in the same
4112 # Functions for separate debug info testing
4114 # starting with an executable:
4115 # foo --> original executable
4117 # at the end of the process we have:
4118 # foo.stripped --> foo w/o debug info
4119 # foo.debug --> foo's debug info
4120 # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug.
4122 # Return the build-id hex string (usually 160 bits as 40 hex characters)
4123 # converted to the form: .build-id/ab/cdef1234...89.debug
4124 # Return "" if no build-id found.
4125 proc build_id_debug_filename_get { exec } {
4126 set tmp [standard_output_file "${exec}-tmp"]
4127 set objcopy_program [gdb_find_objcopy]
4129 set result [catch "exec $objcopy_program -j .note.gnu.build-id -O binary $exec $tmp" output]
4130 verbose "result is $result"
4131 verbose "output is $output"
4136 fconfigure $fi -translation binary
4137 # Skip the NOTE header.
4142 if ![string compare $data ""] then {
4145 # Convert it to hex.
4146 binary scan $data H* data
4147 regsub {^..} $data {\0/} data
4148 return ".build-id/${data}.debug"
4151 # Create stripped files for DEST, replacing it. If ARGS is passed, it is a
4152 # list of optional flags. The only currently supported flag is no-main,
4153 # which removes the symbol entry for main from the separate debug file.
4155 # Function returns zero on success. Function will return non-zero failure code
4156 # on some targets not supporting separate debug info (such as i386-msdos).
4158 proc gdb_gnu_strip_debug { dest args } {
4160 # Use the first separate debug info file location searched by GDB so the
4161 # run cannot be broken by some stale file searched with higher precedence.
4162 set debug_file "${dest}.debug"
4164 set strip_to_file_program [transform strip]
4165 set objcopy_program [gdb_find_objcopy]
4167 set debug_link [file tail $debug_file]
4168 set stripped_file "${dest}.stripped"
4170 # Get rid of the debug info, and store result in stripped_file
4171 # something like gdb/testsuite/gdb.base/blah.stripped.
4172 set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
4173 verbose "result is $result"
4174 verbose "output is $output"
4179 # Workaround PR binutils/10802:
4180 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
4181 set perm [file attributes ${dest} -permissions]
4182 file attributes ${stripped_file} -permissions $perm
4184 # Get rid of everything but the debug info, and store result in debug_file
4185 # This will be in the .debug subdirectory, see above.
4186 set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
4187 verbose "result is $result"
4188 verbose "output is $output"
4193 # If no-main is passed, strip the symbol for main from the separate
4194 # file. This is to simulate the behavior of elfutils's eu-strip, which
4195 # leaves the symtab in the original file only. There's no way to get
4196 # objcopy or strip to remove the symbol table without also removing the
4197 # debugging sections, so this is as close as we can get.
4198 if { [llength $args] == 1 && [lindex $args 0] == "no-main" } {
4199 set result [catch "exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp" output]
4200 verbose "result is $result"
4201 verbose "output is $output"
4205 file delete "${debug_file}"
4206 file rename "${debug_file}-tmp" "${debug_file}"
4209 # Link the two previous output files together, adding the .gnu_debuglink
4210 # section to the stripped_file, containing a pointer to the debug_file,
4211 # save the new file in dest.
4212 # This will be the regular executable filename, in the usual location.
4213 set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
4214 verbose "result is $result"
4215 verbose "output is $output"
4220 # Workaround PR binutils/10802:
4221 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
4222 set perm [file attributes ${stripped_file} -permissions]
4223 file attributes ${dest} -permissions $perm
4228 # Test the output of GDB_COMMAND matches the pattern obtained
4229 # by concatenating all elements of EXPECTED_LINES. This makes
4230 # it possible to split otherwise very long string into pieces.
4231 # If third argument is not empty, it's used as the name of the
4232 # test to be printed on pass/fail.
4233 proc help_test_raw { gdb_command expected_lines args } {
4234 set message $gdb_command
4235 if [llength $args]>0 then {
4236 set message [lindex $args 0]
4238 set expected_output [join $expected_lines ""]
4239 gdb_test "${gdb_command}" "${expected_output}" $message
4242 # Test the output of "help COMMAND_CLASS". EXPECTED_INITIAL_LINES
4243 # are regular expressions that should match the beginning of output,
4244 # before the list of commands in that class. The presence of
4245 # command list and standard epilogue will be tested automatically.
4246 proc test_class_help { command_class expected_initial_lines args } {
4248 "List of commands\:.*\[\r\n\]+"
4249 "Type \"help\" followed by command name for full documentation\.\[\r\n\]+"
4250 "Type \"apropos word\" to search for commands related to \"word\"\.[\r\n\]+"
4251 "Command name abbreviations are allowed if unambiguous\."
4253 set l_entire_body [concat $expected_initial_lines $l_stock_body]
4255 eval [list help_test_raw "help ${command_class}" $l_entire_body] $args
4258 # COMMAND_LIST should have either one element -- command to test, or
4259 # two elements -- abbreviated command to test, and full command the first
4260 # element is abbreviation of.
4261 # The command must be a prefix command. EXPECTED_INITIAL_LINES
4262 # are regular expressions that should match the beginning of output,
4263 # before the list of subcommands. The presence of
4264 # subcommand list and standard epilogue will be tested automatically.
4265 proc test_prefix_command_help { command_list expected_initial_lines args } {
4266 set command [lindex $command_list 0]
4267 if {[llength $command_list]>1} {
4268 set full_command [lindex $command_list 1]
4270 set full_command $command
4272 # Use 'list' and not just {} because we want variables to
4273 # be expanded in this list.
4274 set l_stock_body [list\
4275 "List of $full_command subcommands\:.*\[\r\n\]+"\
4276 "Type \"help $full_command\" followed by $full_command subcommand name for full documentation\.\[\r\n\]+"\
4277 "Type \"apropos word\" to search for commands related to \"word\"\.\[\r\n\]+"\
4278 "Command name abbreviations are allowed if unambiguous\."]
4279 set l_entire_body [concat $expected_initial_lines $l_stock_body]
4280 if {[llength $args]>0} {
4281 help_test_raw "help ${command}" $l_entire_body [lindex $args 0]
4283 help_test_raw "help ${command}" $l_entire_body
4287 # Build executable named EXECUTABLE from specifications that allow
4288 # different options to be passed to different sub-compilations.
4289 # TESTNAME is the name of the test; this is passed to 'untested' if
4291 # OPTIONS is passed to the final link, using gdb_compile. If OPTIONS
4292 # contains the option "pthreads", then gdb_compile_pthreads is used.
4293 # ARGS is a flat list of source specifications, of the form:
4294 # { SOURCE1 OPTIONS1 [ SOURCE2 OPTIONS2 ]... }
4295 # Each SOURCE is compiled to an object file using its OPTIONS,
4296 # using gdb_compile.
4297 # Returns 0 on success, -1 on failure.
4298 proc build_executable_from_specs {testname executable options args} {
4302 set binfile [standard_output_file $executable]
4305 if { [lsearch -exact $options "c++"] >= 0 } {
4306 set info_options "c++"
4308 if [get_compiler_info ${info_options}] {
4312 set func gdb_compile
4313 set func_index [lsearch -regexp $options {^(pthreads|shlib|shlib_pthreads)$}]
4314 if {$func_index != -1} {
4315 set func "${func}_[lindex $options $func_index]"
4318 # gdb_compile_shlib and gdb_compile_shlib_pthreads do not use the 3rd
4319 # parameter. They also requires $sources while gdb_compile and
4320 # gdb_compile_pthreads require $objects. Moreover they ignore any options.
4321 if [string match gdb_compile_shlib* $func] {
4323 foreach {s local_options} $args {
4324 if { [regexp "^/" "$s"] } then {
4325 lappend sources_path "$s"
4327 lappend sources_path "$srcdir/$subdir/$s"
4330 set ret [$func $sources_path "${binfile}" $options]
4334 foreach {s local_options} $args {
4335 if { ! [regexp "^/" "$s"] } then {
4336 set s "$srcdir/$subdir/$s"
4338 if { [gdb_compile "${s}" "${binfile}${i}.o" object $local_options] != "" } {
4342 lappend objects "${binfile}${i}.o"
4345 set ret [$func $objects "${binfile}" executable $options]
4355 # Build executable named EXECUTABLE, from SOURCES. If SOURCES are not
4356 # provided, uses $EXECUTABLE.c. The TESTNAME paramer is the name of test
4357 # to pass to untested, if something is wrong. OPTIONS are passed
4358 # to gdb_compile directly.
4359 proc build_executable { testname executable {sources ""} {options {debug}} } {
4360 if {[llength $sources]==0} {
4361 set sources ${executable}.c
4364 set arglist [list $testname $executable $options]
4365 foreach source $sources {
4366 lappend arglist $source $options
4369 return [eval build_executable_from_specs $arglist]
4372 # Starts fresh GDB binary and loads EXECUTABLE into GDB. EXECUTABLE is
4373 # the basename of the binary.
4374 proc clean_restart { executable } {
4377 set binfile [standard_output_file ${executable}]
4381 gdb_reinitialize_dir $srcdir/$subdir
4385 # Prepares for testing by calling build_executable_full, then
4387 # TESTNAME is the name of the test.
4388 # Each element in ARGS is a list of the form
4389 # { EXECUTABLE OPTIONS SOURCE_SPEC... }
4390 # These are passed to build_executable_from_specs, which see.
4391 # The last EXECUTABLE is passed to clean_restart.
4392 # Returns 0 on success, non-zero on failure.
4393 proc prepare_for_testing_full {testname args} {
4394 foreach spec $args {
4395 if {[eval build_executable_from_specs [list $testname] $spec] == -1} {
4398 set executable [lindex $spec 0]
4400 clean_restart $executable
4404 # Prepares for testing, by calling build_executable, and then clean_restart.
4405 # Please refer to build_executable for parameter description.
4406 proc prepare_for_testing { testname executable {sources ""} {options {debug}}} {
4408 if {[build_executable $testname $executable $sources $options] == -1} {
4411 clean_restart $executable
4416 proc get_valueof { fmt exp default } {
4419 set test "get valueof \"${exp}\""
4421 gdb_test_multiple "print${fmt} ${exp}" "$test" {
4422 -re "\\$\[0-9\]* = (.*)\[\r\n\]*$gdb_prompt $" {
4423 set val $expect_out(1,string)
4427 fail "$test (timeout)"
4433 proc get_integer_valueof { exp default } {
4436 set test "get integer valueof \"${exp}\""
4438 gdb_test_multiple "print /d ${exp}" "$test" {
4439 -re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" {
4440 set val $expect_out(1,string)
4444 fail "$test (timeout)"
4450 proc get_hexadecimal_valueof { exp default } {
4452 send_gdb "print /x ${exp}\n"
4453 set test "get hexadecimal valueof \"${exp}\""
4455 -re "\\$\[0-9\]* = (0x\[0-9a-zA-Z\]+).*$gdb_prompt $" {
4456 set val $expect_out(1,string)
4461 fail "$test (timeout)"
4467 proc get_sizeof { type default } {
4468 return [get_integer_valueof "sizeof (${type})" $default]
4471 proc get_target_charset { } {
4474 gdb_test_multiple "show target-charset" "" {
4475 -re "The target character set is \"auto; currently (\[^\"\]*)\".*$gdb_prompt $" {
4476 return $expect_out(1,string)
4478 -re "The target character set is \"(\[^\"\]*)\".*$gdb_prompt $" {
4479 return $expect_out(1,string)
4483 # Pick a reasonable default.
4484 warning "Unable to read target-charset."
4488 # Get the current value for remotetimeout and return it.
4489 proc get_remotetimeout { } {
4493 gdb_test_multiple "show remotetimeout" "" {
4494 -re "Timeout limit to wait for target to respond is ($decimal).*$gdb_prompt $" {
4495 return $expect_out(1,string)
4499 # Pick the default that gdb uses
4500 warning "Unable to read remotetimeout"
4504 # Set the remotetimeout to the specified timeout. Nothing is returned.
4505 proc set_remotetimeout { timeout } {
4508 gdb_test_multiple "set remotetimeout $timeout" "" {
4509 -re "$gdb_prompt $" {
4510 verbose "Set remotetimeout to $timeout\n"
4515 # ROOT and FULL are file names. Returns the relative path from ROOT
4516 # to FULL. Note that FULL must be in a subdirectory of ROOT.
4517 # For example, given ROOT = /usr/bin and FULL = /usr/bin/ls, this
4520 proc relative_filename {root full} {
4521 set root_split [file split $root]
4522 set full_split [file split $full]
4524 set len [llength $root_split]
4526 if {[eval file join $root_split]
4527 != [eval file join [lrange $full_split 0 [expr {$len - 1}]]]} {
4528 error "$full not a subdir of $root"
4531 return [eval file join [lrange $full_split $len end]]
4534 # Log gdb command line and script if requested.
4535 if {[info exists TRANSCRIPT]} {
4536 rename send_gdb real_send_gdb
4537 rename remote_spawn real_remote_spawn
4538 rename remote_close real_remote_close
4540 global gdb_transcript
4541 set gdb_transcript ""
4543 global gdb_trans_count
4544 set gdb_trans_count 1
4546 proc remote_spawn {args} {
4547 global gdb_transcript gdb_trans_count outdir
4549 if {$gdb_transcript != ""} {
4550 close $gdb_transcript
4552 set gdb_transcript [open [file join $outdir transcript.$gdb_trans_count] w]
4553 puts $gdb_transcript [lindex $args 1]
4554 incr gdb_trans_count
4556 return [uplevel real_remote_spawn $args]
4559 proc remote_close {args} {
4560 global gdb_transcript
4562 if {$gdb_transcript != ""} {
4563 close $gdb_transcript
4564 set gdb_transcript ""
4567 return [uplevel real_remote_close $args]
4570 proc send_gdb {args} {
4571 global gdb_transcript
4573 if {$gdb_transcript != ""} {
4574 puts -nonewline $gdb_transcript [lindex $args 0]
4577 return [uplevel real_send_gdb $args]
4581 # If GDB_PARALLEL exists, then set up the parallel-mode directories.
4582 if {[info exists GDB_PARALLEL]} {
4583 if {[is_remote host]} {
4586 file mkdir outputs temp cache
4590 proc core_find {binfile {deletefiles {}} {arg ""}} {
4591 global objdir subdir
4593 set destcore "$binfile.core"
4594 file delete $destcore
4596 # Create a core file named "$destcore" rather than just "core", to
4597 # avoid problems with sys admin types that like to regularly prune all
4598 # files named "core" from the system.
4600 # Arbitrarily try setting the core size limit to "unlimited" since
4601 # this does not hurt on systems where the command does not work and
4602 # allows us to generate a core on systems where it does.
4604 # Some systems append "core" to the name of the program; others append
4605 # the name of the program to "core"; still others (like Linux, as of
4606 # May 2003) create cores named "core.PID". In the latter case, we
4607 # could have many core files lying around, and it may be difficult to
4608 # tell which one is ours, so let's run the program in a subdirectory.
4610 set coredir [standard_output_file coredir.[getpid]]
4612 catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile} ${arg}; true) >/dev/null 2>&1\""
4613 # remote_exec host "${binfile}"
4614 foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
4615 if [remote_file build exists $i] {
4616 remote_exec build "mv $i $destcore"
4620 # Check for "core.PID".
4621 if { $found == 0 } {
4622 set names [glob -nocomplain -directory $coredir core.*]
4623 if {[llength $names] == 1} {
4624 set corefile [file join $coredir [lindex $names 0]]
4625 remote_exec build "mv $corefile $destcore"
4629 if { $found == 0 } {
4630 # The braindamaged HPUX shell quits after the ulimit -c above
4631 # without executing ${binfile}. So we try again without the
4632 # ulimit here if we didn't find a core file above.
4633 # Oh, I should mention that any "braindamaged" non-Unix system has
4634 # the same problem. I like the cd bit too, it's really neat'n stuff.
4635 catch "system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\""
4636 foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" {
4637 if [remote_file build exists $i] {
4638 remote_exec build "mv $i $destcore"
4644 # Try to clean up after ourselves.
4645 foreach deletefile $deletefiles {
4646 remote_file build delete [file join $coredir $deletefile]
4648 remote_exec build "rmdir $coredir"
4650 if { $found == 0 } {
4651 warning "can't generate a core file - core tests suppressed - check ulimit -c"
4657 # gdb_target_symbol_prefix_flags returns a string that can be added
4658 # to gdb_compile options to define SYMBOL_PREFIX macro value
4659 # symbol_prefix_flags returns a string that can be added
4660 # for targets that use underscore as symbol prefix.
4661 # TODO: find out automatically if the target needs this.
4663 proc gdb_target_symbol_prefix_flags {} {
4664 if { [istarget "*-*-cygwin*"] || [istarget "i?86-*-mingw*"]
4665 || [istarget "*-*-msdosdjgpp*"] || [istarget "*-*-go32*"] } {
4666 return "additional_flags=-DSYMBOL_PREFIX=\"_\""
4672 # A wrapper for 'remote_exec host' that passes or fails a test.
4673 # Returns 0 if all went well, nonzero on failure.
4674 # TEST is the name of the test, other arguments are as for remote_exec.
4676 proc run_on_host { test program args } {
4677 verbose -log "run_on_host: $program $args"
4678 # remote_exec doesn't work properly if the output is set but the
4679 # input is the empty string -- so replace an empty input with
4681 if {[llength $args] > 1 && [lindex $args 1] == ""} {
4682 set args [lreplace $args 1 1 "/dev/null"]
4684 set result [eval remote_exec host [list $program] $args]
4685 verbose "result is $result"
4686 set status [lindex $result 0]
4687 set output [lindex $result 1]
4692 verbose -log "run_on_host failed: $output"
4698 # Return non-zero if "board_info debug_flags" mentions Fission.
4699 # http://gcc.gnu.org/wiki/DebugFission
4700 # Fission doesn't support everything yet.
4701 # This supports working around bug 15954.
4703 proc using_fission { } {
4704 set debug_flags [board_info [target_info name] debug_flags]
4705 return [regexp -- "-gsplit-dwarf" $debug_flags]
4708 # Always load compatibility stuff.