1 # Copyright 1992-2017 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
35 # The spawn ID used for I/O interaction with the inferior. For native
36 # targets, or remote targets that can do I/O through GDB
37 # (semi-hosting) this will be the same as the host/GDB's spawn ID.
38 # Otherwise, the board may set this to some other spawn ID. E.g.,
39 # when debugging with GDBserver, this is set to GDBserver's spawn ID,
40 # so input/output is done on gdbserver's tty.
41 global inferior_spawn_id
43 if [info exists TOOL_EXECUTABLE] {
44 set GDB $TOOL_EXECUTABLE
46 if ![info exists GDB] {
47 if ![is_remote host] {
48 set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]]
50 set GDB [transform gdb]
53 verbose "using GDB = $GDB" 2
55 # GDBFLAGS is available for the user to set on the command line.
56 # E.g. make check RUNTESTFLAGS=GDBFLAGS=mumble
57 # Testcases may use it to add additional flags, but they must:
58 # - append new flags, not overwrite
59 # - restore the original value when done
61 if ![info exists GDBFLAGS] {
64 verbose "using GDBFLAGS = $GDBFLAGS" 2
66 # Make the build data directory available to tests.
67 set BUILD_DATA_DIRECTORY "[pwd]/../data-directory"
69 # INTERNAL_GDBFLAGS contains flags that the testsuite requires.
70 global INTERNAL_GDBFLAGS
71 if ![info exists INTERNAL_GDBFLAGS] {
72 set INTERNAL_GDBFLAGS "-nw -nx -data-directory $BUILD_DATA_DIRECTORY"
75 # The variable gdb_prompt is a regexp which matches the gdb prompt.
76 # Set it if it is not already set. This is also set by default_gdb_init
77 # but it's not clear what removing one of them will break.
78 # See with_gdb_prompt for more details on prompt handling.
80 if ![info exists gdb_prompt] then {
81 set gdb_prompt "\\(gdb\\)"
84 # A regexp that matches the pagination prompt.
85 set pagination_prompt [string_to_regexp "---Type <return> to continue, or q <return> to quit---"]
87 # The variable fullname_syntax_POSIX is a regexp which matches a POSIX
88 # absolute path ie. /foo/
89 set fullname_syntax_POSIX {/[^\n]*/}
90 # The variable fullname_syntax_UNC is a regexp which matches a Windows
91 # UNC path ie. \\D\foo\
92 set fullname_syntax_UNC {\\\\[^\\]+\\[^\n]+\\}
93 # The variable fullname_syntax_DOS_CASE is a regexp which matches a
94 # particular DOS case that GDB most likely will output
95 # ie. \foo\, but don't match \\.*\
96 set fullname_syntax_DOS_CASE {\\[^\\][^\n]*\\}
97 # The variable fullname_syntax_DOS is a regexp which matches a DOS path
98 # ie. a:\foo\ && a:foo\
99 set fullname_syntax_DOS {[a-zA-Z]:[^\n]*\\}
100 # The variable fullname_syntax is a regexp which matches what GDB considers
101 # an absolute path. It is currently debatable if the Windows style paths
102 # d:foo and \abc should be considered valid as an absolute path.
103 # Also, the purpse of this regexp is not to recognize a well formed
104 # absolute path, but to say with certainty that a path is absolute.
105 set fullname_syntax "($fullname_syntax_POSIX|$fullname_syntax_UNC|$fullname_syntax_DOS_CASE|$fullname_syntax_DOS)"
107 # Needed for some tests under Cygwin.
111 if ![info exists env(EXEEXT)] {
114 set EXEEXT $env(EXEEXT)
119 set inferior_exited_re "(\\\[Inferior \[0-9\]+ \\(.*\\) exited)"
121 # A regular expression that matches a value history number.
123 set valnum_re "\\\$$decimal"
125 ### Only procedures should come after this point.
128 # gdb_version -- extract and print the version number of GDB
130 proc default_gdb_version {} {
132 global INTERNAL_GDBFLAGS GDBFLAGS
136 if {[info exists inotify_pid]} {
137 eval exec kill $inotify_pid
140 set output [remote_exec host "$GDB $INTERNAL_GDBFLAGS --version"]
141 set tmp [lindex $output 1]
143 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
144 if ![is_remote host] {
145 clone_output "[which $GDB] version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
147 clone_output "$GDB on remote host version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
151 proc gdb_version { } {
152 return [default_gdb_version]
156 # gdb_unload -- unload a file if one is loaded
157 # Return 0 on success, -1 on error.
166 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
167 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
168 -re "A program is being debugged already.*Are you sure you want to change the file.*y or n. $" {
172 -re "Discard symbol table from .*y or n.*$" {
176 -re "$gdb_prompt $" {}
178 perror "couldn't unload file in $GDB (timeout)."
185 # Many of the tests depend on setting breakpoints at various places and
186 # running until that breakpoint is reached. At times, we want to start
187 # with a clean-slate with respect to breakpoints, so this utility proc
188 # lets us do this without duplicating this code everywhere.
191 proc delete_breakpoints {} {
194 # we need a larger timeout value here or this thing just confuses
195 # itself. May need a better implementation if possible. - guo
199 set msg "delete all breakpoints in delete_breakpoints"
201 gdb_test_multiple "delete breakpoints" "$msg" {
202 -re "Delete all breakpoints.*y or n.*$" {
206 -re "$gdb_prompt $" {
212 # Confirm with "info breakpoints".
214 set msg "info breakpoints"
215 gdb_test_multiple $msg $msg {
216 -re "No breakpoints or watchpoints..*$gdb_prompt $" {
219 -re "$gdb_prompt $" {
225 perror "breakpoints not deleted"
229 # Generic run command.
231 # The second pattern below matches up to the first newline *only*.
232 # Using ``.*$'' could swallow up output that we attempt to match
235 # N.B. This function does not wait for gdb to return to the prompt,
236 # that is the caller's responsibility.
238 proc gdb_run_cmd {args} {
239 global gdb_prompt use_gdb_stub
241 foreach command [gdb_init_commands] {
242 send_gdb "$command\n"
244 -re "$gdb_prompt $" { }
246 perror "gdb_init_command for target failed"
253 if [target_info exists gdb,do_reload_on_run] {
254 if { [gdb_reload] != 0 } {
257 send_gdb "continue\n"
259 -re "Continu\[^\r\n\]*\[\r\n\]" {}
265 if [target_info exists gdb,start_symbol] {
266 set start [target_info gdb,start_symbol]
270 send_gdb "jump *$start\n"
272 while { $start_attempt } {
273 # Cap (re)start attempts at three to ensure that this loop
274 # always eventually fails. Don't worry about trying to be
275 # clever and not send a command when it has failed.
276 if [expr $start_attempt > 3] {
277 perror "Jump to start() failed (retry count exceeded)"
280 set start_attempt [expr $start_attempt + 1]
282 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
285 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
286 perror "Can't find start symbol to run in gdb_run"
289 -re "No symbol \"start\" in current.*$gdb_prompt $" {
290 send_gdb "jump *_start\n"
292 -re "No symbol.*context.*$gdb_prompt $" {
295 -re "Line.* Jump anyway.*y or n. $" {
298 -re "The program is not being run.*$gdb_prompt $" {
299 if { [gdb_reload] != 0 } {
302 send_gdb "jump *$start\n"
305 perror "Jump to start() failed (timeout)"
313 if [target_info exists gdb,do_reload_on_run] {
314 if { [gdb_reload] != 0 } {
318 send_gdb "run $args\n"
319 # This doesn't work quite right yet.
320 # Use -notransfer here so that test cases (like chng-sym.exp)
321 # may test for additional start-up messages.
323 -re "The program .* has been started already.*y or n. $" {
327 -notransfer -re "Starting program: \[^\r\n\]*" {}
328 -notransfer -re "$gdb_prompt $" {
329 # There is no more input expected.
334 # Generic start command. Return 0 if we could start the program, -1
337 # N.B. This function does not wait for gdb to return to the prompt,
338 # that is the caller's responsibility.
340 proc gdb_start_cmd {args} {
341 global gdb_prompt use_gdb_stub
343 foreach command [gdb_init_commands] {
344 send_gdb "$command\n"
346 -re "$gdb_prompt $" { }
348 perror "gdb_init_command for target failed"
358 send_gdb "start $args\n"
359 # Use -notransfer here so that test cases (like chng-sym.exp)
360 # may test for additional start-up messages.
362 -re "The program .* has been started already.*y or n. $" {
366 -notransfer -re "Starting program: \[^\r\n\]*" {
373 # Set a breakpoint at FUNCTION. If there is an additional argument it is
374 # a list of options; the supported options are allow-pending, temporary,
375 # message, no-message, and passfail.
376 # The result is 1 for success, 0 for failure.
378 # Note: The handling of message vs no-message is messed up, but it's based
379 # on historical usage. By default this function does not print passes,
381 # no-message: turns off printing of fails (and passes, but they're already off)
382 # message: turns on printing of passes (and fails, but they're already on)
384 proc gdb_breakpoint { function args } {
388 set pending_response n
389 if {[lsearch -exact $args allow-pending] != -1} {
390 set pending_response y
393 set break_command "break"
394 set break_message "Breakpoint"
395 if {[lsearch -exact $args temporary] != -1} {
396 set break_command "tbreak"
397 set break_message "Temporary breakpoint"
402 set no_message_loc [lsearch -exact $args no-message]
403 set message_loc [lsearch -exact $args message]
404 # The last one to appear in args wins.
405 if { $no_message_loc > $message_loc } {
407 } elseif { $message_loc > $no_message_loc } {
411 set test_name "setting breakpoint at $function"
413 send_gdb "$break_command $function\n"
414 # The first two regexps are what we get with -g, the third is without -g.
416 -re "$break_message \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
417 -re "$break_message \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
418 -re "$break_message \[0-9\]* at .*$gdb_prompt $" {}
419 -re "$break_message \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" {
420 if {$pending_response == "n"} {
427 -re "Make breakpoint pending.*y or \\\[n\\\]. $" {
428 send_gdb "$pending_response\n"
431 -re "A problem internal to GDB has been detected" {
433 fail "$test_name (GDB internal error)"
435 gdb_internal_error_resync
438 -re "$gdb_prompt $" {
446 fail "$test_name (eof)"
452 fail "$test_name (timeout)"
463 # Set breakpoint at function and run gdb until it breaks there.
464 # Since this is the only breakpoint that will be set, if it stops
465 # at a breakpoint, we will assume it is the one we want. We can't
466 # just compare to "function" because it might be a fully qualified,
467 # single quoted C++ function specifier.
469 # If there are additional arguments, pass them to gdb_breakpoint.
470 # We recognize no-message/message ourselves.
471 # The default is no-message.
472 # no-message is messed up here, like gdb_breakpoint: to preserve
473 # historical usage fails are always printed by default.
474 # no-message: turns off printing of fails (and passes, but they're already off)
475 # message: turns on printing of passes (and fails, but they're already on)
477 proc runto { function args } {
483 # Default to "no-message".
484 set args "no-message $args"
488 set no_message_loc [lsearch -exact $args no-message]
489 set message_loc [lsearch -exact $args message]
490 # The last one to appear in args wins.
491 if { $no_message_loc > $message_loc } {
493 } elseif { $message_loc > $no_message_loc } {
497 set test_name "running to $function in runto"
499 # We need to use eval here to pass our varargs args to gdb_breakpoint
500 # which is also a varargs function.
501 # But we also have to be careful because $function may have multiple
502 # elements, and we don't want Tcl to move the remaining elements after
503 # the first to $args. That is why $function is wrapped in {}.
504 if ![eval gdb_breakpoint {$function} $args] {
510 # the "at foo.c:36" output we get with -g.
511 # the "in func" output we get without -g.
513 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
519 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
525 -re "The target does not support running in non-stop mode.\r\n$gdb_prompt $" {
527 unsupported "non-stop mode not supported"
531 -re ".*A problem internal to GDB has been detected" {
533 fail "$test_name (GDB internal error)"
535 gdb_internal_error_resync
538 -re "$gdb_prompt $" {
546 fail "$test_name (eof)"
552 fail "$test_name (timeout)"
563 # Ask gdb to run until we hit a breakpoint at main.
565 # N.B. This function deletes all existing breakpoints.
566 # If you don't want that, use gdb_start_cmd.
568 proc runto_main { } {
569 return [runto main no-message]
572 ### Continue, and expect to hit a breakpoint.
573 ### Report a pass or fail, depending on whether it seems to have
574 ### worked. Use NAME as part of the test name; each call to
575 ### continue_to_breakpoint should use a NAME which is unique within
577 proc gdb_continue_to_breakpoint {name {location_pattern .*}} {
579 set full_name "continue to breakpoint: $name"
581 gdb_test_multiple "continue" $full_name {
582 -re "(?:Breakpoint|Temporary breakpoint) .* (at|in) $location_pattern\r\n$gdb_prompt $" {
589 # gdb_internal_error_resync:
591 # Answer the questions GDB asks after it reports an internal error
592 # until we get back to a GDB prompt. Decline to quit the debugging
593 # session, and decline to create a core file. Return non-zero if the
596 # This procedure just answers whatever questions come up until it sees
597 # a GDB prompt; it doesn't require you to have matched the input up to
598 # any specific point. However, it only answers questions it sees in
599 # the output itself, so if you've matched a question, you had better
600 # answer it yourself before calling this.
602 # You can use this function thus:
606 # -re ".*A problem internal to GDB has been detected" {
607 # gdb_internal_error_resync
612 proc gdb_internal_error_resync {} {
615 verbose -log "Resyncing due to internal error."
618 while {$count < 10} {
620 -re "Quit this debugging session\\? \\(y or n\\) $" {
624 -re "Create a core file of GDB\\? \\(y or n\\) $" {
628 -re "$gdb_prompt $" {
629 # We're resynchronized.
633 perror "Could not resync from internal error (timeout)"
638 perror "Could not resync from internal error (resync count exceeded)"
643 # gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS
644 # Send a command to gdb; test the result.
646 # COMMAND is the command to execute, send to GDB with send_gdb. If
647 # this is the null string no command is sent.
648 # MESSAGE is a message to be printed with the built-in failure patterns
649 # if one of them matches. If MESSAGE is empty COMMAND will be used.
650 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
651 # patterns. Pattern elements will be evaluated in the caller's
652 # context; action elements will be executed in the caller's context.
653 # Unlike patterns for gdb_test, these patterns should generally include
654 # the final newline and prompt.
657 # 1 if the test failed, according to a built-in failure pattern
658 # 0 if only user-supplied patterns matched
659 # -1 if there was an internal error.
661 # You can use this function thus:
663 # gdb_test_multiple "print foo" "test foo" {
664 # -re "expected output 1" {
667 # -re "expected output 2" {
672 # Like with "expect", you can also specify the spawn id to match with
673 # -i "$id". Interesting spawn ids are $inferior_spawn_id and
674 # $gdb_spawn_id. The former matches inferior I/O, while the latter
675 # matches GDB I/O. E.g.:
677 # send_inferior "hello\n"
678 # gdb_test_multiple "continue" "test echo" {
679 # -i "$inferior_spawn_id" -re "^hello\r\nhello\r\n$" {
682 # -i "$gdb_spawn_id" -re "Breakpoint.*$gdb_prompt $" {
683 # fail "hit breakpoint"
687 # The standard patterns, such as "Inferior exited..." and "A problem
688 # ...", all being implicitly appended to that list. These are always
689 # expected from $gdb_spawn_id. IOW, callers do not need to worry
690 # about resetting "-i" back to $gdb_spawn_id explicitly.
692 proc gdb_test_multiple { command message user_code } {
693 global verbose use_gdb_stub
694 global gdb_prompt pagination_prompt
697 global inferior_exited_re
698 upvar timeout timeout
699 upvar expect_out expect_out
702 if { $message == "" } {
706 if [string match "*\[\r\n\]" $command] {
707 error "Invalid trailing newline in \"$message\" test"
710 if [string match "*\[\r\n\]*" $message] {
711 error "Invalid newline in \"$message\" test"
715 && [regexp -nocase {^\s*(r|run|star|start|at|att|atta|attac|attach)\M} \
717 error "gdbserver does not support $command without extended-remote"
720 # TCL/EXPECT WART ALERT
721 # Expect does something very strange when it receives a single braced
722 # argument. It splits it along word separators and performs substitutions.
723 # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
724 # evaluated as "\[ab\]". But that's not how TCL normally works; inside a
725 # double-quoted list item, "\[ab\]" is just a long way of representing
726 # "[ab]", because the backslashes will be removed by lindex.
728 # Unfortunately, there appears to be no easy way to duplicate the splitting
729 # that expect will do from within TCL. And many places make use of the
730 # "\[0-9\]" construct, so we need to support that; and some places make use
731 # of the "[func]" construct, so we need to support that too. In order to
732 # get this right we have to substitute quoted list elements differently
733 # from braced list elements.
735 # We do this roughly the same way that Expect does it. We have to use two
736 # lists, because if we leave unquoted newlines in the argument to uplevel
737 # they'll be treated as command separators, and if we escape newlines
738 # we mangle newlines inside of command blocks. This assumes that the
739 # input doesn't contain a pattern which contains actual embedded newlines
742 regsub -all {\n} ${user_code} { } subst_code
743 set subst_code [uplevel list $subst_code]
745 set processed_code ""
747 set expecting_action 0
749 foreach item $user_code subst_item $subst_code {
750 if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } {
751 lappend processed_code $item
754 if { $item == "-indices" || $item == "-re" || $item == "-ex" } {
755 lappend processed_code $item
758 if { $item == "-timeout" || $item == "-i" } {
760 lappend processed_code $item
763 if { $expecting_arg } {
765 lappend processed_code $subst_item
768 if { $expecting_action } {
769 lappend processed_code "uplevel [list $item]"
770 set expecting_action 0
771 # Cosmetic, no effect on the list.
772 append processed_code "\n"
775 set expecting_action 1
776 lappend processed_code $subst_item
777 if {$patterns != ""} {
780 append patterns "\"$subst_item\""
783 # Also purely cosmetic.
784 regsub -all {\r} $patterns {\\r} patterns
785 regsub -all {\n} $patterns {\\n} patterns
788 send_user "Sending \"$command\" to gdb\n"
789 send_user "Looking to match \"$patterns\"\n"
790 send_user "Message is \"$message\"\n"
794 set string "${command}\n"
795 if { $command != "" } {
796 set multi_line_re "\[\r\n\] *>"
797 while { "$string" != "" } {
798 set foo [string first "\n" "$string"]
799 set len [string length "$string"]
800 if { $foo < [expr $len - 1] } {
801 set str [string range "$string" 0 $foo]
802 if { [send_gdb "$str"] != "" } {
805 if { ! $suppress_flag } {
806 perror "Couldn't send $command to GDB."
811 # since we're checking if each line of the multi-line
812 # command are 'accepted' by GDB here,
813 # we need to set -notransfer expect option so that
814 # command output is not lost for pattern matching
817 -notransfer -re "$multi_line_re$" { verbose "partial: match" 3 }
818 timeout { verbose "partial: timeout" 3 }
820 set string [string range "$string" [expr $foo + 1] end]
821 set multi_line_re "$multi_line_re.*\[\r\n\] *>"
826 if { "$string" != "" } {
827 if { [send_gdb "$string"] != "" } {
830 if { ! $suppress_flag } {
831 perror "Couldn't send $command to GDB."
840 -re ".*A problem internal to GDB has been detected" {
841 fail "$message (GDB internal error)"
842 gdb_internal_error_resync
845 -re "\\*\\*\\* DOSEXIT code.*" {
846 if { $message != "" } {
849 gdb_suppress_entire_file "GDB died"
853 append code $processed_code
855 # Reset the spawn id, in case the processed code used -i.
858 -re "Ending remote debugging.*$gdb_prompt $" {
859 if ![isnative] then {
860 warning "Can`t communicate to remote target."
866 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
867 perror "Undefined command \"$command\"."
871 -re "Ambiguous command.*$gdb_prompt $" {
872 perror "\"$command\" is not a unique command name."
876 -re "$inferior_exited_re with code \[0-9\]+.*$gdb_prompt $" {
877 if ![string match "" $message] then {
878 set errmsg "$message (the program exited)"
880 set errmsg "$command (the program exited)"
885 -re "$inferior_exited_re normally.*$gdb_prompt $" {
886 if ![string match "" $message] then {
887 set errmsg "$message (the program exited)"
889 set errmsg "$command (the program exited)"
894 -re "The program is not being run.*$gdb_prompt $" {
895 if ![string match "" $message] then {
896 set errmsg "$message (the program is no longer running)"
898 set errmsg "$command (the program is no longer running)"
903 -re "\r\n$gdb_prompt $" {
904 if ![string match "" $message] then {
909 -re "$pagination_prompt" {
911 perror "Window too small."
915 -re "\\((y or n|y or \\\[n\\\]|\\\[y\\\] or n)\\) " {
917 gdb_expect -re "$gdb_prompt $"
918 fail "$message (got interactive prompt)"
921 -re "\\\[0\\\] cancel\r\n\\\[1\\\] all.*\r\n> $" {
923 gdb_expect -re "$gdb_prompt $"
924 fail "$message (got breakpoint menu)"
928 # Patterns below apply to any spawn id specified.
931 perror "Process no longer exists"
932 if { $message != "" } {
938 perror "internal buffer is full."
943 if ![string match "" $message] then {
944 fail "$message (timeout)"
951 set code [catch {gdb_expect $code} string]
953 global errorInfo errorCode
954 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
955 } elseif {$code > 1} {
956 return -code $code $string
961 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
962 # Send a command to gdb; test the result.
964 # COMMAND is the command to execute, send to GDB with send_gdb. If
965 # this is the null string no command is sent.
966 # PATTERN is the pattern to match for a PASS, and must NOT include
967 # the \r\n sequence immediately before the gdb prompt. This argument
968 # may be omitted to just match the prompt, ignoring whatever output
970 # MESSAGE is an optional message to be printed. If this is
971 # omitted, then the pass/fail messages use the command string as the
972 # message. (If this is the empty string, then sometimes we don't
973 # call pass or fail at all; I don't understand this at all.)
974 # QUESTION is a question GDB may ask in response to COMMAND, like
976 # RESPONSE is the response to send if QUESTION appears.
979 # 1 if the test failed,
980 # 0 if the test passes,
981 # -1 if there was an internal error.
983 proc gdb_test { args } {
985 upvar timeout timeout
987 if [llength $args]>2 then {
988 set message [lindex $args 2]
990 set message [lindex $args 0]
992 set command [lindex $args 0]
993 set pattern [lindex $args 1]
995 if [llength $args]==5 {
996 set question_string [lindex $args 3]
997 set response_string [lindex $args 4]
999 set question_string "^FOOBAR$"
1002 return [gdb_test_multiple $command $message {
1003 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
1004 if ![string match "" $message] then {
1008 -re "(${question_string})$" {
1009 send_gdb "$response_string\n"
1015 # gdb_test_no_output COMMAND MESSAGE
1016 # Send a command to GDB and verify that this command generated no output.
1018 # See gdb_test_multiple for a description of the COMMAND and MESSAGE
1019 # parameters. If MESSAGE is ommitted, then COMMAND will be used as
1020 # the message. (If MESSAGE is the empty string, then sometimes we do not
1021 # call pass or fail at all; I don't understand this at all.)
1023 proc gdb_test_no_output { args } {
1025 set command [lindex $args 0]
1026 if [llength $args]>1 then {
1027 set message [lindex $args 1]
1029 set message $command
1032 set command_regex [string_to_regexp $command]
1033 gdb_test_multiple $command $message {
1034 -re "^$command_regex\r\n$gdb_prompt $" {
1035 if ![string match "" $message] then {
1042 # Send a command and then wait for a sequence of outputs.
1043 # This is useful when the sequence is long and contains ".*", a single
1044 # regexp to match the entire output can get a timeout much easier.
1046 # COMMAND is the command to send.
1047 # TEST_NAME is passed to pass/fail. COMMAND is used if TEST_NAME is "".
1048 # EXPECTED_OUTPUT_LIST is a list of regexps of expected output, which are
1049 # processed in order, and all must be present in the output.
1051 # It is unnecessary to specify ".*" at the beginning or end of any regexp,
1052 # there is an implicit ".*" between each element of EXPECTED_OUTPUT_LIST.
1053 # There is also an implicit ".*" between the last regexp and the gdb prompt.
1055 # Like gdb_test and gdb_test_multiple, the output is expected to end with the
1056 # gdb prompt, which must not be specified in EXPECTED_OUTPUT_LIST.
1059 # 1 if the test failed,
1060 # 0 if the test passes,
1061 # -1 if there was an internal error.
1063 proc gdb_test_sequence { command test_name expected_output_list } {
1065 if { $test_name == "" } {
1066 set test_name $command
1068 lappend expected_output_list ""; # implicit ".*" before gdb prompt
1069 send_gdb "$command\n"
1070 return [gdb_expect_list $test_name "$gdb_prompt $" $expected_output_list]
1074 # Test that a command gives an error. For pass or fail, return
1075 # a 1 to indicate that more tests can proceed. However a timeout
1076 # is a serious error, generates a special fail message, and causes
1077 # a 0 to be returned to indicate that more tests are likely to fail
1080 proc test_print_reject { args } {
1084 if [llength $args]==2 then {
1085 set expectthis [lindex $args 1]
1087 set expectthis "should never match this bogus string"
1089 set sendthis [lindex $args 0]
1090 if $verbose>2 then {
1091 send_user "Sending \"$sendthis\" to gdb\n"
1092 send_user "Looking to match \"$expectthis\"\n"
1094 send_gdb "$sendthis\n"
1095 #FIXME: Should add timeout as parameter.
1097 -re "A .* in expression.*\\.*$gdb_prompt $" {
1098 pass "reject $sendthis"
1101 -re "Invalid syntax in expression.*$gdb_prompt $" {
1102 pass "reject $sendthis"
1105 -re "Junk after end of expression.*$gdb_prompt $" {
1106 pass "reject $sendthis"
1109 -re "Invalid number.*$gdb_prompt $" {
1110 pass "reject $sendthis"
1113 -re "Invalid character constant.*$gdb_prompt $" {
1114 pass "reject $sendthis"
1117 -re "No symbol table is loaded.*$gdb_prompt $" {
1118 pass "reject $sendthis"
1121 -re "No symbol .* in current context.*$gdb_prompt $" {
1122 pass "reject $sendthis"
1125 -re "Unmatched single quote.*$gdb_prompt $" {
1126 pass "reject $sendthis"
1129 -re "A character constant must contain at least one character.*$gdb_prompt $" {
1130 pass "reject $sendthis"
1133 -re "$expectthis.*$gdb_prompt $" {
1134 pass "reject $sendthis"
1137 -re ".*$gdb_prompt $" {
1138 fail "reject $sendthis"
1142 fail "reject $sendthis (eof or timeout)"
1149 # Same as gdb_test, but the second parameter is not a regexp,
1150 # but a string that must match exactly.
1152 proc gdb_test_exact { args } {
1153 upvar timeout timeout
1155 set command [lindex $args 0]
1157 # This applies a special meaning to a null string pattern. Without
1158 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
1159 # messages from commands that should have no output except a new
1160 # prompt. With this, only results of a null string will match a null
1163 set pattern [lindex $args 1]
1164 if [string match $pattern ""] {
1165 set pattern [string_to_regexp [lindex $args 0]]
1167 set pattern [string_to_regexp [lindex $args 1]]
1170 # It is most natural to write the pattern argument with only
1171 # embedded \n's, especially if you are trying to avoid Tcl quoting
1172 # problems. But gdb_expect really wants to see \r\n in patterns. So
1173 # transform the pattern here. First transform \r\n back to \n, in
1174 # case some users of gdb_test_exact already do the right thing.
1175 regsub -all "\r\n" $pattern "\n" pattern
1176 regsub -all "\n" $pattern "\r\n" pattern
1177 if [llength $args]==3 then {
1178 set message [lindex $args 2]
1180 set message $command
1183 return [gdb_test $command $pattern $message]
1186 # Wrapper around gdb_test_multiple that looks for a list of expected
1187 # output elements, but which can appear in any order.
1188 # CMD is the gdb command.
1189 # NAME is the name of the test.
1190 # ELM_FIND_REGEXP specifies how to partition the output into elements to
1192 # ELM_EXTRACT_REGEXP specifies the part of ELM_FIND_REGEXP to compare.
1193 # RESULT_MATCH_LIST is a list of exact matches for each expected element.
1194 # All elements of RESULT_MATCH_LIST must appear for the test to pass.
1196 # A typical use of ELM_FIND_REGEXP/ELM_EXTRACT_REGEXP is to extract one line
1197 # of text per element and then strip trailing \r\n's.
1199 # gdb_test_list_exact "foo" "bar" \
1200 # "\[^\r\n\]+\[\r\n\]+" \
1203 # {expected result 1} \
1204 # {expected result 2} \
1207 proc gdb_test_list_exact { cmd name elm_find_regexp elm_extract_regexp result_match_list } {
1210 set matches [lsort $result_match_list]
1212 gdb_test_multiple $cmd $name {
1213 "$cmd\[\r\n\]" { exp_continue }
1214 -re $elm_find_regexp {
1215 set str $expect_out(0,string)
1216 verbose -log "seen: $str" 3
1217 regexp -- $elm_extract_regexp $str elm_seen
1218 verbose -log "extracted: $elm_seen" 3
1219 lappend seen $elm_seen
1222 -re "$gdb_prompt $" {
1224 foreach got [lsort $seen] have $matches {
1225 if {![string equal $got $have]} {
1230 if {[string length $failed] != 0} {
1231 fail "$name ($failed not found)"
1239 # gdb_test_stdio COMMAND INFERIOR_PATTERN GDB_PATTERN MESSAGE
1240 # Send a command to gdb; expect inferior and gdb output.
1242 # See gdb_test_multiple for a description of the COMMAND and MESSAGE
1245 # INFERIOR_PATTERN is the pattern to match against inferior output.
1247 # GDB_PATTERN is the pattern to match against gdb output, and must NOT
1248 # include the \r\n sequence immediately before the gdb prompt, nor the
1249 # prompt. The default is empty.
1251 # Both inferior and gdb patterns must match for a PASS.
1253 # If MESSAGE is ommitted, then COMMAND will be used as the message.
1256 # 1 if the test failed,
1257 # 0 if the test passes,
1258 # -1 if there was an internal error.
1261 proc gdb_test_stdio {command inferior_pattern {gdb_pattern ""} {message ""}} {
1262 global inferior_spawn_id gdb_spawn_id
1265 if {$message == ""} {
1266 set message $command
1269 set inferior_matched 0
1272 # Use an indirect spawn id list, and remove the inferior spawn id
1273 # from the expected output as soon as it matches, in case
1274 # $inferior_pattern happens to be a prefix of the resulting full
1275 # gdb pattern below (e.g., "\r\n").
1276 global gdb_test_stdio_spawn_id_list
1277 set gdb_test_stdio_spawn_id_list "$inferior_spawn_id"
1279 # Note that if $inferior_spawn_id and $gdb_spawn_id are different,
1280 # then we may see gdb's output arriving before the inferior's
1282 set res [gdb_test_multiple $command $message {
1283 -i gdb_test_stdio_spawn_id_list -re "$inferior_pattern" {
1284 set inferior_matched 1
1285 if {!$gdb_matched} {
1286 set gdb_test_stdio_spawn_id_list ""
1290 -i $gdb_spawn_id -re "$gdb_pattern\r\n$gdb_prompt $" {
1292 if {!$inferior_matched} {
1300 verbose -log "inferior_matched=$inferior_matched, gdb_matched=$gdb_matched"
1307 # Issue a PASS and return true if evaluating CONDITION in the caller's
1308 # frame returns true, and issue a FAIL and return false otherwise.
1309 # MESSAGE is the pass/fail message to be printed. If MESSAGE is
1310 # omitted or is empty, then the pass/fail messages use the condition
1311 # string as the message.
1313 proc gdb_assert { condition {message ""} } {
1314 if { $message == ""} {
1315 set message $condition
1318 set res [uplevel 1 expr $condition]
1327 proc gdb_reinitialize_dir { subdir } {
1330 if [is_remote host] {
1335 -re "Reinitialize source path to empty.*y or n. " {
1338 -re "Source directories searched.*$gdb_prompt $" {
1339 send_gdb "dir $subdir\n"
1341 -re "Source directories searched.*$gdb_prompt $" {
1342 verbose "Dir set to $subdir"
1344 -re "$gdb_prompt $" {
1345 perror "Dir \"$subdir\" failed."
1349 -re "$gdb_prompt $" {
1350 perror "Dir \"$subdir\" failed."
1354 -re "$gdb_prompt $" {
1355 perror "Dir \"$subdir\" failed."
1361 # gdb_exit -- exit the GDB, killing the target program if necessary
1363 proc default_gdb_exit {} {
1365 global INTERNAL_GDBFLAGS GDBFLAGS
1367 global gdb_spawn_id inferior_spawn_id
1368 global inotify_log_file
1370 gdb_stop_suppressing_tests
1372 if ![info exists gdb_spawn_id] {
1376 verbose "Quitting $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1378 if {[info exists inotify_log_file] && [file exists $inotify_log_file]} {
1379 set fd [open $inotify_log_file]
1380 set data [read -nonewline $fd]
1383 if {[string compare $data ""] != 0} {
1384 warning "parallel-unsafe file creations noticed"
1387 set fd [open $inotify_log_file w]
1392 if { [is_remote host] && [board_info host exists fileid] } {
1399 -re "DOSEXIT code" { }
1404 if ![is_remote host] {
1408 unset inferior_spawn_id
1411 # Load a file into the debugger.
1412 # The return value is 0 for success, -1 for failure.
1414 # This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO
1415 # to one of these values:
1417 # debug file was loaded successfully and has debug information
1418 # nodebug file was loaded successfully and has no debug information
1419 # lzma file was loaded, .gnu_debugdata found, but no LZMA support
1421 # fail file was not loaded
1423 # I tried returning this information as part of the return value,
1424 # but ran into a mess because of the many re-implementations of
1425 # gdb_load in config/*.exp.
1427 # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use
1428 # this if they can get more information set.
1430 proc gdb_file_cmd { arg } {
1434 global last_loaded_file
1436 # Save this for the benefit of gdbserver-support.exp.
1437 set last_loaded_file $arg
1439 # Set whether debug info was found.
1440 # Default to "fail".
1441 global gdb_file_cmd_debug_info
1442 set gdb_file_cmd_debug_info "fail"
1444 if [is_remote host] {
1445 set arg [remote_download host $arg]
1447 perror "download failed"
1452 # The file command used to kill the remote target. For the benefit
1453 # of the testsuite, preserve this behavior.
1456 -re "Kill the program being debugged. .y or n. $" {
1458 verbose "\t\tKilling previous program being debugged"
1461 -re "$gdb_prompt $" {
1466 send_gdb "file $arg\n"
1468 -re "Reading symbols from.*LZMA support was disabled.*done.*$gdb_prompt $" {
1469 verbose "\t\tLoaded $arg into $GDB; .gnu_debugdata found but no LZMA available"
1470 set gdb_file_cmd_debug_info "lzma"
1473 -re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" {
1474 verbose "\t\tLoaded $arg into $GDB with no debugging symbols"
1475 set gdb_file_cmd_debug_info "nodebug"
1478 -re "Reading symbols from.*done.*$gdb_prompt $" {
1479 verbose "\t\tLoaded $arg into $GDB"
1480 set gdb_file_cmd_debug_info "debug"
1483 -re "Load new symbol table from \".*\".*y or n. $" {
1486 -re "Reading symbols from.*done.*$gdb_prompt $" {
1487 verbose "\t\tLoaded $arg with new symbol table into $GDB"
1488 set gdb_file_cmd_debug_info "debug"
1492 perror "Couldn't load $arg, other program already loaded (timeout)."
1496 perror "Couldn't load $arg, other program already loaded (eof)."
1501 -re "No such file or directory.*$gdb_prompt $" {
1502 perror "($arg) No such file or directory"
1505 -re "A problem internal to GDB has been detected" {
1506 fail "($arg) (GDB internal error)"
1507 gdb_internal_error_resync
1510 -re "$gdb_prompt $" {
1511 perror "Couldn't load $arg into $GDB."
1515 perror "Couldn't load $arg into $GDB (timeout)."
1519 # This is an attempt to detect a core dump, but seems not to
1520 # work. Perhaps we need to match .* followed by eof, in which
1521 # gdb_expect does not seem to have a way to do that.
1522 perror "Couldn't load $arg into $GDB (eof)."
1528 # Default gdb_spawn procedure.
1530 proc default_gdb_spawn { } {
1533 global INTERNAL_GDBFLAGS GDBFLAGS
1536 gdb_stop_suppressing_tests
1538 # Set the default value, it may be overriden later by specific testfile.
1540 # Use `set_board_info use_gdb_stub' for the board file to flag the inferior
1541 # is already started after connecting and run/attach are not supported.
1542 # This is used for the "remote" protocol. After GDB starts you should
1543 # check global $use_gdb_stub instead of the board as the testfile may force
1544 # a specific different target protocol itself.
1545 set use_gdb_stub [target_info exists use_gdb_stub]
1547 verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1549 if [info exists gdb_spawn_id] {
1553 if ![is_remote host] {
1554 if { [which $GDB] == 0 } then {
1555 perror "$GDB does not exist."
1559 set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"]
1560 if { $res < 0 || $res == "" } {
1561 perror "Spawning $GDB failed."
1565 set gdb_spawn_id $res
1569 # Default gdb_start procedure.
1571 proc default_gdb_start { } {
1572 global gdb_prompt pagination_prompt
1574 global inferior_spawn_id
1576 if [info exists gdb_spawn_id] {
1585 # Default to assuming inferior I/O is done on GDB's terminal.
1586 if {![info exists inferior_spawn_id]} {
1587 set inferior_spawn_id $gdb_spawn_id
1590 # When running over NFS, particularly if running many simultaneous
1591 # tests on different hosts all using the same server, things can
1592 # get really slow. Give gdb at least 3 minutes to start up.
1594 while { $loop_again } {
1597 -re "$pagination_prompt" {
1598 verbose "Hit pagination during startup. Pressing enter to continue."
1602 -re "\[\r\n\]$gdb_prompt $" {
1603 verbose "GDB initialized."
1605 -re "$gdb_prompt $" {
1606 perror "GDB never initialized."
1611 perror "(timeout) GDB never initialized after 10 seconds."
1619 # force the height to "unlimited", so no pagers get used
1621 send_gdb "set height 0\n"
1623 -re "$gdb_prompt $" {
1624 verbose "Setting height to 0." 2
1627 warning "Couldn't set the height to 0"
1630 # force the width to "unlimited", so no wraparound occurs
1631 send_gdb "set width 0\n"
1633 -re "$gdb_prompt $" {
1634 verbose "Setting width to 0." 2
1637 warning "Couldn't set the width to 0."
1643 # Utility procedure to give user control of the gdb prompt in a script. It is
1644 # meant to be used for debugging test cases, and should not be left in the
1647 proc gdb_interact { } {
1649 set spawn_id $gdb_spawn_id
1651 send_user "+------------------------------------------+\n"
1652 send_user "| Script interrupted, you can now interact |\n"
1653 send_user "| with by gdb. Type >>> to continue. |\n"
1654 send_user "+------------------------------------------+\n"
1661 # Examine the output of compilation to determine whether compilation
1662 # failed or not. If it failed determine whether it is due to missing
1663 # compiler or due to compiler error. Report pass, fail or unsupported
1666 proc gdb_compile_test {src output} {
1667 if { $output == "" } {
1668 pass "compilation [file tail $src]"
1669 } elseif { [regexp {^[a-zA-Z_0-9]+: Can't find [^ ]+\.$} $output] } {
1670 unsupported "compilation [file tail $src]"
1671 } elseif { [regexp {.*: command not found[\r|\n]*$} $output] } {
1672 unsupported "compilation [file tail $src]"
1673 } elseif { [regexp {.*: [^\r\n]*compiler not installed[^\r\n]*[\r|\n]*$} $output] } {
1674 unsupported "compilation [file tail $src]"
1676 verbose -log "compilation failed: $output" 2
1677 fail "compilation [file tail $src]"
1681 # Return a 1 for configurations for which we don't even want to try to
1684 proc skip_cplus_tests {} {
1685 if { [istarget "h8300-*-*"] } {
1689 # The C++ IO streams are too large for HC11/HC12 and are thus not
1690 # available. The gdb C++ tests use them and don't compile.
1691 if { [istarget "m6811-*-*"] } {
1694 if { [istarget "m6812-*-*"] } {
1700 # Return a 1 for configurations for which don't have both C++ and the STL.
1702 proc skip_stl_tests {} {
1703 # Symbian supports the C++ language, but the STL is missing
1704 # (both headers and libraries).
1705 if { [istarget "arm*-*-symbianelf*"] } {
1709 return [skip_cplus_tests]
1712 # Return a 1 if I don't even want to try to test FORTRAN.
1714 proc skip_fortran_tests {} {
1718 # Return a 1 if I don't even want to try to test ada.
1720 proc skip_ada_tests {} {
1724 # Return a 1 if I don't even want to try to test GO.
1726 proc skip_go_tests {} {
1730 # Return a 1 if I don't even want to try to test D.
1732 proc skip_d_tests {} {
1736 # Return 1 to skip Rust tests, 0 to try them.
1737 proc skip_rust_tests {} {
1738 return [expr {![isnative]}]
1741 # Return a 1 for configurations that do not support Python scripting.
1742 # PROMPT_REGEXP is the expected prompt.
1744 proc skip_python_tests_prompt { prompt_regexp } {
1745 global gdb_py_is_py3k
1746 global gdb_py_is_py24
1748 gdb_test_multiple "python print ('test')" "verify python support" {
1749 -re "not supported.*$prompt_regexp" {
1750 unsupported "Python support is disabled."
1753 -re "$prompt_regexp" {}
1756 set gdb_py_is_py24 0
1757 gdb_test_multiple "python print (sys.version_info\[0\])" "check if python 3" {
1758 -re "3.*$prompt_regexp" {
1759 set gdb_py_is_py3k 1
1761 -re ".*$prompt_regexp" {
1762 set gdb_py_is_py3k 0
1765 if { $gdb_py_is_py3k == 0 } {
1766 gdb_test_multiple "python print (sys.version_info\[1\])" "check if python 2.4" {
1767 -re "\[45\].*$prompt_regexp" {
1768 set gdb_py_is_py24 1
1770 -re ".*$prompt_regexp" {
1771 set gdb_py_is_py24 0
1779 # Return a 1 for configurations that do not support Python scripting.
1780 # Note: This also sets various globals that specify which version of Python
1781 # is in use. See skip_python_tests_prompt.
1783 proc skip_python_tests {} {
1785 return [skip_python_tests_prompt "$gdb_prompt $"]
1788 # Return a 1 if we should skip shared library tests.
1790 proc skip_shlib_tests {} {
1791 # Run the shared library tests on native systems.
1796 # An abbreviated list of remote targets where we should be able to
1797 # run shared library tests.
1798 if {([istarget *-*-linux*]
1799 || [istarget *-*-*bsd*]
1800 || [istarget *-*-solaris2*]
1801 || [istarget arm*-*-symbianelf*]
1802 || [istarget *-*-mingw*]
1803 || [istarget *-*-cygwin*]
1804 || [istarget *-*-pe*])} {
1811 # Return 1 if we should skip tui related tests.
1813 proc skip_tui_tests {} {
1816 gdb_test_multiple "help layout" "verify tui support" {
1817 -re "Undefined command: \"layout\".*$gdb_prompt $" {
1820 -re "$gdb_prompt $" {
1827 # Test files shall make sure all the test result lines in gdb.sum are
1828 # unique in a test run, so that comparing the gdb.sum files of two
1829 # test runs gives correct results. Test files that exercise
1830 # variations of the same tests more than once, shall prefix the
1831 # different test invocations with different identifying strings in
1832 # order to make them unique.
1834 # About test prefixes:
1836 # $pf_prefix is the string that dejagnu prints after the result (FAIL,
1837 # PASS, etc.), and before the test message/name in gdb.sum. E.g., the
1838 # underlined substring in
1840 # PASS: gdb.base/mytest.exp: some test
1841 # ^^^^^^^^^^^^^^^^^^^^
1845 # The easiest way to adjust the test prefix is to append a test
1846 # variation prefix to the $pf_prefix, using the with_test_prefix
1849 # proc do_tests {} {
1850 # gdb_test ... ... "test foo"
1851 # gdb_test ... ... "test bar"
1853 # with_test_prefix "subvariation a" {
1854 # gdb_test ... ... "test x"
1857 # with_test_prefix "subvariation b" {
1858 # gdb_test ... ... "test x"
1862 # with_test_prefix "variation1" {
1863 # ...do setup for variation 1...
1867 # with_test_prefix "variation2" {
1868 # ...do setup for variation 2...
1874 # PASS: gdb.base/mytest.exp: variation1: test foo
1875 # PASS: gdb.base/mytest.exp: variation1: test bar
1876 # PASS: gdb.base/mytest.exp: variation1: subvariation a: test x
1877 # PASS: gdb.base/mytest.exp: variation1: subvariation b: test x
1878 # PASS: gdb.base/mytest.exp: variation2: test foo
1879 # PASS: gdb.base/mytest.exp: variation2: test bar
1880 # PASS: gdb.base/mytest.exp: variation2: subvariation a: test x
1881 # PASS: gdb.base/mytest.exp: variation2: subvariation b: test x
1883 # If for some reason more flexibility is necessary, one can also
1884 # manipulate the pf_prefix global directly, treating it as a string.
1888 # set saved_pf_prefix
1889 # append pf_prefix "${foo}: bar"
1890 # ... actual tests ...
1891 # set pf_prefix $saved_pf_prefix
1894 # Run BODY in the context of the caller, with the current test prefix
1895 # (pf_prefix) appended with one space, then PREFIX, and then a colon.
1896 # Returns the result of BODY.
1898 proc with_test_prefix { prefix body } {
1901 set saved $pf_prefix
1902 append pf_prefix " " $prefix ":"
1903 set code [catch {uplevel 1 $body} result]
1904 set pf_prefix $saved
1907 global errorInfo errorCode
1908 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
1910 return -code $code $result
1914 # Wrapper for foreach that calls with_test_prefix on each iteration,
1915 # including the iterator's name and current value in the prefix.
1917 proc foreach_with_prefix {var list body} {
1919 foreach myvar $list {
1920 with_test_prefix "$var=$myvar" {
1926 # Like TCL's native proc, but defines a procedure that wraps its body
1927 # within 'with_test_prefix "$proc_name" { ... }'.
1928 proc proc_with_prefix {name arguments body} {
1929 # Define the advertised proc.
1930 proc $name $arguments [list with_test_prefix $name $body]
1934 # Run BODY in the context of the caller. After BODY is run, the variables
1935 # listed in VARS will be reset to the values they had before BODY was run.
1937 # This is useful for providing a scope in which it is safe to temporarily
1938 # modify global variables, e.g.
1940 # global INTERNAL_GDBFLAGS
1943 # set foo GDBHISTSIZE
1945 # save_vars { INTERNAL_GDBFLAGS env($foo) env(HOME) } {
1946 # append INTERNAL_GDBFLAGS " -nx"
1947 # unset -nocomplain env(GDBHISTSIZE)
1952 # Here, although INTERNAL_GDBFLAGS, env(GDBHISTSIZE) and env(HOME) may be
1953 # modified inside BODY, this proc guarantees that the modifications will be
1954 # undone after BODY finishes executing.
1956 proc save_vars { vars body } {
1957 array set saved_scalars { }
1958 array set saved_arrays { }
1962 # First evaluate VAR in the context of the caller in case the variable
1963 # name may be a not-yet-interpolated string like env($foo)
1964 set var [uplevel 1 list $var]
1966 if [uplevel 1 [list info exists $var]] {
1967 if [uplevel 1 [list array exists $var]] {
1968 set saved_arrays($var) [uplevel 1 [list array get $var]]
1970 set saved_scalars($var) [uplevel 1 [list set $var]]
1973 lappend unset_vars $var
1977 set code [catch {uplevel 1 $body} result]
1979 foreach {var value} [array get saved_scalars] {
1980 uplevel 1 [list set $var $value]
1983 foreach {var value} [array get saved_arrays] {
1984 uplevel 1 [list unset $var]
1985 uplevel 1 [list array set $var $value]
1988 foreach var $unset_vars {
1989 uplevel 1 [list unset -nocomplain $var]
1993 global errorInfo errorCode
1994 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
1996 return -code $code $result
2001 # Run tests in BODY with GDB prompt and variable $gdb_prompt set to
2002 # PROMPT. When BODY is finished, restore GDB prompt and variable
2004 # Returns the result of BODY.
2008 # 1) If you want to use, for example, "(foo)" as the prompt you must pass it
2009 # as "(foo)", and not the regexp form "\(foo\)" (expressed as "\\(foo\\)" in
2010 # TCL). PROMPT is internally converted to a suitable regexp for matching.
2011 # We do the conversion from "(foo)" to "\(foo\)" here for a few reasons:
2012 # a) It's more intuitive for callers to pass the plain text form.
2013 # b) We need two forms of the prompt:
2014 # - a regexp to use in output matching,
2015 # - a value to pass to the "set prompt" command.
2016 # c) It's easier to convert the plain text form to its regexp form.
2018 # 2) Don't add a trailing space, we do that here.
2020 proc with_gdb_prompt { prompt body } {
2023 # Convert "(foo)" to "\(foo\)".
2024 # We don't use string_to_regexp because while it works today it's not
2025 # clear it will work tomorrow: the value we need must work as both a
2026 # regexp *and* as the argument to the "set prompt" command, at least until
2027 # we start recording both forms separately instead of just $gdb_prompt.
2028 # The testsuite is pretty-much hardwired to interpret $gdb_prompt as the
2030 regsub -all {[]*+.|()^$\[\\]} $prompt {\\&} prompt
2032 set saved $gdb_prompt
2034 verbose -log "Setting gdb prompt to \"$prompt \"."
2035 set gdb_prompt $prompt
2036 gdb_test_no_output "set prompt $prompt " ""
2038 set code [catch {uplevel 1 $body} result]
2040 verbose -log "Restoring gdb prompt to \"$saved \"."
2041 set gdb_prompt $saved
2042 gdb_test_no_output "set prompt $saved " ""
2045 global errorInfo errorCode
2046 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2048 return -code $code $result
2052 # Run tests in BODY with target-charset setting to TARGET_CHARSET. When
2053 # BODY is finished, restore target-charset.
2055 proc with_target_charset { target_charset body } {
2059 gdb_test_multiple "show target-charset" "" {
2060 -re "The target character set is \".*; currently (.*)\"\..*$gdb_prompt " {
2061 set saved $expect_out(1,string)
2063 -re "The target character set is \"(.*)\".*$gdb_prompt " {
2064 set saved $expect_out(1,string)
2066 -re ".*$gdb_prompt " {
2067 fail "get target-charset"
2071 gdb_test_no_output "set target-charset $target_charset" ""
2073 set code [catch {uplevel 1 $body} result]
2075 gdb_test_no_output "set target-charset $saved" ""
2078 global errorInfo errorCode
2079 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2081 return -code $code $result
2085 # Switch the default spawn id to SPAWN_ID, so that gdb_test,
2086 # mi_gdb_test etc. default to using it.
2088 proc switch_gdb_spawn_id {spawn_id} {
2090 global board board_info
2092 set gdb_spawn_id $spawn_id
2093 set board [host_info name]
2094 set board_info($board,fileid) $spawn_id
2097 # Clear the default spawn id.
2099 proc clear_gdb_spawn_id {} {
2101 global board board_info
2103 unset -nocomplain gdb_spawn_id
2104 set board [host_info name]
2105 unset -nocomplain board_info($board,fileid)
2108 # Run BODY with SPAWN_ID as current spawn id.
2110 proc with_spawn_id { spawn_id body } {
2113 if [info exists gdb_spawn_id] {
2114 set saved_spawn_id $gdb_spawn_id
2117 switch_gdb_spawn_id $spawn_id
2119 set code [catch {uplevel 1 $body} result]
2121 if [info exists saved_spawn_id] {
2122 switch_gdb_spawn_id $saved_spawn_id
2128 global errorInfo errorCode
2129 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2131 return -code $code $result
2135 # Select the largest timeout from all the timeouts:
2136 # - the local "timeout" variable of the scope two levels above,
2137 # - the global "timeout" variable,
2138 # - the board variable "gdb,timeout".
2140 proc get_largest_timeout {} {
2141 upvar #0 timeout gtimeout
2142 upvar 2 timeout timeout
2145 if [info exists timeout] {
2148 if { [info exists gtimeout] && $gtimeout > $tmt } {
2151 if { [target_info exists gdb,timeout]
2152 && [target_info gdb,timeout] > $tmt } {
2153 set tmt [target_info gdb,timeout]
2163 # Run tests in BODY with timeout increased by factor of FACTOR. When
2164 # BODY is finished, restore timeout.
2166 proc with_timeout_factor { factor body } {
2169 set savedtimeout $timeout
2171 set timeout [expr [get_largest_timeout] * $factor]
2172 set code [catch {uplevel 1 $body} result]
2174 set timeout $savedtimeout
2176 global errorInfo errorCode
2177 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2179 return -code $code $result
2183 # Return 1 if _Complex types are supported, otherwise, return 0.
2185 gdb_caching_proc support_complex_tests {
2187 if { [gdb_skip_float_test] } {
2188 # If floating point is not supported, _Complex is not
2193 # Set up, compile, and execute a test program containing _Complex types.
2194 # Include the current process ID in the file names to prevent conflicts
2195 # with invocations for multiple testsuites.
2196 set src [standard_temp_file complex[pid].c]
2197 set exe [standard_temp_file complex[pid].x]
2199 gdb_produce_source $src {
2203 _Complex long double cld;
2208 verbose "compiling testfile $src" 2
2209 set compile_flags {debug nowarnings quiet}
2210 set lines [gdb_compile $src $exe executable $compile_flags]
2214 if ![string match "" $lines] then {
2215 verbose "testfile compilation failed, returning 0" 2
2224 # Return 1 if GDB can get a type for siginfo from the target, otherwise
2227 proc supports_get_siginfo_type {} {
2228 if { [istarget "*-*-linux*"] } {
2235 # Return 1 if the target supports hardware single stepping.
2237 proc can_hardware_single_step {} {
2239 if { [istarget "arm*-*-*"] || [istarget "mips*-*-*"]
2240 || [istarget "tic6x-*-*"] || [istarget "sparc*-*-linux*"]
2241 || [istarget "nios2-*-*"] } {
2248 # Return 1 if target hardware or OS supports single stepping to signal
2249 # handler, otherwise, return 0.
2251 proc can_single_step_to_signal_handler {} {
2252 # Targets don't have hardware single step. On these targets, when
2253 # a signal is delivered during software single step, gdb is unable
2254 # to determine the next instruction addresses, because start of signal
2255 # handler is one of them.
2256 return [can_hardware_single_step]
2259 # Return 1 if target supports process record, otherwise return 0.
2261 proc supports_process_record {} {
2263 if [target_info exists gdb,use_precord] {
2264 return [target_info gdb,use_precord]
2267 if { [istarget "arm*-*-linux*"] || [istarget "x86_64-*-linux*"]
2268 || [istarget "i\[34567\]86-*-linux*"]
2269 || [istarget "aarch64*-*-linux*"]
2270 || [istarget "powerpc*-*-linux*"]
2271 || [istarget "s390*-*-linux*"] } {
2278 # Return 1 if target supports reverse debugging, otherwise return 0.
2280 proc supports_reverse {} {
2282 if [target_info exists gdb,can_reverse] {
2283 return [target_info gdb,can_reverse]
2286 if { [istarget "arm*-*-linux*"] || [istarget "x86_64-*-linux*"]
2287 || [istarget "i\[34567\]86-*-linux*"]
2288 || [istarget "aarch64*-*-linux*"]
2289 || [istarget "powerpc*-*-linux*"]
2290 || [istarget "s390*-*-linux*"] } {
2297 # Return 1 if readline library is used.
2299 proc readline_is_used { } {
2302 gdb_test_multiple "show editing" "" {
2303 -re ".*Editing of command lines as they are typed is on\..*$gdb_prompt $" {
2306 -re ".*$gdb_prompt $" {
2312 # Return 1 if target is ELF.
2313 gdb_caching_proc is_elf_target {
2314 set me "is_elf_target"
2316 set src [standard_temp_file is_elf_target[pid].c]
2317 set obj [standard_temp_file is_elf_target[pid].o]
2319 gdb_produce_source $src {
2320 int foo () {return 0;}
2323 verbose "$me: compiling testfile $src" 2
2324 set lines [gdb_compile $src $obj object {quiet}]
2328 if ![string match "" $lines] then {
2329 verbose "$me: testfile compilation failed, returning 0" 2
2333 set fp_obj [open $obj "r"]
2334 fconfigure $fp_obj -translation binary
2335 set data [read $fp_obj]
2340 set ELFMAG "\u007FELF"
2342 if {[string compare -length 4 $data $ELFMAG] != 0} {
2343 verbose "$me: returning 0" 2
2347 verbose "$me: returning 1" 2
2351 # Return 1 if the memory at address zero is readable.
2353 gdb_caching_proc is_address_zero_readable {
2357 gdb_test_multiple "x 0" "" {
2358 -re "Cannot access memory at address 0x0.*$gdb_prompt $" {
2361 -re ".*$gdb_prompt $" {
2369 # Produce source file NAME and write SOURCES into it.
2371 proc gdb_produce_source { name sources } {
2373 set f [open $name "w"]
2379 # Return 1 if target is ILP32.
2380 # This cannot be decided simply from looking at the target string,
2381 # as it might depend on externally passed compiler options like -m64.
2382 gdb_caching_proc is_ilp32_target {
2383 set me "is_ilp32_target"
2385 set src [standard_temp_file ilp32[pid].c]
2386 set obj [standard_temp_file ilp32[pid].o]
2388 gdb_produce_source $src {
2389 int dummy[sizeof (int) == 4
2390 && sizeof (void *) == 4
2391 && sizeof (long) == 4 ? 1 : -1];
2394 verbose "$me: compiling testfile $src" 2
2395 set lines [gdb_compile $src $obj object {quiet}]
2399 if ![string match "" $lines] then {
2400 verbose "$me: testfile compilation failed, returning 0" 2
2404 verbose "$me: returning 1" 2
2408 # Return 1 if target is LP64.
2409 # This cannot be decided simply from looking at the target string,
2410 # as it might depend on externally passed compiler options like -m64.
2411 gdb_caching_proc is_lp64_target {
2412 set me "is_lp64_target"
2414 set src [standard_temp_file lp64[pid].c]
2415 set obj [standard_temp_file lp64[pid].o]
2417 gdb_produce_source $src {
2418 int dummy[sizeof (int) == 4
2419 && sizeof (void *) == 8
2420 && sizeof (long) == 8 ? 1 : -1];
2423 verbose "$me: compiling testfile $src" 2
2424 set lines [gdb_compile $src $obj object {quiet}]
2428 if ![string match "" $lines] then {
2429 verbose "$me: testfile compilation failed, returning 0" 2
2433 verbose "$me: returning 1" 2
2437 # Return 1 if target has 64 bit addresses.
2438 # This cannot be decided simply from looking at the target string,
2439 # as it might depend on externally passed compiler options like -m64.
2440 gdb_caching_proc is_64_target {
2441 set me "is_64_target"
2443 set src [standard_temp_file is64[pid].c]
2444 set obj [standard_temp_file is64[pid].o]
2446 gdb_produce_source $src {
2447 int function(void) { return 3; }
2448 int dummy[sizeof (&function) == 8 ? 1 : -1];
2451 verbose "$me: compiling testfile $src" 2
2452 set lines [gdb_compile $src $obj object {quiet}]
2456 if ![string match "" $lines] then {
2457 verbose "$me: testfile compilation failed, returning 0" 2
2461 verbose "$me: returning 1" 2
2465 # Return 1 if target has x86_64 registers - either amd64 or x32.
2466 # x32 target identifies as x86_64-*-linux*, therefore it cannot be determined
2467 # just from the target string.
2468 gdb_caching_proc is_amd64_regs_target {
2469 if {![istarget "x86_64-*-*"] && ![istarget "i?86-*"]} {
2473 set me "is_amd64_regs_target"
2475 set src [standard_temp_file reg64[pid].s]
2476 set obj [standard_temp_file reg64[pid].o]
2480 {rax rbx rcx rdx rsi rdi rbp rsp r8 r9 r10 r11 r12 r13 r14 r15} {
2481 lappend list "\tincq %$reg"
2483 gdb_produce_source $src [join $list \n]
2485 verbose "$me: compiling testfile $src" 2
2486 set lines [gdb_compile $src $obj object {quiet}]
2490 if ![string match "" $lines] then {
2491 verbose "$me: testfile compilation failed, returning 0" 2
2495 verbose "$me: returning 1" 2
2499 # Return 1 if this target is an x86 or x86-64 with -m32.
2500 proc is_x86_like_target {} {
2501 if {![istarget "x86_64-*-*"] && ![istarget i?86-*]} {
2504 return [expr [is_ilp32_target] && ![is_amd64_regs_target]]
2507 # Return 1 if this target is an arm or aarch32 on aarch64.
2509 gdb_caching_proc is_aarch32_target {
2510 if { [istarget "arm*-*-*"] } {
2514 if { ![istarget "aarch64*-*-*"] } {
2518 set me "is_aarch32_target"
2520 set src [standard_temp_file aarch32[pid].s]
2521 set obj [standard_temp_file aarch32[pid].o]
2526 lappend list "\tmov $reg, $reg"
2528 gdb_produce_source $src [join $list \n]
2530 verbose "$me: compiling testfile $src" 2
2531 set lines [gdb_compile $src $obj object {quiet}]
2535 if ![string match "" $lines] then {
2536 verbose "$me: testfile compilation failed, returning 0" 2
2540 verbose "$me: returning 1" 2
2544 # Return 1 if this target is an aarch64, either lp64 or ilp32.
2546 proc is_aarch64_target {} {
2547 if { ![istarget "aarch64*-*-*"] } {
2551 return [expr ![is_aarch32_target]]
2554 # Return 1 if displaced stepping is supported on target, otherwise, return 0.
2555 proc support_displaced_stepping {} {
2557 if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"]
2558 || [istarget "arm*-*-linux*"] || [istarget "powerpc-*-linux*"]
2559 || [istarget "powerpc64-*-linux*"] || [istarget "s390*-*-*"]
2560 || [istarget "aarch64*-*-linux*"] } {
2567 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
2568 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
2570 gdb_caching_proc skip_altivec_tests {
2571 global srcdir subdir gdb_prompt inferior_exited_re
2573 set me "skip_altivec_tests"
2575 # Some simulators are known to not support VMX instructions.
2576 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
2577 verbose "$me: target known to not support VMX, returning 1" 2
2581 # Make sure we have a compiler that understands altivec.
2582 set compile_flags {debug nowarnings}
2583 if [get_compiler_info] {
2584 warning "Could not get compiler info"
2587 if [test_compiler_info gcc*] {
2588 set compile_flags "$compile_flags additional_flags=-maltivec"
2589 } elseif [test_compiler_info xlc*] {
2590 set compile_flags "$compile_flags additional_flags=-qaltivec"
2592 verbose "Could not compile with altivec support, returning 1" 2
2596 # Set up, compile, and execute a test program containing VMX instructions.
2597 # Include the current process ID in the file names to prevent conflicts
2598 # with invocations for multiple testsuites.
2599 set src [standard_temp_file vmx[pid].c]
2600 set exe [standard_temp_file vmx[pid].x]
2602 gdb_produce_source $src {
2605 asm volatile ("vor v0,v0,v0");
2607 asm volatile ("vor 0,0,0");
2613 verbose "$me: compiling testfile $src" 2
2614 set lines [gdb_compile $src $exe executable $compile_flags]
2617 if ![string match "" $lines] then {
2618 verbose "$me: testfile compilation failed, returning 1" 2
2622 # No error message, compilation succeeded so now run it via gdb.
2626 gdb_reinitialize_dir $srcdir/$subdir
2630 -re ".*Illegal instruction.*${gdb_prompt} $" {
2631 verbose -log "\n$me altivec hardware not detected"
2632 set skip_vmx_tests 1
2634 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
2635 verbose -log "\n$me: altivec hardware detected"
2636 set skip_vmx_tests 0
2639 warning "\n$me: default case taken"
2640 set skip_vmx_tests 1
2644 remote_file build delete $exe
2646 verbose "$me: returning $skip_vmx_tests" 2
2647 return $skip_vmx_tests
2650 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
2651 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
2653 gdb_caching_proc skip_vsx_tests {
2654 global srcdir subdir gdb_prompt inferior_exited_re
2656 set me "skip_vsx_tests"
2658 # Some simulators are known to not support Altivec instructions, so
2659 # they won't support VSX instructions as well.
2660 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
2661 verbose "$me: target known to not support VSX, returning 1" 2
2665 # Make sure we have a compiler that understands altivec.
2666 set compile_flags {debug nowarnings quiet}
2667 if [get_compiler_info] {
2668 warning "Could not get compiler info"
2671 if [test_compiler_info gcc*] {
2672 set compile_flags "$compile_flags additional_flags=-mvsx"
2673 } elseif [test_compiler_info xlc*] {
2674 set compile_flags "$compile_flags additional_flags=-qasm=gcc"
2676 verbose "Could not compile with vsx support, returning 1" 2
2680 set src [standard_temp_file vsx[pid].c]
2681 set exe [standard_temp_file vsx[pid].x]
2683 gdb_produce_source $src {
2685 double a[2] = { 1.0, 2.0 };
2687 asm volatile ("lxvd2x v0,v0,%[addr]" : : [addr] "r" (a));
2689 asm volatile ("lxvd2x 0,0,%[addr]" : : [addr] "r" (a));
2695 verbose "$me: compiling testfile $src" 2
2696 set lines [gdb_compile $src $exe executable $compile_flags]
2699 if ![string match "" $lines] then {
2700 verbose "$me: testfile compilation failed, returning 1" 2
2704 # No error message, compilation succeeded so now run it via gdb.
2708 gdb_reinitialize_dir $srcdir/$subdir
2712 -re ".*Illegal instruction.*${gdb_prompt} $" {
2713 verbose -log "\n$me VSX hardware not detected"
2714 set skip_vsx_tests 1
2716 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
2717 verbose -log "\n$me: VSX hardware detected"
2718 set skip_vsx_tests 0
2721 warning "\n$me: default case taken"
2722 set skip_vsx_tests 1
2726 remote_file build delete $exe
2728 verbose "$me: returning $skip_vsx_tests" 2
2729 return $skip_vsx_tests
2732 # Run a test on the target to see if it supports TSX hardware. Return 0 if so,
2733 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
2735 gdb_caching_proc skip_tsx_tests {
2736 global srcdir subdir gdb_prompt inferior_exited_re
2738 set me "skip_tsx_tests"
2740 set src [standard_temp_file tsx[pid].c]
2741 set exe [standard_temp_file tsx[pid].x]
2743 gdb_produce_source $src {
2745 asm volatile ("xbegin .L0");
2746 asm volatile ("xend");
2747 asm volatile (".L0: nop");
2752 verbose "$me: compiling testfile $src" 2
2753 set lines [gdb_compile $src $exe executable {nowarnings quiet}]
2756 if ![string match "" $lines] then {
2757 verbose "$me: testfile compilation failed." 2
2761 # No error message, compilation succeeded so now run it via gdb.
2765 gdb_reinitialize_dir $srcdir/$subdir
2769 -re ".*Illegal instruction.*${gdb_prompt} $" {
2770 verbose -log "$me: TSX hardware not detected."
2771 set skip_tsx_tests 1
2773 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
2774 verbose -log "$me: TSX hardware detected."
2775 set skip_tsx_tests 0
2778 warning "\n$me: default case taken."
2779 set skip_tsx_tests 1
2783 remote_file build delete $exe
2785 verbose "$me: returning $skip_tsx_tests" 2
2786 return $skip_tsx_tests
2789 # Run a test on the target to see if it supports btrace hardware. Return 0 if so,
2790 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
2792 gdb_caching_proc skip_btrace_tests {
2793 global srcdir subdir gdb_prompt inferior_exited_re
2795 set me "skip_btrace_tests"
2796 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
2797 verbose "$me: target does not support btrace, returning 1" 2
2801 # Set up, compile, and execute a test program.
2802 # Include the current process ID in the file names to prevent conflicts
2803 # with invocations for multiple testsuites.
2804 set src [standard_temp_file btrace[pid].c]
2805 set exe [standard_temp_file btrace[pid].x]
2807 gdb_produce_source $src {
2808 int main(void) { return 0; }
2811 verbose "$me: compiling testfile $src" 2
2812 set compile_flags {debug nowarnings quiet}
2813 set lines [gdb_compile $src $exe executable $compile_flags]
2815 if ![string match "" $lines] then {
2816 verbose "$me: testfile compilation failed, returning 1" 2
2821 # No error message, compilation succeeded so now run it via gdb.
2825 gdb_reinitialize_dir $srcdir/$subdir
2832 # In case of an unexpected output, we return 2 as a fail value.
2833 set skip_btrace_tests 2
2834 gdb_test_multiple "record btrace" "check btrace support" {
2835 -re "You can't do that when your target is.*\r\n$gdb_prompt $" {
2836 set skip_btrace_tests 1
2838 -re "Target does not support branch tracing.*\r\n$gdb_prompt $" {
2839 set skip_btrace_tests 1
2841 -re "Could not enable branch tracing.*\r\n$gdb_prompt $" {
2842 set skip_btrace_tests 1
2844 -re "^record btrace\r\n$gdb_prompt $" {
2845 set skip_btrace_tests 0
2849 remote_file build delete $exe
2851 verbose "$me: returning $skip_btrace_tests" 2
2852 return $skip_btrace_tests
2855 # Run a test on the target to see if it supports btrace pt hardware.
2856 # Return 0 if so, 1 if it does not. Based on 'check_vmx_hw_available'
2857 # from the GCC testsuite.
2859 gdb_caching_proc skip_btrace_pt_tests {
2860 global srcdir subdir gdb_prompt inferior_exited_re
2862 set me "skip_btrace_tests"
2863 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
2864 verbose "$me: target does not support btrace, returning 1" 2
2868 # Set up, compile, and execute a test program.
2869 # Include the current process ID in the file names to prevent conflicts
2870 # with invocations for multiple testsuites.
2871 set src [standard_temp_file btrace[pid].c]
2872 set exe [standard_temp_file btrace[pid].x]
2874 gdb_produce_source $src {
2875 int main(void) { return 0; }
2878 verbose "$me: compiling testfile $src" 2
2879 set compile_flags {debug nowarnings quiet}
2880 set lines [gdb_compile $src $exe executable $compile_flags]
2882 if ![string match "" $lines] then {
2883 verbose "$me: testfile compilation failed, returning 1" 2
2888 # No error message, compilation succeeded so now run it via gdb.
2892 gdb_reinitialize_dir $srcdir/$subdir
2899 # In case of an unexpected output, we return 2 as a fail value.
2900 set skip_btrace_tests 2
2901 gdb_test_multiple "record btrace pt" "check btrace support" {
2902 -re "You can't do that when your target is.*\r\n$gdb_prompt $" {
2903 set skip_btrace_tests 1
2905 -re "Target does not support branch tracing.*\r\n$gdb_prompt $" {
2906 set skip_btrace_tests 1
2908 -re "Could not enable branch tracing.*\r\n$gdb_prompt $" {
2909 set skip_btrace_tests 1
2911 -re "GDB does not support.*\r\n$gdb_prompt $" {
2912 set skip_btrace_tests 1
2914 -re "^record btrace pt\r\n$gdb_prompt $" {
2915 set skip_btrace_tests 0
2919 remote_file build delete $exe
2921 verbose "$me: returning $skip_btrace_tests" 2
2922 return $skip_btrace_tests
2925 # Return whether we should skip tests for showing inlined functions in
2926 # backtraces. Requires get_compiler_info and get_debug_format.
2928 proc skip_inline_frame_tests {} {
2929 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
2930 if { ! [test_debug_format "DWARF 2"] } {
2934 # GCC before 4.1 does not emit DW_AT_call_file / DW_AT_call_line.
2935 if { ([test_compiler_info "gcc-2-*"]
2936 || [test_compiler_info "gcc-3-*"]
2937 || [test_compiler_info "gcc-4-0-*"]) } {
2944 # Return whether we should skip tests for showing variables from
2945 # inlined functions. Requires get_compiler_info and get_debug_format.
2947 proc skip_inline_var_tests {} {
2948 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
2949 if { ! [test_debug_format "DWARF 2"] } {
2956 # Return a 1 if we should skip tests that require hardware breakpoints
2958 proc skip_hw_breakpoint_tests {} {
2959 # Skip tests if requested by the board (note that no_hardware_watchpoints
2960 # disables both watchpoints and breakpoints)
2961 if { [target_info exists gdb,no_hardware_watchpoints]} {
2965 # These targets support hardware breakpoints natively
2966 if { [istarget "i?86-*-*"]
2967 || [istarget "x86_64-*-*"]
2968 || [istarget "ia64-*-*"]
2969 || [istarget "arm*-*-*"]
2970 || [istarget "aarch64*-*-*"]
2971 || [istarget "s390*-*-*"] } {
2978 # Return a 1 if we should skip tests that require hardware watchpoints
2980 proc skip_hw_watchpoint_tests {} {
2981 # Skip tests if requested by the board
2982 if { [target_info exists gdb,no_hardware_watchpoints]} {
2986 # These targets support hardware watchpoints natively
2987 if { [istarget "i?86-*-*"]
2988 || [istarget "x86_64-*-*"]
2989 || [istarget "ia64-*-*"]
2990 || [istarget "arm*-*-*"]
2991 || [istarget "aarch64*-*-*"]
2992 || [istarget "powerpc*-*-linux*"]
2993 || [istarget "s390*-*-*"] } {
3000 # Return a 1 if we should skip tests that require *multiple* hardware
3001 # watchpoints to be active at the same time
3003 proc skip_hw_watchpoint_multi_tests {} {
3004 if { [skip_hw_watchpoint_tests] } {
3008 # These targets support just a single hardware watchpoint
3009 if { [istarget "arm*-*-*"]
3010 || [istarget "powerpc*-*-linux*"] } {
3017 # Return a 1 if we should skip tests that require read/access watchpoints
3019 proc skip_hw_watchpoint_access_tests {} {
3020 if { [skip_hw_watchpoint_tests] } {
3024 # These targets support just write watchpoints
3025 if { [istarget "s390*-*-*"] } {
3032 # Return 1 if we should skip tests that require the runtime unwinder
3033 # hook. This must be invoked while gdb is running, after shared
3034 # libraries have been loaded. This is needed because otherwise a
3035 # shared libgcc won't be visible.
3037 proc skip_unwinder_tests {} {
3041 gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook" {
3042 -re "= .*no debug info.*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
3044 -re "= .*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
3047 -re "No symbol .* in current context.\r\n$gdb_prompt $" {
3051 gdb_test_multiple "info probe" "check for stap probe in unwinder" {
3052 -re ".*libgcc.*unwind.*\r\n$gdb_prompt $" {
3055 -re "\r\n$gdb_prompt $" {
3062 # Return 0 if we should skip tests that require the libstdc++ stap
3063 # probes. This must be invoked while gdb is running, after shared
3064 # libraries have been loaded.
3066 proc skip_libstdcxx_probe_tests {} {
3070 gdb_test_multiple "info probe" "check for stap probe in libstdc++" {
3071 -re ".*libstdcxx.*catch.*\r\n$gdb_prompt $" {
3074 -re "\r\n$gdb_prompt $" {
3080 # Return 1 if we should skip tests of the "compile" feature.
3081 # This must be invoked after the inferior has been started.
3083 proc skip_compile_feature_tests {} {
3087 gdb_test_multiple "compile code -- ;" "check for working compile command" {
3088 "Could not load libcc1.*\r\n$gdb_prompt $" {
3091 -re "Command not supported on this host\\..*\r\n$gdb_prompt $" {
3094 -re "\r\n$gdb_prompt $" {
3100 # Helper for gdb_is_target_remote. PROMPT_REGEXP is the expected
3103 proc gdb_is_target_remote_prompt { prompt_regexp } {
3105 set test "probe for target remote"
3106 gdb_test_multiple "maint print target-stack" $test {
3107 -re ".*emote serial target in gdb-specific protocol.*$prompt_regexp" {
3111 -re "$prompt_regexp" {
3118 # Check whether we're testing with the remote or extended-remote
3121 proc gdb_is_target_remote {} {
3124 return [gdb_is_target_remote_prompt "$gdb_prompt $"]
3127 # Return the effective value of use_gdb_stub.
3129 # If the use_gdb_stub global has been set (it is set when the gdb process is
3130 # spawned), return that. Otherwise, return the value of the use_gdb_stub
3131 # property from the board file.
3133 # This is the preferred way of checking use_gdb_stub, since it allows to check
3134 # the value before the gdb has been spawned and it will return the correct value
3135 # even when it was overriden by the test.
3137 proc use_gdb_stub {} {
3140 if [info exists use_gdb_stub] {
3141 return $use_gdb_stub
3144 return [target_info exists use_gdb_stub]
3147 # Return 1 if the current remote target is an instance of our GDBserver, 0
3148 # otherwise. Return -1 if there was an error and we can't tell.
3150 gdb_caching_proc target_is_gdbserver {
3154 set test "probing for GDBserver"
3156 gdb_test_multiple "monitor help" $test {
3157 -re "The following monitor commands are supported.*Quit GDBserver.*$gdb_prompt $" {
3160 -re "$gdb_prompt $" {
3165 if { $is_gdbserver == -1 } {
3166 verbose -log "Unable to tell whether we are using GDBserver or not."
3169 return $is_gdbserver
3172 # N.B. compiler_info is intended to be local to this file.
3173 # Call test_compiler_info with no arguments to fetch its value.
3174 # Yes, this is counterintuitive when there's get_compiler_info,
3175 # but that's the current API.
3176 if [info exists compiler_info] {
3182 # Figure out what compiler I am using.
3183 # The result is cached so only the first invocation runs the compiler.
3185 # ARG can be empty or "C++". If empty, "C" is assumed.
3187 # There are several ways to do this, with various problems.
3189 # [ gdb_compile -E $ifile -o $binfile.ci ]
3190 # source $binfile.ci
3192 # Single Unix Spec v3 says that "-E -o ..." together are not
3193 # specified. And in fact, the native compiler on hp-ux 11 (among
3194 # others) does not work with "-E -o ...". Most targets used to do
3195 # this, and it mostly worked, because it works with gcc.
3197 # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ]
3198 # source $binfile.ci
3200 # This avoids the problem with -E and -o together. This almost works
3201 # if the build machine is the same as the host machine, which is
3202 # usually true of the targets which are not gcc. But this code does
3203 # not figure which compiler to call, and it always ends up using the C
3204 # compiler. Not good for setting hp_aCC_compiler. Target
3205 # hppa*-*-hpux* used to do this.
3207 # [ gdb_compile -E $ifile > $binfile.ci ]
3208 # source $binfile.ci
3210 # dejagnu target_compile says that it supports output redirection,
3211 # but the code is completely different from the normal path and I
3212 # don't want to sweep the mines from that path. So I didn't even try
3215 # set cppout [ gdb_compile $ifile "" preprocess $args quiet ]
3218 # I actually do this for all targets now. gdb_compile runs the right
3219 # compiler, and TCL captures the output, and I eval the output.
3221 # Unfortunately, expect logs the output of the command as it goes by,
3222 # and dejagnu helpfully prints a second copy of it right afterwards.
3223 # So I turn off expect logging for a moment.
3225 # [ gdb_compile $ifile $ciexe_file executable $args ]
3226 # [ remote_exec $ciexe_file ]
3227 # [ source $ci_file.out ]
3229 # I could give up on -E and just do this.
3230 # I didn't get desperate enough to try this.
3232 # -- chastain 2004-01-06
3234 proc get_compiler_info {{arg ""}} {
3235 # For compiler.c and compiler.cc
3238 # I am going to play with the log to keep noise out.
3242 # These come from compiler.c or compiler.cc
3243 global compiler_info
3245 # Legacy global data symbols.
3248 if [info exists compiler_info] {
3253 # Choose which file to preprocess.
3254 set ifile "${srcdir}/lib/compiler.c"
3255 if { $arg == "c++" } {
3256 set ifile "${srcdir}/lib/compiler.cc"
3259 # Run $ifile through the right preprocessor.
3260 # Toggle gdb.log to keep the compiler output out of the log.
3261 set saved_log [log_file -info]
3263 if [is_remote host] {
3264 # We have to use -E and -o together, despite the comments
3265 # above, because of how DejaGnu handles remote host testing.
3266 set ppout "$outdir/compiler.i"
3267 gdb_compile "${ifile}" "$ppout" preprocess [list "$arg" quiet]
3268 set file [open $ppout r]
3269 set cppout [read $file]
3272 set cppout [ gdb_compile "${ifile}" "" preprocess [list "$arg" quiet] ]
3274 eval log_file $saved_log
3278 foreach cppline [ split "$cppout" "\n" ] {
3279 if { [ regexp "^#" "$cppline" ] } {
3281 } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } {
3283 } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } {
3285 verbose "get_compiler_info: $cppline" 2
3289 verbose -log "get_compiler_info: $cppline"
3294 # Set to unknown if for some reason compiler_info didn't get defined.
3295 if ![info exists compiler_info] {
3296 verbose -log "get_compiler_info: compiler_info not provided"
3297 set compiler_info "unknown"
3299 # Also set to unknown compiler if any diagnostics happened.
3301 verbose -log "get_compiler_info: got unexpected diagnostics"
3302 set compiler_info "unknown"
3305 # Set the legacy symbols.
3307 regexp "^gcc-(\[0-9\]+)-" "$compiler_info" matchall gcc_compiled
3309 # Log what happened.
3310 verbose -log "get_compiler_info: $compiler_info"
3312 # Most compilers will evaluate comparisons and other boolean
3313 # operations to 0 or 1.
3314 uplevel \#0 { set true 1 }
3315 uplevel \#0 { set false 0 }
3320 # Return the compiler_info string if no arg is provided.
3321 # Otherwise the argument is a glob-style expression to match against
3324 proc test_compiler_info { {compiler ""} } {
3325 global compiler_info
3328 # If no arg, return the compiler_info string.
3329 if [string match "" $compiler] {
3330 return $compiler_info
3333 return [string match $compiler $compiler_info]
3336 proc current_target_name { } {
3338 if [info exists target_info(target,name)] {
3339 set answer $target_info(target,name)
3346 set gdb_wrapper_initialized 0
3347 set gdb_wrapper_target ""
3349 proc gdb_wrapper_init { args } {
3350 global gdb_wrapper_initialized
3351 global gdb_wrapper_file
3352 global gdb_wrapper_flags
3353 global gdb_wrapper_target
3355 if { $gdb_wrapper_initialized == 1 } { return; }
3357 if {[target_info exists needs_status_wrapper] && \
3358 [target_info needs_status_wrapper] != "0"} {
3359 set result [build_wrapper "testglue.o"]
3360 if { $result != "" } {
3361 set gdb_wrapper_file [lindex $result 0]
3362 set gdb_wrapper_flags [lindex $result 1]
3364 warning "Status wrapper failed to build."
3367 set gdb_wrapper_initialized 1
3368 set gdb_wrapper_target [current_target_name]
3371 # Some targets need to always link a special object in. Save its path here.
3372 global gdb_saved_set_unbuffered_mode_obj
3373 set gdb_saved_set_unbuffered_mode_obj ""
3375 # Compile source files specified by SOURCE into a binary of type TYPE at path
3376 # DEST. gdb_compile is implemented using DejaGnu's target_compile, so the type
3377 # parameter and most options are passed directly to it.
3379 # The type can be one of the following:
3381 # - object: Compile into an object file.
3382 # - executable: Compile and link into an executable.
3383 # - preprocess: Preprocess the source files.
3384 # - assembly: Generate assembly listing.
3386 # The following options are understood and processed by gdb_compile:
3388 # - shlib=so_path: Add SO_PATH to the sources, and enable some target-specific
3389 # quirks to be able to use shared libraries.
3390 # - shlib_load: Link with appropriate libraries to allow the test to
3391 # dynamically load libraries at runtime. For example, on Linux, this adds
3392 # -ldl so that the test can use dlopen.
3393 # - nowarnings: Inhibit all compiler warnings.
3395 # And here are some of the not too obscure options understood by DejaGnu that
3396 # influence the compilation:
3398 # - additional_flags=flag: Add FLAG to the compiler flags.
3399 # - libs=library: Add LIBRARY to the libraries passed to the linker. The
3400 # argument can be a file, in which case it's added to the sources, or a
3402 # - ldflags=flag: Add FLAG to the linker flags.
3403 # - incdir=path: Add PATH to the searched include directories.
3404 # - libdir=path: Add PATH to the linker searched directories.
3405 # - ada, c++, f77: Compile the file as Ada, C++ or Fortran.
3406 # - debug: Build with debug information.
3407 # - optimize: Build with optimization.
3409 proc gdb_compile {source dest type options} {
3410 global GDB_TESTCASE_OPTIONS
3411 global gdb_wrapper_file
3412 global gdb_wrapper_flags
3413 global gdb_wrapper_initialized
3416 global gdb_saved_set_unbuffered_mode_obj
3418 set outdir [file dirname $dest]
3420 # Add platform-specific options if a shared library was specified using
3421 # "shlib=librarypath" in OPTIONS.
3425 foreach opt $options {
3426 if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] {
3427 if [test_compiler_info "xlc-*"] {
3428 # IBM xlc compiler doesn't accept shared library named other
3429 # than .so: use "-Wl," to bypass this
3430 lappend source "-Wl,$shlib_name"
3431 } elseif { ([istarget "*-*-mingw*"]
3432 || [istarget *-*-cygwin*]
3433 || [istarget *-*-pe*])} {
3434 lappend source "${shlib_name}.a"
3436 lappend source $shlib_name
3438 if { $shlib_found == 0 } {
3440 if { ([istarget "*-*-mingw*"]
3441 || [istarget *-*-cygwin*]) } {
3442 lappend new_options "additional_flags=-Wl,--enable-auto-import"
3444 if { [test_compiler_info "gcc-*"] || [test_compiler_info "clang-*"] } {
3445 # Undo debian's change in the default.
3446 # Put it at the front to not override any user-provided
3447 # value, and to make sure it appears in front of all the
3449 lappend new_options "early_flags=-Wl,--no-as-needed"
3452 } elseif { $opt == "shlib_load" } {
3455 lappend new_options $opt
3459 # Because we link with libraries using their basename, we may need
3460 # (depending on the platform) to set a special rpath value, to allow
3461 # the executable to find the libraries it depends on.
3462 if { $shlib_load || $shlib_found } {
3463 if { ([istarget "*-*-mingw*"]
3464 || [istarget *-*-cygwin*]
3465 || [istarget *-*-pe*]) } {
3466 # Do not need anything.
3467 } elseif { [istarget *-*-freebsd*] || [istarget *-*-openbsd*] } {
3468 lappend new_options "ldflags=-Wl,-rpath,${outdir}"
3469 } elseif { [istarget arm*-*-symbianelf*] } {
3470 if { $shlib_load } {
3471 lappend new_options "libs=-ldl"
3474 if { $shlib_load } {
3475 lappend new_options "libs=-ldl"
3477 lappend new_options "ldflags=-Wl,-rpath,\\\$ORIGIN"
3480 set options $new_options
3482 if [info exists GDB_TESTCASE_OPTIONS] {
3483 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS"
3485 verbose "options are $options"
3486 verbose "source is $source $dest $type $options"
3488 if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init }
3490 if {[target_info exists needs_status_wrapper] && \
3491 [target_info needs_status_wrapper] != "0" && \
3492 [info exists gdb_wrapper_file]} {
3493 lappend options "libs=${gdb_wrapper_file}"
3494 lappend options "ldflags=${gdb_wrapper_flags}"
3497 # Replace the "nowarnings" option with the appropriate additional_flags
3498 # to disable compiler warnings.
3499 set nowarnings [lsearch -exact $options nowarnings]
3500 if {$nowarnings != -1} {
3501 if [target_info exists gdb,nowarnings_flag] {
3502 set flag "additional_flags=[target_info gdb,nowarnings_flag]"
3504 set flag "additional_flags=-w"
3506 set options [lreplace $options $nowarnings $nowarnings $flag]
3509 if { $type == "executable" } {
3510 if { ([istarget "*-*-mingw*"]
3511 || [istarget "*-*-*djgpp"]
3512 || [istarget "*-*-cygwin*"])} {
3513 # Force output to unbuffered mode, by linking in an object file
3514 # with a global contructor that calls setvbuf.
3516 # Compile the special object seperatelly for two reasons:
3517 # 1) Insulate it from $options.
3518 # 2) Avoid compiling it for every gdb_compile invocation,
3519 # which is time consuming, especially if we're remote
3522 if { $gdb_saved_set_unbuffered_mode_obj == "" } {
3523 verbose "compiling gdb_saved_set_unbuffered_obj"
3524 set unbuf_src ${srcdir}/lib/set_unbuffered_mode.c
3525 set unbuf_obj ${objdir}/set_unbuffered_mode.o
3527 set result [gdb_compile "${unbuf_src}" "${unbuf_obj}" object {nowarnings}]
3528 if { $result != "" } {
3531 if {[is_remote host]} {
3532 set gdb_saved_set_unbuffered_mode_obj set_unbuffered_mode_saved.o
3534 set gdb_saved_set_unbuffered_mode_obj ${objdir}/set_unbuffered_mode_saved.o
3536 # Link a copy of the output object, because the
3537 # original may be automatically deleted.
3538 remote_download host $unbuf_obj $gdb_saved_set_unbuffered_mode_obj
3540 verbose "gdb_saved_set_unbuffered_obj already compiled"
3543 # Rely on the internal knowledge that the global ctors are ran in
3544 # reverse link order. In that case, we can use ldflags to
3545 # avoid copying the object file to the host multiple
3547 # This object can only be added if standard libraries are
3548 # used. Thus, we need to disable it if -nostdlib option is used
3549 if {[lsearch -regexp $options "-nostdlib"] < 0 } {
3550 lappend options "ldflags=$gdb_saved_set_unbuffered_mode_obj"
3555 set result [target_compile $source $dest $type $options]
3557 # Prune uninteresting compiler (and linker) output.
3558 regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result
3560 regsub "\[\r\n\]*$" "$result" "" result
3561 regsub "^\[\r\n\]*" "$result" "" result
3563 if {[lsearch $options quiet] < 0} {
3564 # We shall update this on a per language basis, to avoid
3565 # changing the entire testsuite in one go.
3566 if {[lsearch $options f77] >= 0} {
3567 gdb_compile_test $source $result
3568 } elseif { $result != "" } {
3569 clone_output "gdb compile failed, $result"
3576 # This is just like gdb_compile, above, except that it tries compiling
3577 # against several different thread libraries, to see which one this
3579 proc gdb_compile_pthreads {source dest type options} {
3581 set why_msg "unrecognized error"
3582 foreach lib {-lpthreads -lpthread -lthread ""} {
3583 # This kind of wipes out whatever libs the caller may have
3584 # set. Or maybe theirs will override ours. How infelicitous.
3585 set options_with_lib [concat $options [list libs=$lib quiet]]
3586 set ccout [gdb_compile $source $dest $type $options_with_lib]
3587 switch -regexp -- $ccout {
3588 ".*no posix threads support.*" {
3589 set why_msg "missing threads include file"
3592 ".*cannot open -lpthread.*" {
3593 set why_msg "missing runtime threads library"
3595 ".*Can't find library for -lpthread.*" {
3596 set why_msg "missing runtime threads library"
3599 pass "successfully compiled posix threads test case"
3605 if {!$built_binfile} {
3606 unsupported "couldn't compile [file tail $source]: ${why_msg}"
3611 # Build a shared library from SOURCES.
3613 proc gdb_compile_shlib {sources dest options} {
3614 set obj_options $options
3617 if { [lsearch -exact $options "c++"] >= 0 } {
3618 set info_options "c++"
3620 if [get_compiler_info ${info_options}] {
3624 switch -glob [test_compiler_info] {
3626 lappend obj_options "additional_flags=-qpic"
3629 if { !([istarget "*-*-cygwin*"]
3630 || [istarget "*-*-mingw*"]) } {
3631 lappend obj_options "additional_flags=-fpic"
3635 if { !([istarget "powerpc*-*-aix*"]
3636 || [istarget "rs6000*-*-aix*"]
3637 || [istarget "*-*-cygwin*"]
3638 || [istarget "*-*-mingw*"]
3639 || [istarget "*-*-pe*"]) } {
3640 lappend obj_options "additional_flags=-fpic"
3644 lappend obj_options "additional_flags=-fpic"
3647 # don't know what the compiler is...
3651 set outdir [file dirname $dest]
3653 foreach source $sources {
3654 set sourcebase [file tail $source]
3655 if {[gdb_compile $source "${outdir}/${sourcebase}.o" object $obj_options] != ""} {
3658 lappend objects ${outdir}/${sourcebase}.o
3661 set link_options $options
3662 if [test_compiler_info "xlc-*"] {
3663 lappend link_options "additional_flags=-qmkshrobj"
3665 lappend link_options "additional_flags=-shared"
3667 if { ([istarget "*-*-mingw*"]
3668 || [istarget *-*-cygwin*]
3669 || [istarget *-*-pe*]) } {
3670 if { [is_remote host] } {
3671 set name [file tail ${dest}]
3675 lappend link_options "additional_flags=-Wl,--out-implib,${name}.a"
3677 # Set the soname of the library. This causes the linker on ELF
3678 # systems to create the DT_NEEDED entry in the executable referring
3679 # to the soname of the library, and not its absolute path. This
3680 # (using the absolute path) would be problem when testing on a
3683 # In conjunction with setting the soname, we add the special
3684 # rpath=$ORIGIN value when building the executable, so that it's
3685 # able to find the library in its own directory.
3686 set destbase [file tail $dest]
3687 lappend link_options "additional_flags=-Wl,-soname,$destbase"
3690 if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
3693 if { [is_remote host]
3694 && ([istarget "*-*-mingw*"]
3695 || [istarget *-*-cygwin*]
3696 || [istarget *-*-pe*]) } {
3697 set dest_tail_name [file tail ${dest}]
3698 remote_upload host $dest_tail_name.a ${dest}.a
3699 remote_file host delete $dest_tail_name.a
3705 # This is just like gdb_compile_shlib, above, except that it tries compiling
3706 # against several different thread libraries, to see which one this
3708 proc gdb_compile_shlib_pthreads {sources dest options} {
3710 set why_msg "unrecognized error"
3711 foreach lib {-lpthreads -lpthread -lthread ""} {
3712 # This kind of wipes out whatever libs the caller may have
3713 # set. Or maybe theirs will override ours. How infelicitous.
3714 set options_with_lib [concat $options [list libs=$lib quiet]]
3715 set ccout [gdb_compile_shlib $sources $dest $options_with_lib]
3716 switch -regexp -- $ccout {
3717 ".*no posix threads support.*" {
3718 set why_msg "missing threads include file"
3721 ".*cannot open -lpthread.*" {
3722 set why_msg "missing runtime threads library"
3724 ".*Can't find library for -lpthread.*" {
3725 set why_msg "missing runtime threads library"
3728 pass "successfully compiled posix threads test case"
3734 if {!$built_binfile} {
3735 unsupported "couldn't compile $sources: ${why_msg}"
3740 # This is just like gdb_compile_pthreads, above, except that we always add the
3741 # objc library for compiling Objective-C programs
3742 proc gdb_compile_objc {source dest type options} {
3744 set why_msg "unrecognized error"
3745 foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} {
3746 # This kind of wipes out whatever libs the caller may have
3747 # set. Or maybe theirs will override ours. How infelicitous.
3748 if { $lib == "solaris" } {
3749 set lib "-lpthread -lposix4"
3751 if { $lib != "-lobjc" } {
3752 set lib "-lobjc $lib"
3754 set options_with_lib [concat $options [list libs=$lib quiet]]
3755 set ccout [gdb_compile $source $dest $type $options_with_lib]
3756 switch -regexp -- $ccout {
3757 ".*no posix threads support.*" {
3758 set why_msg "missing threads include file"
3761 ".*cannot open -lpthread.*" {
3762 set why_msg "missing runtime threads library"
3764 ".*Can't find library for -lpthread.*" {
3765 set why_msg "missing runtime threads library"
3768 pass "successfully compiled objc with posix threads test case"
3774 if {!$built_binfile} {
3775 unsupported "couldn't compile [file tail $source]: ${why_msg}"
3780 proc send_gdb { string } {
3781 global suppress_flag
3782 if { $suppress_flag } {
3785 return [remote_send host "$string"]
3788 # Send STRING to the inferior's terminal.
3790 proc send_inferior { string } {
3791 global inferior_spawn_id
3793 if {[catch "send -i $inferior_spawn_id -- \$string" errorInfo]} {
3803 proc gdb_expect { args } {
3804 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
3805 set atimeout [lindex $args 0]
3806 set expcode [list [lindex $args 1]]
3811 # A timeout argument takes precedence, otherwise of all the timeouts
3812 # select the largest.
3813 if [info exists atimeout] {
3816 set tmt [get_largest_timeout]
3819 global suppress_flag
3820 global remote_suppress_flag
3821 if [info exists remote_suppress_flag] {
3822 set old_val $remote_suppress_flag
3824 if [info exists suppress_flag] {
3825 if { $suppress_flag } {
3826 set remote_suppress_flag 1
3830 {uplevel remote_expect host $tmt $expcode} string]
3831 if [info exists old_val] {
3832 set remote_suppress_flag $old_val
3834 if [info exists remote_suppress_flag] {
3835 unset remote_suppress_flag
3840 global errorInfo errorCode
3842 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
3844 return -code $code $string
3848 # gdb_expect_list TEST SENTINEL LIST -- expect a sequence of outputs
3850 # Check for long sequence of output by parts.
3851 # TEST: is the test message to be printed with the test success/fail.
3852 # SENTINEL: Is the terminal pattern indicating that output has finished.
3853 # LIST: is the sequence of outputs to match.
3854 # If the sentinel is recognized early, it is considered an error.
3857 # 1 if the test failed,
3858 # 0 if the test passes,
3859 # -1 if there was an internal error.
3861 proc gdb_expect_list {test sentinel list} {
3863 global suppress_flag
3866 if { $suppress_flag } {
3868 unresolved "${test}"
3870 while { ${index} < [llength ${list}] } {
3871 set pattern [lindex ${list} ${index}]
3872 set index [expr ${index} + 1]
3873 verbose -log "gdb_expect_list pattern: /$pattern/" 2
3874 if { ${index} == [llength ${list}] } {
3877 -re "${pattern}${sentinel}" {
3878 # pass "${test}, pattern ${index} + sentinel"
3881 fail "${test} (pattern ${index} + sentinel)"
3884 -re ".*A problem internal to GDB has been detected" {
3885 fail "${test} (GDB internal error)"
3887 gdb_internal_error_resync
3890 fail "${test} (pattern ${index} + sentinel) (timeout)"
3895 # unresolved "${test}, pattern ${index} + sentinel"
3901 # pass "${test}, pattern ${index}"
3904 fail "${test} (pattern ${index})"
3907 -re ".*A problem internal to GDB has been detected" {
3908 fail "${test} (GDB internal error)"
3910 gdb_internal_error_resync
3913 fail "${test} (pattern ${index}) (timeout)"
3918 # unresolved "${test}, pattern ${index}"
3932 proc gdb_suppress_entire_file { reason } {
3933 global suppress_flag
3936 set suppress_flag -1
3940 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
3941 # gdb_expect to fail immediately (until the next call to
3942 # gdb_stop_suppressing_tests).
3944 proc gdb_suppress_tests { args } {
3945 global suppress_flag
3947 return; # fnf - disable pending review of results where
3948 # testsuite ran better without this
3951 if { $suppress_flag == 1 } {
3952 if { [llength $args] > 0 } {
3953 warning "[lindex $args 0]\n"
3955 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n"
3961 # Clear suppress_flag.
3963 proc gdb_stop_suppressing_tests { } {
3964 global suppress_flag
3966 if [info exists suppress_flag] {
3967 if { $suppress_flag > 0 } {
3969 clone_output "Tests restarted.\n"
3976 proc gdb_clear_suppressed { } {
3977 global suppress_flag
3982 # Spawn the gdb process.
3984 # This doesn't expect any output or do any other initialization,
3985 # leaving those to the caller.
3987 # Overridable function -- you can override this function in your
3990 proc gdb_spawn { } {
3994 # Spawn GDB with CMDLINE_FLAGS appended to the GDBFLAGS global.
3996 proc gdb_spawn_with_cmdline_opts { cmdline_flags } {
3999 set saved_gdbflags $GDBFLAGS
4001 if {$GDBFLAGS != ""} {
4004 append GDBFLAGS $cmdline_flags
4008 set GDBFLAGS $saved_gdbflags
4013 # Start gdb running, wait for prompt, and disable the pagers.
4015 # Overridable function -- you can override this function in your
4018 proc gdb_start { } {
4023 catch default_gdb_exit
4026 # Return true if we can spawn a program on the target and attach to
4029 proc can_spawn_for_attach { } {
4030 # We use exp_pid to get the inferior's pid, assuming that gives
4031 # back the pid of the program. On remote boards, that would give
4032 # us instead the PID of e.g., the ssh client, etc.
4033 if [is_remote target] then {
4037 # The "attach" command doesn't make sense when the target is
4038 # stub-like, where GDB finds the program already started on
4039 # initial connection.
4040 if {[target_info exists use_gdb_stub]} {
4048 # Kill a progress previously started with spawn_wait_for_attach, and
4049 # reap its wait status. PROC_SPAWN_ID is the spawn id associated with
4052 proc kill_wait_spawned_process { proc_spawn_id } {
4053 set pid [exp_pid -i $proc_spawn_id]
4055 verbose -log "killing ${pid}"
4056 remote_exec build "kill -9 ${pid}"
4058 verbose -log "closing ${proc_spawn_id}"
4059 catch "close -i $proc_spawn_id"
4060 verbose -log "waiting for ${proc_spawn_id}"
4062 # If somehow GDB ends up still attached to the process here, a
4063 # blocking wait hangs until gdb is killed (or until gdb / the
4064 # ptracer reaps the exit status too, but that won't happen because
4065 # something went wrong.) Passing -nowait makes expect tell Tcl to
4066 # wait for the PID in the background. That's fine because we
4067 # don't care about the exit status. */
4068 wait -nowait -i $proc_spawn_id
4071 # Returns the process id corresponding to the given spawn id.
4073 proc spawn_id_get_pid { spawn_id } {
4074 set testpid [exp_pid -i $spawn_id]
4076 if { [istarget "*-*-cygwin*"] } {
4077 # testpid is the Cygwin PID, GDB uses the Windows PID, which
4078 # might be different due to the way fork/exec works.
4079 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
4085 # Start a set of programs running and then wait for a bit, to be sure
4086 # that they can be attached to. Return a list of processes spawn IDs,
4087 # one element for each process spawned. It's a test error to call
4088 # this when [can_spawn_for_attach] is false.
4090 proc spawn_wait_for_attach { executable_list } {
4091 set spawn_id_list {}
4093 if ![can_spawn_for_attach] {
4094 # The caller should have checked can_spawn_for_attach itself
4095 # before getting here.
4096 error "can't spawn for attach with this target/board"
4099 foreach {executable} $executable_list {
4100 # Note we use Expect's spawn, not Tcl's exec, because with
4101 # spawn we control when to wait for/reap the process. That
4102 # allows killing the process by PID without being subject to
4104 lappend spawn_id_list [remote_spawn target $executable]
4109 return $spawn_id_list
4113 # gdb_load_cmd -- load a file into the debugger.
4114 # ARGS - additional args to load command.
4115 # return a -1 if anything goes wrong.
4117 proc gdb_load_cmd { args } {
4120 if [target_info exists gdb_load_timeout] {
4121 set loadtimeout [target_info gdb_load_timeout]
4123 set loadtimeout 1600
4125 send_gdb "load $args\n"
4126 verbose "Timeout is now $loadtimeout seconds" 2
4127 gdb_expect $loadtimeout {
4128 -re "Loading section\[^\r\]*\r\n" {
4131 -re "Start address\[\r\]*\r\n" {
4134 -re "Transfer rate\[\r\]*\r\n" {
4137 -re "Memory access error\[^\r\]*\r\n" {
4138 perror "Failed to load program"
4141 -re "$gdb_prompt $" {
4144 -re "(.*)\r\n$gdb_prompt " {
4145 perror "Unexpected reponse from 'load' -- $expect_out(1,string)"
4149 perror "Timed out trying to load $args."
4156 # Invoke "gcore". CORE is the name of the core file to write. TEST
4157 # is the name of the test case. This will return 1 if the core file
4158 # was created, 0 otherwise. If this fails to make a core file because
4159 # this configuration of gdb does not support making core files, it
4160 # will call "unsupported", not "fail". However, if this fails to make
4161 # a core file for some other reason, then it will call "fail".
4163 proc gdb_gcore_cmd {core test} {
4167 gdb_test_multiple "gcore $core" $test {
4168 -re "Saved corefile .*\[\r\n\]+$gdb_prompt $" {
4172 -re "(?:Can't create a corefile|Target does not support core file generation\\.)\[\r\n\]+$gdb_prompt $" {
4180 # Load core file CORE. TEST is the name of the test case.
4181 # This will record a pass/fail for loading the core file.
4183 # 1 - core file is successfully loaded
4184 # 0 - core file loaded but has a non fatal error
4185 # -1 - core file failed to load
4187 proc gdb_core_cmd { core test } {
4190 gdb_test_multiple "core $core" "$test" {
4191 -re "\\\[Thread debugging using \[^ \r\n\]* enabled\\\]\r\n" {
4194 -re " is not a core dump:.*\r\n$gdb_prompt $" {
4195 fail "$test (bad file format)"
4198 -re ": No such file or directory.*\r\n$gdb_prompt $" {
4199 fail "$test (file not found)"
4202 -re "Couldn't find .* registers in core file.*\r\n$gdb_prompt $" {
4203 fail "$test (incomplete note section)"
4206 -re "Core was generated by .*\r\n$gdb_prompt $" {
4210 -re ".*$gdb_prompt $" {
4215 fail "$test (timeout)"
4219 fail "unsupported output from 'core' command"
4223 # Return the filename to download to the target and load on the target
4224 # for this shared library. Normally just LIBNAME, unless shared libraries
4225 # for this target have separate link and load images.
4227 proc shlib_target_file { libname } {
4231 # Return the filename GDB will load symbols from when debugging this
4232 # shared library. Normally just LIBNAME, unless shared libraries for
4233 # this target have separate link and load images.
4235 proc shlib_symbol_file { libname } {
4239 # Return the filename to download to the target and load for this
4240 # executable. Normally just BINFILE unless it is renamed to something
4241 # else for this target.
4243 proc exec_target_file { binfile } {
4247 # Return the filename GDB will load symbols from when debugging this
4248 # executable. Normally just BINFILE unless executables for this target
4249 # have separate files for symbols.
4251 proc exec_symbol_file { binfile } {
4255 # Rename the executable file. Normally this is just BINFILE1 being renamed
4256 # to BINFILE2, but some targets require multiple binary files.
4257 proc gdb_rename_execfile { binfile1 binfile2 } {
4258 file rename -force [exec_target_file ${binfile1}] \
4259 [exec_target_file ${binfile2}]
4260 if { [exec_target_file ${binfile1}] != [exec_symbol_file ${binfile1}] } {
4261 file rename -force [exec_symbol_file ${binfile1}] \
4262 [exec_symbol_file ${binfile2}]
4266 # "Touch" the executable file to update the date. Normally this is just
4267 # BINFILE, but some targets require multiple files.
4268 proc gdb_touch_execfile { binfile } {
4269 set time [clock seconds]
4270 file mtime [exec_target_file ${binfile}] $time
4271 if { [exec_target_file ${binfile}] != [exec_symbol_file ${binfile}] } {
4272 file mtime [exec_symbol_file ${binfile}] $time
4276 # Like remote_download but provides a gdb-specific behavior.
4278 # If the destination board is remote, the local file FROMFILE is transferred as
4279 # usual with remote_download to TOFILE on the remote board. The destination
4280 # filename is added to the CLEANFILES global, so it can be cleaned up at the
4283 # If the destination board is local, the destination path TOFILE is passed
4284 # through standard_output_file, and FROMFILE is copied there.
4286 # In both cases, if TOFILE is omitted, it defaults to the [file tail] of
4289 proc gdb_remote_download {dest fromfile {tofile {}}} {
4290 # If TOFILE is not given, default to the same filename as FROMFILE.
4291 if {[string length $tofile] == 0} {
4292 set tofile [file tail $fromfile]
4295 if {[is_remote $dest]} {
4296 # When the DEST is remote, we simply send the file to DEST.
4299 set destname [remote_download $dest $fromfile $tofile]
4300 lappend cleanfiles $destname
4304 # When the DEST is local, we copy the file to the test directory (where
4305 # the executable is).
4307 # Note that we pass TOFILE through standard_output_file, regardless of
4308 # whether it is absolute or relative, because we don't want the tests
4309 # to be able to write outside their standard output directory.
4311 set tofile [standard_output_file $tofile]
4313 file copy -force $fromfile $tofile
4319 # gdb_load_shlib LIB...
4321 # Copy the listed library to the target.
4323 proc gdb_load_shlib { file } {
4324 set dest [gdb_remote_download target [shlib_target_file $file]]
4326 if {[is_remote target]} {
4327 # If the target is remote, we need to tell gdb where to find the
4330 # We could set this even when not testing remotely, but a user
4331 # generally won't set it unless necessary. In order to make the tests
4332 # more like the real-life scenarios, we don't set it for local testing.
4333 gdb_test "set solib-search-path [file dirname $file]" "" ""
4340 # gdb_load -- load a file into the debugger. Specifying no file
4341 # defaults to the executable currently being debugged.
4342 # The return value is 0 for success, -1 for failure.
4343 # Many files in config/*.exp override this procedure.
4345 proc gdb_load { arg } {
4347 return [gdb_file_cmd $arg]
4352 # gdb_reload -- load a file into the target. Called before "running",
4353 # either the first time or after already starting the program once,
4354 # for remote targets. Most files that override gdb_load should now
4355 # override this instead.
4357 proc gdb_reload { } {
4358 # For the benefit of existing configurations, default to gdb_load.
4359 # Specifying no file defaults to the executable currently being
4361 return [gdb_load ""]
4364 proc gdb_continue { function } {
4367 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"]
4370 proc default_gdb_init { test_file_name } {
4371 global gdb_wrapper_initialized
4372 global gdb_wrapper_target
4373 global gdb_test_file_name
4379 gdb_clear_suppressed
4381 set gdb_test_file_name [file rootname [file tail $test_file_name]]
4383 # Make sure that the wrapper is rebuilt
4384 # with the appropriate multilib option.
4385 if { $gdb_wrapper_target != [current_target_name] } {
4386 set gdb_wrapper_initialized 0
4389 # Unlike most tests, we have a small number of tests that generate
4390 # a very large amount of output. We therefore increase the expect
4391 # buffer size to be able to contain the entire test output. This
4392 # is especially needed by gdb.base/info-macros.exp.
4394 # Also set this value for the currently running GDB.
4395 match_max [match_max -d]
4397 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
4398 set pf_prefix "[file tail [file dirname $test_file_name]]/[file tail $test_file_name]:"
4401 if [target_info exists gdb_prompt] {
4402 set gdb_prompt [target_info gdb_prompt]
4404 set gdb_prompt "\\(gdb\\)"
4407 if [info exists use_gdb_stub] {
4412 # Return a path using GDB_PARALLEL.
4413 # ARGS is a list of path elements to append to "$objdir/$GDB_PARALLEL".
4414 # GDB_PARALLEL must be defined, the caller must check.
4416 # The default value for GDB_PARALLEL is, canonically, ".".
4417 # The catch is that tests don't expect an additional "./" in file paths so
4418 # omit any directory for the default case.
4419 # GDB_PARALLEL is written as "yes" for the default case in Makefile.in to mark
4420 # its special handling.
4422 proc make_gdb_parallel_path { args } {
4423 global GDB_PARALLEL objdir
4424 set joiner [list "file" "join" $objdir]
4425 if { [info exists GDB_PARALLEL] && $GDB_PARALLEL != "yes" } {
4426 lappend joiner $GDB_PARALLEL
4428 set joiner [concat $joiner $args]
4429 return [eval $joiner]
4432 # Turn BASENAME into a full file name in the standard output
4433 # directory. It is ok if BASENAME is the empty string; in this case
4434 # the directory is returned.
4436 proc standard_output_file {basename} {
4437 global objdir subdir gdb_test_file_name
4439 set dir [make_gdb_parallel_path outputs $subdir $gdb_test_file_name]
4441 return [file join $dir $basename]
4444 # Return the name of a file in our standard temporary directory.
4446 proc standard_temp_file {basename} {
4447 # Since a particular runtest invocation is only executing a single test
4448 # file at any given time, we can use the runtest pid to build the
4449 # path of the temp directory.
4450 set dir [make_gdb_parallel_path temp [pid]]
4452 return [file join $dir $basename]
4455 # Set 'testfile', 'srcfile', and 'binfile'.
4457 # ARGS is a list of source file specifications.
4458 # Without any arguments, the .exp file's base name is used to
4459 # compute the source file name. The ".c" extension is added in this case.
4460 # If ARGS is not empty, each entry is a source file specification.
4461 # If the specification starts with a ".", it is treated as a suffix
4462 # to append to the .exp file's base name.
4463 # If the specification is the empty string, it is treated as if it
4465 # Otherwise it is a file name.
4466 # The first file in the list is used to set the 'srcfile' global.
4467 # Each subsequent name is used to set 'srcfile2', 'srcfile3', etc.
4469 # Most tests should call this without arguments.
4471 # If a completely different binary file name is needed, then it
4472 # should be handled in the .exp file with a suitable comment.
4474 proc standard_testfile {args} {
4475 global gdb_test_file_name
4477 global gdb_test_file_last_vars
4480 global testfile binfile
4482 set testfile $gdb_test_file_name
4483 set binfile [standard_output_file ${testfile}]
4485 if {[llength $args] == 0} {
4489 # Unset our previous output variables.
4490 # This can help catch hidden bugs.
4491 if {[info exists gdb_test_file_last_vars]} {
4492 foreach varname $gdb_test_file_last_vars {
4494 catch {unset $varname}
4497 # 'executable' is often set by tests.
4498 set gdb_test_file_last_vars {executable}
4502 set varname srcfile$suffix
4505 # Handle an extension.
4508 } elseif {[string range $arg 0 0] == "."} {
4509 set arg $testfile$arg
4513 lappend gdb_test_file_last_vars $varname
4515 if {$suffix == ""} {
4523 # The default timeout used when testing GDB commands. We want to use
4524 # the same timeout as the default dejagnu timeout, unless the user has
4525 # already provided a specific value (probably through a site.exp file).
4526 global gdb_test_timeout
4527 if ![info exists gdb_test_timeout] {
4528 set gdb_test_timeout $timeout
4531 # A list of global variables that GDB testcases should not use.
4532 # We try to prevent their use by monitoring write accesses and raising
4533 # an error when that happens.
4534 set banned_variables { bug_id prms_id }
4536 # A list of procedures that GDB testcases should not use.
4537 # We try to prevent their use by monitoring invocations and raising
4538 # an error when that happens.
4539 set banned_procedures { strace }
4541 # gdb_init is called by runtest at start, but also by several
4542 # tests directly; gdb_finish is only called from within runtest after
4543 # each test source execution.
4544 # Placing several traces by repetitive calls to gdb_init leads
4545 # to problems, as only one trace is removed in gdb_finish.
4546 # To overcome this possible problem, we add a variable that records
4547 # if the banned variables and procedures are already traced.
4550 proc gdb_init { test_file_name } {
4551 # Reset the timeout value to the default. This way, any testcase
4552 # that changes the timeout value without resetting it cannot affect
4553 # the timeout used in subsequent testcases.
4554 global gdb_test_timeout
4556 set timeout $gdb_test_timeout
4558 if { [regexp ".*gdb\.reverse\/.*" $test_file_name]
4559 && [target_info exists gdb_reverse_timeout] } {
4560 set timeout [target_info gdb_reverse_timeout]
4563 # If GDB_INOTIFY is given, check for writes to '.'. This is a
4564 # debugging tool to help confirm that the test suite is
4565 # parallel-safe. You need "inotifywait" from the
4566 # inotify-tools package to use this.
4567 global GDB_INOTIFY inotify_pid
4568 if {[info exists GDB_INOTIFY] && ![info exists inotify_pid]} {
4569 global outdir tool inotify_log_file
4571 set exclusions {outputs temp gdb[.](log|sum) cache}
4572 set exclusion_re ([join $exclusions |])
4574 set inotify_log_file [standard_temp_file inotify.out]
4575 set inotify_pid [exec inotifywait -r -m -e move,create,delete . \
4576 --exclude $exclusion_re \
4577 |& tee -a $outdir/$tool.log $inotify_log_file &]
4579 # Wait for the watches; hopefully this is long enough.
4582 # Clear the log so that we don't emit a warning the first time
4584 set fd [open $inotify_log_file w]
4588 # Block writes to all banned variables, and invocation of all
4589 # banned procedures...
4590 global banned_variables
4591 global banned_procedures
4592 global banned_traced
4593 if (!$banned_traced) {
4594 foreach banned_var $banned_variables {
4595 global "$banned_var"
4596 trace add variable "$banned_var" write error
4598 foreach banned_proc $banned_procedures {
4599 global "$banned_proc"
4600 trace add execution "$banned_proc" enter error
4605 # We set LC_ALL, LC_CTYPE, and LANG to C so that we get the same
4606 # messages as expected.
4611 # Don't let a .inputrc file or an existing setting of INPUTRC mess up
4612 # the test results. Even if /dev/null doesn't exist on the particular
4613 # platform, the readline library will use the default setting just by
4614 # failing to open the file. OTOH, opening /dev/null successfully will
4615 # also result in the default settings being used since nothing will be
4616 # read from this file.
4617 setenv INPUTRC "/dev/null"
4619 # The gdb.base/readline.exp arrow key test relies on the standard VT100
4620 # bindings, so make sure that an appropriate terminal is selected.
4621 # The same bug doesn't show up if we use ^P / ^N instead.
4624 # Some tests (for example gdb.base/maint.exp) shell out from gdb to use
4625 # grep. Clear GREP_OPTIONS to make the behavior predictable,
4626 # especially having color output turned on can cause tests to fail.
4627 setenv GREP_OPTIONS ""
4629 # Clear $gdbserver_reconnect_p.
4630 global gdbserver_reconnect_p
4631 set gdbserver_reconnect_p 1
4632 unset gdbserver_reconnect_p
4634 return [default_gdb_init $test_file_name]
4637 proc gdb_finish { } {
4638 global gdbserver_reconnect_p
4642 # Exit first, so that the files are no longer in use.
4645 if { [llength $cleanfiles] > 0 } {
4646 eval remote_file target delete $cleanfiles
4650 # Unblock write access to the banned variables. Dejagnu typically
4651 # resets some of them between testcases.
4652 global banned_variables
4653 global banned_procedures
4654 global banned_traced
4655 if ($banned_traced) {
4656 foreach banned_var $banned_variables {
4657 global "$banned_var"
4658 trace remove variable "$banned_var" write error
4660 foreach banned_proc $banned_procedures {
4661 global "$banned_proc"
4662 trace remove execution "$banned_proc" enter error
4669 set debug_format "unknown"
4671 # Run the gdb command "info source" and extract the debugging format
4672 # information from the output and save it in debug_format.
4674 proc get_debug_format { } {
4680 set debug_format "unknown"
4681 send_gdb "info source\n"
4683 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
4684 set debug_format $expect_out(1,string)
4685 verbose "debug format is $debug_format"
4688 -re "No current source file.\r\n$gdb_prompt $" {
4689 perror "get_debug_format used when no current source file"
4692 -re "$gdb_prompt $" {
4693 warning "couldn't check debug format (no valid response)."
4697 warning "couldn't check debug format (timeout)."
4703 # Return true if FORMAT matches the debug format the current test was
4704 # compiled with. FORMAT is a shell-style globbing pattern; it can use
4705 # `*', `[...]', and so on.
4707 # This function depends on variables set by `get_debug_format', above.
4709 proc test_debug_format {format} {
4712 return [expr [string match $format $debug_format] != 0]
4715 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
4716 # COFF, stabs, etc). If that format matches the format that the
4717 # current test was compiled with, then the next test is expected to
4718 # fail for any target. Returns 1 if the next test or set of tests is
4719 # expected to fail, 0 otherwise (or if it is unknown). Must have
4720 # previously called get_debug_format.
4721 proc setup_xfail_format { format } {
4722 set ret [test_debug_format $format]
4730 # gdb_get_line_number TEXT [FILE]
4732 # Search the source file FILE, and return the line number of the
4733 # first line containing TEXT. If no match is found, an error is thrown.
4735 # TEXT is a string literal, not a regular expression.
4737 # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is
4738 # specified, and does not start with "/", then it is assumed to be in
4739 # "$srcdir/$subdir". This is awkward, and can be fixed in the future,
4740 # by changing the callers and the interface at the same time.
4741 # In particular: gdb.base/break.exp, gdb.base/condbreak.exp,
4742 # gdb.base/ena-dis-br.exp.
4744 # Use this function to keep your test scripts independent of the
4745 # exact line numbering of the source file. Don't write:
4747 # send_gdb "break 20"
4749 # This means that if anyone ever edits your test's source file,
4750 # your test could break. Instead, put a comment like this on the
4751 # source file line you want to break at:
4753 # /* breakpoint spot: frotz.exp: test name */
4755 # and then write, in your test script (which we assume is named
4758 # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
4760 # (Yes, Tcl knows how to handle the nested quotes and brackets.
4763 # % puts "foo [lindex "bar baz" 1]"
4766 # Tcl is quite clever, for a little stringy language.)
4770 # The previous implementation of this procedure used the gdb search command.
4771 # This version is different:
4773 # . It works with MI, and it also works when gdb is not running.
4775 # . It operates on the build machine, not the host machine.
4777 # . For now, this implementation fakes a current directory of
4778 # $srcdir/$subdir to be compatible with the old implementation.
4779 # This will go away eventually and some callers will need to
4782 # . The TEXT argument is literal text and matches literally,
4783 # not a regular expression as it was before.
4785 # . State changes in gdb, such as changing the current file
4786 # and setting $_, no longer happen.
4788 # After a bit of time we can forget about the differences from the
4789 # old implementation.
4791 # --chastain 2004-08-05
4793 proc gdb_get_line_number { text { file "" } } {
4798 if { "$file" == "" } then {
4801 if { ! [regexp "^/" "$file"] } then {
4802 set file "$srcdir/$subdir/$file"
4805 if { [ catch { set fd [open "$file"] } message ] } then {
4810 for { set line 1 } { 1 } { incr line } {
4811 if { [ catch { set nchar [gets "$fd" body] } message ] } then {
4814 if { $nchar < 0 } then {
4817 if { [string first "$text" "$body"] >= 0 } then {
4823 if { [ catch { close "$fd" } message ] } then {
4828 error "undefined tag \"$text\""
4834 # Continue the program until it ends.
4836 # MSSG is the error message that gets printed. If not given, a
4838 # COMMAND is the command to invoke. If not given, "continue" is
4840 # ALLOW_EXTRA is a flag indicating whether the test should expect
4841 # extra output between the "Continuing." line and the program
4842 # exiting. By default it is zero; if nonzero, any extra output
4845 proc gdb_continue_to_end {{mssg ""} {command continue} {allow_extra 0}} {
4846 global inferior_exited_re use_gdb_stub
4849 set text "continue until exit"
4851 set text "continue until exit at $mssg"
4859 # By default, we don't rely on exit() behavior of remote stubs --
4860 # it's common for exit() to be implemented as a simple infinite
4861 # loop, or a forced crash/reset. For native targets, by default, we
4862 # assume process exit is reported as such. If a non-reliable target
4863 # is used, we set a breakpoint at exit, and continue to that.
4864 if { [target_info exists exit_is_reliable] } {
4865 set exit_is_reliable [target_info exit_is_reliable]
4867 set exit_is_reliable [expr ! $use_gdb_stub]
4870 if { ! $exit_is_reliable } {
4871 if {![gdb_breakpoint "exit"]} {
4874 gdb_test $command "Continuing..*Breakpoint .*exit.*" \
4877 # Continue until we exit. Should not stop again.
4878 # Don't bother to check the output of the program, that may be
4879 # extremely tough for some remote systems.
4881 "Continuing.\[\r\n0-9\]+${extra}(... EXIT code 0\[\r\n\]+|$inferior_exited_re normally).*"\
4886 proc rerun_to_main {} {
4887 global gdb_prompt use_gdb_stub
4892 -re ".*Breakpoint .*main .*$gdb_prompt $"\
4893 {pass "rerun to main" ; return 0}
4894 -re "$gdb_prompt $"\
4895 {fail "rerun to main" ; return 0}
4896 timeout {fail "(timeout) rerun to main" ; return 0}
4901 -re "The program .* has been started already.*y or n. $" {
4905 -re "Starting program.*$gdb_prompt $"\
4906 {pass "rerun to main" ; return 0}
4907 -re "$gdb_prompt $"\
4908 {fail "rerun to main" ; return 0}
4909 timeout {fail "(timeout) rerun to main" ; return 0}
4914 # Return true if a test should be skipped due to lack of floating
4915 # point support or GDB can't fetch the contents from floating point
4918 gdb_caching_proc gdb_skip_float_test {
4919 if [target_info exists gdb,skip_float_tests] {
4923 # There is an ARM kernel ptrace bug that hardware VFP registers
4924 # are not updated after GDB ptrace set VFP registers. The bug
4925 # was introduced by kernel commit 8130b9d7b9d858aa04ce67805e8951e3cb6e9b2f
4926 # in 2012 and is fixed in e2dfb4b880146bfd4b6aa8e138c0205407cebbaf
4927 # in May 2016. In other words, kernels older than 4.6.3, 4.4.14,
4928 # 4.1.27, 3.18.36, and 3.14.73 have this bug.
4929 # This kernel bug is detected by check how does GDB change the
4930 # program result by changing one VFP register.
4931 if { [istarget "arm*-*-linux*"] } {
4933 set compile_flags {debug nowarnings }
4935 # Set up, compile, and execute a test program having VFP
4937 set src [standard_temp_file arm_vfp[pid].c]
4938 set exe [standard_temp_file arm_vfp[pid].x]
4940 gdb_produce_source $src {
4945 asm ("vldr d0, [%0]" : : "r" (&d));
4946 asm ("vldr d1, [%0]" : : "r" (&d));
4947 asm (".global break_here\n"
4949 asm ("vcmp.f64 d0, d1\n"
4950 "vmrs APSR_nzcv, fpscr\n"
4951 "bne L_value_different\n"
4954 "L_value_different:\n"
4956 "L_end:\n" : "=r" (ret) :);
4958 /* Return $d0 != $d1. */
4963 verbose "compiling testfile $src" 2
4964 set lines [gdb_compile $src $exe executable $compile_flags]
4967 if ![string match "" $lines] then {
4968 verbose "testfile compilation failed, returning 1" 2
4972 # No error message, compilation succeeded so now run it via gdb.
4973 # Run the test up to 5 times to detect whether ptrace can
4974 # correctly update VFP registers or not.
4976 for {set i 0} {$i < 5} {incr i} {
4977 global gdb_prompt srcdir subdir
4981 gdb_reinitialize_dir $srcdir/$subdir
4985 gdb_test "break *break_here"
4986 gdb_continue_to_breakpoint "break_here"
4988 # Modify $d0 to a different value, so the exit code should
4990 gdb_test "set \$d0 = 5.0"
4992 set test "continue to exit"
4993 gdb_test_multiple "continue" "$test" {
4994 -re "exited with code 01.*$gdb_prompt $" {
4996 -re "exited normally.*$gdb_prompt $" {
4997 # However, the exit code is 0. That means something
4998 # wrong in setting VFP registers.
5006 remote_file build delete $exe
5008 return $skip_vfp_test
5013 # Print a message and return true if a test should be skipped
5014 # due to lack of stdio support.
5016 proc gdb_skip_stdio_test { msg } {
5017 if [target_info exists gdb,noinferiorio] {
5018 verbose "Skipping test '$msg': no inferior i/o."
5024 proc gdb_skip_bogus_test { msg } {
5028 # Return true if a test should be skipped due to lack of XML support
5030 # NOTE: This must be called while gdb is *not* running.
5032 gdb_caching_proc gdb_skip_xml_test {
5037 if { [info exists gdb_spawn_id] } {
5038 error "GDB must not be running in gdb_skip_xml_tests."
5041 set xml_file [gdb_remote_download host "${srcdir}/gdb.xml/trivial.xml"]
5045 gdb_test_multiple "set tdesc filename $xml_file" "" {
5046 -re ".*XML support was disabled at compile time.*$gdb_prompt $" {
5049 -re ".*$gdb_prompt $" { }
5055 # Return true if argv[0] is available.
5057 gdb_caching_proc gdb_has_argv0 {
5060 # Set up, compile, and execute a test program to check whether
5061 # argv[0] is available.
5062 set src [standard_temp_file has_argv0[pid].c]
5063 set exe [standard_temp_file has_argv0[pid].x]
5065 gdb_produce_source $src {
5066 int main (int argc, char **argv) {
5071 gdb_compile $src $exe executable {debug}
5074 proc gdb_has_argv0_1 { exe } {
5075 global srcdir subdir
5076 global gdb_prompt hex
5080 gdb_reinitialize_dir $srcdir/$subdir
5083 # Set breakpoint on main.
5084 gdb_test_multiple "break main" "break main" {
5085 -re "Breakpoint.*${gdb_prompt} $" {
5087 -re "${gdb_prompt} $" {
5094 gdb_test_multiple "" "run to main" {
5095 -re "Breakpoint.*${gdb_prompt} $" {
5097 -re "${gdb_prompt} $" {
5102 set old_elements "200"
5103 set test "show print elements"
5104 gdb_test_multiple $test $test {
5105 -re "Limit on string chars or array elements to print is (\[^\r\n\]+)\\.\r\n$gdb_prompt $" {
5106 set old_elements $expect_out(1,string)
5109 set old_repeats "200"
5110 set test "show print repeats"
5111 gdb_test_multiple $test $test {
5112 -re "Threshold for repeated print elements is (\[^\r\n\]+)\\.\r\n$gdb_prompt $" {
5113 set old_repeats $expect_out(1,string)
5116 gdb_test_no_output "set print elements unlimited" ""
5117 gdb_test_no_output "set print repeats unlimited" ""
5120 # Check whether argc is 1.
5121 gdb_test_multiple "p argc" "p argc" {
5122 -re " = 1\r\n${gdb_prompt} $" {
5124 gdb_test_multiple "p argv\[0\]" "p argv\[0\]" {
5125 -re " = $hex \".*[file tail $exe]\"\r\n${gdb_prompt} $" {
5128 -re "${gdb_prompt} $" {
5132 -re "${gdb_prompt} $" {
5136 gdb_test_no_output "set print elements $old_elements" ""
5137 gdb_test_no_output "set print repeats $old_repeats" ""
5142 set result [gdb_has_argv0_1 $exe]
5149 && ([istarget *-*-linux*]
5150 || [istarget *-*-freebsd*] || [istarget *-*-kfreebsd*]
5151 || [istarget *-*-netbsd*] || [istarget *-*-knetbsd*]
5152 || [istarget *-*-openbsd*]
5153 || [istarget *-*-darwin*]
5154 || [istarget *-*-solaris*]
5155 || [istarget *-*-aix*]
5156 || [istarget *-*-gnu*]
5157 || [istarget *-*-cygwin*] || [istarget *-*-mingw32*]
5158 || [istarget *-*-*djgpp*] || [istarget *-*-go32*]
5159 || [istarget *-wince-pe] || [istarget *-*-mingw32ce*]
5160 || [istarget *-*-symbianelf*]
5161 || [istarget *-*-osf*]
5162 || [istarget *-*-dicos*]
5163 || [istarget *-*-nto*]
5164 || [istarget *-*-*vms*]
5165 || [istarget *-*-lynx*178]) } {
5166 fail "argv\[0\] should be available on this target"
5172 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
5173 # ${binfile}.dbglnk, which is just like the executable ($binfile) but without
5174 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
5175 # the name of a debuginfo only file. This file will be stored in the same
5178 # Functions for separate debug info testing
5180 # starting with an executable:
5181 # foo --> original executable
5183 # at the end of the process we have:
5184 # foo.stripped --> foo w/o debug info
5185 # foo.debug --> foo's debug info
5186 # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug.
5188 # Fetch the build id from the file.
5189 # Returns "" if there is none.
5191 proc get_build_id { filename } {
5192 if { ([istarget "*-*-mingw*"]
5193 || [istarget *-*-cygwin*]) } {
5194 set objdump_program [gdb_find_objdump]
5195 set result [catch {set data [exec $objdump_program -p $filename | grep signature | cut "-d " -f4]} output]
5196 verbose "result is $result"
5197 verbose "output is $output"
5203 set tmp [standard_output_file "${filename}-tmp"]
5204 set objcopy_program [gdb_find_objcopy]
5205 set result [catch "exec $objcopy_program -j .note.gnu.build-id -O binary $filename $tmp" output]
5206 verbose "result is $result"
5207 verbose "output is $output"
5212 fconfigure $fi -translation binary
5213 # Skip the NOTE header.
5218 if ![string compare $data ""] then {
5221 # Convert it to hex.
5222 binary scan $data H* data
5227 # Return the build-id hex string (usually 160 bits as 40 hex characters)
5228 # converted to the form: .build-id/ab/cdef1234...89.debug
5229 # Return "" if no build-id found.
5230 proc build_id_debug_filename_get { filename } {
5231 set data [get_build_id $filename]
5232 if { $data == "" } {
5235 regsub {^..} $data {\0/} data
5236 return ".build-id/${data}.debug"
5239 # Create stripped files for DEST, replacing it. If ARGS is passed, it is a
5240 # list of optional flags. The only currently supported flag is no-main,
5241 # which removes the symbol entry for main from the separate debug file.
5243 # Function returns zero on success. Function will return non-zero failure code
5244 # on some targets not supporting separate debug info (such as i386-msdos).
5246 proc gdb_gnu_strip_debug { dest args } {
5248 # Use the first separate debug info file location searched by GDB so the
5249 # run cannot be broken by some stale file searched with higher precedence.
5250 set debug_file "${dest}.debug"
5252 set strip_to_file_program [transform strip]
5253 set objcopy_program [gdb_find_objcopy]
5255 set debug_link [file tail $debug_file]
5256 set stripped_file "${dest}.stripped"
5258 # Get rid of the debug info, and store result in stripped_file
5259 # something like gdb/testsuite/gdb.base/blah.stripped.
5260 set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
5261 verbose "result is $result"
5262 verbose "output is $output"
5267 # Workaround PR binutils/10802:
5268 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
5269 set perm [file attributes ${dest} -permissions]
5270 file attributes ${stripped_file} -permissions $perm
5272 # Get rid of everything but the debug info, and store result in debug_file
5273 # This will be in the .debug subdirectory, see above.
5274 set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
5275 verbose "result is $result"
5276 verbose "output is $output"
5281 # If no-main is passed, strip the symbol for main from the separate
5282 # file. This is to simulate the behavior of elfutils's eu-strip, which
5283 # leaves the symtab in the original file only. There's no way to get
5284 # objcopy or strip to remove the symbol table without also removing the
5285 # debugging sections, so this is as close as we can get.
5286 if { [llength $args] == 1 && [lindex $args 0] == "no-main" } {
5287 set result [catch "exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp" output]
5288 verbose "result is $result"
5289 verbose "output is $output"
5293 file delete "${debug_file}"
5294 file rename "${debug_file}-tmp" "${debug_file}"
5297 # Link the two previous output files together, adding the .gnu_debuglink
5298 # section to the stripped_file, containing a pointer to the debug_file,
5299 # save the new file in dest.
5300 # This will be the regular executable filename, in the usual location.
5301 set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
5302 verbose "result is $result"
5303 verbose "output is $output"
5308 # Workaround PR binutils/10802:
5309 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
5310 set perm [file attributes ${stripped_file} -permissions]
5311 file attributes ${dest} -permissions $perm
5316 # Test the output of GDB_COMMAND matches the pattern obtained
5317 # by concatenating all elements of EXPECTED_LINES. This makes
5318 # it possible to split otherwise very long string into pieces.
5319 # If third argument is not empty, it's used as the name of the
5320 # test to be printed on pass/fail.
5321 proc help_test_raw { gdb_command expected_lines args } {
5322 set message $gdb_command
5323 if [llength $args]>0 then {
5324 set message [lindex $args 0]
5326 set expected_output [join $expected_lines ""]
5327 gdb_test "${gdb_command}" "${expected_output}" $message
5330 # Test the output of "help COMMAND_CLASS". EXPECTED_INITIAL_LINES
5331 # are regular expressions that should match the beginning of output,
5332 # before the list of commands in that class. The presence of
5333 # command list and standard epilogue will be tested automatically.
5334 # Notice that the '[' and ']' characters don't need to be escaped for strings
5335 # wrapped in {} braces.
5336 proc test_class_help { command_class expected_initial_lines args } {
5338 "List of commands\:.*[\r\n]+"
5339 "Type \"help\" followed by command name for full documentation\.[\r\n]+"
5340 "Type \"apropos word\" to search for commands related to \"word\"\.[\r\n]+"
5341 "Command name abbreviations are allowed if unambiguous\."
5343 set l_entire_body [concat $expected_initial_lines $l_stock_body]
5345 eval [list help_test_raw "help ${command_class}" $l_entire_body] $args
5348 # COMMAND_LIST should have either one element -- command to test, or
5349 # two elements -- abbreviated command to test, and full command the first
5350 # element is abbreviation of.
5351 # The command must be a prefix command. EXPECTED_INITIAL_LINES
5352 # are regular expressions that should match the beginning of output,
5353 # before the list of subcommands. The presence of
5354 # subcommand list and standard epilogue will be tested automatically.
5355 proc test_prefix_command_help { command_list expected_initial_lines args } {
5356 set command [lindex $command_list 0]
5357 if {[llength $command_list]>1} {
5358 set full_command [lindex $command_list 1]
5360 set full_command $command
5362 # Use 'list' and not just {} because we want variables to
5363 # be expanded in this list.
5364 set l_stock_body [list\
5365 "List of $full_command subcommands\:.*\[\r\n\]+"\
5366 "Type \"help $full_command\" followed by $full_command subcommand name for full documentation\.\[\r\n\]+"\
5367 "Type \"apropos word\" to search for commands related to \"word\"\.\[\r\n\]+"\
5368 "Command name abbreviations are allowed if unambiguous\."]
5369 set l_entire_body [concat $expected_initial_lines $l_stock_body]
5370 if {[llength $args]>0} {
5371 help_test_raw "help ${command}" $l_entire_body [lindex $args 0]
5373 help_test_raw "help ${command}" $l_entire_body
5377 # Build executable named EXECUTABLE from specifications that allow
5378 # different options to be passed to different sub-compilations.
5379 # TESTNAME is the name of the test; this is passed to 'untested' if
5381 # OPTIONS is passed to the final link, using gdb_compile. If OPTIONS
5382 # contains the option "pthreads", then gdb_compile_pthreads is used.
5383 # ARGS is a flat list of source specifications, of the form:
5384 # { SOURCE1 OPTIONS1 [ SOURCE2 OPTIONS2 ]... }
5385 # Each SOURCE is compiled to an object file using its OPTIONS,
5386 # using gdb_compile.
5387 # Returns 0 on success, -1 on failure.
5388 proc build_executable_from_specs {testname executable options args} {
5392 set binfile [standard_output_file $executable]
5395 if { [lsearch -exact $options "c++"] >= 0 } {
5396 set info_options "c++"
5398 if [get_compiler_info ${info_options}] {
5402 set func gdb_compile
5403 set func_index [lsearch -regexp $options {^(pthreads|shlib|shlib_pthreads)$}]
5404 if {$func_index != -1} {
5405 set func "${func}_[lindex $options $func_index]"
5408 # gdb_compile_shlib and gdb_compile_shlib_pthreads do not use the 3rd
5409 # parameter. They also requires $sources while gdb_compile and
5410 # gdb_compile_pthreads require $objects. Moreover they ignore any options.
5411 if [string match gdb_compile_shlib* $func] {
5413 foreach {s local_options} $args {
5414 if { [regexp "^/" "$s"] } then {
5415 lappend sources_path "$s"
5417 lappend sources_path "$srcdir/$subdir/$s"
5420 set ret [$func $sources_path "${binfile}" $options]
5421 } elseif {[lsearch -exact $options rust] != -1} {
5423 foreach {s local_options} $args {
5424 if { [regexp "^/" "$s"] } then {
5425 lappend sources_path "$s"
5427 lappend sources_path "$srcdir/$subdir/$s"
5430 set ret [gdb_compile_rust $sources_path "${binfile}" $options]
5434 foreach {s local_options} $args {
5435 if { ! [regexp "^/" "$s"] } then {
5436 set s "$srcdir/$subdir/$s"
5438 if { [gdb_compile "${s}" "${binfile}${i}.o" object $local_options] != "" } {
5442 lappend objects "${binfile}${i}.o"
5445 set ret [$func $objects "${binfile}" executable $options]
5455 # Build executable named EXECUTABLE, from SOURCES. If SOURCES are not
5456 # provided, uses $EXECUTABLE.c. The TESTNAME paramer is the name of test
5457 # to pass to untested, if something is wrong. OPTIONS are passed
5458 # to gdb_compile directly.
5459 proc build_executable { testname executable {sources ""} {options {debug}} } {
5460 if {[llength $sources]==0} {
5461 set sources ${executable}.c
5464 set arglist [list $testname $executable $options]
5465 foreach source $sources {
5466 lappend arglist $source $options
5469 return [eval build_executable_from_specs $arglist]
5472 # Starts fresh GDB binary and loads an optional executable into GDB.
5473 # Usage: clean_restart [executable]
5474 # EXECUTABLE is the basename of the binary.
5476 proc clean_restart { args } {
5480 if { [llength $args] > 1 } {
5481 error "bad number of args: [llength $args]"
5486 gdb_reinitialize_dir $srcdir/$subdir
5488 if { [llength $args] >= 1 } {
5489 set executable [lindex $args 0]
5490 set binfile [standard_output_file ${executable}]
5495 # Prepares for testing by calling build_executable_full, then
5497 # TESTNAME is the name of the test.
5498 # Each element in ARGS is a list of the form
5499 # { EXECUTABLE OPTIONS SOURCE_SPEC... }
5500 # These are passed to build_executable_from_specs, which see.
5501 # The last EXECUTABLE is passed to clean_restart.
5502 # Returns 0 on success, non-zero on failure.
5503 proc prepare_for_testing_full {testname args} {
5504 foreach spec $args {
5505 if {[eval build_executable_from_specs [list $testname] $spec] == -1} {
5508 set executable [lindex $spec 0]
5510 clean_restart $executable
5514 # Prepares for testing, by calling build_executable, and then clean_restart.
5515 # Please refer to build_executable for parameter description.
5516 proc prepare_for_testing { testname executable {sources ""} {options {debug}}} {
5518 if {[build_executable $testname $executable $sources $options] == -1} {
5521 clean_restart $executable
5526 proc get_valueof { fmt exp default } {
5529 set test "get valueof \"${exp}\""
5531 gdb_test_multiple "print${fmt} ${exp}" "$test" {
5532 -re "\\$\[0-9\]* = (.*)\[\r\n\]*$gdb_prompt $" {
5533 set val $expect_out(1,string)
5537 fail "$test (timeout)"
5543 proc get_integer_valueof { exp default } {
5546 set test "get integer valueof \"${exp}\""
5548 gdb_test_multiple "print /d ${exp}" "$test" {
5549 -re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" {
5550 set val $expect_out(1,string)
5554 fail "$test (timeout)"
5560 # Retrieve the value of EXP in the inferior, as an hexadecimal value
5561 # (using "print /x"). DEFAULT is used as fallback if print fails.
5562 # TEST is the test message to use. If can be ommitted, in which case
5563 # a test message is built from EXP.
5565 proc get_hexadecimal_valueof { exp default {test ""} } {
5569 set test "get hexadecimal valueof \"${exp}\""
5573 gdb_test_multiple "print /x ${exp}" $test {
5574 -re "\\$\[0-9\]* = (0x\[0-9a-zA-Z\]+).*$gdb_prompt $" {
5575 set val $expect_out(1,string)
5582 proc get_sizeof { type default } {
5583 return [get_integer_valueof "sizeof (${type})" $default]
5586 proc get_target_charset { } {
5589 gdb_test_multiple "show target-charset" "" {
5590 -re "The target character set is \"auto; currently (\[^\"\]*)\".*$gdb_prompt $" {
5591 return $expect_out(1,string)
5593 -re "The target character set is \"(\[^\"\]*)\".*$gdb_prompt $" {
5594 return $expect_out(1,string)
5598 # Pick a reasonable default.
5599 warning "Unable to read target-charset."
5603 # Get the address of VAR.
5605 proc get_var_address { var } {
5606 global gdb_prompt hex
5608 # Match output like:
5610 # $5 = (int (*)()) 0
5611 # $6 = (int (*)()) 0x24 <function_bar>
5613 gdb_test_multiple "print &${var}" "get address of ${var}" {
5614 -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $"
5616 pass "get address of ${var}"
5617 if { $expect_out(1,string) == "0" } {
5620 return $expect_out(1,string)
5627 # Get the current value for remotetimeout and return it.
5628 proc get_remotetimeout { } {
5632 gdb_test_multiple "show remotetimeout" "" {
5633 -re "Timeout limit to wait for target to respond is ($decimal).*$gdb_prompt $" {
5634 return $expect_out(1,string)
5638 # Pick the default that gdb uses
5639 warning "Unable to read remotetimeout"
5643 # Set the remotetimeout to the specified timeout. Nothing is returned.
5644 proc set_remotetimeout { timeout } {
5647 gdb_test_multiple "set remotetimeout $timeout" "" {
5648 -re "$gdb_prompt $" {
5649 verbose "Set remotetimeout to $timeout\n"
5654 # ROOT and FULL are file names. Returns the relative path from ROOT
5655 # to FULL. Note that FULL must be in a subdirectory of ROOT.
5656 # For example, given ROOT = /usr/bin and FULL = /usr/bin/ls, this
5659 proc relative_filename {root full} {
5660 set root_split [file split $root]
5661 set full_split [file split $full]
5663 set len [llength $root_split]
5665 if {[eval file join $root_split]
5666 != [eval file join [lrange $full_split 0 [expr {$len - 1}]]]} {
5667 error "$full not a subdir of $root"
5670 return [eval file join [lrange $full_split $len end]]
5673 # Log gdb command line and script if requested.
5674 if {[info exists TRANSCRIPT]} {
5675 rename send_gdb real_send_gdb
5676 rename remote_spawn real_remote_spawn
5677 rename remote_close real_remote_close
5679 global gdb_transcript
5680 set gdb_transcript ""
5682 global gdb_trans_count
5683 set gdb_trans_count 1
5685 proc remote_spawn {args} {
5686 global gdb_transcript gdb_trans_count outdir
5688 if {$gdb_transcript != ""} {
5689 close $gdb_transcript
5691 set gdb_transcript [open [file join $outdir transcript.$gdb_trans_count] w]
5692 puts $gdb_transcript [lindex $args 1]
5693 incr gdb_trans_count
5695 return [uplevel real_remote_spawn $args]
5698 proc remote_close {args} {
5699 global gdb_transcript
5701 if {$gdb_transcript != ""} {
5702 close $gdb_transcript
5703 set gdb_transcript ""
5706 return [uplevel real_remote_close $args]
5709 proc send_gdb {args} {
5710 global gdb_transcript
5712 if {$gdb_transcript != ""} {
5713 puts -nonewline $gdb_transcript [lindex $args 0]
5716 return [uplevel real_send_gdb $args]
5720 # If GDB_PARALLEL exists, then set up the parallel-mode directories.
5721 if {[info exists GDB_PARALLEL]} {
5722 if {[is_remote host]} {
5726 [make_gdb_parallel_path outputs] \
5727 [make_gdb_parallel_path temp] \
5728 [make_gdb_parallel_path cache]
5732 proc core_find {binfile {deletefiles {}} {arg ""}} {
5733 global objdir subdir
5735 set destcore "$binfile.core"
5736 file delete $destcore
5738 # Create a core file named "$destcore" rather than just "core", to
5739 # avoid problems with sys admin types that like to regularly prune all
5740 # files named "core" from the system.
5742 # Arbitrarily try setting the core size limit to "unlimited" since
5743 # this does not hurt on systems where the command does not work and
5744 # allows us to generate a core on systems where it does.
5746 # Some systems append "core" to the name of the program; others append
5747 # the name of the program to "core"; still others (like Linux, as of
5748 # May 2003) create cores named "core.PID". In the latter case, we
5749 # could have many core files lying around, and it may be difficult to
5750 # tell which one is ours, so let's run the program in a subdirectory.
5752 set coredir [standard_output_file coredir.[getpid]]
5754 catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile} ${arg}; true) >/dev/null 2>&1\""
5755 # remote_exec host "${binfile}"
5756 foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
5757 if [remote_file build exists $i] {
5758 remote_exec build "mv $i $destcore"
5762 # Check for "core.PID".
5763 if { $found == 0 } {
5764 set names [glob -nocomplain -directory $coredir core.*]
5765 if {[llength $names] == 1} {
5766 set corefile [file join $coredir [lindex $names 0]]
5767 remote_exec build "mv $corefile $destcore"
5771 if { $found == 0 } {
5772 # The braindamaged HPUX shell quits after the ulimit -c above
5773 # without executing ${binfile}. So we try again without the
5774 # ulimit here if we didn't find a core file above.
5775 # Oh, I should mention that any "braindamaged" non-Unix system has
5776 # the same problem. I like the cd bit too, it's really neat'n stuff.
5777 catch "system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\""
5778 foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" {
5779 if [remote_file build exists $i] {
5780 remote_exec build "mv $i $destcore"
5786 # Try to clean up after ourselves.
5787 foreach deletefile $deletefiles {
5788 remote_file build delete [file join $coredir $deletefile]
5790 remote_exec build "rmdir $coredir"
5792 if { $found == 0 } {
5793 warning "can't generate a core file - core tests suppressed - check ulimit -c"
5799 # gdb_target_symbol_prefix compiles a test program and then examines
5800 # the output from objdump to determine the prefix (such as underscore)
5801 # for linker symbol prefixes.
5803 gdb_caching_proc gdb_target_symbol_prefix {
5804 # Set up and compile a simple test program...
5805 set src [standard_temp_file main[pid].c]
5806 set exe [standard_temp_file main[pid].x]
5808 gdb_produce_source $src {
5814 verbose "compiling testfile $src" 2
5815 set compile_flags {debug nowarnings quiet}
5816 set lines [gdb_compile $src $exe executable $compile_flags]
5820 if ![string match "" $lines] then {
5821 verbose "gdb_target_symbol_prefix: testfile compilation failed, returning null prefix" 2
5823 set objdump_program [gdb_find_objdump]
5824 set result [catch "exec $objdump_program --syms $exe" output]
5827 && ![regexp -lineanchor \
5828 { ([^ a-zA-Z0-9]*)main$} $output dummy prefix] } {
5829 verbose "gdb_target_symbol_prefix: Could not find main in objdump output; returning null prefix" 2
5839 # gdb_target_symbol returns the provided symbol with the correct prefix
5840 # prepended. (See gdb_target_symbol_prefix, above.)
5842 proc gdb_target_symbol { symbol } {
5843 set prefix [gdb_target_symbol_prefix]
5844 return "${prefix}${symbol}"
5847 # gdb_target_symbol_prefix_flags_asm returns a string that can be
5848 # added to gdb_compile options to define the C-preprocessor macro
5849 # SYMBOL_PREFIX with a value that can be prepended to symbols
5850 # for targets which require a prefix, such as underscore.
5852 # This version (_asm) defines the prefix without double quotes
5853 # surrounding the prefix. It is used to define the macro
5854 # SYMBOL_PREFIX for assembly language files. Another version, below,
5855 # is used for symbols in inline assembler in C/C++ files.
5857 # The lack of quotes in this version (_asm) makes it possible to
5858 # define supporting macros in the .S file. (The version which
5859 # uses quotes for the prefix won't work for such files since it's
5860 # impossible to define a quote-stripping macro in C.)
5862 # It's possible to use this version (_asm) for C/C++ source files too,
5863 # but a string is usually required in such files; providing a version
5864 # (no _asm) which encloses the prefix with double quotes makes it
5865 # somewhat easier to define the supporting macros in the test case.
5867 proc gdb_target_symbol_prefix_flags_asm {} {
5868 set prefix [gdb_target_symbol_prefix]
5869 if {$prefix ne ""} {
5870 return "additional_flags=-DSYMBOL_PREFIX=$prefix"
5876 # gdb_target_symbol_prefix_flags returns the same string as
5877 # gdb_target_symbol_prefix_flags_asm, above, but with the prefix
5878 # enclosed in double quotes if there is a prefix.
5880 # See the comment for gdb_target_symbol_prefix_flags_asm for an
5881 # extended discussion.
5883 proc gdb_target_symbol_prefix_flags {} {
5884 set prefix [gdb_target_symbol_prefix]
5885 if {$prefix ne ""} {
5886 return "additional_flags=-DSYMBOL_PREFIX=\"$prefix\""
5892 # A wrapper for 'remote_exec host' that passes or fails a test.
5893 # Returns 0 if all went well, nonzero on failure.
5894 # TEST is the name of the test, other arguments are as for remote_exec.
5896 proc run_on_host { test program args } {
5897 verbose -log "run_on_host: $program $args"
5898 # remote_exec doesn't work properly if the output is set but the
5899 # input is the empty string -- so replace an empty input with
5901 if {[llength $args] > 1 && [lindex $args 1] == ""} {
5902 set args [lreplace $args 1 1 "/dev/null"]
5904 set result [eval remote_exec host [list $program] $args]
5905 verbose "result is $result"
5906 set status [lindex $result 0]
5907 set output [lindex $result 1]
5912 verbose -log "run_on_host failed: $output"
5918 # Return non-zero if "board_info debug_flags" mentions Fission.
5919 # http://gcc.gnu.org/wiki/DebugFission
5920 # Fission doesn't support everything yet.
5921 # This supports working around bug 15954.
5923 proc using_fission { } {
5924 set debug_flags [board_info [target_info name] debug_flags]
5925 return [regexp -- "-gsplit-dwarf" $debug_flags]
5928 # Search the caller's ARGS list and set variables according to the list of
5929 # valid options described by ARGSET.
5931 # The first member of each one- or two-element list in ARGSET defines the
5932 # name of a variable that will be added to the caller's scope.
5934 # If only one element is given to describe an option, it the value is
5935 # 0 if the option is not present in (the caller's) ARGS or 1 if
5938 # If two elements are given, the second element is the default value of
5939 # the variable. This is then overwritten if the option exists in ARGS.
5941 # Any parse_args elements in (the caller's) ARGS will be removed, leaving
5942 # any optional components.
5945 # proc myproc {foo args} {
5946 # parse_args {{bar} {baz "abc"} {qux}}
5949 # myproc ABC -bar -baz DEF peanut butter
5950 # will define the following variables in myproc:
5951 # foo (=ABC), bar (=1), baz (=DEF), and qux (=0)
5952 # args will be the list {peanut butter}
5954 proc parse_args { argset } {
5957 foreach argument $argset {
5958 if {[llength $argument] == 1} {
5959 # No default specified, so we assume that we should set
5960 # the value to 1 if the arg is present and 0 if it's not.
5961 # It is assumed that no value is given with the argument.
5962 set result [lsearch -exact $args "-$argument"]
5963 if {$result != -1} then {
5964 uplevel 1 [list set $argument 1]
5965 set args [lreplace $args $result $result]
5967 uplevel 1 [list set $argument 0]
5969 } elseif {[llength $argument] == 2} {
5970 # There are two items in the argument. The second is a
5971 # default value to use if the item is not present.
5972 # Otherwise, the variable is set to whatever is provided
5973 # after the item in the args.
5974 set arg [lindex $argument 0]
5975 set result [lsearch -exact $args "-[lindex $arg 0]"]
5976 if {$result != -1} then {
5977 uplevel 1 [list set $arg [lindex $args [expr $result+1]]]
5978 set args [lreplace $args $result [expr $result+1]]
5980 uplevel 1 [list set $arg [lindex $argument 1]]
5983 error "Badly formatted argument \"$argument\" in argument set"
5987 # The remaining args should be checked to see that they match the
5988 # number of items expected to be passed into the procedure...
5991 # Capture the output of COMMAND in a string ignoring PREFIX (a regexp);
5992 # return that string.
5994 proc capture_command_output { command prefix } {
5998 set output_string ""
5999 gdb_test_multiple "$command" "capture_command_output for $command" {
6000 -re "[string_to_regexp ${command}]\[\r\n\]+${prefix}(.*)\[\r\n\]+$gdb_prompt $" {
6001 set output_string $expect_out(1,string)
6004 return $output_string
6007 # A convenience function that joins all the arguments together, with a
6008 # regexp that matches exactly one end of line in between each argument.
6009 # This function is ideal to write the expected output of a GDB command
6010 # that generates more than a couple of lines, as this allows us to write
6011 # each line as a separate string, which is easier to read by a human
6014 proc multi_line { args } {
6015 return [join $args "\r\n"]
6018 # Similar to the above, but while multi_line is meant to be used to
6019 # match GDB output, this one is meant to be used to build strings to
6020 # send as GDB input.
6022 proc multi_line_input { args } {
6023 return [join $args "\n"]
6026 # Return the version of the DejaGnu framework.
6028 # The return value is a list containing the major, minor and patch version
6029 # numbers. If the version does not contain a minor or patch number, they will
6030 # be set to 0. For example:
6036 proc dejagnu_version { } {
6037 # The frame_version variable is defined by DejaGnu, in runtest.exp.
6038 global frame_version
6040 verbose -log "DejaGnu version: $frame_version"
6041 verbose -log "Expect version: [exp_version]"
6042 verbose -log "Tcl version: [info tclversion]"
6044 set dg_ver [split $frame_version .]
6046 while { [llength $dg_ver] < 3 } {
6053 # Always load compatibility stuff.