1 # Copyright 1992-2015 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # This file was written by Fred Fish. (fnf@cygnus.com)
18 # Generic gdb subroutines that should work for any target. If these
19 # need to be modified for any target, it can be done with a variable
20 # or by passing arguments.
23 # Tests would fail, logs on get_compiler_info() would be missing.
24 send_error "`site.exp' not found, run `make site.exp'!\n"
30 load_lib gdb-utils.exp
34 if [info exists TOOL_EXECUTABLE] {
35 set GDB $TOOL_EXECUTABLE
37 if ![info exists GDB] {
38 if ![is_remote host] {
39 set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]]
41 set GDB [transform gdb]
44 verbose "using GDB = $GDB" 2
46 # GDBFLAGS is available for the user to set on the command line.
47 # E.g. make check RUNTESTFLAGS=GDBFLAGS=mumble
48 # Testcases may use it to add additional flags, but they must:
49 # - append new flags, not overwrite
50 # - restore the original value when done
52 if ![info exists GDBFLAGS] {
55 verbose "using GDBFLAGS = $GDBFLAGS" 2
57 # Make the build data directory available to tests.
58 set BUILD_DATA_DIRECTORY "[pwd]/../data-directory"
60 # INTERNAL_GDBFLAGS contains flags that the testsuite requires.
61 global INTERNAL_GDBFLAGS
62 if ![info exists INTERNAL_GDBFLAGS] {
63 set INTERNAL_GDBFLAGS "-nw -nx -data-directory $BUILD_DATA_DIRECTORY"
66 # The variable gdb_prompt is a regexp which matches the gdb prompt.
67 # Set it if it is not already set. This is also set by default_gdb_init
68 # but it's not clear what removing one of them will break.
69 # See with_gdb_prompt for more details on prompt handling.
71 if ![info exists gdb_prompt] then {
72 set gdb_prompt "\\(gdb\\)"
75 # A regexp that matches the pagination prompt.
76 set pagination_prompt [string_to_regexp "---Type <return> to continue, or q <return> to quit---"]
78 # The variable fullname_syntax_POSIX is a regexp which matches a POSIX
79 # absolute path ie. /foo/
80 set fullname_syntax_POSIX {/[^\n]*/}
81 # The variable fullname_syntax_UNC is a regexp which matches a Windows
82 # UNC path ie. \\D\foo\
83 set fullname_syntax_UNC {\\\\[^\\]+\\[^\n]+\\}
84 # The variable fullname_syntax_DOS_CASE is a regexp which matches a
85 # particular DOS case that GDB most likely will output
86 # ie. \foo\, but don't match \\.*\
87 set fullname_syntax_DOS_CASE {\\[^\\][^\n]*\\}
88 # The variable fullname_syntax_DOS is a regexp which matches a DOS path
89 # ie. a:\foo\ && a:foo\
90 set fullname_syntax_DOS {[a-zA-Z]:[^\n]*\\}
91 # The variable fullname_syntax is a regexp which matches what GDB considers
92 # an absolute path. It is currently debatable if the Windows style paths
93 # d:foo and \abc should be considered valid as an absolute path.
94 # Also, the purpse of this regexp is not to recognize a well formed
95 # absolute path, but to say with certainty that a path is absolute.
96 set fullname_syntax "($fullname_syntax_POSIX|$fullname_syntax_UNC|$fullname_syntax_DOS_CASE|$fullname_syntax_DOS)"
98 # Needed for some tests under Cygwin.
102 if ![info exists env(EXEEXT)] {
105 set EXEEXT $env(EXEEXT)
110 set inferior_exited_re "(\\\[Inferior \[0-9\]+ \\(.*\\) exited)"
112 ### Only procedures should come after this point.
115 # gdb_version -- extract and print the version number of GDB
117 proc default_gdb_version {} {
119 global INTERNAL_GDBFLAGS GDBFLAGS
123 if {[info exists inotify_pid]} {
124 eval exec kill $inotify_pid
127 set output [remote_exec host "$GDB $INTERNAL_GDBFLAGS --version"]
128 set tmp [lindex $output 1]
130 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
131 if ![is_remote host] {
132 clone_output "[which $GDB] version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
134 clone_output "$GDB on remote host version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
138 proc gdb_version { } {
139 return [default_gdb_version]
143 # gdb_unload -- unload a file if one is loaded
144 # Return 0 on success, -1 on error.
153 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
154 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
155 -re "A program is being debugged already.*Are you sure you want to change the file.*y or n. $" {
159 -re "Discard symbol table from .*y or n.*$" {
163 -re "$gdb_prompt $" {}
165 perror "couldn't unload file in $GDB (timeout)."
172 # Many of the tests depend on setting breakpoints at various places and
173 # running until that breakpoint is reached. At times, we want to start
174 # with a clean-slate with respect to breakpoints, so this utility proc
175 # lets us do this without duplicating this code everywhere.
178 proc delete_breakpoints {} {
181 # we need a larger timeout value here or this thing just confuses
182 # itself. May need a better implementation if possible. - guo
186 set msg "delete all breakpoints in delete_breakpoints"
188 gdb_test_multiple "delete breakpoints" "$msg" {
189 -re "Delete all breakpoints.*y or n.*$" {
193 -re "$gdb_prompt $" {
199 # Confirm with "info breakpoints".
201 set msg "info breakpoints"
202 gdb_test_multiple $msg $msg {
203 -re "No breakpoints or watchpoints..*$gdb_prompt $" {
206 -re "$gdb_prompt $" {
212 perror "breakpoints not deleted"
216 # Generic run command.
218 # The second pattern below matches up to the first newline *only*.
219 # Using ``.*$'' could swallow up output that we attempt to match
222 # N.B. This function does not wait for gdb to return to the prompt,
223 # that is the caller's responsibility.
225 proc gdb_run_cmd {args} {
226 global gdb_prompt use_gdb_stub
228 foreach command [gdb_init_commands] {
229 send_gdb "$command\n"
231 -re "$gdb_prompt $" { }
233 perror "gdb_init_command for target failed"
240 if [target_info exists gdb,do_reload_on_run] {
241 if { [gdb_reload] != 0 } {
244 send_gdb "continue\n"
246 -re "Continu\[^\r\n\]*\[\r\n\]" {}
252 if [target_info exists gdb,start_symbol] {
253 set start [target_info gdb,start_symbol]
257 send_gdb "jump *$start\n"
259 while { $start_attempt } {
260 # Cap (re)start attempts at three to ensure that this loop
261 # always eventually fails. Don't worry about trying to be
262 # clever and not send a command when it has failed.
263 if [expr $start_attempt > 3] {
264 perror "Jump to start() failed (retry count exceeded)"
267 set start_attempt [expr $start_attempt + 1]
269 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
272 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
273 perror "Can't find start symbol to run in gdb_run"
276 -re "No symbol \"start\" in current.*$gdb_prompt $" {
277 send_gdb "jump *_start\n"
279 -re "No symbol.*context.*$gdb_prompt $" {
282 -re "Line.* Jump anyway.*y or n. $" {
285 -re "The program is not being run.*$gdb_prompt $" {
286 if { [gdb_reload] != 0 } {
289 send_gdb "jump *$start\n"
292 perror "Jump to start() failed (timeout)"
300 if [target_info exists gdb,do_reload_on_run] {
301 if { [gdb_reload] != 0 } {
305 send_gdb "run $args\n"
306 # This doesn't work quite right yet.
307 # Use -notransfer here so that test cases (like chng-sym.exp)
308 # may test for additional start-up messages.
310 -re "The program .* has been started already.*y or n. $" {
314 -notransfer -re "Starting program: \[^\r\n\]*" {}
315 -notransfer -re "$gdb_prompt $" {
316 # There is no more input expected.
321 # Generic start command. Return 0 if we could start the program, -1
324 # N.B. This function does not wait for gdb to return to the prompt,
325 # that is the caller's responsibility.
327 proc gdb_start_cmd {args} {
328 global gdb_prompt use_gdb_stub
330 foreach command [gdb_init_commands] {
331 send_gdb "$command\n"
333 -re "$gdb_prompt $" { }
335 perror "gdb_init_command for target failed"
345 send_gdb "start $args\n"
346 # Use -notransfer here so that test cases (like chng-sym.exp)
347 # may test for additional start-up messages.
349 -re "The program .* has been started already.*y or n. $" {
353 -notransfer -re "Starting program: \[^\r\n\]*" {
360 # Set a breakpoint at FUNCTION. If there is an additional argument it is
361 # a list of options; the supported options are allow-pending, temporary,
362 # message, no-message, and passfail.
363 # The result is 1 for success, 0 for failure.
365 # Note: The handling of message vs no-message is messed up, but it's based
366 # on historical usage. By default this function does not print passes,
368 # no-message: turns off printing of fails (and passes, but they're already off)
369 # message: turns on printing of passes (and fails, but they're already on)
371 proc gdb_breakpoint { function args } {
375 set pending_response n
376 if {[lsearch -exact $args allow-pending] != -1} {
377 set pending_response y
380 set break_command "break"
381 set break_message "Breakpoint"
382 if {[lsearch -exact $args temporary] != -1} {
383 set break_command "tbreak"
384 set break_message "Temporary breakpoint"
389 set no_message_loc [lsearch -exact $args no-message]
390 set message_loc [lsearch -exact $args message]
391 # The last one to appear in args wins.
392 if { $no_message_loc > $message_loc } {
394 } elseif { $message_loc > $no_message_loc } {
398 set test_name "setting breakpoint at $function"
400 send_gdb "$break_command $function\n"
401 # The first two regexps are what we get with -g, the third is without -g.
403 -re "$break_message \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
404 -re "$break_message \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
405 -re "$break_message \[0-9\]* at .*$gdb_prompt $" {}
406 -re "$break_message \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" {
407 if {$pending_response == "n"} {
414 -re "Make breakpoint pending.*y or \\\[n\\\]. $" {
415 send_gdb "$pending_response\n"
418 -re "A problem internal to GDB has been detected" {
420 fail "$test_name (GDB internal error)"
422 gdb_internal_error_resync
425 -re "$gdb_prompt $" {
433 fail "$test_name (eof)"
439 fail "$test_name (timeout)"
450 # Set breakpoint at function and run gdb until it breaks there.
451 # Since this is the only breakpoint that will be set, if it stops
452 # at a breakpoint, we will assume it is the one we want. We can't
453 # just compare to "function" because it might be a fully qualified,
454 # single quoted C++ function specifier.
456 # If there are additional arguments, pass them to gdb_breakpoint.
457 # We recognize no-message/message ourselves.
458 # The default is no-message.
459 # no-message is messed up here, like gdb_breakpoint: to preserve
460 # historical usage fails are always printed by default.
461 # no-message: turns off printing of fails (and passes, but they're already off)
462 # message: turns on printing of passes (and fails, but they're already on)
464 proc runto { function args } {
470 # Default to "no-message".
471 set args "no-message $args"
475 set no_message_loc [lsearch -exact $args no-message]
476 set message_loc [lsearch -exact $args message]
477 # The last one to appear in args wins.
478 if { $no_message_loc > $message_loc } {
480 } elseif { $message_loc > $no_message_loc } {
484 set test_name "running to $function in runto"
486 # We need to use eval here to pass our varargs args to gdb_breakpoint
487 # which is also a varargs function.
488 # But we also have to be careful because $function may have multiple
489 # elements, and we don't want Tcl to move the remaining elements after
490 # the first to $args. That is why $function is wrapped in {}.
491 if ![eval gdb_breakpoint {$function} $args] {
497 # the "at foo.c:36" output we get with -g.
498 # the "in func" output we get without -g.
500 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
506 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
512 -re "The target does not support running in non-stop mode.\r\n$gdb_prompt $" {
514 unsupported "Non-stop mode not supported"
518 -re ".*A problem internal to GDB has been detected" {
520 fail "$test_name (GDB internal error)"
522 gdb_internal_error_resync
525 -re "$gdb_prompt $" {
533 fail "$test_name (eof)"
539 fail "$test_name (timeout)"
550 # Ask gdb to run until we hit a breakpoint at main.
552 # N.B. This function deletes all existing breakpoints.
553 # If you don't want that, use gdb_start_cmd.
555 proc runto_main { } {
556 return [runto main no-message]
559 ### Continue, and expect to hit a breakpoint.
560 ### Report a pass or fail, depending on whether it seems to have
561 ### worked. Use NAME as part of the test name; each call to
562 ### continue_to_breakpoint should use a NAME which is unique within
564 proc gdb_continue_to_breakpoint {name {location_pattern .*}} {
566 set full_name "continue to breakpoint: $name"
568 gdb_test_multiple "continue" $full_name {
569 -re "(?:Breakpoint|Temporary breakpoint) .* (at|in) $location_pattern\r\n$gdb_prompt $" {
576 # gdb_internal_error_resync:
578 # Answer the questions GDB asks after it reports an internal error
579 # until we get back to a GDB prompt. Decline to quit the debugging
580 # session, and decline to create a core file. Return non-zero if the
583 # This procedure just answers whatever questions come up until it sees
584 # a GDB prompt; it doesn't require you to have matched the input up to
585 # any specific point. However, it only answers questions it sees in
586 # the output itself, so if you've matched a question, you had better
587 # answer it yourself before calling this.
589 # You can use this function thus:
593 # -re ".*A problem internal to GDB has been detected" {
594 # gdb_internal_error_resync
599 proc gdb_internal_error_resync {} {
602 verbose -log "Resyncing due to internal error."
605 while {$count < 10} {
607 -re "Quit this debugging session\\? \\(y or n\\) $" {
611 -re "Create a core file of GDB\\? \\(y or n\\) $" {
615 -re "$gdb_prompt $" {
616 # We're resynchronized.
620 perror "Could not resync from internal error (timeout)"
625 perror "Could not resync from internal error (resync count exceeded)"
630 # gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS
631 # Send a command to gdb; test the result.
633 # COMMAND is the command to execute, send to GDB with send_gdb. If
634 # this is the null string no command is sent.
635 # MESSAGE is a message to be printed with the built-in failure patterns
636 # if one of them matches. If MESSAGE is empty COMMAND will be used.
637 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
638 # patterns. Pattern elements will be evaluated in the caller's
639 # context; action elements will be executed in the caller's context.
640 # Unlike patterns for gdb_test, these patterns should generally include
641 # the final newline and prompt.
644 # 1 if the test failed, according to a built-in failure pattern
645 # 0 if only user-supplied patterns matched
646 # -1 if there was an internal error.
648 # You can use this function thus:
650 # gdb_test_multiple "print foo" "test foo" {
651 # -re "expected output 1" {
654 # -re "expected output 2" {
659 # The standard patterns, such as "Inferior exited..." and "A problem
660 # ...", all being implicitly appended to that list.
662 proc gdb_test_multiple { command message user_code } {
663 global verbose use_gdb_stub
664 global gdb_prompt pagination_prompt
666 global inferior_exited_re
667 upvar timeout timeout
668 upvar expect_out expect_out
670 if { $message == "" } {
674 if [string match "*\[\r\n\]" $command] {
675 error "Invalid trailing newline in \"$message\" test"
678 if [string match "*\[\r\n\]*" $message] {
679 error "Invalid newline in \"$message\" test"
683 && [regexp -nocase {^\s*(r|run|star|start|at|att|atta|attac|attach)\M} \
685 error "gdbserver does not support $command without extended-remote"
688 # TCL/EXPECT WART ALERT
689 # Expect does something very strange when it receives a single braced
690 # argument. It splits it along word separators and performs substitutions.
691 # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
692 # evaluated as "\[ab\]". But that's not how TCL normally works; inside a
693 # double-quoted list item, "\[ab\]" is just a long way of representing
694 # "[ab]", because the backslashes will be removed by lindex.
696 # Unfortunately, there appears to be no easy way to duplicate the splitting
697 # that expect will do from within TCL. And many places make use of the
698 # "\[0-9\]" construct, so we need to support that; and some places make use
699 # of the "[func]" construct, so we need to support that too. In order to
700 # get this right we have to substitute quoted list elements differently
701 # from braced list elements.
703 # We do this roughly the same way that Expect does it. We have to use two
704 # lists, because if we leave unquoted newlines in the argument to uplevel
705 # they'll be treated as command separators, and if we escape newlines
706 # we mangle newlines inside of command blocks. This assumes that the
707 # input doesn't contain a pattern which contains actual embedded newlines
710 regsub -all {\n} ${user_code} { } subst_code
711 set subst_code [uplevel list $subst_code]
713 set processed_code ""
715 set expecting_action 0
717 foreach item $user_code subst_item $subst_code {
718 if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } {
719 lappend processed_code $item
722 if { $item == "-indices" || $item == "-re" || $item == "-ex" } {
723 lappend processed_code $item
726 if { $item == "-timeout" } {
728 lappend processed_code $item
731 if { $expecting_arg } {
733 lappend processed_code $subst_item
736 if { $expecting_action } {
737 lappend processed_code "uplevel [list $item]"
738 set expecting_action 0
739 # Cosmetic, no effect on the list.
740 append processed_code "\n"
743 set expecting_action 1
744 lappend processed_code $subst_item
745 if {$patterns != ""} {
748 append patterns "\"$subst_item\""
751 # Also purely cosmetic.
752 regsub -all {\r} $patterns {\\r} patterns
753 regsub -all {\n} $patterns {\\n} patterns
756 send_user "Sending \"$command\" to gdb\n"
757 send_user "Looking to match \"$patterns\"\n"
758 send_user "Message is \"$message\"\n"
762 set string "${command}\n"
763 if { $command != "" } {
764 set multi_line_re "\[\r\n\] *>"
765 while { "$string" != "" } {
766 set foo [string first "\n" "$string"]
767 set len [string length "$string"]
768 if { $foo < [expr $len - 1] } {
769 set str [string range "$string" 0 $foo]
770 if { [send_gdb "$str"] != "" } {
773 if { ! $suppress_flag } {
774 perror "Couldn't send $command to GDB."
779 # since we're checking if each line of the multi-line
780 # command are 'accepted' by GDB here,
781 # we need to set -notransfer expect option so that
782 # command output is not lost for pattern matching
785 -notransfer -re "$multi_line_re$" { verbose "partial: match" 3 }
786 timeout { verbose "partial: timeout" 3 }
788 set string [string range "$string" [expr $foo + 1] end]
789 set multi_line_re "$multi_line_re.*\[\r\n\] *>"
794 if { "$string" != "" } {
795 if { [send_gdb "$string"] != "" } {
798 if { ! $suppress_flag } {
799 perror "Couldn't send $command to GDB."
808 -re ".*A problem internal to GDB has been detected" {
809 fail "$message (GDB internal error)"
810 gdb_internal_error_resync
813 -re "\\*\\*\\* DOSEXIT code.*" {
814 if { $message != "" } {
817 gdb_suppress_entire_file "GDB died"
821 append code $processed_code
823 -re "Ending remote debugging.*$gdb_prompt $" {
824 if ![isnative] then {
825 warning "Can`t communicate to remote target."
831 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
832 perror "Undefined command \"$command\"."
836 -re "Ambiguous command.*$gdb_prompt $" {
837 perror "\"$command\" is not a unique command name."
841 -re "$inferior_exited_re with code \[0-9\]+.*$gdb_prompt $" {
842 if ![string match "" $message] then {
843 set errmsg "$message (the program exited)"
845 set errmsg "$command (the program exited)"
850 -re "$inferior_exited_re normally.*$gdb_prompt $" {
851 if ![string match "" $message] then {
852 set errmsg "$message (the program exited)"
854 set errmsg "$command (the program exited)"
859 -re "The program is not being run.*$gdb_prompt $" {
860 if ![string match "" $message] then {
861 set errmsg "$message (the program is no longer running)"
863 set errmsg "$command (the program is no longer running)"
868 -re "\r\n$gdb_prompt $" {
869 if ![string match "" $message] then {
874 -re "$pagination_prompt" {
876 perror "Window too small."
880 -re "\\((y or n|y or \\\[n\\\]|\\\[y\\\] or n)\\) " {
882 gdb_expect -re "$gdb_prompt $"
883 fail "$message (got interactive prompt)"
886 -re "\\\[0\\\] cancel\r\n\\\[1\\\] all.*\r\n> $" {
888 gdb_expect -re "$gdb_prompt $"
889 fail "$message (got breakpoint menu)"
893 perror "Process no longer exists"
894 if { $message != "" } {
900 perror "internal buffer is full."
905 if ![string match "" $message] then {
906 fail "$message (timeout)"
913 set code [catch {gdb_expect $code} string]
915 global errorInfo errorCode
916 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
917 } elseif {$code > 1} {
918 return -code $code $string
923 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
924 # Send a command to gdb; test the result.
926 # COMMAND is the command to execute, send to GDB with send_gdb. If
927 # this is the null string no command is sent.
928 # PATTERN is the pattern to match for a PASS, and must NOT include
929 # the \r\n sequence immediately before the gdb prompt.
930 # MESSAGE is an optional message to be printed. If this is
931 # omitted, then the pass/fail messages use the command string as the
932 # message. (If this is the empty string, then sometimes we don't
933 # call pass or fail at all; I don't understand this at all.)
934 # QUESTION is a question GDB may ask in response to COMMAND, like
936 # RESPONSE is the response to send if QUESTION appears.
939 # 1 if the test failed,
940 # 0 if the test passes,
941 # -1 if there was an internal error.
943 proc gdb_test { args } {
947 upvar timeout timeout
949 if [llength $args]>2 then {
950 set message [lindex $args 2]
952 set message [lindex $args 0]
954 set command [lindex $args 0]
955 set pattern [lindex $args 1]
957 if [llength $args]==5 {
958 set question_string [lindex $args 3]
959 set response_string [lindex $args 4]
961 set question_string "^FOOBAR$"
964 return [gdb_test_multiple $command $message {
965 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
966 if ![string match "" $message] then {
970 -re "(${question_string})$" {
971 send_gdb "$response_string\n"
977 # gdb_test_no_output COMMAND MESSAGE
978 # Send a command to GDB and verify that this command generated no output.
980 # See gdb_test_multiple for a description of the COMMAND and MESSAGE
981 # parameters. If MESSAGE is ommitted, then COMMAND will be used as
982 # the message. (If MESSAGE is the empty string, then sometimes we do not
983 # call pass or fail at all; I don't understand this at all.)
985 proc gdb_test_no_output { args } {
987 set command [lindex $args 0]
988 if [llength $args]>1 then {
989 set message [lindex $args 1]
994 set command_regex [string_to_regexp $command]
995 gdb_test_multiple $command $message {
996 -re "^$command_regex\r\n$gdb_prompt $" {
997 if ![string match "" $message] then {
1004 # Send a command and then wait for a sequence of outputs.
1005 # This is useful when the sequence is long and contains ".*", a single
1006 # regexp to match the entire output can get a timeout much easier.
1008 # COMMAND is the command to send.
1009 # TEST_NAME is passed to pass/fail. COMMAND is used if TEST_NAME is "".
1010 # EXPECTED_OUTPUT_LIST is a list of regexps of expected output, which are
1011 # processed in order, and all must be present in the output.
1013 # It is unnecessary to specify ".*" at the beginning or end of any regexp,
1014 # there is an implicit ".*" between each element of EXPECTED_OUTPUT_LIST.
1015 # There is also an implicit ".*" between the last regexp and the gdb prompt.
1017 # Like gdb_test and gdb_test_multiple, the output is expected to end with the
1018 # gdb prompt, which must not be specified in EXPECTED_OUTPUT_LIST.
1021 # 1 if the test failed,
1022 # 0 if the test passes,
1023 # -1 if there was an internal error.
1025 proc gdb_test_sequence { command test_name expected_output_list } {
1027 if { $test_name == "" } {
1028 set test_name $command
1030 lappend expected_output_list ""; # implicit ".*" before gdb prompt
1031 send_gdb "$command\n"
1032 return [gdb_expect_list $test_name "$gdb_prompt $" $expected_output_list]
1036 # Test that a command gives an error. For pass or fail, return
1037 # a 1 to indicate that more tests can proceed. However a timeout
1038 # is a serious error, generates a special fail message, and causes
1039 # a 0 to be returned to indicate that more tests are likely to fail
1042 proc test_print_reject { args } {
1046 if [llength $args]==2 then {
1047 set expectthis [lindex $args 1]
1049 set expectthis "should never match this bogus string"
1051 set sendthis [lindex $args 0]
1052 if $verbose>2 then {
1053 send_user "Sending \"$sendthis\" to gdb\n"
1054 send_user "Looking to match \"$expectthis\"\n"
1056 send_gdb "$sendthis\n"
1057 #FIXME: Should add timeout as parameter.
1059 -re "A .* in expression.*\\.*$gdb_prompt $" {
1060 pass "reject $sendthis"
1063 -re "Invalid syntax in expression.*$gdb_prompt $" {
1064 pass "reject $sendthis"
1067 -re "Junk after end of expression.*$gdb_prompt $" {
1068 pass "reject $sendthis"
1071 -re "Invalid number.*$gdb_prompt $" {
1072 pass "reject $sendthis"
1075 -re "Invalid character constant.*$gdb_prompt $" {
1076 pass "reject $sendthis"
1079 -re "No symbol table is loaded.*$gdb_prompt $" {
1080 pass "reject $sendthis"
1083 -re "No symbol .* in current context.*$gdb_prompt $" {
1084 pass "reject $sendthis"
1087 -re "Unmatched single quote.*$gdb_prompt $" {
1088 pass "reject $sendthis"
1091 -re "A character constant must contain at least one character.*$gdb_prompt $" {
1092 pass "reject $sendthis"
1095 -re "$expectthis.*$gdb_prompt $" {
1096 pass "reject $sendthis"
1099 -re ".*$gdb_prompt $" {
1100 fail "reject $sendthis"
1104 fail "reject $sendthis (eof or timeout)"
1111 # Same as gdb_test, but the second parameter is not a regexp,
1112 # but a string that must match exactly.
1114 proc gdb_test_exact { args } {
1115 upvar timeout timeout
1117 set command [lindex $args 0]
1119 # This applies a special meaning to a null string pattern. Without
1120 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
1121 # messages from commands that should have no output except a new
1122 # prompt. With this, only results of a null string will match a null
1125 set pattern [lindex $args 1]
1126 if [string match $pattern ""] {
1127 set pattern [string_to_regexp [lindex $args 0]]
1129 set pattern [string_to_regexp [lindex $args 1]]
1132 # It is most natural to write the pattern argument with only
1133 # embedded \n's, especially if you are trying to avoid Tcl quoting
1134 # problems. But gdb_expect really wants to see \r\n in patterns. So
1135 # transform the pattern here. First transform \r\n back to \n, in
1136 # case some users of gdb_test_exact already do the right thing.
1137 regsub -all "\r\n" $pattern "\n" pattern
1138 regsub -all "\n" $pattern "\r\n" pattern
1139 if [llength $args]==3 then {
1140 set message [lindex $args 2]
1142 set message $command
1145 return [gdb_test $command $pattern $message]
1148 # Wrapper around gdb_test_multiple that looks for a list of expected
1149 # output elements, but which can appear in any order.
1150 # CMD is the gdb command.
1151 # NAME is the name of the test.
1152 # ELM_FIND_REGEXP specifies how to partition the output into elements to
1154 # ELM_EXTRACT_REGEXP specifies the part of ELM_FIND_REGEXP to compare.
1155 # RESULT_MATCH_LIST is a list of exact matches for each expected element.
1156 # All elements of RESULT_MATCH_LIST must appear for the test to pass.
1158 # A typical use of ELM_FIND_REGEXP/ELM_EXTRACT_REGEXP is to extract one line
1159 # of text per element and then strip trailing \r\n's.
1161 # gdb_test_list_exact "foo" "bar" \
1162 # "\[^\r\n\]+\[\r\n\]+" \
1165 # {expected result 1} \
1166 # {expected result 2} \
1169 proc gdb_test_list_exact { cmd name elm_find_regexp elm_extract_regexp result_match_list } {
1172 set matches [lsort $result_match_list]
1174 gdb_test_multiple $cmd $name {
1175 "$cmd\[\r\n\]" { exp_continue }
1176 -re $elm_find_regexp {
1177 set str $expect_out(0,string)
1178 verbose -log "seen: $str" 3
1179 regexp -- $elm_extract_regexp $str elm_seen
1180 verbose -log "extracted: $elm_seen" 3
1181 lappend seen $elm_seen
1184 -re "$gdb_prompt $" {
1186 foreach got [lsort $seen] have $matches {
1187 if {![string equal $got $have]} {
1192 if {[string length $failed] != 0} {
1193 fail "$name ($failed not found)"
1202 # Issue a PASS and return true if evaluating CONDITION in the caller's
1203 # frame returns true, and issue a FAIL and return false otherwise.
1204 # MESSAGE is the pass/fail message to be printed. If MESSAGE is
1205 # omitted or is empty, then the pass/fail messages use the condition
1206 # string as the message.
1208 proc gdb_assert { condition {message ""} } {
1209 if { $message == ""} {
1210 set message $condition
1213 set res [uplevel 1 expr $condition]
1222 proc gdb_reinitialize_dir { subdir } {
1225 if [is_remote host] {
1230 -re "Reinitialize source path to empty.*y or n. " {
1233 -re "Source directories searched.*$gdb_prompt $" {
1234 send_gdb "dir $subdir\n"
1236 -re "Source directories searched.*$gdb_prompt $" {
1237 verbose "Dir set to $subdir"
1239 -re "$gdb_prompt $" {
1240 perror "Dir \"$subdir\" failed."
1244 -re "$gdb_prompt $" {
1245 perror "Dir \"$subdir\" failed."
1249 -re "$gdb_prompt $" {
1250 perror "Dir \"$subdir\" failed."
1256 # gdb_exit -- exit the GDB, killing the target program if necessary
1258 proc default_gdb_exit {} {
1260 global INTERNAL_GDBFLAGS GDBFLAGS
1263 global inotify_log_file
1265 gdb_stop_suppressing_tests
1267 if ![info exists gdb_spawn_id] {
1271 verbose "Quitting $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1273 if {[info exists inotify_log_file] && [file exists $inotify_log_file]} {
1274 set fd [open $inotify_log_file]
1275 set data [read -nonewline $fd]
1278 if {[string compare $data ""] != 0} {
1279 warning "parallel-unsafe file creations noticed"
1282 set fd [open $inotify_log_file w]
1287 if { [is_remote host] && [board_info host exists fileid] } {
1294 -re "DOSEXIT code" { }
1299 if ![is_remote host] {
1305 # Load a file into the debugger.
1306 # The return value is 0 for success, -1 for failure.
1308 # This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO
1309 # to one of these values:
1311 # debug file was loaded successfully and has debug information
1312 # nodebug file was loaded successfully and has no debug information
1313 # lzma file was loaded, .gnu_debugdata found, but no LZMA support
1315 # fail file was not loaded
1317 # I tried returning this information as part of the return value,
1318 # but ran into a mess because of the many re-implementations of
1319 # gdb_load in config/*.exp.
1321 # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use
1322 # this if they can get more information set.
1324 proc gdb_file_cmd { arg } {
1328 global last_loaded_file
1330 # Save this for the benefit of gdbserver-support.exp.
1331 set last_loaded_file $arg
1333 # Set whether debug info was found.
1334 # Default to "fail".
1335 global gdb_file_cmd_debug_info
1336 set gdb_file_cmd_debug_info "fail"
1338 if [is_remote host] {
1339 set arg [remote_download host $arg]
1341 perror "download failed"
1346 # The file command used to kill the remote target. For the benefit
1347 # of the testsuite, preserve this behavior.
1350 -re "Kill the program being debugged. .y or n. $" {
1352 verbose "\t\tKilling previous program being debugged"
1355 -re "$gdb_prompt $" {
1360 send_gdb "file $arg\n"
1362 -re "Reading symbols from.*LZMA support was disabled.*done.*$gdb_prompt $" {
1363 verbose "\t\tLoaded $arg into $GDB; .gnu_debugdata found but no LZMA available"
1364 set gdb_file_cmd_debug_info "lzma"
1367 -re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" {
1368 verbose "\t\tLoaded $arg into $GDB with no debugging symbols"
1369 set gdb_file_cmd_debug_info "nodebug"
1372 -re "Reading symbols from.*done.*$gdb_prompt $" {
1373 verbose "\t\tLoaded $arg into $GDB"
1374 set gdb_file_cmd_debug_info "debug"
1377 -re "Load new symbol table from \".*\".*y or n. $" {
1380 -re "Reading symbols from.*done.*$gdb_prompt $" {
1381 verbose "\t\tLoaded $arg with new symbol table into $GDB"
1382 set gdb_file_cmd_debug_info "debug"
1386 perror "Couldn't load $arg, other program already loaded (timeout)."
1390 perror "Couldn't load $arg, other program already loaded (eof)."
1395 -re "No such file or directory.*$gdb_prompt $" {
1396 perror "($arg) No such file or directory"
1399 -re "A problem internal to GDB has been detected" {
1400 fail "($arg) (GDB internal error)"
1401 gdb_internal_error_resync
1404 -re "$gdb_prompt $" {
1405 perror "Couldn't load $arg into $GDB."
1409 perror "Couldn't load $arg into $GDB (timeout)."
1413 # This is an attempt to detect a core dump, but seems not to
1414 # work. Perhaps we need to match .* followed by eof, in which
1415 # gdb_expect does not seem to have a way to do that.
1416 perror "Couldn't load $arg into $GDB (eof)."
1422 # Default gdb_spawn procedure.
1424 proc default_gdb_spawn { } {
1427 global INTERNAL_GDBFLAGS GDBFLAGS
1430 gdb_stop_suppressing_tests
1432 # Set the default value, it may be overriden later by specific testfile.
1434 # Use `set_board_info use_gdb_stub' for the board file to flag the inferior
1435 # is already started after connecting and run/attach are not supported.
1436 # This is used for the "remote" protocol. After GDB starts you should
1437 # check global $use_gdb_stub instead of the board as the testfile may force
1438 # a specific different target protocol itself.
1439 set use_gdb_stub [target_info exists use_gdb_stub]
1441 verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1443 if [info exists gdb_spawn_id] {
1447 if ![is_remote host] {
1448 if { [which $GDB] == 0 } then {
1449 perror "$GDB does not exist."
1453 set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"]
1454 if { $res < 0 || $res == "" } {
1455 perror "Spawning $GDB failed."
1459 set gdb_spawn_id $res
1463 # Default gdb_start procedure.
1465 proc default_gdb_start { } {
1466 global gdb_prompt pagination_prompt
1469 if [info exists gdb_spawn_id] {
1478 # When running over NFS, particularly if running many simultaneous
1479 # tests on different hosts all using the same server, things can
1480 # get really slow. Give gdb at least 3 minutes to start up.
1482 while { $loop_again } {
1485 -re "$pagination_prompt" {
1486 verbose "Hit pagination during startup. Pressing enter to continue."
1490 -re "\[\r\n\]$gdb_prompt $" {
1491 verbose "GDB initialized."
1493 -re "$gdb_prompt $" {
1494 perror "GDB never initialized."
1499 perror "(timeout) GDB never initialized after 10 seconds."
1507 # force the height to "unlimited", so no pagers get used
1509 send_gdb "set height 0\n"
1511 -re "$gdb_prompt $" {
1512 verbose "Setting height to 0." 2
1515 warning "Couldn't set the height to 0"
1518 # force the width to "unlimited", so no wraparound occurs
1519 send_gdb "set width 0\n"
1521 -re "$gdb_prompt $" {
1522 verbose "Setting width to 0." 2
1525 warning "Couldn't set the width to 0."
1531 # Utility procedure to give user control of the gdb prompt in a script. It is
1532 # meant to be used for debugging test cases, and should not be left in the
1535 proc gdb_interact { } {
1537 set spawn_id $gdb_spawn_id
1539 send_user "+------------------------------------------+\n"
1540 send_user "| Script interrupted, you can now interact |\n"
1541 send_user "| with by gdb. Type >>> to continue. |\n"
1542 send_user "+------------------------------------------+\n"
1549 # Examine the output of compilation to determine whether compilation
1550 # failed or not. If it failed determine whether it is due to missing
1551 # compiler or due to compiler error. Report pass, fail or unsupported
1554 proc gdb_compile_test {src output} {
1555 if { $output == "" } {
1556 pass "compilation [file tail $src]"
1557 } elseif { [regexp {^[a-zA-Z_0-9]+: Can't find [^ ]+\.$} $output] } {
1558 unsupported "compilation [file tail $src]"
1559 } elseif { [regexp {.*: command not found[\r|\n]*$} $output] } {
1560 unsupported "compilation [file tail $src]"
1561 } elseif { [regexp {.*: [^\r\n]*compiler not installed[^\r\n]*[\r|\n]*$} $output] } {
1562 unsupported "compilation [file tail $src]"
1564 verbose -log "compilation failed: $output" 2
1565 fail "compilation [file tail $src]"
1569 # Return a 1 for configurations for which we don't even want to try to
1572 proc skip_cplus_tests {} {
1573 if { [istarget "h8300-*-*"] } {
1577 # The C++ IO streams are too large for HC11/HC12 and are thus not
1578 # available. The gdb C++ tests use them and don't compile.
1579 if { [istarget "m6811-*-*"] } {
1582 if { [istarget "m6812-*-*"] } {
1588 # Return a 1 for configurations for which don't have both C++ and the STL.
1590 proc skip_stl_tests {} {
1591 # Symbian supports the C++ language, but the STL is missing
1592 # (both headers and libraries).
1593 if { [istarget "arm*-*-symbianelf*"] } {
1597 return [skip_cplus_tests]
1600 # Return a 1 if I don't even want to try to test FORTRAN.
1602 proc skip_fortran_tests {} {
1606 # Return a 1 if I don't even want to try to test ada.
1608 proc skip_ada_tests {} {
1612 # Return a 1 if I don't even want to try to test GO.
1614 proc skip_go_tests {} {
1618 # Return a 1 if I don't even want to try to test java.
1620 proc skip_java_tests {} {
1624 # Return a 1 if I don't even want to try to test D.
1626 proc skip_d_tests {} {
1630 # Return a 1 for configurations that do not support Python scripting.
1632 proc skip_python_tests {} {
1634 global gdb_py_is_py3k
1635 global gdb_py_is_py24
1637 gdb_test_multiple "python print ('test')" "verify python support" {
1638 -re "not supported.*$gdb_prompt $" {
1639 unsupported "Python support is disabled."
1642 -re "$gdb_prompt $" {}
1645 set gdb_py_is_py24 0
1646 gdb_test_multiple "python print (sys.version_info\[0\])" "check if python 3" {
1647 -re "3.*$gdb_prompt $" {
1648 set gdb_py_is_py3k 1
1650 -re ".*$gdb_prompt $" {
1651 set gdb_py_is_py3k 0
1654 if { $gdb_py_is_py3k == 0 } {
1655 gdb_test_multiple "python print (sys.version_info\[1\])" "check if python 2.4" {
1656 -re "\[45\].*$gdb_prompt $" {
1657 set gdb_py_is_py24 1
1659 -re ".*$gdb_prompt $" {
1660 set gdb_py_is_py24 0
1668 # Return a 1 if we should skip shared library tests.
1670 proc skip_shlib_tests {} {
1671 # Run the shared library tests on native systems.
1676 # An abbreviated list of remote targets where we should be able to
1677 # run shared library tests.
1678 if {([istarget *-*-linux*]
1679 || [istarget *-*-*bsd*]
1680 || [istarget *-*-solaris2*]
1681 || [istarget arm*-*-symbianelf*]
1682 || [istarget *-*-mingw*]
1683 || [istarget *-*-cygwin*]
1684 || [istarget *-*-pe*])} {
1691 # Test files shall make sure all the test result lines in gdb.sum are
1692 # unique in a test run, so that comparing the gdb.sum files of two
1693 # test runs gives correct results. Test files that exercise
1694 # variations of the same tests more than once, shall prefix the
1695 # different test invocations with different identifying strings in
1696 # order to make them unique.
1698 # About test prefixes:
1700 # $pf_prefix is the string that dejagnu prints after the result (FAIL,
1701 # PASS, etc.), and before the test message/name in gdb.sum. E.g., the
1702 # underlined substring in
1704 # PASS: gdb.base/mytest.exp: some test
1705 # ^^^^^^^^^^^^^^^^^^^^
1709 # The easiest way to adjust the test prefix is to append a test
1710 # variation prefix to the $pf_prefix, using the with_test_prefix
1713 # proc do_tests {} {
1714 # gdb_test ... ... "test foo"
1715 # gdb_test ... ... "test bar"
1717 # with_test_prefix "subvariation a" {
1718 # gdb_test ... ... "test x"
1721 # with_test_prefix "subvariation b" {
1722 # gdb_test ... ... "test x"
1726 # with_test_prefix "variation1" {
1727 # ...do setup for variation 1...
1731 # with_test_prefix "variation2" {
1732 # ...do setup for variation 2...
1738 # PASS: gdb.base/mytest.exp: variation1: test foo
1739 # PASS: gdb.base/mytest.exp: variation1: test bar
1740 # PASS: gdb.base/mytest.exp: variation1: subvariation a: test x
1741 # PASS: gdb.base/mytest.exp: variation1: subvariation b: test x
1742 # PASS: gdb.base/mytest.exp: variation2: test foo
1743 # PASS: gdb.base/mytest.exp: variation2: test bar
1744 # PASS: gdb.base/mytest.exp: variation2: subvariation a: test x
1745 # PASS: gdb.base/mytest.exp: variation2: subvariation b: test x
1747 # If for some reason more flexibility is necessary, one can also
1748 # manipulate the pf_prefix global directly, treating it as a string.
1752 # set saved_pf_prefix
1753 # append pf_prefix "${foo}: bar"
1754 # ... actual tests ...
1755 # set pf_prefix $saved_pf_prefix
1758 # Run BODY in the context of the caller, with the current test prefix
1759 # (pf_prefix) appended with one space, then PREFIX, and then a colon.
1760 # Returns the result of BODY.
1762 proc with_test_prefix { prefix body } {
1765 set saved $pf_prefix
1766 append pf_prefix " " $prefix ":"
1767 set code [catch {uplevel 1 $body} result]
1768 set pf_prefix $saved
1771 global errorInfo errorCode
1772 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
1774 return -code $code $result
1778 # Run tests in BODY with GDB prompt and variable $gdb_prompt set to
1779 # PROMPT. When BODY is finished, restore GDB prompt and variable
1781 # Returns the result of BODY.
1785 # 1) If you want to use, for example, "(foo)" as the prompt you must pass it
1786 # as "(foo)", and not the regexp form "\(foo\)" (expressed as "\\(foo\\)" in
1787 # TCL). PROMPT is internally converted to a suitable regexp for matching.
1788 # We do the conversion from "(foo)" to "\(foo\)" here for a few reasons:
1789 # a) It's more intuitive for callers to pass the plain text form.
1790 # b) We need two forms of the prompt:
1791 # - a regexp to use in output matching,
1792 # - a value to pass to the "set prompt" command.
1793 # c) It's easier to convert the plain text form to its regexp form.
1795 # 2) Don't add a trailing space, we do that here.
1797 proc with_gdb_prompt { prompt body } {
1800 # Convert "(foo)" to "\(foo\)".
1801 # We don't use string_to_regexp because while it works today it's not
1802 # clear it will work tomorrow: the value we need must work as both a
1803 # regexp *and* as the argument to the "set prompt" command, at least until
1804 # we start recording both forms separately instead of just $gdb_prompt.
1805 # The testsuite is pretty-much hardwired to interpret $gdb_prompt as the
1807 regsub -all {[]*+.|()^$\[\\]} $prompt {\\&} prompt
1809 set saved $gdb_prompt
1811 verbose -log "Setting gdb prompt to \"$prompt \"."
1812 set gdb_prompt $prompt
1813 gdb_test_no_output "set prompt $prompt " ""
1815 set code [catch {uplevel 1 $body} result]
1817 verbose -log "Restoring gdb prompt to \"$saved \"."
1818 set gdb_prompt $saved
1819 gdb_test_no_output "set prompt $saved " ""
1822 global errorInfo errorCode
1823 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
1825 return -code $code $result
1829 # Run tests in BODY with target-charset setting to TARGET_CHARSET. When
1830 # BODY is finished, restore target-charset.
1832 proc with_target_charset { target_charset body } {
1836 gdb_test_multiple "show target-charset" "" {
1837 -re "The target character set is \".*; currently (.*)\"\..*$gdb_prompt " {
1838 set saved $expect_out(1,string)
1840 -re "The target character set is \"(.*)\".*$gdb_prompt " {
1841 set saved $expect_out(1,string)
1843 -re ".*$gdb_prompt " {
1844 fail "get target-charset"
1848 gdb_test_no_output "set target-charset $target_charset" ""
1850 set code [catch {uplevel 1 $body} result]
1852 gdb_test_no_output "set target-charset $saved" ""
1855 global errorInfo errorCode
1856 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
1858 return -code $code $result
1862 # Return 1 if _Complex types are supported, otherwise, return 0.
1864 gdb_caching_proc support_complex_tests {
1865 # Set up, compile, and execute a test program containing _Complex types.
1866 # Include the current process ID in the file names to prevent conflicts
1867 # with invocations for multiple testsuites.
1868 set src [standard_temp_file complex[pid].c]
1869 set exe [standard_temp_file complex[pid].x]
1871 gdb_produce_source $src {
1875 _Complex long double cld;
1880 verbose "compiling testfile $src" 2
1881 set compile_flags {debug nowarnings quiet}
1882 set lines [gdb_compile $src $exe executable $compile_flags]
1886 if ![string match "" $lines] then {
1887 verbose "testfile compilation failed, returning 0" 2
1896 # Return 1 if target hardware or OS supports single stepping to signal
1897 # handler, otherwise, return 0.
1899 proc can_single_step_to_signal_handler {} {
1901 # Targets don't have hardware single step. On these targets, when
1902 # a signal is delivered during software single step, gdb is unable
1903 # to determine the next instruction addresses, because start of signal
1904 # handler is one of them.
1905 if { [istarget "arm*-*-*"] || [istarget "mips*-*-*"]
1906 || [istarget "tic6x-*-*"] || [istarget "sparc*-*-linux*"]
1907 || [istarget "nios2-*-*"] } {
1914 # Return 1 if target supports process record, otherwise return 0.
1916 proc supports_process_record {} {
1918 if [target_info exists gdb,use_precord] {
1919 return [target_info gdb,use_precord]
1922 if { [istarget "arm*-*-linux*"] || [istarget "x86_64-*-linux*"]
1923 || [istarget "i\[34567\]86-*-linux*"]
1924 || [istarget "powerpc*-*-linux*"] } {
1931 # Return 1 if target supports reverse debugging, otherwise return 0.
1933 proc supports_reverse {} {
1935 if [target_info exists gdb,can_reverse] {
1936 return [target_info gdb,can_reverse]
1939 if { [istarget "arm*-*-linux*"] || [istarget "x86_64-*-linux*"]
1940 || [istarget "i\[34567\]86-*-linux*"]
1941 || [istarget "powerpc*-*-linux*"] } {
1948 # Return 1 if readline library is used.
1950 proc readline_is_used { } {
1953 gdb_test_multiple "show editing" "" {
1954 -re ".*Editing of command lines as they are typed is on\..*$gdb_prompt $" {
1957 -re ".*$gdb_prompt $" {
1963 # Return 1 if target is ELF.
1964 gdb_caching_proc is_elf_target {
1965 set me "is_elf_target"
1967 set src [standard_temp_file is_elf_target[pid].c]
1968 set obj [standard_temp_file is_elf_target[pid].o]
1970 gdb_produce_source $src {
1971 int foo () {return 0;}
1974 verbose "$me: compiling testfile $src" 2
1975 set lines [gdb_compile $src $obj object {quiet}]
1979 if ![string match "" $lines] then {
1980 verbose "$me: testfile compilation failed, returning 0" 2
1984 set fp_obj [open $obj "r"]
1985 fconfigure $fp_obj -translation binary
1986 set data [read $fp_obj]
1991 set ELFMAG "\u007FELF"
1993 if {[string compare -length 4 $data $ELFMAG] != 0} {
1994 verbose "$me: returning 0" 2
1998 verbose "$me: returning 1" 2
2002 # Return 1 if the memory at address zero is readable.
2004 gdb_caching_proc is_address_zero_readable {
2008 gdb_test_multiple "x 0" "" {
2009 -re "Cannot access memory at address 0x0.*$gdb_prompt $" {
2012 -re ".*$gdb_prompt $" {
2020 # Produce source file NAME and write SOURCES into it.
2022 proc gdb_produce_source { name sources } {
2024 set f [open $name "w"]
2030 # Return 1 if target is ILP32.
2031 # This cannot be decided simply from looking at the target string,
2032 # as it might depend on externally passed compiler options like -m64.
2033 gdb_caching_proc is_ilp32_target {
2034 set me "is_ilp32_target"
2036 set src [standard_temp_file ilp32[pid].c]
2037 set obj [standard_temp_file ilp32[pid].o]
2039 gdb_produce_source $src {
2040 int dummy[sizeof (int) == 4
2041 && sizeof (void *) == 4
2042 && sizeof (long) == 4 ? 1 : -1];
2045 verbose "$me: compiling testfile $src" 2
2046 set lines [gdb_compile $src $obj object {quiet}]
2050 if ![string match "" $lines] then {
2051 verbose "$me: testfile compilation failed, returning 0" 2
2055 verbose "$me: returning 1" 2
2059 # Return 1 if target is LP64.
2060 # This cannot be decided simply from looking at the target string,
2061 # as it might depend on externally passed compiler options like -m64.
2062 gdb_caching_proc is_lp64_target {
2063 set me "is_lp64_target"
2065 set src [standard_temp_file lp64[pid].c]
2066 set obj [standard_temp_file lp64[pid].o]
2068 gdb_produce_source $src {
2069 int dummy[sizeof (int) == 4
2070 && sizeof (void *) == 8
2071 && sizeof (long) == 8 ? 1 : -1];
2074 verbose "$me: compiling testfile $src" 2
2075 set lines [gdb_compile $src $obj object {quiet}]
2079 if ![string match "" $lines] then {
2080 verbose "$me: testfile compilation failed, returning 0" 2
2084 verbose "$me: returning 1" 2
2088 # Return 1 if target has 64 bit addresses.
2089 # This cannot be decided simply from looking at the target string,
2090 # as it might depend on externally passed compiler options like -m64.
2091 gdb_caching_proc is_64_target {
2092 set me "is_64_target"
2094 set src [standard_temp_file is64[pid].c]
2095 set obj [standard_temp_file is64[pid].o]
2097 gdb_produce_source $src {
2098 int function(void) { return 3; }
2099 int dummy[sizeof (&function) == 8 ? 1 : -1];
2102 verbose "$me: compiling testfile $src" 2
2103 set lines [gdb_compile $src $obj object {quiet}]
2107 if ![string match "" $lines] then {
2108 verbose "$me: testfile compilation failed, returning 0" 2
2112 verbose "$me: returning 1" 2
2116 # Return 1 if target has x86_64 registers - either amd64 or x32.
2117 # x32 target identifies as x86_64-*-linux*, therefore it cannot be determined
2118 # just from the target string.
2119 gdb_caching_proc is_amd64_regs_target {
2120 if {![istarget "x86_64-*-*"] && ![istarget "i?86-*"]} {
2124 set me "is_amd64_regs_target"
2126 set src [standard_temp_file reg64[pid].s]
2127 set obj [standard_temp_file reg64[pid].o]
2131 {rax rbx rcx rdx rsi rdi rbp rsp r8 r9 r10 r11 r12 r13 r14 r15} {
2132 lappend list "\tincq %$reg"
2134 gdb_produce_source $src [join $list \n]
2136 verbose "$me: compiling testfile $src" 2
2137 set lines [gdb_compile $src $obj object {quiet}]
2141 if ![string match "" $lines] then {
2142 verbose "$me: testfile compilation failed, returning 0" 2
2146 verbose "$me: returning 1" 2
2150 # Return 1 if this target is an x86 or x86-64 with -m32.
2151 proc is_x86_like_target {} {
2152 if {![istarget "x86_64-*-*"] && ![istarget i?86-*]} {
2155 return [expr [is_ilp32_target] && ![is_amd64_regs_target]]
2158 # Return 1 if displaced stepping is supported on target, otherwise, return 0.
2159 proc support_displaced_stepping {} {
2161 if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"]
2162 || [istarget "arm*-*-linux*"] || [istarget "powerpc-*-linux*"]
2163 || [istarget "powerpc64-*-linux*"] || [istarget "s390*-*-*"] } {
2170 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
2171 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
2173 gdb_caching_proc skip_altivec_tests {
2174 global srcdir subdir gdb_prompt inferior_exited_re
2176 set me "skip_altivec_tests"
2178 # Some simulators are known to not support VMX instructions.
2179 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
2180 verbose "$me: target known to not support VMX, returning 1" 2
2184 # Make sure we have a compiler that understands altivec.
2185 set compile_flags {debug nowarnings}
2186 if [get_compiler_info] {
2187 warning "Could not get compiler info"
2190 if [test_compiler_info gcc*] {
2191 set compile_flags "$compile_flags additional_flags=-maltivec"
2192 } elseif [test_compiler_info xlc*] {
2193 set compile_flags "$compile_flags additional_flags=-qaltivec"
2195 verbose "Could not compile with altivec support, returning 1" 2
2199 # Set up, compile, and execute a test program containing VMX instructions.
2200 # Include the current process ID in the file names to prevent conflicts
2201 # with invocations for multiple testsuites.
2202 set src [standard_temp_file vmx[pid].c]
2203 set exe [standard_temp_file vmx[pid].x]
2205 gdb_produce_source $src {
2208 asm volatile ("vor v0,v0,v0");
2210 asm volatile ("vor 0,0,0");
2216 verbose "$me: compiling testfile $src" 2
2217 set lines [gdb_compile $src $exe executable $compile_flags]
2220 if ![string match "" $lines] then {
2221 verbose "$me: testfile compilation failed, returning 1" 2
2225 # No error message, compilation succeeded so now run it via gdb.
2229 gdb_reinitialize_dir $srcdir/$subdir
2233 -re ".*Illegal instruction.*${gdb_prompt} $" {
2234 verbose -log "\n$me altivec hardware not detected"
2235 set skip_vmx_tests 1
2237 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
2238 verbose -log "\n$me: altivec hardware detected"
2239 set skip_vmx_tests 0
2242 warning "\n$me: default case taken"
2243 set skip_vmx_tests 1
2247 remote_file build delete $exe
2249 verbose "$me: returning $skip_vmx_tests" 2
2250 return $skip_vmx_tests
2253 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
2254 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
2256 gdb_caching_proc skip_vsx_tests {
2257 global srcdir subdir gdb_prompt inferior_exited_re
2259 set me "skip_vsx_tests"
2261 # Some simulators are known to not support Altivec instructions, so
2262 # they won't support VSX instructions as well.
2263 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
2264 verbose "$me: target known to not support VSX, returning 1" 2
2268 # Make sure we have a compiler that understands altivec.
2269 set compile_flags {debug nowarnings quiet}
2270 if [get_compiler_info] {
2271 warning "Could not get compiler info"
2274 if [test_compiler_info gcc*] {
2275 set compile_flags "$compile_flags additional_flags=-mvsx"
2276 } elseif [test_compiler_info xlc*] {
2277 set compile_flags "$compile_flags additional_flags=-qasm=gcc"
2279 verbose "Could not compile with vsx support, returning 1" 2
2283 set src [standard_temp_file vsx[pid].c]
2284 set exe [standard_temp_file vsx[pid].x]
2286 gdb_produce_source $src {
2288 double a[2] = { 1.0, 2.0 };
2290 asm volatile ("lxvd2x v0,v0,%[addr]" : : [addr] "r" (a));
2292 asm volatile ("lxvd2x 0,0,%[addr]" : : [addr] "r" (a));
2298 verbose "$me: compiling testfile $src" 2
2299 set lines [gdb_compile $src $exe executable $compile_flags]
2302 if ![string match "" $lines] then {
2303 verbose "$me: testfile compilation failed, returning 1" 2
2307 # No error message, compilation succeeded so now run it via gdb.
2311 gdb_reinitialize_dir $srcdir/$subdir
2315 -re ".*Illegal instruction.*${gdb_prompt} $" {
2316 verbose -log "\n$me VSX hardware not detected"
2317 set skip_vsx_tests 1
2319 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
2320 verbose -log "\n$me: VSX hardware detected"
2321 set skip_vsx_tests 0
2324 warning "\n$me: default case taken"
2325 set skip_vsx_tests 1
2329 remote_file build delete $exe
2331 verbose "$me: returning $skip_vsx_tests" 2
2332 return $skip_vsx_tests
2335 # Run a test on the target to see if it supports btrace hardware. Return 0 if so,
2336 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
2338 gdb_caching_proc skip_btrace_tests {
2339 global srcdir subdir gdb_prompt inferior_exited_re
2341 set me "skip_btrace_tests"
2342 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
2343 verbose "$me: target does not support btrace, returning 1" 2
2347 # Set up, compile, and execute a test program.
2348 # Include the current process ID in the file names to prevent conflicts
2349 # with invocations for multiple testsuites.
2350 set src [standard_temp_file btrace[pid].c]
2351 set exe [standard_temp_file btrace[pid].x]
2353 gdb_produce_source $src {
2354 int main(void) { return 0; }
2357 verbose "$me: compiling testfile $src" 2
2358 set compile_flags {debug nowarnings quiet}
2359 set lines [gdb_compile $src $exe executable $compile_flags]
2361 if ![string match "" $lines] then {
2362 verbose "$me: testfile compilation failed, returning 1" 2
2367 # No error message, compilation succeeded so now run it via gdb.
2371 gdb_reinitialize_dir $srcdir/$subdir
2378 # In case of an unexpected output, we return 2 as a fail value.
2379 set skip_btrace_tests 2
2380 gdb_test_multiple "record btrace" "check btrace support" {
2381 -re "You can't do that when your target is.*\r\n$gdb_prompt $" {
2382 set skip_btrace_tests 1
2384 -re "Target does not support branch tracing.*\r\n$gdb_prompt $" {
2385 set skip_btrace_tests 1
2387 -re "Could not enable branch tracing.*\r\n$gdb_prompt $" {
2388 set skip_btrace_tests 1
2390 -re "^record btrace\r\n$gdb_prompt $" {
2391 set skip_btrace_tests 0
2395 remote_file build delete $exe
2397 verbose "$me: returning $skip_btrace_tests" 2
2398 return $skip_btrace_tests
2401 # Skip all the tests in the file if you are not on an hppa running
2404 proc skip_hp_tests {} {
2405 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
2406 verbose "Skip hp tests is $skip_hp"
2410 # Return whether we should skip tests for showing inlined functions in
2411 # backtraces. Requires get_compiler_info and get_debug_format.
2413 proc skip_inline_frame_tests {} {
2414 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
2415 if { ! [test_debug_format "DWARF 2"] } {
2419 # GCC before 4.1 does not emit DW_AT_call_file / DW_AT_call_line.
2420 if { ([test_compiler_info "gcc-2-*"]
2421 || [test_compiler_info "gcc-3-*"]
2422 || [test_compiler_info "gcc-4-0-*"]) } {
2429 # Return whether we should skip tests for showing variables from
2430 # inlined functions. Requires get_compiler_info and get_debug_format.
2432 proc skip_inline_var_tests {} {
2433 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
2434 if { ! [test_debug_format "DWARF 2"] } {
2441 # Return a 1 if we should skip tests that require hardware breakpoints
2443 proc skip_hw_breakpoint_tests {} {
2444 # Skip tests if requested by the board (note that no_hardware_watchpoints
2445 # disables both watchpoints and breakpoints)
2446 if { [target_info exists gdb,no_hardware_watchpoints]} {
2450 # These targets support hardware breakpoints natively
2451 if { [istarget "i?86-*-*"]
2452 || [istarget "x86_64-*-*"]
2453 || [istarget "ia64-*-*"]
2454 || [istarget "arm*-*-*"]} {
2461 # Return a 1 if we should skip tests that require hardware watchpoints
2463 proc skip_hw_watchpoint_tests {} {
2464 # Skip tests if requested by the board
2465 if { [target_info exists gdb,no_hardware_watchpoints]} {
2469 # These targets support hardware watchpoints natively
2470 if { [istarget "i?86-*-*"]
2471 || [istarget "x86_64-*-*"]
2472 || [istarget "ia64-*-*"]
2473 || [istarget "arm*-*-*"]
2474 || [istarget "powerpc*-*-linux*"]
2475 || [istarget "s390*-*-*"] } {
2482 # Return a 1 if we should skip tests that require *multiple* hardware
2483 # watchpoints to be active at the same time
2485 proc skip_hw_watchpoint_multi_tests {} {
2486 if { [skip_hw_watchpoint_tests] } {
2490 # These targets support just a single hardware watchpoint
2491 if { [istarget "arm*-*-*"]
2492 || [istarget "powerpc*-*-linux*"] } {
2499 # Return a 1 if we should skip tests that require read/access watchpoints
2501 proc skip_hw_watchpoint_access_tests {} {
2502 if { [skip_hw_watchpoint_tests] } {
2506 # These targets support just write watchpoints
2507 if { [istarget "s390*-*-*"] } {
2514 # Return 1 if we should skip tests that require the runtime unwinder
2515 # hook. This must be invoked while gdb is running, after shared
2516 # libraries have been loaded. This is needed because otherwise a
2517 # shared libgcc won't be visible.
2519 proc skip_unwinder_tests {} {
2523 gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook" {
2524 -re "= .*no debug info.*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
2526 -re "= .*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
2529 -re "No symbol .* in current context.\r\n$gdb_prompt $" {
2533 gdb_test_multiple "info probe" "check for stap probe in unwinder" {
2534 -re ".*libgcc.*unwind.*\r\n$gdb_prompt $" {
2537 -re "\r\n$gdb_prompt $" {
2544 # Return 0 if we should skip tests that require the libstdc++ stap
2545 # probes. This must be invoked while gdb is running, after shared
2546 # libraries have been loaded.
2548 proc skip_libstdcxx_probe_tests {} {
2552 gdb_test_multiple "info probe" "check for stap probe in libstdc++" {
2553 -re ".*libstdcxx.*catch.*\r\n$gdb_prompt $" {
2556 -re "\r\n$gdb_prompt $" {
2562 # Return 1 if we should skip tests of the "compile" feature.
2563 # This must be invoked after the inferior has been started.
2565 proc skip_compile_feature_tests {} {
2569 gdb_test_multiple "compile code -- ;" "check for working compile command" {
2570 "Could not load libcc1.*\r\n$gdb_prompt $" {
2573 -re "Command not supported on this host\\..*\r\n$gdb_prompt $" {
2576 -re "\r\n$gdb_prompt $" {
2582 # Check whether we're testing with the remote or extended-remote
2585 proc gdb_is_target_remote {} {
2588 set test "probe for target remote"
2589 gdb_test_multiple "maint print target-stack" $test {
2590 -re ".*emote serial target in gdb-specific protocol.*$gdb_prompt $" {
2594 -re "$gdb_prompt $" {
2601 # Return 1 if the current remote target is an instance of our GDBserver, 0
2602 # otherwise. Return -1 if there was an error and we can't tell.
2604 gdb_caching_proc target_is_gdbserver {
2608 set test "Probing for GDBserver"
2610 gdb_test_multiple "monitor help" $test {
2611 -re "The following monitor commands are supported.*Quit GDBserver.*$gdb_prompt $" {
2614 -re "$gdb_prompt $" {
2619 if { $is_gdbserver == -1 } {
2620 verbose -log "Unable to tell whether we are using GDBserver or not."
2623 return $is_gdbserver
2626 set compiler_info "unknown"
2628 set hp_cc_compiler 0
2629 set hp_aCC_compiler 0
2631 # Figure out what compiler I am using.
2633 # ARG can be empty or "C++". If empty, "C" is assumed.
2635 # There are several ways to do this, with various problems.
2637 # [ gdb_compile -E $ifile -o $binfile.ci ]
2638 # source $binfile.ci
2640 # Single Unix Spec v3 says that "-E -o ..." together are not
2641 # specified. And in fact, the native compiler on hp-ux 11 (among
2642 # others) does not work with "-E -o ...". Most targets used to do
2643 # this, and it mostly worked, because it works with gcc.
2645 # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ]
2646 # source $binfile.ci
2648 # This avoids the problem with -E and -o together. This almost works
2649 # if the build machine is the same as the host machine, which is
2650 # usually true of the targets which are not gcc. But this code does
2651 # not figure which compiler to call, and it always ends up using the C
2652 # compiler. Not good for setting hp_aCC_compiler. Target
2653 # hppa*-*-hpux* used to do this.
2655 # [ gdb_compile -E $ifile > $binfile.ci ]
2656 # source $binfile.ci
2658 # dejagnu target_compile says that it supports output redirection,
2659 # but the code is completely different from the normal path and I
2660 # don't want to sweep the mines from that path. So I didn't even try
2663 # set cppout [ gdb_compile $ifile "" preprocess $args quiet ]
2666 # I actually do this for all targets now. gdb_compile runs the right
2667 # compiler, and TCL captures the output, and I eval the output.
2669 # Unfortunately, expect logs the output of the command as it goes by,
2670 # and dejagnu helpfully prints a second copy of it right afterwards.
2671 # So I turn off expect logging for a moment.
2673 # [ gdb_compile $ifile $ciexe_file executable $args ]
2674 # [ remote_exec $ciexe_file ]
2675 # [ source $ci_file.out ]
2677 # I could give up on -E and just do this.
2678 # I didn't get desperate enough to try this.
2680 # -- chastain 2004-01-06
2682 proc get_compiler_info {{arg ""}} {
2683 # For compiler.c and compiler.cc
2686 # I am going to play with the log to keep noise out.
2690 # These come from compiler.c or compiler.cc
2691 global compiler_info
2693 # Legacy global data symbols.
2695 global hp_cc_compiler
2696 global hp_aCC_compiler
2698 # Choose which file to preprocess.
2699 set ifile "${srcdir}/lib/compiler.c"
2700 if { $arg == "c++" } {
2701 set ifile "${srcdir}/lib/compiler.cc"
2704 # Run $ifile through the right preprocessor.
2705 # Toggle gdb.log to keep the compiler output out of the log.
2706 set saved_log [log_file -info]
2708 if [is_remote host] {
2709 # We have to use -E and -o together, despite the comments
2710 # above, because of how DejaGnu handles remote host testing.
2711 set ppout "$outdir/compiler.i"
2712 gdb_compile "${ifile}" "$ppout" preprocess [list "$arg" quiet]
2713 set file [open $ppout r]
2714 set cppout [read $file]
2717 set cppout [ gdb_compile "${ifile}" "" preprocess [list "$arg" quiet] ]
2719 eval log_file $saved_log
2723 foreach cppline [ split "$cppout" "\n" ] {
2724 if { [ regexp "^#" "$cppline" ] } {
2726 } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } {
2728 } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } {
2730 verbose "get_compiler_info: $cppline" 2
2734 verbose -log "get_compiler_info: $cppline"
2739 # Reset to unknown compiler if any diagnostics happened.
2741 set compiler_info "unknown"
2744 # Set the legacy symbols.
2746 set hp_cc_compiler 0
2747 set hp_aCC_compiler 0
2748 if { [regexp "^gcc-1-" "$compiler_info" ] } { set gcc_compiled 1 }
2749 if { [regexp "^gcc-2-" "$compiler_info" ] } { set gcc_compiled 2 }
2750 if { [regexp "^gcc-3-" "$compiler_info" ] } { set gcc_compiled 3 }
2751 if { [regexp "^gcc-4-" "$compiler_info" ] } { set gcc_compiled 4 }
2752 if { [regexp "^gcc-5-" "$compiler_info" ] } { set gcc_compiled 5 }
2753 if { [regexp "^hpcc-" "$compiler_info" ] } { set hp_cc_compiler 1 }
2754 if { [regexp "^hpacc-" "$compiler_info" ] } { set hp_aCC_compiler 1 }
2756 # Log what happened.
2757 verbose -log "get_compiler_info: $compiler_info"
2759 # Most compilers will evaluate comparisons and other boolean
2760 # operations to 0 or 1.
2761 uplevel \#0 { set true 1 }
2762 uplevel \#0 { set false 0 }
2764 # Use of aCC results in boolean results being displayed as
2766 if { $hp_aCC_compiler } {
2767 uplevel \#0 { set true true }
2768 uplevel \#0 { set false false }
2774 proc test_compiler_info { {compiler ""} } {
2775 global compiler_info
2777 # if no arg, return the compiler_info string
2779 if [string match "" $compiler] {
2780 if [info exists compiler_info] {
2781 return $compiler_info
2783 perror "No compiler info found."
2787 return [string match $compiler $compiler_info]
2790 proc current_target_name { } {
2792 if [info exists target_info(target,name)] {
2793 set answer $target_info(target,name)
2800 set gdb_wrapper_initialized 0
2801 set gdb_wrapper_target ""
2803 proc gdb_wrapper_init { args } {
2804 global gdb_wrapper_initialized
2805 global gdb_wrapper_file
2806 global gdb_wrapper_flags
2807 global gdb_wrapper_target
2809 if { $gdb_wrapper_initialized == 1 } { return; }
2811 if {[target_info exists needs_status_wrapper] && \
2812 [target_info needs_status_wrapper] != "0"} {
2813 set result [build_wrapper "testglue.o"]
2814 if { $result != "" } {
2815 set gdb_wrapper_file [lindex $result 0]
2816 set gdb_wrapper_flags [lindex $result 1]
2818 warning "Status wrapper failed to build."
2821 set gdb_wrapper_initialized 1
2822 set gdb_wrapper_target [current_target_name]
2825 # Some targets need to always link a special object in. Save its path here.
2826 global gdb_saved_set_unbuffered_mode_obj
2827 set gdb_saved_set_unbuffered_mode_obj ""
2829 proc gdb_compile {source dest type options} {
2830 global GDB_TESTCASE_OPTIONS
2831 global gdb_wrapper_file
2832 global gdb_wrapper_flags
2833 global gdb_wrapper_initialized
2836 global gdb_saved_set_unbuffered_mode_obj
2838 set outdir [file dirname $dest]
2840 # Add platform-specific options if a shared library was specified using
2841 # "shlib=librarypath" in OPTIONS.
2845 foreach opt $options {
2846 if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] {
2847 if [test_compiler_info "xlc-*"] {
2848 # IBM xlc compiler doesn't accept shared library named other
2849 # than .so: use "-Wl," to bypass this
2850 lappend source "-Wl,$shlib_name"
2851 } elseif { ([istarget "*-*-mingw*"]
2852 || [istarget *-*-cygwin*]
2853 || [istarget *-*-pe*])} {
2854 lappend source "${shlib_name}.a"
2856 lappend source $shlib_name
2858 if { $shlib_found == 0 } {
2860 if { ([istarget "*-*-mingw*"]
2861 || [istarget *-*-cygwin*]) } {
2862 lappend new_options "additional_flags=-Wl,--enable-auto-import"
2865 } elseif { $opt == "shlib_load" } {
2868 lappend new_options $opt
2872 # We typically link to shared libraries using an absolute path, and
2873 # that's how they are found at runtime. If we are going to
2874 # dynamically load one by basename, we must specify rpath. If we
2875 # are using a remote host, DejaGNU will link to the shared library
2876 # using a relative path, so again we must specify an rpath.
2877 if { $shlib_load || ($shlib_found && [is_remote target]) } {
2878 if { ([istarget "*-*-mingw*"]
2879 || [istarget *-*-cygwin*]
2880 || [istarget *-*-pe*]
2881 || [istarget hppa*-*-hpux*])} {
2882 # Do not need anything.
2883 } elseif { [istarget *-*-freebsd*] || [istarget *-*-openbsd*] } {
2884 lappend new_options "ldflags=-Wl,-rpath,${outdir}"
2885 } elseif { [istarget arm*-*-symbianelf*] } {
2886 if { $shlib_load } {
2887 lappend new_options "libs=-ldl"
2890 if { $shlib_load } {
2891 lappend new_options "libs=-ldl"
2893 lappend new_options "ldflags=-Wl,-rpath,\\\$ORIGIN"
2896 set options $new_options
2898 if [info exists GDB_TESTCASE_OPTIONS] {
2899 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS"
2901 verbose "options are $options"
2902 verbose "source is $source $dest $type $options"
2904 if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init }
2906 if {[target_info exists needs_status_wrapper] && \
2907 [target_info needs_status_wrapper] != "0" && \
2908 [info exists gdb_wrapper_file]} {
2909 lappend options "libs=${gdb_wrapper_file}"
2910 lappend options "ldflags=${gdb_wrapper_flags}"
2913 # Replace the "nowarnings" option with the appropriate additional_flags
2914 # to disable compiler warnings.
2915 set nowarnings [lsearch -exact $options nowarnings]
2916 if {$nowarnings != -1} {
2917 if [target_info exists gdb,nowarnings_flag] {
2918 set flag "additional_flags=[target_info gdb,nowarnings_flag]"
2920 set flag "additional_flags=-w"
2922 set options [lreplace $options $nowarnings $nowarnings $flag]
2925 if { $type == "executable" } {
2926 if { ([istarget "*-*-mingw*"]
2927 || [istarget "*-*-*djgpp"]
2928 || [istarget "*-*-cygwin*"])} {
2929 # Force output to unbuffered mode, by linking in an object file
2930 # with a global contructor that calls setvbuf.
2932 # Compile the special object seperatelly for two reasons:
2933 # 1) Insulate it from $options.
2934 # 2) Avoid compiling it for every gdb_compile invocation,
2935 # which is time consuming, especially if we're remote
2938 if { $gdb_saved_set_unbuffered_mode_obj == "" } {
2939 verbose "compiling gdb_saved_set_unbuffered_obj"
2940 set unbuf_src ${srcdir}/lib/set_unbuffered_mode.c
2941 set unbuf_obj ${objdir}/set_unbuffered_mode.o
2943 set result [gdb_compile "${unbuf_src}" "${unbuf_obj}" object {nowarnings}]
2944 if { $result != "" } {
2947 if {[is_remote host]} {
2948 set gdb_saved_set_unbuffered_mode_obj set_unbuffered_mode_saved.o
2950 set gdb_saved_set_unbuffered_mode_obj ${objdir}/set_unbuffered_mode_saved.o
2952 # Link a copy of the output object, because the
2953 # original may be automatically deleted.
2954 remote_download host $unbuf_obj $gdb_saved_set_unbuffered_mode_obj
2956 verbose "gdb_saved_set_unbuffered_obj already compiled"
2959 # Rely on the internal knowledge that the global ctors are ran in
2960 # reverse link order. In that case, we can use ldflags to
2961 # avoid copying the object file to the host multiple
2963 # This object can only be added if standard libraries are
2964 # used. Thus, we need to disable it if -nostdlib option is used
2965 if {[lsearch -regexp $options "-nostdlib"] < 0 } {
2966 lappend options "ldflags=$gdb_saved_set_unbuffered_mode_obj"
2971 set result [target_compile $source $dest $type $options]
2973 # Prune uninteresting compiler (and linker) output.
2974 regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result
2976 regsub "\[\r\n\]*$" "$result" "" result
2977 regsub "^\[\r\n\]*" "$result" "" result
2979 if {[lsearch $options quiet] < 0} {
2980 # We shall update this on a per language basis, to avoid
2981 # changing the entire testsuite in one go.
2982 if {[lsearch $options f77] >= 0} {
2983 gdb_compile_test $source $result
2984 } elseif { $result != "" } {
2985 clone_output "gdb compile failed, $result"
2992 # This is just like gdb_compile, above, except that it tries compiling
2993 # against several different thread libraries, to see which one this
2995 proc gdb_compile_pthreads {source dest type options} {
2997 set why_msg "unrecognized error"
2998 foreach lib {-lpthreads -lpthread -lthread ""} {
2999 # This kind of wipes out whatever libs the caller may have
3000 # set. Or maybe theirs will override ours. How infelicitous.
3001 set options_with_lib [concat $options [list libs=$lib quiet]]
3002 set ccout [gdb_compile $source $dest $type $options_with_lib]
3003 switch -regexp -- $ccout {
3004 ".*no posix threads support.*" {
3005 set why_msg "missing threads include file"
3008 ".*cannot open -lpthread.*" {
3009 set why_msg "missing runtime threads library"
3011 ".*Can't find library for -lpthread.*" {
3012 set why_msg "missing runtime threads library"
3015 pass "successfully compiled posix threads test case"
3021 if {!$built_binfile} {
3022 unsupported "Couldn't compile [file tail $source]: ${why_msg}"
3027 # Build a shared library from SOURCES.
3029 proc gdb_compile_shlib {sources dest options} {
3030 set obj_options $options
3033 if { [lsearch -exact $options "c++"] >= 0 } {
3034 set info_options "c++"
3036 if [get_compiler_info ${info_options}] {
3040 switch -glob [test_compiler_info] {
3042 lappend obj_options "additional_flags=-qpic"
3045 if { !([istarget "*-*-cygwin*"]
3046 || [istarget "*-*-mingw*"]) } {
3047 lappend obj_options "additional_flags=-fpic"
3051 if { !([istarget "powerpc*-*-aix*"]
3052 || [istarget "rs6000*-*-aix*"]
3053 || [istarget "*-*-cygwin*"]
3054 || [istarget "*-*-mingw*"]
3055 || [istarget "*-*-pe*"]) } {
3056 lappend obj_options "additional_flags=-fpic"
3060 switch -glob [istarget] {
3062 lappend obj_options "additional_flags=+z"
3065 # don't know what the compiler is...
3071 set outdir [file dirname $dest]
3073 foreach source $sources {
3074 set sourcebase [file tail $source]
3075 if {[gdb_compile $source "${outdir}/${sourcebase}.o" object $obj_options] != ""} {
3078 lappend objects ${outdir}/${sourcebase}.o
3081 if [istarget "hppa*-*-hpux*"] {
3082 remote_exec build "ld -b ${objects} -o ${dest}"
3084 set link_options $options
3085 if [test_compiler_info "xlc-*"] {
3086 lappend link_options "additional_flags=-qmkshrobj"
3088 lappend link_options "additional_flags=-shared"
3090 if { ([istarget "*-*-mingw*"]
3091 || [istarget *-*-cygwin*]
3092 || [istarget *-*-pe*]) } {
3093 if { [is_remote host] } {
3094 set name [file tail ${dest}]
3098 lappend link_options "additional_flags=-Wl,--out-implib,${name}.a"
3099 } elseif [is_remote target] {
3100 # By default, we do not set the soname. This causes the linker
3101 # on ELF systems to create a DT_NEEDED entry in the executable
3102 # refering to the full path name of the library. This is a
3103 # problem in remote testing if the library is in a different
3104 # directory there. To fix this, we set a soname of just the
3105 # base filename for the library, and add an appropriate -rpath
3106 # to the main executable (in gdb_compile).
3107 set destbase [file tail $dest]
3108 lappend link_options "additional_flags=-Wl,-soname,$destbase"
3111 if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
3114 if { [is_remote host]
3115 && ([istarget "*-*-mingw*"]
3116 || [istarget *-*-cygwin*]
3117 || [istarget *-*-pe*]) } {
3118 set dest_tail_name [file tail ${dest}]
3119 remote_upload host $dest_tail_name.a ${dest}.a
3120 remote_file host delete $dest_tail_name.a
3126 # This is just like gdb_compile_shlib, above, except that it tries compiling
3127 # against several different thread libraries, to see which one this
3129 proc gdb_compile_shlib_pthreads {sources dest options} {
3131 set why_msg "unrecognized error"
3132 foreach lib {-lpthreads -lpthread -lthread ""} {
3133 # This kind of wipes out whatever libs the caller may have
3134 # set. Or maybe theirs will override ours. How infelicitous.
3135 set options_with_lib [concat $options [list libs=$lib quiet]]
3136 set ccout [gdb_compile_shlib $sources $dest $options_with_lib]
3137 switch -regexp -- $ccout {
3138 ".*no posix threads support.*" {
3139 set why_msg "missing threads include file"
3142 ".*cannot open -lpthread.*" {
3143 set why_msg "missing runtime threads library"
3145 ".*Can't find library for -lpthread.*" {
3146 set why_msg "missing runtime threads library"
3149 pass "successfully compiled posix threads test case"
3155 if {!$built_binfile} {
3156 unsupported "Couldn't compile $sources: ${why_msg}"
3161 # This is just like gdb_compile_pthreads, above, except that we always add the
3162 # objc library for compiling Objective-C programs
3163 proc gdb_compile_objc {source dest type options} {
3165 set why_msg "unrecognized error"
3166 foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} {
3167 # This kind of wipes out whatever libs the caller may have
3168 # set. Or maybe theirs will override ours. How infelicitous.
3169 if { $lib == "solaris" } {
3170 set lib "-lpthread -lposix4"
3172 if { $lib != "-lobjc" } {
3173 set lib "-lobjc $lib"
3175 set options_with_lib [concat $options [list libs=$lib quiet]]
3176 set ccout [gdb_compile $source $dest $type $options_with_lib]
3177 switch -regexp -- $ccout {
3178 ".*no posix threads support.*" {
3179 set why_msg "missing threads include file"
3182 ".*cannot open -lpthread.*" {
3183 set why_msg "missing runtime threads library"
3185 ".*Can't find library for -lpthread.*" {
3186 set why_msg "missing runtime threads library"
3189 pass "successfully compiled objc with posix threads test case"
3195 if {!$built_binfile} {
3196 unsupported "Couldn't compile [file tail $source]: ${why_msg}"
3201 proc send_gdb { string } {
3202 global suppress_flag
3203 if { $suppress_flag } {
3206 return [remote_send host "$string"]
3212 proc gdb_expect { args } {
3213 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
3214 set atimeout [lindex $args 0]
3215 set expcode [list [lindex $args 1]]
3220 # A timeout argument takes precedence, otherwise of all the timeouts
3221 # select the largest.
3222 upvar #0 timeout gtimeout
3223 upvar timeout timeout
3224 if [info exists atimeout] {
3228 if [info exists timeout] {
3231 if { [info exists gtimeout] && $gtimeout > $tmt } {
3234 if { [target_info exists gdb,timeout]
3235 && [target_info gdb,timeout] > $tmt } {
3236 set tmt [target_info gdb,timeout]
3244 global suppress_flag
3245 global remote_suppress_flag
3246 if [info exists remote_suppress_flag] {
3247 set old_val $remote_suppress_flag
3249 if [info exists suppress_flag] {
3250 if { $suppress_flag } {
3251 set remote_suppress_flag 1
3255 {uplevel remote_expect host $tmt $expcode} string]
3256 if [info exists old_val] {
3257 set remote_suppress_flag $old_val
3259 if [info exists remote_suppress_flag] {
3260 unset remote_suppress_flag
3265 global errorInfo errorCode
3267 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
3269 return -code $code $string
3273 # gdb_expect_list TEST SENTINEL LIST -- expect a sequence of outputs
3275 # Check for long sequence of output by parts.
3276 # TEST: is the test message to be printed with the test success/fail.
3277 # SENTINEL: Is the terminal pattern indicating that output has finished.
3278 # LIST: is the sequence of outputs to match.
3279 # If the sentinel is recognized early, it is considered an error.
3282 # 1 if the test failed,
3283 # 0 if the test passes,
3284 # -1 if there was an internal error.
3286 proc gdb_expect_list {test sentinel list} {
3288 global suppress_flag
3291 if { $suppress_flag } {
3293 unresolved "${test}"
3295 while { ${index} < [llength ${list}] } {
3296 set pattern [lindex ${list} ${index}]
3297 set index [expr ${index} + 1]
3298 verbose -log "gdb_expect_list pattern: /$pattern/" 2
3299 if { ${index} == [llength ${list}] } {
3302 -re "${pattern}${sentinel}" {
3303 # pass "${test}, pattern ${index} + sentinel"
3306 fail "${test} (pattern ${index} + sentinel)"
3309 -re ".*A problem internal to GDB has been detected" {
3310 fail "${test} (GDB internal error)"
3312 gdb_internal_error_resync
3315 fail "${test} (pattern ${index} + sentinel) (timeout)"
3320 # unresolved "${test}, pattern ${index} + sentinel"
3326 # pass "${test}, pattern ${index}"
3329 fail "${test} (pattern ${index})"
3332 -re ".*A problem internal to GDB has been detected" {
3333 fail "${test} (GDB internal error)"
3335 gdb_internal_error_resync
3338 fail "${test} (pattern ${index}) (timeout)"
3343 # unresolved "${test}, pattern ${index}"
3357 proc gdb_suppress_entire_file { reason } {
3358 global suppress_flag
3361 set suppress_flag -1
3365 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
3366 # gdb_expect to fail immediately (until the next call to
3367 # gdb_stop_suppressing_tests).
3369 proc gdb_suppress_tests { args } {
3370 global suppress_flag
3372 return; # fnf - disable pending review of results where
3373 # testsuite ran better without this
3376 if { $suppress_flag == 1 } {
3377 if { [llength $args] > 0 } {
3378 warning "[lindex $args 0]\n"
3380 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n"
3386 # Clear suppress_flag.
3388 proc gdb_stop_suppressing_tests { } {
3389 global suppress_flag
3391 if [info exists suppress_flag] {
3392 if { $suppress_flag > 0 } {
3394 clone_output "Tests restarted.\n"
3401 proc gdb_clear_suppressed { } {
3402 global suppress_flag
3407 # Spawn the gdb process.
3409 # This doesn't expect any output or do any other initialization,
3410 # leaving those to the caller.
3412 # Overridable function -- you can override this function in your
3415 proc gdb_spawn { } {
3419 # Spawn GDB with CMDLINE_FLAGS appended to the GDBFLAGS global.
3421 proc gdb_spawn_with_cmdline_opts { cmdline_flags } {
3424 set saved_gdbflags $GDBFLAGS
3426 if {$GDBFLAGS != ""} {
3429 append GDBFLAGS $cmdline_flags
3433 set GDBFLAGS $saved_gdbflags
3438 # Start gdb running, wait for prompt, and disable the pagers.
3440 # Overridable function -- you can override this function in your
3443 proc gdb_start { } {
3448 catch default_gdb_exit
3451 # Return true if we can spawn a program on the target and attach to
3454 proc can_spawn_for_attach { } {
3455 # We use TCL's exec to get the inferior's pid.
3456 if [is_remote target] then {
3460 # The "attach" command doesn't make sense when the target is
3461 # stub-like, where GDB finds the program already started on
3462 # initial connection.
3463 if {[target_info exists use_gdb_stub]} {
3471 # Start a set of programs running and then wait for a bit, to be sure
3472 # that they can be attached to. Return a list of the processes' PIDs.
3473 # It's a test error to call this when [can_spawn_for_attach] is false.
3475 proc spawn_wait_for_attach { executable_list } {
3478 if ![can_spawn_for_attach] {
3479 # The caller should have checked can_spawn_for_attach itself
3480 # before getting here.
3481 error "can't spawn for attach with this target/board"
3484 foreach {executable} $executable_list {
3485 lappend pid_list [eval exec $executable &]
3490 if { [istarget "*-*-cygwin*"] } {
3491 for {set i 0} {$i < [llength $pid_list]} {incr i} {
3492 # testpid is the Cygwin PID, GDB uses the Windows PID,
3493 # which might be different due to the way fork/exec works.
3494 set testpid [lindex $pid_list $i]
3495 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
3496 set pid_list [lreplace $pid_list $i $i $testpid]
3504 # gdb_load_cmd -- load a file into the debugger.
3505 # ARGS - additional args to load command.
3506 # return a -1 if anything goes wrong.
3508 proc gdb_load_cmd { args } {
3511 if [target_info exists gdb_load_timeout] {
3512 set loadtimeout [target_info gdb_load_timeout]
3514 set loadtimeout 1600
3516 send_gdb "load $args\n"
3517 verbose "Timeout is now $loadtimeout seconds" 2
3518 gdb_expect $loadtimeout {
3519 -re "Loading section\[^\r\]*\r\n" {
3522 -re "Start address\[\r\]*\r\n" {
3525 -re "Transfer rate\[\r\]*\r\n" {
3528 -re "Memory access error\[^\r\]*\r\n" {
3529 perror "Failed to load program"
3532 -re "$gdb_prompt $" {
3535 -re "(.*)\r\n$gdb_prompt " {
3536 perror "Unexpected reponse from 'load' -- $expect_out(1,string)"
3540 perror "Timed out trying to load $args."
3547 # Invoke "gcore". CORE is the name of the core file to write. TEST
3548 # is the name of the test case. This will return 1 if the core file
3549 # was created, 0 otherwise. If this fails to make a core file because
3550 # this configuration of gdb does not support making core files, it
3551 # will call "unsupported", not "fail". However, if this fails to make
3552 # a core file for some other reason, then it will call "fail".
3554 proc gdb_gcore_cmd {core test} {
3558 gdb_test_multiple "gcore $core" $test {
3559 -re "Saved corefile .*\[\r\n\]+$gdb_prompt $" {
3563 -re "(?:Can't create a corefile|Target does not support core file generation\\.)\[\r\n\]+$gdb_prompt $" {
3571 # Load core file CORE. TEST is the name of the test case.
3572 # This will record a pass/fail for loading the core file.
3574 # 1 - core file is successfully loaded
3575 # 0 - core file loaded but has a non fatal error
3576 # -1 - core file failed to load
3578 proc gdb_core_cmd { core test } {
3581 gdb_test_multiple "core $core" "$test" {
3582 -re "\\\[Thread debugging using \[^ \r\n\]* enabled\\\]\r\n" {
3585 -re " is not a core dump:.*\r\n$gdb_prompt $" {
3586 fail "$test (bad file format)"
3589 -re ": No such file or directory.*\r\n$gdb_prompt $" {
3590 fail "$test (file not found)"
3593 -re "Couldn't find .* registers in core file.*\r\n$gdb_prompt $" {
3594 fail "$test (incomplete note section)"
3597 -re "Core was generated by .*\r\n$gdb_prompt $" {
3601 -re ".*$gdb_prompt $" {
3606 fail "$test (timeout)"
3610 fail "unsupported output from 'core' command"
3614 # Return the filename to download to the target and load on the target
3615 # for this shared library. Normally just LIBNAME, unless shared libraries
3616 # for this target have separate link and load images.
3618 proc shlib_target_file { libname } {
3622 # Return the filename GDB will load symbols from when debugging this
3623 # shared library. Normally just LIBNAME, unless shared libraries for
3624 # this target have separate link and load images.
3626 proc shlib_symbol_file { libname } {
3630 # Return the filename to download to the target and load for this
3631 # executable. Normally just BINFILE unless it is renamed to something
3632 # else for this target.
3634 proc exec_target_file { binfile } {
3638 # Return the filename GDB will load symbols from when debugging this
3639 # executable. Normally just BINFILE unless executables for this target
3640 # have separate files for symbols.
3642 proc exec_symbol_file { binfile } {
3646 # Rename the executable file. Normally this is just BINFILE1 being renamed
3647 # to BINFILE2, but some targets require multiple binary files.
3648 proc gdb_rename_execfile { binfile1 binfile2 } {
3649 file rename -force [exec_target_file ${binfile1}] \
3650 [exec_target_file ${binfile2}]
3651 if { [exec_target_file ${binfile1}] != [exec_symbol_file ${binfile1}] } {
3652 file rename -force [exec_symbol_file ${binfile1}] \
3653 [exec_symbol_file ${binfile2}]
3657 # "Touch" the executable file to update the date. Normally this is just
3658 # BINFILE, but some targets require multiple files.
3659 proc gdb_touch_execfile { binfile } {
3660 set time [clock seconds]
3661 file mtime [exec_target_file ${binfile}] $time
3662 if { [exec_target_file ${binfile}] != [exec_symbol_file ${binfile}] } {
3663 file mtime [exec_symbol_file ${binfile}] $time
3667 # Like remote_download but provides a gdb-specific behavior. If DEST
3668 # is "host", and the host is not remote, and TOFILE is not specified,
3669 # then the [file tail] of FROMFILE is passed through
3670 # standard_output_file to compute the destination.
3672 proc gdb_remote_download {dest fromfile {tofile {}}} {
3673 if {$dest == "host" && ![is_remote host] && $tofile == ""} {
3674 set tofile [standard_output_file [file tail $fromfile]]
3677 if { $tofile == "" } {
3678 return [remote_download $dest $fromfile]
3680 return [remote_download $dest $fromfile $tofile]
3686 # Copy a file to the remote target and return its target filename.
3687 # Schedule the file to be deleted at the end of this test.
3689 proc gdb_download { filename } {
3692 set destname [remote_download target $filename]
3693 lappend cleanfiles $destname
3697 # gdb_load_shlibs LIB...
3699 # Copy the listed libraries to the target.
3701 proc gdb_load_shlibs { args } {
3702 if {![is_remote target]} {
3706 foreach file $args {
3707 gdb_download [shlib_target_file $file]
3710 # Even if the target supplies full paths for shared libraries,
3711 # they may not be paths for this system.
3712 gdb_test "set solib-search-path [file dirname [lindex $args 0]]" "" ""
3716 # gdb_load -- load a file into the debugger. Specifying no file
3717 # defaults to the executable currently being debugged.
3718 # The return value is 0 for success, -1 for failure.
3719 # Many files in config/*.exp override this procedure.
3721 proc gdb_load { arg } {
3723 return [gdb_file_cmd $arg]
3728 # gdb_reload -- load a file into the target. Called before "running",
3729 # either the first time or after already starting the program once,
3730 # for remote targets. Most files that override gdb_load should now
3731 # override this instead.
3733 proc gdb_reload { } {
3734 # For the benefit of existing configurations, default to gdb_load.
3735 # Specifying no file defaults to the executable currently being
3737 return [gdb_load ""]
3740 proc gdb_continue { function } {
3743 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"]
3746 proc default_gdb_init { test_file_name } {
3747 global gdb_wrapper_initialized
3748 global gdb_wrapper_target
3749 global gdb_test_file_name
3755 gdb_clear_suppressed
3757 set gdb_test_file_name [file rootname [file tail $test_file_name]]
3759 # Make sure that the wrapper is rebuilt
3760 # with the appropriate multilib option.
3761 if { $gdb_wrapper_target != [current_target_name] } {
3762 set gdb_wrapper_initialized 0
3765 # Unlike most tests, we have a small number of tests that generate
3766 # a very large amount of output. We therefore increase the expect
3767 # buffer size to be able to contain the entire test output. This
3768 # is especially needed by gdb.base/info-macros.exp.
3770 # Also set this value for the currently running GDB.
3771 match_max [match_max -d]
3773 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
3774 set pf_prefix "[file tail [file dirname $test_file_name]]/[file tail $test_file_name]:"
3777 if [target_info exists gdb_prompt] {
3778 set gdb_prompt [target_info gdb_prompt]
3780 set gdb_prompt "\\(gdb\\)"
3783 if [info exists use_gdb_stub] {
3788 # Turn BASENAME into a full file name in the standard output
3789 # directory. It is ok if BASENAME is the empty string; in this case
3790 # the directory is returned.
3792 proc standard_output_file {basename} {
3793 global objdir subdir gdb_test_file_name GDB_PARALLEL
3795 if {[info exists GDB_PARALLEL]} {
3796 set dir [file join $objdir outputs $subdir $gdb_test_file_name]
3798 return [file join $dir $basename]
3800 return [file join $objdir $subdir $basename]
3804 # Return the name of a file in our standard temporary directory.
3806 proc standard_temp_file {basename} {
3807 global objdir GDB_PARALLEL
3809 if {[info exists GDB_PARALLEL]} {
3810 return [file join $objdir temp $basename]
3816 # Set 'testfile', 'srcfile', and 'binfile'.
3818 # ARGS is a list of source file specifications.
3819 # Without any arguments, the .exp file's base name is used to
3820 # compute the source file name. The ".c" extension is added in this case.
3821 # If ARGS is not empty, each entry is a source file specification.
3822 # If the specification starts with a ".", it is treated as a suffix
3823 # to append to the .exp file's base name.
3824 # If the specification is the empty string, it is treated as if it
3826 # Otherwise it is a file name.
3827 # The first file in the list is used to set the 'srcfile' global.
3828 # Each subsequent name is used to set 'srcfile2', 'srcfile3', etc.
3830 # Most tests should call this without arguments.
3832 # If a completely different binary file name is needed, then it
3833 # should be handled in the .exp file with a suitable comment.
3835 proc standard_testfile {args} {
3836 global gdb_test_file_name
3838 global gdb_test_file_last_vars
3841 global testfile binfile
3843 set testfile $gdb_test_file_name
3844 set binfile [standard_output_file ${testfile}]
3846 if {[llength $args] == 0} {
3850 # Unset our previous output variables.
3851 # This can help catch hidden bugs.
3852 if {[info exists gdb_test_file_last_vars]} {
3853 foreach varname $gdb_test_file_last_vars {
3855 catch {unset $varname}
3858 # 'executable' is often set by tests.
3859 set gdb_test_file_last_vars {executable}
3863 set varname srcfile$suffix
3866 # Handle an extension.
3869 } elseif {[string range $arg 0 0] == "."} {
3870 set arg $testfile$arg
3874 lappend gdb_test_file_last_vars $varname
3876 if {$suffix == ""} {
3884 # The default timeout used when testing GDB commands. We want to use
3885 # the same timeout as the default dejagnu timeout, unless the user has
3886 # already provided a specific value (probably through a site.exp file).
3887 global gdb_test_timeout
3888 if ![info exists gdb_test_timeout] {
3889 set gdb_test_timeout $timeout
3892 # A list of global variables that GDB testcases should not use.
3893 # We try to prevent their use by monitoring write accesses and raising
3894 # an error when that happens.
3895 set banned_variables { bug_id prms_id }
3897 # A list of procedures that GDB testcases should not use.
3898 # We try to prevent their use by monitoring invocations and raising
3899 # an error when that happens.
3900 set banned_procedures { strace }
3902 # gdb_init is called by runtest at start, but also by several
3903 # tests directly; gdb_finish is only called from within runtest after
3904 # each test source execution.
3905 # Placing several traces by repetitive calls to gdb_init leads
3906 # to problems, as only one trace is removed in gdb_finish.
3907 # To overcome this possible problem, we add a variable that records
3908 # if the banned variables and procedures are already traced.
3911 proc gdb_init { test_file_name } {
3912 # Reset the timeout value to the default. This way, any testcase
3913 # that changes the timeout value without resetting it cannot affect
3914 # the timeout used in subsequent testcases.
3915 global gdb_test_timeout
3917 set timeout $gdb_test_timeout
3919 if { [regexp ".*gdb\.reverse\/.*" $test_file_name]
3920 && [target_info exists gdb_reverse_timeout] } {
3921 set timeout [target_info gdb_reverse_timeout]
3924 # If GDB_INOTIFY is given, check for writes to '.'. This is a
3925 # debugging tool to help confirm that the test suite is
3926 # parallel-safe. You need "inotifywait" from the
3927 # inotify-tools package to use this.
3928 global GDB_INOTIFY inotify_pid
3929 if {[info exists GDB_INOTIFY] && ![info exists inotify_pid]} {
3930 global outdir tool inotify_log_file
3932 set exclusions {outputs temp gdb[.](log|sum) cache}
3933 set exclusion_re ([join $exclusions |])
3935 set inotify_log_file [standard_temp_file inotify.out]
3936 set inotify_pid [exec inotifywait -r -m -e move,create,delete . \
3937 --exclude $exclusion_re \
3938 |& tee -a $outdir/$tool.log $inotify_log_file &]
3940 # Wait for the watches; hopefully this is long enough.
3943 # Clear the log so that we don't emit a warning the first time
3945 set fd [open $inotify_log_file w]
3949 # Block writes to all banned variables, and invocation of all
3950 # banned procedures...
3951 global banned_variables
3952 global banned_procedures
3953 global banned_traced
3954 if (!$banned_traced) {
3955 foreach banned_var $banned_variables {
3956 global "$banned_var"
3957 trace add variable "$banned_var" write error
3959 foreach banned_proc $banned_procedures {
3960 global "$banned_proc"
3961 trace add execution "$banned_proc" enter error
3966 # We set LC_ALL, LC_CTYPE, and LANG to C so that we get the same
3967 # messages as expected.
3972 # Don't let a .inputrc file or an existing setting of INPUTRC mess up
3973 # the test results. Even if /dev/null doesn't exist on the particular
3974 # platform, the readline library will use the default setting just by
3975 # failing to open the file. OTOH, opening /dev/null successfully will
3976 # also result in the default settings being used since nothing will be
3977 # read from this file.
3978 setenv INPUTRC "/dev/null"
3980 # The gdb.base/readline.exp arrow key test relies on the standard VT100
3981 # bindings, so make sure that an appropriate terminal is selected.
3982 # The same bug doesn't show up if we use ^P / ^N instead.
3985 # Some tests (for example gdb.base/maint.exp) shell out from gdb to use
3986 # grep. Clear GREP_OPTIONS to make the behavior predictable,
3987 # especially having color output turned on can cause tests to fail.
3988 setenv GREP_OPTIONS ""
3990 # Clear $gdbserver_reconnect_p.
3991 global gdbserver_reconnect_p
3992 set gdbserver_reconnect_p 1
3993 unset gdbserver_reconnect_p
3995 return [default_gdb_init $test_file_name]
3998 proc gdb_finish { } {
3999 global gdbserver_reconnect_p
4003 # Exit first, so that the files are no longer in use.
4006 if { [llength $cleanfiles] > 0 } {
4007 eval remote_file target delete $cleanfiles
4011 # Unblock write access to the banned variables. Dejagnu typically
4012 # resets some of them between testcases.
4013 global banned_variables
4014 global banned_procedures
4015 global banned_traced
4016 if ($banned_traced) {
4017 foreach banned_var $banned_variables {
4018 global "$banned_var"
4019 trace remove variable "$banned_var" write error
4021 foreach banned_proc $banned_procedures {
4022 global "$banned_proc"
4023 trace remove execution "$banned_proc" enter error
4030 set debug_format "unknown"
4032 # Run the gdb command "info source" and extract the debugging format
4033 # information from the output and save it in debug_format.
4035 proc get_debug_format { } {
4041 set debug_format "unknown"
4042 send_gdb "info source\n"
4044 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
4045 set debug_format $expect_out(1,string)
4046 verbose "debug format is $debug_format"
4049 -re "No current source file.\r\n$gdb_prompt $" {
4050 perror "get_debug_format used when no current source file"
4053 -re "$gdb_prompt $" {
4054 warning "couldn't check debug format (no valid response)."
4058 warning "couldn't check debug format (timeout)."
4064 # Return true if FORMAT matches the debug format the current test was
4065 # compiled with. FORMAT is a shell-style globbing pattern; it can use
4066 # `*', `[...]', and so on.
4068 # This function depends on variables set by `get_debug_format', above.
4070 proc test_debug_format {format} {
4073 return [expr [string match $format $debug_format] != 0]
4076 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
4077 # COFF, stabs, etc). If that format matches the format that the
4078 # current test was compiled with, then the next test is expected to
4079 # fail for any target. Returns 1 if the next test or set of tests is
4080 # expected to fail, 0 otherwise (or if it is unknown). Must have
4081 # previously called get_debug_format.
4082 proc setup_xfail_format { format } {
4083 set ret [test_debug_format $format]
4091 # gdb_get_line_number TEXT [FILE]
4093 # Search the source file FILE, and return the line number of the
4094 # first line containing TEXT. If no match is found, an error is thrown.
4096 # TEXT is a string literal, not a regular expression.
4098 # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is
4099 # specified, and does not start with "/", then it is assumed to be in
4100 # "$srcdir/$subdir". This is awkward, and can be fixed in the future,
4101 # by changing the callers and the interface at the same time.
4102 # In particular: gdb.base/break.exp, gdb.base/condbreak.exp,
4103 # gdb.base/ena-dis-br.exp.
4105 # Use this function to keep your test scripts independent of the
4106 # exact line numbering of the source file. Don't write:
4108 # send_gdb "break 20"
4110 # This means that if anyone ever edits your test's source file,
4111 # your test could break. Instead, put a comment like this on the
4112 # source file line you want to break at:
4114 # /* breakpoint spot: frotz.exp: test name */
4116 # and then write, in your test script (which we assume is named
4119 # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
4121 # (Yes, Tcl knows how to handle the nested quotes and brackets.
4124 # % puts "foo [lindex "bar baz" 1]"
4127 # Tcl is quite clever, for a little stringy language.)
4131 # The previous implementation of this procedure used the gdb search command.
4132 # This version is different:
4134 # . It works with MI, and it also works when gdb is not running.
4136 # . It operates on the build machine, not the host machine.
4138 # . For now, this implementation fakes a current directory of
4139 # $srcdir/$subdir to be compatible with the old implementation.
4140 # This will go away eventually and some callers will need to
4143 # . The TEXT argument is literal text and matches literally,
4144 # not a regular expression as it was before.
4146 # . State changes in gdb, such as changing the current file
4147 # and setting $_, no longer happen.
4149 # After a bit of time we can forget about the differences from the
4150 # old implementation.
4152 # --chastain 2004-08-05
4154 proc gdb_get_line_number { text { file "" } } {
4159 if { "$file" == "" } then {
4162 if { ! [regexp "^/" "$file"] } then {
4163 set file "$srcdir/$subdir/$file"
4166 if { [ catch { set fd [open "$file"] } message ] } then {
4171 for { set line 1 } { 1 } { incr line } {
4172 if { [ catch { set nchar [gets "$fd" body] } message ] } then {
4175 if { $nchar < 0 } then {
4178 if { [string first "$text" "$body"] >= 0 } then {
4184 if { [ catch { close "$fd" } message ] } then {
4189 error "undefined tag \"$text\""
4195 # Continue the program until it ends.
4197 # MSSG is the error message that gets printed. If not given, a
4199 # COMMAND is the command to invoke. If not given, "continue" is
4201 # ALLOW_EXTRA is a flag indicating whether the test should expect
4202 # extra output between the "Continuing." line and the program
4203 # exiting. By default it is zero; if nonzero, any extra output
4206 proc gdb_continue_to_end {{mssg ""} {command continue} {allow_extra 0}} {
4207 global inferior_exited_re use_gdb_stub
4210 set text "continue until exit"
4212 set text "continue until exit at $mssg"
4220 # By default, we don't rely on exit() behavior of remote stubs --
4221 # it's common for exit() to be implemented as a simple infinite
4222 # loop, or a forced crash/reset. For native targets, by default, we
4223 # assume process exit is reported as such. If a non-reliable target
4224 # is used, we set a breakpoint at exit, and continue to that.
4225 if { [target_info exists exit_is_reliable] } {
4226 set exit_is_reliable [target_info exit_is_reliable]
4228 set exit_is_reliable [expr ! $use_gdb_stub]
4231 if { ! $exit_is_reliable } {
4232 if {![gdb_breakpoint "exit"]} {
4235 gdb_test $command "Continuing..*Breakpoint .*exit.*" \
4238 # Continue until we exit. Should not stop again.
4239 # Don't bother to check the output of the program, that may be
4240 # extremely tough for some remote systems.
4242 "Continuing.\[\r\n0-9\]+${extra}(... EXIT code 0\[\r\n\]+|$inferior_exited_re normally).*"\
4247 proc rerun_to_main {} {
4248 global gdb_prompt use_gdb_stub
4253 -re ".*Breakpoint .*main .*$gdb_prompt $"\
4254 {pass "rerun to main" ; return 0}
4255 -re "$gdb_prompt $"\
4256 {fail "rerun to main" ; return 0}
4257 timeout {fail "(timeout) rerun to main" ; return 0}
4262 -re "The program .* has been started already.*y or n. $" {
4266 -re "Starting program.*$gdb_prompt $"\
4267 {pass "rerun to main" ; return 0}
4268 -re "$gdb_prompt $"\
4269 {fail "rerun to main" ; return 0}
4270 timeout {fail "(timeout) rerun to main" ; return 0}
4275 # Print a message and return true if a test should be skipped
4276 # due to lack of floating point suport.
4278 proc gdb_skip_float_test { msg } {
4279 if [target_info exists gdb,skip_float_tests] {
4280 verbose "Skipping test '$msg': no float tests."
4286 # Print a message and return true if a test should be skipped
4287 # due to lack of stdio support.
4289 proc gdb_skip_stdio_test { msg } {
4290 if [target_info exists gdb,noinferiorio] {
4291 verbose "Skipping test '$msg': no inferior i/o."
4297 proc gdb_skip_bogus_test { msg } {
4301 # Return true if a test should be skipped due to lack of XML support
4303 # NOTE: This must be called while gdb is *not* running.
4305 gdb_caching_proc gdb_skip_xml_test {
4309 set xml_file [gdb_remote_download host "${srcdir}/gdb.xml/trivial.xml"]
4313 gdb_test_multiple "set tdesc filename $xml_file" "" {
4314 -re ".*XML support was disabled at compile time.*$gdb_prompt $" {
4317 -re ".*$gdb_prompt $" { }
4323 # Return true if argv[0] is available.
4325 gdb_caching_proc gdb_has_argv0 {
4328 # Set up, compile, and execute a test program to check whether
4329 # argv[0] is available.
4330 set src [standard_temp_file has_argv0[pid].c]
4331 set exe [standard_temp_file has_argv0[pid].x]
4333 gdb_produce_source $src {
4334 int main (int argc, char **argv) {
4339 gdb_compile $src $exe executable {debug}
4342 proc gdb_has_argv0_1 { exe } {
4343 global srcdir subdir
4344 global gdb_prompt hex
4348 gdb_reinitialize_dir $srcdir/$subdir
4351 # Set breakpoint on main.
4352 gdb_test_multiple "break main" "break main" {
4353 -re "Breakpoint.*${gdb_prompt} $" {
4355 -re "${gdb_prompt} $" {
4362 gdb_test_multiple "" "run to main" {
4363 -re "Breakpoint.*${gdb_prompt} $" {
4365 -re "${gdb_prompt} $" {
4370 # Check whether argc is 1.
4371 gdb_test_multiple "p argc" "p argc" {
4372 -re " = 1\r\n${gdb_prompt} $" {
4374 gdb_test_multiple "p argv\[0\]" "p argv\[0\]" {
4375 -re " = $hex \".*[file tail $exe]\"\r\n${gdb_prompt} $" {
4378 -re "${gdb_prompt} $" {
4383 -re "${gdb_prompt} $" {
4390 set result [gdb_has_argv0_1 $exe]
4397 && ([istarget *-*-linux*]
4398 || [istarget *-*-freebsd*] || [istarget *-*-kfreebsd*]
4399 || [istarget *-*-netbsd*] || [istarget *-*-knetbsd*]
4400 || [istarget *-*-openbsd*]
4401 || [istarget *-*-darwin*]
4402 || [istarget *-*-solaris*]
4403 || [istarget *-*-aix*]
4404 || [istarget *-*-gnu*]
4405 || [istarget *-*-cygwin*] || [istarget *-*-mingw32*]
4406 || [istarget *-*-*djgpp*] || [istarget *-*-go32*]
4407 || [istarget *-wince-pe] || [istarget *-*-mingw32ce*]
4408 || [istarget *-*-symbianelf*]
4409 || [istarget *-*-osf*]
4410 || [istarget *-*-hpux*]
4411 || [istarget *-*-dicos*]
4412 || [istarget *-*-nto*]
4413 || [istarget *-*-*vms*]
4414 || [istarget *-*-lynx*178]) } {
4415 fail "argv\[0\] should be available on this target"
4421 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
4422 # ${binfile}.dbglnk, which is just like the executable ($binfile) but without
4423 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
4424 # the name of a debuginfo only file. This file will be stored in the same
4427 # Functions for separate debug info testing
4429 # starting with an executable:
4430 # foo --> original executable
4432 # at the end of the process we have:
4433 # foo.stripped --> foo w/o debug info
4434 # foo.debug --> foo's debug info
4435 # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug.
4437 # Fetch the build id from the file.
4438 # Returns "" if there is none.
4440 proc get_build_id { filename } {
4441 set tmp [standard_output_file "${filename}-tmp"]
4442 set objcopy_program [gdb_find_objcopy]
4444 set result [catch "exec $objcopy_program -j .note.gnu.build-id -O binary $filename $tmp" output]
4445 verbose "result is $result"
4446 verbose "output is $output"
4451 fconfigure $fi -translation binary
4452 # Skip the NOTE header.
4457 if ![string compare $data ""] then {
4460 # Convert it to hex.
4461 binary scan $data H* data
4465 # Return the build-id hex string (usually 160 bits as 40 hex characters)
4466 # converted to the form: .build-id/ab/cdef1234...89.debug
4467 # Return "" if no build-id found.
4468 proc build_id_debug_filename_get { filename } {
4469 set data [get_build_id $filename]
4470 if { $data == "" } {
4473 regsub {^..} $data {\0/} data
4474 return ".build-id/${data}.debug"
4477 # Create stripped files for DEST, replacing it. If ARGS is passed, it is a
4478 # list of optional flags. The only currently supported flag is no-main,
4479 # which removes the symbol entry for main from the separate debug file.
4481 # Function returns zero on success. Function will return non-zero failure code
4482 # on some targets not supporting separate debug info (such as i386-msdos).
4484 proc gdb_gnu_strip_debug { dest args } {
4486 # Use the first separate debug info file location searched by GDB so the
4487 # run cannot be broken by some stale file searched with higher precedence.
4488 set debug_file "${dest}.debug"
4490 set strip_to_file_program [transform strip]
4491 set objcopy_program [gdb_find_objcopy]
4493 set debug_link [file tail $debug_file]
4494 set stripped_file "${dest}.stripped"
4496 # Get rid of the debug info, and store result in stripped_file
4497 # something like gdb/testsuite/gdb.base/blah.stripped.
4498 set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
4499 verbose "result is $result"
4500 verbose "output is $output"
4505 # Workaround PR binutils/10802:
4506 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
4507 set perm [file attributes ${dest} -permissions]
4508 file attributes ${stripped_file} -permissions $perm
4510 # Get rid of everything but the debug info, and store result in debug_file
4511 # This will be in the .debug subdirectory, see above.
4512 set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
4513 verbose "result is $result"
4514 verbose "output is $output"
4519 # If no-main is passed, strip the symbol for main from the separate
4520 # file. This is to simulate the behavior of elfutils's eu-strip, which
4521 # leaves the symtab in the original file only. There's no way to get
4522 # objcopy or strip to remove the symbol table without also removing the
4523 # debugging sections, so this is as close as we can get.
4524 if { [llength $args] == 1 && [lindex $args 0] == "no-main" } {
4525 set result [catch "exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp" output]
4526 verbose "result is $result"
4527 verbose "output is $output"
4531 file delete "${debug_file}"
4532 file rename "${debug_file}-tmp" "${debug_file}"
4535 # Link the two previous output files together, adding the .gnu_debuglink
4536 # section to the stripped_file, containing a pointer to the debug_file,
4537 # save the new file in dest.
4538 # This will be the regular executable filename, in the usual location.
4539 set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
4540 verbose "result is $result"
4541 verbose "output is $output"
4546 # Workaround PR binutils/10802:
4547 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
4548 set perm [file attributes ${stripped_file} -permissions]
4549 file attributes ${dest} -permissions $perm
4554 # Test the output of GDB_COMMAND matches the pattern obtained
4555 # by concatenating all elements of EXPECTED_LINES. This makes
4556 # it possible to split otherwise very long string into pieces.
4557 # If third argument is not empty, it's used as the name of the
4558 # test to be printed on pass/fail.
4559 proc help_test_raw { gdb_command expected_lines args } {
4560 set message $gdb_command
4561 if [llength $args]>0 then {
4562 set message [lindex $args 0]
4564 set expected_output [join $expected_lines ""]
4565 gdb_test "${gdb_command}" "${expected_output}" $message
4568 # Test the output of "help COMMAND_CLASS". EXPECTED_INITIAL_LINES
4569 # are regular expressions that should match the beginning of output,
4570 # before the list of commands in that class. The presence of
4571 # command list and standard epilogue will be tested automatically.
4572 proc test_class_help { command_class expected_initial_lines args } {
4574 "List of commands\:.*\[\r\n\]+"
4575 "Type \"help\" followed by command name for full documentation\.\[\r\n\]+"
4576 "Type \"apropos word\" to search for commands related to \"word\"\.[\r\n\]+"
4577 "Command name abbreviations are allowed if unambiguous\."
4579 set l_entire_body [concat $expected_initial_lines $l_stock_body]
4581 eval [list help_test_raw "help ${command_class}" $l_entire_body] $args
4584 # COMMAND_LIST should have either one element -- command to test, or
4585 # two elements -- abbreviated command to test, and full command the first
4586 # element is abbreviation of.
4587 # The command must be a prefix command. EXPECTED_INITIAL_LINES
4588 # are regular expressions that should match the beginning of output,
4589 # before the list of subcommands. The presence of
4590 # subcommand list and standard epilogue will be tested automatically.
4591 proc test_prefix_command_help { command_list expected_initial_lines args } {
4592 set command [lindex $command_list 0]
4593 if {[llength $command_list]>1} {
4594 set full_command [lindex $command_list 1]
4596 set full_command $command
4598 # Use 'list' and not just {} because we want variables to
4599 # be expanded in this list.
4600 set l_stock_body [list\
4601 "List of $full_command subcommands\:.*\[\r\n\]+"\
4602 "Type \"help $full_command\" followed by $full_command subcommand name for full documentation\.\[\r\n\]+"\
4603 "Type \"apropos word\" to search for commands related to \"word\"\.\[\r\n\]+"\
4604 "Command name abbreviations are allowed if unambiguous\."]
4605 set l_entire_body [concat $expected_initial_lines $l_stock_body]
4606 if {[llength $args]>0} {
4607 help_test_raw "help ${command}" $l_entire_body [lindex $args 0]
4609 help_test_raw "help ${command}" $l_entire_body
4613 # Build executable named EXECUTABLE from specifications that allow
4614 # different options to be passed to different sub-compilations.
4615 # TESTNAME is the name of the test; this is passed to 'untested' if
4617 # OPTIONS is passed to the final link, using gdb_compile. If OPTIONS
4618 # contains the option "pthreads", then gdb_compile_pthreads is used.
4619 # ARGS is a flat list of source specifications, of the form:
4620 # { SOURCE1 OPTIONS1 [ SOURCE2 OPTIONS2 ]... }
4621 # Each SOURCE is compiled to an object file using its OPTIONS,
4622 # using gdb_compile.
4623 # Returns 0 on success, -1 on failure.
4624 proc build_executable_from_specs {testname executable options args} {
4628 set binfile [standard_output_file $executable]
4631 if { [lsearch -exact $options "c++"] >= 0 } {
4632 set info_options "c++"
4634 if [get_compiler_info ${info_options}] {
4638 set func gdb_compile
4639 set func_index [lsearch -regexp $options {^(pthreads|shlib|shlib_pthreads)$}]
4640 if {$func_index != -1} {
4641 set func "${func}_[lindex $options $func_index]"
4644 # gdb_compile_shlib and gdb_compile_shlib_pthreads do not use the 3rd
4645 # parameter. They also requires $sources while gdb_compile and
4646 # gdb_compile_pthreads require $objects. Moreover they ignore any options.
4647 if [string match gdb_compile_shlib* $func] {
4649 foreach {s local_options} $args {
4650 if { [regexp "^/" "$s"] } then {
4651 lappend sources_path "$s"
4653 lappend sources_path "$srcdir/$subdir/$s"
4656 set ret [$func $sources_path "${binfile}" $options]
4660 foreach {s local_options} $args {
4661 if { ! [regexp "^/" "$s"] } then {
4662 set s "$srcdir/$subdir/$s"
4664 if { [gdb_compile "${s}" "${binfile}${i}.o" object $local_options] != "" } {
4668 lappend objects "${binfile}${i}.o"
4671 set ret [$func $objects "${binfile}" executable $options]
4681 # Build executable named EXECUTABLE, from SOURCES. If SOURCES are not
4682 # provided, uses $EXECUTABLE.c. The TESTNAME paramer is the name of test
4683 # to pass to untested, if something is wrong. OPTIONS are passed
4684 # to gdb_compile directly.
4685 proc build_executable { testname executable {sources ""} {options {debug}} } {
4686 if {[llength $sources]==0} {
4687 set sources ${executable}.c
4690 set arglist [list $testname $executable $options]
4691 foreach source $sources {
4692 lappend arglist $source $options
4695 return [eval build_executable_from_specs $arglist]
4698 # Starts fresh GDB binary and loads EXECUTABLE into GDB. EXECUTABLE is
4699 # the basename of the binary.
4700 # The return value is 0 for success, -1 for failure.
4701 proc clean_restart { executable } {
4704 set binfile [standard_output_file ${executable}]
4708 gdb_reinitialize_dir $srcdir/$subdir
4709 return [gdb_load ${binfile}]
4712 # Prepares for testing by calling build_executable_full, then
4714 # TESTNAME is the name of the test.
4715 # Each element in ARGS is a list of the form
4716 # { EXECUTABLE OPTIONS SOURCE_SPEC... }
4717 # These are passed to build_executable_from_specs, which see.
4718 # The last EXECUTABLE is passed to clean_restart.
4719 # Returns 0 on success, non-zero on failure.
4720 proc prepare_for_testing_full {testname args} {
4721 foreach spec $args {
4722 if {[eval build_executable_from_specs [list $testname] $spec] == -1} {
4725 set executable [lindex $spec 0]
4727 clean_restart $executable
4731 # Prepares for testing, by calling build_executable, and then clean_restart.
4732 # Please refer to build_executable for parameter description.
4733 proc prepare_for_testing { testname executable {sources ""} {options {debug}}} {
4735 if {[build_executable $testname $executable $sources $options] == -1} {
4738 clean_restart $executable
4743 proc get_valueof { fmt exp default } {
4746 set test "get valueof \"${exp}\""
4748 gdb_test_multiple "print${fmt} ${exp}" "$test" {
4749 -re "\\$\[0-9\]* = (.*)\[\r\n\]*$gdb_prompt $" {
4750 set val $expect_out(1,string)
4754 fail "$test (timeout)"
4760 proc get_integer_valueof { exp default } {
4763 set test "get integer valueof \"${exp}\""
4765 gdb_test_multiple "print /d ${exp}" "$test" {
4766 -re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" {
4767 set val $expect_out(1,string)
4771 fail "$test (timeout)"
4777 proc get_hexadecimal_valueof { exp default } {
4779 send_gdb "print /x ${exp}\n"
4780 set test "get hexadecimal valueof \"${exp}\""
4782 -re "\\$\[0-9\]* = (0x\[0-9a-zA-Z\]+).*$gdb_prompt $" {
4783 set val $expect_out(1,string)
4788 fail "$test (timeout)"
4794 proc get_sizeof { type default } {
4795 return [get_integer_valueof "sizeof (${type})" $default]
4798 proc get_target_charset { } {
4801 gdb_test_multiple "show target-charset" "" {
4802 -re "The target character set is \"auto; currently (\[^\"\]*)\".*$gdb_prompt $" {
4803 return $expect_out(1,string)
4805 -re "The target character set is \"(\[^\"\]*)\".*$gdb_prompt $" {
4806 return $expect_out(1,string)
4810 # Pick a reasonable default.
4811 warning "Unable to read target-charset."
4815 # Get the current value for remotetimeout and return it.
4816 proc get_remotetimeout { } {
4820 gdb_test_multiple "show remotetimeout" "" {
4821 -re "Timeout limit to wait for target to respond is ($decimal).*$gdb_prompt $" {
4822 return $expect_out(1,string)
4826 # Pick the default that gdb uses
4827 warning "Unable to read remotetimeout"
4831 # Set the remotetimeout to the specified timeout. Nothing is returned.
4832 proc set_remotetimeout { timeout } {
4835 gdb_test_multiple "set remotetimeout $timeout" "" {
4836 -re "$gdb_prompt $" {
4837 verbose "Set remotetimeout to $timeout\n"
4842 # ROOT and FULL are file names. Returns the relative path from ROOT
4843 # to FULL. Note that FULL must be in a subdirectory of ROOT.
4844 # For example, given ROOT = /usr/bin and FULL = /usr/bin/ls, this
4847 proc relative_filename {root full} {
4848 set root_split [file split $root]
4849 set full_split [file split $full]
4851 set len [llength $root_split]
4853 if {[eval file join $root_split]
4854 != [eval file join [lrange $full_split 0 [expr {$len - 1}]]]} {
4855 error "$full not a subdir of $root"
4858 return [eval file join [lrange $full_split $len end]]
4861 # Log gdb command line and script if requested.
4862 if {[info exists TRANSCRIPT]} {
4863 rename send_gdb real_send_gdb
4864 rename remote_spawn real_remote_spawn
4865 rename remote_close real_remote_close
4867 global gdb_transcript
4868 set gdb_transcript ""
4870 global gdb_trans_count
4871 set gdb_trans_count 1
4873 proc remote_spawn {args} {
4874 global gdb_transcript gdb_trans_count outdir
4876 if {$gdb_transcript != ""} {
4877 close $gdb_transcript
4879 set gdb_transcript [open [file join $outdir transcript.$gdb_trans_count] w]
4880 puts $gdb_transcript [lindex $args 1]
4881 incr gdb_trans_count
4883 return [uplevel real_remote_spawn $args]
4886 proc remote_close {args} {
4887 global gdb_transcript
4889 if {$gdb_transcript != ""} {
4890 close $gdb_transcript
4891 set gdb_transcript ""
4894 return [uplevel real_remote_close $args]
4897 proc send_gdb {args} {
4898 global gdb_transcript
4900 if {$gdb_transcript != ""} {
4901 puts -nonewline $gdb_transcript [lindex $args 0]
4904 return [uplevel real_send_gdb $args]
4908 # If GDB_PARALLEL exists, then set up the parallel-mode directories.
4909 if {[info exists GDB_PARALLEL]} {
4910 if {[is_remote host]} {
4913 file mkdir outputs temp cache
4917 proc core_find {binfile {deletefiles {}} {arg ""}} {
4918 global objdir subdir
4920 set destcore "$binfile.core"
4921 file delete $destcore
4923 # Create a core file named "$destcore" rather than just "core", to
4924 # avoid problems with sys admin types that like to regularly prune all
4925 # files named "core" from the system.
4927 # Arbitrarily try setting the core size limit to "unlimited" since
4928 # this does not hurt on systems where the command does not work and
4929 # allows us to generate a core on systems where it does.
4931 # Some systems append "core" to the name of the program; others append
4932 # the name of the program to "core"; still others (like Linux, as of
4933 # May 2003) create cores named "core.PID". In the latter case, we
4934 # could have many core files lying around, and it may be difficult to
4935 # tell which one is ours, so let's run the program in a subdirectory.
4937 set coredir [standard_output_file coredir.[getpid]]
4939 catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile} ${arg}; true) >/dev/null 2>&1\""
4940 # remote_exec host "${binfile}"
4941 foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
4942 if [remote_file build exists $i] {
4943 remote_exec build "mv $i $destcore"
4947 # Check for "core.PID".
4948 if { $found == 0 } {
4949 set names [glob -nocomplain -directory $coredir core.*]
4950 if {[llength $names] == 1} {
4951 set corefile [file join $coredir [lindex $names 0]]
4952 remote_exec build "mv $corefile $destcore"
4956 if { $found == 0 } {
4957 # The braindamaged HPUX shell quits after the ulimit -c above
4958 # without executing ${binfile}. So we try again without the
4959 # ulimit here if we didn't find a core file above.
4960 # Oh, I should mention that any "braindamaged" non-Unix system has
4961 # the same problem. I like the cd bit too, it's really neat'n stuff.
4962 catch "system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\""
4963 foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" {
4964 if [remote_file build exists $i] {
4965 remote_exec build "mv $i $destcore"
4971 # Try to clean up after ourselves.
4972 foreach deletefile $deletefiles {
4973 remote_file build delete [file join $coredir $deletefile]
4975 remote_exec build "rmdir $coredir"
4977 if { $found == 0 } {
4978 warning "can't generate a core file - core tests suppressed - check ulimit -c"
4984 # gdb_target_symbol_prefix_flags returns a string that can be added
4985 # to gdb_compile options to define SYMBOL_PREFIX macro value
4986 # symbol_prefix_flags returns a string that can be added
4987 # for targets that use underscore as symbol prefix.
4988 # TODO: find out automatically if the target needs this.
4990 proc gdb_target_symbol_prefix_flags {} {
4991 if { [istarget "i?86-*-cygwin*"] || [istarget "i?86-*-mingw*"]
4992 || [istarget "*-*-msdosdjgpp*"] || [istarget "*-*-go32*"] } {
4993 return "additional_flags=-DSYMBOL_PREFIX=\"_\""
4999 # A wrapper for 'remote_exec host' that passes or fails a test.
5000 # Returns 0 if all went well, nonzero on failure.
5001 # TEST is the name of the test, other arguments are as for remote_exec.
5003 proc run_on_host { test program args } {
5004 verbose -log "run_on_host: $program $args"
5005 # remote_exec doesn't work properly if the output is set but the
5006 # input is the empty string -- so replace an empty input with
5008 if {[llength $args] > 1 && [lindex $args 1] == ""} {
5009 set args [lreplace $args 1 1 "/dev/null"]
5011 set result [eval remote_exec host [list $program] $args]
5012 verbose "result is $result"
5013 set status [lindex $result 0]
5014 set output [lindex $result 1]
5019 verbose -log "run_on_host failed: $output"
5025 # Return non-zero if "board_info debug_flags" mentions Fission.
5026 # http://gcc.gnu.org/wiki/DebugFission
5027 # Fission doesn't support everything yet.
5028 # This supports working around bug 15954.
5030 proc using_fission { } {
5031 set debug_flags [board_info [target_info name] debug_flags]
5032 return [regexp -- "-gsplit-dwarf" $debug_flags]
5035 # Search the caller's ARGS list and set variables according to the list of
5036 # valid options described by ARGSET.
5038 # The first member of each one- or two-element list in ARGSET defines the
5039 # name of a variable that will be added to the caller's scope.
5041 # If only one element is given to describe an option, it the value is
5042 # 0 if the option is not present in (the caller's) ARGS or 1 if
5045 # If two elements are given, the second element is the default value of
5046 # the variable. This is then overwritten if the option exists in ARGS.
5048 # Any parse_args elements in (the caller's) ARGS will be removed, leaving
5049 # any optional components.
5052 # proc myproc {foo args} {
5053 # parse_args {{bar} {baz "abc"} {qux}}
5056 # myproc ABC -bar -baz DEF peanut butter
5057 # will define the following variables in myproc:
5058 # foo (=ABC), bar (=1), baz (=DEF), and qux (=0)
5059 # args will be the list {peanut butter}
5061 proc parse_args { argset } {
5064 foreach argument $argset {
5065 if {[llength $argument] == 1} {
5066 # No default specified, so we assume that we should set
5067 # the value to 1 if the arg is present and 0 if it's not.
5068 # It is assumed that no value is given with the argument.
5069 set result [lsearch -exact $args "-$argument"]
5070 if {$result != -1} then {
5071 uplevel 1 [list set $argument 1]
5072 set args [lreplace $args $result $result]
5074 uplevel 1 [list set $argument 0]
5076 } elseif {[llength $argument] == 2} {
5077 # There are two items in the argument. The second is a
5078 # default value to use if the item is not present.
5079 # Otherwise, the variable is set to whatever is provided
5080 # after the item in the args.
5081 set arg [lindex $argument 0]
5082 set result [lsearch -exact $args "-[lindex $arg 0]"]
5083 if {$result != -1} then {
5084 uplevel 1 [list set $arg [lindex $args [expr $result+1]]]
5085 set args [lreplace $args $result [expr $result+1]]
5087 uplevel 1 [list set $arg [lindex $argument 1]]
5090 error "Badly formatted argument \"$argument\" in argument set"
5094 # The remaining args should be checked to see that they match the
5095 # number of items expected to be passed into the procedure...
5098 # Capture the output of COMMAND in a string ignoring PREFIX; return that string.
5099 proc capture_command_output { command prefix } {
5103 set output_string ""
5104 gdb_test_multiple "$command" "capture_command_output for $command" {
5105 -re "${command}\[\r\n\]+${prefix}(.*)\[\r\n\]+$gdb_prompt $" {
5106 set output_string $expect_out(1,string)
5109 return $output_string
5112 # A convenience function that joins all the arguments together, with a
5113 # regexp that matches exactly one end of line in between each argument.
5114 # This function is ideal to write the expected output of a GDB command
5115 # that generates more than a couple of lines, as this allows us to write
5116 # each line as a separate string, which is easier to read by a human
5119 proc multi_line { args } {
5120 return [join $args "\r\n"]
5123 # Always load compatibility stuff.