1 # Copyright 1992-2020 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"
28 # List of procs to run in gdb_finish.
29 set gdb_finish_hooks [list]
31 # Variable in which we keep track of globals that are allowed to be live
33 array set gdb_persistent_globals {}
35 # Mark variable names in ARG as a persistent global, and declare them as
36 # global in the calling context. Can be used to rewrite "global var_a var_b"
37 # into "gdb_persistent_global var_a var_b".
38 proc gdb_persistent_global { args } {
39 global gdb_persistent_globals
40 foreach varname $args {
41 uplevel 1 global $varname
42 set gdb_persistent_globals($varname) 1
46 # Mark variable names in ARG as a persistent global.
47 proc gdb_persistent_global_no_decl { args } {
48 global gdb_persistent_globals
49 foreach varname $args {
50 set gdb_persistent_globals($varname) 1
54 # Override proc load_lib.
55 rename load_lib saved_load_lib
56 # Run the runtest version of load_lib, and mark all variables that were
57 # created by this call as persistent.
58 proc load_lib { file } {
59 array set known_global {}
60 foreach varname [info globals] {
61 set known_globals($varname) 1
64 set code [catch "saved_load_lib $file" result]
66 foreach varname [info globals] {
67 if { ![info exists known_globals($varname)] } {
68 gdb_persistent_global_no_decl $varname
73 global errorInfo errorCode
74 return -code error -errorinfo $errorInfo -errorcode $errorCode $result
75 } elseif {$code > 1} {
76 return -code $code $result
84 load_lib gdb-utils.exp
86 load_lib check-test-names.exp
90 # The spawn ID used for I/O interaction with the inferior. For native
91 # targets, or remote targets that can do I/O through GDB
92 # (semi-hosting) this will be the same as the host/GDB's spawn ID.
93 # Otherwise, the board may set this to some other spawn ID. E.g.,
94 # when debugging with GDBserver, this is set to GDBserver's spawn ID,
95 # so input/output is done on gdbserver's tty.
96 global inferior_spawn_id
98 if [info exists TOOL_EXECUTABLE] {
99 set GDB $TOOL_EXECUTABLE
101 if ![info exists GDB] {
102 if ![is_remote host] {
103 set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]]
105 set GDB [transform gdb]
108 verbose "using GDB = $GDB" 2
110 # GDBFLAGS is available for the user to set on the command line.
111 # E.g. make check RUNTESTFLAGS=GDBFLAGS=mumble
112 # Testcases may use it to add additional flags, but they must:
113 # - append new flags, not overwrite
114 # - restore the original value when done
116 if ![info exists GDBFLAGS] {
119 verbose "using GDBFLAGS = $GDBFLAGS" 2
121 # Make the build data directory available to tests.
122 set BUILD_DATA_DIRECTORY "[pwd]/../data-directory"
124 # INTERNAL_GDBFLAGS contains flags that the testsuite requires.
125 global INTERNAL_GDBFLAGS
126 if ![info exists INTERNAL_GDBFLAGS] {
127 set INTERNAL_GDBFLAGS "-nw -nx -data-directory $BUILD_DATA_DIRECTORY"
130 # The variable gdb_prompt is a regexp which matches the gdb prompt.
131 # Set it if it is not already set. This is also set by default_gdb_init
132 # but it's not clear what removing one of them will break.
133 # See with_gdb_prompt for more details on prompt handling.
135 if ![info exists gdb_prompt] then {
136 set gdb_prompt "\\(gdb\\)"
139 # A regexp that matches the pagination prompt.
140 set pagination_prompt \
141 "--Type <RET> for more, q to quit, c to continue without paging--"
143 # The variable fullname_syntax_POSIX is a regexp which matches a POSIX
144 # absolute path ie. /foo/
145 set fullname_syntax_POSIX {/[^\n]*/}
146 # The variable fullname_syntax_UNC is a regexp which matches a Windows
147 # UNC path ie. \\D\foo\
148 set fullname_syntax_UNC {\\\\[^\\]+\\[^\n]+\\}
149 # The variable fullname_syntax_DOS_CASE is a regexp which matches a
150 # particular DOS case that GDB most likely will output
151 # ie. \foo\, but don't match \\.*\
152 set fullname_syntax_DOS_CASE {\\[^\\][^\n]*\\}
153 # The variable fullname_syntax_DOS is a regexp which matches a DOS path
154 # ie. a:\foo\ && a:foo\
155 set fullname_syntax_DOS {[a-zA-Z]:[^\n]*\\}
156 # The variable fullname_syntax is a regexp which matches what GDB considers
157 # an absolute path. It is currently debatable if the Windows style paths
158 # d:foo and \abc should be considered valid as an absolute path.
159 # Also, the purpse of this regexp is not to recognize a well formed
160 # absolute path, but to say with certainty that a path is absolute.
161 set fullname_syntax "($fullname_syntax_POSIX|$fullname_syntax_UNC|$fullname_syntax_DOS_CASE|$fullname_syntax_DOS)"
163 # Needed for some tests under Cygwin.
167 if ![info exists env(EXEEXT)] {
170 set EXEEXT $env(EXEEXT)
175 set inferior_exited_re "(?:\\\[Inferior \[0-9\]+ \\(\[^\n\r\]*\\) exited)"
177 # A regular expression that matches a value history number.
179 set valnum_re "\\\$$decimal"
181 ### Only procedures should come after this point.
184 # gdb_version -- extract and print the version number of GDB
186 proc default_gdb_version {} {
188 global INTERNAL_GDBFLAGS GDBFLAGS
192 if {[info exists inotify_pid]} {
193 eval exec kill $inotify_pid
196 set output [remote_exec host "$GDB $INTERNAL_GDBFLAGS --version"]
197 set tmp [lindex $output 1]
199 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
200 if ![is_remote host] {
201 clone_output "[which $GDB] version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
203 clone_output "$GDB on remote host version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
207 proc gdb_version { } {
208 return [default_gdb_version]
212 # gdb_unload -- unload a file if one is loaded
213 # Return 0 on success, -1 on error.
221 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
222 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
223 -re "A program is being debugged already.*Are you sure you want to change the file.*y or n. $" {
224 send_gdb "y\n" answer
227 -re "Discard symbol table from .*y or n.*$" {
228 send_gdb "y\n" answer
231 -re "$gdb_prompt $" {}
233 perror "couldn't unload file in $GDB (timeout)."
240 # Many of the tests depend on setting breakpoints at various places and
241 # running until that breakpoint is reached. At times, we want to start
242 # with a clean-slate with respect to breakpoints, so this utility proc
243 # lets us do this without duplicating this code everywhere.
246 proc delete_breakpoints {} {
249 # we need a larger timeout value here or this thing just confuses
250 # itself. May need a better implementation if possible. - guo
254 set msg "delete all breakpoints in delete_breakpoints"
256 gdb_test_multiple "delete breakpoints" "$msg" {
257 -re "Delete all breakpoints.*y or n.*$" {
258 send_gdb "y\n" answer
261 -re "$gdb_prompt $" {
267 # Confirm with "info breakpoints".
269 set msg "info breakpoints"
270 gdb_test_multiple $msg $msg {
271 -re "No breakpoints or watchpoints..*$gdb_prompt $" {
274 -re "$gdb_prompt $" {
280 perror "breakpoints not deleted"
284 # Returns true iff the target supports using the "run" command.
286 proc target_can_use_run_cmd {} {
287 if [target_info exists use_gdb_stub] {
288 # In this case, when we connect, the inferior is already
297 # Generic run command.
299 # Return 0 if we could start the program, -1 if we could not.
301 # The second pattern below matches up to the first newline *only*.
302 # Using ``.*$'' could swallow up output that we attempt to match
305 # INFERIOR_ARGS is passed as arguments to the start command, so may contain
306 # inferior arguments.
308 # N.B. This function does not wait for gdb to return to the prompt,
309 # that is the caller's responsibility.
311 proc gdb_run_cmd { {inferior_args {}} } {
312 global gdb_prompt use_gdb_stub
314 foreach command [gdb_init_commands] {
315 send_gdb "$command\n"
317 -re "$gdb_prompt $" { }
319 perror "gdb_init_command for target failed"
326 if [target_info exists gdb,do_reload_on_run] {
327 if { [gdb_reload $inferior_args] != 0 } {
330 send_gdb "continue\n"
332 -re "Continu\[^\r\n\]*\[\r\n\]" {}
338 if [target_info exists gdb,start_symbol] {
339 set start [target_info gdb,start_symbol]
343 send_gdb "jump *$start\n"
345 while { $start_attempt } {
346 # Cap (re)start attempts at three to ensure that this loop
347 # always eventually fails. Don't worry about trying to be
348 # clever and not send a command when it has failed.
349 if [expr $start_attempt > 3] {
350 perror "Jump to start() failed (retry count exceeded)"
353 set start_attempt [expr $start_attempt + 1]
355 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
358 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
359 perror "Can't find start symbol to run in gdb_run"
362 -re "No symbol \"start\" in current.*$gdb_prompt $" {
363 send_gdb "jump *_start\n"
365 -re "No symbol.*context.*$gdb_prompt $" {
368 -re "Line.* Jump anyway.*y or n. $" {
369 send_gdb "y\n" answer
371 -re "The program is not being run.*$gdb_prompt $" {
372 if { [gdb_reload $inferior_args] != 0 } {
375 send_gdb "jump *$start\n"
378 perror "Jump to start() failed (timeout)"
387 if [target_info exists gdb,do_reload_on_run] {
388 if { [gdb_reload $inferior_args] != 0 } {
392 send_gdb "run $inferior_args\n"
393 # This doesn't work quite right yet.
394 # Use -notransfer here so that test cases (like chng-sym.exp)
395 # may test for additional start-up messages.
397 -re "The program .* has been started already.*y or n. $" {
398 send_gdb "y\n" answer
401 -notransfer -re "Starting program: \[^\r\n\]*" {}
402 -notransfer -re "$gdb_prompt $" {
403 # There is no more input expected.
410 # Generic start command. Return 0 if we could start the program, -1
413 # INFERIOR_ARGS is passed as arguments to the start command, so may contain
414 # inferior arguments.
416 # N.B. This function does not wait for gdb to return to the prompt,
417 # that is the caller's responsibility.
419 proc gdb_start_cmd { {inferior_args {}} } {
420 global gdb_prompt use_gdb_stub
422 foreach command [gdb_init_commands] {
423 send_gdb "$command\n"
425 -re "$gdb_prompt $" { }
427 perror "gdb_init_command for target failed"
437 send_gdb "start $inferior_args\n"
438 # Use -notransfer here so that test cases (like chng-sym.exp)
439 # may test for additional start-up messages.
441 -re "The program .* has been started already.*y or n. $" {
442 send_gdb "y\n" answer
445 -notransfer -re "Starting program: \[^\r\n\]*" {
452 # Generic starti command. Return 0 if we could start the program, -1
455 # INFERIOR_ARGS is passed as arguments to the starti command, so may contain
456 # inferior arguments.
458 # N.B. This function does not wait for gdb to return to the prompt,
459 # that is the caller's responsibility.
461 proc gdb_starti_cmd { {inferior_args {}} } {
462 global gdb_prompt use_gdb_stub
464 foreach command [gdb_init_commands] {
465 send_gdb "$command\n"
467 -re "$gdb_prompt $" { }
469 perror "gdb_init_command for target failed"
479 send_gdb "starti $inferior_args\n"
481 -re "The program .* has been started already.*y or n. $" {
482 send_gdb "y\n" answer
485 -re "Starting program: \[^\r\n\]*" {
492 # Set a breakpoint at FUNCTION. If there is an additional argument it is
493 # a list of options; the supported options are allow-pending, temporary,
494 # message, no-message, passfail and qualified.
495 # The result is 1 for success, 0 for failure.
497 # Note: The handling of message vs no-message is messed up, but it's based
498 # on historical usage. By default this function does not print passes,
500 # no-message: turns off printing of fails (and passes, but they're already off)
501 # message: turns on printing of passes (and fails, but they're already on)
503 proc gdb_breakpoint { function args } {
507 set pending_response n
508 if {[lsearch -exact $args allow-pending] != -1} {
509 set pending_response y
512 set break_command "break"
513 set break_message "Breakpoint"
514 if {[lsearch -exact $args temporary] != -1} {
515 set break_command "tbreak"
516 set break_message "Temporary breakpoint"
519 if {[lsearch -exact $args qualified] != -1} {
520 append break_command " -qualified"
525 set no_message_loc [lsearch -exact $args no-message]
526 set message_loc [lsearch -exact $args message]
527 # The last one to appear in args wins.
528 if { $no_message_loc > $message_loc } {
530 } elseif { $message_loc > $no_message_loc } {
534 set test_name "setting breakpoint at $function"
536 send_gdb "$break_command $function\n"
537 # The first two regexps are what we get with -g, the third is without -g.
539 -re "$break_message \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
540 -re "$break_message \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
541 -re "$break_message \[0-9\]* at .*$gdb_prompt $" {}
542 -re "$break_message \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" {
543 if {$pending_response == "n"} {
550 -re "Make breakpoint pending.*y or \\\[n\\\]. $" {
551 send_gdb "$pending_response\n"
554 -re "A problem internal to GDB has been detected" {
556 fail "$test_name (GDB internal error)"
558 gdb_internal_error_resync
561 -re "$gdb_prompt $" {
569 fail "$test_name (eof)"
575 fail "$test_name (timeout)"
586 # Set breakpoint at function and run gdb until it breaks there.
587 # Since this is the only breakpoint that will be set, if it stops
588 # at a breakpoint, we will assume it is the one we want. We can't
589 # just compare to "function" because it might be a fully qualified,
590 # single quoted C++ function specifier.
592 # If there are additional arguments, pass them to gdb_breakpoint.
593 # We recognize no-message/message ourselves.
594 # The default is no-message.
595 # no-message is messed up here, like gdb_breakpoint: to preserve
596 # historical usage fails are always printed by default.
597 # no-message: turns off printing of fails (and passes, but they're already off)
598 # message: turns on printing of passes (and fails, but they're already on)
600 proc runto { function args } {
606 # Default to "no-message".
607 set args "no-message $args"
611 set no_message_loc [lsearch -exact $args no-message]
612 set message_loc [lsearch -exact $args message]
613 # The last one to appear in args wins.
614 if { $no_message_loc > $message_loc } {
616 } elseif { $message_loc > $no_message_loc } {
620 set test_name "running to $function in runto"
622 # We need to use eval here to pass our varargs args to gdb_breakpoint
623 # which is also a varargs function.
624 # But we also have to be careful because $function may have multiple
625 # elements, and we don't want Tcl to move the remaining elements after
626 # the first to $args. That is why $function is wrapped in {}.
627 if ![eval gdb_breakpoint {$function} $args] {
633 # the "at foo.c:36" output we get with -g.
634 # the "in func" output we get without -g.
636 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
642 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
648 -re "The target does not support running in non-stop mode.\r\n$gdb_prompt $" {
650 unsupported "non-stop mode not supported"
654 -re ".*A problem internal to GDB has been detected" {
656 fail "$test_name (GDB internal error)"
658 gdb_internal_error_resync
661 -re "$gdb_prompt $" {
669 fail "$test_name (eof)"
675 fail "$test_name (timeout)"
686 # Ask gdb to run until we hit a breakpoint at main.
688 # N.B. This function deletes all existing breakpoints.
689 # If you don't want that, use gdb_start_cmd.
691 proc runto_main { } {
692 return [runto main no-message]
695 ### Continue, and expect to hit a breakpoint.
696 ### Report a pass or fail, depending on whether it seems to have
697 ### worked. Use NAME as part of the test name; each call to
698 ### continue_to_breakpoint should use a NAME which is unique within
700 proc gdb_continue_to_breakpoint {name {location_pattern .*}} {
702 set full_name "continue to breakpoint: $name"
704 set kfail_pattern "Process record does not support instruction 0xfae64 at.*"
705 gdb_test_multiple "continue" $full_name {
706 -re "(?:Breakpoint|Temporary breakpoint) .* (at|in) $location_pattern\r\n$gdb_prompt $" {
709 -re "\[\r\n\]*(?:$kfail_pattern)\[\r\n\]+$gdb_prompt $" {
710 kfail "gdb/25038" $full_name
716 # gdb_internal_error_resync:
718 # Answer the questions GDB asks after it reports an internal error
719 # until we get back to a GDB prompt. Decline to quit the debugging
720 # session, and decline to create a core file. Return non-zero if the
723 # This procedure just answers whatever questions come up until it sees
724 # a GDB prompt; it doesn't require you to have matched the input up to
725 # any specific point. However, it only answers questions it sees in
726 # the output itself, so if you've matched a question, you had better
727 # answer it yourself before calling this.
729 # You can use this function thus:
733 # -re ".*A problem internal to GDB has been detected" {
734 # gdb_internal_error_resync
739 proc gdb_internal_error_resync {} {
742 verbose -log "Resyncing due to internal error."
745 while {$count < 10} {
747 -re "Quit this debugging session\\? \\(y or n\\) $" {
748 send_gdb "n\n" answer
751 -re "Create a core file of GDB\\? \\(y or n\\) $" {
752 send_gdb "n\n" answer
755 -re "$gdb_prompt $" {
756 # We're resynchronized.
760 perror "Could not resync from internal error (timeout)"
765 perror "Could not resync from internal error (resync count exceeded)"
770 # gdb_test_multiple COMMAND MESSAGE [ -promp PROMPT_REGEXP] [ -lbl ]
772 # Send a command to gdb; test the result.
774 # COMMAND is the command to execute, send to GDB with send_gdb. If
775 # this is the null string no command is sent.
776 # MESSAGE is a message to be printed with the built-in failure patterns
777 # if one of them matches. If MESSAGE is empty COMMAND will be used.
778 # -prompt PROMPT_REGEXP specifies a regexp matching the expected prompt
779 # after the command output. If empty, defaults to "$gdb_prompt $".
780 # -lbl specifies that line-by-line matching will be used.
781 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
782 # patterns. Pattern elements will be evaluated in the caller's
783 # context; action elements will be executed in the caller's context.
784 # Unlike patterns for gdb_test, these patterns should generally include
785 # the final newline and prompt.
788 # 1 if the test failed, according to a built-in failure pattern
789 # 0 if only user-supplied patterns matched
790 # -1 if there was an internal error.
792 # You can use this function thus:
794 # gdb_test_multiple "print foo" "test foo" {
795 # -re "expected output 1" {
798 # -re "expected output 2" {
803 # Within action elements you can also make use of the variable
804 # gdb_test_name. This variable is setup automatically by
805 # gdb_test_multiple, and contains the value of MESSAGE. You can then
806 # write this, which is equivalent to the above:
808 # gdb_test_multiple "print foo" "test foo" {
809 # -re "expected output 1" {
810 # pass $gdb_test_name
812 # -re "expected output 2" {
813 # fail $gdb_test_name
817 # Like with "expect", you can also specify the spawn id to match with
818 # -i "$id". Interesting spawn ids are $inferior_spawn_id and
819 # $gdb_spawn_id. The former matches inferior I/O, while the latter
820 # matches GDB I/O. E.g.:
822 # send_inferior "hello\n"
823 # gdb_test_multiple "continue" "test echo" {
824 # -i "$inferior_spawn_id" -re "^hello\r\nhello\r\n$" {
827 # -i "$gdb_spawn_id" -re "Breakpoint.*$gdb_prompt $" {
828 # fail "hit breakpoint"
832 # The standard patterns, such as "Inferior exited..." and "A problem
833 # ...", all being implicitly appended to that list. These are always
834 # expected from $gdb_spawn_id. IOW, callers do not need to worry
835 # about resetting "-i" back to $gdb_spawn_id explicitly.
837 # In EXPECT_ARGUMENTS we can use a -wrap pattern flag, that wraps the regexp
838 # pattern as gdb_test wraps its message argument.
839 # This allows us to rewrite:
840 # gdb_test <command> <pattern> <message>
842 # gdb_test_multiple <command> <message> {
843 # -re -wrap <pattern> {
844 # pass $gdb_test_name
848 # In EXPECT_ARGUMENTS, a pattern flag -early can be used. It makes sure the
849 # pattern is inserted before any implicit pattern added by gdb_test_multiple.
850 # Using this pattern flag, we can f.i. setup a kfail for an assertion failure
851 # <assert> during gdb_continue_to_breakpoint by the rewrite:
852 # gdb_continue_to_breakpoint <msg> <pattern>
854 # set breakpoint_pattern "(?:Breakpoint|Temporary breakpoint) .* (at|in)"
855 # gdb_test_multiple "continue" "continue to breakpoint: <msg>" {
856 # -early -re "internal-error: <assert>" {
857 # setup_kfail gdb/nnnnn "*-*-*"
860 # -re "$breakpoint_pattern <pattern>\r\n$gdb_prompt $" {
861 # pass $gdb_test_name
865 proc gdb_test_multiple { command message args } {
866 global verbose use_gdb_stub
867 global gdb_prompt pagination_prompt
870 global inferior_exited_re
871 upvar timeout timeout
872 upvar expect_out expect_out
877 for {set i 0} {$i < [llength $args]} {incr i} {
878 set arg [lindex $args $i]
879 if { $arg == "-prompt" } {
881 set prompt_regexp [lindex $args $i]
882 } elseif { $arg == "-lbl" } {
889 if { [expr $i + 1] < [llength $args] } {
890 error "Too many arguments to gdb_test_multiple"
891 } elseif { ![info exists user_code] } {
892 error "Too few arguments to gdb_test_multiple"
895 if { "$prompt_regexp" == "" } {
896 set prompt_regexp "$gdb_prompt $"
899 if { $message == "" } {
903 if [string match "*\[\r\n\]" $command] {
904 error "Invalid trailing newline in \"$message\" test"
907 if [string match "*\[\r\n\]*" $message] {
908 error "Invalid newline in \"$message\" test"
912 && [regexp -nocase {^\s*(r|run|star|start|at|att|atta|attac|attach)\M} \
914 error "gdbserver does not support $command without extended-remote"
917 # TCL/EXPECT WART ALERT
918 # Expect does something very strange when it receives a single braced
919 # argument. It splits it along word separators and performs substitutions.
920 # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
921 # evaluated as "\[ab\]". But that's not how TCL normally works; inside a
922 # double-quoted list item, "\[ab\]" is just a long way of representing
923 # "[ab]", because the backslashes will be removed by lindex.
925 # Unfortunately, there appears to be no easy way to duplicate the splitting
926 # that expect will do from within TCL. And many places make use of the
927 # "\[0-9\]" construct, so we need to support that; and some places make use
928 # of the "[func]" construct, so we need to support that too. In order to
929 # get this right we have to substitute quoted list elements differently
930 # from braced list elements.
932 # We do this roughly the same way that Expect does it. We have to use two
933 # lists, because if we leave unquoted newlines in the argument to uplevel
934 # they'll be treated as command separators, and if we escape newlines
935 # we mangle newlines inside of command blocks. This assumes that the
936 # input doesn't contain a pattern which contains actual embedded newlines
939 regsub -all {\n} ${user_code} { } subst_code
940 set subst_code [uplevel list $subst_code]
942 set processed_code ""
943 set early_processed_code ""
944 # The variable current_list holds the name of the currently processed
945 # list, either processed_code or early_processed_code.
946 set current_list "processed_code"
948 set expecting_action 0
951 foreach item $user_code subst_item $subst_code {
952 if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } {
953 lappend $current_list $item
956 if { $item == "-indices" || $item == "-re" || $item == "-ex" } {
957 lappend $current_list $item
960 if { $item == "-early" } {
961 set current_list "early_processed_code"
964 if { $item == "-timeout" || $item == "-i" } {
966 lappend $current_list $item
969 if { $item == "-wrap" } {
973 if { $expecting_arg } {
975 lappend $current_list $subst_item
978 if { $expecting_action } {
979 lappend $current_list "uplevel [list $item]"
980 set expecting_action 0
981 # Cosmetic, no effect on the list.
982 append $current_list "\n"
983 # End the effect of -early, it only applies to one action.
984 set current_list "processed_code"
987 set expecting_action 1
988 if { $wrap_pattern } {
989 # Wrap subst_item as is done for the gdb_test PATTERN argument.
990 lappend $current_list \
991 "\[\r\n\]*(?:$subst_item)\[\r\n\]+$gdb_prompt $"
994 lappend $current_list $subst_item
996 if {$patterns != ""} {
999 append patterns "\"$subst_item\""
1002 # Also purely cosmetic.
1003 regsub -all {\r} $patterns {\\r} patterns
1004 regsub -all {\n} $patterns {\\n} patterns
1006 if $verbose>2 then {
1007 send_user "Sending \"$command\" to gdb\n"
1008 send_user "Looking to match \"$patterns\"\n"
1009 send_user "Message is \"$message\"\n"
1013 set string "${command}\n"
1014 if { $command != "" } {
1015 set multi_line_re "\[\r\n\] *>"
1016 while { "$string" != "" } {
1017 set foo [string first "\n" "$string"]
1018 set len [string length "$string"]
1019 if { $foo < [expr $len - 1] } {
1020 set str [string range "$string" 0 $foo]
1021 if { [send_gdb "$str"] != "" } {
1022 global suppress_flag
1024 if { ! $suppress_flag } {
1025 perror "Couldn't send $command to GDB."
1030 # since we're checking if each line of the multi-line
1031 # command are 'accepted' by GDB here,
1032 # we need to set -notransfer expect option so that
1033 # command output is not lost for pattern matching
1036 -notransfer -re "$multi_line_re$" { verbose "partial: match" 3 }
1037 timeout { verbose "partial: timeout" 3 }
1039 set string [string range "$string" [expr $foo + 1] end]
1040 set multi_line_re "$multi_line_re.*\[\r\n\] *>"
1045 if { "$string" != "" } {
1046 if { [send_gdb "$string"] != "" } {
1047 global suppress_flag
1049 if { ! $suppress_flag } {
1050 perror "Couldn't send $command to GDB."
1058 set code $early_processed_code
1060 -re ".*A problem internal to GDB has been detected" {
1061 fail "$message (GDB internal error)"
1062 gdb_internal_error_resync
1065 -re "\\*\\*\\* DOSEXIT code.*" {
1066 if { $message != "" } {
1069 gdb_suppress_entire_file "GDB died"
1073 append code $processed_code
1075 # Reset the spawn id, in case the processed code used -i.
1081 -re "Ending remote debugging.*$prompt_regexp" {
1082 if ![isnative] then {
1083 warning "Can`t communicate to remote target."
1089 -re "Undefined\[a-z\]* command:.*$prompt_regexp" {
1090 perror "Undefined command \"$command\"."
1094 -re "Ambiguous command.*$prompt_regexp" {
1095 perror "\"$command\" is not a unique command name."
1099 -re "$inferior_exited_re with code \[0-9\]+.*$prompt_regexp" {
1100 if ![string match "" $message] then {
1101 set errmsg "$message (the program exited)"
1103 set errmsg "$command (the program exited)"
1108 -re "$inferior_exited_re normally.*$prompt_regexp" {
1109 if ![string match "" $message] then {
1110 set errmsg "$message (the program exited)"
1112 set errmsg "$command (the program exited)"
1117 -re "The program is not being run.*$prompt_regexp" {
1118 if ![string match "" $message] then {
1119 set errmsg "$message (the program is no longer running)"
1121 set errmsg "$command (the program is no longer running)"
1126 -re "\r\n$prompt_regexp" {
1127 if ![string match "" $message] then {
1132 -re "$pagination_prompt" {
1134 perror "Window too small."
1138 -re "\\((y or n|y or \\\[n\\\]|\\\[y\\\] or n)\\) " {
1139 send_gdb "n\n" answer
1140 gdb_expect -re "$prompt_regexp"
1141 fail "$message (got interactive prompt)"
1144 -re "\\\[0\\\] cancel\r\n\\\[1\\\] all.*\r\n> $" {
1146 gdb_expect -re "$prompt_regexp"
1147 fail "$message (got breakpoint menu)"
1153 perror "GDB process no longer exists"
1154 set wait_status [wait -i $gdb_spawn_id]
1155 verbose -log "GDB process exited with wait status $wait_status"
1156 if { $message != "" } {
1163 if {$line_by_line} {
1165 -re "\r\n\[^\r\n\]*(?=\r\n)" {
1171 # Now patterns that apply to any spawn id specified.
1175 perror "Process no longer exists"
1176 if { $message != "" } {
1182 perror "internal buffer is full."
1187 if ![string match "" $message] then {
1188 fail "$message (timeout)"
1194 # remote_expect calls the eof section if there is an error on the
1195 # expect call. We already have eof sections above, and we don't
1196 # want them to get called in that situation. Since the last eof
1197 # section becomes the error section, here we define another eof
1198 # section, but with an empty spawn_id list, so that it won't ever
1202 # This comment is here because the eof section must not be
1203 # the empty string, otherwise remote_expect won't realize
1208 # Create gdb_test_name in the parent scope. If this variable
1209 # already exists, which it might if we have nested calls to
1210 # gdb_test_multiple, then preserve the old value, otherwise,
1211 # create a new variable in the parent scope.
1212 upvar gdb_test_name gdb_test_name
1213 if { [info exists gdb_test_name] } {
1214 set gdb_test_name_old "$gdb_test_name"
1216 set gdb_test_name "$message"
1219 set code [catch {gdb_expect $code} string]
1221 # Clean up the gdb_test_name variable. If we had a
1222 # previous value then restore it, otherwise, delete the variable
1223 # from the parent scope.
1224 if { [info exists gdb_test_name_old] } {
1225 set gdb_test_name "$gdb_test_name_old"
1231 global errorInfo errorCode
1232 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
1233 } elseif {$code > 1} {
1234 return -code $code $string
1239 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
1240 # Send a command to gdb; test the result.
1242 # COMMAND is the command to execute, send to GDB with send_gdb. If
1243 # this is the null string no command is sent.
1244 # PATTERN is the pattern to match for a PASS, and must NOT include
1245 # the \r\n sequence immediately before the gdb prompt. This argument
1246 # may be omitted to just match the prompt, ignoring whatever output
1248 # MESSAGE is an optional message to be printed. If this is
1249 # omitted, then the pass/fail messages use the command string as the
1250 # message. (If this is the empty string, then sometimes we don't
1251 # call pass or fail at all; I don't understand this at all.)
1252 # QUESTION is a question GDB may ask in response to COMMAND, like
1254 # RESPONSE is the response to send if QUESTION appears.
1257 # 1 if the test failed,
1258 # 0 if the test passes,
1259 # -1 if there was an internal error.
1261 proc gdb_test { args } {
1263 upvar timeout timeout
1265 if [llength $args]>2 then {
1266 set message [lindex $args 2]
1268 set message [lindex $args 0]
1270 set command [lindex $args 0]
1271 set pattern [lindex $args 1]
1275 -re "\[\r\n\]*(?:$pattern)\[\r\n\]+$gdb_prompt $" {
1276 if ![string match "" $message] then {
1282 if { [llength $args] == 5 } {
1283 set question_string [lindex $args 3]
1284 set response_string [lindex $args 4]
1286 -re "(${question_string})$" {
1287 send_gdb "$response_string\n"
1293 set user_code [join $user_code]
1294 return [gdb_test_multiple $command $message $user_code]
1297 # Return 1 if version MAJOR.MINOR is at least AT_LEAST_MAJOR.AT_LEAST_MINOR.
1298 proc version_at_least { major minor at_least_major at_least_minor} {
1299 if { $major > $at_least_major } {
1301 } elseif { $major == $at_least_major \
1302 && $minor >= $at_least_minor } {
1309 # Return 1 if tcl version used is at least MAJOR.MINOR
1310 proc tcl_version_at_least { major minor } {
1312 regexp {^([0-9]+)\.([0-9]+)$} $tcl_version \
1313 dummy tcl_version_major tcl_version_minor
1314 return [version_at_least $tcl_version_major $tcl_version_minor \
1318 if { [tcl_version_at_least 8 5] == 0 } {
1319 # lrepeat was added in tcl 8.5. Only add if missing.
1320 proc lrepeat { n element } {
1321 if { [string is integer -strict $n] == 0 } {
1322 error "expected integer but got \"$n\""
1325 error "bad count \"$n\": must be integer >= 0"
1328 for {set i 0} {$i < $n} {incr i} {
1329 lappend res $element
1335 # gdb_test_no_output COMMAND MESSAGE
1336 # Send a command to GDB and verify that this command generated no output.
1338 # See gdb_test_multiple for a description of the COMMAND and MESSAGE
1339 # parameters. If MESSAGE is ommitted, then COMMAND will be used as
1340 # the message. (If MESSAGE is the empty string, then sometimes we do not
1341 # call pass or fail at all; I don't understand this at all.)
1343 proc gdb_test_no_output { args } {
1345 set command [lindex $args 0]
1346 if [llength $args]>1 then {
1347 set message [lindex $args 1]
1349 set message $command
1352 set command_regex [string_to_regexp $command]
1353 gdb_test_multiple $command $message {
1354 -re "^$command_regex\r\n$gdb_prompt $" {
1355 if ![string match "" $message] then {
1362 # Send a command and then wait for a sequence of outputs.
1363 # This is useful when the sequence is long and contains ".*", a single
1364 # regexp to match the entire output can get a timeout much easier.
1366 # COMMAND is the command to execute, send to GDB with send_gdb. If
1367 # this is the null string no command is sent.
1368 # TEST_NAME is passed to pass/fail. COMMAND is used if TEST_NAME is "".
1369 # EXPECTED_OUTPUT_LIST is a list of regexps of expected output, which are
1370 # processed in order, and all must be present in the output.
1372 # It is unnecessary to specify ".*" at the beginning or end of any regexp,
1373 # there is an implicit ".*" between each element of EXPECTED_OUTPUT_LIST.
1374 # There is also an implicit ".*" between the last regexp and the gdb prompt.
1376 # Like gdb_test and gdb_test_multiple, the output is expected to end with the
1377 # gdb prompt, which must not be specified in EXPECTED_OUTPUT_LIST.
1380 # 1 if the test failed,
1381 # 0 if the test passes,
1382 # -1 if there was an internal error.
1384 proc gdb_test_sequence { command test_name expected_output_list } {
1386 if { $test_name == "" } {
1387 set test_name $command
1389 lappend expected_output_list ""; # implicit ".*" before gdb prompt
1390 if { $command != "" } {
1391 send_gdb "$command\n"
1393 return [gdb_expect_list $test_name "$gdb_prompt $" $expected_output_list]
1397 # Test that a command gives an error. For pass or fail, return
1398 # a 1 to indicate that more tests can proceed. However a timeout
1399 # is a serious error, generates a special fail message, and causes
1400 # a 0 to be returned to indicate that more tests are likely to fail
1403 proc test_print_reject { args } {
1407 if [llength $args]==2 then {
1408 set expectthis [lindex $args 1]
1410 set expectthis "should never match this bogus string"
1412 set sendthis [lindex $args 0]
1413 if $verbose>2 then {
1414 send_user "Sending \"$sendthis\" to gdb\n"
1415 send_user "Looking to match \"$expectthis\"\n"
1417 send_gdb "$sendthis\n"
1418 #FIXME: Should add timeout as parameter.
1420 -re "A .* in expression.*\\.*$gdb_prompt $" {
1421 pass "reject $sendthis"
1424 -re "Invalid syntax in expression.*$gdb_prompt $" {
1425 pass "reject $sendthis"
1428 -re "Junk after end of expression.*$gdb_prompt $" {
1429 pass "reject $sendthis"
1432 -re "Invalid number.*$gdb_prompt $" {
1433 pass "reject $sendthis"
1436 -re "Invalid character constant.*$gdb_prompt $" {
1437 pass "reject $sendthis"
1440 -re "No symbol table is loaded.*$gdb_prompt $" {
1441 pass "reject $sendthis"
1444 -re "No symbol .* in current context.*$gdb_prompt $" {
1445 pass "reject $sendthis"
1448 -re "Unmatched single quote.*$gdb_prompt $" {
1449 pass "reject $sendthis"
1452 -re "A character constant must contain at least one character.*$gdb_prompt $" {
1453 pass "reject $sendthis"
1456 -re "$expectthis.*$gdb_prompt $" {
1457 pass "reject $sendthis"
1460 -re ".*$gdb_prompt $" {
1461 fail "reject $sendthis"
1465 fail "reject $sendthis (eof or timeout)"
1472 # Same as gdb_test, but the second parameter is not a regexp,
1473 # but a string that must match exactly.
1475 proc gdb_test_exact { args } {
1476 upvar timeout timeout
1478 set command [lindex $args 0]
1480 # This applies a special meaning to a null string pattern. Without
1481 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
1482 # messages from commands that should have no output except a new
1483 # prompt. With this, only results of a null string will match a null
1486 set pattern [lindex $args 1]
1487 if [string match $pattern ""] {
1488 set pattern [string_to_regexp [lindex $args 0]]
1490 set pattern [string_to_regexp [lindex $args 1]]
1493 # It is most natural to write the pattern argument with only
1494 # embedded \n's, especially if you are trying to avoid Tcl quoting
1495 # problems. But gdb_expect really wants to see \r\n in patterns. So
1496 # transform the pattern here. First transform \r\n back to \n, in
1497 # case some users of gdb_test_exact already do the right thing.
1498 regsub -all "\r\n" $pattern "\n" pattern
1499 regsub -all "\n" $pattern "\r\n" pattern
1500 if [llength $args]==3 then {
1501 set message [lindex $args 2]
1502 return [gdb_test $command $pattern $message]
1505 return [gdb_test $command $pattern]
1508 # Wrapper around gdb_test_multiple that looks for a list of expected
1509 # output elements, but which can appear in any order.
1510 # CMD is the gdb command.
1511 # NAME is the name of the test.
1512 # ELM_FIND_REGEXP specifies how to partition the output into elements to
1514 # ELM_EXTRACT_REGEXP specifies the part of ELM_FIND_REGEXP to compare.
1515 # RESULT_MATCH_LIST is a list of exact matches for each expected element.
1516 # All elements of RESULT_MATCH_LIST must appear for the test to pass.
1518 # A typical use of ELM_FIND_REGEXP/ELM_EXTRACT_REGEXP is to extract one line
1519 # of text per element and then strip trailing \r\n's.
1521 # gdb_test_list_exact "foo" "bar" \
1522 # "\[^\r\n\]+\[\r\n\]+" \
1525 # {expected result 1} \
1526 # {expected result 2} \
1529 proc gdb_test_list_exact { cmd name elm_find_regexp elm_extract_regexp result_match_list } {
1532 set matches [lsort $result_match_list]
1534 gdb_test_multiple $cmd $name {
1535 "$cmd\[\r\n\]" { exp_continue }
1536 -re $elm_find_regexp {
1537 set str $expect_out(0,string)
1538 verbose -log "seen: $str" 3
1539 regexp -- $elm_extract_regexp $str elm_seen
1540 verbose -log "extracted: $elm_seen" 3
1541 lappend seen $elm_seen
1544 -re "$gdb_prompt $" {
1546 foreach got [lsort $seen] have $matches {
1547 if {![string equal $got $have]} {
1552 if {[string length $failed] != 0} {
1553 fail "$name ($failed not found)"
1561 # gdb_test_stdio COMMAND INFERIOR_PATTERN GDB_PATTERN MESSAGE
1562 # Send a command to gdb; expect inferior and gdb output.
1564 # See gdb_test_multiple for a description of the COMMAND and MESSAGE
1567 # INFERIOR_PATTERN is the pattern to match against inferior output.
1569 # GDB_PATTERN is the pattern to match against gdb output, and must NOT
1570 # include the \r\n sequence immediately before the gdb prompt, nor the
1571 # prompt. The default is empty.
1573 # Both inferior and gdb patterns must match for a PASS.
1575 # If MESSAGE is ommitted, then COMMAND will be used as the message.
1578 # 1 if the test failed,
1579 # 0 if the test passes,
1580 # -1 if there was an internal error.
1583 proc gdb_test_stdio {command inferior_pattern {gdb_pattern ""} {message ""}} {
1584 global inferior_spawn_id gdb_spawn_id
1587 if {$message == ""} {
1588 set message $command
1591 set inferior_matched 0
1594 # Use an indirect spawn id list, and remove the inferior spawn id
1595 # from the expected output as soon as it matches, in case
1596 # $inferior_pattern happens to be a prefix of the resulting full
1597 # gdb pattern below (e.g., "\r\n").
1598 global gdb_test_stdio_spawn_id_list
1599 set gdb_test_stdio_spawn_id_list "$inferior_spawn_id"
1601 # Note that if $inferior_spawn_id and $gdb_spawn_id are different,
1602 # then we may see gdb's output arriving before the inferior's
1604 set res [gdb_test_multiple $command $message {
1605 -i gdb_test_stdio_spawn_id_list -re "$inferior_pattern" {
1606 set inferior_matched 1
1607 if {!$gdb_matched} {
1608 set gdb_test_stdio_spawn_id_list ""
1612 -i $gdb_spawn_id -re "$gdb_pattern\r\n$gdb_prompt $" {
1614 if {!$inferior_matched} {
1622 verbose -log "inferior_matched=$inferior_matched, gdb_matched=$gdb_matched"
1627 # get_print_expr_at_depths EXP OUTPUTS
1629 # Used for testing 'set print max-depth'. Prints the expression EXP
1630 # with 'set print max-depth' set to various depths. OUTPUTS is a list
1631 # of `n` different patterns to match at each of the depths from 0 to
1634 # This proc does one final check with the max-depth set to 'unlimited'
1635 # which is tested against the last pattern in the OUTPUTS list. The
1636 # OUTPUTS list is therefore required to match every depth from 0 to a
1637 # depth where the whole of EXP is printed with no ellipsis.
1639 # This proc leaves the 'set print max-depth' set to 'unlimited'.
1640 proc gdb_print_expr_at_depths {exp outputs} {
1641 for { set depth 0 } { $depth <= [llength $outputs] } { incr depth } {
1642 if { $depth == [llength $outputs] } {
1643 set expected_result [lindex $outputs [expr [llength $outputs] - 1]]
1644 set depth_string "unlimited"
1646 set expected_result [lindex $outputs $depth]
1647 set depth_string $depth
1650 with_test_prefix "exp='$exp': depth=${depth_string}" {
1651 gdb_test_no_output "set print max-depth ${depth_string}"
1652 gdb_test "p $exp" "$expected_result"
1659 # Issue a PASS and return true if evaluating CONDITION in the caller's
1660 # frame returns true, and issue a FAIL and return false otherwise.
1661 # MESSAGE is the pass/fail message to be printed. If MESSAGE is
1662 # omitted or is empty, then the pass/fail messages use the condition
1663 # string as the message.
1665 proc gdb_assert { condition {message ""} } {
1666 if { $message == ""} {
1667 set message $condition
1670 set res [uplevel 1 expr $condition]
1679 proc gdb_reinitialize_dir { subdir } {
1682 if [is_remote host] {
1687 -re "Reinitialize source path to empty.*y or n. " {
1688 send_gdb "y\n" answer
1690 -re "Source directories searched.*$gdb_prompt $" {
1691 send_gdb "dir $subdir\n"
1693 -re "Source directories searched.*$gdb_prompt $" {
1694 verbose "Dir set to $subdir"
1696 -re "$gdb_prompt $" {
1697 perror "Dir \"$subdir\" failed."
1701 -re "$gdb_prompt $" {
1702 perror "Dir \"$subdir\" failed."
1706 -re "$gdb_prompt $" {
1707 perror "Dir \"$subdir\" failed."
1713 # gdb_exit -- exit the GDB, killing the target program if necessary
1715 proc default_gdb_exit {} {
1717 global INTERNAL_GDBFLAGS GDBFLAGS
1718 global gdb_spawn_id inferior_spawn_id
1719 global inotify_log_file
1721 gdb_stop_suppressing_tests
1723 if ![info exists gdb_spawn_id] {
1727 verbose "Quitting $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1729 if {[info exists inotify_log_file] && [file exists $inotify_log_file]} {
1730 set fd [open $inotify_log_file]
1731 set data [read -nonewline $fd]
1734 if {[string compare $data ""] != 0} {
1735 warning "parallel-unsafe file creations noticed"
1738 set fd [open $inotify_log_file w]
1743 if { [is_remote host] && [board_info host exists fileid] } {
1747 send_gdb "y\n" answer
1750 -re "DOSEXIT code" { }
1755 if ![is_remote host] {
1759 unset inferior_spawn_id
1762 # Load a file into the debugger.
1763 # The return value is 0 for success, -1 for failure.
1765 # This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO
1766 # to one of these values:
1768 # debug file was loaded successfully and has debug information
1769 # nodebug file was loaded successfully and has no debug information
1770 # lzma file was loaded, .gnu_debugdata found, but no LZMA support
1772 # fail file was not loaded
1774 # I tried returning this information as part of the return value,
1775 # but ran into a mess because of the many re-implementations of
1776 # gdb_load in config/*.exp.
1778 # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use
1779 # this if they can get more information set.
1781 proc gdb_file_cmd { arg } {
1784 global last_loaded_file
1786 # Save this for the benefit of gdbserver-support.exp.
1787 set last_loaded_file $arg
1789 # Set whether debug info was found.
1790 # Default to "fail".
1791 global gdb_file_cmd_debug_info
1792 set gdb_file_cmd_debug_info "fail"
1794 if [is_remote host] {
1795 set arg [remote_download host $arg]
1797 perror "download failed"
1802 # The file command used to kill the remote target. For the benefit
1803 # of the testsuite, preserve this behavior. Mark as optional so it doesn't
1804 # get written to the stdin log.
1805 send_gdb "kill\n" optional
1807 -re "Kill the program being debugged. .y or n. $" {
1808 send_gdb "y\n" answer
1809 verbose "\t\tKilling previous program being debugged"
1812 -re "$gdb_prompt $" {
1817 send_gdb "file $arg\n"
1818 set new_symbol_table 0
1819 set basename [file tail $arg]
1821 -re "Reading symbols from.*LZMA support was disabled.*$gdb_prompt $" {
1822 verbose "\t\tLoaded $arg into $GDB; .gnu_debugdata found but no LZMA available"
1823 set gdb_file_cmd_debug_info "lzma"
1826 -re "Reading symbols from.*no debugging symbols found.*$gdb_prompt $" {
1827 verbose "\t\tLoaded $arg into $GDB with no debugging symbols"
1828 set gdb_file_cmd_debug_info "nodebug"
1831 -re "Reading symbols from.*$gdb_prompt $" {
1832 verbose "\t\tLoaded $arg into $GDB"
1833 set gdb_file_cmd_debug_info "debug"
1836 -re "Load new symbol table from \".*\".*y or n. $" {
1837 if { $new_symbol_table > 0 } {
1838 perror [join [list "Couldn't load $basename,"
1839 "interactive prompt loop detected."]]
1842 send_gdb "y\n" answer
1843 incr new_symbol_table
1844 set suffix "-- with new symbol table"
1845 set arg "$arg $suffix"
1846 set basename "$basename $suffix"
1849 -re "No such file or directory.*$gdb_prompt $" {
1850 perror "($basename) No such file or directory"
1853 -re "A problem internal to GDB has been detected" {
1854 perror "Couldn't load $basename into GDB (GDB internal error)."
1855 gdb_internal_error_resync
1858 -re "$gdb_prompt $" {
1859 perror "Couldn't load $basename into GDB."
1863 perror "Couldn't load $basename into GDB (timeout)."
1867 # This is an attempt to detect a core dump, but seems not to
1868 # work. Perhaps we need to match .* followed by eof, in which
1869 # gdb_expect does not seem to have a way to do that.
1870 perror "Couldn't load $basename into GDB (eof)."
1876 # Default gdb_spawn procedure.
1878 proc default_gdb_spawn { } {
1881 global INTERNAL_GDBFLAGS GDBFLAGS
1884 gdb_stop_suppressing_tests
1886 # Set the default value, it may be overriden later by specific testfile.
1888 # Use `set_board_info use_gdb_stub' for the board file to flag the inferior
1889 # is already started after connecting and run/attach are not supported.
1890 # This is used for the "remote" protocol. After GDB starts you should
1891 # check global $use_gdb_stub instead of the board as the testfile may force
1892 # a specific different target protocol itself.
1893 set use_gdb_stub [target_info exists use_gdb_stub]
1895 verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1896 gdb_write_cmd_file "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1898 if [info exists gdb_spawn_id] {
1902 if ![is_remote host] {
1903 if { [which $GDB] == 0 } then {
1904 perror "$GDB does not exist."
1908 set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"]
1909 if { $res < 0 || $res == "" } {
1910 perror "Spawning $GDB failed."
1914 set gdb_spawn_id $res
1918 # Default gdb_start procedure.
1920 proc default_gdb_start { } {
1923 global inferior_spawn_id
1925 if [info exists gdb_spawn_id] {
1929 # Keep track of the number of times GDB has been launched.
1930 global gdb_instances
1940 # Default to assuming inferior I/O is done on GDB's terminal.
1941 if {![info exists inferior_spawn_id]} {
1942 set inferior_spawn_id $gdb_spawn_id
1945 # When running over NFS, particularly if running many simultaneous
1946 # tests on different hosts all using the same server, things can
1947 # get really slow. Give gdb at least 3 minutes to start up.
1949 -re "\[\r\n\]$gdb_prompt $" {
1950 verbose "GDB initialized."
1952 -re "$gdb_prompt $" {
1953 perror "GDB never initialized."
1958 perror "(timeout) GDB never initialized after 10 seconds."
1964 perror "(eof) GDB never initialized."
1970 # force the height to "unlimited", so no pagers get used
1972 send_gdb "set height 0\n"
1974 -re "$gdb_prompt $" {
1975 verbose "Setting height to 0." 2
1978 warning "Couldn't set the height to 0"
1981 # force the width to "unlimited", so no wraparound occurs
1982 send_gdb "set width 0\n"
1984 -re "$gdb_prompt $" {
1985 verbose "Setting width to 0." 2
1988 warning "Couldn't set the width to 0."
1996 # Utility procedure to give user control of the gdb prompt in a script. It is
1997 # meant to be used for debugging test cases, and should not be left in the
2000 proc gdb_interact { } {
2002 set spawn_id $gdb_spawn_id
2004 send_user "+------------------------------------------+\n"
2005 send_user "| Script interrupted, you can now interact |\n"
2006 send_user "| with by gdb. Type >>> to continue. |\n"
2007 send_user "+------------------------------------------+\n"
2014 # Examine the output of compilation to determine whether compilation
2015 # failed or not. If it failed determine whether it is due to missing
2016 # compiler or due to compiler error. Report pass, fail or unsupported
2019 proc gdb_compile_test {src output} {
2020 if { $output == "" } {
2021 pass "compilation [file tail $src]"
2022 } elseif { [regexp {^[a-zA-Z_0-9]+: Can't find [^ ]+\.$} $output] } {
2023 unsupported "compilation [file tail $src]"
2024 } elseif { [regexp {.*: command not found[\r|\n]*$} $output] } {
2025 unsupported "compilation [file tail $src]"
2026 } elseif { [regexp {.*: [^\r\n]*compiler not installed[^\r\n]*[\r|\n]*$} $output] } {
2027 unsupported "compilation [file tail $src]"
2029 verbose -log "compilation failed: $output" 2
2030 fail "compilation [file tail $src]"
2034 # Return a 1 for configurations for which we don't even want to try to
2037 proc skip_cplus_tests {} {
2038 if { [istarget "h8300-*-*"] } {
2042 # The C++ IO streams are too large for HC11/HC12 and are thus not
2043 # available. The gdb C++ tests use them and don't compile.
2044 if { [istarget "m6811-*-*"] } {
2047 if { [istarget "m6812-*-*"] } {
2053 # Return a 1 for configurations for which don't have both C++ and the STL.
2055 proc skip_stl_tests {} {
2056 # Symbian supports the C++ language, but the STL is missing
2057 # (both headers and libraries).
2058 if { [istarget "arm*-*-symbianelf*"] } {
2062 return [skip_cplus_tests]
2065 # Return a 1 if I don't even want to try to test FORTRAN.
2067 proc skip_fortran_tests {} {
2071 # Return a 1 if I don't even want to try to test ada.
2073 proc skip_ada_tests {} {
2077 # Return a 1 if I don't even want to try to test GO.
2079 proc skip_go_tests {} {
2083 # Return a 1 if I don't even want to try to test D.
2085 proc skip_d_tests {} {
2089 # Return 1 to skip Rust tests, 0 to try them.
2090 proc skip_rust_tests {} {
2091 return [expr {![isnative]}]
2094 # Return a 1 for configurations that do not support Python scripting.
2095 # PROMPT_REGEXP is the expected prompt.
2097 proc skip_python_tests_prompt { prompt_regexp } {
2098 global gdb_py_is_py3k
2100 gdb_test_multiple "python print ('test')" "verify python support" \
2101 -prompt "$prompt_regexp" {
2102 -re "not supported.*$prompt_regexp" {
2103 unsupported "Python support is disabled."
2106 -re "$prompt_regexp" {}
2109 gdb_test_multiple "python print (sys.version_info\[0\])" "check if python 3" \
2110 -prompt "$prompt_regexp" {
2111 -re "3.*$prompt_regexp" {
2112 set gdb_py_is_py3k 1
2114 -re ".*$prompt_regexp" {
2115 set gdb_py_is_py3k 0
2122 # Return a 1 for configurations that do not support Python scripting.
2123 # Note: This also sets various globals that specify which version of Python
2124 # is in use. See skip_python_tests_prompt.
2126 proc skip_python_tests {} {
2128 return [skip_python_tests_prompt "$gdb_prompt $"]
2131 # Return a 1 if we should skip shared library tests.
2133 proc skip_shlib_tests {} {
2134 # Run the shared library tests on native systems.
2139 # An abbreviated list of remote targets where we should be able to
2140 # run shared library tests.
2141 if {([istarget *-*-linux*]
2142 || [istarget *-*-*bsd*]
2143 || [istarget *-*-solaris2*]
2144 || [istarget arm*-*-symbianelf*]
2145 || [istarget *-*-mingw*]
2146 || [istarget *-*-cygwin*]
2147 || [istarget *-*-pe*])} {
2154 # Return 1 if we should skip tui related tests.
2156 proc skip_tui_tests {} {
2159 gdb_test_multiple "help layout" "verify tui support" {
2160 -re "Undefined command: \"layout\".*$gdb_prompt $" {
2163 -re "$gdb_prompt $" {
2170 # Test files shall make sure all the test result lines in gdb.sum are
2171 # unique in a test run, so that comparing the gdb.sum files of two
2172 # test runs gives correct results. Test files that exercise
2173 # variations of the same tests more than once, shall prefix the
2174 # different test invocations with different identifying strings in
2175 # order to make them unique.
2177 # About test prefixes:
2179 # $pf_prefix is the string that dejagnu prints after the result (FAIL,
2180 # PASS, etc.), and before the test message/name in gdb.sum. E.g., the
2181 # underlined substring in
2183 # PASS: gdb.base/mytest.exp: some test
2184 # ^^^^^^^^^^^^^^^^^^^^
2188 # The easiest way to adjust the test prefix is to append a test
2189 # variation prefix to the $pf_prefix, using the with_test_prefix
2192 # proc do_tests {} {
2193 # gdb_test ... ... "test foo"
2194 # gdb_test ... ... "test bar"
2196 # with_test_prefix "subvariation a" {
2197 # gdb_test ... ... "test x"
2200 # with_test_prefix "subvariation b" {
2201 # gdb_test ... ... "test x"
2205 # with_test_prefix "variation1" {
2206 # ...do setup for variation 1...
2210 # with_test_prefix "variation2" {
2211 # ...do setup for variation 2...
2217 # PASS: gdb.base/mytest.exp: variation1: test foo
2218 # PASS: gdb.base/mytest.exp: variation1: test bar
2219 # PASS: gdb.base/mytest.exp: variation1: subvariation a: test x
2220 # PASS: gdb.base/mytest.exp: variation1: subvariation b: test x
2221 # PASS: gdb.base/mytest.exp: variation2: test foo
2222 # PASS: gdb.base/mytest.exp: variation2: test bar
2223 # PASS: gdb.base/mytest.exp: variation2: subvariation a: test x
2224 # PASS: gdb.base/mytest.exp: variation2: subvariation b: test x
2226 # If for some reason more flexibility is necessary, one can also
2227 # manipulate the pf_prefix global directly, treating it as a string.
2231 # set saved_pf_prefix
2232 # append pf_prefix "${foo}: bar"
2233 # ... actual tests ...
2234 # set pf_prefix $saved_pf_prefix
2237 # Run BODY in the context of the caller, with the current test prefix
2238 # (pf_prefix) appended with one space, then PREFIX, and then a colon.
2239 # Returns the result of BODY.
2241 proc with_test_prefix { prefix body } {
2244 set saved $pf_prefix
2245 append pf_prefix " " $prefix ":"
2246 set code [catch {uplevel 1 $body} result]
2247 set pf_prefix $saved
2250 global errorInfo errorCode
2251 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2253 return -code $code $result
2257 # Wrapper for foreach that calls with_test_prefix on each iteration,
2258 # including the iterator's name and current value in the prefix.
2260 proc foreach_with_prefix {var list body} {
2262 foreach myvar $list {
2263 with_test_prefix "$var=$myvar" {
2264 set code [catch {uplevel 1 $body} result]
2268 global errorInfo errorCode
2269 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2270 } elseif {$code == 3} {
2272 } elseif {$code == 2} {
2273 return -code $code $result
2278 # Like TCL's native proc, but defines a procedure that wraps its body
2279 # within 'with_test_prefix "$proc_name" { ... }'.
2280 proc proc_with_prefix {name arguments body} {
2281 # Define the advertised proc.
2282 proc $name $arguments [list with_test_prefix $name $body]
2286 # Run BODY in the context of the caller. After BODY is run, the variables
2287 # listed in VARS will be reset to the values they had before BODY was run.
2289 # This is useful for providing a scope in which it is safe to temporarily
2290 # modify global variables, e.g.
2292 # global INTERNAL_GDBFLAGS
2295 # set foo GDBHISTSIZE
2297 # save_vars { INTERNAL_GDBFLAGS env($foo) env(HOME) } {
2298 # append INTERNAL_GDBFLAGS " -nx"
2299 # unset -nocomplain env(GDBHISTSIZE)
2304 # Here, although INTERNAL_GDBFLAGS, env(GDBHISTSIZE) and env(HOME) may be
2305 # modified inside BODY, this proc guarantees that the modifications will be
2306 # undone after BODY finishes executing.
2308 proc save_vars { vars body } {
2309 array set saved_scalars { }
2310 array set saved_arrays { }
2314 # First evaluate VAR in the context of the caller in case the variable
2315 # name may be a not-yet-interpolated string like env($foo)
2316 set var [uplevel 1 list $var]
2318 if [uplevel 1 [list info exists $var]] {
2319 if [uplevel 1 [list array exists $var]] {
2320 set saved_arrays($var) [uplevel 1 [list array get $var]]
2322 set saved_scalars($var) [uplevel 1 [list set $var]]
2325 lappend unset_vars $var
2329 set code [catch {uplevel 1 $body} result]
2331 foreach {var value} [array get saved_scalars] {
2332 uplevel 1 [list set $var $value]
2335 foreach {var value} [array get saved_arrays] {
2336 uplevel 1 [list unset $var]
2337 uplevel 1 [list array set $var $value]
2340 foreach var $unset_vars {
2341 uplevel 1 [list unset -nocomplain $var]
2345 global errorInfo errorCode
2346 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2348 return -code $code $result
2352 # Run tests in BODY with the current working directory (CWD) set to
2353 # DIR. When BODY is finished, restore the original CWD. Return the
2356 # This procedure doesn't check if DIR is a valid directory, so you
2357 # have to make sure of that.
2359 proc with_cwd { dir body } {
2361 verbose -log "Switching to directory $dir (saved CWD: $saved_dir)."
2364 set code [catch {uplevel 1 $body} result]
2366 verbose -log "Switching back to $saved_dir."
2370 global errorInfo errorCode
2371 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2373 return -code $code $result
2377 # Run tests in BODY with GDB prompt and variable $gdb_prompt set to
2378 # PROMPT. When BODY is finished, restore GDB prompt and variable
2380 # Returns the result of BODY.
2384 # 1) If you want to use, for example, "(foo)" as the prompt you must pass it
2385 # as "(foo)", and not the regexp form "\(foo\)" (expressed as "\\(foo\\)" in
2386 # TCL). PROMPT is internally converted to a suitable regexp for matching.
2387 # We do the conversion from "(foo)" to "\(foo\)" here for a few reasons:
2388 # a) It's more intuitive for callers to pass the plain text form.
2389 # b) We need two forms of the prompt:
2390 # - a regexp to use in output matching,
2391 # - a value to pass to the "set prompt" command.
2392 # c) It's easier to convert the plain text form to its regexp form.
2394 # 2) Don't add a trailing space, we do that here.
2396 proc with_gdb_prompt { prompt body } {
2399 # Convert "(foo)" to "\(foo\)".
2400 # We don't use string_to_regexp because while it works today it's not
2401 # clear it will work tomorrow: the value we need must work as both a
2402 # regexp *and* as the argument to the "set prompt" command, at least until
2403 # we start recording both forms separately instead of just $gdb_prompt.
2404 # The testsuite is pretty-much hardwired to interpret $gdb_prompt as the
2406 regsub -all {[]*+.|()^$\[\\]} $prompt {\\&} prompt
2408 set saved $gdb_prompt
2410 verbose -log "Setting gdb prompt to \"$prompt \"."
2411 set gdb_prompt $prompt
2412 gdb_test_no_output "set prompt $prompt " ""
2414 set code [catch {uplevel 1 $body} result]
2416 verbose -log "Restoring gdb prompt to \"$saved \"."
2417 set gdb_prompt $saved
2418 gdb_test_no_output "set prompt $saved " ""
2421 global errorInfo errorCode
2422 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2424 return -code $code $result
2428 # Run tests in BODY with target-charset setting to TARGET_CHARSET. When
2429 # BODY is finished, restore target-charset.
2431 proc with_target_charset { target_charset body } {
2435 gdb_test_multiple "show target-charset" "" {
2436 -re "The target character set is \".*; currently (.*)\"\..*$gdb_prompt " {
2437 set saved $expect_out(1,string)
2439 -re "The target character set is \"(.*)\".*$gdb_prompt " {
2440 set saved $expect_out(1,string)
2442 -re ".*$gdb_prompt " {
2443 fail "get target-charset"
2447 gdb_test_no_output "set target-charset $target_charset" ""
2449 set code [catch {uplevel 1 $body} result]
2451 gdb_test_no_output "set target-charset $saved" ""
2454 global errorInfo errorCode
2455 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2457 return -code $code $result
2461 # Switch the default spawn id to SPAWN_ID, so that gdb_test,
2462 # mi_gdb_test etc. default to using it.
2464 proc switch_gdb_spawn_id {spawn_id} {
2466 global board board_info
2468 set gdb_spawn_id $spawn_id
2469 set board [host_info name]
2470 set board_info($board,fileid) $spawn_id
2473 # Clear the default spawn id.
2475 proc clear_gdb_spawn_id {} {
2477 global board board_info
2479 unset -nocomplain gdb_spawn_id
2480 set board [host_info name]
2481 unset -nocomplain board_info($board,fileid)
2484 # Run BODY with SPAWN_ID as current spawn id.
2486 proc with_spawn_id { spawn_id body } {
2489 if [info exists gdb_spawn_id] {
2490 set saved_spawn_id $gdb_spawn_id
2493 switch_gdb_spawn_id $spawn_id
2495 set code [catch {uplevel 1 $body} result]
2497 if [info exists saved_spawn_id] {
2498 switch_gdb_spawn_id $saved_spawn_id
2504 global errorInfo errorCode
2505 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2507 return -code $code $result
2511 # Select the largest timeout from all the timeouts:
2512 # - the local "timeout" variable of the scope two levels above,
2513 # - the global "timeout" variable,
2514 # - the board variable "gdb,timeout".
2516 proc get_largest_timeout {} {
2517 upvar #0 timeout gtimeout
2518 upvar 2 timeout timeout
2521 if [info exists timeout] {
2524 if { [info exists gtimeout] && $gtimeout > $tmt } {
2527 if { [target_info exists gdb,timeout]
2528 && [target_info gdb,timeout] > $tmt } {
2529 set tmt [target_info gdb,timeout]
2539 # Run tests in BODY with timeout increased by factor of FACTOR. When
2540 # BODY is finished, restore timeout.
2542 proc with_timeout_factor { factor body } {
2545 set savedtimeout $timeout
2547 set timeout [expr [get_largest_timeout] * $factor]
2548 set code [catch {uplevel 1 $body} result]
2550 set timeout $savedtimeout
2552 global errorInfo errorCode
2553 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2555 return -code $code $result
2559 # Run BODY with timeout factor FACTOR if check-read1 is used.
2561 proc with_read1_timeout_factor { factor body } {
2562 if { [info exists ::env(READ1)] == 1 && $::env(READ1) == 1 } {
2563 # Use timeout factor
2565 # Reset timeout factor
2568 return [uplevel [list with_timeout_factor $factor $body]]
2571 # Return 1 if _Complex types are supported, otherwise, return 0.
2573 gdb_caching_proc support_complex_tests {
2575 if { [gdb_skip_float_test] } {
2576 # If floating point is not supported, _Complex is not
2581 # Compile a test program containing _Complex types.
2583 return [gdb_can_simple_compile complex {
2587 _Complex long double cld;
2593 # Return 1 if compiling go is supported.
2594 gdb_caching_proc support_go_compile {
2596 return [gdb_can_simple_compile go-hello {
2600 fmt.Println("hello world")
2605 # Return 1 if GDB can get a type for siginfo from the target, otherwise
2608 proc supports_get_siginfo_type {} {
2609 if { [istarget "*-*-linux*"] } {
2616 # Return 1 if the target supports hardware single stepping.
2618 proc can_hardware_single_step {} {
2620 if { [istarget "arm*-*-*"] || [istarget "mips*-*-*"]
2621 || [istarget "tic6x-*-*"] || [istarget "sparc*-*-linux*"]
2622 || [istarget "nios2-*-*"] } {
2629 # Return 1 if target hardware or OS supports single stepping to signal
2630 # handler, otherwise, return 0.
2632 proc can_single_step_to_signal_handler {} {
2633 # Targets don't have hardware single step. On these targets, when
2634 # a signal is delivered during software single step, gdb is unable
2635 # to determine the next instruction addresses, because start of signal
2636 # handler is one of them.
2637 return [can_hardware_single_step]
2640 # Return 1 if target supports process record, otherwise return 0.
2642 proc supports_process_record {} {
2644 if [target_info exists gdb,use_precord] {
2645 return [target_info gdb,use_precord]
2648 if { [istarget "arm*-*-linux*"] || [istarget "x86_64-*-linux*"]
2649 || [istarget "i\[34567\]86-*-linux*"]
2650 || [istarget "aarch64*-*-linux*"]
2651 || [istarget "powerpc*-*-linux*"]
2652 || [istarget "s390*-*-linux*"] } {
2659 # Return 1 if target supports reverse debugging, otherwise return 0.
2661 proc supports_reverse {} {
2663 if [target_info exists gdb,can_reverse] {
2664 return [target_info gdb,can_reverse]
2667 if { [istarget "arm*-*-linux*"] || [istarget "x86_64-*-linux*"]
2668 || [istarget "i\[34567\]86-*-linux*"]
2669 || [istarget "aarch64*-*-linux*"]
2670 || [istarget "powerpc*-*-linux*"]
2671 || [istarget "s390*-*-linux*"] } {
2678 # Return 1 if readline library is used.
2680 proc readline_is_used { } {
2683 gdb_test_multiple "show editing" "" {
2684 -re ".*Editing of command lines as they are typed is on\..*$gdb_prompt $" {
2687 -re ".*$gdb_prompt $" {
2693 # Return 1 if target is ELF.
2694 gdb_caching_proc is_elf_target {
2695 set me "is_elf_target"
2697 set src { int foo () {return 0;} }
2698 if {![gdb_simple_compile elf_target $src]} {
2702 set fp_obj [open $obj "r"]
2703 fconfigure $fp_obj -translation binary
2704 set data [read $fp_obj]
2709 set ELFMAG "\u007FELF"
2711 if {[string compare -length 4 $data $ELFMAG] != 0} {
2712 verbose "$me: returning 0" 2
2716 verbose "$me: returning 1" 2
2720 # Return 1 if the memory at address zero is readable.
2722 gdb_caching_proc is_address_zero_readable {
2726 gdb_test_multiple "x 0" "" {
2727 -re "Cannot access memory at address 0x0.*$gdb_prompt $" {
2730 -re ".*$gdb_prompt $" {
2738 # Produce source file NAME and write SOURCES into it.
2740 proc gdb_produce_source { name sources } {
2742 set f [open $name "w"]
2748 # Return 1 if target is ILP32.
2749 # This cannot be decided simply from looking at the target string,
2750 # as it might depend on externally passed compiler options like -m64.
2751 gdb_caching_proc is_ilp32_target {
2752 return [gdb_can_simple_compile is_ilp32_target {
2753 int dummy[sizeof (int) == 4
2754 && sizeof (void *) == 4
2755 && sizeof (long) == 4 ? 1 : -1];
2759 # Return 1 if target is LP64.
2760 # This cannot be decided simply from looking at the target string,
2761 # as it might depend on externally passed compiler options like -m64.
2762 gdb_caching_proc is_lp64_target {
2763 return [gdb_can_simple_compile is_lp64_target {
2764 int dummy[sizeof (int) == 4
2765 && sizeof (void *) == 8
2766 && sizeof (long) == 8 ? 1 : -1];
2770 # Return 1 if target has 64 bit addresses.
2771 # This cannot be decided simply from looking at the target string,
2772 # as it might depend on externally passed compiler options like -m64.
2773 gdb_caching_proc is_64_target {
2774 return [gdb_can_simple_compile is_64_target {
2775 int function(void) { return 3; }
2776 int dummy[sizeof (&function) == 8 ? 1 : -1];
2780 # Return 1 if target has x86_64 registers - either amd64 or x32.
2781 # x32 target identifies as x86_64-*-linux*, therefore it cannot be determined
2782 # just from the target string.
2783 gdb_caching_proc is_amd64_regs_target {
2784 if {![istarget "x86_64-*-*"] && ![istarget "i?86-*"]} {
2788 return [gdb_can_simple_compile is_amd64_regs_target {
2798 # Return 1 if this target is an x86 or x86-64 with -m32.
2799 proc is_x86_like_target {} {
2800 if {![istarget "x86_64-*-*"] && ![istarget i?86-*]} {
2803 return [expr [is_ilp32_target] && ![is_amd64_regs_target]]
2806 # Return 1 if this target is an arm or aarch32 on aarch64.
2808 gdb_caching_proc is_aarch32_target {
2809 if { [istarget "arm*-*-*"] } {
2813 if { ![istarget "aarch64*-*-*"] } {
2820 lappend list "\tmov $reg, $reg"
2823 return [gdb_can_simple_compile aarch32 [join $list \n]]
2826 # Return 1 if this target is an aarch64, either lp64 or ilp32.
2828 proc is_aarch64_target {} {
2829 if { ![istarget "aarch64*-*-*"] } {
2833 return [expr ![is_aarch32_target]]
2836 # Return 1 if displaced stepping is supported on target, otherwise, return 0.
2837 proc support_displaced_stepping {} {
2839 if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"]
2840 || [istarget "arm*-*-linux*"] || [istarget "powerpc-*-linux*"]
2841 || [istarget "powerpc64-*-linux*"] || [istarget "s390*-*-*"]
2842 || [istarget "aarch64*-*-linux*"] } {
2849 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
2850 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
2852 gdb_caching_proc skip_altivec_tests {
2853 global srcdir subdir gdb_prompt inferior_exited_re
2855 set me "skip_altivec_tests"
2857 # Some simulators are known to not support VMX instructions.
2858 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
2859 verbose "$me: target known to not support VMX, returning 1" 2
2863 # Make sure we have a compiler that understands altivec.
2864 if [get_compiler_info] {
2865 warning "Could not get compiler info"
2868 if [test_compiler_info gcc*] {
2869 set compile_flags "additional_flags=-maltivec"
2870 } elseif [test_compiler_info xlc*] {
2871 set compile_flags "additional_flags=-qaltivec"
2873 verbose "Could not compile with altivec support, returning 1" 2
2877 # Compile a test program containing VMX instructions.
2881 asm volatile ("vor v0,v0,v0");
2883 asm volatile ("vor 0,0,0");
2888 if {![gdb_simple_compile $me $src executable $compile_flags]} {
2892 # Compilation succeeded so now run it via gdb.
2896 gdb_reinitialize_dir $srcdir/$subdir
2900 -re ".*Illegal instruction.*${gdb_prompt} $" {
2901 verbose -log "\n$me altivec hardware not detected"
2902 set skip_vmx_tests 1
2904 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
2905 verbose -log "\n$me: altivec hardware detected"
2906 set skip_vmx_tests 0
2909 warning "\n$me: default case taken"
2910 set skip_vmx_tests 1
2914 remote_file build delete $obj
2916 verbose "$me: returning $skip_vmx_tests" 2
2917 return $skip_vmx_tests
2920 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
2921 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
2923 gdb_caching_proc skip_vsx_tests {
2924 global srcdir subdir gdb_prompt inferior_exited_re
2926 set me "skip_vsx_tests"
2928 # Some simulators are known to not support Altivec instructions, so
2929 # they won't support VSX instructions as well.
2930 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
2931 verbose "$me: target known to not support VSX, returning 1" 2
2935 # Make sure we have a compiler that understands altivec.
2936 if [get_compiler_info] {
2937 warning "Could not get compiler info"
2940 if [test_compiler_info gcc*] {
2941 set compile_flags "additional_flags=-mvsx"
2942 } elseif [test_compiler_info xlc*] {
2943 set compile_flags "additional_flags=-qasm=gcc"
2945 verbose "Could not compile with vsx support, returning 1" 2
2949 # Compile a test program containing VSX instructions.
2952 double a[2] = { 1.0, 2.0 };
2954 asm volatile ("lxvd2x v0,v0,%[addr]" : : [addr] "r" (a));
2956 asm volatile ("lxvd2x 0,0,%[addr]" : : [addr] "r" (a));
2961 if {![gdb_simple_compile $me $src executable $compile_flags]} {
2965 # No error message, compilation succeeded so now run it via gdb.
2969 gdb_reinitialize_dir $srcdir/$subdir
2973 -re ".*Illegal instruction.*${gdb_prompt} $" {
2974 verbose -log "\n$me VSX hardware not detected"
2975 set skip_vsx_tests 1
2977 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
2978 verbose -log "\n$me: VSX hardware detected"
2979 set skip_vsx_tests 0
2982 warning "\n$me: default case taken"
2983 set skip_vsx_tests 1
2987 remote_file build delete $obj
2989 verbose "$me: returning $skip_vsx_tests" 2
2990 return $skip_vsx_tests
2993 # Run a test on the target to see if it supports TSX hardware. Return 0 if so,
2994 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
2996 gdb_caching_proc skip_tsx_tests {
2997 global srcdir subdir gdb_prompt inferior_exited_re
2999 set me "skip_tsx_tests"
3001 # Compile a test program.
3004 asm volatile ("xbegin .L0");
3005 asm volatile ("xend");
3006 asm volatile (".L0: nop");
3010 if {![gdb_simple_compile $me $src executable]} {
3014 # No error message, compilation succeeded so now run it via gdb.
3018 gdb_reinitialize_dir $srcdir/$subdir
3022 -re ".*Illegal instruction.*${gdb_prompt} $" {
3023 verbose -log "$me: TSX hardware not detected."
3024 set skip_tsx_tests 1
3026 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
3027 verbose -log "$me: TSX hardware detected."
3028 set skip_tsx_tests 0
3031 warning "\n$me: default case taken."
3032 set skip_tsx_tests 1
3036 remote_file build delete $obj
3038 verbose "$me: returning $skip_tsx_tests" 2
3039 return $skip_tsx_tests
3042 # Run a test on the target to see if it supports btrace hardware. Return 0 if so,
3043 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
3045 gdb_caching_proc skip_btrace_tests {
3046 global srcdir subdir gdb_prompt inferior_exited_re
3048 set me "skip_btrace_tests"
3049 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
3050 verbose "$me: target does not support btrace, returning 1" 2
3054 # Compile a test program.
3055 set src { int main() { return 0; } }
3056 if {![gdb_simple_compile $me $src executable]} {
3060 # No error message, compilation succeeded so now run it via gdb.
3064 gdb_reinitialize_dir $srcdir/$subdir
3069 # In case of an unexpected output, we return 2 as a fail value.
3070 set skip_btrace_tests 2
3071 gdb_test_multiple "record btrace" "check btrace support" {
3072 -re "You can't do that when your target is.*\r\n$gdb_prompt $" {
3073 set skip_btrace_tests 1
3075 -re "Target does not support branch tracing.*\r\n$gdb_prompt $" {
3076 set skip_btrace_tests 1
3078 -re "Could not enable branch tracing.*\r\n$gdb_prompt $" {
3079 set skip_btrace_tests 1
3081 -re "^record btrace\r\n$gdb_prompt $" {
3082 set skip_btrace_tests 0
3086 remote_file build delete $obj
3088 verbose "$me: returning $skip_btrace_tests" 2
3089 return $skip_btrace_tests
3092 # Run a test on the target to see if it supports btrace pt hardware.
3093 # Return 0 if so, 1 if it does not. Based on 'check_vmx_hw_available'
3094 # from the GCC testsuite.
3096 gdb_caching_proc skip_btrace_pt_tests {
3097 global srcdir subdir gdb_prompt inferior_exited_re
3099 set me "skip_btrace_tests"
3100 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
3101 verbose "$me: target does not support btrace, returning 1" 2
3105 # Compile a test program.
3106 set src { int main() { return 0; } }
3107 if {![gdb_simple_compile $me $src executable]} {
3111 # No error message, compilation succeeded so now run it via gdb.
3115 gdb_reinitialize_dir $srcdir/$subdir
3120 # In case of an unexpected output, we return 2 as a fail value.
3121 set skip_btrace_tests 2
3122 gdb_test_multiple "record btrace pt" "check btrace pt support" {
3123 -re "You can't do that when your target is.*\r\n$gdb_prompt $" {
3124 set skip_btrace_tests 1
3126 -re "Target does not support branch tracing.*\r\n$gdb_prompt $" {
3127 set skip_btrace_tests 1
3129 -re "Could not enable branch tracing.*\r\n$gdb_prompt $" {
3130 set skip_btrace_tests 1
3132 -re "support was disabled at compile time.*\r\n$gdb_prompt $" {
3133 set skip_btrace_tests 1
3135 -re "^record btrace pt\r\n$gdb_prompt $" {
3136 set skip_btrace_tests 0
3140 remote_file build delete $obj
3142 verbose "$me: returning $skip_btrace_tests" 2
3143 return $skip_btrace_tests
3146 # Run a test on the target to see if it supports Aarch64 SVE hardware.
3147 # Return 0 if so, 1 if it does not. Note this causes a restart of GDB.
3149 gdb_caching_proc skip_aarch64_sve_tests {
3150 global srcdir subdir gdb_prompt inferior_exited_re
3152 set me "skip_aarch64_sve_tests"
3154 if { ![is_aarch64_target]} {
3158 set compile_flags "{additional_flags=-march=armv8-a+sve}"
3160 # Compile a test program containing SVE instructions.
3163 asm volatile ("ptrue p0.b");
3167 if {![gdb_simple_compile $me $src executable $compile_flags]} {
3171 # Compilation succeeded so now run it via gdb.
3175 -re ".*Illegal instruction.*${gdb_prompt} $" {
3176 verbose -log "\n$me sve hardware not detected"
3177 set skip_sve_tests 1
3179 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
3180 verbose -log "\n$me: sve hardware detected"
3181 set skip_sve_tests 0
3184 warning "\n$me: default case taken"
3185 set skip_sve_tests 1
3189 remote_file build delete $obj
3191 verbose "$me: returning $skip_sve_tests" 2
3192 return $skip_sve_tests
3196 # A helper that compiles a test case to see if __int128 is supported.
3197 proc gdb_int128_helper {lang} {
3198 return [gdb_can_simple_compile "i128-for-$lang" {
3200 int main() { return 0; }
3204 # Return true if the C compiler understands the __int128 type.
3205 gdb_caching_proc has_int128_c {
3206 return [gdb_int128_helper c]
3209 # Return true if the C++ compiler understands the __int128 type.
3210 gdb_caching_proc has_int128_cxx {
3211 return [gdb_int128_helper c++]
3214 # Return true if the IFUNC feature is unsupported.
3215 gdb_caching_proc skip_ifunc_tests {
3216 if [gdb_can_simple_compile ifunc {
3218 typedef void F (void);
3219 F* g (void) { return &f_; }
3220 void f () __attribute__ ((ifunc ("g")));
3228 # Return whether we should skip tests for showing inlined functions in
3229 # backtraces. Requires get_compiler_info and get_debug_format.
3231 proc skip_inline_frame_tests {} {
3232 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
3233 if { ! [test_debug_format "DWARF 2"] } {
3237 # GCC before 4.1 does not emit DW_AT_call_file / DW_AT_call_line.
3238 if { ([test_compiler_info "gcc-2-*"]
3239 || [test_compiler_info "gcc-3-*"]
3240 || [test_compiler_info "gcc-4-0-*"]) } {
3247 # Return whether we should skip tests for showing variables from
3248 # inlined functions. Requires get_compiler_info and get_debug_format.
3250 proc skip_inline_var_tests {} {
3251 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
3252 if { ! [test_debug_format "DWARF 2"] } {
3259 # Return a 1 if we should skip tests that require hardware breakpoints
3261 proc skip_hw_breakpoint_tests {} {
3262 # Skip tests if requested by the board (note that no_hardware_watchpoints
3263 # disables both watchpoints and breakpoints)
3264 if { [target_info exists gdb,no_hardware_watchpoints]} {
3268 # These targets support hardware breakpoints natively
3269 if { [istarget "i?86-*-*"]
3270 || [istarget "x86_64-*-*"]
3271 || [istarget "ia64-*-*"]
3272 || [istarget "arm*-*-*"]
3273 || [istarget "aarch64*-*-*"]
3274 || [istarget "s390*-*-*"] } {
3281 # Return a 1 if we should skip tests that require hardware watchpoints
3283 proc skip_hw_watchpoint_tests {} {
3284 # Skip tests if requested by the board
3285 if { [target_info exists gdb,no_hardware_watchpoints]} {
3289 # These targets support hardware watchpoints natively
3290 if { [istarget "i?86-*-*"]
3291 || [istarget "x86_64-*-*"]
3292 || [istarget "ia64-*-*"]
3293 || [istarget "arm*-*-*"]
3294 || [istarget "aarch64*-*-*"]
3295 || [istarget "powerpc*-*-linux*"]
3296 || [istarget "s390*-*-*"] } {
3303 # Return a 1 if we should skip tests that require *multiple* hardware
3304 # watchpoints to be active at the same time
3306 proc skip_hw_watchpoint_multi_tests {} {
3307 if { [skip_hw_watchpoint_tests] } {
3311 # These targets support just a single hardware watchpoint
3312 if { [istarget "arm*-*-*"]
3313 || [istarget "powerpc*-*-linux*"] } {
3320 # Return a 1 if we should skip tests that require read/access watchpoints
3322 proc skip_hw_watchpoint_access_tests {} {
3323 if { [skip_hw_watchpoint_tests] } {
3327 # These targets support just write watchpoints
3328 if { [istarget "s390*-*-*"] } {
3335 # Return 1 if we should skip tests that require the runtime unwinder
3336 # hook. This must be invoked while gdb is running, after shared
3337 # libraries have been loaded. This is needed because otherwise a
3338 # shared libgcc won't be visible.
3340 proc skip_unwinder_tests {} {
3344 gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook" {
3345 -re "= .*no debug info.*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
3347 -re "= .*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
3350 -re "No symbol .* in current context.\r\n$gdb_prompt $" {
3354 gdb_test_multiple "info probe" "check for stap probe in unwinder" {
3355 -re ".*libgcc.*unwind.*\r\n$gdb_prompt $" {
3358 -re "\r\n$gdb_prompt $" {
3365 # Return 1 if we should skip tests that require the libstdc++ stap
3366 # probes. This must be invoked while gdb is running, after shared
3367 # libraries have been loaded. PROMPT_REGEXP is the expected prompt.
3369 proc skip_libstdcxx_probe_tests_prompt { prompt_regexp } {
3371 gdb_test_multiple "info probe" "check for stap probe in libstdc++" \
3372 -prompt "$prompt_regexp" {
3373 -re ".*libstdcxx.*catch.*\r\n$prompt_regexp" {
3376 -re "\r\n$prompt_regexp" {
3379 set skip [expr !$supported]
3383 # As skip_libstdcxx_probe_tests_prompt, with gdb_prompt.
3385 proc skip_libstdcxx_probe_tests {} {
3387 return [skip_libstdcxx_probe_tests_prompt "$gdb_prompt $"]
3390 # Return 1 if we should skip tests of the "compile" feature.
3391 # This must be invoked after the inferior has been started.
3393 proc skip_compile_feature_tests {} {
3397 gdb_test_multiple "compile code -- ;" "check for working compile command" {
3398 "Could not load libcc1.*\r\n$gdb_prompt $" {
3401 -re "Command not supported on this host\\..*\r\n$gdb_prompt $" {
3404 -re "\r\n$gdb_prompt $" {
3410 # Helper for gdb_is_target_* procs. TARGET_NAME is the name of the target
3411 # we're looking for (used to build the test name). TARGET_STACK_REGEXP
3412 # is a regexp that will match the output of "maint print target-stack" if
3413 # the target in question is currently pushed. PROMPT_REGEXP is a regexp
3414 # matching the expected prompt after the command output.
3416 proc gdb_is_target_1 { target_name target_stack_regexp prompt_regexp } {
3417 set test "probe for target ${target_name}"
3418 gdb_test_multiple "maint print target-stack" $test \
3419 -prompt "$prompt_regexp" {
3420 -re "${target_stack_regexp}${prompt_regexp}" {
3424 -re "$prompt_regexp" {
3431 # Helper for gdb_is_target_remote where the expected prompt is variable.
3433 proc gdb_is_target_remote_prompt { prompt_regexp } {
3434 return [gdb_is_target_1 "remote" ".*emote serial target in gdb-specific protocol.*" $prompt_regexp]
3437 # Check whether we're testing with the remote or extended-remote
3440 proc gdb_is_target_remote { } {
3443 return [gdb_is_target_remote_prompt "$gdb_prompt $"]
3446 # Check whether we're testing with the native target.
3448 proc gdb_is_target_native { } {
3451 return [gdb_is_target_1 "native" ".*native \\(Native process\\).*" "$gdb_prompt $"]
3454 # Return the effective value of use_gdb_stub.
3456 # If the use_gdb_stub global has been set (it is set when the gdb process is
3457 # spawned), return that. Otherwise, return the value of the use_gdb_stub
3458 # property from the board file.
3460 # This is the preferred way of checking use_gdb_stub, since it allows to check
3461 # the value before the gdb has been spawned and it will return the correct value
3462 # even when it was overriden by the test.
3464 proc use_gdb_stub {} {
3467 if [info exists use_gdb_stub] {
3468 return $use_gdb_stub
3471 return [target_info exists use_gdb_stub]
3474 # Return 1 if the current remote target is an instance of our GDBserver, 0
3475 # otherwise. Return -1 if there was an error and we can't tell.
3477 gdb_caching_proc target_is_gdbserver {
3481 set test "probing for GDBserver"
3483 gdb_test_multiple "monitor help" $test {
3484 -re "The following monitor commands are supported.*Quit GDBserver.*$gdb_prompt $" {
3487 -re "$gdb_prompt $" {
3492 if { $is_gdbserver == -1 } {
3493 verbose -log "Unable to tell whether we are using GDBserver or not."
3496 return $is_gdbserver
3499 # N.B. compiler_info is intended to be local to this file.
3500 # Call test_compiler_info with no arguments to fetch its value.
3501 # Yes, this is counterintuitive when there's get_compiler_info,
3502 # but that's the current API.
3503 if [info exists compiler_info] {
3509 # Figure out what compiler I am using.
3510 # The result is cached so only the first invocation runs the compiler.
3512 # ARG can be empty or "C++". If empty, "C" is assumed.
3514 # There are several ways to do this, with various problems.
3516 # [ gdb_compile -E $ifile -o $binfile.ci ]
3517 # source $binfile.ci
3519 # Single Unix Spec v3 says that "-E -o ..." together are not
3520 # specified. And in fact, the native compiler on hp-ux 11 (among
3521 # others) does not work with "-E -o ...". Most targets used to do
3522 # this, and it mostly worked, because it works with gcc.
3524 # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ]
3525 # source $binfile.ci
3527 # This avoids the problem with -E and -o together. This almost works
3528 # if the build machine is the same as the host machine, which is
3529 # usually true of the targets which are not gcc. But this code does
3530 # not figure which compiler to call, and it always ends up using the C
3531 # compiler. Not good for setting hp_aCC_compiler. Target
3532 # hppa*-*-hpux* used to do this.
3534 # [ gdb_compile -E $ifile > $binfile.ci ]
3535 # source $binfile.ci
3537 # dejagnu target_compile says that it supports output redirection,
3538 # but the code is completely different from the normal path and I
3539 # don't want to sweep the mines from that path. So I didn't even try
3542 # set cppout [ gdb_compile $ifile "" preprocess $args quiet ]
3545 # I actually do this for all targets now. gdb_compile runs the right
3546 # compiler, and TCL captures the output, and I eval the output.
3548 # Unfortunately, expect logs the output of the command as it goes by,
3549 # and dejagnu helpfully prints a second copy of it right afterwards.
3550 # So I turn off expect logging for a moment.
3552 # [ gdb_compile $ifile $ciexe_file executable $args ]
3553 # [ remote_exec $ciexe_file ]
3554 # [ source $ci_file.out ]
3556 # I could give up on -E and just do this.
3557 # I didn't get desperate enough to try this.
3559 # -- chastain 2004-01-06
3561 proc get_compiler_info {{arg ""}} {
3562 # For compiler.c and compiler.cc
3565 # I am going to play with the log to keep noise out.
3569 # These come from compiler.c or compiler.cc
3570 global compiler_info
3572 # Legacy global data symbols.
3575 if [info exists compiler_info] {
3580 # Choose which file to preprocess.
3581 set ifile "${srcdir}/lib/compiler.c"
3582 if { $arg == "c++" } {
3583 set ifile "${srcdir}/lib/compiler.cc"
3586 # Run $ifile through the right preprocessor.
3587 # Toggle gdb.log to keep the compiler output out of the log.
3588 set saved_log [log_file -info]
3590 if [is_remote host] {
3591 # We have to use -E and -o together, despite the comments
3592 # above, because of how DejaGnu handles remote host testing.
3593 set ppout "$outdir/compiler.i"
3594 gdb_compile "${ifile}" "$ppout" preprocess [list "$arg" quiet getting_compiler_info]
3595 set file [open $ppout r]
3596 set cppout [read $file]
3599 set cppout [ gdb_compile "${ifile}" "" preprocess [list "$arg" quiet getting_compiler_info] ]
3601 eval log_file $saved_log
3605 foreach cppline [ split "$cppout" "\n" ] {
3606 if { [ regexp "^#" "$cppline" ] } {
3608 } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } {
3610 } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } {
3612 verbose "get_compiler_info: $cppline" 2
3616 verbose -log "get_compiler_info: $cppline"
3621 # Set to unknown if for some reason compiler_info didn't get defined.
3622 if ![info exists compiler_info] {
3623 verbose -log "get_compiler_info: compiler_info not provided"
3624 set compiler_info "unknown"
3626 # Also set to unknown compiler if any diagnostics happened.
3628 verbose -log "get_compiler_info: got unexpected diagnostics"
3629 set compiler_info "unknown"
3632 # Set the legacy symbols.
3634 regexp "^gcc-(\[0-9\]+)-" "$compiler_info" matchall gcc_compiled
3636 # Log what happened.
3637 verbose -log "get_compiler_info: $compiler_info"
3639 # Most compilers will evaluate comparisons and other boolean
3640 # operations to 0 or 1.
3641 uplevel \#0 { set true 1 }
3642 uplevel \#0 { set false 0 }
3647 # Return the compiler_info string if no arg is provided.
3648 # Otherwise the argument is a glob-style expression to match against
3651 proc test_compiler_info { {compiler ""} } {
3652 global compiler_info
3655 # If no arg, return the compiler_info string.
3656 if [string match "" $compiler] {
3657 return $compiler_info
3660 return [string match $compiler $compiler_info]
3663 proc current_target_name { } {
3665 if [info exists target_info(target,name)] {
3666 set answer $target_info(target,name)
3673 set gdb_wrapper_initialized 0
3674 set gdb_wrapper_target ""
3676 proc gdb_wrapper_init { args } {
3677 global gdb_wrapper_initialized
3678 global gdb_wrapper_file
3679 global gdb_wrapper_flags
3680 global gdb_wrapper_target
3682 # If the wrapper is initialized but the wrapper file cannot be
3683 # found anymore, the wrapper file must be built again.
3684 if { $gdb_wrapper_initialized == 1 && \
3685 [info exists gdb_wrapper_file] && \
3686 ![file exists $gdb_wrapper_file] } {
3687 verbose "reinitializing the wrapper"
3688 set gdb_wrapper_initialized 0
3691 if { $gdb_wrapper_initialized == 1 } { return; }
3693 if {[target_info exists needs_status_wrapper] && \
3694 [target_info needs_status_wrapper] != "0"} {
3695 set result [build_wrapper [standard_output_file "testglue.o"]]
3696 if { $result != "" } {
3697 set gdb_wrapper_file [lindex $result 0]
3698 set gdb_wrapper_flags [lindex $result 1]
3700 warning "Status wrapper failed to build."
3703 set gdb_wrapper_initialized 1
3704 set gdb_wrapper_target [current_target_name]
3707 # Determine options that we always want to pass to the compiler.
3708 gdb_caching_proc universal_compile_options {
3709 set me "universal_compile_options"
3712 set src [standard_temp_file ccopts[pid].c]
3713 set obj [standard_temp_file ccopts[pid].o]
3715 gdb_produce_source $src {
3716 int foo(void) { return 0; }
3719 # Try an option for disabling colored diagnostics. Some compilers
3720 # yield colored diagnostics by default (when run from a tty) unless
3721 # such an option is specified.
3722 set opt "additional_flags=-fdiagnostics-color=never"
3723 set lines [target_compile $src $obj object [list "quiet" $opt]]
3724 if [string match "" $lines] then {
3725 # Seems to have worked; use the option.
3726 lappend options $opt
3731 verbose "$me: returning $options" 2
3735 # Compile the code in $code to a file based on $name, using the flags
3736 # $compile_flag as well as debug, nowarning and quiet.
3737 # Return 1 if code can be compiled
3738 # Leave the file name of the resulting object in the upvar object.
3740 proc gdb_simple_compile {name code {type object} {compile_flags {}} {object obj}} {
3743 switch -regexp -- $type {
3758 foreach flag $compile_flags {
3759 if { "$flag" == "go" } {
3764 set src [standard_temp_file $name-[pid].$ext]
3765 set obj [standard_temp_file $name-[pid].$postfix]
3766 set compile_flags [concat $compile_flags {debug nowarnings quiet}]
3768 gdb_produce_source $src $code
3770 verbose "$name: compiling testfile $src" 2
3771 set lines [gdb_compile $src $obj $type $compile_flags]
3775 if ![string match "" $lines] then {
3776 verbose "$name: compilation failed, returning 0" 2
3782 # Compile the code in $code to a file based on $name, using the flags
3783 # $compile_flag as well as debug, nowarning and quiet.
3784 # Return 1 if code can be compiled
3785 # Delete all created files and objects.
3787 proc gdb_can_simple_compile {name code {type object} {compile_flags ""}} {
3788 set ret [gdb_simple_compile $name $code $type $compile_flags temp_obj]
3789 file delete $temp_obj
3793 # Some targets need to always link a special object in. Save its path here.
3794 global gdb_saved_set_unbuffered_mode_obj
3795 set gdb_saved_set_unbuffered_mode_obj ""
3797 # Compile source files specified by SOURCE into a binary of type TYPE at path
3798 # DEST. gdb_compile is implemented using DejaGnu's target_compile, so the type
3799 # parameter and most options are passed directly to it.
3801 # The type can be one of the following:
3803 # - object: Compile into an object file.
3804 # - executable: Compile and link into an executable.
3805 # - preprocess: Preprocess the source files.
3806 # - assembly: Generate assembly listing.
3808 # The following options are understood and processed by gdb_compile:
3810 # - shlib=so_path: Add SO_PATH to the sources, and enable some target-specific
3811 # quirks to be able to use shared libraries.
3812 # - shlib_load: Link with appropriate libraries to allow the test to
3813 # dynamically load libraries at runtime. For example, on Linux, this adds
3814 # -ldl so that the test can use dlopen.
3815 # - nowarnings: Inhibit all compiler warnings.
3816 # - pie: Force creation of PIE executables.
3817 # - nopie: Prevent creation of PIE executables.
3819 # And here are some of the not too obscure options understood by DejaGnu that
3820 # influence the compilation:
3822 # - additional_flags=flag: Add FLAG to the compiler flags.
3823 # - libs=library: Add LIBRARY to the libraries passed to the linker. The
3824 # argument can be a file, in which case it's added to the sources, or a
3826 # - ldflags=flag: Add FLAG to the linker flags.
3827 # - incdir=path: Add PATH to the searched include directories.
3828 # - libdir=path: Add PATH to the linker searched directories.
3829 # - ada, c++, f77: Compile the file as Ada, C++ or Fortran.
3830 # - debug: Build with debug information.
3831 # - optimize: Build with optimization.
3833 proc gdb_compile {source dest type options} {
3834 global GDB_TESTCASE_OPTIONS
3835 global gdb_wrapper_file
3836 global gdb_wrapper_flags
3837 global gdb_wrapper_initialized
3840 global gdb_saved_set_unbuffered_mode_obj
3842 set outdir [file dirname $dest]
3844 # Add platform-specific options if a shared library was specified using
3845 # "shlib=librarypath" in OPTIONS.
3847 if {[lsearch -exact $options rust] != -1} {
3848 # -fdiagnostics-color is not a rustcc option.
3850 set new_options [universal_compile_options]
3853 # Place (and look for) Fortran `.mod` files in the output
3854 # directory for this specific test.
3855 if {[lsearch -exact $options f77] != -1 \
3856 || [lsearch -exact $options f90] != -1 } {
3858 set mod_path [standard_output_file ""]
3859 lappend new_options "additional_flags=-J${mod_path}"
3864 set getting_compiler_info 0
3865 foreach opt $options {
3866 if {[regexp {^shlib=(.*)} $opt dummy_var shlib_name]
3867 && $type == "executable"} {
3868 if [test_compiler_info "xlc-*"] {
3869 # IBM xlc compiler doesn't accept shared library named other
3870 # than .so: use "-Wl," to bypass this
3871 lappend source "-Wl,$shlib_name"
3872 } elseif { ([istarget "*-*-mingw*"]
3873 || [istarget *-*-cygwin*]
3874 || [istarget *-*-pe*])} {
3875 lappend source "${shlib_name}.a"
3877 lappend source $shlib_name
3879 if { $shlib_found == 0 } {
3881 if { ([istarget "*-*-mingw*"]
3882 || [istarget *-*-cygwin*]) } {
3883 lappend new_options "additional_flags=-Wl,--enable-auto-import"
3885 if { [test_compiler_info "gcc-*"] || [test_compiler_info "clang-*"] } {
3886 # Undo debian's change in the default.
3887 # Put it at the front to not override any user-provided
3888 # value, and to make sure it appears in front of all the
3890 lappend new_options "early_flags=-Wl,--no-as-needed"
3893 } elseif { $opt == "shlib_load" && $type == "executable" } {
3895 } elseif { $opt == "getting_compiler_info" } {
3896 # If this is set, calling test_compiler_info will cause recursion.
3897 set getting_compiler_info 1
3899 lappend new_options $opt
3903 # Ensure stack protector is disabled for GCC, as this causes problems with
3904 # DWARF line numbering.
3905 # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88432
3906 # This option defaults to on for Debian/Ubuntu.
3907 if { $getting_compiler_info == 0
3908 && [test_compiler_info {gcc-*-*}]
3909 && !([test_compiler_info {gcc-[0-3]-*}]
3910 || [test_compiler_info {gcc-4-0-*}])
3911 && [lsearch -exact $options rust] == -1} {
3912 # Put it at the front to not override any user-provided value.
3913 lappend new_options "early_flags=-fno-stack-protector"
3916 # Because we link with libraries using their basename, we may need
3917 # (depending on the platform) to set a special rpath value, to allow
3918 # the executable to find the libraries it depends on.
3919 if { $shlib_load || $shlib_found } {
3920 if { ([istarget "*-*-mingw*"]
3921 || [istarget *-*-cygwin*]
3922 || [istarget *-*-pe*]) } {
3923 # Do not need anything.
3924 } elseif { [istarget *-*-freebsd*] || [istarget *-*-openbsd*] } {
3925 lappend new_options "ldflags=-Wl,-rpath,${outdir}"
3926 } elseif { [istarget arm*-*-symbianelf*] } {
3927 if { $shlib_load } {
3928 lappend new_options "libs=-ldl"
3931 if { $shlib_load } {
3932 lappend new_options "libs=-ldl"
3934 lappend new_options "ldflags=-Wl,-rpath,\\\$ORIGIN"
3937 set options $new_options
3939 if [info exists GDB_TESTCASE_OPTIONS] {
3940 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS"
3942 verbose "options are $options"
3943 verbose "source is $source $dest $type $options"
3947 if {[target_info exists needs_status_wrapper] && \
3948 [target_info needs_status_wrapper] != "0" && \
3949 [info exists gdb_wrapper_file]} {
3950 lappend options "libs=${gdb_wrapper_file}"
3951 lappend options "ldflags=${gdb_wrapper_flags}"
3954 # Replace the "nowarnings" option with the appropriate additional_flags
3955 # to disable compiler warnings.
3956 set nowarnings [lsearch -exact $options nowarnings]
3957 if {$nowarnings != -1} {
3958 if [target_info exists gdb,nowarnings_flag] {
3959 set flag "additional_flags=[target_info gdb,nowarnings_flag]"
3961 set flag "additional_flags=-w"
3963 set options [lreplace $options $nowarnings $nowarnings $flag]
3966 # Replace the "pie" option with the appropriate compiler and linker flags
3967 # to enable PIE executables.
3968 set pie [lsearch -exact $options pie]
3970 if [target_info exists gdb,pie_flag] {
3971 set flag "additional_flags=[target_info gdb,pie_flag]"
3973 # For safety, use fPIE rather than fpie. On AArch64, m68k, PowerPC
3974 # and SPARC, fpie can cause compile errors due to the GOT exceeding
3975 # a maximum size. On other architectures the two flags are
3976 # identical (see the GCC manual). Note Debian9 and Ubuntu16.10
3977 # onwards default GCC to using fPIE. If you do require fpie, then
3978 # it can be set using the pie_flag.
3979 set flag "additional_flags=-fPIE"
3981 set options [lreplace $options $pie $pie $flag]
3983 if [target_info exists gdb,pie_ldflag] {
3984 set flag "ldflags=[target_info gdb,pie_ldflag]"
3986 set flag "ldflags=-pie"
3988 lappend options "$flag"
3991 # Replace the "nopie" option with the appropriate linker flag to disable
3992 # PIE executables. There are no compiler flags for this option.
3993 set nopie [lsearch -exact $options nopie]
3995 if [target_info exists gdb,nopie_flag] {
3996 set flag "ldflags=[target_info gdb,nopie_flag]"
3998 set flag "ldflags=-no-pie"
4000 set options [lreplace $options $nopie $nopie $flag]
4003 if { $type == "executable" } {
4004 if { ([istarget "*-*-mingw*"]
4005 || [istarget "*-*-*djgpp"]
4006 || [istarget "*-*-cygwin*"])} {
4007 # Force output to unbuffered mode, by linking in an object file
4008 # with a global contructor that calls setvbuf.
4010 # Compile the special object separately for two reasons:
4011 # 1) Insulate it from $options.
4012 # 2) Avoid compiling it for every gdb_compile invocation,
4013 # which is time consuming, especially if we're remote
4016 if { $gdb_saved_set_unbuffered_mode_obj == "" } {
4017 verbose "compiling gdb_saved_set_unbuffered_obj"
4018 set unbuf_src ${srcdir}/lib/set_unbuffered_mode.c
4019 set unbuf_obj ${objdir}/set_unbuffered_mode.o
4021 set result [gdb_compile "${unbuf_src}" "${unbuf_obj}" object {nowarnings}]
4022 if { $result != "" } {
4025 if {[is_remote host]} {
4026 set gdb_saved_set_unbuffered_mode_obj set_unbuffered_mode_saved.o
4028 set gdb_saved_set_unbuffered_mode_obj ${objdir}/set_unbuffered_mode_saved.o
4030 # Link a copy of the output object, because the
4031 # original may be automatically deleted.
4032 remote_download host $unbuf_obj $gdb_saved_set_unbuffered_mode_obj
4034 verbose "gdb_saved_set_unbuffered_obj already compiled"
4037 # Rely on the internal knowledge that the global ctors are ran in
4038 # reverse link order. In that case, we can use ldflags to
4039 # avoid copying the object file to the host multiple
4041 # This object can only be added if standard libraries are
4042 # used. Thus, we need to disable it if -nostdlib option is used
4043 if {[lsearch -regexp $options "-nostdlib"] < 0 } {
4044 lappend options "ldflags=$gdb_saved_set_unbuffered_mode_obj"
4049 set result [target_compile $source $dest $type $options]
4051 # Prune uninteresting compiler (and linker) output.
4052 regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result
4054 regsub "\[\r\n\]*$" "$result" "" result
4055 regsub "^\[\r\n\]*" "$result" "" result
4057 if { $type == "executable" && $result == "" \
4058 && ($nopie != -1 || $pie != -1) } {
4059 set is_pie [exec_is_pie "$dest"]
4060 if { $nopie != -1 && $is_pie == 1 } {
4061 set result "nopie failed to prevent PIE executable"
4062 } elseif { $pie != -1 && $is_pie == 0 } {
4063 set result "pie failed to generate PIE executable"
4067 if {[lsearch $options quiet] < 0} {
4068 # We shall update this on a per language basis, to avoid
4069 # changing the entire testsuite in one go.
4070 if {[lsearch $options f77] >= 0} {
4071 gdb_compile_test $source $result
4072 } elseif { $result != "" } {
4073 clone_output "gdb compile failed, $result"
4080 # This is just like gdb_compile, above, except that it tries compiling
4081 # against several different thread libraries, to see which one this
4083 proc gdb_compile_pthreads {source dest type options} {
4084 if {$type != "executable"} {
4085 return [gdb_compile $source $dest $type $options]
4088 set why_msg "unrecognized error"
4089 foreach lib {-lpthreads -lpthread -lthread ""} {
4090 # This kind of wipes out whatever libs the caller may have
4091 # set. Or maybe theirs will override ours. How infelicitous.
4092 set options_with_lib [concat $options [list libs=$lib quiet]]
4093 set ccout [gdb_compile $source $dest $type $options_with_lib]
4094 switch -regexp -- $ccout {
4095 ".*no posix threads support.*" {
4096 set why_msg "missing threads include file"
4099 ".*cannot open -lpthread.*" {
4100 set why_msg "missing runtime threads library"
4102 ".*Can't find library for -lpthread.*" {
4103 set why_msg "missing runtime threads library"
4106 pass "successfully compiled posix threads test case"
4112 if {!$built_binfile} {
4113 unsupported "couldn't compile [file tail $source]: ${why_msg}"
4118 # Build a shared library from SOURCES.
4120 proc gdb_compile_shlib {sources dest options} {
4121 set obj_options $options
4124 if { [lsearch -exact $options "c++"] >= 0 } {
4125 set info_options "c++"
4127 if [get_compiler_info ${info_options}] {
4131 switch -glob [test_compiler_info] {
4133 lappend obj_options "additional_flags=-qpic"
4136 if { !([istarget "*-*-cygwin*"]
4137 || [istarget "*-*-mingw*"]) } {
4138 lappend obj_options "additional_flags=-fpic"
4142 if { !([istarget "powerpc*-*-aix*"]
4143 || [istarget "rs6000*-*-aix*"]
4144 || [istarget "*-*-cygwin*"]
4145 || [istarget "*-*-mingw*"]
4146 || [istarget "*-*-pe*"]) } {
4147 lappend obj_options "additional_flags=-fpic"
4151 lappend obj_options "additional_flags=-fpic"
4154 # don't know what the compiler is...
4158 set outdir [file dirname $dest]
4160 foreach source $sources {
4161 set sourcebase [file tail $source]
4162 if {[file extension $source] == ".o"} {
4163 # Already a .o file.
4164 lappend objects $source
4165 } elseif {[gdb_compile $source "${outdir}/${sourcebase}.o" object \
4166 $obj_options] != ""} {
4169 lappend objects ${outdir}/${sourcebase}.o
4173 set link_options $options
4174 if [test_compiler_info "xlc-*"] {
4175 lappend link_options "additional_flags=-qmkshrobj"
4177 lappend link_options "additional_flags=-shared"
4179 if { ([istarget "*-*-mingw*"]
4180 || [istarget *-*-cygwin*]
4181 || [istarget *-*-pe*]) } {
4182 if { [is_remote host] } {
4183 set name [file tail ${dest}]
4187 lappend link_options "additional_flags=-Wl,--out-implib,${name}.a"
4189 # Set the soname of the library. This causes the linker on ELF
4190 # systems to create the DT_NEEDED entry in the executable referring
4191 # to the soname of the library, and not its absolute path. This
4192 # (using the absolute path) would be problem when testing on a
4195 # In conjunction with setting the soname, we add the special
4196 # rpath=$ORIGIN value when building the executable, so that it's
4197 # able to find the library in its own directory.
4198 set destbase [file tail $dest]
4199 lappend link_options "additional_flags=-Wl,-soname,$destbase"
4202 if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
4205 if { [is_remote host]
4206 && ([istarget "*-*-mingw*"]
4207 || [istarget *-*-cygwin*]
4208 || [istarget *-*-pe*]) } {
4209 set dest_tail_name [file tail ${dest}]
4210 remote_upload host $dest_tail_name.a ${dest}.a
4211 remote_file host delete $dest_tail_name.a
4217 # This is just like gdb_compile_shlib, above, except that it tries compiling
4218 # against several different thread libraries, to see which one this
4220 proc gdb_compile_shlib_pthreads {sources dest options} {
4222 set why_msg "unrecognized error"
4223 foreach lib {-lpthreads -lpthread -lthread ""} {
4224 # This kind of wipes out whatever libs the caller may have
4225 # set. Or maybe theirs will override ours. How infelicitous.
4226 set options_with_lib [concat $options [list libs=$lib quiet]]
4227 set ccout [gdb_compile_shlib $sources $dest $options_with_lib]
4228 switch -regexp -- $ccout {
4229 ".*no posix threads support.*" {
4230 set why_msg "missing threads include file"
4233 ".*cannot open -lpthread.*" {
4234 set why_msg "missing runtime threads library"
4236 ".*Can't find library for -lpthread.*" {
4237 set why_msg "missing runtime threads library"
4240 pass "successfully compiled posix threads test case"
4246 if {!$built_binfile} {
4247 unsupported "couldn't compile $sources: ${why_msg}"
4252 # This is just like gdb_compile_pthreads, above, except that we always add the
4253 # objc library for compiling Objective-C programs
4254 proc gdb_compile_objc {source dest type options} {
4256 set why_msg "unrecognized error"
4257 foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} {
4258 # This kind of wipes out whatever libs the caller may have
4259 # set. Or maybe theirs will override ours. How infelicitous.
4260 if { $lib == "solaris" } {
4261 set lib "-lpthread -lposix4"
4263 if { $lib != "-lobjc" } {
4264 set lib "-lobjc $lib"
4266 set options_with_lib [concat $options [list libs=$lib quiet]]
4267 set ccout [gdb_compile $source $dest $type $options_with_lib]
4268 switch -regexp -- $ccout {
4269 ".*no posix threads support.*" {
4270 set why_msg "missing threads include file"
4273 ".*cannot open -lpthread.*" {
4274 set why_msg "missing runtime threads library"
4276 ".*Can't find library for -lpthread.*" {
4277 set why_msg "missing runtime threads library"
4280 pass "successfully compiled objc with posix threads test case"
4286 if {!$built_binfile} {
4287 unsupported "couldn't compile [file tail $source]: ${why_msg}"
4292 # Build an OpenMP program from SOURCE. See prefatory comment for
4293 # gdb_compile, above, for discussion of the parameters to this proc.
4295 proc gdb_compile_openmp {source dest type options} {
4296 lappend options "additional_flags=-fopenmp"
4297 return [gdb_compile $source $dest $type $options]
4300 # Send a command to GDB.
4301 # For options for TYPE see gdb_stdin_log_write
4303 proc send_gdb { string {type standard}} {
4304 global suppress_flag
4305 if { $suppress_flag } {
4308 gdb_stdin_log_write $string $type
4309 return [remote_send host "$string"]
4312 # Send STRING to the inferior's terminal.
4314 proc send_inferior { string } {
4315 global inferior_spawn_id
4317 if {[catch "send -i $inferior_spawn_id -- \$string" errorInfo]} {
4327 proc gdb_expect { args } {
4328 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
4329 set atimeout [lindex $args 0]
4330 set expcode [list [lindex $args 1]]
4335 # A timeout argument takes precedence, otherwise of all the timeouts
4336 # select the largest.
4337 if [info exists atimeout] {
4340 set tmt [get_largest_timeout]
4343 global suppress_flag
4344 global remote_suppress_flag
4345 if [info exists remote_suppress_flag] {
4346 set old_val $remote_suppress_flag
4348 if [info exists suppress_flag] {
4349 if { $suppress_flag } {
4350 set remote_suppress_flag 1
4354 {uplevel remote_expect host $tmt $expcode} string]
4355 if [info exists old_val] {
4356 set remote_suppress_flag $old_val
4358 if [info exists remote_suppress_flag] {
4359 unset remote_suppress_flag
4364 global errorInfo errorCode
4366 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
4368 return -code $code $string
4372 # gdb_expect_list TEST SENTINEL LIST -- expect a sequence of outputs
4374 # Check for long sequence of output by parts.
4375 # TEST: is the test message to be printed with the test success/fail.
4376 # SENTINEL: Is the terminal pattern indicating that output has finished.
4377 # LIST: is the sequence of outputs to match.
4378 # If the sentinel is recognized early, it is considered an error.
4381 # 1 if the test failed,
4382 # 0 if the test passes,
4383 # -1 if there was an internal error.
4385 proc gdb_expect_list {test sentinel list} {
4387 global suppress_flag
4390 if { $suppress_flag } {
4392 unresolved "${test}"
4394 while { ${index} < [llength ${list}] } {
4395 set pattern [lindex ${list} ${index}]
4396 set index [expr ${index} + 1]
4397 verbose -log "gdb_expect_list pattern: /$pattern/" 2
4398 if { ${index} == [llength ${list}] } {
4401 -re "${pattern}${sentinel}" {
4402 # pass "${test}, pattern ${index} + sentinel"
4405 fail "${test} (pattern ${index} + sentinel)"
4408 -re ".*A problem internal to GDB has been detected" {
4409 fail "${test} (GDB internal error)"
4411 gdb_internal_error_resync
4414 fail "${test} (pattern ${index} + sentinel) (timeout)"
4419 # unresolved "${test}, pattern ${index} + sentinel"
4425 # pass "${test}, pattern ${index}"
4428 fail "${test} (pattern ${index})"
4431 -re ".*A problem internal to GDB has been detected" {
4432 fail "${test} (GDB internal error)"
4434 gdb_internal_error_resync
4437 fail "${test} (pattern ${index}) (timeout)"
4442 # unresolved "${test}, pattern ${index}"
4456 proc gdb_suppress_entire_file { reason } {
4457 global suppress_flag
4460 set suppress_flag -1
4464 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
4465 # gdb_expect to fail immediately (until the next call to
4466 # gdb_stop_suppressing_tests).
4468 proc gdb_suppress_tests { args } {
4469 global suppress_flag
4471 return; # fnf - disable pending review of results where
4472 # testsuite ran better without this
4475 if { $suppress_flag == 1 } {
4476 if { [llength $args] > 0 } {
4477 warning "[lindex $args 0]\n"
4479 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n"
4485 # Clear suppress_flag.
4487 proc gdb_stop_suppressing_tests { } {
4488 global suppress_flag
4490 if [info exists suppress_flag] {
4491 if { $suppress_flag > 0 } {
4493 clone_output "Tests restarted.\n"
4500 proc gdb_clear_suppressed { } {
4501 global suppress_flag
4506 # Spawn the gdb process.
4508 # This doesn't expect any output or do any other initialization,
4509 # leaving those to the caller.
4511 # Overridable function -- you can override this function in your
4514 proc gdb_spawn { } {
4518 # Spawn GDB with CMDLINE_FLAGS appended to the GDBFLAGS global.
4520 proc gdb_spawn_with_cmdline_opts { cmdline_flags } {
4523 set saved_gdbflags $GDBFLAGS
4525 if {$GDBFLAGS != ""} {
4528 append GDBFLAGS $cmdline_flags
4532 set GDBFLAGS $saved_gdbflags
4537 # Start gdb running, wait for prompt, and disable the pagers.
4539 # Overridable function -- you can override this function in your
4542 proc gdb_start { } {
4547 catch default_gdb_exit
4550 # Return true if we can spawn a program on the target and attach to
4553 proc can_spawn_for_attach { } {
4554 # We use exp_pid to get the inferior's pid, assuming that gives
4555 # back the pid of the program. On remote boards, that would give
4556 # us instead the PID of e.g., the ssh client, etc.
4557 if [is_remote target] then {
4561 # The "attach" command doesn't make sense when the target is
4562 # stub-like, where GDB finds the program already started on
4563 # initial connection.
4564 if {[target_info exists use_gdb_stub]} {
4572 # Kill a progress previously started with spawn_wait_for_attach, and
4573 # reap its wait status. PROC_SPAWN_ID is the spawn id associated with
4576 proc kill_wait_spawned_process { proc_spawn_id } {
4577 set pid [exp_pid -i $proc_spawn_id]
4579 verbose -log "killing ${pid}"
4580 remote_exec build "kill -9 ${pid}"
4582 verbose -log "closing ${proc_spawn_id}"
4583 catch "close -i $proc_spawn_id"
4584 verbose -log "waiting for ${proc_spawn_id}"
4586 # If somehow GDB ends up still attached to the process here, a
4587 # blocking wait hangs until gdb is killed (or until gdb / the
4588 # ptracer reaps the exit status too, but that won't happen because
4589 # something went wrong.) Passing -nowait makes expect tell Tcl to
4590 # wait for the PID in the background. That's fine because we
4591 # don't care about the exit status. */
4592 wait -nowait -i $proc_spawn_id
4595 # Returns the process id corresponding to the given spawn id.
4597 proc spawn_id_get_pid { spawn_id } {
4598 set testpid [exp_pid -i $spawn_id]
4600 if { [istarget "*-*-cygwin*"] } {
4601 # testpid is the Cygwin PID, GDB uses the Windows PID, which
4602 # might be different due to the way fork/exec works.
4603 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
4609 # Start a set of programs running and then wait for a bit, to be sure
4610 # that they can be attached to. Return a list of processes spawn IDs,
4611 # one element for each process spawned. It's a test error to call
4612 # this when [can_spawn_for_attach] is false.
4614 proc spawn_wait_for_attach { executable_list } {
4615 set spawn_id_list {}
4617 if ![can_spawn_for_attach] {
4618 # The caller should have checked can_spawn_for_attach itself
4619 # before getting here.
4620 error "can't spawn for attach with this target/board"
4623 foreach {executable} $executable_list {
4624 # Note we use Expect's spawn, not Tcl's exec, because with
4625 # spawn we control when to wait for/reap the process. That
4626 # allows killing the process by PID without being subject to
4628 lappend spawn_id_list [remote_spawn target $executable]
4633 return $spawn_id_list
4637 # gdb_load_cmd -- load a file into the debugger.
4638 # ARGS - additional args to load command.
4639 # return a -1 if anything goes wrong.
4641 proc gdb_load_cmd { args } {
4644 if [target_info exists gdb_load_timeout] {
4645 set loadtimeout [target_info gdb_load_timeout]
4647 set loadtimeout 1600
4649 send_gdb "load $args\n"
4650 verbose "Timeout is now $loadtimeout seconds" 2
4651 gdb_expect $loadtimeout {
4652 -re "Loading section\[^\r\]*\r\n" {
4655 -re "Start address\[\r\]*\r\n" {
4658 -re "Transfer rate\[\r\]*\r\n" {
4661 -re "Memory access error\[^\r\]*\r\n" {
4662 perror "Failed to load program"
4665 -re "$gdb_prompt $" {
4668 -re "(.*)\r\n$gdb_prompt " {
4669 perror "Unexpected reponse from 'load' -- $expect_out(1,string)"
4673 perror "Timed out trying to load $args."
4680 # Invoke "gcore". CORE is the name of the core file to write. TEST
4681 # is the name of the test case. This will return 1 if the core file
4682 # was created, 0 otherwise. If this fails to make a core file because
4683 # this configuration of gdb does not support making core files, it
4684 # will call "unsupported", not "fail". However, if this fails to make
4685 # a core file for some other reason, then it will call "fail".
4687 proc gdb_gcore_cmd {core test} {
4691 gdb_test_multiple "gcore $core" $test {
4692 -re "Saved corefile .*\[\r\n\]+$gdb_prompt $" {
4696 -re "(?:Can't create a corefile|Target does not support core file generation\\.)\[\r\n\]+$gdb_prompt $" {
4704 # Load core file CORE. TEST is the name of the test case.
4705 # This will record a pass/fail for loading the core file.
4707 # 1 - core file is successfully loaded
4708 # 0 - core file loaded but has a non fatal error
4709 # -1 - core file failed to load
4711 proc gdb_core_cmd { core test } {
4714 gdb_test_multiple "core $core" "$test" {
4715 -re "\\\[Thread debugging using \[^ \r\n\]* enabled\\\]\r\n" {
4718 -re " is not a core dump:.*\r\n$gdb_prompt $" {
4719 fail "$test (bad file format)"
4722 -re -wrap "[string_to_regexp $core]: No such file or directory.*" {
4723 fail "$test (file not found)"
4726 -re "Couldn't find .* registers in core file.*\r\n$gdb_prompt $" {
4727 fail "$test (incomplete note section)"
4730 -re "Core was generated by .*\r\n$gdb_prompt $" {
4734 -re ".*$gdb_prompt $" {
4739 fail "$test (timeout)"
4743 fail "unsupported output from 'core' command"
4747 # Return the filename to download to the target and load on the target
4748 # for this shared library. Normally just LIBNAME, unless shared libraries
4749 # for this target have separate link and load images.
4751 proc shlib_target_file { libname } {
4755 # Return the filename GDB will load symbols from when debugging this
4756 # shared library. Normally just LIBNAME, unless shared libraries for
4757 # this target have separate link and load images.
4759 proc shlib_symbol_file { libname } {
4763 # Return the filename to download to the target and load for this
4764 # executable. Normally just BINFILE unless it is renamed to something
4765 # else for this target.
4767 proc exec_target_file { binfile } {
4771 # Return the filename GDB will load symbols from when debugging this
4772 # executable. Normally just BINFILE unless executables for this target
4773 # have separate files for symbols.
4775 proc exec_symbol_file { binfile } {
4779 # Rename the executable file. Normally this is just BINFILE1 being renamed
4780 # to BINFILE2, but some targets require multiple binary files.
4781 proc gdb_rename_execfile { binfile1 binfile2 } {
4782 file rename -force [exec_target_file ${binfile1}] \
4783 [exec_target_file ${binfile2}]
4784 if { [exec_target_file ${binfile1}] != [exec_symbol_file ${binfile1}] } {
4785 file rename -force [exec_symbol_file ${binfile1}] \
4786 [exec_symbol_file ${binfile2}]
4790 # "Touch" the executable file to update the date. Normally this is just
4791 # BINFILE, but some targets require multiple files.
4792 proc gdb_touch_execfile { binfile } {
4793 set time [clock seconds]
4794 file mtime [exec_target_file ${binfile}] $time
4795 if { [exec_target_file ${binfile}] != [exec_symbol_file ${binfile}] } {
4796 file mtime [exec_symbol_file ${binfile}] $time
4800 # Like remote_download but provides a gdb-specific behavior.
4802 # If the destination board is remote, the local file FROMFILE is transferred as
4803 # usual with remote_download to TOFILE on the remote board. The destination
4804 # filename is added to the CLEANFILES global, so it can be cleaned up at the
4807 # If the destination board is local, the destination path TOFILE is passed
4808 # through standard_output_file, and FROMFILE is copied there.
4810 # In both cases, if TOFILE is omitted, it defaults to the [file tail] of
4813 proc gdb_remote_download {dest fromfile {tofile {}}} {
4814 # If TOFILE is not given, default to the same filename as FROMFILE.
4815 if {[string length $tofile] == 0} {
4816 set tofile [file tail $fromfile]
4819 if {[is_remote $dest]} {
4820 # When the DEST is remote, we simply send the file to DEST.
4823 set destname [remote_download $dest $fromfile $tofile]
4824 lappend cleanfiles $destname
4828 # When the DEST is local, we copy the file to the test directory (where
4829 # the executable is).
4831 # Note that we pass TOFILE through standard_output_file, regardless of
4832 # whether it is absolute or relative, because we don't want the tests
4833 # to be able to write outside their standard output directory.
4835 set tofile [standard_output_file $tofile]
4837 file copy -force $fromfile $tofile
4843 # gdb_load_shlib LIB...
4845 # Copy the listed library to the target.
4847 proc gdb_load_shlib { file } {
4850 if ![info exists gdb_spawn_id] {
4851 perror "gdb_load_shlib: GDB is not running"
4854 set dest [gdb_remote_download target [shlib_target_file $file]]
4856 if {[is_remote target]} {
4857 # If the target is remote, we need to tell gdb where to find the
4860 # We could set this even when not testing remotely, but a user
4861 # generally won't set it unless necessary. In order to make the tests
4862 # more like the real-life scenarios, we don't set it for local testing.
4863 gdb_test "set solib-search-path [file dirname $file]" "" ""
4870 # gdb_load -- load a file into the debugger. Specifying no file
4871 # defaults to the executable currently being debugged.
4872 # The return value is 0 for success, -1 for failure.
4873 # Many files in config/*.exp override this procedure.
4875 proc gdb_load { arg } {
4877 return [gdb_file_cmd $arg]
4882 # gdb_reload -- load a file into the target. Called before "running",
4883 # either the first time or after already starting the program once,
4884 # for remote targets. Most files that override gdb_load should now
4885 # override this instead.
4887 # INFERIOR_ARGS contains the arguments to pass to the inferiors, as a
4888 # single string to get interpreted by a shell. If the target board
4889 # overriding gdb_reload is a "stub", then it should arrange things such
4890 # these arguments make their way to the inferior process.
4892 proc gdb_reload { {inferior_args {}} } {
4893 # For the benefit of existing configurations, default to gdb_load.
4894 # Specifying no file defaults to the executable currently being
4896 return [gdb_load ""]
4899 proc gdb_continue { function } {
4902 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"]
4905 # Default implementation of gdb_init.
4906 proc default_gdb_init { test_file_name } {
4907 global gdb_wrapper_initialized
4908 global gdb_wrapper_target
4909 global gdb_test_file_name
4913 # Reset the timeout value to the default. This way, any testcase
4914 # that changes the timeout value without resetting it cannot affect
4915 # the timeout used in subsequent testcases.
4916 global gdb_test_timeout
4918 set timeout $gdb_test_timeout
4920 if { [regexp ".*gdb\.reverse\/.*" $test_file_name]
4921 && [target_info exists gdb_reverse_timeout] } {
4922 set timeout [target_info gdb_reverse_timeout]
4925 # If GDB_INOTIFY is given, check for writes to '.'. This is a
4926 # debugging tool to help confirm that the test suite is
4927 # parallel-safe. You need "inotifywait" from the
4928 # inotify-tools package to use this.
4929 global GDB_INOTIFY inotify_pid
4930 if {[info exists GDB_INOTIFY] && ![info exists inotify_pid]} {
4931 global outdir tool inotify_log_file
4933 set exclusions {outputs temp gdb[.](log|sum) cache}
4934 set exclusion_re ([join $exclusions |])
4936 set inotify_log_file [standard_temp_file inotify.out]
4937 set inotify_pid [exec inotifywait -r -m -e move,create,delete . \
4938 --exclude $exclusion_re \
4939 |& tee -a $outdir/$tool.log $inotify_log_file &]
4941 # Wait for the watches; hopefully this is long enough.
4944 # Clear the log so that we don't emit a warning the first time
4946 set fd [open $inotify_log_file w]
4950 # Block writes to all banned variables, and invocation of all
4951 # banned procedures...
4952 global banned_variables
4953 global banned_procedures
4954 global banned_traced
4955 if (!$banned_traced) {
4956 foreach banned_var $banned_variables {
4957 global "$banned_var"
4958 trace add variable "$banned_var" write error
4960 foreach banned_proc $banned_procedures {
4961 global "$banned_proc"
4962 trace add execution "$banned_proc" enter error
4967 # We set LC_ALL, LC_CTYPE, and LANG to C so that we get the same
4968 # messages as expected.
4973 # Don't let a .inputrc file or an existing setting of INPUTRC mess up
4974 # the test results. Even if /dev/null doesn't exist on the particular
4975 # platform, the readline library will use the default setting just by
4976 # failing to open the file. OTOH, opening /dev/null successfully will
4977 # also result in the default settings being used since nothing will be
4978 # read from this file.
4979 setenv INPUTRC "/dev/null"
4981 # This disables style output, which would interfere with many
4985 # Ensure that GDBHISTFILE and GDBHISTSIZE are removed from the
4986 # environment, we don't want these modifications to the history
4988 unset -nocomplain ::env(GDBHISTFILE)
4989 unset -nocomplain ::env(GDBHISTSIZE)
4991 # Initialize GDB's pty with a fixed size, to make sure we avoid pagination
4992 # during startup. See "man expect" for details about stty_init.
4994 set stty_init "rows 25 cols 80"
4996 # Some tests (for example gdb.base/maint.exp) shell out from gdb to use
4997 # grep. Clear GREP_OPTIONS to make the behavior predictable,
4998 # especially having color output turned on can cause tests to fail.
4999 setenv GREP_OPTIONS ""
5001 # Clear $gdbserver_reconnect_p.
5002 global gdbserver_reconnect_p
5003 set gdbserver_reconnect_p 1
5004 unset gdbserver_reconnect_p
5006 # Clear $last_loaded_file
5007 global last_loaded_file
5008 unset -nocomplain last_loaded_file
5010 # Reset GDB number of instances
5011 global gdb_instances
5016 gdb_clear_suppressed
5018 set gdb_test_file_name [file rootname [file tail $test_file_name]]
5020 # Make sure that the wrapper is rebuilt
5021 # with the appropriate multilib option.
5022 if { $gdb_wrapper_target != [current_target_name] } {
5023 set gdb_wrapper_initialized 0
5026 # Unlike most tests, we have a small number of tests that generate
5027 # a very large amount of output. We therefore increase the expect
5028 # buffer size to be able to contain the entire test output. This
5029 # is especially needed by gdb.base/info-macros.exp.
5031 # Also set this value for the currently running GDB.
5032 match_max [match_max -d]
5034 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
5035 set pf_prefix "[file tail [file dirname $test_file_name]]/[file tail $test_file_name]:"
5038 if [target_info exists gdb_prompt] {
5039 set gdb_prompt [target_info gdb_prompt]
5041 set gdb_prompt "\\(gdb\\)"
5044 if [info exists use_gdb_stub] {
5048 gdb_setup_known_globals
5050 if { [info procs ::gdb_tcl_unknown] != "" } {
5051 # Dejagnu overrides proc unknown. The dejagnu version may trigger in a
5052 # test-case but abort the entire test run. To fix this, we install a
5053 # local version here, which reverts dejagnu's override, and restore
5054 # dejagnu's version in gdb_finish.
5055 rename ::unknown ::dejagnu_unknown
5056 proc unknown { args } {
5057 # Use tcl's unknown.
5058 return [uplevel 1 ::gdb_tcl_unknown $args]
5063 # Return a path using GDB_PARALLEL.
5064 # ARGS is a list of path elements to append to "$objdir/$GDB_PARALLEL".
5065 # GDB_PARALLEL must be defined, the caller must check.
5067 # The default value for GDB_PARALLEL is, canonically, ".".
5068 # The catch is that tests don't expect an additional "./" in file paths so
5069 # omit any directory for the default case.
5070 # GDB_PARALLEL is written as "yes" for the default case in Makefile.in to mark
5071 # its special handling.
5073 proc make_gdb_parallel_path { args } {
5074 global GDB_PARALLEL objdir
5075 set joiner [list "file" "join" $objdir]
5076 if { [info exists GDB_PARALLEL] && $GDB_PARALLEL != "yes" } {
5077 lappend joiner $GDB_PARALLEL
5079 set joiner [concat $joiner $args]
5080 return [eval $joiner]
5083 # Turn BASENAME into a full file name in the standard output
5084 # directory. It is ok if BASENAME is the empty string; in this case
5085 # the directory is returned.
5087 proc standard_output_file {basename} {
5088 global objdir subdir gdb_test_file_name
5090 set dir [make_gdb_parallel_path outputs $subdir $gdb_test_file_name]
5092 # If running on MinGW, replace /c/foo with c:/foo
5093 if { [ishost *-*-mingw*] } {
5094 set dir [exec sh -c "cd ${dir} && pwd -W"]
5096 return [file join $dir $basename]
5099 # Turn BASENAME into a full file name in the standard output directory. If
5100 # GDB has been launched more than once then append the count, starting with
5103 proc standard_output_file_with_gdb_instance {basename} {
5104 global gdb_instances
5105 set count [expr $gdb_instances - 1 ]
5108 return [standard_output_file $basename]
5110 return [standard_output_file ${basename}.${count}]
5113 # Return the name of a file in our standard temporary directory.
5115 proc standard_temp_file {basename} {
5116 # Since a particular runtest invocation is only executing a single test
5117 # file at any given time, we can use the runtest pid to build the
5118 # path of the temp directory.
5119 set dir [make_gdb_parallel_path temp [pid]]
5121 return [file join $dir $basename]
5124 # Rename file A to file B, if B does not already exists. Otherwise, leave B
5125 # as is and delete A. Return 1 if rename happened.
5127 proc tentative_rename { a b } {
5128 global errorInfo errorCode
5129 set code [catch {file rename -- $a $b} result]
5130 if { $code == 1 && [lindex $errorCode 0] == "POSIX" \
5131 && [lindex $errorCode 1] == "EEXIST" } {
5136 return -code error -errorinfo $errorInfo -errorcode $errorCode $result
5137 } elseif {$code > 1} {
5138 return -code $code $result
5143 # Create a file with name FILENAME and contents TXT in the cache directory.
5144 # If EXECUTABLE, mark the new file for execution.
5146 proc cached_file { filename txt {executable 0}} {
5147 set filename [make_gdb_parallel_path cache $filename]
5149 if { [file exists $filename] } {
5153 set dir [file dirname $filename]
5156 set tmp_filename $filename.[pid]
5157 set fd [open $tmp_filename w]
5161 if { $executable } {
5162 exec chmod +x $tmp_filename
5164 tentative_rename $tmp_filename $filename
5169 # Set 'testfile', 'srcfile', and 'binfile'.
5171 # ARGS is a list of source file specifications.
5172 # Without any arguments, the .exp file's base name is used to
5173 # compute the source file name. The ".c" extension is added in this case.
5174 # If ARGS is not empty, each entry is a source file specification.
5175 # If the specification starts with a ".", it is treated as a suffix
5176 # to append to the .exp file's base name.
5177 # If the specification is the empty string, it is treated as if it
5179 # Otherwise it is a file name.
5180 # The first file in the list is used to set the 'srcfile' global.
5181 # Each subsequent name is used to set 'srcfile2', 'srcfile3', etc.
5183 # Most tests should call this without arguments.
5185 # If a completely different binary file name is needed, then it
5186 # should be handled in the .exp file with a suitable comment.
5188 proc standard_testfile {args} {
5189 global gdb_test_file_name
5191 global gdb_test_file_last_vars
5194 global testfile binfile
5196 set testfile $gdb_test_file_name
5197 set binfile [standard_output_file ${testfile}]
5199 if {[llength $args] == 0} {
5203 # Unset our previous output variables.
5204 # This can help catch hidden bugs.
5205 if {[info exists gdb_test_file_last_vars]} {
5206 foreach varname $gdb_test_file_last_vars {
5208 catch {unset $varname}
5211 # 'executable' is often set by tests.
5212 set gdb_test_file_last_vars {executable}
5216 set varname srcfile$suffix
5219 # Handle an extension.
5222 } elseif {[string range $arg 0 0] == "."} {
5223 set arg $testfile$arg
5227 lappend gdb_test_file_last_vars $varname
5229 if {$suffix == ""} {
5237 # The default timeout used when testing GDB commands. We want to use
5238 # the same timeout as the default dejagnu timeout, unless the user has
5239 # already provided a specific value (probably through a site.exp file).
5240 global gdb_test_timeout
5241 if ![info exists gdb_test_timeout] {
5242 set gdb_test_timeout $timeout
5245 # A list of global variables that GDB testcases should not use.
5246 # We try to prevent their use by monitoring write accesses and raising
5247 # an error when that happens.
5248 set banned_variables { bug_id prms_id }
5250 # A list of procedures that GDB testcases should not use.
5251 # We try to prevent their use by monitoring invocations and raising
5252 # an error when that happens.
5253 set banned_procedures { strace }
5255 # gdb_init is called by runtest at start, but also by several
5256 # tests directly; gdb_finish is only called from within runtest after
5257 # each test source execution.
5258 # Placing several traces by repetitive calls to gdb_init leads
5259 # to problems, as only one trace is removed in gdb_finish.
5260 # To overcome this possible problem, we add a variable that records
5261 # if the banned variables and procedures are already traced.
5264 # Global array that holds the name of all global variables at the time
5265 # a test script is started. After the test script has completed any
5266 # global not in this list is deleted.
5267 array set gdb_known_globals {}
5269 # Setup the GDB_KNOWN_GLOBALS array with the names of all current
5271 proc gdb_setup_known_globals {} {
5272 global gdb_known_globals
5274 array set gdb_known_globals {}
5275 foreach varname [info globals] {
5276 set gdb_known_globals($varname) 1
5280 # Cleanup the global namespace. Any global not in the
5281 # GDB_KNOWN_GLOBALS array is unset, this ensures we don't "leak"
5282 # globals from one test script to another.
5283 proc gdb_cleanup_globals {} {
5284 global gdb_known_globals gdb_persistent_globals
5286 foreach varname [info globals] {
5287 if {![info exists gdb_known_globals($varname)]} {
5288 if { [info exists gdb_persistent_globals($varname)] } {
5291 uplevel #0 unset $varname
5296 # Create gdb_tcl_unknown, a copy tcl's ::unknown, provided it's present as a
5298 set temp [interp create]
5299 if { [interp eval $temp "info procs ::unknown"] != "" } {
5300 set old_args [interp eval $temp "info args ::unknown"]
5301 set old_body [interp eval $temp "info body ::unknown"]
5302 eval proc gdb_tcl_unknown {$old_args} {$old_body}
5307 # GDB implementation of ${tool}_init. Called right before executing the
5309 # Overridable function -- you can override this function in your
5311 proc gdb_init { args } {
5312 # A baseboard file overriding this proc and calling the default version
5313 # should behave the same as this proc. So, don't add code here, but to
5314 # the default version instead.
5315 return [default_gdb_init {*}$args]
5318 # GDB implementation of ${tool}_finish. Called right after executing the
5320 proc gdb_finish { } {
5321 global gdbserver_reconnect_p
5324 global known_globals
5326 if { [info procs ::gdb_tcl_unknown] != "" } {
5327 # Restore dejagnu's version of proc unknown.
5329 rename ::dejagnu_unknown ::unknown
5332 # Exit first, so that the files are no longer in use.
5335 if { [llength $cleanfiles] > 0 } {
5336 eval remote_file target delete $cleanfiles
5340 # Unblock write access to the banned variables. Dejagnu typically
5341 # resets some of them between testcases.
5342 global banned_variables
5343 global banned_procedures
5344 global banned_traced
5345 if ($banned_traced) {
5346 foreach banned_var $banned_variables {
5347 global "$banned_var"
5348 trace remove variable "$banned_var" write error
5350 foreach banned_proc $banned_procedures {
5351 global "$banned_proc"
5352 trace remove execution "$banned_proc" enter error
5357 global gdb_finish_hooks
5358 foreach gdb_finish_hook $gdb_finish_hooks {
5361 set gdb_finish_hooks [list]
5367 set debug_format "unknown"
5369 # Run the gdb command "info source" and extract the debugging format
5370 # information from the output and save it in debug_format.
5372 proc get_debug_format { } {
5377 set debug_format "unknown"
5378 send_gdb "info source\n"
5380 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
5381 set debug_format $expect_out(1,string)
5382 verbose "debug format is $debug_format"
5385 -re "No current source file.\r\n$gdb_prompt $" {
5386 perror "get_debug_format used when no current source file"
5389 -re "$gdb_prompt $" {
5390 warning "couldn't check debug format (no valid response)."
5394 warning "couldn't check debug format (timeout)."
5400 # Return true if FORMAT matches the debug format the current test was
5401 # compiled with. FORMAT is a shell-style globbing pattern; it can use
5402 # `*', `[...]', and so on.
5404 # This function depends on variables set by `get_debug_format', above.
5406 proc test_debug_format {format} {
5409 return [expr [string match $format $debug_format] != 0]
5412 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
5413 # COFF, stabs, etc). If that format matches the format that the
5414 # current test was compiled with, then the next test is expected to
5415 # fail for any target. Returns 1 if the next test or set of tests is
5416 # expected to fail, 0 otherwise (or if it is unknown). Must have
5417 # previously called get_debug_format.
5418 proc setup_xfail_format { format } {
5419 set ret [test_debug_format $format]
5427 # gdb_get_line_number TEXT [FILE]
5429 # Search the source file FILE, and return the line number of the
5430 # first line containing TEXT. If no match is found, an error is thrown.
5432 # TEXT is a string literal, not a regular expression.
5434 # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is
5435 # specified, and does not start with "/", then it is assumed to be in
5436 # "$srcdir/$subdir". This is awkward, and can be fixed in the future,
5437 # by changing the callers and the interface at the same time.
5438 # In particular: gdb.base/break.exp, gdb.base/condbreak.exp,
5439 # gdb.base/ena-dis-br.exp.
5441 # Use this function to keep your test scripts independent of the
5442 # exact line numbering of the source file. Don't write:
5444 # send_gdb "break 20"
5446 # This means that if anyone ever edits your test's source file,
5447 # your test could break. Instead, put a comment like this on the
5448 # source file line you want to break at:
5450 # /* breakpoint spot: frotz.exp: test name */
5452 # and then write, in your test script (which we assume is named
5455 # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
5457 # (Yes, Tcl knows how to handle the nested quotes and brackets.
5460 # % puts "foo [lindex "bar baz" 1]"
5463 # Tcl is quite clever, for a little stringy language.)
5467 # The previous implementation of this procedure used the gdb search command.
5468 # This version is different:
5470 # . It works with MI, and it also works when gdb is not running.
5472 # . It operates on the build machine, not the host machine.
5474 # . For now, this implementation fakes a current directory of
5475 # $srcdir/$subdir to be compatible with the old implementation.
5476 # This will go away eventually and some callers will need to
5479 # . The TEXT argument is literal text and matches literally,
5480 # not a regular expression as it was before.
5482 # . State changes in gdb, such as changing the current file
5483 # and setting $_, no longer happen.
5485 # After a bit of time we can forget about the differences from the
5486 # old implementation.
5488 # --chastain 2004-08-05
5490 proc gdb_get_line_number { text { file "" } } {
5495 if { "$file" == "" } then {
5498 if { ! [regexp "^/" "$file"] } then {
5499 set file "$srcdir/$subdir/$file"
5502 if { [ catch { set fd [open "$file"] } message ] } then {
5507 for { set line 1 } { 1 } { incr line } {
5508 if { [ catch { set nchar [gets "$fd" body] } message ] } then {
5511 if { $nchar < 0 } then {
5514 if { [string first "$text" "$body"] >= 0 } then {
5520 if { [ catch { close "$fd" } message ] } then {
5525 error "undefined tag \"$text\""
5531 # Continue the program until it ends.
5533 # MSSG is the error message that gets printed. If not given, a
5535 # COMMAND is the command to invoke. If not given, "continue" is
5537 # ALLOW_EXTRA is a flag indicating whether the test should expect
5538 # extra output between the "Continuing." line and the program
5539 # exiting. By default it is zero; if nonzero, any extra output
5542 proc gdb_continue_to_end {{mssg ""} {command continue} {allow_extra 0}} {
5543 global inferior_exited_re use_gdb_stub
5546 set text "continue until exit"
5548 set text "continue until exit at $mssg"
5556 # By default, we don't rely on exit() behavior of remote stubs --
5557 # it's common for exit() to be implemented as a simple infinite
5558 # loop, or a forced crash/reset. For native targets, by default, we
5559 # assume process exit is reported as such. If a non-reliable target
5560 # is used, we set a breakpoint at exit, and continue to that.
5561 if { [target_info exists exit_is_reliable] } {
5562 set exit_is_reliable [target_info exit_is_reliable]
5564 set exit_is_reliable [expr ! $use_gdb_stub]
5567 if { ! $exit_is_reliable } {
5568 if {![gdb_breakpoint "exit"]} {
5571 gdb_test $command "Continuing..*Breakpoint .*exit.*" \
5574 # Continue until we exit. Should not stop again.
5575 # Don't bother to check the output of the program, that may be
5576 # extremely tough for some remote systems.
5578 "Continuing.\[\r\n0-9\]+${extra}(... EXIT code 0\[\r\n\]+|$inferior_exited_re normally).*"\
5583 proc rerun_to_main {} {
5584 global gdb_prompt use_gdb_stub
5589 -re ".*Breakpoint .*main .*$gdb_prompt $"\
5590 {pass "rerun to main" ; return 0}
5591 -re "$gdb_prompt $"\
5592 {fail "rerun to main" ; return 0}
5593 timeout {fail "(timeout) rerun to main" ; return 0}
5598 -re "The program .* has been started already.*y or n. $" {
5599 send_gdb "y\n" answer
5602 -re "Starting program.*$gdb_prompt $"\
5603 {pass "rerun to main" ; return 0}
5604 -re "$gdb_prompt $"\
5605 {fail "rerun to main" ; return 0}
5606 timeout {fail "(timeout) rerun to main" ; return 0}
5611 # Return true if EXECUTABLE contains a .gdb_index or .debug_names index section.
5613 proc exec_has_index_section { executable } {
5614 set readelf_program [gdb_find_readelf]
5615 set res [catch {exec $readelf_program -S $executable \
5616 | grep -E "\.gdb_index|\.debug_names" }]
5623 # Return list with major and minor version of readelf, or an empty list.
5624 gdb_caching_proc readelf_version {
5625 set readelf_program [gdb_find_readelf]
5626 set res [catch {exec $readelf_program --version} output]
5630 set lines [split $output \n]
5631 set line [lindex $lines 0]
5632 set res [regexp {[ \t]+([0-9]+)[.]([0-9]+)[^ \t]*$} \
5633 $line dummy major minor]
5637 return [list $major $minor]
5640 # Return 1 if readelf prints the PIE flag, 0 if is doesn't, and -1 if unknown.
5641 proc readelf_prints_pie { } {
5642 set version [readelf_version]
5643 if { [llength $version] == 0 } {
5646 set major [lindex $version 0]
5647 set minor [lindex $version 1]
5648 # It would be better to construct a PIE executable and test if the PIE
5649 # flag is printed by readelf, but we cannot reliably construct a PIE
5650 # executable if the multilib_flags dictate otherwise
5651 # (--target_board=unix/-no-pie/-fno-PIE).
5652 return [version_at_least $major $minor 2 26]
5655 # Return 1 if EXECUTABLE is a Position Independent Executable, 0 if it is not,
5656 # and -1 if unknown.
5658 proc exec_is_pie { executable } {
5659 set res [readelf_prints_pie]
5663 set readelf_program [gdb_find_readelf]
5664 # We're not testing readelf -d | grep "FLAGS_1.*Flags:.*PIE"
5665 # because the PIE flag is not set by all versions of gold, see PR
5667 set res [catch {exec $readelf_program -h $executable} output]
5671 set res [regexp -line {^[ \t]*Type:[ \t]*DYN \(Shared object file\)$} \
5679 # Return true if a test should be skipped due to lack of floating
5680 # point support or GDB can't fetch the contents from floating point
5683 gdb_caching_proc gdb_skip_float_test {
5684 if [target_info exists gdb,skip_float_tests] {
5688 # There is an ARM kernel ptrace bug that hardware VFP registers
5689 # are not updated after GDB ptrace set VFP registers. The bug
5690 # was introduced by kernel commit 8130b9d7b9d858aa04ce67805e8951e3cb6e9b2f
5691 # in 2012 and is fixed in e2dfb4b880146bfd4b6aa8e138c0205407cebbaf
5692 # in May 2016. In other words, kernels older than 4.6.3, 4.4.14,
5693 # 4.1.27, 3.18.36, and 3.14.73 have this bug.
5694 # This kernel bug is detected by check how does GDB change the
5695 # program result by changing one VFP register.
5696 if { [istarget "arm*-*-linux*"] } {
5698 set compile_flags {debug nowarnings }
5700 # Set up, compile, and execute a test program having VFP
5702 set src [standard_temp_file arm_vfp[pid].c]
5703 set exe [standard_temp_file arm_vfp[pid].x]
5705 gdb_produce_source $src {
5710 asm ("vldr d0, [%0]" : : "r" (&d));
5711 asm ("vldr d1, [%0]" : : "r" (&d));
5712 asm (".global break_here\n"
5714 asm ("vcmp.f64 d0, d1\n"
5715 "vmrs APSR_nzcv, fpscr\n"
5716 "bne L_value_different\n"
5719 "L_value_different:\n"
5721 "L_end:\n" : "=r" (ret) :);
5723 /* Return $d0 != $d1. */
5728 verbose "compiling testfile $src" 2
5729 set lines [gdb_compile $src $exe executable $compile_flags]
5732 if ![string match "" $lines] then {
5733 verbose "testfile compilation failed, returning 1" 2
5737 # No error message, compilation succeeded so now run it via gdb.
5738 # Run the test up to 5 times to detect whether ptrace can
5739 # correctly update VFP registers or not.
5741 for {set i 0} {$i < 5} {incr i} {
5742 global gdb_prompt srcdir subdir
5746 gdb_reinitialize_dir $srcdir/$subdir
5750 gdb_test "break *break_here"
5751 gdb_continue_to_breakpoint "break_here"
5753 # Modify $d0 to a different value, so the exit code should
5755 gdb_test "set \$d0 = 5.0"
5757 set test "continue to exit"
5758 gdb_test_multiple "continue" "$test" {
5759 -re "exited with code 01.*$gdb_prompt $" {
5761 -re "exited normally.*$gdb_prompt $" {
5762 # However, the exit code is 0. That means something
5763 # wrong in setting VFP registers.
5771 remote_file build delete $exe
5773 return $skip_vfp_test
5778 # Print a message and return true if a test should be skipped
5779 # due to lack of stdio support.
5781 proc gdb_skip_stdio_test { msg } {
5782 if [target_info exists gdb,noinferiorio] {
5783 verbose "Skipping test '$msg': no inferior i/o."
5789 proc gdb_skip_bogus_test { msg } {
5793 # Return true if a test should be skipped due to lack of XML support
5795 # NOTE: This must be called while gdb is *not* running.
5797 gdb_caching_proc gdb_skip_xml_test {
5802 if { [info exists gdb_spawn_id] } {
5803 error "GDB must not be running in gdb_skip_xml_tests."
5806 set xml_file [gdb_remote_download host "${srcdir}/gdb.xml/trivial.xml"]
5810 gdb_test_multiple "set tdesc filename $xml_file" "" {
5811 -re ".*XML support was disabled at compile time.*$gdb_prompt $" {
5814 -re ".*$gdb_prompt $" { }
5820 # Return true if argv[0] is available.
5822 gdb_caching_proc gdb_has_argv0 {
5825 # Compile and execute a test program to check whether argv[0] is available.
5826 gdb_simple_compile has_argv0 {
5827 int main (int argc, char **argv) {
5834 proc gdb_has_argv0_1 { exe } {
5835 global srcdir subdir
5836 global gdb_prompt hex
5840 gdb_reinitialize_dir $srcdir/$subdir
5843 # Set breakpoint on main.
5844 gdb_test_multiple "break main" "break main" {
5845 -re "Breakpoint.*${gdb_prompt} $" {
5847 -re "${gdb_prompt} $" {
5854 gdb_test_multiple "" "run to main" {
5855 -re "Breakpoint.*${gdb_prompt} $" {
5857 -re "${gdb_prompt} $" {
5862 set old_elements "200"
5863 set test "show print elements"
5864 gdb_test_multiple $test $test {
5865 -re "Limit on string chars or array elements to print is (\[^\r\n\]+)\\.\r\n$gdb_prompt $" {
5866 set old_elements $expect_out(1,string)
5869 set old_repeats "200"
5870 set test "show print repeats"
5871 gdb_test_multiple $test $test {
5872 -re "Threshold for repeated print elements is (\[^\r\n\]+)\\.\r\n$gdb_prompt $" {
5873 set old_repeats $expect_out(1,string)
5876 gdb_test_no_output "set print elements unlimited" ""
5877 gdb_test_no_output "set print repeats unlimited" ""
5880 # Check whether argc is 1.
5881 gdb_test_multiple "p argc" "p argc" {
5882 -re " = 1\r\n${gdb_prompt} $" {
5884 gdb_test_multiple "p argv\[0\]" "p argv\[0\]" {
5885 -re " = $hex \".*[file tail $exe]\"\r\n${gdb_prompt} $" {
5888 -re "${gdb_prompt} $" {
5892 -re "${gdb_prompt} $" {
5896 gdb_test_no_output "set print elements $old_elements" ""
5897 gdb_test_no_output "set print repeats $old_repeats" ""
5902 set result [gdb_has_argv0_1 $obj]
5908 && ([istarget *-*-linux*]
5909 || [istarget *-*-freebsd*] || [istarget *-*-kfreebsd*]
5910 || [istarget *-*-netbsd*] || [istarget *-*-knetbsd*]
5911 || [istarget *-*-openbsd*]
5912 || [istarget *-*-darwin*]
5913 || [istarget *-*-solaris*]
5914 || [istarget *-*-aix*]
5915 || [istarget *-*-gnu*]
5916 || [istarget *-*-cygwin*] || [istarget *-*-mingw32*]
5917 || [istarget *-*-*djgpp*] || [istarget *-*-go32*]
5918 || [istarget *-wince-pe] || [istarget *-*-mingw32ce*]
5919 || [istarget *-*-symbianelf*]
5920 || [istarget *-*-osf*]
5921 || [istarget *-*-dicos*]
5922 || [istarget *-*-nto*]
5923 || [istarget *-*-*vms*]
5924 || [istarget *-*-lynx*178]) } {
5925 fail "argv\[0\] should be available on this target"
5931 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
5932 # ${binfile}.dbglnk, which is just like the executable ($binfile) but without
5933 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
5934 # the name of a debuginfo only file. This file will be stored in the same
5937 # Functions for separate debug info testing
5939 # starting with an executable:
5940 # foo --> original executable
5942 # at the end of the process we have:
5943 # foo.stripped --> foo w/o debug info
5944 # foo.debug --> foo's debug info
5945 # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug.
5947 # Fetch the build id from the file.
5948 # Returns "" if there is none.
5950 proc get_build_id { filename } {
5951 if { ([istarget "*-*-mingw*"]
5952 || [istarget *-*-cygwin*]) } {
5953 set objdump_program [gdb_find_objdump]
5954 set result [catch {set data [exec $objdump_program -p $filename | grep signature | cut "-d " -f4]} output]
5955 verbose "result is $result"
5956 verbose "output is $output"
5962 set tmp [standard_output_file "${filename}-tmp"]
5963 set objcopy_program [gdb_find_objcopy]
5964 set result [catch "exec $objcopy_program -j .note.gnu.build-id -O binary $filename $tmp" output]
5965 verbose "result is $result"
5966 verbose "output is $output"
5971 fconfigure $fi -translation binary
5972 # Skip the NOTE header.
5977 if ![string compare $data ""] then {
5980 # Convert it to hex.
5981 binary scan $data H* data
5986 # Return the build-id hex string (usually 160 bits as 40 hex characters)
5987 # converted to the form: .build-id/ab/cdef1234...89.debug
5988 # Return "" if no build-id found.
5989 proc build_id_debug_filename_get { filename } {
5990 set data [get_build_id $filename]
5991 if { $data == "" } {
5994 regsub {^..} $data {\0/} data
5995 return ".build-id/${data}.debug"
5998 # Create stripped files for DEST, replacing it. If ARGS is passed, it is a
5999 # list of optional flags. The only currently supported flag is no-main,
6000 # which removes the symbol entry for main from the separate debug file.
6002 # Function returns zero on success. Function will return non-zero failure code
6003 # on some targets not supporting separate debug info (such as i386-msdos).
6005 proc gdb_gnu_strip_debug { dest args } {
6007 # Use the first separate debug info file location searched by GDB so the
6008 # run cannot be broken by some stale file searched with higher precedence.
6009 set debug_file "${dest}.debug"
6011 set strip_to_file_program [transform strip]
6012 set objcopy_program [gdb_find_objcopy]
6014 set debug_link [file tail $debug_file]
6015 set stripped_file "${dest}.stripped"
6017 # Get rid of the debug info, and store result in stripped_file
6018 # something like gdb/testsuite/gdb.base/blah.stripped.
6019 set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
6020 verbose "result is $result"
6021 verbose "output is $output"
6026 # Workaround PR binutils/10802:
6027 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
6028 set perm [file attributes ${dest} -permissions]
6029 file attributes ${stripped_file} -permissions $perm
6031 # Get rid of everything but the debug info, and store result in debug_file
6032 # This will be in the .debug subdirectory, see above.
6033 set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
6034 verbose "result is $result"
6035 verbose "output is $output"
6040 # If no-main is passed, strip the symbol for main from the separate
6041 # file. This is to simulate the behavior of elfutils's eu-strip, which
6042 # leaves the symtab in the original file only. There's no way to get
6043 # objcopy or strip to remove the symbol table without also removing the
6044 # debugging sections, so this is as close as we can get.
6045 if { [llength $args] == 1 && [lindex $args 0] == "no-main" } {
6046 set result [catch "exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp" output]
6047 verbose "result is $result"
6048 verbose "output is $output"
6052 file delete "${debug_file}"
6053 file rename "${debug_file}-tmp" "${debug_file}"
6056 # Link the two previous output files together, adding the .gnu_debuglink
6057 # section to the stripped_file, containing a pointer to the debug_file,
6058 # save the new file in dest.
6059 # This will be the regular executable filename, in the usual location.
6060 set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
6061 verbose "result is $result"
6062 verbose "output is $output"
6067 # Workaround PR binutils/10802:
6068 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
6069 set perm [file attributes ${stripped_file} -permissions]
6070 file attributes ${dest} -permissions $perm
6075 # Test the output of GDB_COMMAND matches the pattern obtained
6076 # by concatenating all elements of EXPECTED_LINES. This makes
6077 # it possible to split otherwise very long string into pieces.
6078 # If third argument TESTNAME is not empty, it's used as the name of the
6079 # test to be printed on pass/fail.
6080 proc help_test_raw { gdb_command expected_lines {testname {}} } {
6081 set expected_output [join $expected_lines ""]
6082 if {$testname != {}} {
6083 gdb_test "${gdb_command}" "${expected_output}" $testname
6087 gdb_test "${gdb_command}" "${expected_output}"
6090 # A regexp that matches the end of help CLASS|PREFIX_COMMAND
6091 set help_list_trailer {
6092 "Type \"apropos word\" to search for commands related to \"word\"\.[\r\n]+"
6093 "Type \"apropos -v word\" for full documentation of commands related to \"word\"\.[\r\n]+"
6094 "Command name abbreviations are allowed if unambiguous\."
6097 # Test the output of "help COMMAND_CLASS". EXPECTED_INITIAL_LINES
6098 # are regular expressions that should match the beginning of output,
6099 # before the list of commands in that class.
6100 # LIST_OF_COMMANDS are regular expressions that should match the
6101 # list of commands in that class. If empty, the command list will be
6102 # matched automatically. The presence of standard epilogue will be tested
6104 # If last argument TESTNAME is not empty, it's used as the name of the
6105 # test to be printed on pass/fail.
6106 # Notice that the '[' and ']' characters don't need to be escaped for strings
6107 # wrapped in {} braces.
6108 proc test_class_help { command_class expected_initial_lines {list_of_commands {}} {testname {}} } {
6109 global help_list_trailer
6110 if {[llength $list_of_commands]>0} {
6111 set l_list_of_commands {"List of commands:[\r\n]+[\r\n]+"}
6112 set l_list_of_commands [concat $l_list_of_commands $list_of_commands]
6113 set l_list_of_commands [concat $l_list_of_commands {"[\r\n]+[\r\n]+"}]
6115 set l_list_of_commands {"List of commands\:.*[\r\n]+"}
6118 "Type \"help\" followed by command name for full documentation\.[\r\n]+"
6120 set l_entire_body [concat $expected_initial_lines $l_list_of_commands \
6121 $l_stock_body $help_list_trailer]
6123 help_test_raw "help ${command_class}" $l_entire_body $testname
6126 # Like test_class_help but specialised to test "help user-defined".
6127 proc test_user_defined_class_help { {list_of_commands {}} {testname {}} } {
6128 test_class_help "user-defined" {
6129 "User-defined commands\.[\r\n]+"
6130 "The commands in this class are those defined by the user\.[\r\n]+"
6131 "Use the \"define\" command to define a command\.[\r\n]+"
6132 } $list_of_commands $testname
6136 # COMMAND_LIST should have either one element -- command to test, or
6137 # two elements -- abbreviated command to test, and full command the first
6138 # element is abbreviation of.
6139 # The command must be a prefix command. EXPECTED_INITIAL_LINES
6140 # are regular expressions that should match the beginning of output,
6141 # before the list of subcommands. The presence of
6142 # subcommand list and standard epilogue will be tested automatically.
6143 proc test_prefix_command_help { command_list expected_initial_lines args } {
6144 global help_list_trailer
6145 set command [lindex $command_list 0]
6146 if {[llength $command_list]>1} {
6147 set full_command [lindex $command_list 1]
6149 set full_command $command
6151 # Use 'list' and not just {} because we want variables to
6152 # be expanded in this list.
6153 set l_stock_body [list\
6154 "List of $full_command subcommands\:.*\[\r\n\]+"\
6155 "Type \"help $full_command\" followed by $full_command subcommand name for full documentation\.\[\r\n\]+"]
6156 set l_entire_body [concat $expected_initial_lines $l_stock_body $help_list_trailer]
6157 if {[llength $args]>0} {
6158 help_test_raw "help ${command}" $l_entire_body [lindex $args 0]
6160 help_test_raw "help ${command}" $l_entire_body
6164 # Build executable named EXECUTABLE from specifications that allow
6165 # different options to be passed to different sub-compilations.
6166 # TESTNAME is the name of the test; this is passed to 'untested' if
6168 # OPTIONS is passed to the final link, using gdb_compile. If OPTIONS
6169 # contains the option "pthreads", then gdb_compile_pthreads is used.
6170 # ARGS is a flat list of source specifications, of the form:
6171 # { SOURCE1 OPTIONS1 [ SOURCE2 OPTIONS2 ]... }
6172 # Each SOURCE is compiled to an object file using its OPTIONS,
6173 # using gdb_compile.
6174 # Returns 0 on success, -1 on failure.
6175 proc build_executable_from_specs {testname executable options args} {
6179 set binfile [standard_output_file $executable]
6182 if { [lsearch -exact $options "c++"] >= 0 } {
6183 set info_options "c++"
6185 if [get_compiler_info ${info_options}] {
6189 set func gdb_compile
6190 set func_index [lsearch -regexp $options {^(pthreads|shlib|shlib_pthreads|openmp)$}]
6191 if {$func_index != -1} {
6192 set func "${func}_[lindex $options $func_index]"
6195 # gdb_compile_shlib and gdb_compile_shlib_pthreads do not use the 3rd
6196 # parameter. They also requires $sources while gdb_compile and
6197 # gdb_compile_pthreads require $objects. Moreover they ignore any options.
6198 if [string match gdb_compile_shlib* $func] {
6200 foreach {s local_options} $args {
6201 if { [regexp "^/" "$s"] } then {
6202 lappend sources_path "$s"
6204 lappend sources_path "$srcdir/$subdir/$s"
6207 set ret [$func $sources_path "${binfile}" $options]
6208 } elseif {[lsearch -exact $options rust] != -1} {
6210 foreach {s local_options} $args {
6211 if { [regexp "^/" "$s"] } then {
6212 lappend sources_path "$s"
6214 lappend sources_path "$srcdir/$subdir/$s"
6217 set ret [gdb_compile_rust $sources_path "${binfile}" $options]
6221 foreach {s local_options} $args {
6222 if { ! [regexp "^/" "$s"] } then {
6223 set s "$srcdir/$subdir/$s"
6225 if { [$func "${s}" "${binfile}${i}.o" object $local_options] != "" } {
6229 lappend objects "${binfile}${i}.o"
6232 set ret [$func $objects "${binfile}" executable $options]
6242 # Build executable named EXECUTABLE, from SOURCES. If SOURCES are not
6243 # provided, uses $EXECUTABLE.c. The TESTNAME paramer is the name of test
6244 # to pass to untested, if something is wrong. OPTIONS are passed
6245 # to gdb_compile directly.
6246 proc build_executable { testname executable {sources ""} {options {debug}} } {
6247 if {[llength $sources]==0} {
6248 set sources ${executable}.c
6251 set arglist [list $testname $executable $options]
6252 foreach source $sources {
6253 lappend arglist $source $options
6256 return [eval build_executable_from_specs $arglist]
6259 # Starts fresh GDB binary and loads an optional executable into GDB.
6260 # Usage: clean_restart [executable]
6261 # EXECUTABLE is the basename of the binary.
6262 # Return -1 if starting gdb or loading the executable failed.
6264 proc clean_restart { args } {
6270 if { [llength $args] > 1 } {
6271 error "bad number of args: [llength $args]"
6276 # This is a clean restart, so reset error and warning count.
6281 # if { [gdb_start] == -1 } {
6284 # but gdb_start is a ${tool}_start proc, which doesn't have a defined
6285 # return value. So instead, we test for errcnt.
6287 if { $errcnt > 0 } {
6291 gdb_reinitialize_dir $srcdir/$subdir
6293 if { [llength $args] >= 1 } {
6294 set executable [lindex $args 0]
6295 set binfile [standard_output_file ${executable}]
6296 return [gdb_load ${binfile}]
6302 # Prepares for testing by calling build_executable_full, then
6304 # TESTNAME is the name of the test.
6305 # Each element in ARGS is a list of the form
6306 # { EXECUTABLE OPTIONS SOURCE_SPEC... }
6307 # These are passed to build_executable_from_specs, which see.
6308 # The last EXECUTABLE is passed to clean_restart.
6309 # Returns 0 on success, non-zero on failure.
6310 proc prepare_for_testing_full {testname args} {
6311 foreach spec $args {
6312 if {[eval build_executable_from_specs [list $testname] $spec] == -1} {
6315 set executable [lindex $spec 0]
6317 clean_restart $executable
6321 # Prepares for testing, by calling build_executable, and then clean_restart.
6322 # Please refer to build_executable for parameter description.
6323 proc prepare_for_testing { testname executable {sources ""} {options {debug}}} {
6325 if {[build_executable $testname $executable $sources $options] == -1} {
6328 clean_restart $executable
6333 # Retrieve the value of EXP in the inferior, represented in format
6334 # specified in FMT (using "printFMT"). DEFAULT is used as fallback if
6335 # print fails. TEST is the test message to use. It can be omitted,
6336 # in which case a test message is built from EXP.
6338 proc get_valueof { fmt exp default {test ""} } {
6342 set test "get valueof \"${exp}\""
6346 gdb_test_multiple "print${fmt} ${exp}" "$test" {
6347 -re "\\$\[0-9\]* = (\[^\r\n\]*)\[\r\n\]*$gdb_prompt $" {
6348 set val $expect_out(1,string)
6352 fail "$test (timeout)"
6358 # Retrieve the value of local var EXP in the inferior. DEFAULT is used as
6359 # fallback if print fails. TEST is the test message to use. It can be
6360 # omitted, in which case a test message is built from EXP.
6362 proc get_local_valueof { exp default {test ""} } {
6366 set test "get local valueof \"${exp}\""
6370 gdb_test_multiple "info locals ${exp}" "$test" {
6371 -re "$exp = (\[^\r\n\]*)\[\r\n\]*$gdb_prompt $" {
6372 set val $expect_out(1,string)
6376 fail "$test (timeout)"
6382 # Retrieve the value of EXP in the inferior, as a signed decimal value
6383 # (using "print /d"). DEFAULT is used as fallback if print fails.
6384 # TEST is the test message to use. It can be omitted, in which case
6385 # a test message is built from EXP.
6387 proc get_integer_valueof { exp default {test ""} } {
6391 set test "get integer valueof \"${exp}\""
6395 gdb_test_multiple "print /d ${exp}" "$test" {
6396 -re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" {
6397 set val $expect_out(1,string)
6401 fail "$test (timeout)"
6407 # Retrieve the value of EXP in the inferior, as an hexadecimal value
6408 # (using "print /x"). DEFAULT is used as fallback if print fails.
6409 # TEST is the test message to use. It can be omitted, in which case
6410 # a test message is built from EXP.
6412 proc get_hexadecimal_valueof { exp default {test ""} } {
6416 set test "get hexadecimal valueof \"${exp}\""
6420 gdb_test_multiple "print /x ${exp}" $test {
6421 -re "\\$\[0-9\]* = (0x\[0-9a-zA-Z\]+).*$gdb_prompt $" {
6422 set val $expect_out(1,string)
6429 # Retrieve the size of TYPE in the inferior, as a decimal value. DEFAULT
6430 # is used as fallback if print fails. TEST is the test message to use.
6431 # It can be omitted, in which case a test message is 'sizeof (TYPE)'.
6433 proc get_sizeof { type default {test ""} } {
6434 return [get_integer_valueof "sizeof (${type})" $default $test]
6437 proc get_target_charset { } {
6440 gdb_test_multiple "show target-charset" "" {
6441 -re "The target character set is \"auto; currently (\[^\"\]*)\".*$gdb_prompt $" {
6442 return $expect_out(1,string)
6444 -re "The target character set is \"(\[^\"\]*)\".*$gdb_prompt $" {
6445 return $expect_out(1,string)
6449 # Pick a reasonable default.
6450 warning "Unable to read target-charset."
6454 # Get the address of VAR.
6456 proc get_var_address { var } {
6457 global gdb_prompt hex
6459 # Match output like:
6461 # $5 = (int (*)()) 0
6462 # $6 = (int (*)()) 0x24 <function_bar>
6464 gdb_test_multiple "print &${var}" "get address of ${var}" {
6465 -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $"
6467 pass "get address of ${var}"
6468 if { $expect_out(1,string) == "0" } {
6471 return $expect_out(1,string)
6478 # Return the frame number for the currently selected frame
6479 proc get_current_frame_number {{test_name ""}} {
6482 if { $test_name == "" } {
6483 set test_name "get current frame number"
6486 gdb_test_multiple "frame" $test_name {
6487 -re "#(\[0-9\]+) .*$gdb_prompt $" {
6488 set frame_num $expect_out(1,string)
6494 # Get the current value for remotetimeout and return it.
6495 proc get_remotetimeout { } {
6499 gdb_test_multiple "show remotetimeout" "" {
6500 -re "Timeout limit to wait for target to respond is ($decimal).*$gdb_prompt $" {
6501 return $expect_out(1,string)
6505 # Pick the default that gdb uses
6506 warning "Unable to read remotetimeout"
6510 # Set the remotetimeout to the specified timeout. Nothing is returned.
6511 proc set_remotetimeout { timeout } {
6514 gdb_test_multiple "set remotetimeout $timeout" "" {
6515 -re "$gdb_prompt $" {
6516 verbose "Set remotetimeout to $timeout\n"
6521 # Get the target's current endianness and return it.
6522 proc get_endianness { } {
6525 gdb_test_multiple "show endian" "determine endianness" {
6526 -re ".* (little|big) endian.*\r\n$gdb_prompt $" {
6528 return $expect_out(1,string)
6534 # ROOT and FULL are file names. Returns the relative path from ROOT
6535 # to FULL. Note that FULL must be in a subdirectory of ROOT.
6536 # For example, given ROOT = /usr/bin and FULL = /usr/bin/ls, this
6539 proc relative_filename {root full} {
6540 set root_split [file split $root]
6541 set full_split [file split $full]
6543 set len [llength $root_split]
6545 if {[eval file join $root_split]
6546 != [eval file join [lrange $full_split 0 [expr {$len - 1}]]]} {
6547 error "$full not a subdir of $root"
6550 return [eval file join [lrange $full_split $len end]]
6553 # If GDB_PARALLEL exists, then set up the parallel-mode directories.
6554 if {[info exists GDB_PARALLEL]} {
6555 if {[is_remote host]} {
6559 [make_gdb_parallel_path outputs] \
6560 [make_gdb_parallel_path temp] \
6561 [make_gdb_parallel_path cache]
6565 proc core_find {binfile {deletefiles {}} {arg ""}} {
6566 global objdir subdir
6568 set destcore "$binfile.core"
6569 file delete $destcore
6571 # Create a core file named "$destcore" rather than just "core", to
6572 # avoid problems with sys admin types that like to regularly prune all
6573 # files named "core" from the system.
6575 # Arbitrarily try setting the core size limit to "unlimited" since
6576 # this does not hurt on systems where the command does not work and
6577 # allows us to generate a core on systems where it does.
6579 # Some systems append "core" to the name of the program; others append
6580 # the name of the program to "core"; still others (like Linux, as of
6581 # May 2003) create cores named "core.PID". In the latter case, we
6582 # could have many core files lying around, and it may be difficult to
6583 # tell which one is ours, so let's run the program in a subdirectory.
6585 set coredir [standard_output_file coredir.[getpid]]
6587 catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile} ${arg}; true) >/dev/null 2>&1\""
6588 # remote_exec host "${binfile}"
6589 foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
6590 if [remote_file build exists $i] {
6591 remote_exec build "mv $i $destcore"
6595 # Check for "core.PID".
6596 if { $found == 0 } {
6597 set names [glob -nocomplain -directory $coredir core.*]
6598 if {[llength $names] == 1} {
6599 set corefile [file join $coredir [lindex $names 0]]
6600 remote_exec build "mv $corefile $destcore"
6604 if { $found == 0 } {
6605 # The braindamaged HPUX shell quits after the ulimit -c above
6606 # without executing ${binfile}. So we try again without the
6607 # ulimit here if we didn't find a core file above.
6608 # Oh, I should mention that any "braindamaged" non-Unix system has
6609 # the same problem. I like the cd bit too, it's really neat'n stuff.
6610 catch "system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\""
6611 foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" {
6612 if [remote_file build exists $i] {
6613 remote_exec build "mv $i $destcore"
6619 # Try to clean up after ourselves.
6620 foreach deletefile $deletefiles {
6621 remote_file build delete [file join $coredir $deletefile]
6623 remote_exec build "rmdir $coredir"
6625 if { $found == 0 } {
6626 warning "can't generate a core file - core tests suppressed - check ulimit -c"
6632 # gdb_target_symbol_prefix compiles a test program and then examines
6633 # the output from objdump to determine the prefix (such as underscore)
6634 # for linker symbol prefixes.
6636 gdb_caching_proc gdb_target_symbol_prefix {
6637 # Compile a simple test program...
6638 set src { int main() { return 0; } }
6639 if {![gdb_simple_compile target_symbol_prefix $src executable]} {
6645 set objdump_program [gdb_find_objdump]
6646 set result [catch "exec $objdump_program --syms $obj" output]
6649 && ![regexp -lineanchor \
6650 { ([^ a-zA-Z0-9]*)main$} $output dummy prefix] } {
6651 verbose "gdb_target_symbol_prefix: Could not find main in objdump output; returning null prefix" 2
6659 # Return 1 if target supports scheduler locking, otherwise return 0.
6661 gdb_caching_proc target_supports_scheduler_locking {
6664 set me "gdb_target_supports_scheduler_locking"
6666 set src { int main() { return 0; } }
6667 if {![gdb_simple_compile $me $src executable]} {
6676 set supports_schedule_locking -1
6677 set current_schedule_locking_mode ""
6679 set test "reading current scheduler-locking mode"
6680 gdb_test_multiple "show scheduler-locking" $test {
6681 -re "Mode for locking scheduler during execution is \"(\[\^\"\]*)\".*$gdb_prompt" {
6682 set current_schedule_locking_mode $expect_out(1,string)
6684 -re "$gdb_prompt $" {
6685 set supports_schedule_locking 0
6688 set supports_schedule_locking 0
6692 if { $supports_schedule_locking == -1 } {
6693 set test "checking for scheduler-locking support"
6694 gdb_test_multiple "set scheduler-locking $current_schedule_locking_mode" $test {
6695 -re "Target '\[^'\]+' cannot support this command\..*$gdb_prompt $" {
6696 set supports_schedule_locking 0
6698 -re "$gdb_prompt $" {
6699 set supports_schedule_locking 1
6702 set supports_schedule_locking 0
6707 if { $supports_schedule_locking == -1 } {
6708 set supports_schedule_locking 0
6712 remote_file build delete $obj
6713 verbose "$me: returning $supports_schedule_locking" 2
6714 return $supports_schedule_locking
6717 # Return 1 if compiler supports use of nested functions. Otherwise,
6720 gdb_caching_proc support_nested_function_tests {
6721 # Compile a test program containing a nested function
6722 return [gdb_can_simple_compile nested_func {
6732 # gdb_target_symbol returns the provided symbol with the correct prefix
6733 # prepended. (See gdb_target_symbol_prefix, above.)
6735 proc gdb_target_symbol { symbol } {
6736 set prefix [gdb_target_symbol_prefix]
6737 return "${prefix}${symbol}"
6740 # gdb_target_symbol_prefix_flags_asm returns a string that can be
6741 # added to gdb_compile options to define the C-preprocessor macro
6742 # SYMBOL_PREFIX with a value that can be prepended to symbols
6743 # for targets which require a prefix, such as underscore.
6745 # This version (_asm) defines the prefix without double quotes
6746 # surrounding the prefix. It is used to define the macro
6747 # SYMBOL_PREFIX for assembly language files. Another version, below,
6748 # is used for symbols in inline assembler in C/C++ files.
6750 # The lack of quotes in this version (_asm) makes it possible to
6751 # define supporting macros in the .S file. (The version which
6752 # uses quotes for the prefix won't work for such files since it's
6753 # impossible to define a quote-stripping macro in C.)
6755 # It's possible to use this version (_asm) for C/C++ source files too,
6756 # but a string is usually required in such files; providing a version
6757 # (no _asm) which encloses the prefix with double quotes makes it
6758 # somewhat easier to define the supporting macros in the test case.
6760 proc gdb_target_symbol_prefix_flags_asm {} {
6761 set prefix [gdb_target_symbol_prefix]
6762 if {$prefix ne ""} {
6763 return "additional_flags=-DSYMBOL_PREFIX=$prefix"
6769 # gdb_target_symbol_prefix_flags returns the same string as
6770 # gdb_target_symbol_prefix_flags_asm, above, but with the prefix
6771 # enclosed in double quotes if there is a prefix.
6773 # See the comment for gdb_target_symbol_prefix_flags_asm for an
6774 # extended discussion.
6776 proc gdb_target_symbol_prefix_flags {} {
6777 set prefix [gdb_target_symbol_prefix]
6778 if {$prefix ne ""} {
6779 return "additional_flags=-DSYMBOL_PREFIX=\"$prefix\""
6785 # A wrapper for 'remote_exec host' that passes or fails a test.
6786 # Returns 0 if all went well, nonzero on failure.
6787 # TEST is the name of the test, other arguments are as for remote_exec.
6789 proc run_on_host { test program args } {
6790 verbose -log "run_on_host: $program $args"
6791 # remote_exec doesn't work properly if the output is set but the
6792 # input is the empty string -- so replace an empty input with
6794 if {[llength $args] > 1 && [lindex $args 1] == ""} {
6795 set args [lreplace $args 1 1 "/dev/null"]
6797 set result [eval remote_exec host [list $program] $args]
6798 verbose "result is $result"
6799 set status [lindex $result 0]
6800 set output [lindex $result 1]
6805 verbose -log "run_on_host failed: $output"
6811 # Return non-zero if "board_info debug_flags" mentions Fission.
6812 # http://gcc.gnu.org/wiki/DebugFission
6813 # Fission doesn't support everything yet.
6814 # This supports working around bug 15954.
6816 proc using_fission { } {
6817 set debug_flags [board_info [target_info name] debug_flags]
6818 return [regexp -- "-gsplit-dwarf" $debug_flags]
6821 # Search the caller's ARGS list and set variables according to the list of
6822 # valid options described by ARGSET.
6824 # The first member of each one- or two-element list in ARGSET defines the
6825 # name of a variable that will be added to the caller's scope.
6827 # If only one element is given to describe an option, it the value is
6828 # 0 if the option is not present in (the caller's) ARGS or 1 if
6831 # If two elements are given, the second element is the default value of
6832 # the variable. This is then overwritten if the option exists in ARGS.
6834 # Any parse_args elements in (the caller's) ARGS will be removed, leaving
6835 # any optional components.
6838 # proc myproc {foo args} {
6839 # parse_args {{bar} {baz "abc"} {qux}}
6842 # myproc ABC -bar -baz DEF peanut butter
6843 # will define the following variables in myproc:
6844 # foo (=ABC), bar (=1), baz (=DEF), and qux (=0)
6845 # args will be the list {peanut butter}
6847 proc parse_args { argset } {
6850 foreach argument $argset {
6851 if {[llength $argument] == 1} {
6852 # No default specified, so we assume that we should set
6853 # the value to 1 if the arg is present and 0 if it's not.
6854 # It is assumed that no value is given with the argument.
6855 set result [lsearch -exact $args "-$argument"]
6856 if {$result != -1} then {
6857 uplevel 1 [list set $argument 1]
6858 set args [lreplace $args $result $result]
6860 uplevel 1 [list set $argument 0]
6862 } elseif {[llength $argument] == 2} {
6863 # There are two items in the argument. The second is a
6864 # default value to use if the item is not present.
6865 # Otherwise, the variable is set to whatever is provided
6866 # after the item in the args.
6867 set arg [lindex $argument 0]
6868 set result [lsearch -exact $args "-[lindex $arg 0]"]
6869 if {$result != -1} then {
6870 uplevel 1 [list set $arg [lindex $args [expr $result+1]]]
6871 set args [lreplace $args $result [expr $result+1]]
6873 uplevel 1 [list set $arg [lindex $argument 1]]
6876 error "Badly formatted argument \"$argument\" in argument set"
6880 # The remaining args should be checked to see that they match the
6881 # number of items expected to be passed into the procedure...
6884 # Capture the output of COMMAND in a string ignoring PREFIX (a regexp);
6885 # return that string.
6887 proc capture_command_output { command prefix } {
6891 set output_string ""
6892 gdb_test_multiple "$command" "capture_command_output for $command" {
6893 -re "[string_to_regexp ${command}]\[\r\n\]+${prefix}(.*)\[\r\n\]+$gdb_prompt $" {
6894 set output_string $expect_out(1,string)
6897 return $output_string
6900 # A convenience function that joins all the arguments together, with a
6901 # regexp that matches exactly one end of line in between each argument.
6902 # This function is ideal to write the expected output of a GDB command
6903 # that generates more than a couple of lines, as this allows us to write
6904 # each line as a separate string, which is easier to read by a human
6907 proc multi_line { args } {
6908 return [join $args "\r\n"]
6911 # Similar to the above, but while multi_line is meant to be used to
6912 # match GDB output, this one is meant to be used to build strings to
6913 # send as GDB input.
6915 proc multi_line_input { args } {
6916 return [join $args "\n"]
6919 # Return the version of the DejaGnu framework.
6921 # The return value is a list containing the major, minor and patch version
6922 # numbers. If the version does not contain a minor or patch number, they will
6923 # be set to 0. For example:
6929 proc dejagnu_version { } {
6930 # The frame_version variable is defined by DejaGnu, in runtest.exp.
6931 global frame_version
6933 verbose -log "DejaGnu version: $frame_version"
6934 verbose -log "Expect version: [exp_version]"
6935 verbose -log "Tcl version: [info tclversion]"
6937 set dg_ver [split $frame_version .]
6939 while { [llength $dg_ver] < 3 } {
6946 # Define user-defined command COMMAND using the COMMAND_LIST as the
6947 # command's definition. The terminating "end" is added automatically.
6949 proc gdb_define_cmd {command command_list} {
6952 set input [multi_line_input {*}$command_list "end"]
6953 set test "define $command"
6955 gdb_test_multiple "define $command" $test {
6957 gdb_test_multiple $input $test {
6958 -re "\r\n$gdb_prompt " {
6965 # Override the 'cd' builtin with a version that ensures that the
6966 # log file keeps pointing at the same file. We need this because
6967 # unfortunately the path to the log file is recorded using an
6968 # relative path name, and, we sometimes need to close/reopen the log
6969 # after changing the current directory. See get_compiler_info.
6971 rename cd builtin_cd
6975 # Get the existing log file flags.
6976 set log_file_info [log_file -info]
6978 # Split the flags into args and file name.
6979 set log_file_flags ""
6980 set log_file_file ""
6981 foreach arg [ split "$log_file_info" " "] {
6982 if [string match "-*" $arg] {
6983 lappend log_file_flags $arg
6985 lappend log_file_file $arg
6989 # If there was an existing file, ensure it is an absolute path, and then
6991 if { $log_file_file != "" } {
6992 set log_file_file [file normalize $log_file_file]
6994 log_file $log_file_flags "$log_file_file"
6997 # Call the builtin version of cd.
7001 # Return a list of all languages supported by GDB, suitable for use in
7002 # 'set language NAME'. This doesn't include either the 'local' or
7004 proc gdb_supported_languages {} {
7005 return [list c objective-c c++ d go fortran modula-2 asm pascal \
7006 opencl rust minimal ada]
7009 # Check if debugging is enabled for gdb.
7011 proc gdb_debug_enabled { } {
7014 # If not already read, get the debug setting from environment or board setting.
7015 if {![info exists gdbdebug]} {
7017 if [info exists env(GDB_DEBUG)] {
7018 set gdbdebug $env(GDB_DEBUG)
7019 } elseif [target_info exists gdb,debug] {
7020 set gdbdebug [target_info gdb,debug]
7026 # Ensure it not empty.
7027 return [expr { $gdbdebug != "" }]
7030 # Turn on debugging if enabled, or reset if already on.
7032 proc gdb_debug_init { } {
7036 if ![gdb_debug_enabled] {
7040 # First ensure logging is off.
7041 send_gdb "set logging off\n"
7043 set debugfile [standard_output_file gdb.debug]
7044 send_gdb "set logging file $debugfile\n"
7046 send_gdb "set logging debugredirect\n"
7049 foreach entry [split $gdbdebug ,] {
7050 send_gdb "set debug $entry 1\n"
7053 # Now that everything is set, enable logging.
7054 send_gdb "set logging on\n"
7056 -re "Copying output to $debugfile.*Redirecting debug output to $debugfile.*$gdb_prompt $" {}
7057 timeout { warning "Couldn't set logging file" }
7061 # Check if debugging is enabled for gdbserver.
7063 proc gdbserver_debug_enabled { } {
7064 # Always disabled for GDB only setups.
7068 # Open the file for logging gdb input
7070 proc gdb_stdin_log_init { } {
7071 gdb_persistent_global in_file
7073 if {[info exists in_file]} {
7074 # Close existing file.
7075 catch "close $in_file"
7078 set logfile [standard_output_file_with_gdb_instance gdb.in]
7079 set in_file [open $logfile w]
7082 # Write to the file for logging gdb input.
7083 # TYPE can be one of the following:
7084 # "standard" : Default. Standard message written to the log
7085 # "answer" : Answer to a question (eg "Y"). Not written the log.
7086 # "optional" : Optional message. Not written to the log.
7088 proc gdb_stdin_log_write { message {type standard} } {
7091 if {![info exists in_file]} {
7095 # Check message types.
7096 switch -regexp -- $type {
7106 puts -nonewline $in_file "$message"
7109 # Write the command line used to invocate gdb to the cmd file.
7111 proc gdb_write_cmd_file { cmdline } {
7112 set logfile [standard_output_file_with_gdb_instance gdb.cmd]
7113 set cmd_file [open $logfile w]
7114 puts $cmd_file $cmdline
7115 catch "close $cmd_file"
7118 # Compare contents of FILE to string STR. Pass with MSG if equal, otherwise
7121 proc cmp_file_string { file str msg } {
7122 if { ![file exists $file]} {
7127 set caught_error [catch {
7128 set fp [open "$file" r]
7129 set file_contents [read $fp]
7132 if { $caught_error } then {
7133 error "$error_message"
7138 if { $file_contents == $str } {
7145 # Does the compiler support CTF debug output using '-gt' compiler
7146 # flag? If not then we should skip these tests.
7148 gdb_caching_proc skip_ctf_tests {
7149 return ![gdb_can_simple_compile ctfdebug {
7153 } executable "additional_flags=-gt"]
7156 # Return 1 if compiler supports -gstatement-frontiers. Otherwise,
7159 gdb_caching_proc supports_statement_frontiers {
7160 return [gdb_can_simple_compile supports_statement_frontiers {
7164 } executable "additional_flags=-gstatement-frontiers"]
7167 # Return 1 if compiler supports -mmpx -fcheck-pointer-bounds. Otherwise,
7170 gdb_caching_proc supports_mpx_check_pointer_bounds {
7171 set flags "additional_flags=-mmpx additional_flags=-fcheck-pointer-bounds"
7172 return [gdb_can_simple_compile supports_mpx_check_pointer_bounds {
7176 } executable $flags]
7179 # Return 1 if compiler supports -fcf-protection=. Otherwise,
7182 gdb_caching_proc supports_fcf_protection {
7183 return [gdb_can_simple_compile supports_fcf_protection {
7187 } executable "additional_flags=-fcf-protection=full"]
7190 # Return 1 if symbols were read in using -readnow. Otherwise, return 0.
7193 set cmd "maint print objfiles"
7194 gdb_test_multiple $cmd "" {
7195 -re -wrap "\r\n.gdb_index: faked for \"readnow\"\r\n.*" {
7206 # Return 1 if partial symbols are available. Otherwise, return 0.
7208 proc psymtabs_p { } {
7211 set cmd "maint info psymtab"
7212 gdb_test_multiple $cmd "" {
7213 -re "$cmd\r\n$gdb_prompt $" {
7224 # Verify that partial symtab expansion for $filename has state $readin.
7226 proc verify_psymtab_expanded { filename readin } {
7229 set cmd "maint info psymtab"
7230 set test "$cmd: $filename: $readin"
7231 set re [multi_line \
7232 " \{ psymtab \[^\r\n\]*$filename\[^\r\n\]*" \
7236 gdb_test_multiple $cmd $test {
7237 -re "$cmd\r\n$gdb_prompt $" {
7238 unsupported $gdb_test_name
7246 # Add a .gdb_index section to PROGRAM.
7247 # PROGRAM is assumed to be the output of standard_output_file.
7248 # Returns the 0 if there is a failure, otherwise 1.
7250 proc add_gdb_index { program } {
7251 global srcdir GDB env BUILD_DATA_DIRECTORY
7252 set contrib_dir "$srcdir/../contrib"
7253 set env(GDB) "$GDB --data-directory=$BUILD_DATA_DIRECTORY"
7254 set result [catch "exec $contrib_dir/gdb-add-index.sh $program" output]
7255 if { $result != 0 } {
7256 verbose -log "result is $result"
7257 verbose -log "output is $output"
7264 # Add a .gdb_index section to PROGRAM, unless it alread has an index
7265 # (.gdb_index/.debug_names). Gdb doesn't support building an index from a
7266 # program already using one. Return 1 if a .gdb_index was added, return 0
7267 # if it already contained an index, and -1 if an error occurred.
7269 proc ensure_gdb_index { binfile } {
7270 set testfile [file tail $binfile]
7271 set test "check if index present"
7272 gdb_test_multiple "mt print objfiles ${testfile}" $test {
7273 -re -wrap "gdb_index.*" {
7276 -re -wrap "debug_names.*" {
7279 -re -wrap "Psymtabs.*" {
7280 if { [add_gdb_index $binfile] != "1" } {
7289 # Return 1 if executable contains .debug_types section. Otherwise, return 0.
7291 proc debug_types { } {
7294 set cmd "maint info sections"
7295 gdb_test_multiple $cmd "" {
7296 -re -wrap "at $hex: .debug_types.*" {
7307 # Return the addresses in the line table for FILE for which is_stmt is true.
7309 proc is_stmt_addresses { file } {
7315 gdb_test_multiple "maint info line-table $file" "" {
7316 -re "\r\n$decimal\[ \t\]+$decimal\[ \t\]+($hex)\[ \t\]+Y\[^\r\n\]*" {
7317 lappend is_stmt $expect_out(1,string)
7327 # Return 1 if hex number VAL is an element of HEXLIST.
7329 proc hex_in_list { val hexlist } {
7330 # Normalize val by removing 0x prefix, and leading zeros.
7331 set val [regsub ^0x $val ""]
7332 set val [regsub ^0+ $val "0"]
7335 set index [lsearch -regexp $hexlist $re]
7336 return [expr $index != -1]
7339 # Override proc NAME to proc OVERRIDE for the duration of the execution of
7342 proc with_override { name override body } {
7343 # Implementation note: It's possible to implement the override using
7344 # rename, like this:
7345 # rename $name save_$name
7346 # rename $override $name
7347 # set code [catch {uplevel 1 $body} result]
7348 # rename $name $override
7349 # rename save_$name $name
7350 # but there are two issues here:
7351 # - the save_$name might clash with an existing proc
7352 # - the override is no longer available under its original name during
7354 # So, we use this more elaborate but cleaner mechanism.
7356 # Save the old proc.
7357 set old_args [info args $name]
7358 set old_body [info body $name]
7360 # Install the override.
7361 set new_args [info args $override]
7362 set new_body [info body $override]
7363 eval proc $name {$new_args} {$new_body}
7366 set code [catch {uplevel 1 $body} result]
7369 eval proc $name {$old_args} {$old_body}
7371 # Return as appropriate.
7373 global errorInfo errorCode
7374 return -code error -errorinfo $errorInfo -errorcode $errorCode $result
7375 } elseif { $code > 1 } {
7376 return -code $code $result
7382 # Setup tuiterm.exp environment. To be used in test-cases instead of
7383 # "load_lib tuiterm.exp". Calls initialization function and schedules
7384 # finalization function.
7385 proc tuiterm_env { } {
7386 load_lib tuiterm.exp
7388 # Do initialization.
7391 # Schedule finalization.
7392 global gdb_finish_hooks
7393 lappend gdb_finish_hooks tuiterm_env_finish
7396 # Dejagnu has a version of note, but usage is not allowed outside of dejagnu.
7397 # Define a local version.
7398 proc gdb_note { message } {
7399 verbose -- "NOTE: $message" 0
7402 # Always load compatibility stuff.