1 # Copyright 1992-2021 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 \
131 "-data-directory $BUILD_DATA_DIRECTORY" \
132 {-iex "set height 0"} \
133 {-iex "set width 0"}]]
136 # The variable gdb_prompt is a regexp which matches the gdb prompt.
137 # Set it if it is not already set. This is also set by default_gdb_init
138 # but it's not clear what removing one of them will break.
139 # See with_gdb_prompt for more details on prompt handling.
141 if ![info exists gdb_prompt] then {
142 set gdb_prompt "\\(gdb\\)"
145 # A regexp that matches the pagination prompt.
146 set pagination_prompt \
147 "--Type <RET> for more, q to quit, c to continue without paging--"
149 # The variable fullname_syntax_POSIX is a regexp which matches a POSIX
150 # absolute path ie. /foo/
151 set fullname_syntax_POSIX {/[^\n]*/}
152 # The variable fullname_syntax_UNC is a regexp which matches a Windows
153 # UNC path ie. \\D\foo\
154 set fullname_syntax_UNC {\\\\[^\\]+\\[^\n]+\\}
155 # The variable fullname_syntax_DOS_CASE is a regexp which matches a
156 # particular DOS case that GDB most likely will output
157 # ie. \foo\, but don't match \\.*\
158 set fullname_syntax_DOS_CASE {\\[^\\][^\n]*\\}
159 # The variable fullname_syntax_DOS is a regexp which matches a DOS path
160 # ie. a:\foo\ && a:foo\
161 set fullname_syntax_DOS {[a-zA-Z]:[^\n]*\\}
162 # The variable fullname_syntax is a regexp which matches what GDB considers
163 # an absolute path. It is currently debatable if the Windows style paths
164 # d:foo and \abc should be considered valid as an absolute path.
165 # Also, the purpse of this regexp is not to recognize a well formed
166 # absolute path, but to say with certainty that a path is absolute.
167 set fullname_syntax "($fullname_syntax_POSIX|$fullname_syntax_UNC|$fullname_syntax_DOS_CASE|$fullname_syntax_DOS)"
169 # Needed for some tests under Cygwin.
173 if ![info exists env(EXEEXT)] {
176 set EXEEXT $env(EXEEXT)
181 set inferior_exited_re "(?:\\\[Inferior \[0-9\]+ \\(\[^\n\r\]*\\) exited)"
183 # A regular expression that matches a value history number.
185 set valnum_re "\\\$$decimal"
187 ### Only procedures should come after this point.
190 # gdb_version -- extract and print the version number of GDB
192 proc default_gdb_version {} {
194 global INTERNAL_GDBFLAGS GDBFLAGS
198 if {[info exists inotify_pid]} {
199 eval exec kill $inotify_pid
202 set output [remote_exec host "$GDB $INTERNAL_GDBFLAGS --version"]
203 set tmp [lindex $output 1]
205 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
206 if ![is_remote host] {
207 clone_output "[which $GDB] version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
209 clone_output "$GDB on remote host version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
213 proc gdb_version { } {
214 return [default_gdb_version]
218 # gdb_unload -- unload a file if one is loaded
219 # Return 0 on success, -1 on error.
227 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
228 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
229 -re "A program is being debugged already.*Are you sure you want to change the file.*y or n. $" {
230 send_gdb "y\n" answer
233 -re "Discard symbol table from .*y or n.*$" {
234 send_gdb "y\n" answer
237 -re "$gdb_prompt $" {}
238 -re "A problem internal to GDB has been detected" {
239 perror "Couldn't unload file in $GDB (GDB internal error)."
240 gdb_internal_error_resync
244 perror "couldn't unload file in $GDB (timeout)."
251 # Many of the tests depend on setting breakpoints at various places and
252 # running until that breakpoint is reached. At times, we want to start
253 # with a clean-slate with respect to breakpoints, so this utility proc
254 # lets us do this without duplicating this code everywhere.
257 proc delete_breakpoints {} {
260 # we need a larger timeout value here or this thing just confuses
261 # itself. May need a better implementation if possible. - guo
265 set msg "delete all breakpoints in delete_breakpoints"
267 gdb_test_multiple "delete breakpoints" "$msg" {
268 -re "Delete all breakpoints.*y or n.*$" {
269 send_gdb "y\n" answer
272 -re "$gdb_prompt $" {
278 # Confirm with "info breakpoints".
280 set msg "info breakpoints"
281 gdb_test_multiple $msg $msg {
282 -re "No breakpoints or watchpoints..*$gdb_prompt $" {
285 -re "$gdb_prompt $" {
291 perror "breakpoints not deleted"
295 # Returns true iff the target supports using the "run" command.
297 proc target_can_use_run_cmd {} {
298 if [target_info exists use_gdb_stub] {
299 # In this case, when we connect, the inferior is already
308 # Generic run command.
310 # Return 0 if we could start the program, -1 if we could not.
312 # The second pattern below matches up to the first newline *only*.
313 # Using ``.*$'' could swallow up output that we attempt to match
316 # INFERIOR_ARGS is passed as arguments to the start command, so may contain
317 # inferior arguments.
319 # N.B. This function does not wait for gdb to return to the prompt,
320 # that is the caller's responsibility.
322 proc gdb_run_cmd { {inferior_args {}} } {
323 global gdb_prompt use_gdb_stub
325 foreach command [gdb_init_commands] {
326 send_gdb "$command\n"
328 -re "$gdb_prompt $" { }
330 perror "gdb_init_command for target failed"
337 if [target_info exists gdb,do_reload_on_run] {
338 if { [gdb_reload $inferior_args] != 0 } {
341 send_gdb "continue\n"
343 -re "Continu\[^\r\n\]*\[\r\n\]" {}
349 if [target_info exists gdb,start_symbol] {
350 set start [target_info gdb,start_symbol]
354 send_gdb "jump *$start\n"
356 while { $start_attempt } {
357 # Cap (re)start attempts at three to ensure that this loop
358 # always eventually fails. Don't worry about trying to be
359 # clever and not send a command when it has failed.
360 if [expr $start_attempt > 3] {
361 perror "Jump to start() failed (retry count exceeded)"
364 set start_attempt [expr $start_attempt + 1]
366 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
369 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
370 perror "Can't find start symbol to run in gdb_run"
373 -re "No symbol \"start\" in current.*$gdb_prompt $" {
374 send_gdb "jump *_start\n"
376 -re "No symbol.*context.*$gdb_prompt $" {
379 -re "Line.* Jump anyway.*y or n. $" {
380 send_gdb "y\n" answer
382 -re "The program is not being run.*$gdb_prompt $" {
383 if { [gdb_reload $inferior_args] != 0 } {
386 send_gdb "jump *$start\n"
389 perror "Jump to start() failed (timeout)"
398 if [target_info exists gdb,do_reload_on_run] {
399 if { [gdb_reload $inferior_args] != 0 } {
403 send_gdb "run $inferior_args\n"
404 # This doesn't work quite right yet.
405 # Use -notransfer here so that test cases (like chng-sym.exp)
406 # may test for additional start-up messages.
408 -re "The program .* has been started already.*y or n. $" {
409 send_gdb "y\n" answer
412 -notransfer -re "Starting program: \[^\r\n\]*" {}
413 -notransfer -re "$gdb_prompt $" {
414 # There is no more input expected.
416 -notransfer -re "A problem internal to GDB has been detected" {
417 # Let caller handle this.
424 # Generic start command. Return 0 if we could start the program, -1
427 # INFERIOR_ARGS is passed as arguments to the start command, so may contain
428 # inferior arguments.
430 # N.B. This function does not wait for gdb to return to the prompt,
431 # that is the caller's responsibility.
433 proc gdb_start_cmd { {inferior_args {}} } {
434 global gdb_prompt use_gdb_stub
436 foreach command [gdb_init_commands] {
437 send_gdb "$command\n"
439 -re "$gdb_prompt $" { }
441 perror "gdb_init_command for target failed"
451 send_gdb "start $inferior_args\n"
452 # Use -notransfer here so that test cases (like chng-sym.exp)
453 # may test for additional start-up messages.
455 -re "The program .* has been started already.*y or n. $" {
456 send_gdb "y\n" answer
459 -notransfer -re "Starting program: \[^\r\n\]*" {
466 # Generic starti command. Return 0 if we could start the program, -1
469 # INFERIOR_ARGS is passed as arguments to the starti command, so may contain
470 # inferior arguments.
472 # N.B. This function does not wait for gdb to return to the prompt,
473 # that is the caller's responsibility.
475 proc gdb_starti_cmd { {inferior_args {}} } {
476 global gdb_prompt use_gdb_stub
478 foreach command [gdb_init_commands] {
479 send_gdb "$command\n"
481 -re "$gdb_prompt $" { }
483 perror "gdb_init_command for target failed"
493 send_gdb "starti $inferior_args\n"
495 -re "The program .* has been started already.*y or n. $" {
496 send_gdb "y\n" answer
499 -re "Starting program: \[^\r\n\]*" {
506 # Set a breakpoint at FUNCTION. If there is an additional argument it is
507 # a list of options; the supported options are allow-pending, temporary,
508 # message, no-message and qualified.
509 # The result is 1 for success, 0 for failure.
511 # Note: The handling of message vs no-message is messed up, but it's based
512 # on historical usage. By default this function does not print passes,
514 # no-message: turns off printing of fails (and passes, but they're already off)
515 # message: turns on printing of passes (and fails, but they're already on)
517 proc gdb_breakpoint { function args } {
521 set pending_response n
522 if {[lsearch -exact $args allow-pending] != -1} {
523 set pending_response y
526 set break_command "break"
527 set break_message "Breakpoint"
528 if {[lsearch -exact $args temporary] != -1} {
529 set break_command "tbreak"
530 set break_message "Temporary breakpoint"
533 if {[lsearch -exact $args qualified] != -1} {
534 append break_command " -qualified"
539 set no_message_loc [lsearch -exact $args no-message]
540 set message_loc [lsearch -exact $args message]
541 # The last one to appear in args wins.
542 if { $no_message_loc > $message_loc } {
544 } elseif { $message_loc > $no_message_loc } {
548 set test_name "setting breakpoint at $function"
550 send_gdb "$break_command $function\n"
551 # The first two regexps are what we get with -g, the third is without -g.
553 -re "$break_message \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
554 -re "$break_message \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
555 -re "$break_message \[0-9\]* at .*$gdb_prompt $" {}
556 -re "$break_message \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" {
557 if {$pending_response == "n"} {
564 -re "Make breakpoint pending.*y or \\\[n\\\]. $" {
565 send_gdb "$pending_response\n"
568 -re "A problem internal to GDB has been detected" {
570 fail "$test_name (GDB internal error)"
572 gdb_internal_error_resync
575 -re "$gdb_prompt $" {
582 perror "GDB process no longer exists"
584 set wait_status [wait -i $gdb_spawn_id]
585 verbose -log "GDB process exited with wait status $wait_status"
587 fail "$test_name (eof)"
593 fail "$test_name (timeout)"
604 # Set breakpoint at function and run gdb until it breaks there.
605 # Since this is the only breakpoint that will be set, if it stops
606 # at a breakpoint, we will assume it is the one we want. We can't
607 # just compare to "function" because it might be a fully qualified,
608 # single quoted C++ function specifier.
610 # If there are additional arguments, pass them to gdb_breakpoint.
611 # We recognize no-message/message ourselves.
612 # The default is no-message.
613 # no-message is messed up here, like gdb_breakpoint: to preserve
614 # historical usage fails are always printed by default.
615 # no-message: turns off printing of fails (and passes, but they're already off)
616 # message: turns on printing of passes (and fails, but they're already on)
618 proc runto { function args } {
624 # Default to "no-message".
625 set args "no-message $args"
629 set no_message_loc [lsearch -exact $args no-message]
630 set message_loc [lsearch -exact $args message]
631 # The last one to appear in args wins.
632 if { $no_message_loc > $message_loc } {
634 } elseif { $message_loc > $no_message_loc } {
638 set test_name "running to $function in runto"
640 # We need to use eval here to pass our varargs args to gdb_breakpoint
641 # which is also a varargs function.
642 # But we also have to be careful because $function may have multiple
643 # elements, and we don't want Tcl to move the remaining elements after
644 # the first to $args. That is why $function is wrapped in {}.
645 if ![eval gdb_breakpoint {$function} $args] {
651 # the "at foo.c:36" output we get with -g.
652 # the "in func" output we get without -g.
654 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
660 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
666 -re "The target does not support running in non-stop mode.\r\n$gdb_prompt $" {
668 unsupported "non-stop mode not supported"
672 -re ".*A problem internal to GDB has been detected" {
673 # Always emit a FAIL if we encounter an internal error: internal
674 # errors are never expected.
675 fail "$test_name (GDB internal error)"
676 gdb_internal_error_resync
679 -re "$gdb_prompt $" {
687 fail "$test_name (eof)"
693 fail "$test_name (timeout)"
704 # Ask gdb to run until we hit a breakpoint at main.
706 # N.B. This function deletes all existing breakpoints.
707 # If you don't want that, use gdb_start_cmd.
709 proc runto_main { } {
710 return [runto main no-message qualified]
713 ### Continue, and expect to hit a breakpoint.
714 ### Report a pass or fail, depending on whether it seems to have
715 ### worked. Use NAME as part of the test name; each call to
716 ### continue_to_breakpoint should use a NAME which is unique within
718 proc gdb_continue_to_breakpoint {name {location_pattern .*}} {
720 set full_name "continue to breakpoint: $name"
722 set kfail_pattern "Process record does not support instruction 0xfae64 at.*"
723 gdb_test_multiple "continue" $full_name {
724 -re "(?:Breakpoint|Temporary breakpoint) .* (at|in) $location_pattern\r\n$gdb_prompt $" {
727 -re "\[\r\n\]*(?:$kfail_pattern)\[\r\n\]+$gdb_prompt $" {
728 kfail "gdb/25038" $full_name
734 # gdb_internal_error_resync:
736 # Answer the questions GDB asks after it reports an internal error
737 # until we get back to a GDB prompt. Decline to quit the debugging
738 # session, and decline to create a core file. Return non-zero if the
741 # This procedure just answers whatever questions come up until it sees
742 # a GDB prompt; it doesn't require you to have matched the input up to
743 # any specific point. However, it only answers questions it sees in
744 # the output itself, so if you've matched a question, you had better
745 # answer it yourself before calling this.
747 # You can use this function thus:
751 # -re ".*A problem internal to GDB has been detected" {
752 # gdb_internal_error_resync
757 proc gdb_internal_error_resync {} {
760 verbose -log "Resyncing due to internal error."
763 while {$count < 10} {
765 -re "Quit this debugging session\\? \\(y or n\\) $" {
766 send_gdb "n\n" answer
769 -re "Create a core file of GDB\\? \\(y or n\\) $" {
770 send_gdb "n\n" answer
773 -re "$gdb_prompt $" {
774 # We're resynchronized.
778 perror "Could not resync from internal error (timeout)"
782 perror "Could not resync from internal error (eof)"
787 perror "Could not resync from internal error (resync count exceeded)"
792 # gdb_test_multiple COMMAND MESSAGE [ -prompt PROMPT_REGEXP] [ -lbl ]
794 # Send a command to gdb; test the result.
796 # COMMAND is the command to execute, send to GDB with send_gdb. If
797 # this is the null string no command is sent.
798 # MESSAGE is a message to be printed with the built-in failure patterns
799 # if one of them matches. If MESSAGE is empty COMMAND will be used.
800 # -prompt PROMPT_REGEXP specifies a regexp matching the expected prompt
801 # after the command output. If empty, defaults to "$gdb_prompt $".
802 # -lbl specifies that line-by-line matching will be used.
803 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
804 # patterns. Pattern elements will be evaluated in the caller's
805 # context; action elements will be executed in the caller's context.
806 # Unlike patterns for gdb_test, these patterns should generally include
807 # the final newline and prompt.
810 # 1 if the test failed, according to a built-in failure pattern
811 # 0 if only user-supplied patterns matched
812 # -1 if there was an internal error.
814 # You can use this function thus:
816 # gdb_test_multiple "print foo" "test foo" {
817 # -re "expected output 1" {
820 # -re "expected output 2" {
825 # Within action elements you can also make use of the variable
826 # gdb_test_name. This variable is setup automatically by
827 # gdb_test_multiple, and contains the value of MESSAGE. You can then
828 # write this, which is equivalent to the above:
830 # gdb_test_multiple "print foo" "test foo" {
831 # -re "expected output 1" {
832 # pass $gdb_test_name
834 # -re "expected output 2" {
835 # fail $gdb_test_name
839 # Like with "expect", you can also specify the spawn id to match with
840 # -i "$id". Interesting spawn ids are $inferior_spawn_id and
841 # $gdb_spawn_id. The former matches inferior I/O, while the latter
842 # matches GDB I/O. E.g.:
844 # send_inferior "hello\n"
845 # gdb_test_multiple "continue" "test echo" {
846 # -i "$inferior_spawn_id" -re "^hello\r\nhello\r\n$" {
849 # -i "$gdb_spawn_id" -re "Breakpoint.*$gdb_prompt $" {
850 # fail "hit breakpoint"
854 # The standard patterns, such as "Inferior exited..." and "A problem
855 # ...", all being implicitly appended to that list. These are always
856 # expected from $gdb_spawn_id. IOW, callers do not need to worry
857 # about resetting "-i" back to $gdb_spawn_id explicitly.
859 # In EXPECT_ARGUMENTS we can use a -wrap pattern flag, that wraps the regexp
860 # pattern as gdb_test wraps its message argument.
861 # This allows us to rewrite:
862 # gdb_test <command> <pattern> <message>
864 # gdb_test_multiple <command> <message> {
865 # -re -wrap <pattern> {
866 # pass $gdb_test_name
870 # In EXPECT_ARGUMENTS, a pattern flag -early can be used. It makes sure the
871 # pattern is inserted before any implicit pattern added by gdb_test_multiple.
872 # Using this pattern flag, we can f.i. setup a kfail for an assertion failure
873 # <assert> during gdb_continue_to_breakpoint by the rewrite:
874 # gdb_continue_to_breakpoint <msg> <pattern>
876 # set breakpoint_pattern "(?:Breakpoint|Temporary breakpoint) .* (at|in)"
877 # gdb_test_multiple "continue" "continue to breakpoint: <msg>" {
878 # -early -re "internal-error: <assert>" {
879 # setup_kfail gdb/nnnnn "*-*-*"
882 # -re "$breakpoint_pattern <pattern>\r\n$gdb_prompt $" {
883 # pass $gdb_test_name
887 proc gdb_test_multiple { command message args } {
888 global verbose use_gdb_stub
889 global gdb_prompt pagination_prompt
892 global inferior_exited_re
893 upvar timeout timeout
894 upvar expect_out expect_out
899 for {set i 0} {$i < [llength $args]} {incr i} {
900 set arg [lindex $args $i]
901 if { $arg == "-prompt" } {
903 set prompt_regexp [lindex $args $i]
904 } elseif { $arg == "-lbl" } {
911 if { [expr $i + 1] < [llength $args] } {
912 error "Too many arguments to gdb_test_multiple"
913 } elseif { ![info exists user_code] } {
914 error "Too few arguments to gdb_test_multiple"
917 if { "$prompt_regexp" == "" } {
918 set prompt_regexp "$gdb_prompt $"
921 if { $message == "" } {
925 if [string match "*\[\r\n\]" $command] {
926 error "Invalid trailing newline in \"$message\" test"
929 if [string match "*\[\r\n\]*" $message] {
930 error "Invalid newline in \"$message\" test"
934 && [regexp -nocase {^\s*(r|run|star|start|at|att|atta|attac|attach)\M} \
936 error "gdbserver does not support $command without extended-remote"
939 # TCL/EXPECT WART ALERT
940 # Expect does something very strange when it receives a single braced
941 # argument. It splits it along word separators and performs substitutions.
942 # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
943 # evaluated as "\[ab\]". But that's not how TCL normally works; inside a
944 # double-quoted list item, "\[ab\]" is just a long way of representing
945 # "[ab]", because the backslashes will be removed by lindex.
947 # Unfortunately, there appears to be no easy way to duplicate the splitting
948 # that expect will do from within TCL. And many places make use of the
949 # "\[0-9\]" construct, so we need to support that; and some places make use
950 # of the "[func]" construct, so we need to support that too. In order to
951 # get this right we have to substitute quoted list elements differently
952 # from braced list elements.
954 # We do this roughly the same way that Expect does it. We have to use two
955 # lists, because if we leave unquoted newlines in the argument to uplevel
956 # they'll be treated as command separators, and if we escape newlines
957 # we mangle newlines inside of command blocks. This assumes that the
958 # input doesn't contain a pattern which contains actual embedded newlines
961 regsub -all {\n} ${user_code} { } subst_code
962 set subst_code [uplevel list $subst_code]
964 set processed_code ""
965 set early_processed_code ""
966 # The variable current_list holds the name of the currently processed
967 # list, either processed_code or early_processed_code.
968 set current_list "processed_code"
970 set expecting_action 0
973 foreach item $user_code subst_item $subst_code {
974 if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } {
975 lappend $current_list $item
978 if { $item == "-indices" || $item == "-re" || $item == "-ex" } {
979 lappend $current_list $item
982 if { $item == "-early" } {
983 set current_list "early_processed_code"
986 if { $item == "-timeout" || $item == "-i" } {
988 lappend $current_list $item
991 if { $item == "-wrap" } {
995 if { $expecting_arg } {
997 lappend $current_list $subst_item
1000 if { $expecting_action } {
1001 lappend $current_list "uplevel [list $item]"
1002 set expecting_action 0
1003 # Cosmetic, no effect on the list.
1004 append $current_list "\n"
1005 # End the effect of -early, it only applies to one action.
1006 set current_list "processed_code"
1009 set expecting_action 1
1010 if { $wrap_pattern } {
1011 # Wrap subst_item as is done for the gdb_test PATTERN argument.
1012 lappend $current_list \
1013 "\[\r\n\]*(?:$subst_item)\[\r\n\]+$gdb_prompt $"
1016 lappend $current_list $subst_item
1018 if {$patterns != ""} {
1019 append patterns "; "
1021 append patterns "\"$subst_item\""
1024 # Also purely cosmetic.
1025 regsub -all {\r} $patterns {\\r} patterns
1026 regsub -all {\n} $patterns {\\n} patterns
1028 if $verbose>2 then {
1029 send_user "Sending \"$command\" to gdb\n"
1030 send_user "Looking to match \"$patterns\"\n"
1031 send_user "Message is \"$message\"\n"
1035 set string "${command}\n"
1036 if { $command != "" } {
1037 set multi_line_re "\[\r\n\] *>"
1038 while { "$string" != "" } {
1039 set foo [string first "\n" "$string"]
1040 set len [string length "$string"]
1041 if { $foo < [expr $len - 1] } {
1042 set str [string range "$string" 0 $foo]
1043 if { [send_gdb "$str"] != "" } {
1044 perror "Couldn't send $command to GDB."
1046 # since we're checking if each line of the multi-line
1047 # command are 'accepted' by GDB here,
1048 # we need to set -notransfer expect option so that
1049 # command output is not lost for pattern matching
1052 -notransfer -re "$multi_line_re$" { verbose "partial: match" 3 }
1053 timeout { verbose "partial: timeout" 3 }
1055 set string [string range "$string" [expr $foo + 1] end]
1056 set multi_line_re "$multi_line_re.*\[\r\n\] *>"
1061 if { "$string" != "" } {
1062 if { [send_gdb "$string"] != "" } {
1063 perror "Couldn't send $command to GDB."
1068 set code $early_processed_code
1070 -re ".*A problem internal to GDB has been detected" {
1071 fail "$message (GDB internal error)"
1072 gdb_internal_error_resync
1075 -re "\\*\\*\\* DOSEXIT code.*" {
1076 if { $message != "" } {
1082 append code $processed_code
1084 # Reset the spawn id, in case the processed code used -i.
1090 -re "Ending remote debugging.*$prompt_regexp" {
1091 if ![isnative] then {
1092 warning "Can`t communicate to remote target."
1098 -re "Undefined\[a-z\]* command:.*$prompt_regexp" {
1099 perror "Undefined command \"$command\"."
1103 -re "Ambiguous command.*$prompt_regexp" {
1104 perror "\"$command\" is not a unique command name."
1108 -re "$inferior_exited_re with code \[0-9\]+.*$prompt_regexp" {
1109 if ![string match "" $message] then {
1110 set errmsg "$message (the program exited)"
1112 set errmsg "$command (the program exited)"
1117 -re "$inferior_exited_re normally.*$prompt_regexp" {
1118 if ![string match "" $message] then {
1119 set errmsg "$message (the program exited)"
1121 set errmsg "$command (the program exited)"
1126 -re "The program is not being run.*$prompt_regexp" {
1127 if ![string match "" $message] then {
1128 set errmsg "$message (the program is no longer running)"
1130 set errmsg "$command (the program is no longer running)"
1135 -re "\r\n$prompt_regexp" {
1136 if ![string match "" $message] then {
1141 -re "$pagination_prompt" {
1143 perror "Window too small."
1147 -re "\\((y or n|y or \\\[n\\\]|\\\[y\\\] or n)\\) " {
1148 send_gdb "n\n" answer
1149 gdb_expect -re "$prompt_regexp"
1150 fail "$message (got interactive prompt)"
1153 -re "\\\[0\\\] cancel\r\n\\\[1\\\] all.*\r\n> $" {
1155 gdb_expect -re "$prompt_regexp"
1156 fail "$message (got breakpoint menu)"
1162 perror "GDB process no longer exists"
1163 set wait_status [wait -i $gdb_spawn_id]
1164 verbose -log "GDB process exited with wait status $wait_status"
1165 if { $message != "" } {
1172 if {$line_by_line} {
1174 -re "\r\n\[^\r\n\]*(?=\r\n)" {
1180 # Now patterns that apply to any spawn id specified.
1184 perror "Process no longer exists"
1185 if { $message != "" } {
1191 perror "internal buffer is full."
1196 if ![string match "" $message] then {
1197 fail "$message (timeout)"
1203 # remote_expect calls the eof section if there is an error on the
1204 # expect call. We already have eof sections above, and we don't
1205 # want them to get called in that situation. Since the last eof
1206 # section becomes the error section, here we define another eof
1207 # section, but with an empty spawn_id list, so that it won't ever
1211 # This comment is here because the eof section must not be
1212 # the empty string, otherwise remote_expect won't realize
1217 # Create gdb_test_name in the parent scope. If this variable
1218 # already exists, which it might if we have nested calls to
1219 # gdb_test_multiple, then preserve the old value, otherwise,
1220 # create a new variable in the parent scope.
1221 upvar gdb_test_name gdb_test_name
1222 if { [info exists gdb_test_name] } {
1223 set gdb_test_name_old "$gdb_test_name"
1225 set gdb_test_name "$message"
1228 set code [catch {gdb_expect $code} string]
1230 # Clean up the gdb_test_name variable. If we had a
1231 # previous value then restore it, otherwise, delete the variable
1232 # from the parent scope.
1233 if { [info exists gdb_test_name_old] } {
1234 set gdb_test_name "$gdb_test_name_old"
1240 global errorInfo errorCode
1241 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
1242 } elseif {$code > 1} {
1243 return -code $code $string
1248 # Usage: gdb_test_multiline NAME INPUT RESULT {INPUT RESULT} ...
1249 # Run a test named NAME, consisting of multiple lines of input.
1250 # After each input line INPUT, search for result line RESULT.
1251 # Succeed if all results are seen; fail otherwise.
1253 proc gdb_test_multiline { name args } {
1256 foreach {input result} $args {
1258 if {[gdb_test_multiple $input "$name: input $inputnr: $input" {
1259 -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
1270 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
1271 # Send a command to gdb; test the result.
1273 # COMMAND is the command to execute, send to GDB with send_gdb. If
1274 # this is the null string no command is sent.
1275 # PATTERN is the pattern to match for a PASS, and must NOT include
1276 # the \r\n sequence immediately before the gdb prompt. This argument
1277 # may be omitted to just match the prompt, ignoring whatever output
1279 # MESSAGE is an optional message to be printed. If this is
1280 # omitted, then the pass/fail messages use the command string as the
1281 # message. (If this is the empty string, then sometimes we don't
1282 # call pass or fail at all; I don't understand this at all.)
1283 # QUESTION is a question GDB may ask in response to COMMAND, like
1285 # RESPONSE is the response to send if QUESTION appears.
1288 # 1 if the test failed,
1289 # 0 if the test passes,
1290 # -1 if there was an internal error.
1292 proc gdb_test { args } {
1294 upvar timeout timeout
1296 if [llength $args]>2 then {
1297 set message [lindex $args 2]
1299 set message [lindex $args 0]
1301 set command [lindex $args 0]
1302 set pattern [lindex $args 1]
1306 -re "\[\r\n\]*(?:$pattern)\[\r\n\]+$gdb_prompt $" {
1307 if ![string match "" $message] then {
1313 if { [llength $args] == 5 } {
1314 set question_string [lindex $args 3]
1315 set response_string [lindex $args 4]
1317 -re "(${question_string})$" {
1318 send_gdb "$response_string\n"
1324 set user_code [join $user_code]
1325 return [gdb_test_multiple $command $message $user_code]
1328 # Return 1 if version MAJOR.MINOR is at least AT_LEAST_MAJOR.AT_LEAST_MINOR.
1329 proc version_at_least { major minor at_least_major at_least_minor} {
1330 if { $major > $at_least_major } {
1332 } elseif { $major == $at_least_major \
1333 && $minor >= $at_least_minor } {
1340 # Return 1 if tcl version used is at least MAJOR.MINOR
1341 proc tcl_version_at_least { major minor } {
1343 regexp {^([0-9]+)\.([0-9]+)$} $tcl_version \
1344 dummy tcl_version_major tcl_version_minor
1345 return [version_at_least $tcl_version_major $tcl_version_minor \
1349 if { [tcl_version_at_least 8 5] == 0 } {
1350 # lrepeat was added in tcl 8.5. Only add if missing.
1351 proc lrepeat { n element } {
1352 if { [string is integer -strict $n] == 0 } {
1353 error "expected integer but got \"$n\""
1356 error "bad count \"$n\": must be integer >= 0"
1359 for {set i 0} {$i < $n} {incr i} {
1360 lappend res $element
1366 # gdb_test_no_output COMMAND MESSAGE
1367 # Send a command to GDB and verify that this command generated no output.
1369 # See gdb_test_multiple for a description of the COMMAND and MESSAGE
1370 # parameters. If MESSAGE is ommitted, then COMMAND will be used as
1371 # the message. (If MESSAGE is the empty string, then sometimes we do not
1372 # call pass or fail at all; I don't understand this at all.)
1374 proc gdb_test_no_output { args } {
1376 set command [lindex $args 0]
1377 if [llength $args]>1 then {
1378 set message [lindex $args 1]
1380 set message $command
1383 set command_regex [string_to_regexp $command]
1384 gdb_test_multiple $command $message {
1385 -re "^$command_regex\r\n$gdb_prompt $" {
1386 if ![string match "" $message] then {
1393 # Send a command and then wait for a sequence of outputs.
1394 # This is useful when the sequence is long and contains ".*", a single
1395 # regexp to match the entire output can get a timeout much easier.
1397 # COMMAND is the command to execute, send to GDB with send_gdb. If
1398 # this is the null string no command is sent.
1399 # TEST_NAME is passed to pass/fail. COMMAND is used if TEST_NAME is "".
1400 # EXPECTED_OUTPUT_LIST is a list of regexps of expected output, which are
1401 # processed in order, and all must be present in the output.
1403 # The -prompt switch can be used to override the prompt expected at the end of
1404 # the output sequence.
1406 # It is unnecessary to specify ".*" at the beginning or end of any regexp,
1407 # there is an implicit ".*" between each element of EXPECTED_OUTPUT_LIST.
1408 # There is also an implicit ".*" between the last regexp and the gdb prompt.
1410 # Like gdb_test and gdb_test_multiple, the output is expected to end with the
1411 # gdb prompt, which must not be specified in EXPECTED_OUTPUT_LIST.
1414 # 1 if the test failed,
1415 # 0 if the test passes,
1416 # -1 if there was an internal error.
1418 proc gdb_test_sequence { args } {
1421 parse_args {{prompt ""}}
1423 if { $prompt == "" } {
1424 set prompt "$gdb_prompt $"
1427 if { [llength $args] != 3 } {
1428 error "Unexpected # of arguments, expecting: COMMAND TEST_NAME EXPECTED_OUTPUT_LIST"
1431 lassign $args command test_name expected_output_list
1433 if { $test_name == "" } {
1434 set test_name $command
1437 lappend expected_output_list ""; # implicit ".*" before gdb prompt
1439 if { $command != "" } {
1440 send_gdb "$command\n"
1443 return [gdb_expect_list $test_name $prompt $expected_output_list]
1447 # Match output of COMMAND using RE. Read output line-by-line.
1448 # Report pass/fail with MESSAGE.
1449 # For a command foo with output:
1454 # the portion matched using RE is:
1459 # Optionally, additional -re-not <regexp> arguments can be specified, to
1460 # ensure that a regexp is not match by the COMMAND output.
1461 # Such an additional argument generates an additional PASS/FAIL of the form:
1462 # PASS: test-case.exp: $message: pattern not matched: <regexp>
1464 proc gdb_test_lines { command message re args } {
1467 for {set i 0} {$i < [llength $args]} {incr i} {
1468 set arg [lindex $args $i]
1469 if { $arg == "-re-not" } {
1471 if { [llength $args] == $i } {
1472 error "Missing argument for -re-not"
1475 set arg [lindex $args $i]
1478 error "Unhandled argument: $arg"
1482 if { $message == ""} {
1483 set message $command
1487 gdb_test_multiple $command $message {
1488 -re "\r\n(\[^\r\n\]*)(?=\r\n)" {
1489 set line $expect_out(1,string)
1490 if { $lines eq "" } {
1491 append lines "$line"
1493 append lines "\r\n$line"
1502 gdb_assert { [regexp $re $lines] } $message
1504 foreach re $re_not {
1505 gdb_assert { ![regexp $re $lines] } "$message: pattern not matched: $re"
1509 # Test that a command gives an error. For pass or fail, return
1510 # a 1 to indicate that more tests can proceed. However a timeout
1511 # is a serious error, generates a special fail message, and causes
1512 # a 0 to be returned to indicate that more tests are likely to fail
1515 proc test_print_reject { args } {
1519 if [llength $args]==2 then {
1520 set expectthis [lindex $args 1]
1522 set expectthis "should never match this bogus string"
1524 set sendthis [lindex $args 0]
1525 if $verbose>2 then {
1526 send_user "Sending \"$sendthis\" to gdb\n"
1527 send_user "Looking to match \"$expectthis\"\n"
1529 send_gdb "$sendthis\n"
1530 #FIXME: Should add timeout as parameter.
1532 -re "A .* in expression.*\\.*$gdb_prompt $" {
1533 pass "reject $sendthis"
1536 -re "Invalid syntax in expression.*$gdb_prompt $" {
1537 pass "reject $sendthis"
1540 -re "Junk after end of expression.*$gdb_prompt $" {
1541 pass "reject $sendthis"
1544 -re "Invalid number.*$gdb_prompt $" {
1545 pass "reject $sendthis"
1548 -re "Invalid character constant.*$gdb_prompt $" {
1549 pass "reject $sendthis"
1552 -re "No symbol table is loaded.*$gdb_prompt $" {
1553 pass "reject $sendthis"
1556 -re "No symbol .* in current context.*$gdb_prompt $" {
1557 pass "reject $sendthis"
1560 -re "Unmatched single quote.*$gdb_prompt $" {
1561 pass "reject $sendthis"
1564 -re "A character constant must contain at least one character.*$gdb_prompt $" {
1565 pass "reject $sendthis"
1568 -re "$expectthis.*$gdb_prompt $" {
1569 pass "reject $sendthis"
1572 -re ".*$gdb_prompt $" {
1573 fail "reject $sendthis"
1577 fail "reject $sendthis (eof or timeout)"
1584 # Same as gdb_test, but the second parameter is not a regexp,
1585 # but a string that must match exactly.
1587 proc gdb_test_exact { args } {
1588 upvar timeout timeout
1590 set command [lindex $args 0]
1592 # This applies a special meaning to a null string pattern. Without
1593 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
1594 # messages from commands that should have no output except a new
1595 # prompt. With this, only results of a null string will match a null
1598 set pattern [lindex $args 1]
1599 if [string match $pattern ""] {
1600 set pattern [string_to_regexp [lindex $args 0]]
1602 set pattern [string_to_regexp [lindex $args 1]]
1605 # It is most natural to write the pattern argument with only
1606 # embedded \n's, especially if you are trying to avoid Tcl quoting
1607 # problems. But gdb_expect really wants to see \r\n in patterns. So
1608 # transform the pattern here. First transform \r\n back to \n, in
1609 # case some users of gdb_test_exact already do the right thing.
1610 regsub -all "\r\n" $pattern "\n" pattern
1611 regsub -all "\n" $pattern "\r\n" pattern
1612 if [llength $args]==3 then {
1613 set message [lindex $args 2]
1614 return [gdb_test $command $pattern $message]
1617 return [gdb_test $command $pattern]
1620 # Wrapper around gdb_test_multiple that looks for a list of expected
1621 # output elements, but which can appear in any order.
1622 # CMD is the gdb command.
1623 # NAME is the name of the test.
1624 # ELM_FIND_REGEXP specifies how to partition the output into elements to
1626 # ELM_EXTRACT_REGEXP specifies the part of ELM_FIND_REGEXP to compare.
1627 # RESULT_MATCH_LIST is a list of exact matches for each expected element.
1628 # All elements of RESULT_MATCH_LIST must appear for the test to pass.
1630 # A typical use of ELM_FIND_REGEXP/ELM_EXTRACT_REGEXP is to extract one line
1631 # of text per element and then strip trailing \r\n's.
1633 # gdb_test_list_exact "foo" "bar" \
1634 # "\[^\r\n\]+\[\r\n\]+" \
1637 # {expected result 1} \
1638 # {expected result 2} \
1641 proc gdb_test_list_exact { cmd name elm_find_regexp elm_extract_regexp result_match_list } {
1644 set matches [lsort $result_match_list]
1646 gdb_test_multiple $cmd $name {
1647 "$cmd\[\r\n\]" { exp_continue }
1648 -re $elm_find_regexp {
1649 set str $expect_out(0,string)
1650 verbose -log "seen: $str" 3
1651 regexp -- $elm_extract_regexp $str elm_seen
1652 verbose -log "extracted: $elm_seen" 3
1653 lappend seen $elm_seen
1656 -re "$gdb_prompt $" {
1658 foreach got [lsort $seen] have $matches {
1659 if {![string equal $got $have]} {
1664 if {[string length $failed] != 0} {
1665 fail "$name ($failed not found)"
1673 # gdb_test_stdio COMMAND INFERIOR_PATTERN GDB_PATTERN MESSAGE
1674 # Send a command to gdb; expect inferior and gdb output.
1676 # See gdb_test_multiple for a description of the COMMAND and MESSAGE
1679 # INFERIOR_PATTERN is the pattern to match against inferior output.
1681 # GDB_PATTERN is the pattern to match against gdb output, and must NOT
1682 # include the \r\n sequence immediately before the gdb prompt, nor the
1683 # prompt. The default is empty.
1685 # Both inferior and gdb patterns must match for a PASS.
1687 # If MESSAGE is ommitted, then COMMAND will be used as the message.
1690 # 1 if the test failed,
1691 # 0 if the test passes,
1692 # -1 if there was an internal error.
1695 proc gdb_test_stdio {command inferior_pattern {gdb_pattern ""} {message ""}} {
1696 global inferior_spawn_id gdb_spawn_id
1699 if {$message == ""} {
1700 set message $command
1703 set inferior_matched 0
1706 # Use an indirect spawn id list, and remove the inferior spawn id
1707 # from the expected output as soon as it matches, in case
1708 # $inferior_pattern happens to be a prefix of the resulting full
1709 # gdb pattern below (e.g., "\r\n").
1710 global gdb_test_stdio_spawn_id_list
1711 set gdb_test_stdio_spawn_id_list "$inferior_spawn_id"
1713 # Note that if $inferior_spawn_id and $gdb_spawn_id are different,
1714 # then we may see gdb's output arriving before the inferior's
1716 set res [gdb_test_multiple $command $message {
1717 -i gdb_test_stdio_spawn_id_list -re "$inferior_pattern" {
1718 set inferior_matched 1
1719 if {!$gdb_matched} {
1720 set gdb_test_stdio_spawn_id_list ""
1724 -i $gdb_spawn_id -re "$gdb_pattern\r\n$gdb_prompt $" {
1726 if {!$inferior_matched} {
1734 verbose -log "inferior_matched=$inferior_matched, gdb_matched=$gdb_matched"
1739 # Wrapper around gdb_test_multiple to be used when testing expression
1740 # evaluation while 'set debug expression 1' is in effect.
1741 # Looks for some patterns that indicates the expression was rejected.
1743 # CMD is the command to execute, which should include an expression
1744 # that GDB will need to parse.
1746 # OUTPUT is the expected output pattern.
1748 # TESTNAME is the name to be used for the test, defaults to CMD if not
1750 proc gdb_test_debug_expr { cmd output {testname "" }} {
1753 if { ${testname} == "" } {
1757 gdb_test_multiple $cmd $testname {
1758 -re ".*Invalid expression.*\r\n$gdb_prompt $" {
1761 -re ".*\[\r\n\]$output\r\n$gdb_prompt $" {
1767 # get_print_expr_at_depths EXP OUTPUTS
1769 # Used for testing 'set print max-depth'. Prints the expression EXP
1770 # with 'set print max-depth' set to various depths. OUTPUTS is a list
1771 # of `n` different patterns to match at each of the depths from 0 to
1774 # This proc does one final check with the max-depth set to 'unlimited'
1775 # which is tested against the last pattern in the OUTPUTS list. The
1776 # OUTPUTS list is therefore required to match every depth from 0 to a
1777 # depth where the whole of EXP is printed with no ellipsis.
1779 # This proc leaves the 'set print max-depth' set to 'unlimited'.
1780 proc gdb_print_expr_at_depths {exp outputs} {
1781 for { set depth 0 } { $depth <= [llength $outputs] } { incr depth } {
1782 if { $depth == [llength $outputs] } {
1783 set expected_result [lindex $outputs [expr [llength $outputs] - 1]]
1784 set depth_string "unlimited"
1786 set expected_result [lindex $outputs $depth]
1787 set depth_string $depth
1790 with_test_prefix "exp='$exp': depth=${depth_string}" {
1791 gdb_test_no_output "set print max-depth ${depth_string}"
1792 gdb_test "p $exp" "$expected_result"
1799 # Issue a PASS and return true if evaluating CONDITION in the caller's
1800 # frame returns true, and issue a FAIL and return false otherwise.
1801 # MESSAGE is the pass/fail message to be printed. If MESSAGE is
1802 # omitted or is empty, then the pass/fail messages use the condition
1803 # string as the message.
1805 proc gdb_assert { condition {message ""} } {
1806 if { $message == ""} {
1807 set message $condition
1810 set code [catch {uplevel 1 expr $condition} res]
1812 # If code is 1 (TCL_ERROR), it means evaluation failed and res contains
1813 # an error message. Print the error message, and set res to 0 since we
1814 # want to return a boolean.
1815 warning "While evaluating expression in gdb_assert: $res"
1818 } elseif { !$res } {
1826 proc gdb_reinitialize_dir { subdir } {
1829 if [is_remote host] {
1834 -re "Reinitialize source path to empty.*y or n. " {
1835 send_gdb "y\n" answer
1837 -re "Source directories searched.*$gdb_prompt $" {
1838 send_gdb "dir $subdir\n"
1840 -re "Source directories searched.*$gdb_prompt $" {
1841 verbose "Dir set to $subdir"
1843 -re "$gdb_prompt $" {
1844 perror "Dir \"$subdir\" failed."
1848 -re "$gdb_prompt $" {
1849 perror "Dir \"$subdir\" failed."
1853 -re "$gdb_prompt $" {
1854 perror "Dir \"$subdir\" failed."
1860 # gdb_exit -- exit the GDB, killing the target program if necessary
1862 proc default_gdb_exit {} {
1864 global INTERNAL_GDBFLAGS GDBFLAGS
1865 global gdb_spawn_id inferior_spawn_id
1866 global inotify_log_file
1868 if ![info exists gdb_spawn_id] {
1872 verbose "Quitting $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1874 if {[info exists inotify_log_file] && [file exists $inotify_log_file]} {
1875 set fd [open $inotify_log_file]
1876 set data [read -nonewline $fd]
1879 if {[string compare $data ""] != 0} {
1880 warning "parallel-unsafe file creations noticed"
1883 set fd [open $inotify_log_file w]
1888 if { [is_remote host] && [board_info host exists fileid] } {
1892 send_gdb "y\n" answer
1895 -re "DOSEXIT code" { }
1900 if ![is_remote host] {
1904 unset ::gdb_tty_name
1905 unset inferior_spawn_id
1908 # Load a file into the debugger.
1909 # The return value is 0 for success, -1 for failure.
1911 # This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO
1912 # to one of these values:
1914 # debug file was loaded successfully and has debug information
1915 # nodebug file was loaded successfully and has no debug information
1916 # lzma file was loaded, .gnu_debugdata found, but no LZMA support
1918 # fail file was not loaded
1920 # This procedure also set the global variable GDB_FILE_CMD_MSG to the
1921 # output of the file command in case of success.
1923 # I tried returning this information as part of the return value,
1924 # but ran into a mess because of the many re-implementations of
1925 # gdb_load in config/*.exp.
1927 # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use
1928 # this if they can get more information set.
1930 proc gdb_file_cmd { arg } {
1933 global last_loaded_file
1935 # GCC for Windows target may create foo.exe given "-o foo".
1936 if { ![file exists $arg] && [file exists "$arg.exe"] } {
1940 # Save this for the benefit of gdbserver-support.exp.
1941 set last_loaded_file $arg
1943 # Set whether debug info was found.
1944 # Default to "fail".
1945 global gdb_file_cmd_debug_info gdb_file_cmd_msg
1946 set gdb_file_cmd_debug_info "fail"
1948 if [is_remote host] {
1949 set arg [remote_download host $arg]
1951 perror "download failed"
1956 # The file command used to kill the remote target. For the benefit
1957 # of the testsuite, preserve this behavior. Mark as optional so it doesn't
1958 # get written to the stdin log.
1959 send_gdb "kill\n" optional
1961 -re "Kill the program being debugged. .y or n. $" {
1962 send_gdb "y\n" answer
1963 verbose "\t\tKilling previous program being debugged"
1966 -re "$gdb_prompt $" {
1971 send_gdb "file $arg\n"
1972 set new_symbol_table 0
1973 set basename [file tail $arg]
1975 -re "(Reading symbols from.*LZMA support was disabled.*$gdb_prompt $)" {
1976 verbose "\t\tLoaded $arg into $GDB; .gnu_debugdata found but no LZMA available"
1977 set gdb_file_cmd_msg $expect_out(1,string)
1978 set gdb_file_cmd_debug_info "lzma"
1981 -re "(Reading symbols from.*no debugging symbols found.*$gdb_prompt $)" {
1982 verbose "\t\tLoaded $arg into $GDB with no debugging symbols"
1983 set gdb_file_cmd_msg $expect_out(1,string)
1984 set gdb_file_cmd_debug_info "nodebug"
1987 -re "(Reading symbols from.*$gdb_prompt $)" {
1988 verbose "\t\tLoaded $arg into $GDB"
1989 set gdb_file_cmd_msg $expect_out(1,string)
1990 set gdb_file_cmd_debug_info "debug"
1993 -re "Load new symbol table from \".*\".*y or n. $" {
1994 if { $new_symbol_table > 0 } {
1995 perror [join [list "Couldn't load $basename,"
1996 "interactive prompt loop detected."]]
1999 send_gdb "y\n" answer
2000 incr new_symbol_table
2001 set suffix "-- with new symbol table"
2002 set arg "$arg $suffix"
2003 set basename "$basename $suffix"
2006 -re "No such file or directory.*$gdb_prompt $" {
2007 perror "($basename) No such file or directory"
2010 -re "A problem internal to GDB has been detected" {
2011 perror "Couldn't load $basename into GDB (GDB internal error)."
2012 gdb_internal_error_resync
2015 -re "$gdb_prompt $" {
2016 perror "Couldn't load $basename into GDB."
2020 perror "Couldn't load $basename into GDB (timeout)."
2024 # This is an attempt to detect a core dump, but seems not to
2025 # work. Perhaps we need to match .* followed by eof, in which
2026 # gdb_expect does not seem to have a way to do that.
2027 perror "Couldn't load $basename into GDB (eof)."
2033 # The expect "spawn" function puts the tty name into the spawn_out
2034 # array; but dejagnu doesn't export this globally. So, we have to
2035 # wrap spawn with our own function and poke in the built-in spawn
2036 # so that we can capture this value.
2038 # If available, the TTY name is saved to the LAST_SPAWN_TTY_NAME global.
2039 # Otherwise, LAST_SPAWN_TTY_NAME is unset.
2041 proc spawn_capture_tty_name { args } {
2042 set result [uplevel builtin_spawn $args]
2043 upvar spawn_out spawn_out
2044 if { [info exists spawn_out(slave,name)] } {
2045 set ::last_spawn_tty_name $spawn_out(slave,name)
2047 # If a process is spawned as part of a pipe line (e.g. passing
2048 # -leaveopen to the spawn proc) then the spawned process is no
2049 # assigned a tty and spawn_out(slave,name) will not be set.
2050 # In that case we want to ensure that last_spawn_tty_name is
2053 # If the previous process spawned was also not assigned a tty
2054 # (e.g. multiple processed chained in a pipeline) then
2055 # last_spawn_tty_name will already be unset, so, if we don't
2056 # use -nocomplain here we would otherwise get an error.
2057 unset -nocomplain ::last_spawn_tty_name
2062 rename spawn builtin_spawn
2063 rename spawn_capture_tty_name spawn
2065 # Default gdb_spawn procedure.
2067 proc default_gdb_spawn { } {
2070 global INTERNAL_GDBFLAGS GDBFLAGS
2073 # Set the default value, it may be overriden later by specific testfile.
2075 # Use `set_board_info use_gdb_stub' for the board file to flag the inferior
2076 # is already started after connecting and run/attach are not supported.
2077 # This is used for the "remote" protocol. After GDB starts you should
2078 # check global $use_gdb_stub instead of the board as the testfile may force
2079 # a specific different target protocol itself.
2080 set use_gdb_stub [target_info exists use_gdb_stub]
2082 verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
2083 gdb_write_cmd_file "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
2085 if [info exists gdb_spawn_id] {
2089 if ![is_remote host] {
2090 if { [which $GDB] == 0 } then {
2091 perror "$GDB does not exist."
2095 set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"]
2096 if { $res < 0 || $res == "" } {
2097 perror "Spawning $GDB failed."
2101 set gdb_spawn_id $res
2102 set ::gdb_tty_name $::last_spawn_tty_name
2106 # Default gdb_start procedure.
2108 proc default_gdb_start { } {
2111 global inferior_spawn_id
2113 if [info exists gdb_spawn_id] {
2117 # Keep track of the number of times GDB has been launched.
2118 global gdb_instances
2128 # Default to assuming inferior I/O is done on GDB's terminal.
2129 if {![info exists inferior_spawn_id]} {
2130 set inferior_spawn_id $gdb_spawn_id
2133 # When running over NFS, particularly if running many simultaneous
2134 # tests on different hosts all using the same server, things can
2135 # get really slow. Give gdb at least 3 minutes to start up.
2137 -re "\[\r\n\]$gdb_prompt $" {
2138 verbose "GDB initialized."
2140 -re "$gdb_prompt $" {
2141 perror "GDB never initialized."
2146 perror "(timeout) GDB never initialized after 10 seconds."
2152 perror "(eof) GDB never initialized."
2158 # force the height to "unlimited", so no pagers get used
2160 send_gdb "set height 0\n"
2162 -re "$gdb_prompt $" {
2163 verbose "Setting height to 0." 2
2166 warning "Couldn't set the height to 0"
2169 # force the width to "unlimited", so no wraparound occurs
2170 send_gdb "set width 0\n"
2172 -re "$gdb_prompt $" {
2173 verbose "Setting width to 0." 2
2176 warning "Couldn't set the width to 0."
2184 # Utility procedure to give user control of the gdb prompt in a script. It is
2185 # meant to be used for debugging test cases, and should not be left in the
2188 proc gdb_interact { } {
2190 set spawn_id $gdb_spawn_id
2192 send_user "+------------------------------------------+\n"
2193 send_user "| Script interrupted, you can now interact |\n"
2194 send_user "| with by gdb. Type >>> to continue. |\n"
2195 send_user "+------------------------------------------+\n"
2202 # Examine the output of compilation to determine whether compilation
2203 # failed or not. If it failed determine whether it is due to missing
2204 # compiler or due to compiler error. Report pass, fail or unsupported
2207 proc gdb_compile_test {src output} {
2208 set msg "compilation [file tail $src]"
2210 if { $output == "" } {
2215 if { [regexp {^[a-zA-Z_0-9]+: Can't find [^ ]+\.$} $output]
2216 || [regexp {.*: command not found[\r|\n]*$} $output]
2217 || [regexp {.*: [^\r\n]*compiler not installed[^\r\n]*[\r|\n]*$} $output] } {
2218 unsupported "$msg (missing compiler)"
2222 set gcc_re ".*: error: unrecognized command line option "
2223 set clang_re ".*: error: unsupported option "
2224 if { [regexp "(?:$gcc_re|$clang_re)(\[^ \t;\r\n\]*)" $output dummy option]
2225 && $option != "" } {
2226 unsupported "$msg (unsupported option $option)"
2230 # Unclassified compilation failure, be more verbose.
2231 verbose -log "compilation failed: $output" 2
2235 # Return a 1 for configurations for which we don't even want to try to
2238 proc skip_cplus_tests {} {
2239 if { [istarget "h8300-*-*"] } {
2243 # The C++ IO streams are too large for HC11/HC12 and are thus not
2244 # available. The gdb C++ tests use them and don't compile.
2245 if { [istarget "m6811-*-*"] } {
2248 if { [istarget "m6812-*-*"] } {
2254 # Return a 1 for configurations for which don't have both C++ and the STL.
2256 proc skip_stl_tests {} {
2257 return [skip_cplus_tests]
2260 # Return a 1 if I don't even want to try to test FORTRAN.
2262 proc skip_fortran_tests {} {
2266 # Return a 1 if I don't even want to try to test ada.
2268 proc skip_ada_tests {} {
2272 # Return a 1 if I don't even want to try to test GO.
2274 proc skip_go_tests {} {
2278 # Return a 1 if I don't even want to try to test D.
2280 proc skip_d_tests {} {
2284 # Return 1 to skip Rust tests, 0 to try them.
2285 proc skip_rust_tests {} {
2286 if { ![isnative] } {
2290 # The rust compiler does not support "-m32", skip.
2291 global board board_info
2292 set board [target_info name]
2293 if {[board_info $board exists multilib_flags]} {
2294 foreach flag [board_info $board multilib_flags] {
2295 if { $flag == "-m32" } {
2304 # Return a 1 for configurations that do not support Python scripting.
2305 # PROMPT_REGEXP is the expected prompt.
2307 proc skip_python_tests_prompt { prompt_regexp } {
2308 global gdb_py_is_py3k
2310 gdb_test_multiple "python print ('test')" "verify python support" \
2311 -prompt "$prompt_regexp" {
2312 -re "not supported.*$prompt_regexp" {
2313 unsupported "Python support is disabled."
2316 -re "$prompt_regexp" {}
2319 gdb_test_multiple "python print (sys.version_info\[0\])" "check if python 3" \
2320 -prompt "$prompt_regexp" {
2321 -re "3.*$prompt_regexp" {
2322 set gdb_py_is_py3k 1
2324 -re ".*$prompt_regexp" {
2325 set gdb_py_is_py3k 0
2332 # Return a 1 for configurations that do not support Python scripting.
2333 # Note: This also sets various globals that specify which version of Python
2334 # is in use. See skip_python_tests_prompt.
2336 proc skip_python_tests {} {
2338 return [skip_python_tests_prompt "$gdb_prompt $"]
2341 # Return a 1 if we should skip shared library tests.
2343 proc skip_shlib_tests {} {
2344 # Run the shared library tests on native systems.
2349 # An abbreviated list of remote targets where we should be able to
2350 # run shared library tests.
2351 if {([istarget *-*-linux*]
2352 || [istarget *-*-*bsd*]
2353 || [istarget *-*-solaris2*]
2354 || [istarget *-*-mingw*]
2355 || [istarget *-*-cygwin*]
2356 || [istarget *-*-pe*])} {
2363 # Return 1 if we should skip tui related tests.
2365 proc skip_tui_tests {} {
2368 gdb_test_multiple "help layout" "verify tui support" {
2369 -re "Undefined command: \"layout\".*$gdb_prompt $" {
2372 -re "$gdb_prompt $" {
2379 # Test files shall make sure all the test result lines in gdb.sum are
2380 # unique in a test run, so that comparing the gdb.sum files of two
2381 # test runs gives correct results. Test files that exercise
2382 # variations of the same tests more than once, shall prefix the
2383 # different test invocations with different identifying strings in
2384 # order to make them unique.
2386 # About test prefixes:
2388 # $pf_prefix is the string that dejagnu prints after the result (FAIL,
2389 # PASS, etc.), and before the test message/name in gdb.sum. E.g., the
2390 # underlined substring in
2392 # PASS: gdb.base/mytest.exp: some test
2393 # ^^^^^^^^^^^^^^^^^^^^
2397 # The easiest way to adjust the test prefix is to append a test
2398 # variation prefix to the $pf_prefix, using the with_test_prefix
2401 # proc do_tests {} {
2402 # gdb_test ... ... "test foo"
2403 # gdb_test ... ... "test bar"
2405 # with_test_prefix "subvariation a" {
2406 # gdb_test ... ... "test x"
2409 # with_test_prefix "subvariation b" {
2410 # gdb_test ... ... "test x"
2414 # with_test_prefix "variation1" {
2415 # ...do setup for variation 1...
2419 # with_test_prefix "variation2" {
2420 # ...do setup for variation 2...
2426 # PASS: gdb.base/mytest.exp: variation1: test foo
2427 # PASS: gdb.base/mytest.exp: variation1: test bar
2428 # PASS: gdb.base/mytest.exp: variation1: subvariation a: test x
2429 # PASS: gdb.base/mytest.exp: variation1: subvariation b: test x
2430 # PASS: gdb.base/mytest.exp: variation2: test foo
2431 # PASS: gdb.base/mytest.exp: variation2: test bar
2432 # PASS: gdb.base/mytest.exp: variation2: subvariation a: test x
2433 # PASS: gdb.base/mytest.exp: variation2: subvariation b: test x
2435 # If for some reason more flexibility is necessary, one can also
2436 # manipulate the pf_prefix global directly, treating it as a string.
2440 # set saved_pf_prefix
2441 # append pf_prefix "${foo}: bar"
2442 # ... actual tests ...
2443 # set pf_prefix $saved_pf_prefix
2446 # Run BODY in the context of the caller, with the current test prefix
2447 # (pf_prefix) appended with one space, then PREFIX, and then a colon.
2448 # Returns the result of BODY.
2450 proc with_test_prefix { prefix body } {
2453 set saved $pf_prefix
2454 append pf_prefix " " $prefix ":"
2455 set code [catch {uplevel 1 $body} result]
2456 set pf_prefix $saved
2459 global errorInfo errorCode
2460 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2462 return -code $code $result
2466 # Wrapper for foreach that calls with_test_prefix on each iteration,
2467 # including the iterator's name and current value in the prefix.
2469 proc foreach_with_prefix {var list body} {
2471 foreach myvar $list {
2472 with_test_prefix "$var=$myvar" {
2473 set code [catch {uplevel 1 $body} result]
2477 global errorInfo errorCode
2478 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2479 } elseif {$code == 3} {
2481 } elseif {$code == 2} {
2482 return -code $code $result
2487 # Like TCL's native proc, but defines a procedure that wraps its body
2488 # within 'with_test_prefix "$proc_name" { ... }'.
2489 proc proc_with_prefix {name arguments body} {
2490 # Define the advertised proc.
2491 proc $name $arguments [list with_test_prefix $name $body]
2495 # Run BODY in the context of the caller. After BODY is run, the variables
2496 # listed in VARS will be reset to the values they had before BODY was run.
2498 # This is useful for providing a scope in which it is safe to temporarily
2499 # modify global variables, e.g.
2501 # global INTERNAL_GDBFLAGS
2504 # set foo GDBHISTSIZE
2506 # save_vars { INTERNAL_GDBFLAGS env($foo) env(HOME) } {
2507 # append INTERNAL_GDBFLAGS " -nx"
2508 # unset -nocomplain env(GDBHISTSIZE)
2513 # Here, although INTERNAL_GDBFLAGS, env(GDBHISTSIZE) and env(HOME) may be
2514 # modified inside BODY, this proc guarantees that the modifications will be
2515 # undone after BODY finishes executing.
2517 proc save_vars { vars body } {
2518 array set saved_scalars { }
2519 array set saved_arrays { }
2523 # First evaluate VAR in the context of the caller in case the variable
2524 # name may be a not-yet-interpolated string like env($foo)
2525 set var [uplevel 1 list $var]
2527 if [uplevel 1 [list info exists $var]] {
2528 if [uplevel 1 [list array exists $var]] {
2529 set saved_arrays($var) [uplevel 1 [list array get $var]]
2531 set saved_scalars($var) [uplevel 1 [list set $var]]
2534 lappend unset_vars $var
2538 set code [catch {uplevel 1 $body} result]
2540 foreach {var value} [array get saved_scalars] {
2541 uplevel 1 [list set $var $value]
2544 foreach {var value} [array get saved_arrays] {
2545 uplevel 1 [list unset $var]
2546 uplevel 1 [list array set $var $value]
2549 foreach var $unset_vars {
2550 uplevel 1 [list unset -nocomplain $var]
2554 global errorInfo errorCode
2555 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2557 return -code $code $result
2561 # As save_vars, but for variables stored in the board_info for the
2566 # save_target_board_info { multilib_flags } {
2568 # set board [target_info name]
2569 # unset_board_info multilib_flags
2570 # set_board_info multilib_flags "$multilib_flags"
2574 proc save_target_board_info { vars body } {
2575 global board board_info
2576 set board [target_info name]
2578 array set saved_target_board_info { }
2579 set unset_target_board_info { }
2582 if { [info exists board_info($board,$var)] } {
2583 set saved_target_board_info($var) [board_info $board $var]
2585 lappend unset_target_board_info $var
2589 set code [catch {uplevel 1 $body} result]
2591 foreach {var value} [array get saved_target_board_info] {
2592 unset_board_info $var
2593 set_board_info $var $value
2596 foreach var $unset_target_board_info {
2597 unset_board_info $var
2601 global errorInfo errorCode
2602 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2604 return -code $code $result
2608 # Run tests in BODY with the current working directory (CWD) set to
2609 # DIR. When BODY is finished, restore the original CWD. Return the
2612 # This procedure doesn't check if DIR is a valid directory, so you
2613 # have to make sure of that.
2615 proc with_cwd { dir body } {
2617 verbose -log "Switching to directory $dir (saved CWD: $saved_dir)."
2620 set code [catch {uplevel 1 $body} result]
2622 verbose -log "Switching back to $saved_dir."
2626 global errorInfo errorCode
2627 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2629 return -code $code $result
2633 # Run tests in BODY with GDB prompt and variable $gdb_prompt set to
2634 # PROMPT. When BODY is finished, restore GDB prompt and variable
2636 # Returns the result of BODY.
2640 # 1) If you want to use, for example, "(foo)" as the prompt you must pass it
2641 # as "(foo)", and not the regexp form "\(foo\)" (expressed as "\\(foo\\)" in
2642 # TCL). PROMPT is internally converted to a suitable regexp for matching.
2643 # We do the conversion from "(foo)" to "\(foo\)" here for a few reasons:
2644 # a) It's more intuitive for callers to pass the plain text form.
2645 # b) We need two forms of the prompt:
2646 # - a regexp to use in output matching,
2647 # - a value to pass to the "set prompt" command.
2648 # c) It's easier to convert the plain text form to its regexp form.
2650 # 2) Don't add a trailing space, we do that here.
2652 proc with_gdb_prompt { prompt body } {
2655 # Convert "(foo)" to "\(foo\)".
2656 # We don't use string_to_regexp because while it works today it's not
2657 # clear it will work tomorrow: the value we need must work as both a
2658 # regexp *and* as the argument to the "set prompt" command, at least until
2659 # we start recording both forms separately instead of just $gdb_prompt.
2660 # The testsuite is pretty-much hardwired to interpret $gdb_prompt as the
2662 regsub -all {[]*+.|()^$\[\\]} $prompt {\\&} prompt
2664 set saved $gdb_prompt
2666 verbose -log "Setting gdb prompt to \"$prompt \"."
2667 set gdb_prompt $prompt
2668 gdb_test_no_output "set prompt $prompt " ""
2670 set code [catch {uplevel 1 $body} result]
2672 verbose -log "Restoring gdb prompt to \"$saved \"."
2673 set gdb_prompt $saved
2674 gdb_test_no_output "set prompt $saved " ""
2677 global errorInfo errorCode
2678 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2680 return -code $code $result
2684 # Run tests in BODY with target-charset setting to TARGET_CHARSET. When
2685 # BODY is finished, restore target-charset.
2687 proc with_target_charset { target_charset body } {
2691 gdb_test_multiple "show target-charset" "" {
2692 -re "The target character set is \".*; currently (.*)\"\..*$gdb_prompt " {
2693 set saved $expect_out(1,string)
2695 -re "The target character set is \"(.*)\".*$gdb_prompt " {
2696 set saved $expect_out(1,string)
2698 -re ".*$gdb_prompt " {
2699 fail "get target-charset"
2703 gdb_test_no_output "set target-charset $target_charset" ""
2705 set code [catch {uplevel 1 $body} result]
2707 gdb_test_no_output "set target-charset $saved" ""
2710 global errorInfo errorCode
2711 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2713 return -code $code $result
2717 # Switch the default spawn id to SPAWN_ID, so that gdb_test,
2718 # mi_gdb_test etc. default to using it.
2720 proc switch_gdb_spawn_id {spawn_id} {
2722 global board board_info
2724 set gdb_spawn_id $spawn_id
2725 set board [host_info name]
2726 set board_info($board,fileid) $spawn_id
2729 # Clear the default spawn id.
2731 proc clear_gdb_spawn_id {} {
2733 global board board_info
2735 unset -nocomplain gdb_spawn_id
2736 set board [host_info name]
2737 unset -nocomplain board_info($board,fileid)
2740 # Run BODY with SPAWN_ID as current spawn id.
2742 proc with_spawn_id { spawn_id body } {
2745 if [info exists gdb_spawn_id] {
2746 set saved_spawn_id $gdb_spawn_id
2749 switch_gdb_spawn_id $spawn_id
2751 set code [catch {uplevel 1 $body} result]
2753 if [info exists saved_spawn_id] {
2754 switch_gdb_spawn_id $saved_spawn_id
2760 global errorInfo errorCode
2761 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2763 return -code $code $result
2767 # Select the largest timeout from all the timeouts:
2768 # - the local "timeout" variable of the scope two levels above,
2769 # - the global "timeout" variable,
2770 # - the board variable "gdb,timeout".
2772 proc get_largest_timeout {} {
2773 upvar #0 timeout gtimeout
2774 upvar 2 timeout timeout
2777 if [info exists timeout] {
2780 if { [info exists gtimeout] && $gtimeout > $tmt } {
2783 if { [target_info exists gdb,timeout]
2784 && [target_info gdb,timeout] > $tmt } {
2785 set tmt [target_info gdb,timeout]
2795 # Run tests in BODY with timeout increased by factor of FACTOR. When
2796 # BODY is finished, restore timeout.
2798 proc with_timeout_factor { factor body } {
2801 set savedtimeout $timeout
2803 set timeout [expr [get_largest_timeout] * $factor]
2804 set code [catch {uplevel 1 $body} result]
2806 set timeout $savedtimeout
2808 global errorInfo errorCode
2809 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2811 return -code $code $result
2815 # Run BODY with timeout factor FACTOR if check-read1 is used.
2817 proc with_read1_timeout_factor { factor body } {
2818 if { [info exists ::env(READ1)] == 1 && $::env(READ1) == 1 } {
2819 # Use timeout factor
2821 # Reset timeout factor
2824 return [uplevel [list with_timeout_factor $factor $body]]
2827 # Return 1 if _Complex types are supported, otherwise, return 0.
2829 gdb_caching_proc support_complex_tests {
2831 if { [gdb_skip_float_test] } {
2832 # If floating point is not supported, _Complex is not
2837 # Compile a test program containing _Complex types.
2839 return [gdb_can_simple_compile complex {
2843 _Complex long double cld;
2849 # Return 1 if compiling go is supported.
2850 gdb_caching_proc support_go_compile {
2852 return [gdb_can_simple_compile go-hello {
2856 fmt.Println("hello world")
2861 # Return 1 if GDB can get a type for siginfo from the target, otherwise
2864 proc supports_get_siginfo_type {} {
2865 if { [istarget "*-*-linux*"] } {
2872 # Return 1 if memory tagging is supported at runtime, otherwise return 0.
2874 gdb_caching_proc supports_memtag {
2877 gdb_test_multiple "memory-tag check" "" {
2878 -re "Memory tagging not supported or disabled by the current architecture\..*$gdb_prompt $" {
2881 -re "Argument required \\(address or pointer\\).*$gdb_prompt $" {
2888 # Return 1 if the target supports hardware single stepping.
2890 proc can_hardware_single_step {} {
2892 if { [istarget "arm*-*-*"] || [istarget "mips*-*-*"]
2893 || [istarget "tic6x-*-*"] || [istarget "sparc*-*-linux*"]
2894 || [istarget "nios2-*-*"] || [istarget "riscv*-*-linux*"] } {
2901 # Return 1 if target hardware or OS supports single stepping to signal
2902 # handler, otherwise, return 0.
2904 proc can_single_step_to_signal_handler {} {
2905 # Targets don't have hardware single step. On these targets, when
2906 # a signal is delivered during software single step, gdb is unable
2907 # to determine the next instruction addresses, because start of signal
2908 # handler is one of them.
2909 return [can_hardware_single_step]
2912 # Return 1 if target supports process record, otherwise return 0.
2914 proc supports_process_record {} {
2916 if [target_info exists gdb,use_precord] {
2917 return [target_info gdb,use_precord]
2920 if { [istarget "arm*-*-linux*"] || [istarget "x86_64-*-linux*"]
2921 || [istarget "i\[34567\]86-*-linux*"]
2922 || [istarget "aarch64*-*-linux*"]
2923 || [istarget "powerpc*-*-linux*"]
2924 || [istarget "s390*-*-linux*"] } {
2931 # Return 1 if target supports reverse debugging, otherwise return 0.
2933 proc supports_reverse {} {
2935 if [target_info exists gdb,can_reverse] {
2936 return [target_info gdb,can_reverse]
2939 if { [istarget "arm*-*-linux*"] || [istarget "x86_64-*-linux*"]
2940 || [istarget "i\[34567\]86-*-linux*"]
2941 || [istarget "aarch64*-*-linux*"]
2942 || [istarget "powerpc*-*-linux*"]
2943 || [istarget "s390*-*-linux*"] } {
2950 # Return 1 if readline library is used.
2952 proc readline_is_used { } {
2955 gdb_test_multiple "show editing" "" {
2956 -re ".*Editing of command lines as they are typed is on\..*$gdb_prompt $" {
2959 -re ".*$gdb_prompt $" {
2965 # Return 1 if target is ELF.
2966 gdb_caching_proc is_elf_target {
2967 set me "is_elf_target"
2969 set src { int foo () {return 0;} }
2970 if {![gdb_simple_compile elf_target $src]} {
2974 set fp_obj [open $obj "r"]
2975 fconfigure $fp_obj -translation binary
2976 set data [read $fp_obj]
2981 set ELFMAG "\u007FELF"
2983 if {[string compare -length 4 $data $ELFMAG] != 0} {
2984 verbose "$me: returning 0" 2
2988 verbose "$me: returning 1" 2
2992 # Return 1 if the memory at address zero is readable.
2994 gdb_caching_proc is_address_zero_readable {
2998 gdb_test_multiple "x 0" "" {
2999 -re "Cannot access memory at address 0x0.*$gdb_prompt $" {
3002 -re ".*$gdb_prompt $" {
3010 # Produce source file NAME and write SOURCES into it.
3012 proc gdb_produce_source { name sources } {
3014 set f [open $name "w"]
3020 # Return 1 if target is ILP32.
3021 # This cannot be decided simply from looking at the target string,
3022 # as it might depend on externally passed compiler options like -m64.
3023 gdb_caching_proc is_ilp32_target {
3024 return [gdb_can_simple_compile is_ilp32_target {
3025 int dummy[sizeof (int) == 4
3026 && sizeof (void *) == 4
3027 && sizeof (long) == 4 ? 1 : -1];
3031 # Return 1 if target is LP64.
3032 # This cannot be decided simply from looking at the target string,
3033 # as it might depend on externally passed compiler options like -m64.
3034 gdb_caching_proc is_lp64_target {
3035 return [gdb_can_simple_compile is_lp64_target {
3036 int dummy[sizeof (int) == 4
3037 && sizeof (void *) == 8
3038 && sizeof (long) == 8 ? 1 : -1];
3042 # Return 1 if target has 64 bit addresses.
3043 # This cannot be decided simply from looking at the target string,
3044 # as it might depend on externally passed compiler options like -m64.
3045 gdb_caching_proc is_64_target {
3046 return [gdb_can_simple_compile is_64_target {
3047 int function(void) { return 3; }
3048 int dummy[sizeof (&function) == 8 ? 1 : -1];
3052 # Return 1 if target has x86_64 registers - either amd64 or x32.
3053 # x32 target identifies as x86_64-*-linux*, therefore it cannot be determined
3054 # just from the target string.
3055 gdb_caching_proc is_amd64_regs_target {
3056 if {![istarget "x86_64-*-*"] && ![istarget "i?86-*"]} {
3060 return [gdb_can_simple_compile is_amd64_regs_target {
3070 # Return 1 if this target is an x86 or x86-64 with -m32.
3071 proc is_x86_like_target {} {
3072 if {![istarget "x86_64-*-*"] && ![istarget i?86-*]} {
3075 return [expr [is_ilp32_target] && ![is_amd64_regs_target]]
3078 # Return 1 if this target is an arm or aarch32 on aarch64.
3080 gdb_caching_proc is_aarch32_target {
3081 if { [istarget "arm*-*-*"] } {
3085 if { ![istarget "aarch64*-*-*"] } {
3092 lappend list "\tmov $reg, $reg"
3095 return [gdb_can_simple_compile aarch32 [join $list \n]]
3098 # Return 1 if this target is an aarch64, either lp64 or ilp32.
3100 proc is_aarch64_target {} {
3101 if { ![istarget "aarch64*-*-*"] } {
3105 return [expr ![is_aarch32_target]]
3108 # Return 1 if displaced stepping is supported on target, otherwise, return 0.
3109 proc support_displaced_stepping {} {
3111 if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"]
3112 || [istarget "arm*-*-linux*"] || [istarget "powerpc-*-linux*"]
3113 || [istarget "powerpc64-*-linux*"] || [istarget "s390*-*-*"]
3114 || [istarget "aarch64*-*-linux*"] } {
3121 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
3122 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
3124 gdb_caching_proc skip_altivec_tests {
3125 global srcdir subdir gdb_prompt inferior_exited_re
3127 set me "skip_altivec_tests"
3129 # Some simulators are known to not support VMX instructions.
3130 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
3131 verbose "$me: target known to not support VMX, returning 1" 2
3135 # Make sure we have a compiler that understands altivec.
3136 if [get_compiler_info] {
3137 warning "Could not get compiler info"
3140 if [test_compiler_info gcc*] {
3141 set compile_flags "additional_flags=-maltivec"
3142 } elseif [test_compiler_info xlc*] {
3143 set compile_flags "additional_flags=-qaltivec"
3145 verbose "Could not compile with altivec support, returning 1" 2
3149 # Compile a test program containing VMX instructions.
3153 asm volatile ("vor v0,v0,v0");
3155 asm volatile ("vor 0,0,0");
3160 if {![gdb_simple_compile $me $src executable $compile_flags]} {
3164 # Compilation succeeded so now run it via gdb.
3168 gdb_reinitialize_dir $srcdir/$subdir
3172 -re ".*Illegal instruction.*${gdb_prompt} $" {
3173 verbose -log "\n$me altivec hardware not detected"
3174 set skip_vmx_tests 1
3176 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
3177 verbose -log "\n$me: altivec hardware detected"
3178 set skip_vmx_tests 0
3181 warning "\n$me: default case taken"
3182 set skip_vmx_tests 1
3186 remote_file build delete $obj
3188 verbose "$me: returning $skip_vmx_tests" 2
3189 return $skip_vmx_tests
3192 # Run a test on the power target to see if it supports ISA 3.1 instructions
3193 gdb_caching_proc skip_power_isa_3_1_tests {
3194 global srcdir subdir gdb_prompt inferior_exited_re
3196 set me "skip_power_isa_3_1_tests"
3198 # Compile a test program containing ISA 3.1 instructions.
3201 asm volatile ("pnop"); // marker
3202 asm volatile ("nop");
3207 if {![gdb_simple_compile $me $src executable ]} {
3211 # No error message, compilation succeeded so now run it via gdb.
3215 gdb_reinitialize_dir $srcdir/$subdir
3219 -re ".*Illegal instruction.*${gdb_prompt} $" {
3220 verbose -log "\n$me Power ISA 3.1 hardware not detected"
3221 set skip_power_isa_3_1_tests 1
3223 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
3224 verbose -log "\n$me: Power ISA 3.1 hardware detected"
3225 set skip_power_isa_3_1_tests 0
3228 warning "\n$me: default case taken"
3229 set skip_power_isa_3_1_tests 1
3233 remote_file build delete $obj
3235 verbose "$me: returning $skip_power_isa_3_1_tests" 2
3236 return $skip_power_isa_3_1_tests
3239 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
3240 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
3242 gdb_caching_proc skip_vsx_tests {
3243 global srcdir subdir gdb_prompt inferior_exited_re
3245 set me "skip_vsx_tests"
3247 # Some simulators are known to not support Altivec instructions, so
3248 # they won't support VSX instructions as well.
3249 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
3250 verbose "$me: target known to not support VSX, returning 1" 2
3254 # Make sure we have a compiler that understands altivec.
3255 if [get_compiler_info] {
3256 warning "Could not get compiler info"
3259 if [test_compiler_info gcc*] {
3260 set compile_flags "additional_flags=-mvsx"
3261 } elseif [test_compiler_info xlc*] {
3262 set compile_flags "additional_flags=-qasm=gcc"
3264 verbose "Could not compile with vsx support, returning 1" 2
3268 # Compile a test program containing VSX instructions.
3271 double a[2] = { 1.0, 2.0 };
3273 asm volatile ("lxvd2x v0,v0,%[addr]" : : [addr] "r" (a));
3275 asm volatile ("lxvd2x 0,0,%[addr]" : : [addr] "r" (a));
3280 if {![gdb_simple_compile $me $src executable $compile_flags]} {
3284 # No error message, compilation succeeded so now run it via gdb.
3288 gdb_reinitialize_dir $srcdir/$subdir
3292 -re ".*Illegal instruction.*${gdb_prompt} $" {
3293 verbose -log "\n$me VSX hardware not detected"
3294 set skip_vsx_tests 1
3296 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
3297 verbose -log "\n$me: VSX hardware detected"
3298 set skip_vsx_tests 0
3301 warning "\n$me: default case taken"
3302 set skip_vsx_tests 1
3306 remote_file build delete $obj
3308 verbose "$me: returning $skip_vsx_tests" 2
3309 return $skip_vsx_tests
3312 # Run a test on the target to see if it supports TSX hardware. Return 0 if so,
3313 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
3315 gdb_caching_proc skip_tsx_tests {
3316 global srcdir subdir gdb_prompt inferior_exited_re
3318 set me "skip_tsx_tests"
3320 # Compile a test program.
3323 asm volatile ("xbegin .L0");
3324 asm volatile ("xend");
3325 asm volatile (".L0: nop");
3329 if {![gdb_simple_compile $me $src executable]} {
3333 # No error message, compilation succeeded so now run it via gdb.
3337 gdb_reinitialize_dir $srcdir/$subdir
3341 -re ".*Illegal instruction.*${gdb_prompt} $" {
3342 verbose -log "$me: TSX hardware not detected."
3343 set skip_tsx_tests 1
3345 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
3346 verbose -log "$me: TSX hardware detected."
3347 set skip_tsx_tests 0
3350 warning "\n$me: default case taken."
3351 set skip_tsx_tests 1
3355 remote_file build delete $obj
3357 verbose "$me: returning $skip_tsx_tests" 2
3358 return $skip_tsx_tests
3361 # Run a test on the target to see if it supports avx512bf16. Return 0 if so,
3362 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
3364 gdb_caching_proc skip_avx512bf16_tests {
3365 global srcdir subdir gdb_prompt inferior_exited_re
3367 set me "skip_avx512bf16_tests"
3368 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
3369 verbose "$me: target does not support avx512bf16, returning 1" 2
3373 # Compile a test program.
3376 asm volatile ("vcvtne2ps2bf16 %xmm0, %xmm1, %xmm0");
3380 if {![gdb_simple_compile $me $src executable]} {
3384 # No error message, compilation succeeded so now run it via gdb.
3388 gdb_reinitialize_dir $srcdir/$subdir
3392 -re ".*Illegal instruction.*${gdb_prompt} $" {
3393 verbose -log "$me: avx512bf16 hardware not detected."
3394 set skip_avx512bf16_tests 1
3396 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
3397 verbose -log "$me: avx512bf16 hardware detected."
3398 set skip_avx512bf16_tests 0
3401 warning "\n$me: default case taken."
3402 set skip_avx512bf16_tests 1
3406 remote_file build delete $obj
3408 verbose "$me: returning $skip_avx512bf16_tests" 2
3409 return $skip_avx512bf16_tests
3412 # Run a test on the target to see if it supports avx512fp16. Return 0 if so,
3413 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
3415 gdb_caching_proc skip_avx512fp16_tests {
3416 global srcdir subdir gdb_prompt inferior_exited_re
3418 set me "skip_avx512fp16_tests"
3419 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
3420 verbose "$me: target does not support avx512fp16, returning 1" 2
3424 # Compile a test program.
3427 asm volatile ("vcvtps2phx %xmm1, %xmm0");
3431 if {![gdb_simple_compile $me $src executable]} {
3435 # No error message, compilation succeeded so now run it via gdb.
3439 gdb_reinitialize_dir $srcdir/$subdir
3443 -re ".*Illegal instruction.*${gdb_prompt} $" {
3444 verbose -log "$me: avx512fp16 hardware not detected."
3445 set skip_avx512fp16_tests 1
3447 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
3448 verbose -log "$me: avx512fp16 hardware detected."
3449 set skip_avx512fp16_tests 0
3452 warning "\n$me: default case taken."
3453 set skip_avx512fp16_tests 1
3457 remote_file build delete $obj
3459 verbose "$me: returning $skip_avx512fp16_tests" 2
3460 return $skip_avx512fp16_tests
3463 # Run a test on the target to see if it supports btrace hardware. Return 0 if so,
3464 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
3466 gdb_caching_proc skip_btrace_tests {
3467 global srcdir subdir gdb_prompt inferior_exited_re
3469 set me "skip_btrace_tests"
3470 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
3471 verbose "$me: target does not support btrace, returning 1" 2
3475 # Compile a test program.
3476 set src { int main() { return 0; } }
3477 if {![gdb_simple_compile $me $src executable]} {
3481 # No error message, compilation succeeded so now run it via gdb.
3485 gdb_reinitialize_dir $srcdir/$subdir
3490 # In case of an unexpected output, we return 2 as a fail value.
3491 set skip_btrace_tests 2
3492 gdb_test_multiple "record btrace" "check btrace support" {
3493 -re "You can't do that when your target is.*\r\n$gdb_prompt $" {
3494 set skip_btrace_tests 1
3496 -re "Target does not support branch tracing.*\r\n$gdb_prompt $" {
3497 set skip_btrace_tests 1
3499 -re "Could not enable branch tracing.*\r\n$gdb_prompt $" {
3500 set skip_btrace_tests 1
3502 -re "^record btrace\r\n$gdb_prompt $" {
3503 set skip_btrace_tests 0
3507 remote_file build delete $obj
3509 verbose "$me: returning $skip_btrace_tests" 2
3510 return $skip_btrace_tests
3513 # Run a test on the target to see if it supports btrace pt hardware.
3514 # Return 0 if so, 1 if it does not. Based on 'check_vmx_hw_available'
3515 # from the GCC testsuite.
3517 gdb_caching_proc skip_btrace_pt_tests {
3518 global srcdir subdir gdb_prompt inferior_exited_re
3520 set me "skip_btrace_tests"
3521 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
3522 verbose "$me: target does not support btrace, returning 1" 2
3526 # Compile a test program.
3527 set src { int main() { return 0; } }
3528 if {![gdb_simple_compile $me $src executable]} {
3532 # No error message, compilation succeeded so now run it via gdb.
3536 gdb_reinitialize_dir $srcdir/$subdir
3541 # In case of an unexpected output, we return 2 as a fail value.
3542 set skip_btrace_tests 2
3543 gdb_test_multiple "record btrace pt" "check btrace pt support" {
3544 -re "You can't do that when your target is.*\r\n$gdb_prompt $" {
3545 set skip_btrace_tests 1
3547 -re "Target does not support branch tracing.*\r\n$gdb_prompt $" {
3548 set skip_btrace_tests 1
3550 -re "Could not enable branch tracing.*\r\n$gdb_prompt $" {
3551 set skip_btrace_tests 1
3553 -re "support was disabled at compile time.*\r\n$gdb_prompt $" {
3554 set skip_btrace_tests 1
3556 -re "^record btrace pt\r\n$gdb_prompt $" {
3557 set skip_btrace_tests 0
3561 remote_file build delete $obj
3563 verbose "$me: returning $skip_btrace_tests" 2
3564 return $skip_btrace_tests
3567 # Run a test on the target to see if it supports Aarch64 SVE hardware.
3568 # Return 0 if so, 1 if it does not. Note this causes a restart of GDB.
3570 gdb_caching_proc skip_aarch64_sve_tests {
3571 global srcdir subdir gdb_prompt inferior_exited_re
3573 set me "skip_aarch64_sve_tests"
3575 if { ![is_aarch64_target]} {
3579 set compile_flags "{additional_flags=-march=armv8-a+sve}"
3581 # Compile a test program containing SVE instructions.
3584 asm volatile ("ptrue p0.b");
3588 if {![gdb_simple_compile $me $src executable $compile_flags]} {
3592 # Compilation succeeded so now run it via gdb.
3596 -re ".*Illegal instruction.*${gdb_prompt} $" {
3597 verbose -log "\n$me sve hardware not detected"
3598 set skip_sve_tests 1
3600 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
3601 verbose -log "\n$me: sve hardware detected"
3602 set skip_sve_tests 0
3605 warning "\n$me: default case taken"
3606 set skip_sve_tests 1
3610 remote_file build delete $obj
3612 verbose "$me: returning $skip_sve_tests" 2
3613 return $skip_sve_tests
3617 # A helper that compiles a test case to see if __int128 is supported.
3618 proc gdb_int128_helper {lang} {
3619 return [gdb_can_simple_compile "i128-for-$lang" {
3621 int main() { return 0; }
3625 # Return true if the C compiler understands the __int128 type.
3626 gdb_caching_proc has_int128_c {
3627 return [gdb_int128_helper c]
3630 # Return true if the C++ compiler understands the __int128 type.
3631 gdb_caching_proc has_int128_cxx {
3632 return [gdb_int128_helper c++]
3635 # Return true if the IFUNC feature is unsupported.
3636 gdb_caching_proc skip_ifunc_tests {
3637 if [gdb_can_simple_compile ifunc {
3639 typedef void F (void);
3640 F* g (void) { return &f_; }
3641 void f () __attribute__ ((ifunc ("g")));
3649 # Return whether we should skip tests for showing inlined functions in
3650 # backtraces. Requires get_compiler_info and get_debug_format.
3652 proc skip_inline_frame_tests {} {
3653 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
3654 if { ! [test_debug_format "DWARF 2"] } {
3658 # GCC before 4.1 does not emit DW_AT_call_file / DW_AT_call_line.
3659 if { ([test_compiler_info "gcc-2-*"]
3660 || [test_compiler_info "gcc-3-*"]
3661 || [test_compiler_info "gcc-4-0-*"]) } {
3668 # Return whether we should skip tests for showing variables from
3669 # inlined functions. Requires get_compiler_info and get_debug_format.
3671 proc skip_inline_var_tests {} {
3672 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
3673 if { ! [test_debug_format "DWARF 2"] } {
3680 # Return a 1 if we should skip tests that require hardware breakpoints
3682 proc skip_hw_breakpoint_tests {} {
3683 # Skip tests if requested by the board (note that no_hardware_watchpoints
3684 # disables both watchpoints and breakpoints)
3685 if { [target_info exists gdb,no_hardware_watchpoints]} {
3689 # These targets support hardware breakpoints natively
3690 if { [istarget "i?86-*-*"]
3691 || [istarget "x86_64-*-*"]
3692 || [istarget "ia64-*-*"]
3693 || [istarget "arm*-*-*"]
3694 || [istarget "aarch64*-*-*"]
3695 || [istarget "s390*-*-*"] } {
3702 # Return a 1 if we should skip tests that require hardware watchpoints
3704 proc skip_hw_watchpoint_tests {} {
3705 # Skip tests if requested by the board
3706 if { [target_info exists gdb,no_hardware_watchpoints]} {
3710 # These targets support hardware watchpoints natively
3711 if { [istarget "i?86-*-*"]
3712 || [istarget "x86_64-*-*"]
3713 || [istarget "ia64-*-*"]
3714 || [istarget "arm*-*-*"]
3715 || [istarget "aarch64*-*-*"]
3716 || [istarget "powerpc*-*-linux*"]
3717 || [istarget "s390*-*-*"] } {
3724 # Return a 1 if we should skip tests that require *multiple* hardware
3725 # watchpoints to be active at the same time
3727 proc skip_hw_watchpoint_multi_tests {} {
3728 if { [skip_hw_watchpoint_tests] } {
3732 # These targets support just a single hardware watchpoint
3733 if { [istarget "arm*-*-*"]
3734 || [istarget "powerpc*-*-linux*"] } {
3741 # Return a 1 if we should skip tests that require read/access watchpoints
3743 proc skip_hw_watchpoint_access_tests {} {
3744 if { [skip_hw_watchpoint_tests] } {
3748 # These targets support just write watchpoints
3749 if { [istarget "s390*-*-*"] } {
3756 # Return 1 if we should skip tests that require the runtime unwinder
3757 # hook. This must be invoked while gdb is running, after shared
3758 # libraries have been loaded. This is needed because otherwise a
3759 # shared libgcc won't be visible.
3761 proc skip_unwinder_tests {} {
3765 gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook" {
3766 -re "= .*no debug info.*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
3768 -re "= .*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
3771 -re "No symbol .* in current context.\r\n$gdb_prompt $" {
3775 gdb_test_multiple "info probe" "check for stap probe in unwinder" {
3776 -re ".*libgcc.*unwind.*\r\n$gdb_prompt $" {
3779 -re "\r\n$gdb_prompt $" {
3786 # Return 1 if we should skip tests that require the libstdc++ stap
3787 # probes. This must be invoked while gdb is running, after shared
3788 # libraries have been loaded. PROMPT_REGEXP is the expected prompt.
3790 proc skip_libstdcxx_probe_tests_prompt { prompt_regexp } {
3792 gdb_test_multiple "info probe" "check for stap probe in libstdc++" \
3793 -prompt "$prompt_regexp" {
3794 -re ".*libstdcxx.*catch.*\r\n$prompt_regexp" {
3797 -re "\r\n$prompt_regexp" {
3800 set skip [expr !$supported]
3804 # As skip_libstdcxx_probe_tests_prompt, with gdb_prompt.
3806 proc skip_libstdcxx_probe_tests {} {
3808 return [skip_libstdcxx_probe_tests_prompt "$gdb_prompt $"]
3811 # Return 1 if we should skip tests of the "compile" feature.
3812 # This must be invoked after the inferior has been started.
3814 proc skip_compile_feature_tests {} {
3818 gdb_test_multiple "compile code -- ;" "check for working compile command" {
3819 "Could not load libcc1.*\r\n$gdb_prompt $" {
3822 -re "Command not supported on this host\\..*\r\n$gdb_prompt $" {
3825 -re "\r\n$gdb_prompt $" {
3831 # Helper for gdb_is_target_* procs. TARGET_NAME is the name of the target
3832 # we're looking for (used to build the test name). TARGET_STACK_REGEXP
3833 # is a regexp that will match the output of "maint print target-stack" if
3834 # the target in question is currently pushed. PROMPT_REGEXP is a regexp
3835 # matching the expected prompt after the command output.
3837 proc gdb_is_target_1 { target_name target_stack_regexp prompt_regexp } {
3838 set test "probe for target ${target_name}"
3839 gdb_test_multiple "maint print target-stack" $test \
3840 -prompt "$prompt_regexp" {
3841 -re "${target_stack_regexp}${prompt_regexp}" {
3845 -re "$prompt_regexp" {
3852 # Helper for gdb_is_target_remote where the expected prompt is variable.
3854 proc gdb_is_target_remote_prompt { prompt_regexp } {
3855 return [gdb_is_target_1 "remote" ".*emote serial target in gdb-specific protocol.*" $prompt_regexp]
3858 # Check whether we're testing with the remote or extended-remote
3861 proc gdb_is_target_remote { } {
3864 return [gdb_is_target_remote_prompt "$gdb_prompt $"]
3867 # Check whether we're testing with the native target.
3869 proc gdb_is_target_native { } {
3872 return [gdb_is_target_1 "native" ".*native \\(Native process\\).*" "$gdb_prompt $"]
3875 # Return the effective value of use_gdb_stub.
3877 # If the use_gdb_stub global has been set (it is set when the gdb process is
3878 # spawned), return that. Otherwise, return the value of the use_gdb_stub
3879 # property from the board file.
3881 # This is the preferred way of checking use_gdb_stub, since it allows to check
3882 # the value before the gdb has been spawned and it will return the correct value
3883 # even when it was overriden by the test.
3885 # Note that stub targets are not able to spawn new inferiors. Use this
3886 # check for skipping respective tests.
3888 proc use_gdb_stub {} {
3891 if [info exists use_gdb_stub] {
3892 return $use_gdb_stub
3895 return [target_info exists use_gdb_stub]
3898 # Return 1 if the current remote target is an instance of our GDBserver, 0
3899 # otherwise. Return -1 if there was an error and we can't tell.
3901 gdb_caching_proc target_is_gdbserver {
3905 set test "probing for GDBserver"
3907 gdb_test_multiple "monitor help" $test {
3908 -re "The following monitor commands are supported.*Quit GDBserver.*$gdb_prompt $" {
3911 -re "$gdb_prompt $" {
3916 if { $is_gdbserver == -1 } {
3917 verbose -log "Unable to tell whether we are using GDBserver or not."
3920 return $is_gdbserver
3923 # N.B. compiler_info is intended to be local to this file.
3924 # Call test_compiler_info with no arguments to fetch its value.
3925 # Yes, this is counterintuitive when there's get_compiler_info,
3926 # but that's the current API.
3927 if [info exists compiler_info] {
3933 # Figure out what compiler I am using.
3934 # The result is cached so only the first invocation runs the compiler.
3936 # ARG can be empty or "C++". If empty, "C" is assumed.
3938 # There are several ways to do this, with various problems.
3940 # [ gdb_compile -E $ifile -o $binfile.ci ]
3941 # source $binfile.ci
3943 # Single Unix Spec v3 says that "-E -o ..." together are not
3944 # specified. And in fact, the native compiler on hp-ux 11 (among
3945 # others) does not work with "-E -o ...". Most targets used to do
3946 # this, and it mostly worked, because it works with gcc.
3948 # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ]
3949 # source $binfile.ci
3951 # This avoids the problem with -E and -o together. This almost works
3952 # if the build machine is the same as the host machine, which is
3953 # usually true of the targets which are not gcc. But this code does
3954 # not figure which compiler to call, and it always ends up using the C
3955 # compiler. Not good for setting hp_aCC_compiler. Target
3956 # hppa*-*-hpux* used to do this.
3958 # [ gdb_compile -E $ifile > $binfile.ci ]
3959 # source $binfile.ci
3961 # dejagnu target_compile says that it supports output redirection,
3962 # but the code is completely different from the normal path and I
3963 # don't want to sweep the mines from that path. So I didn't even try
3966 # set cppout [ gdb_compile $ifile "" preprocess $args quiet ]
3969 # I actually do this for all targets now. gdb_compile runs the right
3970 # compiler, and TCL captures the output, and I eval the output.
3972 # Unfortunately, expect logs the output of the command as it goes by,
3973 # and dejagnu helpfully prints a second copy of it right afterwards.
3974 # So I turn off expect logging for a moment.
3976 # [ gdb_compile $ifile $ciexe_file executable $args ]
3977 # [ remote_exec $ciexe_file ]
3978 # [ source $ci_file.out ]
3980 # I could give up on -E and just do this.
3981 # I didn't get desperate enough to try this.
3983 # -- chastain 2004-01-06
3985 proc get_compiler_info {{arg ""}} {
3986 # For compiler.c and compiler.cc
3989 # I am going to play with the log to keep noise out.
3993 # These come from compiler.c or compiler.cc
3994 global compiler_info
3996 # Legacy global data symbols.
3999 if [info exists compiler_info] {
4004 # Choose which file to preprocess.
4005 set ifile "${srcdir}/lib/compiler.c"
4006 if { $arg == "c++" } {
4007 set ifile "${srcdir}/lib/compiler.cc"
4010 # Run $ifile through the right preprocessor.
4011 # Toggle gdb.log to keep the compiler output out of the log.
4012 set saved_log [log_file -info]
4014 if [is_remote host] {
4015 # We have to use -E and -o together, despite the comments
4016 # above, because of how DejaGnu handles remote host testing.
4017 set ppout "$outdir/compiler.i"
4018 gdb_compile "${ifile}" "$ppout" preprocess [list "$arg" quiet getting_compiler_info]
4019 set file [open $ppout r]
4020 set cppout [read $file]
4023 set cppout [ gdb_compile "${ifile}" "" preprocess [list "$arg" quiet getting_compiler_info] ]
4025 eval log_file $saved_log
4029 foreach cppline [ split "$cppout" "\n" ] {
4030 if { [ regexp "^#" "$cppline" ] } {
4032 } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } {
4034 } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } {
4036 verbose "get_compiler_info: $cppline" 2
4040 verbose -log "get_compiler_info: $cppline"
4045 # Set to unknown if for some reason compiler_info didn't get defined.
4046 if ![info exists compiler_info] {
4047 verbose -log "get_compiler_info: compiler_info not provided"
4048 set compiler_info "unknown"
4050 # Also set to unknown compiler if any diagnostics happened.
4052 verbose -log "get_compiler_info: got unexpected diagnostics"
4053 set compiler_info "unknown"
4056 # Set the legacy symbols.
4058 regexp "^gcc-(\[0-9\]+)-" "$compiler_info" matchall gcc_compiled
4060 # Log what happened.
4061 verbose -log "get_compiler_info: $compiler_info"
4063 # Most compilers will evaluate comparisons and other boolean
4064 # operations to 0 or 1.
4065 uplevel \#0 { set true 1 }
4066 uplevel \#0 { set false 0 }
4071 # Return the compiler_info string if no arg is provided.
4072 # Otherwise the argument is a glob-style expression to match against
4075 proc test_compiler_info { {compiler ""} } {
4076 global compiler_info
4079 # If no arg, return the compiler_info string.
4080 if [string match "" $compiler] {
4081 return $compiler_info
4084 return [string match $compiler $compiler_info]
4087 # Return the gcc major version, or -1.
4088 # For gcc 4.8.5, the major version is 4.8.
4089 # For gcc 7.5.0, the major version 7.
4091 proc gcc_major_version { } {
4092 global compiler_info
4094 if { ![test_compiler_info "gcc-*"] } {
4097 set res [regexp gcc-($decimal)-($decimal)- $compiler_info \
4098 dummy_var major minor]
4105 return $major.$minor
4108 proc current_target_name { } {
4110 if [info exists target_info(target,name)] {
4111 set answer $target_info(target,name)
4118 set gdb_wrapper_initialized 0
4119 set gdb_wrapper_target ""
4120 set gdb_wrapper_file ""
4121 set gdb_wrapper_flags ""
4123 proc gdb_wrapper_init { args } {
4124 global gdb_wrapper_initialized
4125 global gdb_wrapper_file
4126 global gdb_wrapper_flags
4127 global gdb_wrapper_target
4129 if { $gdb_wrapper_initialized == 1 } { return; }
4131 if {[target_info exists needs_status_wrapper] && \
4132 [target_info needs_status_wrapper] != "0"} {
4133 set result [build_wrapper "testglue.o"]
4134 if { $result != "" } {
4135 set gdb_wrapper_file [lindex $result 0]
4136 if ![is_remote host] {
4137 set gdb_wrapper_file [file join [pwd] $gdb_wrapper_file]
4139 set gdb_wrapper_flags [lindex $result 1]
4141 warning "Status wrapper failed to build."
4144 set gdb_wrapper_file ""
4145 set gdb_wrapper_flags ""
4147 verbose "set gdb_wrapper_file = $gdb_wrapper_file"
4148 set gdb_wrapper_initialized 1
4149 set gdb_wrapper_target [current_target_name]
4152 # Determine options that we always want to pass to the compiler.
4153 gdb_caching_proc universal_compile_options {
4154 set me "universal_compile_options"
4157 set src [standard_temp_file ccopts[pid].c]
4158 set obj [standard_temp_file ccopts[pid].o]
4160 gdb_produce_source $src {
4161 int foo(void) { return 0; }
4164 # Try an option for disabling colored diagnostics. Some compilers
4165 # yield colored diagnostics by default (when run from a tty) unless
4166 # such an option is specified.
4167 set opt "additional_flags=-fdiagnostics-color=never"
4168 set lines [target_compile $src $obj object [list "quiet" $opt]]
4169 if [string match "" $lines] then {
4170 # Seems to have worked; use the option.
4171 lappend options $opt
4176 verbose "$me: returning $options" 2
4180 # Compile the code in $code to a file based on $name, using the flags
4181 # $compile_flag as well as debug, nowarning and quiet.
4182 # Return 1 if code can be compiled
4183 # Leave the file name of the resulting object in the upvar object.
4185 proc gdb_simple_compile {name code {type object} {compile_flags {}} {object obj}} {
4188 switch -regexp -- $type {
4203 foreach flag $compile_flags {
4204 if { "$flag" == "go" } {
4209 set src [standard_temp_file $name-[pid].$ext]
4210 set obj [standard_temp_file $name-[pid].$postfix]
4211 set compile_flags [concat $compile_flags {debug nowarnings quiet}]
4213 gdb_produce_source $src $code
4215 verbose "$name: compiling testfile $src" 2
4216 set lines [gdb_compile $src $obj $type $compile_flags]
4220 if ![string match "" $lines] then {
4221 verbose "$name: compilation failed, returning 0" 2
4227 # Compile the code in $code to a file based on $name, using the flags
4228 # $compile_flag as well as debug, nowarning and quiet.
4229 # Return 1 if code can be compiled
4230 # Delete all created files and objects.
4232 proc gdb_can_simple_compile {name code {type object} {compile_flags ""}} {
4233 set ret [gdb_simple_compile $name $code $type $compile_flags temp_obj]
4234 file delete $temp_obj
4238 # Some targets need to always link a special object in. Save its path here.
4239 global gdb_saved_set_unbuffered_mode_obj
4240 set gdb_saved_set_unbuffered_mode_obj ""
4242 # Compile source files specified by SOURCE into a binary of type TYPE at path
4243 # DEST. gdb_compile is implemented using DejaGnu's target_compile, so the type
4244 # parameter and most options are passed directly to it.
4246 # The type can be one of the following:
4248 # - object: Compile into an object file.
4249 # - executable: Compile and link into an executable.
4250 # - preprocess: Preprocess the source files.
4251 # - assembly: Generate assembly listing.
4253 # The following options are understood and processed by gdb_compile:
4255 # - shlib=so_path: Add SO_PATH to the sources, and enable some target-specific
4256 # quirks to be able to use shared libraries.
4257 # - shlib_load: Link with appropriate libraries to allow the test to
4258 # dynamically load libraries at runtime. For example, on Linux, this adds
4259 # -ldl so that the test can use dlopen.
4260 # - nowarnings: Inhibit all compiler warnings.
4261 # - pie: Force creation of PIE executables.
4262 # - nopie: Prevent creation of PIE executables.
4264 # And here are some of the not too obscure options understood by DejaGnu that
4265 # influence the compilation:
4267 # - additional_flags=flag: Add FLAG to the compiler flags.
4268 # - libs=library: Add LIBRARY to the libraries passed to the linker. The
4269 # argument can be a file, in which case it's added to the sources, or a
4271 # - ldflags=flag: Add FLAG to the linker flags.
4272 # - incdir=path: Add PATH to the searched include directories.
4273 # - libdir=path: Add PATH to the linker searched directories.
4274 # - ada, c++, f77, f90, go, rust: Compile the file as Ada, C++,
4275 # Fortran 77, Fortran 90, Go or Rust.
4276 # - debug: Build with debug information.
4277 # - optimize: Build with optimization.
4279 proc gdb_compile {source dest type options} {
4280 global GDB_TESTCASE_OPTIONS
4281 global gdb_wrapper_file
4282 global gdb_wrapper_flags
4285 global gdb_saved_set_unbuffered_mode_obj
4287 set outdir [file dirname $dest]
4289 # Add platform-specific options if a shared library was specified using
4290 # "shlib=librarypath" in OPTIONS.
4292 if {[lsearch -exact $options rust] != -1} {
4293 # -fdiagnostics-color is not a rustcc option.
4295 set new_options [universal_compile_options]
4298 # Some C/C++ testcases unconditionally pass -Wno-foo as additional
4299 # options to disable some warning. That is OK with GCC, because
4300 # by design, GCC accepts any -Wno-foo option, even if it doesn't
4301 # support -Wfoo. Clang however warns about unknown -Wno-foo by
4302 # default, unless you pass -Wno-unknown-warning-option as well.
4303 # We do that here, so that individual testcases don't have to
4305 if {[lsearch -exact $options getting_compiler_info] == -1
4306 && [lsearch -exact $options rust] == -1
4307 && [lsearch -exact $options ada] == -1
4308 && [lsearch -exact $options f77] == -1
4309 && [lsearch -exact $options f90] == -1
4310 && [lsearch -exact $options go] == -1
4311 && [test_compiler_info "clang-*"]} {
4312 lappend new_options "additional_flags=-Wno-unknown-warning-option"
4315 # Treating .c input files as C++ is deprecated in Clang, so
4316 # explicitly force C++ language.
4317 if { [lsearch -exact $options getting_compiler_info] == -1
4318 && [lsearch -exact $options c++] != -1
4319 && [string match *.c $source] != 0 } {
4321 # gdb_compile cannot handle this combination of options, the
4322 # result is a command like "clang -x c++ foo.c bar.so -o baz"
4323 # which tells Clang to treat bar.so as C++. The solution is
4324 # to call gdb_compile twice--once to compile, once to link--
4325 # either directly, or via build_executable_from_specs.
4326 if { [lsearch $options shlib=*] != -1 } {
4327 error "incompatible gdb_compile options"
4330 if {[test_compiler_info "clang-*"]} {
4331 lappend new_options early_flags=-x\ c++
4335 # Place (and look for) Fortran `.mod` files in the output
4336 # directory for this specific test.
4337 if {[lsearch -exact $options f77] != -1 \
4338 || [lsearch -exact $options f90] != -1 } {
4340 set mod_path [standard_output_file ""]
4341 if [test_compiler_info "gcc-*"] {
4342 lappend new_options "additional_flags=-J${mod_path}"
4348 set getting_compiler_info 0
4349 foreach opt $options {
4350 if {[regexp {^shlib=(.*)} $opt dummy_var shlib_name]
4351 && $type == "executable"} {
4352 if [test_compiler_info "xlc-*"] {
4353 # IBM xlc compiler doesn't accept shared library named other
4354 # than .so: use "-Wl," to bypass this
4355 lappend source "-Wl,$shlib_name"
4356 } elseif { ([istarget "*-*-mingw*"]
4357 || [istarget *-*-cygwin*]
4358 || [istarget *-*-pe*])} {
4359 lappend source "${shlib_name}.a"
4361 lappend source $shlib_name
4363 if { $shlib_found == 0 } {
4365 if { ([istarget "*-*-mingw*"]
4366 || [istarget *-*-cygwin*]) } {
4367 lappend new_options "additional_flags=-Wl,--enable-auto-import"
4369 if { [test_compiler_info "gcc-*"] || [test_compiler_info "clang-*"] } {
4370 # Undo debian's change in the default.
4371 # Put it at the front to not override any user-provided
4372 # value, and to make sure it appears in front of all the
4374 lappend new_options "early_flags=-Wl,--no-as-needed"
4377 } elseif { $opt == "shlib_load" && $type == "executable" } {
4379 } elseif { $opt == "getting_compiler_info" } {
4380 # If this is set, calling test_compiler_info will cause recursion.
4381 set getting_compiler_info 1
4383 lappend new_options $opt
4387 # Ensure stack protector is disabled for GCC, as this causes problems with
4388 # DWARF line numbering.
4389 # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88432
4390 # This option defaults to on for Debian/Ubuntu.
4391 if { $getting_compiler_info == 0
4392 && [test_compiler_info {gcc-*-*}]
4393 && !([test_compiler_info {gcc-[0-3]-*}]
4394 || [test_compiler_info {gcc-4-0-*}])
4395 && [lsearch -exact $options rust] == -1} {
4396 # Put it at the front to not override any user-provided value.
4397 lappend new_options "early_flags=-fno-stack-protector"
4400 # Because we link with libraries using their basename, we may need
4401 # (depending on the platform) to set a special rpath value, to allow
4402 # the executable to find the libraries it depends on.
4403 if { $shlib_load || $shlib_found } {
4404 if { ([istarget "*-*-mingw*"]
4405 || [istarget *-*-cygwin*]
4406 || [istarget *-*-pe*]) } {
4407 # Do not need anything.
4408 } elseif { [istarget *-*-freebsd*] || [istarget *-*-openbsd*] } {
4409 lappend new_options "ldflags=-Wl,-rpath,${outdir}"
4411 if { $shlib_load } {
4412 lappend new_options "libs=-ldl"
4414 lappend new_options "ldflags=-Wl,-rpath,\\\$ORIGIN"
4417 set options $new_options
4419 if [info exists GDB_TESTCASE_OPTIONS] {
4420 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS"
4422 verbose "options are $options"
4423 verbose "source is $source $dest $type $options"
4427 if {[target_info exists needs_status_wrapper] && \
4428 [target_info needs_status_wrapper] != "0" && \
4429 $gdb_wrapper_file != "" } {
4430 lappend options "libs=${gdb_wrapper_file}"
4431 lappend options "ldflags=${gdb_wrapper_flags}"
4434 # Replace the "nowarnings" option with the appropriate additional_flags
4435 # to disable compiler warnings.
4436 set nowarnings [lsearch -exact $options nowarnings]
4437 if {$nowarnings != -1} {
4438 if [target_info exists gdb,nowarnings_flag] {
4439 set flag "additional_flags=[target_info gdb,nowarnings_flag]"
4441 set flag "additional_flags=-w"
4443 set options [lreplace $options $nowarnings $nowarnings $flag]
4446 # Replace the "pie" option with the appropriate compiler and linker flags
4447 # to enable PIE executables.
4448 set pie [lsearch -exact $options pie]
4450 if [target_info exists gdb,pie_flag] {
4451 set flag "additional_flags=[target_info gdb,pie_flag]"
4453 # For safety, use fPIE rather than fpie. On AArch64, m68k, PowerPC
4454 # and SPARC, fpie can cause compile errors due to the GOT exceeding
4455 # a maximum size. On other architectures the two flags are
4456 # identical (see the GCC manual). Note Debian9 and Ubuntu16.10
4457 # onwards default GCC to using fPIE. If you do require fpie, then
4458 # it can be set using the pie_flag.
4459 set flag "additional_flags=-fPIE"
4461 set options [lreplace $options $pie $pie $flag]
4463 if [target_info exists gdb,pie_ldflag] {
4464 set flag "ldflags=[target_info gdb,pie_ldflag]"
4466 set flag "ldflags=-pie"
4468 lappend options "$flag"
4471 # Replace the "nopie" option with the appropriate compiler and linker
4472 # flags to disable PIE executables.
4473 set nopie [lsearch -exact $options nopie]
4475 if [target_info exists gdb,nopie_flag] {
4476 set flag "additional_flags=[target_info gdb,nopie_flag]"
4478 set flag "additional_flags=-fno-pie"
4480 set options [lreplace $options $nopie $nopie $flag]
4482 if [target_info exists gdb,nopie_ldflag] {
4483 set flag "ldflags=[target_info gdb,nopie_ldflag]"
4485 set flag "ldflags=-no-pie"
4487 lappend options "$flag"
4490 if { $type == "executable" } {
4491 if { ([istarget "*-*-mingw*"]
4492 || [istarget "*-*-*djgpp"]
4493 || [istarget "*-*-cygwin*"])} {
4494 # Force output to unbuffered mode, by linking in an object file
4495 # with a global contructor that calls setvbuf.
4497 # Compile the special object separately for two reasons:
4498 # 1) Insulate it from $options.
4499 # 2) Avoid compiling it for every gdb_compile invocation,
4500 # which is time consuming, especially if we're remote
4503 if { $gdb_saved_set_unbuffered_mode_obj == "" } {
4504 verbose "compiling gdb_saved_set_unbuffered_obj"
4505 set unbuf_src ${srcdir}/lib/set_unbuffered_mode.c
4506 set unbuf_obj ${objdir}/set_unbuffered_mode.o
4508 set result [gdb_compile "${unbuf_src}" "${unbuf_obj}" object {nowarnings}]
4509 if { $result != "" } {
4512 if {[is_remote host]} {
4513 set gdb_saved_set_unbuffered_mode_obj set_unbuffered_mode_saved.o
4515 set gdb_saved_set_unbuffered_mode_obj ${objdir}/set_unbuffered_mode_saved.o
4517 # Link a copy of the output object, because the
4518 # original may be automatically deleted.
4519 remote_download host $unbuf_obj $gdb_saved_set_unbuffered_mode_obj
4521 verbose "gdb_saved_set_unbuffered_obj already compiled"
4524 # Rely on the internal knowledge that the global ctors are ran in
4525 # reverse link order. In that case, we can use ldflags to
4526 # avoid copying the object file to the host multiple
4528 # This object can only be added if standard libraries are
4529 # used. Thus, we need to disable it if -nostdlib option is used
4530 if {[lsearch -regexp $options "-nostdlib"] < 0 } {
4531 lappend options "ldflags=$gdb_saved_set_unbuffered_mode_obj"
4536 set result [target_compile $source $dest $type $options]
4538 # Prune uninteresting compiler (and linker) output.
4539 regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result
4541 regsub "\[\r\n\]*$" "$result" "" result
4542 regsub "^\[\r\n\]*" "$result" "" result
4544 if { $type == "executable" && $result == "" \
4545 && ($nopie != -1 || $pie != -1) } {
4546 set is_pie [exec_is_pie "$dest"]
4547 if { $nopie != -1 && $is_pie == 1 } {
4548 set result "nopie failed to prevent PIE executable"
4549 } elseif { $pie != -1 && $is_pie == 0 } {
4550 set result "pie failed to generate PIE executable"
4554 if {[lsearch $options quiet] < 0} {
4555 # We shall update this on a per language basis, to avoid
4556 # changing the entire testsuite in one go.
4557 if {[lsearch $options f77] >= 0} {
4558 gdb_compile_test $source $result
4559 } elseif { $result != "" } {
4560 clone_output "gdb compile failed, $result"
4567 # This is just like gdb_compile, above, except that it tries compiling
4568 # against several different thread libraries, to see which one this
4570 proc gdb_compile_pthreads {source dest type options} {
4571 if {$type != "executable"} {
4572 return [gdb_compile $source $dest $type $options]
4575 set why_msg "unrecognized error"
4576 foreach lib {-lpthreads -lpthread -lthread ""} {
4577 # This kind of wipes out whatever libs the caller may have
4578 # set. Or maybe theirs will override ours. How infelicitous.
4579 set options_with_lib [concat $options [list libs=$lib quiet]]
4580 set ccout [gdb_compile $source $dest $type $options_with_lib]
4581 switch -regexp -- $ccout {
4582 ".*no posix threads support.*" {
4583 set why_msg "missing threads include file"
4586 ".*cannot open -lpthread.*" {
4587 set why_msg "missing runtime threads library"
4589 ".*Can't find library for -lpthread.*" {
4590 set why_msg "missing runtime threads library"
4593 pass "successfully compiled posix threads test case"
4599 if {!$built_binfile} {
4600 unsupported "couldn't compile [file tail $source]: ${why_msg}"
4605 # Build a shared library from SOURCES.
4607 proc gdb_compile_shlib_1 {sources dest options} {
4608 set obj_options $options
4611 if { [lsearch -exact $options "ada"] >= 0 } {
4616 if { [lsearch -exact $options "c++"] >= 0 } {
4617 set info_options "c++"
4619 if [get_compiler_info ${info_options}] {
4623 switch -glob [test_compiler_info] {
4625 lappend obj_options "additional_flags=-qpic"
4628 if { [istarget "*-*-cygwin*"]
4629 || [istarget "*-*-mingw*"] } {
4630 lappend obj_options "additional_flags=-fPIC"
4632 lappend obj_options "additional_flags=-fpic"
4636 if { [istarget "powerpc*-*-aix*"]
4637 || [istarget "rs6000*-*-aix*"]
4638 || [istarget "*-*-cygwin*"]
4639 || [istarget "*-*-mingw*"]
4640 || [istarget "*-*-pe*"] } {
4641 lappend obj_options "additional_flags=-fPIC"
4643 lappend obj_options "additional_flags=-fpic"
4647 lappend obj_options "additional_flags=-fpic"
4650 # don't know what the compiler is...
4651 lappend obj_options "additional_flags=-fPIC"
4655 set outdir [file dirname $dest]
4657 foreach source $sources {
4658 if {[file extension $source] == ".o"} {
4659 # Already a .o file.
4660 lappend objects $source
4664 set sourcebase [file tail $source]
4667 # Gnatmake doesn't like object name foo.adb.o, use foo.o.
4668 set sourcebase [file rootname $sourcebase]
4670 set object ${outdir}/${sourcebase}.o
4673 # Use gdb_compile_ada_1 instead of gdb_compile_ada to avoid the
4675 if {[gdb_compile_ada_1 $source $object object \
4676 $obj_options] != ""} {
4680 if {[gdb_compile $source $object object \
4681 $obj_options] != ""} {
4686 lappend objects $object
4689 set link_options $options
4691 # If we try to use gnatmake for the link, it will interpret the
4692 # object file as an .adb file. Remove ada from the options to
4694 set idx [lsearch $link_options "ada"]
4695 set link_options [lreplace $link_options $idx $idx]
4697 if [test_compiler_info "xlc-*"] {
4698 lappend link_options "additional_flags=-qmkshrobj"
4700 lappend link_options "additional_flags=-shared"
4702 if { ([istarget "*-*-mingw*"]
4703 || [istarget *-*-cygwin*]
4704 || [istarget *-*-pe*]) } {
4705 if { [is_remote host] } {
4706 set name [file tail ${dest}]
4710 lappend link_options "additional_flags=-Wl,--out-implib,${name}.a"
4712 # Set the soname of the library. This causes the linker on ELF
4713 # systems to create the DT_NEEDED entry in the executable referring
4714 # to the soname of the library, and not its absolute path. This
4715 # (using the absolute path) would be problem when testing on a
4718 # In conjunction with setting the soname, we add the special
4719 # rpath=$ORIGIN value when building the executable, so that it's
4720 # able to find the library in its own directory.
4721 set destbase [file tail $dest]
4722 lappend link_options "additional_flags=-Wl,-soname,$destbase"
4725 if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
4728 if { [is_remote host]
4729 && ([istarget "*-*-mingw*"]
4730 || [istarget *-*-cygwin*]
4731 || [istarget *-*-pe*]) } {
4732 set dest_tail_name [file tail ${dest}]
4733 remote_upload host $dest_tail_name.a ${dest}.a
4734 remote_file host delete $dest_tail_name.a
4740 # Build a shared library from SOURCES. Ignore target boards PIE-related
4743 proc gdb_compile_shlib {sources dest options} {
4746 # Ignore PIE-related setting in multilib_flags.
4747 set board [target_info name]
4748 set multilib_flags_orig [board_info $board multilib_flags]
4749 set multilib_flags ""
4750 foreach op $multilib_flags_orig {
4751 if { $op == "-pie" || $op == "-no-pie" \
4752 || $op == "-fPIE" || $op == "-fno-PIE"} {
4754 append multilib_flags " $op"
4758 save_target_board_info { multilib_flags } {
4759 unset_board_info multilib_flags
4760 set_board_info multilib_flags "$multilib_flags"
4761 set result [gdb_compile_shlib_1 $sources $dest $options]
4767 # This is just like gdb_compile_shlib, above, except that it tries compiling
4768 # against several different thread libraries, to see which one this
4770 proc gdb_compile_shlib_pthreads {sources dest options} {
4772 set why_msg "unrecognized error"
4773 foreach lib {-lpthreads -lpthread -lthread ""} {
4774 # This kind of wipes out whatever libs the caller may have
4775 # set. Or maybe theirs will override ours. How infelicitous.
4776 set options_with_lib [concat $options [list libs=$lib quiet]]
4777 set ccout [gdb_compile_shlib $sources $dest $options_with_lib]
4778 switch -regexp -- $ccout {
4779 ".*no posix threads support.*" {
4780 set why_msg "missing threads include file"
4783 ".*cannot open -lpthread.*" {
4784 set why_msg "missing runtime threads library"
4786 ".*Can't find library for -lpthread.*" {
4787 set why_msg "missing runtime threads library"
4790 pass "successfully compiled posix threads shlib test case"
4796 if {!$built_binfile} {
4797 unsupported "couldn't compile $sources: ${why_msg}"
4802 # This is just like gdb_compile_pthreads, above, except that we always add the
4803 # objc library for compiling Objective-C programs
4804 proc gdb_compile_objc {source dest type options} {
4806 set why_msg "unrecognized error"
4807 foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} {
4808 # This kind of wipes out whatever libs the caller may have
4809 # set. Or maybe theirs will override ours. How infelicitous.
4810 if { $lib == "solaris" } {
4811 set lib "-lpthread -lposix4"
4813 if { $lib != "-lobjc" } {
4814 set lib "-lobjc $lib"
4816 set options_with_lib [concat $options [list libs=$lib quiet]]
4817 set ccout [gdb_compile $source $dest $type $options_with_lib]
4818 switch -regexp -- $ccout {
4819 ".*no posix threads support.*" {
4820 set why_msg "missing threads include file"
4823 ".*cannot open -lpthread.*" {
4824 set why_msg "missing runtime threads library"
4826 ".*Can't find library for -lpthread.*" {
4827 set why_msg "missing runtime threads library"
4830 pass "successfully compiled objc with posix threads test case"
4836 if {!$built_binfile} {
4837 unsupported "couldn't compile [file tail $source]: ${why_msg}"
4842 # Build an OpenMP program from SOURCE. See prefatory comment for
4843 # gdb_compile, above, for discussion of the parameters to this proc.
4845 proc gdb_compile_openmp {source dest type options} {
4846 lappend options "additional_flags=-fopenmp"
4847 return [gdb_compile $source $dest $type $options]
4850 # Send a command to GDB.
4851 # For options for TYPE see gdb_stdin_log_write
4853 proc send_gdb { string {type standard}} {
4854 gdb_stdin_log_write $string $type
4855 return [remote_send host "$string"]
4858 # Send STRING to the inferior's terminal.
4860 proc send_inferior { string } {
4861 global inferior_spawn_id
4863 if {[catch "send -i $inferior_spawn_id -- \$string" errorInfo]} {
4873 proc gdb_expect { args } {
4874 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
4875 set atimeout [lindex $args 0]
4876 set expcode [list [lindex $args 1]]
4881 # A timeout argument takes precedence, otherwise of all the timeouts
4882 # select the largest.
4883 if [info exists atimeout] {
4886 set tmt [get_largest_timeout]
4890 {uplevel remote_expect host $tmt $expcode} string]
4893 global errorInfo errorCode
4895 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
4897 return -code $code $string
4901 # gdb_expect_list TEST SENTINEL LIST -- expect a sequence of outputs
4903 # Check for long sequence of output by parts.
4904 # TEST: is the test message to be printed with the test success/fail.
4905 # SENTINEL: Is the terminal pattern indicating that output has finished.
4906 # LIST: is the sequence of outputs to match.
4907 # If the sentinel is recognized early, it is considered an error.
4910 # 1 if the test failed,
4911 # 0 if the test passes,
4912 # -1 if there was an internal error.
4914 proc gdb_expect_list {test sentinel list} {
4919 while { ${index} < [llength ${list}] } {
4920 set pattern [lindex ${list} ${index}]
4921 set index [expr ${index} + 1]
4922 verbose -log "gdb_expect_list pattern: /$pattern/" 2
4923 if { ${index} == [llength ${list}] } {
4926 -re "${pattern}${sentinel}" {
4927 # pass "${test}, pattern ${index} + sentinel"
4930 fail "${test} (pattern ${index} + sentinel)"
4933 -re ".*A problem internal to GDB has been detected" {
4934 fail "${test} (GDB internal error)"
4936 gdb_internal_error_resync
4939 fail "${test} (pattern ${index} + sentinel) (timeout)"
4944 # unresolved "${test}, pattern ${index} + sentinel"
4950 # pass "${test}, pattern ${index}"
4953 fail "${test} (pattern ${index})"
4956 -re ".*A problem internal to GDB has been detected" {
4957 fail "${test} (GDB internal error)"
4959 gdb_internal_error_resync
4962 fail "${test} (pattern ${index}) (timeout)"
4967 # unresolved "${test}, pattern ${index}"
4979 # Spawn the gdb process.
4981 # This doesn't expect any output or do any other initialization,
4982 # leaving those to the caller.
4984 # Overridable function -- you can override this function in your
4987 proc gdb_spawn { } {
4991 # Spawn GDB with CMDLINE_FLAGS appended to the GDBFLAGS global.
4993 proc gdb_spawn_with_cmdline_opts { cmdline_flags } {
4996 set saved_gdbflags $GDBFLAGS
4998 if {$GDBFLAGS != ""} {
5001 append GDBFLAGS $cmdline_flags
5005 set GDBFLAGS $saved_gdbflags
5010 # Start gdb running, wait for prompt, and disable the pagers.
5012 # Overridable function -- you can override this function in your
5015 proc gdb_start { } {
5020 catch default_gdb_exit
5023 # Return true if we can spawn a program on the target and attach to
5026 proc can_spawn_for_attach { } {
5027 # We use exp_pid to get the inferior's pid, assuming that gives
5028 # back the pid of the program. On remote boards, that would give
5029 # us instead the PID of e.g., the ssh client, etc.
5030 if [is_remote target] then {
5034 # The "attach" command doesn't make sense when the target is
5035 # stub-like, where GDB finds the program already started on
5036 # initial connection.
5037 if {[target_info exists use_gdb_stub]} {
5045 # Kill a progress previously started with spawn_wait_for_attach, and
5046 # reap its wait status. PROC_SPAWN_ID is the spawn id associated with
5049 proc kill_wait_spawned_process { proc_spawn_id } {
5050 set pid [exp_pid -i $proc_spawn_id]
5052 verbose -log "killing ${pid}"
5053 remote_exec build "kill -9 ${pid}"
5055 verbose -log "closing ${proc_spawn_id}"
5056 catch "close -i $proc_spawn_id"
5057 verbose -log "waiting for ${proc_spawn_id}"
5059 # If somehow GDB ends up still attached to the process here, a
5060 # blocking wait hangs until gdb is killed (or until gdb / the
5061 # ptracer reaps the exit status too, but that won't happen because
5062 # something went wrong.) Passing -nowait makes expect tell Tcl to
5063 # wait for the PID in the background. That's fine because we
5064 # don't care about the exit status. */
5065 wait -nowait -i $proc_spawn_id
5068 # Returns the process id corresponding to the given spawn id.
5070 proc spawn_id_get_pid { spawn_id } {
5071 set testpid [exp_pid -i $spawn_id]
5073 if { [istarget "*-*-cygwin*"] } {
5074 # testpid is the Cygwin PID, GDB uses the Windows PID, which
5075 # might be different due to the way fork/exec works.
5076 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
5082 # Start a set of programs running and then wait for a bit, to be sure
5083 # that they can be attached to. Return a list of processes spawn IDs,
5084 # one element for each process spawned. It's a test error to call
5085 # this when [can_spawn_for_attach] is false.
5087 proc spawn_wait_for_attach { executable_list } {
5088 set spawn_id_list {}
5090 if ![can_spawn_for_attach] {
5091 # The caller should have checked can_spawn_for_attach itself
5092 # before getting here.
5093 error "can't spawn for attach with this target/board"
5096 foreach {executable} $executable_list {
5097 # Note we use Expect's spawn, not Tcl's exec, because with
5098 # spawn we control when to wait for/reap the process. That
5099 # allows killing the process by PID without being subject to
5101 lappend spawn_id_list [remote_spawn target $executable]
5106 return $spawn_id_list
5110 # gdb_load_cmd -- load a file into the debugger.
5111 # ARGS - additional args to load command.
5112 # return a -1 if anything goes wrong.
5114 proc gdb_load_cmd { args } {
5117 if [target_info exists gdb_load_timeout] {
5118 set loadtimeout [target_info gdb_load_timeout]
5120 set loadtimeout 1600
5122 send_gdb "load $args\n"
5123 verbose "Timeout is now $loadtimeout seconds" 2
5124 gdb_expect $loadtimeout {
5125 -re "Loading section\[^\r\]*\r\n" {
5128 -re "Start address\[\r\]*\r\n" {
5131 -re "Transfer rate\[\r\]*\r\n" {
5134 -re "Memory access error\[^\r\]*\r\n" {
5135 perror "Failed to load program"
5138 -re "$gdb_prompt $" {
5141 -re "(.*)\r\n$gdb_prompt " {
5142 perror "Unexpected reponse from 'load' -- $expect_out(1,string)"
5146 perror "Timed out trying to load $args."
5153 # Invoke "gcore". CORE is the name of the core file to write. TEST
5154 # is the name of the test case. This will return 1 if the core file
5155 # was created, 0 otherwise. If this fails to make a core file because
5156 # this configuration of gdb does not support making core files, it
5157 # will call "unsupported", not "fail". However, if this fails to make
5158 # a core file for some other reason, then it will call "fail".
5160 proc gdb_gcore_cmd {core test} {
5164 gdb_test_multiple "gcore $core" $test {
5165 -re "Saved corefile .*\[\r\n\]+$gdb_prompt $" {
5169 -re "(?:Can't create a corefile|Target does not support core file generation\\.)\[\r\n\]+$gdb_prompt $" {
5177 # Load core file CORE. TEST is the name of the test case.
5178 # This will record a pass/fail for loading the core file.
5180 # 1 - core file is successfully loaded
5181 # 0 - core file loaded but has a non fatal error
5182 # -1 - core file failed to load
5184 proc gdb_core_cmd { core test } {
5187 gdb_test_multiple "core $core" "$test" {
5188 -re "\\\[Thread debugging using \[^ \r\n\]* enabled\\\]\r\n" {
5191 -re " is not a core dump:.*\r\n$gdb_prompt $" {
5192 fail "$test (bad file format)"
5195 -re -wrap "[string_to_regexp $core]: No such file or directory.*" {
5196 fail "$test (file not found)"
5199 -re "Couldn't find .* registers in core file.*\r\n$gdb_prompt $" {
5200 fail "$test (incomplete note section)"
5203 -re "Core was generated by .*\r\n$gdb_prompt $" {
5207 -re ".*$gdb_prompt $" {
5212 fail "$test (timeout)"
5216 fail "unsupported output from 'core' command"
5220 # Return the filename to download to the target and load on the target
5221 # for this shared library. Normally just LIBNAME, unless shared libraries
5222 # for this target have separate link and load images.
5224 proc shlib_target_file { libname } {
5228 # Return the filename GDB will load symbols from when debugging this
5229 # shared library. Normally just LIBNAME, unless shared libraries for
5230 # this target have separate link and load images.
5232 proc shlib_symbol_file { libname } {
5236 # Return the filename to download to the target and load for this
5237 # executable. Normally just BINFILE unless it is renamed to something
5238 # else for this target.
5240 proc exec_target_file { binfile } {
5244 # Return the filename GDB will load symbols from when debugging this
5245 # executable. Normally just BINFILE unless executables for this target
5246 # have separate files for symbols.
5248 proc exec_symbol_file { binfile } {
5252 # Rename the executable file. Normally this is just BINFILE1 being renamed
5253 # to BINFILE2, but some targets require multiple binary files.
5254 proc gdb_rename_execfile { binfile1 binfile2 } {
5255 file rename -force [exec_target_file ${binfile1}] \
5256 [exec_target_file ${binfile2}]
5257 if { [exec_target_file ${binfile1}] != [exec_symbol_file ${binfile1}] } {
5258 file rename -force [exec_symbol_file ${binfile1}] \
5259 [exec_symbol_file ${binfile2}]
5263 # "Touch" the executable file to update the date. Normally this is just
5264 # BINFILE, but some targets require multiple files.
5265 proc gdb_touch_execfile { binfile } {
5266 set time [clock seconds]
5267 file mtime [exec_target_file ${binfile}] $time
5268 if { [exec_target_file ${binfile}] != [exec_symbol_file ${binfile}] } {
5269 file mtime [exec_symbol_file ${binfile}] $time
5273 # Like remote_download but provides a gdb-specific behavior.
5275 # If the destination board is remote, the local file FROMFILE is transferred as
5276 # usual with remote_download to TOFILE on the remote board. The destination
5277 # filename is added to the CLEANFILES global, so it can be cleaned up at the
5280 # If the destination board is local, the destination path TOFILE is passed
5281 # through standard_output_file, and FROMFILE is copied there.
5283 # In both cases, if TOFILE is omitted, it defaults to the [file tail] of
5286 proc gdb_remote_download {dest fromfile {tofile {}}} {
5287 # If TOFILE is not given, default to the same filename as FROMFILE.
5288 if {[string length $tofile] == 0} {
5289 set tofile [file tail $fromfile]
5292 if {[is_remote $dest]} {
5293 # When the DEST is remote, we simply send the file to DEST.
5296 set destname [remote_download $dest $fromfile $tofile]
5297 lappend cleanfiles $destname
5301 # When the DEST is local, we copy the file to the test directory (where
5302 # the executable is).
5304 # Note that we pass TOFILE through standard_output_file, regardless of
5305 # whether it is absolute or relative, because we don't want the tests
5306 # to be able to write outside their standard output directory.
5308 set tofile [standard_output_file $tofile]
5310 file copy -force $fromfile $tofile
5316 # gdb_load_shlib LIB...
5318 # Copy the listed library to the target.
5320 proc gdb_load_shlib { file } {
5323 if ![info exists gdb_spawn_id] {
5324 perror "gdb_load_shlib: GDB is not running"
5327 set dest [gdb_remote_download target [shlib_target_file $file]]
5329 if {[is_remote target]} {
5330 # If the target is remote, we need to tell gdb where to find the
5333 # We could set this even when not testing remotely, but a user
5334 # generally won't set it unless necessary. In order to make the tests
5335 # more like the real-life scenarios, we don't set it for local testing.
5336 gdb_test "set solib-search-path [file dirname $file]" "" ""
5343 # gdb_load -- load a file into the debugger. Specifying no file
5344 # defaults to the executable currently being debugged.
5345 # The return value is 0 for success, -1 for failure.
5346 # Many files in config/*.exp override this procedure.
5348 proc gdb_load { arg } {
5350 return [gdb_file_cmd $arg]
5356 # with_complaints -- Execute BODY and set complaints temporary to N for the
5359 proc with_complaints { n body } {
5362 # Save current setting of complaints.
5364 set show_complaints_re \
5365 "Max number of complaints about incorrect symbols is ($decimal)\\."
5366 gdb_test_multiple "show complaints" "" {
5367 -re -wrap $show_complaints_re {
5368 set save $expect_out(1,string)
5372 if { $save == "" } {
5373 perror "Did not manage to set complaints"
5376 gdb_test_no_output "set complaints $n" ""
5379 set code [catch {uplevel 1 $body} result]
5381 # Restore saved setting of complaints.
5382 if { $save != "" } {
5383 gdb_test_no_output "set complaints $save" ""
5387 global errorInfo errorCode
5388 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
5390 return -code $code $result
5395 # gdb_load_no_complaints -- As gdb_load, but in addition verifies that
5396 # loading caused no symbol reading complaints.
5398 proc gdb_load_no_complaints { arg } {
5399 global gdb_prompt gdb_file_cmd_msg decimal
5401 # Temporarily set complaint to a small non-zero number.
5406 # Verify that there were no complaints.
5409 "^Reading symbols from \[^\r\n\]*" \
5410 "(Expanding full symbols from \[^\r\n\]*" \
5412 gdb_assert {[regexp $re $gdb_file_cmd_msg]} "No complaints"
5415 # gdb_reload -- load a file into the target. Called before "running",
5416 # either the first time or after already starting the program once,
5417 # for remote targets. Most files that override gdb_load should now
5418 # override this instead.
5420 # INFERIOR_ARGS contains the arguments to pass to the inferiors, as a
5421 # single string to get interpreted by a shell. If the target board
5422 # overriding gdb_reload is a "stub", then it should arrange things such
5423 # these arguments make their way to the inferior process.
5425 proc gdb_reload { {inferior_args {}} } {
5426 # For the benefit of existing configurations, default to gdb_load.
5427 # Specifying no file defaults to the executable currently being
5429 return [gdb_load ""]
5432 proc gdb_continue { function } {
5435 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"]
5438 # Default implementation of gdb_init.
5439 proc default_gdb_init { test_file_name } {
5440 global gdb_wrapper_initialized
5441 global gdb_wrapper_target
5442 global gdb_test_file_name
5446 # Reset the timeout value to the default. This way, any testcase
5447 # that changes the timeout value without resetting it cannot affect
5448 # the timeout used in subsequent testcases.
5449 global gdb_test_timeout
5451 set timeout $gdb_test_timeout
5453 if { [regexp ".*gdb\.reverse\/.*" $test_file_name]
5454 && [target_info exists gdb_reverse_timeout] } {
5455 set timeout [target_info gdb_reverse_timeout]
5458 # If GDB_INOTIFY is given, check for writes to '.'. This is a
5459 # debugging tool to help confirm that the test suite is
5460 # parallel-safe. You need "inotifywait" from the
5461 # inotify-tools package to use this.
5462 global GDB_INOTIFY inotify_pid
5463 if {[info exists GDB_INOTIFY] && ![info exists inotify_pid]} {
5464 global outdir tool inotify_log_file
5466 set exclusions {outputs temp gdb[.](log|sum) cache}
5467 set exclusion_re ([join $exclusions |])
5469 set inotify_log_file [standard_temp_file inotify.out]
5470 set inotify_pid [exec inotifywait -r -m -e move,create,delete . \
5471 --exclude $exclusion_re \
5472 |& tee -a $outdir/$tool.log $inotify_log_file &]
5474 # Wait for the watches; hopefully this is long enough.
5477 # Clear the log so that we don't emit a warning the first time
5479 set fd [open $inotify_log_file w]
5483 # Block writes to all banned variables, and invocation of all
5484 # banned procedures...
5485 global banned_variables
5486 global banned_procedures
5487 global banned_traced
5488 if (!$banned_traced) {
5489 foreach banned_var $banned_variables {
5490 global "$banned_var"
5491 trace add variable "$banned_var" write error
5493 foreach banned_proc $banned_procedures {
5494 global "$banned_proc"
5495 trace add execution "$banned_proc" enter error
5500 # We set LC_ALL, LC_CTYPE, and LANG to C so that we get the same
5501 # messages as expected.
5506 # Don't let a .inputrc file or an existing setting of INPUTRC mess
5507 # up the test results. Certain tests (style tests and TUI tests)
5508 # want to set the terminal to a non-"dumb" value, and for those we
5509 # want to disable bracketed paste mode. Versions of Readline
5510 # before 8.0 will not understand this and will issue a warning.
5511 # We tried using a $if to guard it, but Readline 8.1 had a bug in
5512 # its version-comparison code that prevented this for working.
5513 setenv INPUTRC [cached_file inputrc "set enable-bracketed-paste off"]
5515 # This disables style output, which would interfere with many
5519 # If DEBUGINFOD_URLS is set, gdb will try to download sources and
5520 # debug info for f.i. system libraries. Prevent this.
5521 unset -nocomplain ::env(DEBUGINFOD_URLS)
5523 # Ensure that GDBHISTFILE and GDBHISTSIZE are removed from the
5524 # environment, we don't want these modifications to the history
5526 unset -nocomplain ::env(GDBHISTFILE)
5527 unset -nocomplain ::env(GDBHISTSIZE)
5529 # Ensure that XDG_CONFIG_HOME is not set. Some tests setup a fake
5530 # home directory in order to test loading settings from gdbinit.
5531 # If XDG_CONFIG_HOME is set then GDB will load a gdbinit from
5532 # there (if one is present) rather than the home directory setup
5534 unset -nocomplain ::env(XDG_CONFIG_HOME)
5536 # Initialize GDB's pty with a fixed size, to make sure we avoid pagination
5537 # during startup. See "man expect" for details about stty_init.
5539 set stty_init "rows 25 cols 80"
5541 # Some tests (for example gdb.base/maint.exp) shell out from gdb to use
5542 # grep. Clear GREP_OPTIONS to make the behavior predictable,
5543 # especially having color output turned on can cause tests to fail.
5544 setenv GREP_OPTIONS ""
5546 # Clear $gdbserver_reconnect_p.
5547 global gdbserver_reconnect_p
5548 set gdbserver_reconnect_p 1
5549 unset gdbserver_reconnect_p
5551 # Clear $last_loaded_file
5552 global last_loaded_file
5553 unset -nocomplain last_loaded_file
5555 # Reset GDB number of instances
5556 global gdb_instances
5561 set gdb_test_file_name [file rootname [file tail $test_file_name]]
5563 # Make sure that the wrapper is rebuilt
5564 # with the appropriate multilib option.
5565 if { $gdb_wrapper_target != [current_target_name] } {
5566 set gdb_wrapper_initialized 0
5569 # Unlike most tests, we have a small number of tests that generate
5570 # a very large amount of output. We therefore increase the expect
5571 # buffer size to be able to contain the entire test output. This
5572 # is especially needed by gdb.base/info-macros.exp.
5574 # Also set this value for the currently running GDB.
5575 match_max [match_max -d]
5577 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
5578 set pf_prefix "[file tail [file dirname $test_file_name]]/[file tail $test_file_name]:"
5581 if [target_info exists gdb_prompt] {
5582 set gdb_prompt [target_info gdb_prompt]
5584 set gdb_prompt "\\(gdb\\)"
5587 if [info exists use_gdb_stub] {
5591 gdb_setup_known_globals
5593 if { [info procs ::gdb_tcl_unknown] != "" } {
5594 # Dejagnu overrides proc unknown. The dejagnu version may trigger in a
5595 # test-case but abort the entire test run. To fix this, we install a
5596 # local version here, which reverts dejagnu's override, and restore
5597 # dejagnu's version in gdb_finish.
5598 rename ::unknown ::dejagnu_unknown
5599 proc unknown { args } {
5600 # Use tcl's unknown.
5601 set cmd [lindex $args 0]
5602 unresolved "testcase aborted due to invalid command name: $cmd"
5603 return [uplevel 1 ::gdb_tcl_unknown $args]
5608 # Return a path using GDB_PARALLEL.
5609 # ARGS is a list of path elements to append to "$objdir/$GDB_PARALLEL".
5610 # GDB_PARALLEL must be defined, the caller must check.
5612 # The default value for GDB_PARALLEL is, canonically, ".".
5613 # The catch is that tests don't expect an additional "./" in file paths so
5614 # omit any directory for the default case.
5615 # GDB_PARALLEL is written as "yes" for the default case in Makefile.in to mark
5616 # its special handling.
5618 proc make_gdb_parallel_path { args } {
5619 global GDB_PARALLEL objdir
5620 set joiner [list "file" "join" $objdir]
5621 if { [info exists GDB_PARALLEL] && $GDB_PARALLEL != "yes" } {
5622 lappend joiner $GDB_PARALLEL
5624 set joiner [concat $joiner $args]
5625 return [eval $joiner]
5628 # Turn BASENAME into a full file name in the standard output
5629 # directory. It is ok if BASENAME is the empty string; in this case
5630 # the directory is returned.
5632 proc standard_output_file {basename} {
5633 global objdir subdir gdb_test_file_name
5635 set dir [make_gdb_parallel_path outputs $subdir $gdb_test_file_name]
5637 # If running on MinGW, replace /c/foo with c:/foo
5638 if { [ishost *-*-mingw*] } {
5639 set dir [exec sh -c "cd ${dir} && pwd -W"]
5641 return [file join $dir $basename]
5644 # Turn BASENAME into a full file name in the standard output directory. If
5645 # GDB has been launched more than once then append the count, starting with
5648 proc standard_output_file_with_gdb_instance {basename} {
5649 global gdb_instances
5650 set count $gdb_instances
5653 return [standard_output_file $basename]
5655 return [standard_output_file ${basename}.${count}]
5658 # Return the name of a file in our standard temporary directory.
5660 proc standard_temp_file {basename} {
5661 # Since a particular runtest invocation is only executing a single test
5662 # file at any given time, we can use the runtest pid to build the
5663 # path of the temp directory.
5664 set dir [make_gdb_parallel_path temp [pid]]
5666 return [file join $dir $basename]
5669 # Rename file A to file B, if B does not already exists. Otherwise, leave B
5670 # as is and delete A. Return 1 if rename happened.
5672 proc tentative_rename { a b } {
5673 global errorInfo errorCode
5674 set code [catch {file rename -- $a $b} result]
5675 if { $code == 1 && [lindex $errorCode 0] == "POSIX" \
5676 && [lindex $errorCode 1] == "EEXIST" } {
5681 return -code error -errorinfo $errorInfo -errorcode $errorCode $result
5682 } elseif {$code > 1} {
5683 return -code $code $result
5688 # Create a file with name FILENAME and contents TXT in the cache directory.
5689 # If EXECUTABLE, mark the new file for execution.
5691 proc cached_file { filename txt {executable 0}} {
5692 set filename [make_gdb_parallel_path cache $filename]
5694 if { [file exists $filename] } {
5698 set dir [file dirname $filename]
5701 set tmp_filename $filename.[pid]
5702 set fd [open $tmp_filename w]
5706 if { $executable } {
5707 exec chmod +x $tmp_filename
5709 tentative_rename $tmp_filename $filename
5714 # Set 'testfile', 'srcfile', and 'binfile'.
5716 # ARGS is a list of source file specifications.
5717 # Without any arguments, the .exp file's base name is used to
5718 # compute the source file name. The ".c" extension is added in this case.
5719 # If ARGS is not empty, each entry is a source file specification.
5720 # If the specification starts with a "." or "-", it is treated as a suffix
5721 # to append to the .exp file's base name.
5722 # If the specification is the empty string, it is treated as if it
5724 # Otherwise it is a file name.
5725 # The first file in the list is used to set the 'srcfile' global.
5726 # Each subsequent name is used to set 'srcfile2', 'srcfile3', etc.
5728 # Most tests should call this without arguments.
5730 # If a completely different binary file name is needed, then it
5731 # should be handled in the .exp file with a suitable comment.
5733 proc standard_testfile {args} {
5734 global gdb_test_file_name
5736 global gdb_test_file_last_vars
5739 global testfile binfile
5741 set testfile $gdb_test_file_name
5742 set binfile [standard_output_file ${testfile}]
5744 if {[llength $args] == 0} {
5748 # Unset our previous output variables.
5749 # This can help catch hidden bugs.
5750 if {[info exists gdb_test_file_last_vars]} {
5751 foreach varname $gdb_test_file_last_vars {
5753 catch {unset $varname}
5756 # 'executable' is often set by tests.
5757 set gdb_test_file_last_vars {executable}
5761 set varname srcfile$suffix
5764 # Handle an extension.
5768 set first [string range $arg 0 0]
5769 if { $first == "." || $first == "-" } {
5770 set arg $testfile$arg
5775 lappend gdb_test_file_last_vars $varname
5777 if {$suffix == ""} {
5785 # The default timeout used when testing GDB commands. We want to use
5786 # the same timeout as the default dejagnu timeout, unless the user has
5787 # already provided a specific value (probably through a site.exp file).
5788 global gdb_test_timeout
5789 if ![info exists gdb_test_timeout] {
5790 set gdb_test_timeout $timeout
5793 # A list of global variables that GDB testcases should not use.
5794 # We try to prevent their use by monitoring write accesses and raising
5795 # an error when that happens.
5796 set banned_variables { bug_id prms_id }
5798 # A list of procedures that GDB testcases should not use.
5799 # We try to prevent their use by monitoring invocations and raising
5800 # an error when that happens.
5801 set banned_procedures { strace }
5803 # gdb_init is called by runtest at start, but also by several
5804 # tests directly; gdb_finish is only called from within runtest after
5805 # each test source execution.
5806 # Placing several traces by repetitive calls to gdb_init leads
5807 # to problems, as only one trace is removed in gdb_finish.
5808 # To overcome this possible problem, we add a variable that records
5809 # if the banned variables and procedures are already traced.
5812 # Global array that holds the name of all global variables at the time
5813 # a test script is started. After the test script has completed any
5814 # global not in this list is deleted.
5815 array set gdb_known_globals {}
5817 # Setup the GDB_KNOWN_GLOBALS array with the names of all current
5819 proc gdb_setup_known_globals {} {
5820 global gdb_known_globals
5822 array set gdb_known_globals {}
5823 foreach varname [info globals] {
5824 set gdb_known_globals($varname) 1
5828 # Cleanup the global namespace. Any global not in the
5829 # GDB_KNOWN_GLOBALS array is unset, this ensures we don't "leak"
5830 # globals from one test script to another.
5831 proc gdb_cleanup_globals {} {
5832 global gdb_known_globals gdb_persistent_globals
5834 foreach varname [info globals] {
5835 if {![info exists gdb_known_globals($varname)]} {
5836 if { [info exists gdb_persistent_globals($varname)] } {
5839 uplevel #0 unset $varname
5844 # Create gdb_tcl_unknown, a copy tcl's ::unknown, provided it's present as a
5846 set temp [interp create]
5847 if { [interp eval $temp "info procs ::unknown"] != "" } {
5848 set old_args [interp eval $temp "info args ::unknown"]
5849 set old_body [interp eval $temp "info body ::unknown"]
5850 eval proc gdb_tcl_unknown {$old_args} {$old_body}
5855 # GDB implementation of ${tool}_init. Called right before executing the
5857 # Overridable function -- you can override this function in your
5859 proc gdb_init { args } {
5860 # A baseboard file overriding this proc and calling the default version
5861 # should behave the same as this proc. So, don't add code here, but to
5862 # the default version instead.
5863 return [default_gdb_init {*}$args]
5866 # GDB implementation of ${tool}_finish. Called right after executing the
5868 proc gdb_finish { } {
5869 global gdbserver_reconnect_p
5872 global known_globals
5874 if { [info procs ::gdb_tcl_unknown] != "" } {
5875 # Restore dejagnu's version of proc unknown.
5877 rename ::dejagnu_unknown ::unknown
5880 # Exit first, so that the files are no longer in use.
5883 if { [llength $cleanfiles] > 0 } {
5884 eval remote_file target delete $cleanfiles
5888 # Unblock write access to the banned variables. Dejagnu typically
5889 # resets some of them between testcases.
5890 global banned_variables
5891 global banned_procedures
5892 global banned_traced
5893 if ($banned_traced) {
5894 foreach banned_var $banned_variables {
5895 global "$banned_var"
5896 trace remove variable "$banned_var" write error
5898 foreach banned_proc $banned_procedures {
5899 global "$banned_proc"
5900 trace remove execution "$banned_proc" enter error
5905 global gdb_finish_hooks
5906 foreach gdb_finish_hook $gdb_finish_hooks {
5909 set gdb_finish_hooks [list]
5915 set debug_format "unknown"
5917 # Run the gdb command "info source" and extract the debugging format
5918 # information from the output and save it in debug_format.
5920 proc get_debug_format { } {
5925 set debug_format "unknown"
5926 send_gdb "info source\n"
5928 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
5929 set debug_format $expect_out(1,string)
5930 verbose "debug format is $debug_format"
5933 -re "No current source file.\r\n$gdb_prompt $" {
5934 perror "get_debug_format used when no current source file"
5937 -re "$gdb_prompt $" {
5938 warning "couldn't check debug format (no valid response)."
5942 warning "couldn't check debug format (timeout)."
5948 # Return true if FORMAT matches the debug format the current test was
5949 # compiled with. FORMAT is a shell-style globbing pattern; it can use
5950 # `*', `[...]', and so on.
5952 # This function depends on variables set by `get_debug_format', above.
5954 proc test_debug_format {format} {
5957 return [expr [string match $format $debug_format] != 0]
5960 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
5961 # COFF, stabs, etc). If that format matches the format that the
5962 # current test was compiled with, then the next test is expected to
5963 # fail for any target. Returns 1 if the next test or set of tests is
5964 # expected to fail, 0 otherwise (or if it is unknown). Must have
5965 # previously called get_debug_format.
5966 proc setup_xfail_format { format } {
5967 set ret [test_debug_format $format]
5975 # gdb_get_line_number TEXT [FILE]
5977 # Search the source file FILE, and return the line number of the
5978 # first line containing TEXT. If no match is found, an error is thrown.
5980 # TEXT is a string literal, not a regular expression.
5982 # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is
5983 # specified, and does not start with "/", then it is assumed to be in
5984 # "$srcdir/$subdir". This is awkward, and can be fixed in the future,
5985 # by changing the callers and the interface at the same time.
5986 # In particular: gdb.base/break.exp, gdb.base/condbreak.exp,
5987 # gdb.base/ena-dis-br.exp.
5989 # Use this function to keep your test scripts independent of the
5990 # exact line numbering of the source file. Don't write:
5992 # send_gdb "break 20"
5994 # This means that if anyone ever edits your test's source file,
5995 # your test could break. Instead, put a comment like this on the
5996 # source file line you want to break at:
5998 # /* breakpoint spot: frotz.exp: test name */
6000 # and then write, in your test script (which we assume is named
6003 # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
6005 # (Yes, Tcl knows how to handle the nested quotes and brackets.
6008 # % puts "foo [lindex "bar baz" 1]"
6011 # Tcl is quite clever, for a little stringy language.)
6015 # The previous implementation of this procedure used the gdb search command.
6016 # This version is different:
6018 # . It works with MI, and it also works when gdb is not running.
6020 # . It operates on the build machine, not the host machine.
6022 # . For now, this implementation fakes a current directory of
6023 # $srcdir/$subdir to be compatible with the old implementation.
6024 # This will go away eventually and some callers will need to
6027 # . The TEXT argument is literal text and matches literally,
6028 # not a regular expression as it was before.
6030 # . State changes in gdb, such as changing the current file
6031 # and setting $_, no longer happen.
6033 # After a bit of time we can forget about the differences from the
6034 # old implementation.
6036 # --chastain 2004-08-05
6038 proc gdb_get_line_number { text { file "" } } {
6043 if { "$file" == "" } then {
6046 if { ! [regexp "^/" "$file"] } then {
6047 set file "$srcdir/$subdir/$file"
6050 if { [ catch { set fd [open "$file"] } message ] } then {
6055 for { set line 1 } { 1 } { incr line } {
6056 if { [ catch { set nchar [gets "$fd" body] } message ] } then {
6059 if { $nchar < 0 } then {
6062 if { [string first "$text" "$body"] >= 0 } then {
6068 if { [ catch { close "$fd" } message ] } then {
6073 error "undefined tag \"$text\""
6079 # Continue the program until it ends.
6081 # MSSG is the error message that gets printed. If not given, a
6083 # COMMAND is the command to invoke. If not given, "continue" is
6085 # ALLOW_EXTRA is a flag indicating whether the test should expect
6086 # extra output between the "Continuing." line and the program
6087 # exiting. By default it is zero; if nonzero, any extra output
6090 proc gdb_continue_to_end {{mssg ""} {command continue} {allow_extra 0}} {
6091 global inferior_exited_re use_gdb_stub
6094 set text "continue until exit"
6096 set text "continue until exit at $mssg"
6104 # By default, we don't rely on exit() behavior of remote stubs --
6105 # it's common for exit() to be implemented as a simple infinite
6106 # loop, or a forced crash/reset. For native targets, by default, we
6107 # assume process exit is reported as such. If a non-reliable target
6108 # is used, we set a breakpoint at exit, and continue to that.
6109 if { [target_info exists exit_is_reliable] } {
6110 set exit_is_reliable [target_info exit_is_reliable]
6112 set exit_is_reliable [expr ! $use_gdb_stub]
6115 if { ! $exit_is_reliable } {
6116 if {![gdb_breakpoint "exit"]} {
6119 gdb_test $command "Continuing..*Breakpoint .*exit.*" \
6122 # Continue until we exit. Should not stop again.
6123 # Don't bother to check the output of the program, that may be
6124 # extremely tough for some remote systems.
6126 "Continuing.\[\r\n0-9\]+${extra}(... EXIT code 0\[\r\n\]+|$inferior_exited_re normally).*"\
6131 proc rerun_to_main {} {
6132 global gdb_prompt use_gdb_stub
6137 -re ".*Breakpoint .*main .*$gdb_prompt $"\
6138 {pass "rerun to main" ; return 0}
6139 -re "$gdb_prompt $"\
6140 {fail "rerun to main" ; return 0}
6141 timeout {fail "(timeout) rerun to main" ; return 0}
6146 -re "The program .* has been started already.*y or n. $" {
6147 send_gdb "y\n" answer
6150 -re "Starting program.*$gdb_prompt $"\
6151 {pass "rerun to main" ; return 0}
6152 -re "$gdb_prompt $"\
6153 {fail "rerun to main" ; return 0}
6154 timeout {fail "(timeout) rerun to main" ; return 0}
6159 # Return true if EXECUTABLE contains a .gdb_index or .debug_names index section.
6161 proc exec_has_index_section { executable } {
6162 set readelf_program [gdb_find_readelf]
6163 set res [catch {exec $readelf_program -S $executable \
6164 | grep -E "\.gdb_index|\.debug_names" }]
6171 # Return list with major and minor version of readelf, or an empty list.
6172 gdb_caching_proc readelf_version {
6173 set readelf_program [gdb_find_readelf]
6174 set res [catch {exec $readelf_program --version} output]
6178 set lines [split $output \n]
6179 set line [lindex $lines 0]
6180 set res [regexp {[ \t]+([0-9]+)[.]([0-9]+)[^ \t]*$} \
6181 $line dummy major minor]
6185 return [list $major $minor]
6188 # Return 1 if readelf prints the PIE flag, 0 if is doesn't, and -1 if unknown.
6189 proc readelf_prints_pie { } {
6190 set version [readelf_version]
6191 if { [llength $version] == 0 } {
6194 set major [lindex $version 0]
6195 set minor [lindex $version 1]
6196 # It would be better to construct a PIE executable and test if the PIE
6197 # flag is printed by readelf, but we cannot reliably construct a PIE
6198 # executable if the multilib_flags dictate otherwise
6199 # (--target_board=unix/-no-pie/-fno-PIE).
6200 return [version_at_least $major $minor 2 26]
6203 # Return 1 if EXECUTABLE is a Position Independent Executable, 0 if it is not,
6204 # and -1 if unknown.
6206 proc exec_is_pie { executable } {
6207 set res [readelf_prints_pie]
6211 set readelf_program [gdb_find_readelf]
6212 # We're not testing readelf -d | grep "FLAGS_1.*Flags:.*PIE"
6213 # because the PIE flag is not set by all versions of gold, see PR
6215 set res [catch {exec $readelf_program -h $executable} output]
6219 set res [regexp -line {^[ \t]*Type:[ \t]*DYN \((Position-Independent Executable|Shared object) file\)$} \
6227 # Return true if a test should be skipped due to lack of floating
6228 # point support or GDB can't fetch the contents from floating point
6231 gdb_caching_proc gdb_skip_float_test {
6232 if [target_info exists gdb,skip_float_tests] {
6236 # There is an ARM kernel ptrace bug that hardware VFP registers
6237 # are not updated after GDB ptrace set VFP registers. The bug
6238 # was introduced by kernel commit 8130b9d7b9d858aa04ce67805e8951e3cb6e9b2f
6239 # in 2012 and is fixed in e2dfb4b880146bfd4b6aa8e138c0205407cebbaf
6240 # in May 2016. In other words, kernels older than 4.6.3, 4.4.14,
6241 # 4.1.27, 3.18.36, and 3.14.73 have this bug.
6242 # This kernel bug is detected by check how does GDB change the
6243 # program result by changing one VFP register.
6244 if { [istarget "arm*-*-linux*"] } {
6246 set compile_flags {debug nowarnings }
6248 # Set up, compile, and execute a test program having VFP
6250 set src [standard_temp_file arm_vfp[pid].c]
6251 set exe [standard_temp_file arm_vfp[pid].x]
6253 gdb_produce_source $src {
6258 asm ("vldr d0, [%0]" : : "r" (&d));
6259 asm ("vldr d1, [%0]" : : "r" (&d));
6260 asm (".global break_here\n"
6262 asm ("vcmp.f64 d0, d1\n"
6263 "vmrs APSR_nzcv, fpscr\n"
6264 "bne L_value_different\n"
6267 "L_value_different:\n"
6269 "L_end:\n" : "=r" (ret) :);
6271 /* Return $d0 != $d1. */
6276 verbose "compiling testfile $src" 2
6277 set lines [gdb_compile $src $exe executable $compile_flags]
6280 if ![string match "" $lines] then {
6281 verbose "testfile compilation failed, returning 1" 2
6285 # No error message, compilation succeeded so now run it via gdb.
6286 # Run the test up to 5 times to detect whether ptrace can
6287 # correctly update VFP registers or not.
6289 for {set i 0} {$i < 5} {incr i} {
6290 global gdb_prompt srcdir subdir
6294 gdb_reinitialize_dir $srcdir/$subdir
6298 gdb_test "break *break_here"
6299 gdb_continue_to_breakpoint "break_here"
6301 # Modify $d0 to a different value, so the exit code should
6303 gdb_test "set \$d0 = 5.0"
6305 set test "continue to exit"
6306 gdb_test_multiple "continue" "$test" {
6307 -re "exited with code 01.*$gdb_prompt $" {
6309 -re "exited normally.*$gdb_prompt $" {
6310 # However, the exit code is 0. That means something
6311 # wrong in setting VFP registers.
6319 remote_file build delete $exe
6321 return $skip_vfp_test
6326 # Print a message and return true if a test should be skipped
6327 # due to lack of stdio support.
6329 proc gdb_skip_stdio_test { msg } {
6330 if [target_info exists gdb,noinferiorio] {
6331 verbose "Skipping test '$msg': no inferior i/o."
6337 proc gdb_skip_bogus_test { msg } {
6341 # Return true if a test should be skipped due to lack of XML support
6343 # NOTE: This must be called while gdb is *not* running.
6345 gdb_caching_proc gdb_skip_xml_test {
6350 if { [info exists gdb_spawn_id] } {
6351 error "GDB must not be running in gdb_skip_xml_tests."
6354 set xml_file [gdb_remote_download host "${srcdir}/gdb.xml/trivial.xml"]
6358 gdb_test_multiple "set tdesc filename $xml_file" "" {
6359 -re ".*XML support was disabled at compile time.*$gdb_prompt $" {
6362 -re ".*$gdb_prompt $" { }
6368 # Return true if argv[0] is available.
6370 gdb_caching_proc gdb_has_argv0 {
6373 # Compile and execute a test program to check whether argv[0] is available.
6374 gdb_simple_compile has_argv0 {
6375 int main (int argc, char **argv) {
6382 proc gdb_has_argv0_1 { exe } {
6383 global srcdir subdir
6384 global gdb_prompt hex
6388 gdb_reinitialize_dir $srcdir/$subdir
6391 # Set breakpoint on main.
6392 gdb_test_multiple "break -q main" "break -q main" {
6393 -re "Breakpoint.*${gdb_prompt} $" {
6395 -re "${gdb_prompt} $" {
6402 gdb_test_multiple "" "run to main" {
6403 -re "Breakpoint.*${gdb_prompt} $" {
6405 -re "${gdb_prompt} $" {
6410 set old_elements "200"
6411 set test "show print elements"
6412 gdb_test_multiple $test $test {
6413 -re "Limit on string chars or array elements to print is (\[^\r\n\]+)\\.\r\n$gdb_prompt $" {
6414 set old_elements $expect_out(1,string)
6417 set old_repeats "200"
6418 set test "show print repeats"
6419 gdb_test_multiple $test $test {
6420 -re "Threshold for repeated print elements is (\[^\r\n\]+)\\.\r\n$gdb_prompt $" {
6421 set old_repeats $expect_out(1,string)
6424 gdb_test_no_output "set print elements unlimited" ""
6425 gdb_test_no_output "set print repeats unlimited" ""
6428 # Check whether argc is 1.
6429 gdb_test_multiple "p argc" "p argc" {
6430 -re " = 1\r\n${gdb_prompt} $" {
6432 gdb_test_multiple "p argv\[0\]" "p argv\[0\]" {
6433 -re " = $hex \".*[file tail $exe]\"\r\n${gdb_prompt} $" {
6436 -re "${gdb_prompt} $" {
6440 -re "${gdb_prompt} $" {
6444 gdb_test_no_output "set print elements $old_elements" ""
6445 gdb_test_no_output "set print repeats $old_repeats" ""
6450 set result [gdb_has_argv0_1 $obj]
6456 && ([istarget *-*-linux*]
6457 || [istarget *-*-freebsd*] || [istarget *-*-kfreebsd*]
6458 || [istarget *-*-netbsd*] || [istarget *-*-knetbsd*]
6459 || [istarget *-*-openbsd*]
6460 || [istarget *-*-darwin*]
6461 || [istarget *-*-solaris*]
6462 || [istarget *-*-aix*]
6463 || [istarget *-*-gnu*]
6464 || [istarget *-*-cygwin*] || [istarget *-*-mingw32*]
6465 || [istarget *-*-*djgpp*] || [istarget *-*-go32*]
6466 || [istarget *-wince-pe] || [istarget *-*-mingw32ce*]
6467 || [istarget *-*-osf*]
6468 || [istarget *-*-dicos*]
6469 || [istarget *-*-nto*]
6470 || [istarget *-*-*vms*]
6471 || [istarget *-*-lynx*178]) } {
6472 fail "argv\[0\] should be available on this target"
6478 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
6479 # ${binfile}.dbglnk, which is just like the executable ($binfile) but without
6480 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
6481 # the name of a debuginfo only file. This file will be stored in the same
6484 # Functions for separate debug info testing
6486 # starting with an executable:
6487 # foo --> original executable
6489 # at the end of the process we have:
6490 # foo.stripped --> foo w/o debug info
6491 # foo.debug --> foo's debug info
6492 # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug.
6494 # Fetch the build id from the file.
6495 # Returns "" if there is none.
6497 proc get_build_id { filename } {
6498 if { ([istarget "*-*-mingw*"]
6499 || [istarget *-*-cygwin*]) } {
6500 set objdump_program [gdb_find_objdump]
6501 set result [catch {set data [exec $objdump_program -p $filename | grep signature | cut "-d " -f4]} output]
6502 verbose "result is $result"
6503 verbose "output is $output"
6509 set tmp [standard_output_file "${filename}-tmp"]
6510 set objcopy_program [gdb_find_objcopy]
6511 set result [catch "exec $objcopy_program -j .note.gnu.build-id -O binary $filename $tmp" output]
6512 verbose "result is $result"
6513 verbose "output is $output"
6518 fconfigure $fi -translation binary
6519 # Skip the NOTE header.
6524 if ![string compare $data ""] then {
6527 # Convert it to hex.
6528 binary scan $data H* data
6533 # Return the build-id hex string (usually 160 bits as 40 hex characters)
6534 # converted to the form: .build-id/ab/cdef1234...89.debug
6535 # Return "" if no build-id found.
6536 proc build_id_debug_filename_get { filename } {
6537 set data [get_build_id $filename]
6538 if { $data == "" } {
6541 regsub {^..} $data {\0/} data
6542 return ".build-id/${data}.debug"
6545 # Create stripped files for DEST, replacing it. If ARGS is passed, it is a
6546 # list of optional flags. The only currently supported flag is no-main,
6547 # which removes the symbol entry for main from the separate debug file.
6549 # Function returns zero on success. Function will return non-zero failure code
6550 # on some targets not supporting separate debug info (such as i386-msdos).
6552 proc gdb_gnu_strip_debug { dest args } {
6554 # Use the first separate debug info file location searched by GDB so the
6555 # run cannot be broken by some stale file searched with higher precedence.
6556 set debug_file "${dest}.debug"
6558 set strip_to_file_program [transform strip]
6559 set objcopy_program [gdb_find_objcopy]
6561 set debug_link [file tail $debug_file]
6562 set stripped_file "${dest}.stripped"
6564 # Get rid of the debug info, and store result in stripped_file
6565 # something like gdb/testsuite/gdb.base/blah.stripped.
6566 set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
6567 verbose "result is $result"
6568 verbose "output is $output"
6573 # Workaround PR binutils/10802:
6574 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
6575 set perm [file attributes ${dest} -permissions]
6576 file attributes ${stripped_file} -permissions $perm
6578 # Get rid of everything but the debug info, and store result in debug_file
6579 # This will be in the .debug subdirectory, see above.
6580 set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
6581 verbose "result is $result"
6582 verbose "output is $output"
6587 # If no-main is passed, strip the symbol for main from the separate
6588 # file. This is to simulate the behavior of elfutils's eu-strip, which
6589 # leaves the symtab in the original file only. There's no way to get
6590 # objcopy or strip to remove the symbol table without also removing the
6591 # debugging sections, so this is as close as we can get.
6592 if { [llength $args] == 1 && [lindex $args 0] == "no-main" } {
6593 set result [catch "exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp" output]
6594 verbose "result is $result"
6595 verbose "output is $output"
6599 file delete "${debug_file}"
6600 file rename "${debug_file}-tmp" "${debug_file}"
6603 # Link the two previous output files together, adding the .gnu_debuglink
6604 # section to the stripped_file, containing a pointer to the debug_file,
6605 # save the new file in dest.
6606 # This will be the regular executable filename, in the usual location.
6607 set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
6608 verbose "result is $result"
6609 verbose "output is $output"
6614 # Workaround PR binutils/10802:
6615 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
6616 set perm [file attributes ${stripped_file} -permissions]
6617 file attributes ${dest} -permissions $perm
6622 # Test the output of GDB_COMMAND matches the pattern obtained
6623 # by concatenating all elements of EXPECTED_LINES. This makes
6624 # it possible to split otherwise very long string into pieces.
6625 # If third argument TESTNAME is not empty, it's used as the name of the
6626 # test to be printed on pass/fail.
6627 proc help_test_raw { gdb_command expected_lines {testname {}} } {
6628 set expected_output [join $expected_lines ""]
6629 if {$testname != {}} {
6630 gdb_test "${gdb_command}" "${expected_output}" $testname
6634 gdb_test "${gdb_command}" "${expected_output}"
6637 # A regexp that matches the end of help CLASS|PREFIX_COMMAND
6638 set help_list_trailer {
6639 "Type \"apropos word\" to search for commands related to \"word\"\.[\r\n]+"
6640 "Type \"apropos -v word\" for full documentation of commands related to \"word\"\.[\r\n]+"
6641 "Command name abbreviations are allowed if unambiguous\."
6644 # Test the output of "help COMMAND_CLASS". EXPECTED_INITIAL_LINES
6645 # are regular expressions that should match the beginning of output,
6646 # before the list of commands in that class.
6647 # LIST_OF_COMMANDS are regular expressions that should match the
6648 # list of commands in that class. If empty, the command list will be
6649 # matched automatically. The presence of standard epilogue will be tested
6651 # If last argument TESTNAME is not empty, it's used as the name of the
6652 # test to be printed on pass/fail.
6653 # Notice that the '[' and ']' characters don't need to be escaped for strings
6654 # wrapped in {} braces.
6655 proc test_class_help { command_class expected_initial_lines {list_of_commands {}} {testname {}} } {
6656 global help_list_trailer
6657 if {[llength $list_of_commands]>0} {
6658 set l_list_of_commands {"List of commands:[\r\n]+[\r\n]+"}
6659 set l_list_of_commands [concat $l_list_of_commands $list_of_commands]
6660 set l_list_of_commands [concat $l_list_of_commands {"[\r\n]+[\r\n]+"}]
6662 set l_list_of_commands {"List of commands\:.*[\r\n]+"}
6665 "Type \"help\" followed by command name for full documentation\.[\r\n]+"
6667 set l_entire_body [concat $expected_initial_lines $l_list_of_commands \
6668 $l_stock_body $help_list_trailer]
6670 help_test_raw "help ${command_class}" $l_entire_body $testname
6673 # Like test_class_help but specialised to test "help user-defined".
6674 proc test_user_defined_class_help { {list_of_commands {}} {testname {}} } {
6675 test_class_help "user-defined" {
6676 "User-defined commands\.[\r\n]+"
6677 "The commands in this class are those defined by the user\.[\r\n]+"
6678 "Use the \"define\" command to define a command\.[\r\n]+"
6679 } $list_of_commands $testname
6683 # COMMAND_LIST should have either one element -- command to test, or
6684 # two elements -- abbreviated command to test, and full command the first
6685 # element is abbreviation of.
6686 # The command must be a prefix command. EXPECTED_INITIAL_LINES
6687 # are regular expressions that should match the beginning of output,
6688 # before the list of subcommands. The presence of
6689 # subcommand list and standard epilogue will be tested automatically.
6690 proc test_prefix_command_help { command_list expected_initial_lines args } {
6691 global help_list_trailer
6692 set command [lindex $command_list 0]
6693 if {[llength $command_list]>1} {
6694 set full_command [lindex $command_list 1]
6696 set full_command $command
6698 # Use 'list' and not just {} because we want variables to
6699 # be expanded in this list.
6700 set l_stock_body [list\
6701 "List of $full_command subcommands\:.*\[\r\n\]+"\
6702 "Type \"help $full_command\" followed by $full_command subcommand name for full documentation\.\[\r\n\]+"]
6703 set l_entire_body [concat $expected_initial_lines $l_stock_body $help_list_trailer]
6704 if {[llength $args]>0} {
6705 help_test_raw "help ${command}" $l_entire_body [lindex $args 0]
6707 help_test_raw "help ${command}" $l_entire_body
6711 # Build executable named EXECUTABLE from specifications that allow
6712 # different options to be passed to different sub-compilations.
6713 # TESTNAME is the name of the test; this is passed to 'untested' if
6715 # OPTIONS is passed to the final link, using gdb_compile. If OPTIONS
6716 # contains the option "pthreads", then gdb_compile_pthreads is used.
6717 # ARGS is a flat list of source specifications, of the form:
6718 # { SOURCE1 OPTIONS1 [ SOURCE2 OPTIONS2 ]... }
6719 # Each SOURCE is compiled to an object file using its OPTIONS,
6720 # using gdb_compile.
6721 # Returns 0 on success, -1 on failure.
6722 proc build_executable_from_specs {testname executable options args} {
6726 set binfile [standard_output_file $executable]
6729 if { [lsearch -exact $options "c++"] >= 0 } {
6730 set info_options "c++"
6732 if [get_compiler_info ${info_options}] {
6736 set func gdb_compile
6737 set func_index [lsearch -regexp $options {^(pthreads|shlib|shlib_pthreads|openmp)$}]
6738 if {$func_index != -1} {
6739 set func "${func}_[lindex $options $func_index]"
6742 # gdb_compile_shlib and gdb_compile_shlib_pthreads do not use the 3rd
6743 # parameter. They also requires $sources while gdb_compile and
6744 # gdb_compile_pthreads require $objects. Moreover they ignore any options.
6745 if [string match gdb_compile_shlib* $func] {
6747 foreach {s local_options} $args {
6748 if { [regexp "^/" "$s"] } then {
6749 lappend sources_path "$s"
6751 lappend sources_path "$srcdir/$subdir/$s"
6754 set ret [$func $sources_path "${binfile}" $options]
6755 } elseif {[lsearch -exact $options rust] != -1} {
6757 foreach {s local_options} $args {
6758 if { [regexp "^/" "$s"] } then {
6759 lappend sources_path "$s"
6761 lappend sources_path "$srcdir/$subdir/$s"
6764 set ret [gdb_compile_rust $sources_path "${binfile}" $options]
6768 foreach {s local_options} $args {
6769 if { ! [regexp "^/" "$s"] } then {
6770 set s "$srcdir/$subdir/$s"
6772 if { [$func "${s}" "${binfile}${i}.o" object $local_options] != "" } {
6776 lappend objects "${binfile}${i}.o"
6779 set ret [$func $objects "${binfile}" executable $options]
6789 # Build executable named EXECUTABLE, from SOURCES. If SOURCES are not
6790 # provided, uses $EXECUTABLE.c. The TESTNAME paramer is the name of test
6791 # to pass to untested, if something is wrong. OPTIONS are passed
6792 # to gdb_compile directly.
6793 proc build_executable { testname executable {sources ""} {options {debug}} } {
6794 if {[llength $sources]==0} {
6795 set sources ${executable}.c
6798 set arglist [list $testname $executable $options]
6799 foreach source $sources {
6800 lappend arglist $source $options
6803 return [eval build_executable_from_specs $arglist]
6806 # Starts fresh GDB binary and loads an optional executable into GDB.
6807 # Usage: clean_restart [executable]
6808 # EXECUTABLE is the basename of the binary.
6809 # Return -1 if starting gdb or loading the executable failed.
6811 proc clean_restart { args } {
6817 if { [llength $args] > 1 } {
6818 error "bad number of args: [llength $args]"
6823 # This is a clean restart, so reset error and warning count.
6828 # if { [gdb_start] == -1 } {
6831 # but gdb_start is a ${tool}_start proc, which doesn't have a defined
6832 # return value. So instead, we test for errcnt.
6834 if { $errcnt > 0 } {
6838 gdb_reinitialize_dir $srcdir/$subdir
6840 if { [llength $args] >= 1 } {
6841 set executable [lindex $args 0]
6842 set binfile [standard_output_file ${executable}]
6843 return [gdb_load ${binfile}]
6849 # Prepares for testing by calling build_executable_full, then
6851 # TESTNAME is the name of the test.
6852 # Each element in ARGS is a list of the form
6853 # { EXECUTABLE OPTIONS SOURCE_SPEC... }
6854 # These are passed to build_executable_from_specs, which see.
6855 # The last EXECUTABLE is passed to clean_restart.
6856 # Returns 0 on success, non-zero on failure.
6857 proc prepare_for_testing_full {testname args} {
6858 foreach spec $args {
6859 if {[eval build_executable_from_specs [list $testname] $spec] == -1} {
6862 set executable [lindex $spec 0]
6864 clean_restart $executable
6868 # Prepares for testing, by calling build_executable, and then clean_restart.
6869 # Please refer to build_executable for parameter description.
6870 proc prepare_for_testing { testname executable {sources ""} {options {debug}}} {
6872 if {[build_executable $testname $executable $sources $options] == -1} {
6875 clean_restart $executable
6880 # Retrieve the value of EXP in the inferior, represented in format
6881 # specified in FMT (using "printFMT"). DEFAULT is used as fallback if
6882 # print fails. TEST is the test message to use. It can be omitted,
6883 # in which case a test message is built from EXP.
6885 proc get_valueof { fmt exp default {test ""} } {
6889 set test "get valueof \"${exp}\""
6893 gdb_test_multiple "print${fmt} ${exp}" "$test" {
6894 -re "\\$\[0-9\]* = (\[^\r\n\]*)\[\r\n\]*$gdb_prompt $" {
6895 set val $expect_out(1,string)
6899 fail "$test (timeout)"
6905 # Retrieve the value of local var EXP in the inferior. DEFAULT is used as
6906 # fallback if print fails. TEST is the test message to use. It can be
6907 # omitted, in which case a test message is built from EXP.
6909 proc get_local_valueof { exp default {test ""} } {
6913 set test "get local valueof \"${exp}\""
6917 gdb_test_multiple "info locals ${exp}" "$test" {
6918 -re "$exp = (\[^\r\n\]*)\[\r\n\]*$gdb_prompt $" {
6919 set val $expect_out(1,string)
6923 fail "$test (timeout)"
6929 # Retrieve the value of EXP in the inferior, as a signed decimal value
6930 # (using "print /d"). DEFAULT is used as fallback if print fails.
6931 # TEST is the test message to use. It can be omitted, in which case
6932 # a test message is built from EXP.
6934 proc get_integer_valueof { exp default {test ""} } {
6938 set test "get integer valueof \"${exp}\""
6942 gdb_test_multiple "print /d ${exp}" "$test" {
6943 -re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" {
6944 set val $expect_out(1,string)
6948 fail "$test (timeout)"
6954 # Retrieve the value of EXP in the inferior, as an hexadecimal value
6955 # (using "print /x"). DEFAULT is used as fallback if print fails.
6956 # TEST is the test message to use. It can be omitted, in which case
6957 # a test message is built from EXP.
6959 proc get_hexadecimal_valueof { exp default {test ""} } {
6963 set test "get hexadecimal valueof \"${exp}\""
6967 gdb_test_multiple "print /x ${exp}" $test {
6968 -re "\\$\[0-9\]* = (0x\[0-9a-zA-Z\]+).*$gdb_prompt $" {
6969 set val $expect_out(1,string)
6976 # Retrieve the size of TYPE in the inferior, as a decimal value. DEFAULT
6977 # is used as fallback if print fails. TEST is the test message to use.
6978 # It can be omitted, in which case a test message is 'sizeof (TYPE)'.
6980 proc get_sizeof { type default {test ""} } {
6981 return [get_integer_valueof "sizeof (${type})" $default $test]
6984 proc get_target_charset { } {
6987 gdb_test_multiple "show target-charset" "" {
6988 -re "The target character set is \"auto; currently (\[^\"\]*)\".*$gdb_prompt $" {
6989 return $expect_out(1,string)
6991 -re "The target character set is \"(\[^\"\]*)\".*$gdb_prompt $" {
6992 return $expect_out(1,string)
6996 # Pick a reasonable default.
6997 warning "Unable to read target-charset."
7001 # Get the address of VAR.
7003 proc get_var_address { var } {
7004 global gdb_prompt hex
7006 # Match output like:
7008 # $5 = (int (*)()) 0
7009 # $6 = (int (*)()) 0x24 <function_bar>
7011 gdb_test_multiple "print &${var}" "get address of ${var}" {
7012 -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $"
7014 pass "get address of ${var}"
7015 if { $expect_out(1,string) == "0" } {
7018 return $expect_out(1,string)
7025 # Return the frame number for the currently selected frame
7026 proc get_current_frame_number {{test_name ""}} {
7029 if { $test_name == "" } {
7030 set test_name "get current frame number"
7033 gdb_test_multiple "frame" $test_name {
7034 -re "#(\[0-9\]+) .*$gdb_prompt $" {
7035 set frame_num $expect_out(1,string)
7041 # Get the current value for remotetimeout and return it.
7042 proc get_remotetimeout { } {
7046 gdb_test_multiple "show remotetimeout" "" {
7047 -re "Timeout limit to wait for target to respond is ($decimal).*$gdb_prompt $" {
7048 return $expect_out(1,string)
7052 # Pick the default that gdb uses
7053 warning "Unable to read remotetimeout"
7057 # Set the remotetimeout to the specified timeout. Nothing is returned.
7058 proc set_remotetimeout { timeout } {
7061 gdb_test_multiple "set remotetimeout $timeout" "" {
7062 -re "$gdb_prompt $" {
7063 verbose "Set remotetimeout to $timeout\n"
7068 # Get the target's current endianness and return it.
7069 proc get_endianness { } {
7072 gdb_test_multiple "show endian" "determine endianness" {
7073 -re ".* (little|big) endian.*\r\n$gdb_prompt $" {
7075 return $expect_out(1,string)
7081 # ROOT and FULL are file names. Returns the relative path from ROOT
7082 # to FULL. Note that FULL must be in a subdirectory of ROOT.
7083 # For example, given ROOT = /usr/bin and FULL = /usr/bin/ls, this
7086 proc relative_filename {root full} {
7087 set root_split [file split $root]
7088 set full_split [file split $full]
7090 set len [llength $root_split]
7092 if {[eval file join $root_split]
7093 != [eval file join [lrange $full_split 0 [expr {$len - 1}]]]} {
7094 error "$full not a subdir of $root"
7097 return [eval file join [lrange $full_split $len end]]
7100 # If GDB_PARALLEL exists, then set up the parallel-mode directories.
7101 if {[info exists GDB_PARALLEL]} {
7102 if {[is_remote host]} {
7106 [make_gdb_parallel_path outputs] \
7107 [make_gdb_parallel_path temp] \
7108 [make_gdb_parallel_path cache]
7112 proc core_find {binfile {deletefiles {}} {arg ""}} {
7113 global objdir subdir
7115 set destcore "$binfile.core"
7116 file delete $destcore
7118 # Create a core file named "$destcore" rather than just "core", to
7119 # avoid problems with sys admin types that like to regularly prune all
7120 # files named "core" from the system.
7122 # Arbitrarily try setting the core size limit to "unlimited" since
7123 # this does not hurt on systems where the command does not work and
7124 # allows us to generate a core on systems where it does.
7126 # Some systems append "core" to the name of the program; others append
7127 # the name of the program to "core"; still others (like Linux, as of
7128 # May 2003) create cores named "core.PID". In the latter case, we
7129 # could have many core files lying around, and it may be difficult to
7130 # tell which one is ours, so let's run the program in a subdirectory.
7132 set coredir [standard_output_file coredir.[getpid]]
7134 catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile} ${arg}; true) >/dev/null 2>&1\""
7135 # remote_exec host "${binfile}"
7136 foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
7137 if [remote_file build exists $i] {
7138 remote_exec build "mv $i $destcore"
7142 # Check for "core.PID".
7143 if { $found == 0 } {
7144 set names [glob -nocomplain -directory $coredir core.*]
7145 if {[llength $names] == 1} {
7146 set corefile [file join $coredir [lindex $names 0]]
7147 remote_exec build "mv $corefile $destcore"
7151 if { $found == 0 } {
7152 # The braindamaged HPUX shell quits after the ulimit -c above
7153 # without executing ${binfile}. So we try again without the
7154 # ulimit here if we didn't find a core file above.
7155 # Oh, I should mention that any "braindamaged" non-Unix system has
7156 # the same problem. I like the cd bit too, it's really neat'n stuff.
7157 catch "system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\""
7158 foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" {
7159 if [remote_file build exists $i] {
7160 remote_exec build "mv $i $destcore"
7166 # Try to clean up after ourselves.
7167 foreach deletefile $deletefiles {
7168 remote_file build delete [file join $coredir $deletefile]
7170 remote_exec build "rmdir $coredir"
7172 if { $found == 0 } {
7173 warning "can't generate a core file - core tests suppressed - check ulimit -c"
7179 # gdb_target_symbol_prefix compiles a test program and then examines
7180 # the output from objdump to determine the prefix (such as underscore)
7181 # for linker symbol prefixes.
7183 gdb_caching_proc gdb_target_symbol_prefix {
7184 # Compile a simple test program...
7185 set src { int main() { return 0; } }
7186 if {![gdb_simple_compile target_symbol_prefix $src executable]} {
7192 set objdump_program [gdb_find_objdump]
7193 set result [catch "exec $objdump_program --syms $obj" output]
7196 && ![regexp -lineanchor \
7197 { ([^ a-zA-Z0-9]*)main$} $output dummy prefix] } {
7198 verbose "gdb_target_symbol_prefix: Could not find main in objdump output; returning null prefix" 2
7206 # Return 1 if target supports scheduler locking, otherwise return 0.
7208 gdb_caching_proc target_supports_scheduler_locking {
7211 set me "gdb_target_supports_scheduler_locking"
7213 set src { int main() { return 0; } }
7214 if {![gdb_simple_compile $me $src executable]} {
7223 set supports_schedule_locking -1
7224 set current_schedule_locking_mode ""
7226 set test "reading current scheduler-locking mode"
7227 gdb_test_multiple "show scheduler-locking" $test {
7228 -re "Mode for locking scheduler during execution is \"(\[\^\"\]*)\".*$gdb_prompt" {
7229 set current_schedule_locking_mode $expect_out(1,string)
7231 -re "$gdb_prompt $" {
7232 set supports_schedule_locking 0
7235 set supports_schedule_locking 0
7239 if { $supports_schedule_locking == -1 } {
7240 set test "checking for scheduler-locking support"
7241 gdb_test_multiple "set scheduler-locking $current_schedule_locking_mode" $test {
7242 -re "Target '\[^'\]+' cannot support this command\..*$gdb_prompt $" {
7243 set supports_schedule_locking 0
7245 -re "$gdb_prompt $" {
7246 set supports_schedule_locking 1
7249 set supports_schedule_locking 0
7254 if { $supports_schedule_locking == -1 } {
7255 set supports_schedule_locking 0
7259 remote_file build delete $obj
7260 verbose "$me: returning $supports_schedule_locking" 2
7261 return $supports_schedule_locking
7264 # Return 1 if compiler supports use of nested functions. Otherwise,
7267 gdb_caching_proc support_nested_function_tests {
7268 # Compile a test program containing a nested function
7269 return [gdb_can_simple_compile nested_func {
7279 # gdb_target_symbol returns the provided symbol with the correct prefix
7280 # prepended. (See gdb_target_symbol_prefix, above.)
7282 proc gdb_target_symbol { symbol } {
7283 set prefix [gdb_target_symbol_prefix]
7284 return "${prefix}${symbol}"
7287 # gdb_target_symbol_prefix_flags_asm returns a string that can be
7288 # added to gdb_compile options to define the C-preprocessor macro
7289 # SYMBOL_PREFIX with a value that can be prepended to symbols
7290 # for targets which require a prefix, such as underscore.
7292 # This version (_asm) defines the prefix without double quotes
7293 # surrounding the prefix. It is used to define the macro
7294 # SYMBOL_PREFIX for assembly language files. Another version, below,
7295 # is used for symbols in inline assembler in C/C++ files.
7297 # The lack of quotes in this version (_asm) makes it possible to
7298 # define supporting macros in the .S file. (The version which
7299 # uses quotes for the prefix won't work for such files since it's
7300 # impossible to define a quote-stripping macro in C.)
7302 # It's possible to use this version (_asm) for C/C++ source files too,
7303 # but a string is usually required in such files; providing a version
7304 # (no _asm) which encloses the prefix with double quotes makes it
7305 # somewhat easier to define the supporting macros in the test case.
7307 proc gdb_target_symbol_prefix_flags_asm {} {
7308 set prefix [gdb_target_symbol_prefix]
7309 if {$prefix ne ""} {
7310 return "additional_flags=-DSYMBOL_PREFIX=$prefix"
7316 # gdb_target_symbol_prefix_flags returns the same string as
7317 # gdb_target_symbol_prefix_flags_asm, above, but with the prefix
7318 # enclosed in double quotes if there is a prefix.
7320 # See the comment for gdb_target_symbol_prefix_flags_asm for an
7321 # extended discussion.
7323 proc gdb_target_symbol_prefix_flags {} {
7324 set prefix [gdb_target_symbol_prefix]
7325 if {$prefix ne ""} {
7326 return "additional_flags=-DSYMBOL_PREFIX=\"$prefix\""
7332 # A wrapper for 'remote_exec host' that passes or fails a test.
7333 # Returns 0 if all went well, nonzero on failure.
7334 # TEST is the name of the test, other arguments are as for remote_exec.
7336 proc run_on_host { test program args } {
7337 verbose -log "run_on_host: $program $args"
7338 # remote_exec doesn't work properly if the output is set but the
7339 # input is the empty string -- so replace an empty input with
7341 if {[llength $args] > 1 && [lindex $args 1] == ""} {
7342 set args [lreplace $args 1 1 "/dev/null"]
7344 set result [eval remote_exec host [list $program] $args]
7345 verbose "result is $result"
7346 set status [lindex $result 0]
7347 set output [lindex $result 1]
7352 verbose -log "run_on_host failed: $output"
7353 if { $output == "spawn failed" } {
7362 # Return non-zero if "board_info debug_flags" mentions Fission.
7363 # http://gcc.gnu.org/wiki/DebugFission
7364 # Fission doesn't support everything yet.
7365 # This supports working around bug 15954.
7367 proc using_fission { } {
7368 set debug_flags [board_info [target_info name] debug_flags]
7369 return [regexp -- "-gsplit-dwarf" $debug_flags]
7372 # Search LISTNAME in uplevel LEVEL caller and set variables according to the
7373 # list of valid options with prefix PREFIX described by ARGSET.
7375 # The first member of each one- or two-element list in ARGSET defines the
7376 # name of a variable that will be added to the caller's scope.
7378 # If only one element is given to describe an option, it the value is
7379 # 0 if the option is not present in (the caller's) ARGS or 1 if
7382 # If two elements are given, the second element is the default value of
7383 # the variable. This is then overwritten if the option exists in ARGS.
7384 # If EVAL, then subst is called on the value, which allows variables
7387 # Any parse_args elements in (the caller's) ARGS will be removed, leaving
7388 # any optional components.
7391 # proc myproc {foo args} {
7392 # parse_list args 1 {{bar} {baz "abc"} {qux}} "-" false
7395 # myproc ABC -bar -baz DEF peanut butter
7396 # will define the following variables in myproc:
7397 # foo (=ABC), bar (=1), baz (=DEF), and qux (=0)
7398 # args will be the list {peanut butter}
7400 proc parse_list { level listname argset prefix eval } {
7401 upvar $level $listname args
7403 foreach argument $argset {
7404 if {[llength $argument] == 1} {
7405 # Normalize argument, strip leading/trailing whitespace.
7406 # Allows us to treat {foo} and { foo } the same.
7407 set argument [string trim $argument]
7409 # No default specified, so we assume that we should set
7410 # the value to 1 if the arg is present and 0 if it's not.
7411 # It is assumed that no value is given with the argument.
7412 set pattern "$prefix$argument"
7413 set result [lsearch -exact $args $pattern]
7415 if {$result != -1} then {
7417 set args [lreplace $args $result $result]
7421 uplevel $level [list set $argument $value]
7422 } elseif {[llength $argument] == 2} {
7423 # There are two items in the argument. The second is a
7424 # default value to use if the item is not present.
7425 # Otherwise, the variable is set to whatever is provided
7426 # after the item in the args.
7427 set arg [lindex $argument 0]
7428 set pattern "$prefix[lindex $arg 0]"
7429 set result [lsearch -exact $args $pattern]
7431 if {$result != -1} then {
7432 set value [lindex $args [expr $result+1]]
7434 set value [uplevel [expr $level + 1] [list subst $value]]
7436 set args [lreplace $args $result [expr $result+1]]
7438 set value [lindex $argument 1]
7440 set value [uplevel $level [list subst $value]]
7443 uplevel $level [list set $arg $value]
7445 error "Badly formatted argument \"$argument\" in argument set"
7450 # Search the caller's args variable and set variables according to the list of
7451 # valid options described by ARGSET.
7453 proc parse_args { argset } {
7454 parse_list 2 args $argset "-" false
7456 # The remaining args should be checked to see that they match the
7457 # number of items expected to be passed into the procedure...
7460 # Process the caller's options variable and set variables according
7461 # to the list of valid options described by OPTIONSET.
7463 proc parse_options { optionset } {
7464 parse_list 2 options $optionset "" true
7466 # Require no remaining options.
7467 upvar 1 options options
7468 if { [llength $options] != 0 } {
7469 error "Options left unparsed: $options"
7473 # Capture the output of COMMAND in a string ignoring PREFIX (a regexp);
7474 # return that string.
7476 proc capture_command_output { command prefix } {
7480 set output_string ""
7481 gdb_test_multiple "$command" "capture_command_output for $command" {
7482 -re "[string_to_regexp ${command}]\[\r\n\]+${prefix}(.*)\[\r\n\]+$gdb_prompt $" {
7483 set output_string $expect_out(1,string)
7486 return $output_string
7489 # A convenience function that joins all the arguments together, with a
7490 # regexp that matches exactly one end of line in between each argument.
7491 # This function is ideal to write the expected output of a GDB command
7492 # that generates more than a couple of lines, as this allows us to write
7493 # each line as a separate string, which is easier to read by a human
7496 proc multi_line { args } {
7497 if { [llength $args] == 1 } {
7498 set hint "forgot {*} before list argument?"
7499 error "multi_line called with one argument ($hint)"
7501 return [join $args "\r\n"]
7504 # Similar to the above, but while multi_line is meant to be used to
7505 # match GDB output, this one is meant to be used to build strings to
7506 # send as GDB input.
7508 proc multi_line_input { args } {
7509 return [join $args "\n"]
7512 # Return the version of the DejaGnu framework.
7514 # The return value is a list containing the major, minor and patch version
7515 # numbers. If the version does not contain a minor or patch number, they will
7516 # be set to 0. For example:
7522 proc dejagnu_version { } {
7523 # The frame_version variable is defined by DejaGnu, in runtest.exp.
7524 global frame_version
7526 verbose -log "DejaGnu version: $frame_version"
7527 verbose -log "Expect version: [exp_version]"
7528 verbose -log "Tcl version: [info tclversion]"
7530 set dg_ver [split $frame_version .]
7532 while { [llength $dg_ver] < 3 } {
7539 # Define user-defined command COMMAND using the COMMAND_LIST as the
7540 # command's definition. The terminating "end" is added automatically.
7542 proc gdb_define_cmd {command command_list} {
7545 set input [multi_line_input {*}$command_list "end"]
7546 set test "define $command"
7548 gdb_test_multiple "define $command" $test {
7550 gdb_test_multiple $input $test {
7551 -re "\r\n$gdb_prompt " {
7558 # Override the 'cd' builtin with a version that ensures that the
7559 # log file keeps pointing at the same file. We need this because
7560 # unfortunately the path to the log file is recorded using an
7561 # relative path name, and, we sometimes need to close/reopen the log
7562 # after changing the current directory. See get_compiler_info.
7564 rename cd builtin_cd
7568 # Get the existing log file flags.
7569 set log_file_info [log_file -info]
7571 # Split the flags into args and file name.
7572 set log_file_flags ""
7573 set log_file_file ""
7574 foreach arg [ split "$log_file_info" " "] {
7575 if [string match "-*" $arg] {
7576 lappend log_file_flags $arg
7578 lappend log_file_file $arg
7582 # If there was an existing file, ensure it is an absolute path, and then
7584 if { $log_file_file != "" } {
7585 set log_file_file [file normalize $log_file_file]
7587 log_file $log_file_flags "$log_file_file"
7590 # Call the builtin version of cd.
7594 # Return a list of all languages supported by GDB, suitable for use in
7595 # 'set language NAME'. This doesn't include either the 'local' or
7597 proc gdb_supported_languages {} {
7598 return [list c objective-c c++ d go fortran modula-2 asm pascal \
7599 opencl rust minimal ada]
7602 # Check if debugging is enabled for gdb.
7604 proc gdb_debug_enabled { } {
7607 # If not already read, get the debug setting from environment or board setting.
7608 if {![info exists gdbdebug]} {
7610 if [info exists env(GDB_DEBUG)] {
7611 set gdbdebug $env(GDB_DEBUG)
7612 } elseif [target_info exists gdb,debug] {
7613 set gdbdebug [target_info gdb,debug]
7619 # Ensure it not empty.
7620 return [expr { $gdbdebug != "" }]
7623 # Turn on debugging if enabled, or reset if already on.
7625 proc gdb_debug_init { } {
7629 if ![gdb_debug_enabled] {
7633 # First ensure logging is off.
7634 send_gdb "set logging off\n"
7636 set debugfile [standard_output_file gdb.debug]
7637 send_gdb "set logging file $debugfile\n"
7639 send_gdb "set logging debugredirect\n"
7642 foreach entry [split $gdbdebug ,] {
7643 send_gdb "set debug $entry 1\n"
7646 # Now that everything is set, enable logging.
7647 send_gdb "set logging on\n"
7649 -re "Copying output to $debugfile.*Redirecting debug output to $debugfile.*$gdb_prompt $" {}
7650 timeout { warning "Couldn't set logging file" }
7654 # Check if debugging is enabled for gdbserver.
7656 proc gdbserver_debug_enabled { } {
7657 # Always disabled for GDB only setups.
7661 # Open the file for logging gdb input
7663 proc gdb_stdin_log_init { } {
7664 gdb_persistent_global in_file
7666 if {[info exists in_file]} {
7667 # Close existing file.
7668 catch "close $in_file"
7671 set logfile [standard_output_file_with_gdb_instance gdb.in]
7672 set in_file [open $logfile w]
7675 # Write to the file for logging gdb input.
7676 # TYPE can be one of the following:
7677 # "standard" : Default. Standard message written to the log
7678 # "answer" : Answer to a question (eg "Y"). Not written the log.
7679 # "optional" : Optional message. Not written to the log.
7681 proc gdb_stdin_log_write { message {type standard} } {
7684 if {![info exists in_file]} {
7688 # Check message types.
7689 switch -regexp -- $type {
7698 # Write to the log and make sure the output is there, even in case
7700 puts -nonewline $in_file "$message"
7704 # Write the command line used to invocate gdb to the cmd file.
7706 proc gdb_write_cmd_file { cmdline } {
7707 set logfile [standard_output_file_with_gdb_instance gdb.cmd]
7708 set cmd_file [open $logfile w]
7709 puts $cmd_file $cmdline
7710 catch "close $cmd_file"
7713 # Compare contents of FILE to string STR. Pass with MSG if equal, otherwise
7716 proc cmp_file_string { file str msg } {
7717 if { ![file exists $file]} {
7722 set caught_error [catch {
7723 set fp [open "$file" r]
7724 set file_contents [read $fp]
7727 if { $caught_error } then {
7728 error "$error_message"
7733 if { $file_contents == $str } {
7740 # Does the compiler support CTF debug output using '-gt' compiler
7741 # flag? If not then we should skip these tests. We should also
7742 # skip them if libctf was explicitly disabled.
7744 gdb_caching_proc skip_ctf_tests {
7745 global enable_libctf
7747 if {$enable_libctf eq "no"} {
7751 set can_ctf [gdb_can_simple_compile ctfdebug {
7755 } executable "additional_flags=-gt"]
7757 return [expr {!$can_ctf}]
7760 # Return 1 if compiler supports -gstatement-frontiers. Otherwise,
7763 gdb_caching_proc supports_statement_frontiers {
7764 return [gdb_can_simple_compile supports_statement_frontiers {
7768 } executable "additional_flags=-gstatement-frontiers"]
7771 # Return 1 if compiler supports -mmpx -fcheck-pointer-bounds. Otherwise,
7774 gdb_caching_proc supports_mpx_check_pointer_bounds {
7775 set flags "additional_flags=-mmpx additional_flags=-fcheck-pointer-bounds"
7776 return [gdb_can_simple_compile supports_mpx_check_pointer_bounds {
7780 } executable $flags]
7783 # Return 1 if compiler supports -fcf-protection=. Otherwise,
7786 gdb_caching_proc supports_fcf_protection {
7787 return [gdb_can_simple_compile supports_fcf_protection {
7791 } executable "additional_flags=-fcf-protection=full"]
7794 # Return 1 if symbols were read in using -readnow. Otherwise, return 0.
7796 proc readnow { args } {
7797 if { [llength $args] == 1 } {
7798 set re [lindex $args 0]
7804 # Given the listing from the following command can be very verbose, match
7805 # the patterns line-by-line. This prevents timeouts from waiting for
7806 # too much data to come at once.
7807 set cmd "maint print objfiles $re"
7808 gdb_test_multiple $cmd "" -lbl {
7809 -re "\r\n.gdb_index: faked for \"readnow\"" {
7810 # Record the we've seen the above pattern.
7815 # We don't care about any other input.
7822 # Return index name if symbols were read in using an index.
7823 # Otherwise, return "".
7825 proc have_index { objfile } {
7828 set cmd "maint print objfiles $objfile"
7829 gdb_test_multiple $cmd "" -lbl {
7830 -re "\r\n.gdb_index: faked for \"readnow\"" {
7834 -re "\r\n.gdb_index:" {
7838 -re "\r\n.debug_names:" {
7839 set res "debug_names"
7843 # We don't care about any other input.
7850 # Return 1 if partial symbols are available. Otherwise, return 0.
7852 proc psymtabs_p { } {
7855 set cmd "maint info psymtab"
7856 gdb_test_multiple $cmd "" {
7857 -re "$cmd\r\n$gdb_prompt $" {
7868 # Verify that partial symtab expansion for $filename has state $readin.
7870 proc verify_psymtab_expanded { filename readin } {
7873 set cmd "maint info psymtab"
7874 set test "$cmd: $filename: $readin"
7875 set re [multi_line \
7876 " \{ psymtab \[^\r\n\]*$filename\[^\r\n\]*" \
7880 gdb_test_multiple $cmd $test {
7881 -re "$cmd\r\n$gdb_prompt $" {
7882 unsupported $gdb_test_name
7890 # Add a .gdb_index section to PROGRAM.
7891 # PROGRAM is assumed to be the output of standard_output_file.
7892 # Returns the 0 if there is a failure, otherwise 1.
7894 # STYLE controls which style of index to add, if needed. The empty
7895 # string (the default) means .gdb_index; "-dwarf-5" means .debug_names.
7897 proc add_gdb_index { program {style ""} } {
7898 global srcdir GDB env BUILD_DATA_DIRECTORY
7899 set contrib_dir "$srcdir/../contrib"
7900 set env(GDB) "$GDB --data-directory=$BUILD_DATA_DIRECTORY"
7901 set result [catch "exec $contrib_dir/gdb-add-index.sh $style $program" output]
7902 if { $result != 0 } {
7903 verbose -log "result is $result"
7904 verbose -log "output is $output"
7911 # Add a .gdb_index section to PROGRAM, unless it alread has an index
7912 # (.gdb_index/.debug_names). Gdb doesn't support building an index from a
7913 # program already using one. Return 1 if a .gdb_index was added, return 0
7914 # if it already contained an index, and -1 if an error occurred.
7916 # STYLE controls which style of index to add, if needed. The empty
7917 # string (the default) means .gdb_index; "-dwarf-5" means .debug_names.
7919 proc ensure_gdb_index { binfile {style ""} } {
7920 set testfile [file tail $binfile]
7921 set test "check if index present"
7922 gdb_test_multiple "mt print objfiles ${testfile}" $test {
7923 -re -wrap "gdb_index.*" {
7926 -re -wrap "debug_names.*" {
7929 -re -wrap "Psymtabs.*" {
7930 if { [add_gdb_index $binfile $style] != "1" } {
7939 # Return 1 if executable contains .debug_types section. Otherwise, return 0.
7941 proc debug_types { } {
7944 set cmd "maint info sections"
7945 gdb_test_multiple $cmd "" {
7946 -re -wrap "at $hex: .debug_types.*" {
7957 # Return the addresses in the line table for FILE for which is_stmt is true.
7959 proc is_stmt_addresses { file } {
7965 gdb_test_multiple "maint info line-table $file" "" {
7966 -re "\r\n$decimal\[ \t\]+$decimal\[ \t\]+($hex)\[ \t\]+Y\[^\r\n\]*" {
7967 lappend is_stmt $expect_out(1,string)
7977 # Return 1 if hex number VAL is an element of HEXLIST.
7979 proc hex_in_list { val hexlist } {
7980 # Normalize val by removing 0x prefix, and leading zeros.
7981 set val [regsub ^0x $val ""]
7982 set val [regsub ^0+ $val "0"]
7985 set index [lsearch -regexp $hexlist $re]
7986 return [expr $index != -1]
7989 # Override proc NAME to proc OVERRIDE for the duration of the execution of
7992 proc with_override { name override body } {
7993 # Implementation note: It's possible to implement the override using
7994 # rename, like this:
7995 # rename $name save_$name
7996 # rename $override $name
7997 # set code [catch {uplevel 1 $body} result]
7998 # rename $name $override
7999 # rename save_$name $name
8000 # but there are two issues here:
8001 # - the save_$name might clash with an existing proc
8002 # - the override is no longer available under its original name during
8004 # So, we use this more elaborate but cleaner mechanism.
8006 # Save the old proc.
8007 set old_args [info args $name]
8008 set old_body [info body $name]
8010 # Install the override.
8011 set new_args [info args $override]
8012 set new_body [info body $override]
8013 eval proc $name {$new_args} {$new_body}
8016 set code [catch {uplevel 1 $body} result]
8019 eval proc $name {$old_args} {$old_body}
8021 # Return as appropriate.
8023 global errorInfo errorCode
8024 return -code error -errorinfo $errorInfo -errorcode $errorCode $result
8025 } elseif { $code > 1 } {
8026 return -code $code $result
8032 # Setup tuiterm.exp environment. To be used in test-cases instead of
8033 # "load_lib tuiterm.exp". Calls initialization function and schedules
8034 # finalization function.
8035 proc tuiterm_env { } {
8036 load_lib tuiterm.exp
8039 # Dejagnu has a version of note, but usage is not allowed outside of dejagnu.
8040 # Define a local version.
8041 proc gdb_note { message } {
8042 verbose -- "NOTE: $message" 0
8045 # Return 1 if compiler supports -fuse-ld=gold, otherwise return 0.
8046 gdb_caching_proc have_fuse_ld_gold {
8047 set me "have_fuse_ld_gold"
8048 set flags "additional_flags=-fuse-ld=gold"
8049 set src { int main() { return 0; } }
8050 return [gdb_simple_compile $me $src executable $flags]
8053 # Return 1 if compiler supports scalar_storage_order attribute, otherwise
8055 gdb_caching_proc supports_scalar_storage_order_attribute {
8056 set me "supports_scalar_storage_order_attribute"
8061 } __attribute__((scalar_storage_order("little-endian")));
8064 } __attribute__((scalar_storage_order("big-endian")));
8068 sle.v = sbe.v = 0x11223344;
8069 int same = memcmp (&sle, &sbe, sizeof (int)) == 0;
8074 if { ![gdb_simple_compile $me $src executable ""] } {
8078 set result [remote_exec target $obj]
8079 set status [lindex $result 0]
8080 set output [lindex $result 1]
8081 if { $output != "" } {
8088 # Return 1 if compiler supports __GNUC__, otherwise return 0.
8089 gdb_caching_proc supports_gnuc {
8090 set me "supports_gnuc"
8096 return [gdb_simple_compile $me $src object ""]
8099 # Return 1 if target supports mpx, otherwise return 0.
8100 gdb_caching_proc have_mpx {
8104 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
8105 verbose "$me: target does not support mpx, returning 0" 2
8109 # Compile a test program.
8111 #include "nat/x86-cpuid.h"
8114 unsigned int eax, ebx, ecx, edx;
8116 if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
8119 if ((ecx & bit_OSXSAVE) == bit_OSXSAVE)
8121 if (__get_cpuid_max (0, (void *)0) < 7)
8124 __cpuid_count (7, 0, eax, ebx, ecx, edx);
8126 if ((ebx & bit_MPX) == bit_MPX)
8133 set compile_flags "incdir=${srcdir}/.."
8134 if {![gdb_simple_compile $me $src executable $compile_flags]} {
8138 set result [remote_exec target $obj]
8139 set status [lindex $result 0]
8140 set output [lindex $result 1]
8141 if { $output != "" } {
8145 remote_file build delete $obj
8147 verbose "$me: returning $status" 2
8151 # Return 1 if target supports avx, otherwise return 0.
8152 gdb_caching_proc have_avx {
8156 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
8157 verbose "$me: target does not support avx, returning 0" 2
8161 # Compile a test program.
8163 #include "nat/x86-cpuid.h"
8166 unsigned int eax, ebx, ecx, edx;
8168 if (!x86_cpuid (1, &eax, &ebx, &ecx, &edx))
8171 if ((ecx & (bit_AVX | bit_OSXSAVE)) == (bit_AVX | bit_OSXSAVE))
8177 set compile_flags "incdir=${srcdir}/.."
8178 if {![gdb_simple_compile $me $src executable $compile_flags]} {
8182 set result [remote_exec target $obj]
8183 set status [lindex $result 0]
8184 set output [lindex $result 1]
8185 if { $output != "" } {
8189 remote_file build delete $obj
8191 verbose "$me: returning $status" 2
8195 # Always load compatibility stuff.