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 # Determine options that we always want to pass to the compiler.
3372 gdb_caching_proc universal_compile_options {
3373 set me "universal_compile_options"
3376 set src [standard_temp_file ccopts[pid].c]
3377 set obj [standard_temp_file ccopts[pid].o]
3379 gdb_produce_source $src {
3380 int foo(void) { return 0; }
3383 # Try an option for disabling colored diagnostics. Some compilers
3384 # yield colored diagnostics by default (when run from a tty) unless
3385 # such an option is specified.
3386 set opt "additional_flags=-fdiagnostics-color=never"
3387 set lines [target_compile $src $obj object [list "quiet" $opt]]
3388 if [string match "" $lines] then {
3389 # Seems to have worked; use the option.
3390 lappend options $opt
3395 verbose "$me: returning $options" 2
3399 # Some targets need to always link a special object in. Save its path here.
3400 global gdb_saved_set_unbuffered_mode_obj
3401 set gdb_saved_set_unbuffered_mode_obj ""
3403 # Compile source files specified by SOURCE into a binary of type TYPE at path
3404 # DEST. gdb_compile is implemented using DejaGnu's target_compile, so the type
3405 # parameter and most options are passed directly to it.
3407 # The type can be one of the following:
3409 # - object: Compile into an object file.
3410 # - executable: Compile and link into an executable.
3411 # - preprocess: Preprocess the source files.
3412 # - assembly: Generate assembly listing.
3414 # The following options are understood and processed by gdb_compile:
3416 # - shlib=so_path: Add SO_PATH to the sources, and enable some target-specific
3417 # quirks to be able to use shared libraries.
3418 # - shlib_load: Link with appropriate libraries to allow the test to
3419 # dynamically load libraries at runtime. For example, on Linux, this adds
3420 # -ldl so that the test can use dlopen.
3421 # - nowarnings: Inhibit all compiler warnings.
3423 # And here are some of the not too obscure options understood by DejaGnu that
3424 # influence the compilation:
3426 # - additional_flags=flag: Add FLAG to the compiler flags.
3427 # - libs=library: Add LIBRARY to the libraries passed to the linker. The
3428 # argument can be a file, in which case it's added to the sources, or a
3430 # - ldflags=flag: Add FLAG to the linker flags.
3431 # - incdir=path: Add PATH to the searched include directories.
3432 # - libdir=path: Add PATH to the linker searched directories.
3433 # - ada, c++, f77: Compile the file as Ada, C++ or Fortran.
3434 # - debug: Build with debug information.
3435 # - optimize: Build with optimization.
3437 proc gdb_compile {source dest type options} {
3438 global GDB_TESTCASE_OPTIONS
3439 global gdb_wrapper_file
3440 global gdb_wrapper_flags
3441 global gdb_wrapper_initialized
3444 global gdb_saved_set_unbuffered_mode_obj
3446 set outdir [file dirname $dest]
3448 # Add platform-specific options if a shared library was specified using
3449 # "shlib=librarypath" in OPTIONS.
3450 if {[lsearch -exact $options rust] != -1} {
3451 # -fdiagnostics-color is not a rustcc option.
3453 set new_options [universal_compile_options]
3458 foreach opt $options {
3459 if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] {
3460 if [test_compiler_info "xlc-*"] {
3461 # IBM xlc compiler doesn't accept shared library named other
3462 # than .so: use "-Wl," to bypass this
3463 lappend source "-Wl,$shlib_name"
3464 } elseif { ([istarget "*-*-mingw*"]
3465 || [istarget *-*-cygwin*]
3466 || [istarget *-*-pe*])} {
3467 lappend source "${shlib_name}.a"
3469 lappend source $shlib_name
3471 if { $shlib_found == 0 } {
3473 if { ([istarget "*-*-mingw*"]
3474 || [istarget *-*-cygwin*]) } {
3475 lappend new_options "additional_flags=-Wl,--enable-auto-import"
3477 if { [test_compiler_info "gcc-*"] || [test_compiler_info "clang-*"] } {
3478 # Undo debian's change in the default.
3479 # Put it at the front to not override any user-provided
3480 # value, and to make sure it appears in front of all the
3482 lappend new_options "early_flags=-Wl,--no-as-needed"
3485 } elseif { $opt == "shlib_load" } {
3488 lappend new_options $opt
3492 # Because we link with libraries using their basename, we may need
3493 # (depending on the platform) to set a special rpath value, to allow
3494 # the executable to find the libraries it depends on.
3495 if { $shlib_load || $shlib_found } {
3496 if { ([istarget "*-*-mingw*"]
3497 || [istarget *-*-cygwin*]
3498 || [istarget *-*-pe*]) } {
3499 # Do not need anything.
3500 } elseif { [istarget *-*-freebsd*] || [istarget *-*-openbsd*] } {
3501 lappend new_options "ldflags=-Wl,-rpath,${outdir}"
3502 } elseif { [istarget arm*-*-symbianelf*] } {
3503 if { $shlib_load } {
3504 lappend new_options "libs=-ldl"
3507 if { $shlib_load } {
3508 lappend new_options "libs=-ldl"
3510 lappend new_options "ldflags=-Wl,-rpath,\\\$ORIGIN"
3513 set options $new_options
3515 if [info exists GDB_TESTCASE_OPTIONS] {
3516 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS"
3518 verbose "options are $options"
3519 verbose "source is $source $dest $type $options"
3521 if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init }
3523 if {[target_info exists needs_status_wrapper] && \
3524 [target_info needs_status_wrapper] != "0" && \
3525 [info exists gdb_wrapper_file]} {
3526 lappend options "libs=${gdb_wrapper_file}"
3527 lappend options "ldflags=${gdb_wrapper_flags}"
3530 # Replace the "nowarnings" option with the appropriate additional_flags
3531 # to disable compiler warnings.
3532 set nowarnings [lsearch -exact $options nowarnings]
3533 if {$nowarnings != -1} {
3534 if [target_info exists gdb,nowarnings_flag] {
3535 set flag "additional_flags=[target_info gdb,nowarnings_flag]"
3537 set flag "additional_flags=-w"
3539 set options [lreplace $options $nowarnings $nowarnings $flag]
3542 if { $type == "executable" } {
3543 if { ([istarget "*-*-mingw*"]
3544 || [istarget "*-*-*djgpp"]
3545 || [istarget "*-*-cygwin*"])} {
3546 # Force output to unbuffered mode, by linking in an object file
3547 # with a global contructor that calls setvbuf.
3549 # Compile the special object seperatelly for two reasons:
3550 # 1) Insulate it from $options.
3551 # 2) Avoid compiling it for every gdb_compile invocation,
3552 # which is time consuming, especially if we're remote
3555 if { $gdb_saved_set_unbuffered_mode_obj == "" } {
3556 verbose "compiling gdb_saved_set_unbuffered_obj"
3557 set unbuf_src ${srcdir}/lib/set_unbuffered_mode.c
3558 set unbuf_obj ${objdir}/set_unbuffered_mode.o
3560 set result [gdb_compile "${unbuf_src}" "${unbuf_obj}" object {nowarnings}]
3561 if { $result != "" } {
3564 if {[is_remote host]} {
3565 set gdb_saved_set_unbuffered_mode_obj set_unbuffered_mode_saved.o
3567 set gdb_saved_set_unbuffered_mode_obj ${objdir}/set_unbuffered_mode_saved.o
3569 # Link a copy of the output object, because the
3570 # original may be automatically deleted.
3571 remote_download host $unbuf_obj $gdb_saved_set_unbuffered_mode_obj
3573 verbose "gdb_saved_set_unbuffered_obj already compiled"
3576 # Rely on the internal knowledge that the global ctors are ran in
3577 # reverse link order. In that case, we can use ldflags to
3578 # avoid copying the object file to the host multiple
3580 # This object can only be added if standard libraries are
3581 # used. Thus, we need to disable it if -nostdlib option is used
3582 if {[lsearch -regexp $options "-nostdlib"] < 0 } {
3583 lappend options "ldflags=$gdb_saved_set_unbuffered_mode_obj"
3588 set result [target_compile $source $dest $type $options]
3590 # Prune uninteresting compiler (and linker) output.
3591 regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result
3593 regsub "\[\r\n\]*$" "$result" "" result
3594 regsub "^\[\r\n\]*" "$result" "" result
3596 if {[lsearch $options quiet] < 0} {
3597 # We shall update this on a per language basis, to avoid
3598 # changing the entire testsuite in one go.
3599 if {[lsearch $options f77] >= 0} {
3600 gdb_compile_test $source $result
3601 } elseif { $result != "" } {
3602 clone_output "gdb compile failed, $result"
3609 # This is just like gdb_compile, above, except that it tries compiling
3610 # against several different thread libraries, to see which one this
3612 proc gdb_compile_pthreads {source dest type options} {
3614 set why_msg "unrecognized error"
3615 foreach lib {-lpthreads -lpthread -lthread ""} {
3616 # This kind of wipes out whatever libs the caller may have
3617 # set. Or maybe theirs will override ours. How infelicitous.
3618 set options_with_lib [concat $options [list libs=$lib quiet]]
3619 set ccout [gdb_compile $source $dest $type $options_with_lib]
3620 switch -regexp -- $ccout {
3621 ".*no posix threads support.*" {
3622 set why_msg "missing threads include file"
3625 ".*cannot open -lpthread.*" {
3626 set why_msg "missing runtime threads library"
3628 ".*Can't find library for -lpthread.*" {
3629 set why_msg "missing runtime threads library"
3632 pass "successfully compiled posix threads test case"
3638 if {!$built_binfile} {
3639 unsupported "couldn't compile [file tail $source]: ${why_msg}"
3644 # Build a shared library from SOURCES.
3646 proc gdb_compile_shlib {sources dest options} {
3647 set obj_options $options
3650 if { [lsearch -exact $options "c++"] >= 0 } {
3651 set info_options "c++"
3653 if [get_compiler_info ${info_options}] {
3657 switch -glob [test_compiler_info] {
3659 lappend obj_options "additional_flags=-qpic"
3662 if { !([istarget "*-*-cygwin*"]
3663 || [istarget "*-*-mingw*"]) } {
3664 lappend obj_options "additional_flags=-fpic"
3668 if { !([istarget "powerpc*-*-aix*"]
3669 || [istarget "rs6000*-*-aix*"]
3670 || [istarget "*-*-cygwin*"]
3671 || [istarget "*-*-mingw*"]
3672 || [istarget "*-*-pe*"]) } {
3673 lappend obj_options "additional_flags=-fpic"
3677 lappend obj_options "additional_flags=-fpic"
3680 # don't know what the compiler is...
3684 set outdir [file dirname $dest]
3686 foreach source $sources {
3687 set sourcebase [file tail $source]
3688 if {[gdb_compile $source "${outdir}/${sourcebase}.o" object $obj_options] != ""} {
3691 lappend objects ${outdir}/${sourcebase}.o
3694 set link_options $options
3695 if [test_compiler_info "xlc-*"] {
3696 lappend link_options "additional_flags=-qmkshrobj"
3698 lappend link_options "additional_flags=-shared"
3700 if { ([istarget "*-*-mingw*"]
3701 || [istarget *-*-cygwin*]
3702 || [istarget *-*-pe*]) } {
3703 if { [is_remote host] } {
3704 set name [file tail ${dest}]
3708 lappend link_options "additional_flags=-Wl,--out-implib,${name}.a"
3710 # Set the soname of the library. This causes the linker on ELF
3711 # systems to create the DT_NEEDED entry in the executable referring
3712 # to the soname of the library, and not its absolute path. This
3713 # (using the absolute path) would be problem when testing on a
3716 # In conjunction with setting the soname, we add the special
3717 # rpath=$ORIGIN value when building the executable, so that it's
3718 # able to find the library in its own directory.
3719 set destbase [file tail $dest]
3720 lappend link_options "additional_flags=-Wl,-soname,$destbase"
3723 if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
3726 if { [is_remote host]
3727 && ([istarget "*-*-mingw*"]
3728 || [istarget *-*-cygwin*]
3729 || [istarget *-*-pe*]) } {
3730 set dest_tail_name [file tail ${dest}]
3731 remote_upload host $dest_tail_name.a ${dest}.a
3732 remote_file host delete $dest_tail_name.a
3738 # This is just like gdb_compile_shlib, above, except that it tries compiling
3739 # against several different thread libraries, to see which one this
3741 proc gdb_compile_shlib_pthreads {sources dest options} {
3743 set why_msg "unrecognized error"
3744 foreach lib {-lpthreads -lpthread -lthread ""} {
3745 # This kind of wipes out whatever libs the caller may have
3746 # set. Or maybe theirs will override ours. How infelicitous.
3747 set options_with_lib [concat $options [list libs=$lib quiet]]
3748 set ccout [gdb_compile_shlib $sources $dest $options_with_lib]
3749 switch -regexp -- $ccout {
3750 ".*no posix threads support.*" {
3751 set why_msg "missing threads include file"
3754 ".*cannot open -lpthread.*" {
3755 set why_msg "missing runtime threads library"
3757 ".*Can't find library for -lpthread.*" {
3758 set why_msg "missing runtime threads library"
3761 pass "successfully compiled posix threads test case"
3767 if {!$built_binfile} {
3768 unsupported "couldn't compile $sources: ${why_msg}"
3773 # This is just like gdb_compile_pthreads, above, except that we always add the
3774 # objc library for compiling Objective-C programs
3775 proc gdb_compile_objc {source dest type options} {
3777 set why_msg "unrecognized error"
3778 foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} {
3779 # This kind of wipes out whatever libs the caller may have
3780 # set. Or maybe theirs will override ours. How infelicitous.
3781 if { $lib == "solaris" } {
3782 set lib "-lpthread -lposix4"
3784 if { $lib != "-lobjc" } {
3785 set lib "-lobjc $lib"
3787 set options_with_lib [concat $options [list libs=$lib quiet]]
3788 set ccout [gdb_compile $source $dest $type $options_with_lib]
3789 switch -regexp -- $ccout {
3790 ".*no posix threads support.*" {
3791 set why_msg "missing threads include file"
3794 ".*cannot open -lpthread.*" {
3795 set why_msg "missing runtime threads library"
3797 ".*Can't find library for -lpthread.*" {
3798 set why_msg "missing runtime threads library"
3801 pass "successfully compiled objc with posix threads test case"
3807 if {!$built_binfile} {
3808 unsupported "couldn't compile [file tail $source]: ${why_msg}"
3813 proc send_gdb { string } {
3814 global suppress_flag
3815 if { $suppress_flag } {
3818 return [remote_send host "$string"]
3821 # Send STRING to the inferior's terminal.
3823 proc send_inferior { string } {
3824 global inferior_spawn_id
3826 if {[catch "send -i $inferior_spawn_id -- \$string" errorInfo]} {
3836 proc gdb_expect { args } {
3837 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
3838 set atimeout [lindex $args 0]
3839 set expcode [list [lindex $args 1]]
3844 # A timeout argument takes precedence, otherwise of all the timeouts
3845 # select the largest.
3846 if [info exists atimeout] {
3849 set tmt [get_largest_timeout]
3852 global suppress_flag
3853 global remote_suppress_flag
3854 if [info exists remote_suppress_flag] {
3855 set old_val $remote_suppress_flag
3857 if [info exists suppress_flag] {
3858 if { $suppress_flag } {
3859 set remote_suppress_flag 1
3863 {uplevel remote_expect host $tmt $expcode} string]
3864 if [info exists old_val] {
3865 set remote_suppress_flag $old_val
3867 if [info exists remote_suppress_flag] {
3868 unset remote_suppress_flag
3873 global errorInfo errorCode
3875 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
3877 return -code $code $string
3881 # gdb_expect_list TEST SENTINEL LIST -- expect a sequence of outputs
3883 # Check for long sequence of output by parts.
3884 # TEST: is the test message to be printed with the test success/fail.
3885 # SENTINEL: Is the terminal pattern indicating that output has finished.
3886 # LIST: is the sequence of outputs to match.
3887 # If the sentinel is recognized early, it is considered an error.
3890 # 1 if the test failed,
3891 # 0 if the test passes,
3892 # -1 if there was an internal error.
3894 proc gdb_expect_list {test sentinel list} {
3896 global suppress_flag
3899 if { $suppress_flag } {
3901 unresolved "${test}"
3903 while { ${index} < [llength ${list}] } {
3904 set pattern [lindex ${list} ${index}]
3905 set index [expr ${index} + 1]
3906 verbose -log "gdb_expect_list pattern: /$pattern/" 2
3907 if { ${index} == [llength ${list}] } {
3910 -re "${pattern}${sentinel}" {
3911 # pass "${test}, pattern ${index} + sentinel"
3914 fail "${test} (pattern ${index} + sentinel)"
3917 -re ".*A problem internal to GDB has been detected" {
3918 fail "${test} (GDB internal error)"
3920 gdb_internal_error_resync
3923 fail "${test} (pattern ${index} + sentinel) (timeout)"
3928 # unresolved "${test}, pattern ${index} + sentinel"
3934 # pass "${test}, pattern ${index}"
3937 fail "${test} (pattern ${index})"
3940 -re ".*A problem internal to GDB has been detected" {
3941 fail "${test} (GDB internal error)"
3943 gdb_internal_error_resync
3946 fail "${test} (pattern ${index}) (timeout)"
3951 # unresolved "${test}, pattern ${index}"
3965 proc gdb_suppress_entire_file { reason } {
3966 global suppress_flag
3969 set suppress_flag -1
3973 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
3974 # gdb_expect to fail immediately (until the next call to
3975 # gdb_stop_suppressing_tests).
3977 proc gdb_suppress_tests { args } {
3978 global suppress_flag
3980 return; # fnf - disable pending review of results where
3981 # testsuite ran better without this
3984 if { $suppress_flag == 1 } {
3985 if { [llength $args] > 0 } {
3986 warning "[lindex $args 0]\n"
3988 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n"
3994 # Clear suppress_flag.
3996 proc gdb_stop_suppressing_tests { } {
3997 global suppress_flag
3999 if [info exists suppress_flag] {
4000 if { $suppress_flag > 0 } {
4002 clone_output "Tests restarted.\n"
4009 proc gdb_clear_suppressed { } {
4010 global suppress_flag
4015 # Spawn the gdb process.
4017 # This doesn't expect any output or do any other initialization,
4018 # leaving those to the caller.
4020 # Overridable function -- you can override this function in your
4023 proc gdb_spawn { } {
4027 # Spawn GDB with CMDLINE_FLAGS appended to the GDBFLAGS global.
4029 proc gdb_spawn_with_cmdline_opts { cmdline_flags } {
4032 set saved_gdbflags $GDBFLAGS
4034 if {$GDBFLAGS != ""} {
4037 append GDBFLAGS $cmdline_flags
4041 set GDBFLAGS $saved_gdbflags
4046 # Start gdb running, wait for prompt, and disable the pagers.
4048 # Overridable function -- you can override this function in your
4051 proc gdb_start { } {
4056 catch default_gdb_exit
4059 # Return true if we can spawn a program on the target and attach to
4062 proc can_spawn_for_attach { } {
4063 # We use exp_pid to get the inferior's pid, assuming that gives
4064 # back the pid of the program. On remote boards, that would give
4065 # us instead the PID of e.g., the ssh client, etc.
4066 if [is_remote target] then {
4070 # The "attach" command doesn't make sense when the target is
4071 # stub-like, where GDB finds the program already started on
4072 # initial connection.
4073 if {[target_info exists use_gdb_stub]} {
4081 # Kill a progress previously started with spawn_wait_for_attach, and
4082 # reap its wait status. PROC_SPAWN_ID is the spawn id associated with
4085 proc kill_wait_spawned_process { proc_spawn_id } {
4086 set pid [exp_pid -i $proc_spawn_id]
4088 verbose -log "killing ${pid}"
4089 remote_exec build "kill -9 ${pid}"
4091 verbose -log "closing ${proc_spawn_id}"
4092 catch "close -i $proc_spawn_id"
4093 verbose -log "waiting for ${proc_spawn_id}"
4095 # If somehow GDB ends up still attached to the process here, a
4096 # blocking wait hangs until gdb is killed (or until gdb / the
4097 # ptracer reaps the exit status too, but that won't happen because
4098 # something went wrong.) Passing -nowait makes expect tell Tcl to
4099 # wait for the PID in the background. That's fine because we
4100 # don't care about the exit status. */
4101 wait -nowait -i $proc_spawn_id
4104 # Returns the process id corresponding to the given spawn id.
4106 proc spawn_id_get_pid { spawn_id } {
4107 set testpid [exp_pid -i $spawn_id]
4109 if { [istarget "*-*-cygwin*"] } {
4110 # testpid is the Cygwin PID, GDB uses the Windows PID, which
4111 # might be different due to the way fork/exec works.
4112 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
4118 # Start a set of programs running and then wait for a bit, to be sure
4119 # that they can be attached to. Return a list of processes spawn IDs,
4120 # one element for each process spawned. It's a test error to call
4121 # this when [can_spawn_for_attach] is false.
4123 proc spawn_wait_for_attach { executable_list } {
4124 set spawn_id_list {}
4126 if ![can_spawn_for_attach] {
4127 # The caller should have checked can_spawn_for_attach itself
4128 # before getting here.
4129 error "can't spawn for attach with this target/board"
4132 foreach {executable} $executable_list {
4133 # Note we use Expect's spawn, not Tcl's exec, because with
4134 # spawn we control when to wait for/reap the process. That
4135 # allows killing the process by PID without being subject to
4137 lappend spawn_id_list [remote_spawn target $executable]
4142 return $spawn_id_list
4146 # gdb_load_cmd -- load a file into the debugger.
4147 # ARGS - additional args to load command.
4148 # return a -1 if anything goes wrong.
4150 proc gdb_load_cmd { args } {
4153 if [target_info exists gdb_load_timeout] {
4154 set loadtimeout [target_info gdb_load_timeout]
4156 set loadtimeout 1600
4158 send_gdb "load $args\n"
4159 verbose "Timeout is now $loadtimeout seconds" 2
4160 gdb_expect $loadtimeout {
4161 -re "Loading section\[^\r\]*\r\n" {
4164 -re "Start address\[\r\]*\r\n" {
4167 -re "Transfer rate\[\r\]*\r\n" {
4170 -re "Memory access error\[^\r\]*\r\n" {
4171 perror "Failed to load program"
4174 -re "$gdb_prompt $" {
4177 -re "(.*)\r\n$gdb_prompt " {
4178 perror "Unexpected reponse from 'load' -- $expect_out(1,string)"
4182 perror "Timed out trying to load $args."
4189 # Invoke "gcore". CORE is the name of the core file to write. TEST
4190 # is the name of the test case. This will return 1 if the core file
4191 # was created, 0 otherwise. If this fails to make a core file because
4192 # this configuration of gdb does not support making core files, it
4193 # will call "unsupported", not "fail". However, if this fails to make
4194 # a core file for some other reason, then it will call "fail".
4196 proc gdb_gcore_cmd {core test} {
4200 gdb_test_multiple "gcore $core" $test {
4201 -re "Saved corefile .*\[\r\n\]+$gdb_prompt $" {
4205 -re "(?:Can't create a corefile|Target does not support core file generation\\.)\[\r\n\]+$gdb_prompt $" {
4213 # Load core file CORE. TEST is the name of the test case.
4214 # This will record a pass/fail for loading the core file.
4216 # 1 - core file is successfully loaded
4217 # 0 - core file loaded but has a non fatal error
4218 # -1 - core file failed to load
4220 proc gdb_core_cmd { core test } {
4223 gdb_test_multiple "core $core" "$test" {
4224 -re "\\\[Thread debugging using \[^ \r\n\]* enabled\\\]\r\n" {
4227 -re " is not a core dump:.*\r\n$gdb_prompt $" {
4228 fail "$test (bad file format)"
4231 -re ": No such file or directory.*\r\n$gdb_prompt $" {
4232 fail "$test (file not found)"
4235 -re "Couldn't find .* registers in core file.*\r\n$gdb_prompt $" {
4236 fail "$test (incomplete note section)"
4239 -re "Core was generated by .*\r\n$gdb_prompt $" {
4243 -re ".*$gdb_prompt $" {
4248 fail "$test (timeout)"
4252 fail "unsupported output from 'core' command"
4256 # Return the filename to download to the target and load on the target
4257 # for this shared library. Normally just LIBNAME, unless shared libraries
4258 # for this target have separate link and load images.
4260 proc shlib_target_file { libname } {
4264 # Return the filename GDB will load symbols from when debugging this
4265 # shared library. Normally just LIBNAME, unless shared libraries for
4266 # this target have separate link and load images.
4268 proc shlib_symbol_file { libname } {
4272 # Return the filename to download to the target and load for this
4273 # executable. Normally just BINFILE unless it is renamed to something
4274 # else for this target.
4276 proc exec_target_file { binfile } {
4280 # Return the filename GDB will load symbols from when debugging this
4281 # executable. Normally just BINFILE unless executables for this target
4282 # have separate files for symbols.
4284 proc exec_symbol_file { binfile } {
4288 # Rename the executable file. Normally this is just BINFILE1 being renamed
4289 # to BINFILE2, but some targets require multiple binary files.
4290 proc gdb_rename_execfile { binfile1 binfile2 } {
4291 file rename -force [exec_target_file ${binfile1}] \
4292 [exec_target_file ${binfile2}]
4293 if { [exec_target_file ${binfile1}] != [exec_symbol_file ${binfile1}] } {
4294 file rename -force [exec_symbol_file ${binfile1}] \
4295 [exec_symbol_file ${binfile2}]
4299 # "Touch" the executable file to update the date. Normally this is just
4300 # BINFILE, but some targets require multiple files.
4301 proc gdb_touch_execfile { binfile } {
4302 set time [clock seconds]
4303 file mtime [exec_target_file ${binfile}] $time
4304 if { [exec_target_file ${binfile}] != [exec_symbol_file ${binfile}] } {
4305 file mtime [exec_symbol_file ${binfile}] $time
4309 # Like remote_download but provides a gdb-specific behavior.
4311 # If the destination board is remote, the local file FROMFILE is transferred as
4312 # usual with remote_download to TOFILE on the remote board. The destination
4313 # filename is added to the CLEANFILES global, so it can be cleaned up at the
4316 # If the destination board is local, the destination path TOFILE is passed
4317 # through standard_output_file, and FROMFILE is copied there.
4319 # In both cases, if TOFILE is omitted, it defaults to the [file tail] of
4322 proc gdb_remote_download {dest fromfile {tofile {}}} {
4323 # If TOFILE is not given, default to the same filename as FROMFILE.
4324 if {[string length $tofile] == 0} {
4325 set tofile [file tail $fromfile]
4328 if {[is_remote $dest]} {
4329 # When the DEST is remote, we simply send the file to DEST.
4332 set destname [remote_download $dest $fromfile $tofile]
4333 lappend cleanfiles $destname
4337 # When the DEST is local, we copy the file to the test directory (where
4338 # the executable is).
4340 # Note that we pass TOFILE through standard_output_file, regardless of
4341 # whether it is absolute or relative, because we don't want the tests
4342 # to be able to write outside their standard output directory.
4344 set tofile [standard_output_file $tofile]
4346 file copy -force $fromfile $tofile
4352 # gdb_load_shlib LIB...
4354 # Copy the listed library to the target.
4356 proc gdb_load_shlib { file } {
4357 set dest [gdb_remote_download target [shlib_target_file $file]]
4359 if {[is_remote target]} {
4360 # If the target is remote, we need to tell gdb where to find the
4363 # We could set this even when not testing remotely, but a user
4364 # generally won't set it unless necessary. In order to make the tests
4365 # more like the real-life scenarios, we don't set it for local testing.
4366 gdb_test "set solib-search-path [file dirname $file]" "" ""
4373 # gdb_load -- load a file into the debugger. Specifying no file
4374 # defaults to the executable currently being debugged.
4375 # The return value is 0 for success, -1 for failure.
4376 # Many files in config/*.exp override this procedure.
4378 proc gdb_load { arg } {
4380 return [gdb_file_cmd $arg]
4385 # gdb_reload -- load a file into the target. Called before "running",
4386 # either the first time or after already starting the program once,
4387 # for remote targets. Most files that override gdb_load should now
4388 # override this instead.
4390 proc gdb_reload { } {
4391 # For the benefit of existing configurations, default to gdb_load.
4392 # Specifying no file defaults to the executable currently being
4394 return [gdb_load ""]
4397 proc gdb_continue { function } {
4400 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"]
4403 proc default_gdb_init { test_file_name } {
4404 global gdb_wrapper_initialized
4405 global gdb_wrapper_target
4406 global gdb_test_file_name
4412 gdb_clear_suppressed
4414 set gdb_test_file_name [file rootname [file tail $test_file_name]]
4416 # Make sure that the wrapper is rebuilt
4417 # with the appropriate multilib option.
4418 if { $gdb_wrapper_target != [current_target_name] } {
4419 set gdb_wrapper_initialized 0
4422 # Unlike most tests, we have a small number of tests that generate
4423 # a very large amount of output. We therefore increase the expect
4424 # buffer size to be able to contain the entire test output. This
4425 # is especially needed by gdb.base/info-macros.exp.
4427 # Also set this value for the currently running GDB.
4428 match_max [match_max -d]
4430 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
4431 set pf_prefix "[file tail [file dirname $test_file_name]]/[file tail $test_file_name]:"
4434 if [target_info exists gdb_prompt] {
4435 set gdb_prompt [target_info gdb_prompt]
4437 set gdb_prompt "\\(gdb\\)"
4440 if [info exists use_gdb_stub] {
4445 # Return a path using GDB_PARALLEL.
4446 # ARGS is a list of path elements to append to "$objdir/$GDB_PARALLEL".
4447 # GDB_PARALLEL must be defined, the caller must check.
4449 # The default value for GDB_PARALLEL is, canonically, ".".
4450 # The catch is that tests don't expect an additional "./" in file paths so
4451 # omit any directory for the default case.
4452 # GDB_PARALLEL is written as "yes" for the default case in Makefile.in to mark
4453 # its special handling.
4455 proc make_gdb_parallel_path { args } {
4456 global GDB_PARALLEL objdir
4457 set joiner [list "file" "join" $objdir]
4458 if { [info exists GDB_PARALLEL] && $GDB_PARALLEL != "yes" } {
4459 lappend joiner $GDB_PARALLEL
4461 set joiner [concat $joiner $args]
4462 return [eval $joiner]
4465 # Turn BASENAME into a full file name in the standard output
4466 # directory. It is ok if BASENAME is the empty string; in this case
4467 # the directory is returned.
4469 proc standard_output_file {basename} {
4470 global objdir subdir gdb_test_file_name
4472 set dir [make_gdb_parallel_path outputs $subdir $gdb_test_file_name]
4474 return [file join $dir $basename]
4477 # Return the name of a file in our standard temporary directory.
4479 proc standard_temp_file {basename} {
4480 # Since a particular runtest invocation is only executing a single test
4481 # file at any given time, we can use the runtest pid to build the
4482 # path of the temp directory.
4483 set dir [make_gdb_parallel_path temp [pid]]
4485 return [file join $dir $basename]
4488 # Set 'testfile', 'srcfile', and 'binfile'.
4490 # ARGS is a list of source file specifications.
4491 # Without any arguments, the .exp file's base name is used to
4492 # compute the source file name. The ".c" extension is added in this case.
4493 # If ARGS is not empty, each entry is a source file specification.
4494 # If the specification starts with a ".", it is treated as a suffix
4495 # to append to the .exp file's base name.
4496 # If the specification is the empty string, it is treated as if it
4498 # Otherwise it is a file name.
4499 # The first file in the list is used to set the 'srcfile' global.
4500 # Each subsequent name is used to set 'srcfile2', 'srcfile3', etc.
4502 # Most tests should call this without arguments.
4504 # If a completely different binary file name is needed, then it
4505 # should be handled in the .exp file with a suitable comment.
4507 proc standard_testfile {args} {
4508 global gdb_test_file_name
4510 global gdb_test_file_last_vars
4513 global testfile binfile
4515 set testfile $gdb_test_file_name
4516 set binfile [standard_output_file ${testfile}]
4518 if {[llength $args] == 0} {
4522 # Unset our previous output variables.
4523 # This can help catch hidden bugs.
4524 if {[info exists gdb_test_file_last_vars]} {
4525 foreach varname $gdb_test_file_last_vars {
4527 catch {unset $varname}
4530 # 'executable' is often set by tests.
4531 set gdb_test_file_last_vars {executable}
4535 set varname srcfile$suffix
4538 # Handle an extension.
4541 } elseif {[string range $arg 0 0] == "."} {
4542 set arg $testfile$arg
4546 lappend gdb_test_file_last_vars $varname
4548 if {$suffix == ""} {
4556 # The default timeout used when testing GDB commands. We want to use
4557 # the same timeout as the default dejagnu timeout, unless the user has
4558 # already provided a specific value (probably through a site.exp file).
4559 global gdb_test_timeout
4560 if ![info exists gdb_test_timeout] {
4561 set gdb_test_timeout $timeout
4564 # A list of global variables that GDB testcases should not use.
4565 # We try to prevent their use by monitoring write accesses and raising
4566 # an error when that happens.
4567 set banned_variables { bug_id prms_id }
4569 # A list of procedures that GDB testcases should not use.
4570 # We try to prevent their use by monitoring invocations and raising
4571 # an error when that happens.
4572 set banned_procedures { strace }
4574 # gdb_init is called by runtest at start, but also by several
4575 # tests directly; gdb_finish is only called from within runtest after
4576 # each test source execution.
4577 # Placing several traces by repetitive calls to gdb_init leads
4578 # to problems, as only one trace is removed in gdb_finish.
4579 # To overcome this possible problem, we add a variable that records
4580 # if the banned variables and procedures are already traced.
4583 proc gdb_init { test_file_name } {
4584 # Reset the timeout value to the default. This way, any testcase
4585 # that changes the timeout value without resetting it cannot affect
4586 # the timeout used in subsequent testcases.
4587 global gdb_test_timeout
4589 set timeout $gdb_test_timeout
4591 if { [regexp ".*gdb\.reverse\/.*" $test_file_name]
4592 && [target_info exists gdb_reverse_timeout] } {
4593 set timeout [target_info gdb_reverse_timeout]
4596 # If GDB_INOTIFY is given, check for writes to '.'. This is a
4597 # debugging tool to help confirm that the test suite is
4598 # parallel-safe. You need "inotifywait" from the
4599 # inotify-tools package to use this.
4600 global GDB_INOTIFY inotify_pid
4601 if {[info exists GDB_INOTIFY] && ![info exists inotify_pid]} {
4602 global outdir tool inotify_log_file
4604 set exclusions {outputs temp gdb[.](log|sum) cache}
4605 set exclusion_re ([join $exclusions |])
4607 set inotify_log_file [standard_temp_file inotify.out]
4608 set inotify_pid [exec inotifywait -r -m -e move,create,delete . \
4609 --exclude $exclusion_re \
4610 |& tee -a $outdir/$tool.log $inotify_log_file &]
4612 # Wait for the watches; hopefully this is long enough.
4615 # Clear the log so that we don't emit a warning the first time
4617 set fd [open $inotify_log_file w]
4621 # Block writes to all banned variables, and invocation of all
4622 # banned procedures...
4623 global banned_variables
4624 global banned_procedures
4625 global banned_traced
4626 if (!$banned_traced) {
4627 foreach banned_var $banned_variables {
4628 global "$banned_var"
4629 trace add variable "$banned_var" write error
4631 foreach banned_proc $banned_procedures {
4632 global "$banned_proc"
4633 trace add execution "$banned_proc" enter error
4638 # We set LC_ALL, LC_CTYPE, and LANG to C so that we get the same
4639 # messages as expected.
4644 # Don't let a .inputrc file or an existing setting of INPUTRC mess up
4645 # the test results. Even if /dev/null doesn't exist on the particular
4646 # platform, the readline library will use the default setting just by
4647 # failing to open the file. OTOH, opening /dev/null successfully will
4648 # also result in the default settings being used since nothing will be
4649 # read from this file.
4650 setenv INPUTRC "/dev/null"
4652 # The gdb.base/readline.exp arrow key test relies on the standard VT100
4653 # bindings, so make sure that an appropriate terminal is selected.
4654 # The same bug doesn't show up if we use ^P / ^N instead.
4657 # Some tests (for example gdb.base/maint.exp) shell out from gdb to use
4658 # grep. Clear GREP_OPTIONS to make the behavior predictable,
4659 # especially having color output turned on can cause tests to fail.
4660 setenv GREP_OPTIONS ""
4662 # Clear $gdbserver_reconnect_p.
4663 global gdbserver_reconnect_p
4664 set gdbserver_reconnect_p 1
4665 unset gdbserver_reconnect_p
4667 return [default_gdb_init $test_file_name]
4670 proc gdb_finish { } {
4671 global gdbserver_reconnect_p
4675 # Exit first, so that the files are no longer in use.
4678 if { [llength $cleanfiles] > 0 } {
4679 eval remote_file target delete $cleanfiles
4683 # Unblock write access to the banned variables. Dejagnu typically
4684 # resets some of them between testcases.
4685 global banned_variables
4686 global banned_procedures
4687 global banned_traced
4688 if ($banned_traced) {
4689 foreach banned_var $banned_variables {
4690 global "$banned_var"
4691 trace remove variable "$banned_var" write error
4693 foreach banned_proc $banned_procedures {
4694 global "$banned_proc"
4695 trace remove execution "$banned_proc" enter error
4702 set debug_format "unknown"
4704 # Run the gdb command "info source" and extract the debugging format
4705 # information from the output and save it in debug_format.
4707 proc get_debug_format { } {
4713 set debug_format "unknown"
4714 send_gdb "info source\n"
4716 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
4717 set debug_format $expect_out(1,string)
4718 verbose "debug format is $debug_format"
4721 -re "No current source file.\r\n$gdb_prompt $" {
4722 perror "get_debug_format used when no current source file"
4725 -re "$gdb_prompt $" {
4726 warning "couldn't check debug format (no valid response)."
4730 warning "couldn't check debug format (timeout)."
4736 # Return true if FORMAT matches the debug format the current test was
4737 # compiled with. FORMAT is a shell-style globbing pattern; it can use
4738 # `*', `[...]', and so on.
4740 # This function depends on variables set by `get_debug_format', above.
4742 proc test_debug_format {format} {
4745 return [expr [string match $format $debug_format] != 0]
4748 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
4749 # COFF, stabs, etc). If that format matches the format that the
4750 # current test was compiled with, then the next test is expected to
4751 # fail for any target. Returns 1 if the next test or set of tests is
4752 # expected to fail, 0 otherwise (or if it is unknown). Must have
4753 # previously called get_debug_format.
4754 proc setup_xfail_format { format } {
4755 set ret [test_debug_format $format]
4763 # gdb_get_line_number TEXT [FILE]
4765 # Search the source file FILE, and return the line number of the
4766 # first line containing TEXT. If no match is found, an error is thrown.
4768 # TEXT is a string literal, not a regular expression.
4770 # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is
4771 # specified, and does not start with "/", then it is assumed to be in
4772 # "$srcdir/$subdir". This is awkward, and can be fixed in the future,
4773 # by changing the callers and the interface at the same time.
4774 # In particular: gdb.base/break.exp, gdb.base/condbreak.exp,
4775 # gdb.base/ena-dis-br.exp.
4777 # Use this function to keep your test scripts independent of the
4778 # exact line numbering of the source file. Don't write:
4780 # send_gdb "break 20"
4782 # This means that if anyone ever edits your test's source file,
4783 # your test could break. Instead, put a comment like this on the
4784 # source file line you want to break at:
4786 # /* breakpoint spot: frotz.exp: test name */
4788 # and then write, in your test script (which we assume is named
4791 # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
4793 # (Yes, Tcl knows how to handle the nested quotes and brackets.
4796 # % puts "foo [lindex "bar baz" 1]"
4799 # Tcl is quite clever, for a little stringy language.)
4803 # The previous implementation of this procedure used the gdb search command.
4804 # This version is different:
4806 # . It works with MI, and it also works when gdb is not running.
4808 # . It operates on the build machine, not the host machine.
4810 # . For now, this implementation fakes a current directory of
4811 # $srcdir/$subdir to be compatible with the old implementation.
4812 # This will go away eventually and some callers will need to
4815 # . The TEXT argument is literal text and matches literally,
4816 # not a regular expression as it was before.
4818 # . State changes in gdb, such as changing the current file
4819 # and setting $_, no longer happen.
4821 # After a bit of time we can forget about the differences from the
4822 # old implementation.
4824 # --chastain 2004-08-05
4826 proc gdb_get_line_number { text { file "" } } {
4831 if { "$file" == "" } then {
4834 if { ! [regexp "^/" "$file"] } then {
4835 set file "$srcdir/$subdir/$file"
4838 if { [ catch { set fd [open "$file"] } message ] } then {
4843 for { set line 1 } { 1 } { incr line } {
4844 if { [ catch { set nchar [gets "$fd" body] } message ] } then {
4847 if { $nchar < 0 } then {
4850 if { [string first "$text" "$body"] >= 0 } then {
4856 if { [ catch { close "$fd" } message ] } then {
4861 error "undefined tag \"$text\""
4867 # Continue the program until it ends.
4869 # MSSG is the error message that gets printed. If not given, a
4871 # COMMAND is the command to invoke. If not given, "continue" is
4873 # ALLOW_EXTRA is a flag indicating whether the test should expect
4874 # extra output between the "Continuing." line and the program
4875 # exiting. By default it is zero; if nonzero, any extra output
4878 proc gdb_continue_to_end {{mssg ""} {command continue} {allow_extra 0}} {
4879 global inferior_exited_re use_gdb_stub
4882 set text "continue until exit"
4884 set text "continue until exit at $mssg"
4892 # By default, we don't rely on exit() behavior of remote stubs --
4893 # it's common for exit() to be implemented as a simple infinite
4894 # loop, or a forced crash/reset. For native targets, by default, we
4895 # assume process exit is reported as such. If a non-reliable target
4896 # is used, we set a breakpoint at exit, and continue to that.
4897 if { [target_info exists exit_is_reliable] } {
4898 set exit_is_reliable [target_info exit_is_reliable]
4900 set exit_is_reliable [expr ! $use_gdb_stub]
4903 if { ! $exit_is_reliable } {
4904 if {![gdb_breakpoint "exit"]} {
4907 gdb_test $command "Continuing..*Breakpoint .*exit.*" \
4910 # Continue until we exit. Should not stop again.
4911 # Don't bother to check the output of the program, that may be
4912 # extremely tough for some remote systems.
4914 "Continuing.\[\r\n0-9\]+${extra}(... EXIT code 0\[\r\n\]+|$inferior_exited_re normally).*"\
4919 proc rerun_to_main {} {
4920 global gdb_prompt use_gdb_stub
4925 -re ".*Breakpoint .*main .*$gdb_prompt $"\
4926 {pass "rerun to main" ; return 0}
4927 -re "$gdb_prompt $"\
4928 {fail "rerun to main" ; return 0}
4929 timeout {fail "(timeout) rerun to main" ; return 0}
4934 -re "The program .* has been started already.*y or n. $" {
4938 -re "Starting program.*$gdb_prompt $"\
4939 {pass "rerun to main" ; return 0}
4940 -re "$gdb_prompt $"\
4941 {fail "rerun to main" ; return 0}
4942 timeout {fail "(timeout) rerun to main" ; return 0}
4947 # Return true if a test should be skipped due to lack of floating
4948 # point support or GDB can't fetch the contents from floating point
4951 gdb_caching_proc gdb_skip_float_test {
4952 if [target_info exists gdb,skip_float_tests] {
4956 # There is an ARM kernel ptrace bug that hardware VFP registers
4957 # are not updated after GDB ptrace set VFP registers. The bug
4958 # was introduced by kernel commit 8130b9d7b9d858aa04ce67805e8951e3cb6e9b2f
4959 # in 2012 and is fixed in e2dfb4b880146bfd4b6aa8e138c0205407cebbaf
4960 # in May 2016. In other words, kernels older than 4.6.3, 4.4.14,
4961 # 4.1.27, 3.18.36, and 3.14.73 have this bug.
4962 # This kernel bug is detected by check how does GDB change the
4963 # program result by changing one VFP register.
4964 if { [istarget "arm*-*-linux*"] } {
4966 set compile_flags {debug nowarnings }
4968 # Set up, compile, and execute a test program having VFP
4970 set src [standard_temp_file arm_vfp[pid].c]
4971 set exe [standard_temp_file arm_vfp[pid].x]
4973 gdb_produce_source $src {
4978 asm ("vldr d0, [%0]" : : "r" (&d));
4979 asm ("vldr d1, [%0]" : : "r" (&d));
4980 asm (".global break_here\n"
4982 asm ("vcmp.f64 d0, d1\n"
4983 "vmrs APSR_nzcv, fpscr\n"
4984 "bne L_value_different\n"
4987 "L_value_different:\n"
4989 "L_end:\n" : "=r" (ret) :);
4991 /* Return $d0 != $d1. */
4996 verbose "compiling testfile $src" 2
4997 set lines [gdb_compile $src $exe executable $compile_flags]
5000 if ![string match "" $lines] then {
5001 verbose "testfile compilation failed, returning 1" 2
5005 # No error message, compilation succeeded so now run it via gdb.
5006 # Run the test up to 5 times to detect whether ptrace can
5007 # correctly update VFP registers or not.
5009 for {set i 0} {$i < 5} {incr i} {
5010 global gdb_prompt srcdir subdir
5014 gdb_reinitialize_dir $srcdir/$subdir
5018 gdb_test "break *break_here"
5019 gdb_continue_to_breakpoint "break_here"
5021 # Modify $d0 to a different value, so the exit code should
5023 gdb_test "set \$d0 = 5.0"
5025 set test "continue to exit"
5026 gdb_test_multiple "continue" "$test" {
5027 -re "exited with code 01.*$gdb_prompt $" {
5029 -re "exited normally.*$gdb_prompt $" {
5030 # However, the exit code is 0. That means something
5031 # wrong in setting VFP registers.
5039 remote_file build delete $exe
5041 return $skip_vfp_test
5046 # Print a message and return true if a test should be skipped
5047 # due to lack of stdio support.
5049 proc gdb_skip_stdio_test { msg } {
5050 if [target_info exists gdb,noinferiorio] {
5051 verbose "Skipping test '$msg': no inferior i/o."
5057 proc gdb_skip_bogus_test { msg } {
5061 # Return true if a test should be skipped due to lack of XML support
5063 # NOTE: This must be called while gdb is *not* running.
5065 gdb_caching_proc gdb_skip_xml_test {
5070 if { [info exists gdb_spawn_id] } {
5071 error "GDB must not be running in gdb_skip_xml_tests."
5074 set xml_file [gdb_remote_download host "${srcdir}/gdb.xml/trivial.xml"]
5078 gdb_test_multiple "set tdesc filename $xml_file" "" {
5079 -re ".*XML support was disabled at compile time.*$gdb_prompt $" {
5082 -re ".*$gdb_prompt $" { }
5088 # Return true if argv[0] is available.
5090 gdb_caching_proc gdb_has_argv0 {
5093 # Set up, compile, and execute a test program to check whether
5094 # argv[0] is available.
5095 set src [standard_temp_file has_argv0[pid].c]
5096 set exe [standard_temp_file has_argv0[pid].x]
5098 gdb_produce_source $src {
5099 int main (int argc, char **argv) {
5104 gdb_compile $src $exe executable {debug}
5107 proc gdb_has_argv0_1 { exe } {
5108 global srcdir subdir
5109 global gdb_prompt hex
5113 gdb_reinitialize_dir $srcdir/$subdir
5116 # Set breakpoint on main.
5117 gdb_test_multiple "break main" "break main" {
5118 -re "Breakpoint.*${gdb_prompt} $" {
5120 -re "${gdb_prompt} $" {
5127 gdb_test_multiple "" "run to main" {
5128 -re "Breakpoint.*${gdb_prompt} $" {
5130 -re "${gdb_prompt} $" {
5135 set old_elements "200"
5136 set test "show print elements"
5137 gdb_test_multiple $test $test {
5138 -re "Limit on string chars or array elements to print is (\[^\r\n\]+)\\.\r\n$gdb_prompt $" {
5139 set old_elements $expect_out(1,string)
5142 set old_repeats "200"
5143 set test "show print repeats"
5144 gdb_test_multiple $test $test {
5145 -re "Threshold for repeated print elements is (\[^\r\n\]+)\\.\r\n$gdb_prompt $" {
5146 set old_repeats $expect_out(1,string)
5149 gdb_test_no_output "set print elements unlimited" ""
5150 gdb_test_no_output "set print repeats unlimited" ""
5153 # Check whether argc is 1.
5154 gdb_test_multiple "p argc" "p argc" {
5155 -re " = 1\r\n${gdb_prompt} $" {
5157 gdb_test_multiple "p argv\[0\]" "p argv\[0\]" {
5158 -re " = $hex \".*[file tail $exe]\"\r\n${gdb_prompt} $" {
5161 -re "${gdb_prompt} $" {
5165 -re "${gdb_prompt} $" {
5169 gdb_test_no_output "set print elements $old_elements" ""
5170 gdb_test_no_output "set print repeats $old_repeats" ""
5175 set result [gdb_has_argv0_1 $exe]
5182 && ([istarget *-*-linux*]
5183 || [istarget *-*-freebsd*] || [istarget *-*-kfreebsd*]
5184 || [istarget *-*-netbsd*] || [istarget *-*-knetbsd*]
5185 || [istarget *-*-openbsd*]
5186 || [istarget *-*-darwin*]
5187 || [istarget *-*-solaris*]
5188 || [istarget *-*-aix*]
5189 || [istarget *-*-gnu*]
5190 || [istarget *-*-cygwin*] || [istarget *-*-mingw32*]
5191 || [istarget *-*-*djgpp*] || [istarget *-*-go32*]
5192 || [istarget *-wince-pe] || [istarget *-*-mingw32ce*]
5193 || [istarget *-*-symbianelf*]
5194 || [istarget *-*-osf*]
5195 || [istarget *-*-dicos*]
5196 || [istarget *-*-nto*]
5197 || [istarget *-*-*vms*]
5198 || [istarget *-*-lynx*178]) } {
5199 fail "argv\[0\] should be available on this target"
5205 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
5206 # ${binfile}.dbglnk, which is just like the executable ($binfile) but without
5207 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
5208 # the name of a debuginfo only file. This file will be stored in the same
5211 # Functions for separate debug info testing
5213 # starting with an executable:
5214 # foo --> original executable
5216 # at the end of the process we have:
5217 # foo.stripped --> foo w/o debug info
5218 # foo.debug --> foo's debug info
5219 # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug.
5221 # Fetch the build id from the file.
5222 # Returns "" if there is none.
5224 proc get_build_id { filename } {
5225 if { ([istarget "*-*-mingw*"]
5226 || [istarget *-*-cygwin*]) } {
5227 set objdump_program [gdb_find_objdump]
5228 set result [catch {set data [exec $objdump_program -p $filename | grep signature | cut "-d " -f4]} output]
5229 verbose "result is $result"
5230 verbose "output is $output"
5236 set tmp [standard_output_file "${filename}-tmp"]
5237 set objcopy_program [gdb_find_objcopy]
5238 set result [catch "exec $objcopy_program -j .note.gnu.build-id -O binary $filename $tmp" output]
5239 verbose "result is $result"
5240 verbose "output is $output"
5245 fconfigure $fi -translation binary
5246 # Skip the NOTE header.
5251 if ![string compare $data ""] then {
5254 # Convert it to hex.
5255 binary scan $data H* data
5260 # Return the build-id hex string (usually 160 bits as 40 hex characters)
5261 # converted to the form: .build-id/ab/cdef1234...89.debug
5262 # Return "" if no build-id found.
5263 proc build_id_debug_filename_get { filename } {
5264 set data [get_build_id $filename]
5265 if { $data == "" } {
5268 regsub {^..} $data {\0/} data
5269 return ".build-id/${data}.debug"
5272 # Create stripped files for DEST, replacing it. If ARGS is passed, it is a
5273 # list of optional flags. The only currently supported flag is no-main,
5274 # which removes the symbol entry for main from the separate debug file.
5276 # Function returns zero on success. Function will return non-zero failure code
5277 # on some targets not supporting separate debug info (such as i386-msdos).
5279 proc gdb_gnu_strip_debug { dest args } {
5281 # Use the first separate debug info file location searched by GDB so the
5282 # run cannot be broken by some stale file searched with higher precedence.
5283 set debug_file "${dest}.debug"
5285 set strip_to_file_program [transform strip]
5286 set objcopy_program [gdb_find_objcopy]
5288 set debug_link [file tail $debug_file]
5289 set stripped_file "${dest}.stripped"
5291 # Get rid of the debug info, and store result in stripped_file
5292 # something like gdb/testsuite/gdb.base/blah.stripped.
5293 set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
5294 verbose "result is $result"
5295 verbose "output is $output"
5300 # Workaround PR binutils/10802:
5301 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
5302 set perm [file attributes ${dest} -permissions]
5303 file attributes ${stripped_file} -permissions $perm
5305 # Get rid of everything but the debug info, and store result in debug_file
5306 # This will be in the .debug subdirectory, see above.
5307 set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
5308 verbose "result is $result"
5309 verbose "output is $output"
5314 # If no-main is passed, strip the symbol for main from the separate
5315 # file. This is to simulate the behavior of elfutils's eu-strip, which
5316 # leaves the symtab in the original file only. There's no way to get
5317 # objcopy or strip to remove the symbol table without also removing the
5318 # debugging sections, so this is as close as we can get.
5319 if { [llength $args] == 1 && [lindex $args 0] == "no-main" } {
5320 set result [catch "exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp" output]
5321 verbose "result is $result"
5322 verbose "output is $output"
5326 file delete "${debug_file}"
5327 file rename "${debug_file}-tmp" "${debug_file}"
5330 # Link the two previous output files together, adding the .gnu_debuglink
5331 # section to the stripped_file, containing a pointer to the debug_file,
5332 # save the new file in dest.
5333 # This will be the regular executable filename, in the usual location.
5334 set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
5335 verbose "result is $result"
5336 verbose "output is $output"
5341 # Workaround PR binutils/10802:
5342 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
5343 set perm [file attributes ${stripped_file} -permissions]
5344 file attributes ${dest} -permissions $perm
5349 # Test the output of GDB_COMMAND matches the pattern obtained
5350 # by concatenating all elements of EXPECTED_LINES. This makes
5351 # it possible to split otherwise very long string into pieces.
5352 # If third argument is not empty, it's used as the name of the
5353 # test to be printed on pass/fail.
5354 proc help_test_raw { gdb_command expected_lines args } {
5355 set message $gdb_command
5356 if [llength $args]>0 then {
5357 set message [lindex $args 0]
5359 set expected_output [join $expected_lines ""]
5360 gdb_test "${gdb_command}" "${expected_output}" $message
5363 # Test the output of "help COMMAND_CLASS". EXPECTED_INITIAL_LINES
5364 # are regular expressions that should match the beginning of output,
5365 # before the list of commands in that class. The presence of
5366 # command list and standard epilogue will be tested automatically.
5367 # Notice that the '[' and ']' characters don't need to be escaped for strings
5368 # wrapped in {} braces.
5369 proc test_class_help { command_class expected_initial_lines args } {
5371 "List of commands\:.*[\r\n]+"
5372 "Type \"help\" followed by command name for full documentation\.[\r\n]+"
5373 "Type \"apropos word\" to search for commands related to \"word\"\.[\r\n]+"
5374 "Command name abbreviations are allowed if unambiguous\."
5376 set l_entire_body [concat $expected_initial_lines $l_stock_body]
5378 eval [list help_test_raw "help ${command_class}" $l_entire_body] $args
5381 # COMMAND_LIST should have either one element -- command to test, or
5382 # two elements -- abbreviated command to test, and full command the first
5383 # element is abbreviation of.
5384 # The command must be a prefix command. EXPECTED_INITIAL_LINES
5385 # are regular expressions that should match the beginning of output,
5386 # before the list of subcommands. The presence of
5387 # subcommand list and standard epilogue will be tested automatically.
5388 proc test_prefix_command_help { command_list expected_initial_lines args } {
5389 set command [lindex $command_list 0]
5390 if {[llength $command_list]>1} {
5391 set full_command [lindex $command_list 1]
5393 set full_command $command
5395 # Use 'list' and not just {} because we want variables to
5396 # be expanded in this list.
5397 set l_stock_body [list\
5398 "List of $full_command subcommands\:.*\[\r\n\]+"\
5399 "Type \"help $full_command\" followed by $full_command subcommand name for full documentation\.\[\r\n\]+"\
5400 "Type \"apropos word\" to search for commands related to \"word\"\.\[\r\n\]+"\
5401 "Command name abbreviations are allowed if unambiguous\."]
5402 set l_entire_body [concat $expected_initial_lines $l_stock_body]
5403 if {[llength $args]>0} {
5404 help_test_raw "help ${command}" $l_entire_body [lindex $args 0]
5406 help_test_raw "help ${command}" $l_entire_body
5410 # Build executable named EXECUTABLE from specifications that allow
5411 # different options to be passed to different sub-compilations.
5412 # TESTNAME is the name of the test; this is passed to 'untested' if
5414 # OPTIONS is passed to the final link, using gdb_compile. If OPTIONS
5415 # contains the option "pthreads", then gdb_compile_pthreads is used.
5416 # ARGS is a flat list of source specifications, of the form:
5417 # { SOURCE1 OPTIONS1 [ SOURCE2 OPTIONS2 ]... }
5418 # Each SOURCE is compiled to an object file using its OPTIONS,
5419 # using gdb_compile.
5420 # Returns 0 on success, -1 on failure.
5421 proc build_executable_from_specs {testname executable options args} {
5425 set binfile [standard_output_file $executable]
5428 if { [lsearch -exact $options "c++"] >= 0 } {
5429 set info_options "c++"
5431 if [get_compiler_info ${info_options}] {
5435 set func gdb_compile
5436 set func_index [lsearch -regexp $options {^(pthreads|shlib|shlib_pthreads)$}]
5437 if {$func_index != -1} {
5438 set func "${func}_[lindex $options $func_index]"
5441 # gdb_compile_shlib and gdb_compile_shlib_pthreads do not use the 3rd
5442 # parameter. They also requires $sources while gdb_compile and
5443 # gdb_compile_pthreads require $objects. Moreover they ignore any options.
5444 if [string match gdb_compile_shlib* $func] {
5446 foreach {s local_options} $args {
5447 if { [regexp "^/" "$s"] } then {
5448 lappend sources_path "$s"
5450 lappend sources_path "$srcdir/$subdir/$s"
5453 set ret [$func $sources_path "${binfile}" $options]
5454 } elseif {[lsearch -exact $options rust] != -1} {
5456 foreach {s local_options} $args {
5457 if { [regexp "^/" "$s"] } then {
5458 lappend sources_path "$s"
5460 lappend sources_path "$srcdir/$subdir/$s"
5463 set ret [gdb_compile_rust $sources_path "${binfile}" $options]
5467 foreach {s local_options} $args {
5468 if { ! [regexp "^/" "$s"] } then {
5469 set s "$srcdir/$subdir/$s"
5471 if { [gdb_compile "${s}" "${binfile}${i}.o" object $local_options] != "" } {
5475 lappend objects "${binfile}${i}.o"
5478 set ret [$func $objects "${binfile}" executable $options]
5488 # Build executable named EXECUTABLE, from SOURCES. If SOURCES are not
5489 # provided, uses $EXECUTABLE.c. The TESTNAME paramer is the name of test
5490 # to pass to untested, if something is wrong. OPTIONS are passed
5491 # to gdb_compile directly.
5492 proc build_executable { testname executable {sources ""} {options {debug}} } {
5493 if {[llength $sources]==0} {
5494 set sources ${executable}.c
5497 set arglist [list $testname $executable $options]
5498 foreach source $sources {
5499 lappend arglist $source $options
5502 return [eval build_executable_from_specs $arglist]
5505 # Starts fresh GDB binary and loads an optional executable into GDB.
5506 # Usage: clean_restart [executable]
5507 # EXECUTABLE is the basename of the binary.
5509 proc clean_restart { args } {
5513 if { [llength $args] > 1 } {
5514 error "bad number of args: [llength $args]"
5519 gdb_reinitialize_dir $srcdir/$subdir
5521 if { [llength $args] >= 1 } {
5522 set executable [lindex $args 0]
5523 set binfile [standard_output_file ${executable}]
5528 # Prepares for testing by calling build_executable_full, then
5530 # TESTNAME is the name of the test.
5531 # Each element in ARGS is a list of the form
5532 # { EXECUTABLE OPTIONS SOURCE_SPEC... }
5533 # These are passed to build_executable_from_specs, which see.
5534 # The last EXECUTABLE is passed to clean_restart.
5535 # Returns 0 on success, non-zero on failure.
5536 proc prepare_for_testing_full {testname args} {
5537 foreach spec $args {
5538 if {[eval build_executable_from_specs [list $testname] $spec] == -1} {
5541 set executable [lindex $spec 0]
5543 clean_restart $executable
5547 # Prepares for testing, by calling build_executable, and then clean_restart.
5548 # Please refer to build_executable for parameter description.
5549 proc prepare_for_testing { testname executable {sources ""} {options {debug}}} {
5551 if {[build_executable $testname $executable $sources $options] == -1} {
5554 clean_restart $executable
5559 # Retrieve the value of EXP in the inferior, represented in format
5560 # specified in FMT (using "printFMT"). DEFAULT is used as fallback if
5561 # print fails. TEST is the test message to use. It can be omitted,
5562 # in which case a test message is built from EXP.
5564 proc get_valueof { fmt exp default {test ""} } {
5568 set test "get valueof \"${exp}\""
5572 gdb_test_multiple "print${fmt} ${exp}" "$test" {
5573 -re "\\$\[0-9\]* = (\[^\r\n\]*)\[\r\n\]*$gdb_prompt $" {
5574 set val $expect_out(1,string)
5578 fail "$test (timeout)"
5584 # Retrieve the value of EXP in the inferior, as a signed decimal value
5585 # (using "print /d"). DEFAULT is used as fallback if print fails.
5586 # TEST is the test message to use. It can be omitted, in which case
5587 # a test message is built from EXP.
5589 proc get_integer_valueof { exp default {test ""} } {
5593 set test "get integer valueof \"${exp}\""
5597 gdb_test_multiple "print /d ${exp}" "$test" {
5598 -re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" {
5599 set val $expect_out(1,string)
5603 fail "$test (timeout)"
5609 # Retrieve the value of EXP in the inferior, as an hexadecimal value
5610 # (using "print /x"). DEFAULT is used as fallback if print fails.
5611 # TEST is the test message to use. It can be omitted, in which case
5612 # a test message is built from EXP.
5614 proc get_hexadecimal_valueof { exp default {test ""} } {
5618 set test "get hexadecimal valueof \"${exp}\""
5622 gdb_test_multiple "print /x ${exp}" $test {
5623 -re "\\$\[0-9\]* = (0x\[0-9a-zA-Z\]+).*$gdb_prompt $" {
5624 set val $expect_out(1,string)
5631 # Retrieve the size of TYPE in the inferior, as a decimal value. DEFAULT
5632 # is used as fallback if print fails. TEST is the test message to use.
5633 # It can be omitted, in which case a test message is 'sizeof (TYPE)'.
5635 proc get_sizeof { type default {test ""} } {
5636 return [get_integer_valueof "sizeof (${type})" $default $test]
5639 proc get_target_charset { } {
5642 gdb_test_multiple "show target-charset" "" {
5643 -re "The target character set is \"auto; currently (\[^\"\]*)\".*$gdb_prompt $" {
5644 return $expect_out(1,string)
5646 -re "The target character set is \"(\[^\"\]*)\".*$gdb_prompt $" {
5647 return $expect_out(1,string)
5651 # Pick a reasonable default.
5652 warning "Unable to read target-charset."
5656 # Get the address of VAR.
5658 proc get_var_address { var } {
5659 global gdb_prompt hex
5661 # Match output like:
5663 # $5 = (int (*)()) 0
5664 # $6 = (int (*)()) 0x24 <function_bar>
5666 gdb_test_multiple "print &${var}" "get address of ${var}" {
5667 -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $"
5669 pass "get address of ${var}"
5670 if { $expect_out(1,string) == "0" } {
5673 return $expect_out(1,string)
5680 # Get the current value for remotetimeout and return it.
5681 proc get_remotetimeout { } {
5685 gdb_test_multiple "show remotetimeout" "" {
5686 -re "Timeout limit to wait for target to respond is ($decimal).*$gdb_prompt $" {
5687 return $expect_out(1,string)
5691 # Pick the default that gdb uses
5692 warning "Unable to read remotetimeout"
5696 # Set the remotetimeout to the specified timeout. Nothing is returned.
5697 proc set_remotetimeout { timeout } {
5700 gdb_test_multiple "set remotetimeout $timeout" "" {
5701 -re "$gdb_prompt $" {
5702 verbose "Set remotetimeout to $timeout\n"
5707 # Get the target's current endianness and return it.
5708 proc get_endianness { } {
5711 gdb_test_multiple "show endian" "determine endianness" {
5712 -re ".* (little|big) endian.*\r\n$gdb_prompt $" {
5714 return $expect_out(1,string)
5720 # ROOT and FULL are file names. Returns the relative path from ROOT
5721 # to FULL. Note that FULL must be in a subdirectory of ROOT.
5722 # For example, given ROOT = /usr/bin and FULL = /usr/bin/ls, this
5725 proc relative_filename {root full} {
5726 set root_split [file split $root]
5727 set full_split [file split $full]
5729 set len [llength $root_split]
5731 if {[eval file join $root_split]
5732 != [eval file join [lrange $full_split 0 [expr {$len - 1}]]]} {
5733 error "$full not a subdir of $root"
5736 return [eval file join [lrange $full_split $len end]]
5739 # Log gdb command line and script if requested.
5740 if {[info exists TRANSCRIPT]} {
5741 rename send_gdb real_send_gdb
5742 rename remote_spawn real_remote_spawn
5743 rename remote_close real_remote_close
5745 global gdb_transcript
5746 set gdb_transcript ""
5748 global gdb_trans_count
5749 set gdb_trans_count 1
5751 proc remote_spawn {args} {
5752 global gdb_transcript gdb_trans_count outdir
5754 if {$gdb_transcript != ""} {
5755 close $gdb_transcript
5757 set gdb_transcript [open [file join $outdir transcript.$gdb_trans_count] w]
5758 puts $gdb_transcript [lindex $args 1]
5759 incr gdb_trans_count
5761 return [uplevel real_remote_spawn $args]
5764 proc remote_close {args} {
5765 global gdb_transcript
5767 if {$gdb_transcript != ""} {
5768 close $gdb_transcript
5769 set gdb_transcript ""
5772 return [uplevel real_remote_close $args]
5775 proc send_gdb {args} {
5776 global gdb_transcript
5778 if {$gdb_transcript != ""} {
5779 puts -nonewline $gdb_transcript [lindex $args 0]
5782 return [uplevel real_send_gdb $args]
5786 # If GDB_PARALLEL exists, then set up the parallel-mode directories.
5787 if {[info exists GDB_PARALLEL]} {
5788 if {[is_remote host]} {
5792 [make_gdb_parallel_path outputs] \
5793 [make_gdb_parallel_path temp] \
5794 [make_gdb_parallel_path cache]
5798 proc core_find {binfile {deletefiles {}} {arg ""}} {
5799 global objdir subdir
5801 set destcore "$binfile.core"
5802 file delete $destcore
5804 # Create a core file named "$destcore" rather than just "core", to
5805 # avoid problems with sys admin types that like to regularly prune all
5806 # files named "core" from the system.
5808 # Arbitrarily try setting the core size limit to "unlimited" since
5809 # this does not hurt on systems where the command does not work and
5810 # allows us to generate a core on systems where it does.
5812 # Some systems append "core" to the name of the program; others append
5813 # the name of the program to "core"; still others (like Linux, as of
5814 # May 2003) create cores named "core.PID". In the latter case, we
5815 # could have many core files lying around, and it may be difficult to
5816 # tell which one is ours, so let's run the program in a subdirectory.
5818 set coredir [standard_output_file coredir.[getpid]]
5820 catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile} ${arg}; true) >/dev/null 2>&1\""
5821 # remote_exec host "${binfile}"
5822 foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
5823 if [remote_file build exists $i] {
5824 remote_exec build "mv $i $destcore"
5828 # Check for "core.PID".
5829 if { $found == 0 } {
5830 set names [glob -nocomplain -directory $coredir core.*]
5831 if {[llength $names] == 1} {
5832 set corefile [file join $coredir [lindex $names 0]]
5833 remote_exec build "mv $corefile $destcore"
5837 if { $found == 0 } {
5838 # The braindamaged HPUX shell quits after the ulimit -c above
5839 # without executing ${binfile}. So we try again without the
5840 # ulimit here if we didn't find a core file above.
5841 # Oh, I should mention that any "braindamaged" non-Unix system has
5842 # the same problem. I like the cd bit too, it's really neat'n stuff.
5843 catch "system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\""
5844 foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" {
5845 if [remote_file build exists $i] {
5846 remote_exec build "mv $i $destcore"
5852 # Try to clean up after ourselves.
5853 foreach deletefile $deletefiles {
5854 remote_file build delete [file join $coredir $deletefile]
5856 remote_exec build "rmdir $coredir"
5858 if { $found == 0 } {
5859 warning "can't generate a core file - core tests suppressed - check ulimit -c"
5865 # gdb_target_symbol_prefix compiles a test program and then examines
5866 # the output from objdump to determine the prefix (such as underscore)
5867 # for linker symbol prefixes.
5869 gdb_caching_proc gdb_target_symbol_prefix {
5870 # Set up and compile a simple test program...
5871 set src [standard_temp_file main[pid].c]
5872 set exe [standard_temp_file main[pid].x]
5874 gdb_produce_source $src {
5880 verbose "compiling testfile $src" 2
5881 set compile_flags {debug nowarnings quiet}
5882 set lines [gdb_compile $src $exe executable $compile_flags]
5886 if ![string match "" $lines] then {
5887 verbose "gdb_target_symbol_prefix: testfile compilation failed, returning null prefix" 2
5889 set objdump_program [gdb_find_objdump]
5890 set result [catch "exec $objdump_program --syms $exe" output]
5893 && ![regexp -lineanchor \
5894 { ([^ a-zA-Z0-9]*)main$} $output dummy prefix] } {
5895 verbose "gdb_target_symbol_prefix: Could not find main in objdump output; returning null prefix" 2
5905 # gdb_target_symbol returns the provided symbol with the correct prefix
5906 # prepended. (See gdb_target_symbol_prefix, above.)
5908 proc gdb_target_symbol { symbol } {
5909 set prefix [gdb_target_symbol_prefix]
5910 return "${prefix}${symbol}"
5913 # gdb_target_symbol_prefix_flags_asm returns a string that can be
5914 # added to gdb_compile options to define the C-preprocessor macro
5915 # SYMBOL_PREFIX with a value that can be prepended to symbols
5916 # for targets which require a prefix, such as underscore.
5918 # This version (_asm) defines the prefix without double quotes
5919 # surrounding the prefix. It is used to define the macro
5920 # SYMBOL_PREFIX for assembly language files. Another version, below,
5921 # is used for symbols in inline assembler in C/C++ files.
5923 # The lack of quotes in this version (_asm) makes it possible to
5924 # define supporting macros in the .S file. (The version which
5925 # uses quotes for the prefix won't work for such files since it's
5926 # impossible to define a quote-stripping macro in C.)
5928 # It's possible to use this version (_asm) for C/C++ source files too,
5929 # but a string is usually required in such files; providing a version
5930 # (no _asm) which encloses the prefix with double quotes makes it
5931 # somewhat easier to define the supporting macros in the test case.
5933 proc gdb_target_symbol_prefix_flags_asm {} {
5934 set prefix [gdb_target_symbol_prefix]
5935 if {$prefix ne ""} {
5936 return "additional_flags=-DSYMBOL_PREFIX=$prefix"
5942 # gdb_target_symbol_prefix_flags returns the same string as
5943 # gdb_target_symbol_prefix_flags_asm, above, but with the prefix
5944 # enclosed in double quotes if there is a prefix.
5946 # See the comment for gdb_target_symbol_prefix_flags_asm for an
5947 # extended discussion.
5949 proc gdb_target_symbol_prefix_flags {} {
5950 set prefix [gdb_target_symbol_prefix]
5951 if {$prefix ne ""} {
5952 return "additional_flags=-DSYMBOL_PREFIX=\"$prefix\""
5958 # A wrapper for 'remote_exec host' that passes or fails a test.
5959 # Returns 0 if all went well, nonzero on failure.
5960 # TEST is the name of the test, other arguments are as for remote_exec.
5962 proc run_on_host { test program args } {
5963 verbose -log "run_on_host: $program $args"
5964 # remote_exec doesn't work properly if the output is set but the
5965 # input is the empty string -- so replace an empty input with
5967 if {[llength $args] > 1 && [lindex $args 1] == ""} {
5968 set args [lreplace $args 1 1 "/dev/null"]
5970 set result [eval remote_exec host [list $program] $args]
5971 verbose "result is $result"
5972 set status [lindex $result 0]
5973 set output [lindex $result 1]
5978 verbose -log "run_on_host failed: $output"
5984 # Return non-zero if "board_info debug_flags" mentions Fission.
5985 # http://gcc.gnu.org/wiki/DebugFission
5986 # Fission doesn't support everything yet.
5987 # This supports working around bug 15954.
5989 proc using_fission { } {
5990 set debug_flags [board_info [target_info name] debug_flags]
5991 return [regexp -- "-gsplit-dwarf" $debug_flags]
5994 # Search the caller's ARGS list and set variables according to the list of
5995 # valid options described by ARGSET.
5997 # The first member of each one- or two-element list in ARGSET defines the
5998 # name of a variable that will be added to the caller's scope.
6000 # If only one element is given to describe an option, it the value is
6001 # 0 if the option is not present in (the caller's) ARGS or 1 if
6004 # If two elements are given, the second element is the default value of
6005 # the variable. This is then overwritten if the option exists in ARGS.
6007 # Any parse_args elements in (the caller's) ARGS will be removed, leaving
6008 # any optional components.
6011 # proc myproc {foo args} {
6012 # parse_args {{bar} {baz "abc"} {qux}}
6015 # myproc ABC -bar -baz DEF peanut butter
6016 # will define the following variables in myproc:
6017 # foo (=ABC), bar (=1), baz (=DEF), and qux (=0)
6018 # args will be the list {peanut butter}
6020 proc parse_args { argset } {
6023 foreach argument $argset {
6024 if {[llength $argument] == 1} {
6025 # No default specified, so we assume that we should set
6026 # the value to 1 if the arg is present and 0 if it's not.
6027 # It is assumed that no value is given with the argument.
6028 set result [lsearch -exact $args "-$argument"]
6029 if {$result != -1} then {
6030 uplevel 1 [list set $argument 1]
6031 set args [lreplace $args $result $result]
6033 uplevel 1 [list set $argument 0]
6035 } elseif {[llength $argument] == 2} {
6036 # There are two items in the argument. The second is a
6037 # default value to use if the item is not present.
6038 # Otherwise, the variable is set to whatever is provided
6039 # after the item in the args.
6040 set arg [lindex $argument 0]
6041 set result [lsearch -exact $args "-[lindex $arg 0]"]
6042 if {$result != -1} then {
6043 uplevel 1 [list set $arg [lindex $args [expr $result+1]]]
6044 set args [lreplace $args $result [expr $result+1]]
6046 uplevel 1 [list set $arg [lindex $argument 1]]
6049 error "Badly formatted argument \"$argument\" in argument set"
6053 # The remaining args should be checked to see that they match the
6054 # number of items expected to be passed into the procedure...
6057 # Capture the output of COMMAND in a string ignoring PREFIX (a regexp);
6058 # return that string.
6060 proc capture_command_output { command prefix } {
6064 set output_string ""
6065 gdb_test_multiple "$command" "capture_command_output for $command" {
6066 -re "[string_to_regexp ${command}]\[\r\n\]+${prefix}(.*)\[\r\n\]+$gdb_prompt $" {
6067 set output_string $expect_out(1,string)
6070 return $output_string
6073 # A convenience function that joins all the arguments together, with a
6074 # regexp that matches exactly one end of line in between each argument.
6075 # This function is ideal to write the expected output of a GDB command
6076 # that generates more than a couple of lines, as this allows us to write
6077 # each line as a separate string, which is easier to read by a human
6080 proc multi_line { args } {
6081 return [join $args "\r\n"]
6084 # Similar to the above, but while multi_line is meant to be used to
6085 # match GDB output, this one is meant to be used to build strings to
6086 # send as GDB input.
6088 proc multi_line_input { args } {
6089 return [join $args "\n"]
6092 # Return the version of the DejaGnu framework.
6094 # The return value is a list containing the major, minor and patch version
6095 # numbers. If the version does not contain a minor or patch number, they will
6096 # be set to 0. For example:
6102 proc dejagnu_version { } {
6103 # The frame_version variable is defined by DejaGnu, in runtest.exp.
6104 global frame_version
6106 verbose -log "DejaGnu version: $frame_version"
6107 verbose -log "Expect version: [exp_version]"
6108 verbose -log "Tcl version: [info tclversion]"
6110 set dg_ver [split $frame_version .]
6112 while { [llength $dg_ver] < 3 } {
6119 # Define user-defined command COMMAND using the COMMAND_LIST as the
6120 # command's definition. The terminating "end" is added automatically.
6122 proc gdb_define_cmd {command command_list} {
6125 set input [multi_line_input {*}$command_list "end"]
6126 set test "define $command"
6128 gdb_test_multiple "define $command" $test {
6130 gdb_test_multiple $input $test {
6131 -re "\r\n$gdb_prompt " {
6138 # Always load compatibility stuff.