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 # If GDB is built with ASAN (and because there are leaks), it will output a
29 # leak report when exiting as well as exit with a non-zero (failure) status.
30 # This can affect tests that are sensitive to what GDB prints on stderr or its
31 # exit status. Add `detect_leaks=0` to the ASAN_OPTIONS environment variable
32 # (which will affect any spawned sub-process) to avoid this.
33 append ::env(ASAN_OPTIONS) ",detect_leaks=0"
35 # List of procs to run in gdb_finish.
36 set gdb_finish_hooks [list]
38 # Variable in which we keep track of globals that are allowed to be live
40 array set gdb_persistent_globals {}
42 # Mark variable names in ARG as a persistent global, and declare them as
43 # global in the calling context. Can be used to rewrite "global var_a var_b"
44 # into "gdb_persistent_global var_a var_b".
45 proc gdb_persistent_global { args } {
46 global gdb_persistent_globals
47 foreach varname $args {
48 uplevel 1 global $varname
49 set gdb_persistent_globals($varname) 1
53 # Mark variable names in ARG as a persistent global.
54 proc gdb_persistent_global_no_decl { args } {
55 global gdb_persistent_globals
56 foreach varname $args {
57 set gdb_persistent_globals($varname) 1
61 # Override proc load_lib.
62 rename load_lib saved_load_lib
63 # Run the runtest version of load_lib, and mark all variables that were
64 # created by this call as persistent.
65 proc load_lib { file } {
66 array set known_global {}
67 foreach varname [info globals] {
68 set known_globals($varname) 1
71 set code [catch "saved_load_lib $file" result]
73 foreach varname [info globals] {
74 if { ![info exists known_globals($varname)] } {
75 gdb_persistent_global_no_decl $varname
80 global errorInfo errorCode
81 return -code error -errorinfo $errorInfo -errorcode $errorCode $result
82 } elseif {$code > 1} {
83 return -code $code $result
91 load_lib gdb-utils.exp
93 load_lib check-test-names.exp
97 # The spawn ID used for I/O interaction with the inferior. For native
98 # targets, or remote targets that can do I/O through GDB
99 # (semi-hosting) this will be the same as the host/GDB's spawn ID.
100 # Otherwise, the board may set this to some other spawn ID. E.g.,
101 # when debugging with GDBserver, this is set to GDBserver's spawn ID,
102 # so input/output is done on gdbserver's tty.
103 global inferior_spawn_id
105 if [info exists TOOL_EXECUTABLE] {
106 set GDB $TOOL_EXECUTABLE
108 if ![info exists GDB] {
109 if ![is_remote host] {
110 set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]]
112 set GDB [transform gdb]
115 verbose "using GDB = $GDB" 2
117 # GDBFLAGS is available for the user to set on the command line.
118 # E.g. make check RUNTESTFLAGS=GDBFLAGS=mumble
119 # Testcases may use it to add additional flags, but they must:
120 # - append new flags, not overwrite
121 # - restore the original value when done
123 if ![info exists GDBFLAGS] {
126 verbose "using GDBFLAGS = $GDBFLAGS" 2
128 # Make the build data directory available to tests.
129 set BUILD_DATA_DIRECTORY "[pwd]/../data-directory"
131 # INTERNAL_GDBFLAGS contains flags that the testsuite requires.
132 global INTERNAL_GDBFLAGS
133 if ![info exists INTERNAL_GDBFLAGS] {
134 set INTERNAL_GDBFLAGS \
138 "-data-directory $BUILD_DATA_DIRECTORY" \
139 {-iex "set height 0"} \
140 {-iex "set width 0"}]]
143 # The variable gdb_prompt is a regexp which matches the gdb prompt.
144 # Set it if it is not already set. This is also set by default_gdb_init
145 # but it's not clear what removing one of them will break.
146 # See with_gdb_prompt for more details on prompt handling.
148 if ![info exists gdb_prompt] then {
149 set gdb_prompt "\\(gdb\\)"
152 # A regexp that matches the pagination prompt.
153 set pagination_prompt \
154 "--Type <RET> for more, q to quit, c to continue without paging--"
156 # The variable fullname_syntax_POSIX is a regexp which matches a POSIX
157 # absolute path ie. /foo/
158 set fullname_syntax_POSIX {/[^\n]*/}
159 # The variable fullname_syntax_UNC is a regexp which matches a Windows
160 # UNC path ie. \\D\foo\
161 set fullname_syntax_UNC {\\\\[^\\]+\\[^\n]+\\}
162 # The variable fullname_syntax_DOS_CASE is a regexp which matches a
163 # particular DOS case that GDB most likely will output
164 # ie. \foo\, but don't match \\.*\
165 set fullname_syntax_DOS_CASE {\\[^\\][^\n]*\\}
166 # The variable fullname_syntax_DOS is a regexp which matches a DOS path
167 # ie. a:\foo\ && a:foo\
168 set fullname_syntax_DOS {[a-zA-Z]:[^\n]*\\}
169 # The variable fullname_syntax is a regexp which matches what GDB considers
170 # an absolute path. It is currently debatable if the Windows style paths
171 # d:foo and \abc should be considered valid as an absolute path.
172 # Also, the purpse of this regexp is not to recognize a well formed
173 # absolute path, but to say with certainty that a path is absolute.
174 set fullname_syntax "($fullname_syntax_POSIX|$fullname_syntax_UNC|$fullname_syntax_DOS_CASE|$fullname_syntax_DOS)"
176 # Needed for some tests under Cygwin.
180 if ![info exists env(EXEEXT)] {
183 set EXEEXT $env(EXEEXT)
188 set inferior_exited_re "(?:\\\[Inferior \[0-9\]+ \\(\[^\n\r\]*\\) exited)"
190 # A regular expression that matches a value history number.
192 set valnum_re "\\\$$decimal"
194 ### Only procedures should come after this point.
197 # gdb_version -- extract and print the version number of GDB
199 proc default_gdb_version {} {
201 global INTERNAL_GDBFLAGS GDBFLAGS
205 if {[info exists inotify_pid]} {
206 eval exec kill $inotify_pid
209 set output [remote_exec host "$GDB $INTERNAL_GDBFLAGS --version"]
210 set tmp [lindex $output 1]
212 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
213 if ![is_remote host] {
214 clone_output "[which $GDB] version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
216 clone_output "$GDB on remote host version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
220 proc gdb_version { } {
221 return [default_gdb_version]
225 # gdb_unload -- unload a file if one is loaded
226 # Return 0 on success, -1 on error.
234 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
235 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
236 -re "A program is being debugged already.*Are you sure you want to change the file.*y or n. $" {
237 send_gdb "y\n" answer
240 -re "Discard symbol table from .*y or n.*$" {
241 send_gdb "y\n" answer
244 -re "$gdb_prompt $" {}
245 -re "A problem internal to GDB has been detected" {
246 perror "Couldn't unload file in $GDB (GDB internal error)."
247 gdb_internal_error_resync
251 perror "couldn't unload file in $GDB (timeout)."
258 # Many of the tests depend on setting breakpoints at various places and
259 # running until that breakpoint is reached. At times, we want to start
260 # with a clean-slate with respect to breakpoints, so this utility proc
261 # lets us do this without duplicating this code everywhere.
264 proc delete_breakpoints {} {
267 # we need a larger timeout value here or this thing just confuses
268 # itself. May need a better implementation if possible. - guo
272 set msg "delete all breakpoints in delete_breakpoints"
274 gdb_test_multiple "delete breakpoints" "$msg" {
275 -re "Delete all breakpoints.*y or n.*$" {
276 send_gdb "y\n" answer
279 -re "$gdb_prompt $" {
285 # Confirm with "info breakpoints".
287 set msg "info breakpoints"
288 gdb_test_multiple $msg $msg {
289 -re "No breakpoints or watchpoints..*$gdb_prompt $" {
292 -re "$gdb_prompt $" {
298 perror "breakpoints not deleted"
302 # Returns true iff the target supports using the "run" command.
304 proc target_can_use_run_cmd {} {
305 if [target_info exists use_gdb_stub] {
306 # In this case, when we connect, the inferior is already
315 # Generic run command.
317 # Return 0 if we could start the program, -1 if we could not.
319 # The second pattern below matches up to the first newline *only*.
320 # Using ``.*$'' could swallow up output that we attempt to match
323 # INFERIOR_ARGS is passed as arguments to the start command, so may contain
324 # inferior arguments.
326 # N.B. This function does not wait for gdb to return to the prompt,
327 # that is the caller's responsibility.
329 proc gdb_run_cmd { {inferior_args {}} } {
330 global gdb_prompt use_gdb_stub
332 foreach command [gdb_init_commands] {
333 send_gdb "$command\n"
335 -re "$gdb_prompt $" { }
337 perror "gdb_init_command for target failed"
344 if [target_info exists gdb,do_reload_on_run] {
345 if { [gdb_reload $inferior_args] != 0 } {
348 send_gdb "continue\n"
350 -re "Continu\[^\r\n\]*\[\r\n\]" {}
356 if [target_info exists gdb,start_symbol] {
357 set start [target_info gdb,start_symbol]
361 send_gdb "jump *$start\n"
363 while { $start_attempt } {
364 # Cap (re)start attempts at three to ensure that this loop
365 # always eventually fails. Don't worry about trying to be
366 # clever and not send a command when it has failed.
367 if [expr $start_attempt > 3] {
368 perror "Jump to start() failed (retry count exceeded)"
371 set start_attempt [expr $start_attempt + 1]
373 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
376 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
377 perror "Can't find start symbol to run in gdb_run"
380 -re "No symbol \"start\" in current.*$gdb_prompt $" {
381 send_gdb "jump *_start\n"
383 -re "No symbol.*context.*$gdb_prompt $" {
386 -re "Line.* Jump anyway.*y or n. $" {
387 send_gdb "y\n" answer
389 -re "The program is not being run.*$gdb_prompt $" {
390 if { [gdb_reload $inferior_args] != 0 } {
393 send_gdb "jump *$start\n"
396 perror "Jump to start() failed (timeout)"
405 if [target_info exists gdb,do_reload_on_run] {
406 if { [gdb_reload $inferior_args] != 0 } {
410 send_gdb "run $inferior_args\n"
411 # This doesn't work quite right yet.
412 # Use -notransfer here so that test cases (like chng-sym.exp)
413 # may test for additional start-up messages.
415 -re "The program .* has been started already.*y or n. $" {
416 send_gdb "y\n" answer
419 -notransfer -re "Starting program: \[^\r\n\]*" {}
420 -notransfer -re "$gdb_prompt $" {
421 # There is no more input expected.
423 -notransfer -re "A problem internal to GDB has been detected" {
424 # Let caller handle this.
431 # Generic start command. Return 0 if we could start the program, -1
434 # INFERIOR_ARGS is passed as arguments to the start command, so may contain
435 # inferior arguments.
437 # N.B. This function does not wait for gdb to return to the prompt,
438 # that is the caller's responsibility.
440 proc gdb_start_cmd { {inferior_args {}} } {
441 global gdb_prompt use_gdb_stub
443 foreach command [gdb_init_commands] {
444 send_gdb "$command\n"
446 -re "$gdb_prompt $" { }
448 perror "gdb_init_command for target failed"
458 send_gdb "start $inferior_args\n"
459 # Use -notransfer here so that test cases (like chng-sym.exp)
460 # may test for additional start-up messages.
462 -re "The program .* has been started already.*y or n. $" {
463 send_gdb "y\n" answer
466 -notransfer -re "Starting program: \[^\r\n\]*" {
473 # Generic starti command. Return 0 if we could start the program, -1
476 # INFERIOR_ARGS is passed as arguments to the starti command, so may contain
477 # inferior arguments.
479 # N.B. This function does not wait for gdb to return to the prompt,
480 # that is the caller's responsibility.
482 proc gdb_starti_cmd { {inferior_args {}} } {
483 global gdb_prompt use_gdb_stub
485 foreach command [gdb_init_commands] {
486 send_gdb "$command\n"
488 -re "$gdb_prompt $" { }
490 perror "gdb_init_command for target failed"
500 send_gdb "starti $inferior_args\n"
502 -re "The program .* has been started already.*y or n. $" {
503 send_gdb "y\n" answer
506 -re "Starting program: \[^\r\n\]*" {
513 # Set a breakpoint at FUNCTION. If there is an additional argument it is
514 # a list of options; the supported options are allow-pending, temporary,
515 # message, no-message and qualified.
516 # The result is 1 for success, 0 for failure.
518 # Note: The handling of message vs no-message is messed up, but it's based
519 # on historical usage. By default this function does not print passes,
521 # no-message: turns off printing of fails (and passes, but they're already off)
522 # message: turns on printing of passes (and fails, but they're already on)
524 proc gdb_breakpoint { function args } {
528 set pending_response n
529 if {[lsearch -exact $args allow-pending] != -1} {
530 set pending_response y
533 set break_command "break"
534 set break_message "Breakpoint"
535 if {[lsearch -exact $args temporary] != -1} {
536 set break_command "tbreak"
537 set break_message "Temporary breakpoint"
540 if {[lsearch -exact $args qualified] != -1} {
541 append break_command " -qualified"
546 set no_message_loc [lsearch -exact $args no-message]
547 set message_loc [lsearch -exact $args message]
548 # The last one to appear in args wins.
549 if { $no_message_loc > $message_loc } {
551 } elseif { $message_loc > $no_message_loc } {
555 set test_name "setting breakpoint at $function"
557 send_gdb "$break_command $function\n"
558 # The first two regexps are what we get with -g, the third is without -g.
560 -re "$break_message \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
561 -re "$break_message \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
562 -re "$break_message \[0-9\]* at .*$gdb_prompt $" {}
563 -re "$break_message \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" {
564 if {$pending_response == "n"} {
571 -re "Make breakpoint pending.*y or \\\[n\\\]. $" {
572 send_gdb "$pending_response\n"
575 -re "A problem internal to GDB has been detected" {
577 fail "$test_name (GDB internal error)"
579 gdb_internal_error_resync
582 -re "$gdb_prompt $" {
589 perror "GDB process no longer exists"
591 set wait_status [wait -i $gdb_spawn_id]
592 verbose -log "GDB process exited with wait status $wait_status"
594 fail "$test_name (eof)"
600 fail "$test_name (timeout)"
611 # Set breakpoint at function and run gdb until it breaks there.
612 # Since this is the only breakpoint that will be set, if it stops
613 # at a breakpoint, we will assume it is the one we want. We can't
614 # just compare to "function" because it might be a fully qualified,
615 # single quoted C++ function specifier.
617 # If there are additional arguments, pass them to gdb_breakpoint.
618 # We recognize no-message/message ourselves.
619 # The default is no-message.
620 # no-message is messed up here, like gdb_breakpoint: to preserve
621 # historical usage fails are always printed by default.
622 # no-message: turns off printing of fails (and passes, but they're already off)
623 # message: turns on printing of passes (and fails, but they're already on)
625 proc runto { function args } {
631 # Default to "no-message".
632 set args "no-message $args"
636 set no_message_loc [lsearch -exact $args no-message]
637 set message_loc [lsearch -exact $args message]
638 # The last one to appear in args wins.
639 if { $no_message_loc > $message_loc } {
641 } elseif { $message_loc > $no_message_loc } {
645 set test_name "running to $function in runto"
647 # We need to use eval here to pass our varargs args to gdb_breakpoint
648 # which is also a varargs function.
649 # But we also have to be careful because $function may have multiple
650 # elements, and we don't want Tcl to move the remaining elements after
651 # the first to $args. That is why $function is wrapped in {}.
652 if ![eval gdb_breakpoint {$function} $args] {
658 # the "at foo.c:36" output we get with -g.
659 # the "in func" output we get without -g.
661 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
667 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
673 -re "The target does not support running in non-stop mode.\r\n$gdb_prompt $" {
675 unsupported "non-stop mode not supported"
679 -re ".*A problem internal to GDB has been detected" {
680 # Always emit a FAIL if we encounter an internal error: internal
681 # errors are never expected.
682 fail "$test_name (GDB internal error)"
683 gdb_internal_error_resync
686 -re "$gdb_prompt $" {
694 fail "$test_name (eof)"
700 fail "$test_name (timeout)"
711 # Ask gdb to run until we hit a breakpoint at main.
713 # N.B. This function deletes all existing breakpoints.
714 # If you don't want that, use gdb_start_cmd.
716 proc runto_main { } {
717 return [runto main qualified]
720 ### Continue, and expect to hit a breakpoint.
721 ### Report a pass or fail, depending on whether it seems to have
722 ### worked. Use NAME as part of the test name; each call to
723 ### continue_to_breakpoint should use a NAME which is unique within
725 proc gdb_continue_to_breakpoint {name {location_pattern .*}} {
727 set full_name "continue to breakpoint: $name"
729 set kfail_pattern "Process record does not support instruction 0xfae64 at.*"
730 gdb_test_multiple "continue" $full_name {
731 -re "(?:Breakpoint|Temporary breakpoint) .* (at|in) $location_pattern\r\n$gdb_prompt $" {
734 -re "\[\r\n\]*(?:$kfail_pattern)\[\r\n\]+$gdb_prompt $" {
735 kfail "gdb/25038" $full_name
741 # gdb_internal_error_resync:
743 # Answer the questions GDB asks after it reports an internal error
744 # until we get back to a GDB prompt. Decline to quit the debugging
745 # session, and decline to create a core file. Return non-zero if the
748 # This procedure just answers whatever questions come up until it sees
749 # a GDB prompt; it doesn't require you to have matched the input up to
750 # any specific point. However, it only answers questions it sees in
751 # the output itself, so if you've matched a question, you had better
752 # answer it yourself before calling this.
754 # You can use this function thus:
758 # -re ".*A problem internal to GDB has been detected" {
759 # gdb_internal_error_resync
764 proc gdb_internal_error_resync {} {
767 verbose -log "Resyncing due to internal error."
770 while {$count < 10} {
772 -re "Quit this debugging session\\? \\(y or n\\) $" {
773 send_gdb "n\n" answer
776 -re "Create a core file of GDB\\? \\(y or n\\) $" {
777 send_gdb "n\n" answer
780 -re "$gdb_prompt $" {
781 # We're resynchronized.
785 perror "Could not resync from internal error (timeout)"
789 perror "Could not resync from internal error (eof)"
794 perror "Could not resync from internal error (resync count exceeded)"
799 # gdb_test_multiple COMMAND MESSAGE [ -prompt PROMPT_REGEXP] [ -lbl ]
801 # Send a command to gdb; test the result.
803 # COMMAND is the command to execute, send to GDB with send_gdb. If
804 # this is the null string no command is sent.
805 # MESSAGE is a message to be printed with the built-in failure patterns
806 # if one of them matches. If MESSAGE is empty COMMAND will be used.
807 # -prompt PROMPT_REGEXP specifies a regexp matching the expected prompt
808 # after the command output. If empty, defaults to "$gdb_prompt $".
809 # -lbl specifies that line-by-line matching will be used.
810 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
811 # patterns. Pattern elements will be evaluated in the caller's
812 # context; action elements will be executed in the caller's context.
813 # Unlike patterns for gdb_test, these patterns should generally include
814 # the final newline and prompt.
817 # 1 if the test failed, according to a built-in failure pattern
818 # 0 if only user-supplied patterns matched
819 # -1 if there was an internal error.
821 # You can use this function thus:
823 # gdb_test_multiple "print foo" "test foo" {
824 # -re "expected output 1" {
827 # -re "expected output 2" {
832 # Within action elements you can also make use of the variable
833 # gdb_test_name. This variable is setup automatically by
834 # gdb_test_multiple, and contains the value of MESSAGE. You can then
835 # write this, which is equivalent to the above:
837 # gdb_test_multiple "print foo" "test foo" {
838 # -re "expected output 1" {
839 # pass $gdb_test_name
841 # -re "expected output 2" {
842 # fail $gdb_test_name
846 # Like with "expect", you can also specify the spawn id to match with
847 # -i "$id". Interesting spawn ids are $inferior_spawn_id and
848 # $gdb_spawn_id. The former matches inferior I/O, while the latter
849 # matches GDB I/O. E.g.:
851 # send_inferior "hello\n"
852 # gdb_test_multiple "continue" "test echo" {
853 # -i "$inferior_spawn_id" -re "^hello\r\nhello\r\n$" {
856 # -i "$gdb_spawn_id" -re "Breakpoint.*$gdb_prompt $" {
857 # fail "hit breakpoint"
861 # The standard patterns, such as "Inferior exited..." and "A problem
862 # ...", all being implicitly appended to that list. These are always
863 # expected from $gdb_spawn_id. IOW, callers do not need to worry
864 # about resetting "-i" back to $gdb_spawn_id explicitly.
866 # In EXPECT_ARGUMENTS we can use a -wrap pattern flag, that wraps the regexp
867 # pattern as gdb_test wraps its message argument.
868 # This allows us to rewrite:
869 # gdb_test <command> <pattern> <message>
871 # gdb_test_multiple <command> <message> {
872 # -re -wrap <pattern> {
873 # pass $gdb_test_name
877 # In EXPECT_ARGUMENTS, a pattern flag -early can be used. It makes sure the
878 # pattern is inserted before any implicit pattern added by gdb_test_multiple.
879 # Using this pattern flag, we can f.i. setup a kfail for an assertion failure
880 # <assert> during gdb_continue_to_breakpoint by the rewrite:
881 # gdb_continue_to_breakpoint <msg> <pattern>
883 # set breakpoint_pattern "(?:Breakpoint|Temporary breakpoint) .* (at|in)"
884 # gdb_test_multiple "continue" "continue to breakpoint: <msg>" {
885 # -early -re "internal-error: <assert>" {
886 # setup_kfail gdb/nnnnn "*-*-*"
889 # -re "$breakpoint_pattern <pattern>\r\n$gdb_prompt $" {
890 # pass $gdb_test_name
894 proc gdb_test_multiple { command message args } {
895 global verbose use_gdb_stub
896 global gdb_prompt pagination_prompt
899 global inferior_exited_re
900 upvar timeout timeout
901 upvar expect_out expect_out
906 for {set i 0} {$i < [llength $args]} {incr i} {
907 set arg [lindex $args $i]
908 if { $arg == "-prompt" } {
910 set prompt_regexp [lindex $args $i]
911 } elseif { $arg == "-lbl" } {
918 if { [expr $i + 1] < [llength $args] } {
919 error "Too many arguments to gdb_test_multiple"
920 } elseif { ![info exists user_code] } {
921 error "Too few arguments to gdb_test_multiple"
924 if { "$prompt_regexp" == "" } {
925 set prompt_regexp "$gdb_prompt $"
928 if { $message == "" } {
932 if [string match "*\[\r\n\]" $command] {
933 error "Invalid trailing newline in \"$message\" test"
936 if [string match "*\[\r\n\]*" $message] {
937 error "Invalid newline in \"$message\" test"
941 && [regexp -nocase {^\s*(r|run|star|start|at|att|atta|attac|attach)\M} \
943 error "gdbserver does not support $command without extended-remote"
946 # TCL/EXPECT WART ALERT
947 # Expect does something very strange when it receives a single braced
948 # argument. It splits it along word separators and performs substitutions.
949 # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
950 # evaluated as "\[ab\]". But that's not how TCL normally works; inside a
951 # double-quoted list item, "\[ab\]" is just a long way of representing
952 # "[ab]", because the backslashes will be removed by lindex.
954 # Unfortunately, there appears to be no easy way to duplicate the splitting
955 # that expect will do from within TCL. And many places make use of the
956 # "\[0-9\]" construct, so we need to support that; and some places make use
957 # of the "[func]" construct, so we need to support that too. In order to
958 # get this right we have to substitute quoted list elements differently
959 # from braced list elements.
961 # We do this roughly the same way that Expect does it. We have to use two
962 # lists, because if we leave unquoted newlines in the argument to uplevel
963 # they'll be treated as command separators, and if we escape newlines
964 # we mangle newlines inside of command blocks. This assumes that the
965 # input doesn't contain a pattern which contains actual embedded newlines
968 regsub -all {\n} ${user_code} { } subst_code
969 set subst_code [uplevel list $subst_code]
971 set processed_code ""
972 set early_processed_code ""
973 # The variable current_list holds the name of the currently processed
974 # list, either processed_code or early_processed_code.
975 set current_list "processed_code"
977 set expecting_action 0
980 foreach item $user_code subst_item $subst_code {
981 if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } {
982 lappend $current_list $item
985 if { $item == "-indices" || $item == "-re" || $item == "-ex" } {
986 lappend $current_list $item
989 if { $item == "-early" } {
990 set current_list "early_processed_code"
993 if { $item == "-timeout" || $item == "-i" } {
995 lappend $current_list $item
998 if { $item == "-wrap" } {
1002 if { $expecting_arg } {
1004 lappend $current_list $subst_item
1007 if { $expecting_action } {
1008 lappend $current_list "uplevel [list $item]"
1009 set expecting_action 0
1010 # Cosmetic, no effect on the list.
1011 append $current_list "\n"
1012 # End the effect of -early, it only applies to one action.
1013 set current_list "processed_code"
1016 set expecting_action 1
1017 if { $wrap_pattern } {
1018 # Wrap subst_item as is done for the gdb_test PATTERN argument.
1019 lappend $current_list \
1020 "\[\r\n\]*(?:$subst_item)\[\r\n\]+$gdb_prompt $"
1023 lappend $current_list $subst_item
1025 if {$patterns != ""} {
1026 append patterns "; "
1028 append patterns "\"$subst_item\""
1031 # Also purely cosmetic.
1032 regsub -all {\r} $patterns {\\r} patterns
1033 regsub -all {\n} $patterns {\\n} patterns
1035 if $verbose>2 then {
1036 send_user "Sending \"$command\" to gdb\n"
1037 send_user "Looking to match \"$patterns\"\n"
1038 send_user "Message is \"$message\"\n"
1042 set string "${command}\n"
1043 if { $command != "" } {
1044 set multi_line_re "\[\r\n\] *>"
1045 while { "$string" != "" } {
1046 set foo [string first "\n" "$string"]
1047 set len [string length "$string"]
1048 if { $foo < [expr $len - 1] } {
1049 set str [string range "$string" 0 $foo]
1050 if { [send_gdb "$str"] != "" } {
1051 perror "Couldn't send $command to GDB."
1053 # since we're checking if each line of the multi-line
1054 # command are 'accepted' by GDB here,
1055 # we need to set -notransfer expect option so that
1056 # command output is not lost for pattern matching
1059 -notransfer -re "$multi_line_re$" { verbose "partial: match" 3 }
1060 timeout { verbose "partial: timeout" 3 }
1062 set string [string range "$string" [expr $foo + 1] end]
1063 set multi_line_re "$multi_line_re.*\[\r\n\] *>"
1068 if { "$string" != "" } {
1069 if { [send_gdb "$string"] != "" } {
1070 perror "Couldn't send $command to GDB."
1075 set code $early_processed_code
1077 -re ".*A problem internal to GDB has been detected" {
1078 fail "$message (GDB internal error)"
1079 gdb_internal_error_resync
1082 -re "\\*\\*\\* DOSEXIT code.*" {
1083 if { $message != "" } {
1089 append code $processed_code
1091 # Reset the spawn id, in case the processed code used -i.
1097 -re "Ending remote debugging.*$prompt_regexp" {
1098 if ![isnative] then {
1099 warning "Can`t communicate to remote target."
1105 -re "Undefined\[a-z\]* command:.*$prompt_regexp" {
1106 perror "Undefined command \"$command\"."
1110 -re "Ambiguous command.*$prompt_regexp" {
1111 perror "\"$command\" is not a unique command name."
1115 -re "$inferior_exited_re with code \[0-9\]+.*$prompt_regexp" {
1116 if ![string match "" $message] then {
1117 set errmsg "$message (the program exited)"
1119 set errmsg "$command (the program exited)"
1124 -re "$inferior_exited_re normally.*$prompt_regexp" {
1125 if ![string match "" $message] then {
1126 set errmsg "$message (the program exited)"
1128 set errmsg "$command (the program exited)"
1133 -re "The program is not being run.*$prompt_regexp" {
1134 if ![string match "" $message] then {
1135 set errmsg "$message (the program is no longer running)"
1137 set errmsg "$command (the program is no longer running)"
1142 -re "\r\n$prompt_regexp" {
1143 if ![string match "" $message] then {
1148 -re "$pagination_prompt" {
1150 perror "Window too small."
1154 -re "\\((y or n|y or \\\[n\\\]|\\\[y\\\] or n)\\) " {
1155 send_gdb "n\n" answer
1156 gdb_expect -re "$prompt_regexp"
1157 fail "$message (got interactive prompt)"
1160 -re "\\\[0\\\] cancel\r\n\\\[1\\\] all.*\r\n> $" {
1162 gdb_expect -re "$prompt_regexp"
1163 fail "$message (got breakpoint menu)"
1169 perror "GDB process no longer exists"
1170 set wait_status [wait -i $gdb_spawn_id]
1171 verbose -log "GDB process exited with wait status $wait_status"
1172 if { $message != "" } {
1179 if {$line_by_line} {
1181 -re "\r\n\[^\r\n\]*(?=\r\n)" {
1187 # Now patterns that apply to any spawn id specified.
1191 perror "Process no longer exists"
1192 if { $message != "" } {
1198 perror "internal buffer is full."
1203 if ![string match "" $message] then {
1204 fail "$message (timeout)"
1210 # remote_expect calls the eof section if there is an error on the
1211 # expect call. We already have eof sections above, and we don't
1212 # want them to get called in that situation. Since the last eof
1213 # section becomes the error section, here we define another eof
1214 # section, but with an empty spawn_id list, so that it won't ever
1218 # This comment is here because the eof section must not be
1219 # the empty string, otherwise remote_expect won't realize
1224 # Create gdb_test_name in the parent scope. If this variable
1225 # already exists, which it might if we have nested calls to
1226 # gdb_test_multiple, then preserve the old value, otherwise,
1227 # create a new variable in the parent scope.
1228 upvar gdb_test_name gdb_test_name
1229 if { [info exists gdb_test_name] } {
1230 set gdb_test_name_old "$gdb_test_name"
1232 set gdb_test_name "$message"
1235 set code [catch {gdb_expect $code} string]
1237 # Clean up the gdb_test_name variable. If we had a
1238 # previous value then restore it, otherwise, delete the variable
1239 # from the parent scope.
1240 if { [info exists gdb_test_name_old] } {
1241 set gdb_test_name "$gdb_test_name_old"
1247 global errorInfo errorCode
1248 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
1249 } elseif {$code > 1} {
1250 return -code $code $string
1255 # Usage: gdb_test_multiline NAME INPUT RESULT {INPUT RESULT} ...
1256 # Run a test named NAME, consisting of multiple lines of input.
1257 # After each input line INPUT, search for result line RESULT.
1258 # Succeed if all results are seen; fail otherwise.
1260 proc gdb_test_multiline { name args } {
1263 foreach {input result} $args {
1265 if {[gdb_test_multiple $input "$name: input $inputnr: $input" {
1266 -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
1277 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
1278 # Send a command to gdb; test the result.
1280 # COMMAND is the command to execute, send to GDB with send_gdb. If
1281 # this is the null string no command is sent.
1282 # PATTERN is the pattern to match for a PASS, and must NOT include
1283 # the \r\n sequence immediately before the gdb prompt. This argument
1284 # may be omitted to just match the prompt, ignoring whatever output
1286 # MESSAGE is an optional message to be printed. If this is
1287 # omitted, then the pass/fail messages use the command string as the
1288 # message. (If this is the empty string, then sometimes we don't
1289 # call pass or fail at all; I don't understand this at all.)
1290 # QUESTION is a question GDB may ask in response to COMMAND, like
1292 # RESPONSE is the response to send if QUESTION appears.
1295 # 1 if the test failed,
1296 # 0 if the test passes,
1297 # -1 if there was an internal error.
1299 proc gdb_test { args } {
1301 upvar timeout timeout
1303 if [llength $args]>2 then {
1304 set message [lindex $args 2]
1306 set message [lindex $args 0]
1308 set command [lindex $args 0]
1309 set pattern [lindex $args 1]
1313 -re "\[\r\n\]*(?:$pattern)\[\r\n\]+$gdb_prompt $" {
1314 if ![string match "" $message] then {
1320 if { [llength $args] == 5 } {
1321 set question_string [lindex $args 3]
1322 set response_string [lindex $args 4]
1324 -re "(${question_string})$" {
1325 send_gdb "$response_string\n"
1331 set user_code [join $user_code]
1332 return [gdb_test_multiple $command $message $user_code]
1335 # Return 1 if version MAJOR.MINOR is at least AT_LEAST_MAJOR.AT_LEAST_MINOR.
1336 proc version_at_least { major minor at_least_major at_least_minor} {
1337 if { $major > $at_least_major } {
1339 } elseif { $major == $at_least_major \
1340 && $minor >= $at_least_minor } {
1347 # Return 1 if tcl version used is at least MAJOR.MINOR
1348 proc tcl_version_at_least { major minor } {
1350 regexp {^([0-9]+)\.([0-9]+)$} $tcl_version \
1351 dummy tcl_version_major tcl_version_minor
1352 return [version_at_least $tcl_version_major $tcl_version_minor \
1356 if { [tcl_version_at_least 8 5] == 0 } {
1357 # lrepeat was added in tcl 8.5. Only add if missing.
1358 proc lrepeat { n element } {
1359 if { [string is integer -strict $n] == 0 } {
1360 error "expected integer but got \"$n\""
1363 error "bad count \"$n\": must be integer >= 0"
1366 for {set i 0} {$i < $n} {incr i} {
1367 lappend res $element
1373 # gdb_test_no_output COMMAND MESSAGE
1374 # Send a command to GDB and verify that this command generated no output.
1376 # See gdb_test_multiple for a description of the COMMAND and MESSAGE
1377 # parameters. If MESSAGE is ommitted, then COMMAND will be used as
1378 # the message. (If MESSAGE is the empty string, then sometimes we do not
1379 # call pass or fail at all; I don't understand this at all.)
1381 proc gdb_test_no_output { args } {
1383 set command [lindex $args 0]
1384 if [llength $args]>1 then {
1385 set message [lindex $args 1]
1387 set message $command
1390 set command_regex [string_to_regexp $command]
1391 gdb_test_multiple $command $message {
1392 -re "^$command_regex\r\n$gdb_prompt $" {
1393 if ![string match "" $message] then {
1400 # Send a command and then wait for a sequence of outputs.
1401 # This is useful when the sequence is long and contains ".*", a single
1402 # regexp to match the entire output can get a timeout much easier.
1404 # COMMAND is the command to execute, send to GDB with send_gdb. If
1405 # this is the null string no command is sent.
1406 # TEST_NAME is passed to pass/fail. COMMAND is used if TEST_NAME is "".
1407 # EXPECTED_OUTPUT_LIST is a list of regexps of expected output, which are
1408 # processed in order, and all must be present in the output.
1410 # The -prompt switch can be used to override the prompt expected at the end of
1411 # the output sequence.
1413 # It is unnecessary to specify ".*" at the beginning or end of any regexp,
1414 # there is an implicit ".*" between each element of EXPECTED_OUTPUT_LIST.
1415 # There is also an implicit ".*" between the last regexp and the gdb prompt.
1417 # Like gdb_test and gdb_test_multiple, the output is expected to end with the
1418 # gdb prompt, which must not be specified in EXPECTED_OUTPUT_LIST.
1421 # 1 if the test failed,
1422 # 0 if the test passes,
1423 # -1 if there was an internal error.
1425 proc gdb_test_sequence { args } {
1428 parse_args {{prompt ""}}
1430 if { $prompt == "" } {
1431 set prompt "$gdb_prompt $"
1434 if { [llength $args] != 3 } {
1435 error "Unexpected # of arguments, expecting: COMMAND TEST_NAME EXPECTED_OUTPUT_LIST"
1438 lassign $args command test_name expected_output_list
1440 if { $test_name == "" } {
1441 set test_name $command
1444 lappend expected_output_list ""; # implicit ".*" before gdb prompt
1446 if { $command != "" } {
1447 send_gdb "$command\n"
1450 return [gdb_expect_list $test_name $prompt $expected_output_list]
1454 # Match output of COMMAND using RE. Read output line-by-line.
1455 # Report pass/fail with MESSAGE.
1456 # For a command foo with output:
1461 # the portion matched using RE is:
1466 # Optionally, additional -re-not <regexp> arguments can be specified, to
1467 # ensure that a regexp is not match by the COMMAND output.
1468 # Such an additional argument generates an additional PASS/FAIL of the form:
1469 # PASS: test-case.exp: $message: pattern not matched: <regexp>
1471 proc gdb_test_lines { command message re args } {
1474 for {set i 0} {$i < [llength $args]} {incr i} {
1475 set arg [lindex $args $i]
1476 if { $arg == "-re-not" } {
1478 if { [llength $args] == $i } {
1479 error "Missing argument for -re-not"
1482 set arg [lindex $args $i]
1485 error "Unhandled argument: $arg"
1489 if { $message == ""} {
1490 set message $command
1494 gdb_test_multiple $command $message {
1495 -re "\r\n(\[^\r\n\]*)(?=\r\n)" {
1496 set line $expect_out(1,string)
1497 if { $lines eq "" } {
1498 append lines "$line"
1500 append lines "\r\n$line"
1509 gdb_assert { [regexp $re $lines] } $message
1511 foreach re $re_not {
1512 gdb_assert { ![regexp $re $lines] } "$message: pattern not matched: $re"
1516 # Test that a command gives an error. For pass or fail, return
1517 # a 1 to indicate that more tests can proceed. However a timeout
1518 # is a serious error, generates a special fail message, and causes
1519 # a 0 to be returned to indicate that more tests are likely to fail
1522 proc test_print_reject { args } {
1526 if [llength $args]==2 then {
1527 set expectthis [lindex $args 1]
1529 set expectthis "should never match this bogus string"
1531 set sendthis [lindex $args 0]
1532 if $verbose>2 then {
1533 send_user "Sending \"$sendthis\" to gdb\n"
1534 send_user "Looking to match \"$expectthis\"\n"
1536 send_gdb "$sendthis\n"
1537 #FIXME: Should add timeout as parameter.
1539 -re "A .* in expression.*\\.*$gdb_prompt $" {
1540 pass "reject $sendthis"
1543 -re "Invalid syntax in expression.*$gdb_prompt $" {
1544 pass "reject $sendthis"
1547 -re "Junk after end of expression.*$gdb_prompt $" {
1548 pass "reject $sendthis"
1551 -re "Invalid number.*$gdb_prompt $" {
1552 pass "reject $sendthis"
1555 -re "Invalid character constant.*$gdb_prompt $" {
1556 pass "reject $sendthis"
1559 -re "No symbol table is loaded.*$gdb_prompt $" {
1560 pass "reject $sendthis"
1563 -re "No symbol .* in current context.*$gdb_prompt $" {
1564 pass "reject $sendthis"
1567 -re "Unmatched single quote.*$gdb_prompt $" {
1568 pass "reject $sendthis"
1571 -re "A character constant must contain at least one character.*$gdb_prompt $" {
1572 pass "reject $sendthis"
1575 -re "$expectthis.*$gdb_prompt $" {
1576 pass "reject $sendthis"
1579 -re ".*$gdb_prompt $" {
1580 fail "reject $sendthis"
1584 fail "reject $sendthis (eof or timeout)"
1591 # Same as gdb_test, but the second parameter is not a regexp,
1592 # but a string that must match exactly.
1594 proc gdb_test_exact { args } {
1595 upvar timeout timeout
1597 set command [lindex $args 0]
1599 # This applies a special meaning to a null string pattern. Without
1600 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
1601 # messages from commands that should have no output except a new
1602 # prompt. With this, only results of a null string will match a null
1605 set pattern [lindex $args 1]
1606 if [string match $pattern ""] {
1607 set pattern [string_to_regexp [lindex $args 0]]
1609 set pattern [string_to_regexp [lindex $args 1]]
1612 # It is most natural to write the pattern argument with only
1613 # embedded \n's, especially if you are trying to avoid Tcl quoting
1614 # problems. But gdb_expect really wants to see \r\n in patterns. So
1615 # transform the pattern here. First transform \r\n back to \n, in
1616 # case some users of gdb_test_exact already do the right thing.
1617 regsub -all "\r\n" $pattern "\n" pattern
1618 regsub -all "\n" $pattern "\r\n" pattern
1619 if [llength $args]==3 then {
1620 set message [lindex $args 2]
1621 return [gdb_test $command $pattern $message]
1624 return [gdb_test $command $pattern]
1627 # Wrapper around gdb_test_multiple that looks for a list of expected
1628 # output elements, but which can appear in any order.
1629 # CMD is the gdb command.
1630 # NAME is the name of the test.
1631 # ELM_FIND_REGEXP specifies how to partition the output into elements to
1633 # ELM_EXTRACT_REGEXP specifies the part of ELM_FIND_REGEXP to compare.
1634 # RESULT_MATCH_LIST is a list of exact matches for each expected element.
1635 # All elements of RESULT_MATCH_LIST must appear for the test to pass.
1637 # A typical use of ELM_FIND_REGEXP/ELM_EXTRACT_REGEXP is to extract one line
1638 # of text per element and then strip trailing \r\n's.
1640 # gdb_test_list_exact "foo" "bar" \
1641 # "\[^\r\n\]+\[\r\n\]+" \
1644 # {expected result 1} \
1645 # {expected result 2} \
1648 proc gdb_test_list_exact { cmd name elm_find_regexp elm_extract_regexp result_match_list } {
1651 set matches [lsort $result_match_list]
1653 gdb_test_multiple $cmd $name {
1654 "$cmd\[\r\n\]" { exp_continue }
1655 -re $elm_find_regexp {
1656 set str $expect_out(0,string)
1657 verbose -log "seen: $str" 3
1658 regexp -- $elm_extract_regexp $str elm_seen
1659 verbose -log "extracted: $elm_seen" 3
1660 lappend seen $elm_seen
1663 -re "$gdb_prompt $" {
1665 foreach got [lsort $seen] have $matches {
1666 if {![string equal $got $have]} {
1671 if {[string length $failed] != 0} {
1672 fail "$name ($failed not found)"
1680 # gdb_test_stdio COMMAND INFERIOR_PATTERN GDB_PATTERN MESSAGE
1681 # Send a command to gdb; expect inferior and gdb output.
1683 # See gdb_test_multiple for a description of the COMMAND and MESSAGE
1686 # INFERIOR_PATTERN is the pattern to match against inferior output.
1688 # GDB_PATTERN is the pattern to match against gdb output, and must NOT
1689 # include the \r\n sequence immediately before the gdb prompt, nor the
1690 # prompt. The default is empty.
1692 # Both inferior and gdb patterns must match for a PASS.
1694 # If MESSAGE is ommitted, then COMMAND will be used as the message.
1697 # 1 if the test failed,
1698 # 0 if the test passes,
1699 # -1 if there was an internal error.
1702 proc gdb_test_stdio {command inferior_pattern {gdb_pattern ""} {message ""}} {
1703 global inferior_spawn_id gdb_spawn_id
1706 if {$message == ""} {
1707 set message $command
1710 set inferior_matched 0
1713 # Use an indirect spawn id list, and remove the inferior spawn id
1714 # from the expected output as soon as it matches, in case
1715 # $inferior_pattern happens to be a prefix of the resulting full
1716 # gdb pattern below (e.g., "\r\n").
1717 global gdb_test_stdio_spawn_id_list
1718 set gdb_test_stdio_spawn_id_list "$inferior_spawn_id"
1720 # Note that if $inferior_spawn_id and $gdb_spawn_id are different,
1721 # then we may see gdb's output arriving before the inferior's
1723 set res [gdb_test_multiple $command $message {
1724 -i gdb_test_stdio_spawn_id_list -re "$inferior_pattern" {
1725 set inferior_matched 1
1726 if {!$gdb_matched} {
1727 set gdb_test_stdio_spawn_id_list ""
1731 -i $gdb_spawn_id -re "$gdb_pattern\r\n$gdb_prompt $" {
1733 if {!$inferior_matched} {
1741 verbose -log "inferior_matched=$inferior_matched, gdb_matched=$gdb_matched"
1746 # Wrapper around gdb_test_multiple to be used when testing expression
1747 # evaluation while 'set debug expression 1' is in effect.
1748 # Looks for some patterns that indicates the expression was rejected.
1750 # CMD is the command to execute, which should include an expression
1751 # that GDB will need to parse.
1753 # OUTPUT is the expected output pattern.
1755 # TESTNAME is the name to be used for the test, defaults to CMD if not
1757 proc gdb_test_debug_expr { cmd output {testname "" }} {
1760 if { ${testname} == "" } {
1764 gdb_test_multiple $cmd $testname {
1765 -re ".*Invalid expression.*\r\n$gdb_prompt $" {
1768 -re ".*\[\r\n\]$output\r\n$gdb_prompt $" {
1774 # get_print_expr_at_depths EXP OUTPUTS
1776 # Used for testing 'set print max-depth'. Prints the expression EXP
1777 # with 'set print max-depth' set to various depths. OUTPUTS is a list
1778 # of `n` different patterns to match at each of the depths from 0 to
1781 # This proc does one final check with the max-depth set to 'unlimited'
1782 # which is tested against the last pattern in the OUTPUTS list. The
1783 # OUTPUTS list is therefore required to match every depth from 0 to a
1784 # depth where the whole of EXP is printed with no ellipsis.
1786 # This proc leaves the 'set print max-depth' set to 'unlimited'.
1787 proc gdb_print_expr_at_depths {exp outputs} {
1788 for { set depth 0 } { $depth <= [llength $outputs] } { incr depth } {
1789 if { $depth == [llength $outputs] } {
1790 set expected_result [lindex $outputs [expr [llength $outputs] - 1]]
1791 set depth_string "unlimited"
1793 set expected_result [lindex $outputs $depth]
1794 set depth_string $depth
1797 with_test_prefix "exp='$exp': depth=${depth_string}" {
1798 gdb_test_no_output "set print max-depth ${depth_string}"
1799 gdb_test "p $exp" "$expected_result"
1806 # Issue a PASS and return true if evaluating CONDITION in the caller's
1807 # frame returns true, and issue a FAIL and return false otherwise.
1808 # MESSAGE is the pass/fail message to be printed. If MESSAGE is
1809 # omitted or is empty, then the pass/fail messages use the condition
1810 # string as the message.
1812 proc gdb_assert { condition {message ""} } {
1813 if { $message == ""} {
1814 set message $condition
1817 set code [catch {uplevel 1 expr $condition} res]
1819 # If code is 1 (TCL_ERROR), it means evaluation failed and res contains
1820 # an error message. Print the error message, and set res to 0 since we
1821 # want to return a boolean.
1822 warning "While evaluating expression in gdb_assert: $res"
1825 } elseif { !$res } {
1833 proc gdb_reinitialize_dir { subdir } {
1836 if [is_remote host] {
1841 -re "Reinitialize source path to empty.*y or n. " {
1842 send_gdb "y\n" answer
1844 -re "Source directories searched.*$gdb_prompt $" {
1845 send_gdb "dir $subdir\n"
1847 -re "Source directories searched.*$gdb_prompt $" {
1848 verbose "Dir set to $subdir"
1850 -re "$gdb_prompt $" {
1851 perror "Dir \"$subdir\" failed."
1855 -re "$gdb_prompt $" {
1856 perror "Dir \"$subdir\" failed."
1860 -re "$gdb_prompt $" {
1861 perror "Dir \"$subdir\" failed."
1867 # gdb_exit -- exit the GDB, killing the target program if necessary
1869 proc default_gdb_exit {} {
1871 global INTERNAL_GDBFLAGS GDBFLAGS
1872 global gdb_spawn_id inferior_spawn_id
1873 global inotify_log_file
1875 if ![info exists gdb_spawn_id] {
1879 verbose "Quitting $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1881 if {[info exists inotify_log_file] && [file exists $inotify_log_file]} {
1882 set fd [open $inotify_log_file]
1883 set data [read -nonewline $fd]
1886 if {[string compare $data ""] != 0} {
1887 warning "parallel-unsafe file creations noticed"
1890 set fd [open $inotify_log_file w]
1895 if { [is_remote host] && [board_info host exists fileid] } {
1899 send_gdb "y\n" answer
1902 -re "DOSEXIT code" { }
1907 if ![is_remote host] {
1911 unset ::gdb_tty_name
1912 unset inferior_spawn_id
1915 # Load a file into the debugger.
1916 # The return value is 0 for success, -1 for failure.
1918 # This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO
1919 # to one of these values:
1921 # debug file was loaded successfully and has debug information
1922 # nodebug file was loaded successfully and has no debug information
1923 # lzma file was loaded, .gnu_debugdata found, but no LZMA support
1925 # fail file was not loaded
1927 # This procedure also set the global variable GDB_FILE_CMD_MSG to the
1928 # output of the file command in case of success.
1930 # I tried returning this information as part of the return value,
1931 # but ran into a mess because of the many re-implementations of
1932 # gdb_load in config/*.exp.
1934 # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use
1935 # this if they can get more information set.
1937 proc gdb_file_cmd { arg } {
1940 global last_loaded_file
1942 # GCC for Windows target may create foo.exe given "-o foo".
1943 if { ![file exists $arg] && [file exists "$arg.exe"] } {
1947 # Save this for the benefit of gdbserver-support.exp.
1948 set last_loaded_file $arg
1950 # Set whether debug info was found.
1951 # Default to "fail".
1952 global gdb_file_cmd_debug_info gdb_file_cmd_msg
1953 set gdb_file_cmd_debug_info "fail"
1955 if [is_remote host] {
1956 set arg [remote_download host $arg]
1958 perror "download failed"
1963 # The file command used to kill the remote target. For the benefit
1964 # of the testsuite, preserve this behavior. Mark as optional so it doesn't
1965 # get written to the stdin log.
1966 send_gdb "kill\n" optional
1968 -re "Kill the program being debugged. .y or n. $" {
1969 send_gdb "y\n" answer
1970 verbose "\t\tKilling previous program being debugged"
1973 -re "$gdb_prompt $" {
1978 send_gdb "file $arg\n"
1979 set new_symbol_table 0
1980 set basename [file tail $arg]
1982 -re "(Reading symbols from.*LZMA support was disabled.*$gdb_prompt $)" {
1983 verbose "\t\tLoaded $arg into $GDB; .gnu_debugdata found but no LZMA available"
1984 set gdb_file_cmd_msg $expect_out(1,string)
1985 set gdb_file_cmd_debug_info "lzma"
1988 -re "(Reading symbols from.*no debugging symbols found.*$gdb_prompt $)" {
1989 verbose "\t\tLoaded $arg into $GDB with no debugging symbols"
1990 set gdb_file_cmd_msg $expect_out(1,string)
1991 set gdb_file_cmd_debug_info "nodebug"
1994 -re "(Reading symbols from.*$gdb_prompt $)" {
1995 verbose "\t\tLoaded $arg into $GDB"
1996 set gdb_file_cmd_msg $expect_out(1,string)
1997 set gdb_file_cmd_debug_info "debug"
2000 -re "Load new symbol table from \".*\".*y or n. $" {
2001 if { $new_symbol_table > 0 } {
2002 perror [join [list "Couldn't load $basename,"
2003 "interactive prompt loop detected."]]
2006 send_gdb "y\n" answer
2007 incr new_symbol_table
2008 set suffix "-- with new symbol table"
2009 set arg "$arg $suffix"
2010 set basename "$basename $suffix"
2013 -re "No such file or directory.*$gdb_prompt $" {
2014 perror "($basename) No such file or directory"
2017 -re "A problem internal to GDB has been detected" {
2018 perror "Couldn't load $basename into GDB (GDB internal error)."
2019 gdb_internal_error_resync
2022 -re "$gdb_prompt $" {
2023 perror "Couldn't load $basename into GDB."
2027 perror "Couldn't load $basename into GDB (timeout)."
2031 # This is an attempt to detect a core dump, but seems not to
2032 # work. Perhaps we need to match .* followed by eof, in which
2033 # gdb_expect does not seem to have a way to do that.
2034 perror "Couldn't load $basename into GDB (eof)."
2040 # The expect "spawn" function puts the tty name into the spawn_out
2041 # array; but dejagnu doesn't export this globally. So, we have to
2042 # wrap spawn with our own function and poke in the built-in spawn
2043 # so that we can capture this value.
2045 # If available, the TTY name is saved to the LAST_SPAWN_TTY_NAME global.
2046 # Otherwise, LAST_SPAWN_TTY_NAME is unset.
2048 proc spawn_capture_tty_name { args } {
2049 set result [uplevel builtin_spawn $args]
2050 upvar spawn_out spawn_out
2051 if { [info exists spawn_out(slave,name)] } {
2052 set ::last_spawn_tty_name $spawn_out(slave,name)
2054 # If a process is spawned as part of a pipe line (e.g. passing
2055 # -leaveopen to the spawn proc) then the spawned process is no
2056 # assigned a tty and spawn_out(slave,name) will not be set.
2057 # In that case we want to ensure that last_spawn_tty_name is
2060 # If the previous process spawned was also not assigned a tty
2061 # (e.g. multiple processed chained in a pipeline) then
2062 # last_spawn_tty_name will already be unset, so, if we don't
2063 # use -nocomplain here we would otherwise get an error.
2064 unset -nocomplain ::last_spawn_tty_name
2069 rename spawn builtin_spawn
2070 rename spawn_capture_tty_name spawn
2072 # Default gdb_spawn procedure.
2074 proc default_gdb_spawn { } {
2077 global INTERNAL_GDBFLAGS GDBFLAGS
2080 # Set the default value, it may be overriden later by specific testfile.
2082 # Use `set_board_info use_gdb_stub' for the board file to flag the inferior
2083 # is already started after connecting and run/attach are not supported.
2084 # This is used for the "remote" protocol. After GDB starts you should
2085 # check global $use_gdb_stub instead of the board as the testfile may force
2086 # a specific different target protocol itself.
2087 set use_gdb_stub [target_info exists use_gdb_stub]
2089 verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
2090 gdb_write_cmd_file "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
2092 if [info exists gdb_spawn_id] {
2096 if ![is_remote host] {
2097 if { [which $GDB] == 0 } then {
2098 perror "$GDB does not exist."
2102 set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"]
2103 if { $res < 0 || $res == "" } {
2104 perror "Spawning $GDB failed."
2108 set gdb_spawn_id $res
2109 set ::gdb_tty_name $::last_spawn_tty_name
2113 # Default gdb_start procedure.
2115 proc default_gdb_start { } {
2118 global inferior_spawn_id
2120 if [info exists gdb_spawn_id] {
2124 # Keep track of the number of times GDB has been launched.
2125 global gdb_instances
2135 # Default to assuming inferior I/O is done on GDB's terminal.
2136 if {![info exists inferior_spawn_id]} {
2137 set inferior_spawn_id $gdb_spawn_id
2140 # When running over NFS, particularly if running many simultaneous
2141 # tests on different hosts all using the same server, things can
2142 # get really slow. Give gdb at least 3 minutes to start up.
2144 -re "\[\r\n\]$gdb_prompt $" {
2145 verbose "GDB initialized."
2147 -re "$gdb_prompt $" {
2148 perror "GDB never initialized."
2153 perror "(timeout) GDB never initialized after 10 seconds."
2159 perror "(eof) GDB never initialized."
2165 # force the height to "unlimited", so no pagers get used
2167 send_gdb "set height 0\n"
2169 -re "$gdb_prompt $" {
2170 verbose "Setting height to 0." 2
2173 warning "Couldn't set the height to 0"
2176 # force the width to "unlimited", so no wraparound occurs
2177 send_gdb "set width 0\n"
2179 -re "$gdb_prompt $" {
2180 verbose "Setting width to 0." 2
2183 warning "Couldn't set the width to 0."
2191 # Utility procedure to give user control of the gdb prompt in a script. It is
2192 # meant to be used for debugging test cases, and should not be left in the
2195 proc gdb_interact { } {
2197 set spawn_id $gdb_spawn_id
2199 send_user "+------------------------------------------+\n"
2200 send_user "| Script interrupted, you can now interact |\n"
2201 send_user "| with by gdb. Type >>> to continue. |\n"
2202 send_user "+------------------------------------------+\n"
2209 # Examine the output of compilation to determine whether compilation
2210 # failed or not. If it failed determine whether it is due to missing
2211 # compiler or due to compiler error. Report pass, fail or unsupported
2214 proc gdb_compile_test {src output} {
2215 set msg "compilation [file tail $src]"
2217 if { $output == "" } {
2222 if { [regexp {^[a-zA-Z_0-9]+: Can't find [^ ]+\.$} $output]
2223 || [regexp {.*: command not found[\r|\n]*$} $output]
2224 || [regexp {.*: [^\r\n]*compiler not installed[^\r\n]*[\r|\n]*$} $output] } {
2225 unsupported "$msg (missing compiler)"
2229 set gcc_re ".*: error: unrecognized command line option "
2230 set clang_re ".*: error: unsupported option "
2231 if { [regexp "(?:$gcc_re|$clang_re)(\[^ \t;\r\n\]*)" $output dummy option]
2232 && $option != "" } {
2233 unsupported "$msg (unsupported option $option)"
2237 # Unclassified compilation failure, be more verbose.
2238 verbose -log "compilation failed: $output" 2
2242 # Return a 1 for configurations for which we don't even want to try to
2245 proc skip_cplus_tests {} {
2246 if { [istarget "h8300-*-*"] } {
2250 # The C++ IO streams are too large for HC11/HC12 and are thus not
2251 # available. The gdb C++ tests use them and don't compile.
2252 if { [istarget "m6811-*-*"] } {
2255 if { [istarget "m6812-*-*"] } {
2261 # Return a 1 for configurations for which don't have both C++ and the STL.
2263 proc skip_stl_tests {} {
2264 return [skip_cplus_tests]
2267 # Return a 1 if I don't even want to try to test FORTRAN.
2269 proc skip_fortran_tests {} {
2273 # Return a 1 if I don't even want to try to test ada.
2275 proc skip_ada_tests {} {
2279 # Return a 1 if I don't even want to try to test GO.
2281 proc skip_go_tests {} {
2285 # Return a 1 if I don't even want to try to test D.
2287 proc skip_d_tests {} {
2291 # Return 1 to skip Rust tests, 0 to try them.
2292 proc skip_rust_tests {} {
2293 if { ![isnative] } {
2297 # The rust compiler does not support "-m32", skip.
2298 global board board_info
2299 set board [target_info name]
2300 if {[board_info $board exists multilib_flags]} {
2301 foreach flag [board_info $board multilib_flags] {
2302 if { $flag == "-m32" } {
2311 # Return a 1 for configurations that do not support Python scripting.
2312 # PROMPT_REGEXP is the expected prompt.
2314 proc skip_python_tests_prompt { prompt_regexp } {
2315 global gdb_py_is_py3k
2317 gdb_test_multiple "python print ('test')" "verify python support" \
2318 -prompt "$prompt_regexp" {
2319 -re "not supported.*$prompt_regexp" {
2320 unsupported "Python support is disabled."
2323 -re "$prompt_regexp" {}
2326 gdb_test_multiple "python print (sys.version_info\[0\])" "check if python 3" \
2327 -prompt "$prompt_regexp" {
2328 -re "3.*$prompt_regexp" {
2329 set gdb_py_is_py3k 1
2331 -re ".*$prompt_regexp" {
2332 set gdb_py_is_py3k 0
2339 # Return a 1 for configurations that do not support Python scripting.
2340 # Note: This also sets various globals that specify which version of Python
2341 # is in use. See skip_python_tests_prompt.
2343 proc skip_python_tests {} {
2345 return [skip_python_tests_prompt "$gdb_prompt $"]
2348 # Return a 1 if we should skip shared library tests.
2350 proc skip_shlib_tests {} {
2351 # Run the shared library tests on native systems.
2356 # An abbreviated list of remote targets where we should be able to
2357 # run shared library tests.
2358 if {([istarget *-*-linux*]
2359 || [istarget *-*-*bsd*]
2360 || [istarget *-*-solaris2*]
2361 || [istarget *-*-mingw*]
2362 || [istarget *-*-cygwin*]
2363 || [istarget *-*-pe*])} {
2370 # Return 1 if we should skip tui related tests.
2372 proc skip_tui_tests {} {
2375 gdb_test_multiple "help layout" "verify tui support" {
2376 -re "Undefined command: \"layout\".*$gdb_prompt $" {
2379 -re "$gdb_prompt $" {
2386 # Test files shall make sure all the test result lines in gdb.sum are
2387 # unique in a test run, so that comparing the gdb.sum files of two
2388 # test runs gives correct results. Test files that exercise
2389 # variations of the same tests more than once, shall prefix the
2390 # different test invocations with different identifying strings in
2391 # order to make them unique.
2393 # About test prefixes:
2395 # $pf_prefix is the string that dejagnu prints after the result (FAIL,
2396 # PASS, etc.), and before the test message/name in gdb.sum. E.g., the
2397 # underlined substring in
2399 # PASS: gdb.base/mytest.exp: some test
2400 # ^^^^^^^^^^^^^^^^^^^^
2404 # The easiest way to adjust the test prefix is to append a test
2405 # variation prefix to the $pf_prefix, using the with_test_prefix
2408 # proc do_tests {} {
2409 # gdb_test ... ... "test foo"
2410 # gdb_test ... ... "test bar"
2412 # with_test_prefix "subvariation a" {
2413 # gdb_test ... ... "test x"
2416 # with_test_prefix "subvariation b" {
2417 # gdb_test ... ... "test x"
2421 # with_test_prefix "variation1" {
2422 # ...do setup for variation 1...
2426 # with_test_prefix "variation2" {
2427 # ...do setup for variation 2...
2433 # PASS: gdb.base/mytest.exp: variation1: test foo
2434 # PASS: gdb.base/mytest.exp: variation1: test bar
2435 # PASS: gdb.base/mytest.exp: variation1: subvariation a: test x
2436 # PASS: gdb.base/mytest.exp: variation1: subvariation b: test x
2437 # PASS: gdb.base/mytest.exp: variation2: test foo
2438 # PASS: gdb.base/mytest.exp: variation2: test bar
2439 # PASS: gdb.base/mytest.exp: variation2: subvariation a: test x
2440 # PASS: gdb.base/mytest.exp: variation2: subvariation b: test x
2442 # If for some reason more flexibility is necessary, one can also
2443 # manipulate the pf_prefix global directly, treating it as a string.
2447 # set saved_pf_prefix
2448 # append pf_prefix "${foo}: bar"
2449 # ... actual tests ...
2450 # set pf_prefix $saved_pf_prefix
2453 # Run BODY in the context of the caller, with the current test prefix
2454 # (pf_prefix) appended with one space, then PREFIX, and then a colon.
2455 # Returns the result of BODY.
2457 proc with_test_prefix { prefix body } {
2460 set saved $pf_prefix
2461 append pf_prefix " " $prefix ":"
2462 set code [catch {uplevel 1 $body} result]
2463 set pf_prefix $saved
2466 global errorInfo errorCode
2467 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2469 return -code $code $result
2473 # Wrapper for foreach that calls with_test_prefix on each iteration,
2474 # including the iterator's name and current value in the prefix.
2476 proc foreach_with_prefix {var list body} {
2478 foreach myvar $list {
2479 with_test_prefix "$var=$myvar" {
2480 set code [catch {uplevel 1 $body} result]
2484 global errorInfo errorCode
2485 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2486 } elseif {$code == 3} {
2488 } elseif {$code == 2} {
2489 return -code $code $result
2494 # Like TCL's native proc, but defines a procedure that wraps its body
2495 # within 'with_test_prefix "$proc_name" { ... }'.
2496 proc proc_with_prefix {name arguments body} {
2497 # Define the advertised proc.
2498 proc $name $arguments [list with_test_prefix $name $body]
2502 # Run BODY in the context of the caller. After BODY is run, the variables
2503 # listed in VARS will be reset to the values they had before BODY was run.
2505 # This is useful for providing a scope in which it is safe to temporarily
2506 # modify global variables, e.g.
2508 # global INTERNAL_GDBFLAGS
2511 # set foo GDBHISTSIZE
2513 # save_vars { INTERNAL_GDBFLAGS env($foo) env(HOME) } {
2514 # append INTERNAL_GDBFLAGS " -nx"
2515 # unset -nocomplain env(GDBHISTSIZE)
2520 # Here, although INTERNAL_GDBFLAGS, env(GDBHISTSIZE) and env(HOME) may be
2521 # modified inside BODY, this proc guarantees that the modifications will be
2522 # undone after BODY finishes executing.
2524 proc save_vars { vars body } {
2525 array set saved_scalars { }
2526 array set saved_arrays { }
2530 # First evaluate VAR in the context of the caller in case the variable
2531 # name may be a not-yet-interpolated string like env($foo)
2532 set var [uplevel 1 list $var]
2534 if [uplevel 1 [list info exists $var]] {
2535 if [uplevel 1 [list array exists $var]] {
2536 set saved_arrays($var) [uplevel 1 [list array get $var]]
2538 set saved_scalars($var) [uplevel 1 [list set $var]]
2541 lappend unset_vars $var
2545 set code [catch {uplevel 1 $body} result]
2547 foreach {var value} [array get saved_scalars] {
2548 uplevel 1 [list set $var $value]
2551 foreach {var value} [array get saved_arrays] {
2552 uplevel 1 [list unset $var]
2553 uplevel 1 [list array set $var $value]
2556 foreach var $unset_vars {
2557 uplevel 1 [list unset -nocomplain $var]
2561 global errorInfo errorCode
2562 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2564 return -code $code $result
2568 # As save_vars, but for variables stored in the board_info for the
2573 # save_target_board_info { multilib_flags } {
2575 # set board [target_info name]
2576 # unset_board_info multilib_flags
2577 # set_board_info multilib_flags "$multilib_flags"
2581 proc save_target_board_info { vars body } {
2582 global board board_info
2583 set board [target_info name]
2585 array set saved_target_board_info { }
2586 set unset_target_board_info { }
2589 if { [info exists board_info($board,$var)] } {
2590 set saved_target_board_info($var) [board_info $board $var]
2592 lappend unset_target_board_info $var
2596 set code [catch {uplevel 1 $body} result]
2598 foreach {var value} [array get saved_target_board_info] {
2599 unset_board_info $var
2600 set_board_info $var $value
2603 foreach var $unset_target_board_info {
2604 unset_board_info $var
2608 global errorInfo errorCode
2609 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2611 return -code $code $result
2615 # Run tests in BODY with the current working directory (CWD) set to
2616 # DIR. When BODY is finished, restore the original CWD. Return the
2619 # This procedure doesn't check if DIR is a valid directory, so you
2620 # have to make sure of that.
2622 proc with_cwd { dir body } {
2624 verbose -log "Switching to directory $dir (saved CWD: $saved_dir)."
2627 set code [catch {uplevel 1 $body} result]
2629 verbose -log "Switching back to $saved_dir."
2633 global errorInfo errorCode
2634 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2636 return -code $code $result
2640 # Run tests in BODY with GDB prompt and variable $gdb_prompt set to
2641 # PROMPT. When BODY is finished, restore GDB prompt and variable
2643 # Returns the result of BODY.
2647 # 1) If you want to use, for example, "(foo)" as the prompt you must pass it
2648 # as "(foo)", and not the regexp form "\(foo\)" (expressed as "\\(foo\\)" in
2649 # TCL). PROMPT is internally converted to a suitable regexp for matching.
2650 # We do the conversion from "(foo)" to "\(foo\)" here for a few reasons:
2651 # a) It's more intuitive for callers to pass the plain text form.
2652 # b) We need two forms of the prompt:
2653 # - a regexp to use in output matching,
2654 # - a value to pass to the "set prompt" command.
2655 # c) It's easier to convert the plain text form to its regexp form.
2657 # 2) Don't add a trailing space, we do that here.
2659 proc with_gdb_prompt { prompt body } {
2662 # Convert "(foo)" to "\(foo\)".
2663 # We don't use string_to_regexp because while it works today it's not
2664 # clear it will work tomorrow: the value we need must work as both a
2665 # regexp *and* as the argument to the "set prompt" command, at least until
2666 # we start recording both forms separately instead of just $gdb_prompt.
2667 # The testsuite is pretty-much hardwired to interpret $gdb_prompt as the
2669 regsub -all {[]*+.|()^$\[\\]} $prompt {\\&} prompt
2671 set saved $gdb_prompt
2673 verbose -log "Setting gdb prompt to \"$prompt \"."
2674 set gdb_prompt $prompt
2675 gdb_test_no_output "set prompt $prompt " ""
2677 set code [catch {uplevel 1 $body} result]
2679 verbose -log "Restoring gdb prompt to \"$saved \"."
2680 set gdb_prompt $saved
2681 gdb_test_no_output "set prompt $saved " ""
2684 global errorInfo errorCode
2685 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2687 return -code $code $result
2691 # Run tests in BODY with target-charset setting to TARGET_CHARSET. When
2692 # BODY is finished, restore target-charset.
2694 proc with_target_charset { target_charset body } {
2698 gdb_test_multiple "show target-charset" "" {
2699 -re "The target character set is \".*; currently (.*)\"\..*$gdb_prompt " {
2700 set saved $expect_out(1,string)
2702 -re "The target character set is \"(.*)\".*$gdb_prompt " {
2703 set saved $expect_out(1,string)
2705 -re ".*$gdb_prompt " {
2706 fail "get target-charset"
2710 gdb_test_no_output "set target-charset $target_charset" ""
2712 set code [catch {uplevel 1 $body} result]
2714 gdb_test_no_output "set target-charset $saved" ""
2717 global errorInfo errorCode
2718 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2720 return -code $code $result
2724 # Switch the default spawn id to SPAWN_ID, so that gdb_test,
2725 # mi_gdb_test etc. default to using it.
2727 proc switch_gdb_spawn_id {spawn_id} {
2729 global board board_info
2731 set gdb_spawn_id $spawn_id
2732 set board [host_info name]
2733 set board_info($board,fileid) $spawn_id
2736 # Clear the default spawn id.
2738 proc clear_gdb_spawn_id {} {
2740 global board board_info
2742 unset -nocomplain gdb_spawn_id
2743 set board [host_info name]
2744 unset -nocomplain board_info($board,fileid)
2747 # Run BODY with SPAWN_ID as current spawn id.
2749 proc with_spawn_id { spawn_id body } {
2752 if [info exists gdb_spawn_id] {
2753 set saved_spawn_id $gdb_spawn_id
2756 switch_gdb_spawn_id $spawn_id
2758 set code [catch {uplevel 1 $body} result]
2760 if [info exists saved_spawn_id] {
2761 switch_gdb_spawn_id $saved_spawn_id
2767 global errorInfo errorCode
2768 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2770 return -code $code $result
2774 # Select the largest timeout from all the timeouts:
2775 # - the local "timeout" variable of the scope two levels above,
2776 # - the global "timeout" variable,
2777 # - the board variable "gdb,timeout".
2779 proc get_largest_timeout {} {
2780 upvar #0 timeout gtimeout
2781 upvar 2 timeout timeout
2784 if [info exists timeout] {
2787 if { [info exists gtimeout] && $gtimeout > $tmt } {
2790 if { [target_info exists gdb,timeout]
2791 && [target_info gdb,timeout] > $tmt } {
2792 set tmt [target_info gdb,timeout]
2802 # Run tests in BODY with timeout increased by factor of FACTOR. When
2803 # BODY is finished, restore timeout.
2805 proc with_timeout_factor { factor body } {
2808 set savedtimeout $timeout
2810 set timeout [expr [get_largest_timeout] * $factor]
2811 set code [catch {uplevel 1 $body} result]
2813 set timeout $savedtimeout
2815 global errorInfo errorCode
2816 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2818 return -code $code $result
2822 # Run BODY with timeout factor FACTOR if check-read1 is used.
2824 proc with_read1_timeout_factor { factor body } {
2825 if { [info exists ::env(READ1)] == 1 && $::env(READ1) == 1 } {
2826 # Use timeout factor
2828 # Reset timeout factor
2831 return [uplevel [list with_timeout_factor $factor $body]]
2834 # Return 1 if _Complex types are supported, otherwise, return 0.
2836 gdb_caching_proc support_complex_tests {
2838 if { [gdb_skip_float_test] } {
2839 # If floating point is not supported, _Complex is not
2844 # Compile a test program containing _Complex types.
2846 return [gdb_can_simple_compile complex {
2850 _Complex long double cld;
2856 # Return 1 if compiling go is supported.
2857 gdb_caching_proc support_go_compile {
2859 return [gdb_can_simple_compile go-hello {
2863 fmt.Println("hello world")
2868 # Return 1 if GDB can get a type for siginfo from the target, otherwise
2871 proc supports_get_siginfo_type {} {
2872 if { [istarget "*-*-linux*"] } {
2879 # Return 1 if memory tagging is supported at runtime, otherwise return 0.
2881 gdb_caching_proc supports_memtag {
2884 gdb_test_multiple "memory-tag check" "" {
2885 -re "Memory tagging not supported or disabled by the current architecture\..*$gdb_prompt $" {
2888 -re "Argument required \\(address or pointer\\).*$gdb_prompt $" {
2895 # Return 1 if the target supports hardware single stepping.
2897 proc can_hardware_single_step {} {
2899 if { [istarget "arm*-*-*"] || [istarget "mips*-*-*"]
2900 || [istarget "tic6x-*-*"] || [istarget "sparc*-*-linux*"]
2901 || [istarget "nios2-*-*"] || [istarget "riscv*-*-linux*"] } {
2908 # Return 1 if target hardware or OS supports single stepping to signal
2909 # handler, otherwise, return 0.
2911 proc can_single_step_to_signal_handler {} {
2912 # Targets don't have hardware single step. On these targets, when
2913 # a signal is delivered during software single step, gdb is unable
2914 # to determine the next instruction addresses, because start of signal
2915 # handler is one of them.
2916 return [can_hardware_single_step]
2919 # Return 1 if target supports process record, otherwise return 0.
2921 proc supports_process_record {} {
2923 if [target_info exists gdb,use_precord] {
2924 return [target_info gdb,use_precord]
2927 if { [istarget "arm*-*-linux*"] || [istarget "x86_64-*-linux*"]
2928 || [istarget "i\[34567\]86-*-linux*"]
2929 || [istarget "aarch64*-*-linux*"]
2930 || [istarget "powerpc*-*-linux*"]
2931 || [istarget "s390*-*-linux*"] } {
2938 # Return 1 if target supports reverse debugging, otherwise return 0.
2940 proc supports_reverse {} {
2942 if [target_info exists gdb,can_reverse] {
2943 return [target_info gdb,can_reverse]
2946 if { [istarget "arm*-*-linux*"] || [istarget "x86_64-*-linux*"]
2947 || [istarget "i\[34567\]86-*-linux*"]
2948 || [istarget "aarch64*-*-linux*"]
2949 || [istarget "powerpc*-*-linux*"]
2950 || [istarget "s390*-*-linux*"] } {
2957 # Return 1 if readline library is used.
2959 proc readline_is_used { } {
2962 gdb_test_multiple "show editing" "" {
2963 -re ".*Editing of command lines as they are typed is on\..*$gdb_prompt $" {
2966 -re ".*$gdb_prompt $" {
2972 # Return 1 if target is ELF.
2973 gdb_caching_proc is_elf_target {
2974 set me "is_elf_target"
2976 set src { int foo () {return 0;} }
2977 if {![gdb_simple_compile elf_target $src]} {
2981 set fp_obj [open $obj "r"]
2982 fconfigure $fp_obj -translation binary
2983 set data [read $fp_obj]
2988 set ELFMAG "\u007FELF"
2990 if {[string compare -length 4 $data $ELFMAG] != 0} {
2991 verbose "$me: returning 0" 2
2995 verbose "$me: returning 1" 2
2999 # Return 1 if the memory at address zero is readable.
3001 gdb_caching_proc is_address_zero_readable {
3005 gdb_test_multiple "x 0" "" {
3006 -re "Cannot access memory at address 0x0.*$gdb_prompt $" {
3009 -re ".*$gdb_prompt $" {
3017 # Produce source file NAME and write SOURCES into it.
3019 proc gdb_produce_source { name sources } {
3021 set f [open $name "w"]
3027 # Return 1 if target is ILP32.
3028 # This cannot be decided simply from looking at the target string,
3029 # as it might depend on externally passed compiler options like -m64.
3030 gdb_caching_proc is_ilp32_target {
3031 return [gdb_can_simple_compile is_ilp32_target {
3032 int dummy[sizeof (int) == 4
3033 && sizeof (void *) == 4
3034 && sizeof (long) == 4 ? 1 : -1];
3038 # Return 1 if target is LP64.
3039 # This cannot be decided simply from looking at the target string,
3040 # as it might depend on externally passed compiler options like -m64.
3041 gdb_caching_proc is_lp64_target {
3042 return [gdb_can_simple_compile is_lp64_target {
3043 int dummy[sizeof (int) == 4
3044 && sizeof (void *) == 8
3045 && sizeof (long) == 8 ? 1 : -1];
3049 # Return 1 if target has 64 bit addresses.
3050 # This cannot be decided simply from looking at the target string,
3051 # as it might depend on externally passed compiler options like -m64.
3052 gdb_caching_proc is_64_target {
3053 return [gdb_can_simple_compile is_64_target {
3054 int function(void) { return 3; }
3055 int dummy[sizeof (&function) == 8 ? 1 : -1];
3059 # Return 1 if target has x86_64 registers - either amd64 or x32.
3060 # x32 target identifies as x86_64-*-linux*, therefore it cannot be determined
3061 # just from the target string.
3062 gdb_caching_proc is_amd64_regs_target {
3063 if {![istarget "x86_64-*-*"] && ![istarget "i?86-*"]} {
3067 return [gdb_can_simple_compile is_amd64_regs_target {
3077 # Return 1 if this target is an x86 or x86-64 with -m32.
3078 proc is_x86_like_target {} {
3079 if {![istarget "x86_64-*-*"] && ![istarget i?86-*]} {
3082 return [expr [is_ilp32_target] && ![is_amd64_regs_target]]
3085 # Return 1 if this target is an arm or aarch32 on aarch64.
3087 gdb_caching_proc is_aarch32_target {
3088 if { [istarget "arm*-*-*"] } {
3092 if { ![istarget "aarch64*-*-*"] } {
3099 lappend list "\tmov $reg, $reg"
3102 return [gdb_can_simple_compile aarch32 [join $list \n]]
3105 # Return 1 if this target is an aarch64, either lp64 or ilp32.
3107 proc is_aarch64_target {} {
3108 if { ![istarget "aarch64*-*-*"] } {
3112 return [expr ![is_aarch32_target]]
3115 # Return 1 if displaced stepping is supported on target, otherwise, return 0.
3116 proc support_displaced_stepping {} {
3118 if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"]
3119 || [istarget "arm*-*-linux*"] || [istarget "powerpc-*-linux*"]
3120 || [istarget "powerpc64-*-linux*"] || [istarget "s390*-*-*"]
3121 || [istarget "aarch64*-*-linux*"] } {
3128 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
3129 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
3131 gdb_caching_proc skip_altivec_tests {
3132 global srcdir subdir gdb_prompt inferior_exited_re
3134 set me "skip_altivec_tests"
3136 # Some simulators are known to not support VMX instructions.
3137 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
3138 verbose "$me: target known to not support VMX, returning 1" 2
3142 # Make sure we have a compiler that understands altivec.
3143 if [get_compiler_info] {
3144 warning "Could not get compiler info"
3147 if [test_compiler_info gcc*] {
3148 set compile_flags "additional_flags=-maltivec"
3149 } elseif [test_compiler_info xlc*] {
3150 set compile_flags "additional_flags=-qaltivec"
3152 verbose "Could not compile with altivec support, returning 1" 2
3156 # Compile a test program containing VMX instructions.
3160 asm volatile ("vor v0,v0,v0");
3162 asm volatile ("vor 0,0,0");
3167 if {![gdb_simple_compile $me $src executable $compile_flags]} {
3171 # Compilation succeeded so now run it via gdb.
3175 gdb_reinitialize_dir $srcdir/$subdir
3179 -re ".*Illegal instruction.*${gdb_prompt} $" {
3180 verbose -log "\n$me altivec hardware not detected"
3181 set skip_vmx_tests 1
3183 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
3184 verbose -log "\n$me: altivec hardware detected"
3185 set skip_vmx_tests 0
3188 warning "\n$me: default case taken"
3189 set skip_vmx_tests 1
3193 remote_file build delete $obj
3195 verbose "$me: returning $skip_vmx_tests" 2
3196 return $skip_vmx_tests
3199 # Run a test on the power target to see if it supports ISA 3.1 instructions
3200 gdb_caching_proc skip_power_isa_3_1_tests {
3201 global srcdir subdir gdb_prompt inferior_exited_re
3203 set me "skip_power_isa_3_1_tests"
3205 # Compile a test program containing ISA 3.1 instructions.
3208 asm volatile ("pnop"); // marker
3209 asm volatile ("nop");
3214 if {![gdb_simple_compile $me $src executable ]} {
3218 # No error message, compilation succeeded so now run it via gdb.
3222 gdb_reinitialize_dir $srcdir/$subdir
3226 -re ".*Illegal instruction.*${gdb_prompt} $" {
3227 verbose -log "\n$me Power ISA 3.1 hardware not detected"
3228 set skip_power_isa_3_1_tests 1
3230 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
3231 verbose -log "\n$me: Power ISA 3.1 hardware detected"
3232 set skip_power_isa_3_1_tests 0
3235 warning "\n$me: default case taken"
3236 set skip_power_isa_3_1_tests 1
3240 remote_file build delete $obj
3242 verbose "$me: returning $skip_power_isa_3_1_tests" 2
3243 return $skip_power_isa_3_1_tests
3246 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
3247 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
3249 gdb_caching_proc skip_vsx_tests {
3250 global srcdir subdir gdb_prompt inferior_exited_re
3252 set me "skip_vsx_tests"
3254 # Some simulators are known to not support Altivec instructions, so
3255 # they won't support VSX instructions as well.
3256 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
3257 verbose "$me: target known to not support VSX, returning 1" 2
3261 # Make sure we have a compiler that understands altivec.
3262 if [get_compiler_info] {
3263 warning "Could not get compiler info"
3266 if [test_compiler_info gcc*] {
3267 set compile_flags "additional_flags=-mvsx"
3268 } elseif [test_compiler_info xlc*] {
3269 set compile_flags "additional_flags=-qasm=gcc"
3271 verbose "Could not compile with vsx support, returning 1" 2
3275 # Compile a test program containing VSX instructions.
3278 double a[2] = { 1.0, 2.0 };
3280 asm volatile ("lxvd2x v0,v0,%[addr]" : : [addr] "r" (a));
3282 asm volatile ("lxvd2x 0,0,%[addr]" : : [addr] "r" (a));
3287 if {![gdb_simple_compile $me $src executable $compile_flags]} {
3291 # No error message, compilation succeeded so now run it via gdb.
3295 gdb_reinitialize_dir $srcdir/$subdir
3299 -re ".*Illegal instruction.*${gdb_prompt} $" {
3300 verbose -log "\n$me VSX hardware not detected"
3301 set skip_vsx_tests 1
3303 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
3304 verbose -log "\n$me: VSX hardware detected"
3305 set skip_vsx_tests 0
3308 warning "\n$me: default case taken"
3309 set skip_vsx_tests 1
3313 remote_file build delete $obj
3315 verbose "$me: returning $skip_vsx_tests" 2
3316 return $skip_vsx_tests
3319 # Run a test on the target to see if it supports TSX hardware. Return 0 if so,
3320 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
3322 gdb_caching_proc skip_tsx_tests {
3323 global srcdir subdir gdb_prompt inferior_exited_re
3325 set me "skip_tsx_tests"
3327 # Compile a test program.
3330 asm volatile ("xbegin .L0");
3331 asm volatile ("xend");
3332 asm volatile (".L0: nop");
3336 if {![gdb_simple_compile $me $src executable]} {
3340 # No error message, compilation succeeded so now run it via gdb.
3344 gdb_reinitialize_dir $srcdir/$subdir
3348 -re ".*Illegal instruction.*${gdb_prompt} $" {
3349 verbose -log "$me: TSX hardware not detected."
3350 set skip_tsx_tests 1
3352 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
3353 verbose -log "$me: TSX hardware detected."
3354 set skip_tsx_tests 0
3357 warning "\n$me: default case taken."
3358 set skip_tsx_tests 1
3362 remote_file build delete $obj
3364 verbose "$me: returning $skip_tsx_tests" 2
3365 return $skip_tsx_tests
3368 # Run a test on the target to see if it supports avx512bf16. Return 0 if so,
3369 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
3371 gdb_caching_proc skip_avx512bf16_tests {
3372 global srcdir subdir gdb_prompt inferior_exited_re
3374 set me "skip_avx512bf16_tests"
3375 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
3376 verbose "$me: target does not support avx512bf16, returning 1" 2
3380 # Compile a test program.
3383 asm volatile ("vcvtne2ps2bf16 %xmm0, %xmm1, %xmm0");
3387 if {![gdb_simple_compile $me $src executable]} {
3391 # No error message, compilation succeeded so now run it via gdb.
3395 gdb_reinitialize_dir $srcdir/$subdir
3399 -re ".*Illegal instruction.*${gdb_prompt} $" {
3400 verbose -log "$me: avx512bf16 hardware not detected."
3401 set skip_avx512bf16_tests 1
3403 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
3404 verbose -log "$me: avx512bf16 hardware detected."
3405 set skip_avx512bf16_tests 0
3408 warning "\n$me: default case taken."
3409 set skip_avx512bf16_tests 1
3413 remote_file build delete $obj
3415 verbose "$me: returning $skip_avx512bf16_tests" 2
3416 return $skip_avx512bf16_tests
3419 # Run a test on the target to see if it supports avx512fp16. Return 0 if so,
3420 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
3422 gdb_caching_proc skip_avx512fp16_tests {
3423 global srcdir subdir gdb_prompt inferior_exited_re
3425 set me "skip_avx512fp16_tests"
3426 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
3427 verbose "$me: target does not support avx512fp16, returning 1" 2
3431 # Compile a test program.
3434 asm volatile ("vcvtps2phx %xmm1, %xmm0");
3438 if {![gdb_simple_compile $me $src executable]} {
3442 # No error message, compilation succeeded so now run it via gdb.
3446 gdb_reinitialize_dir $srcdir/$subdir
3450 -re ".*Illegal instruction.*${gdb_prompt} $" {
3451 verbose -log "$me: avx512fp16 hardware not detected."
3452 set skip_avx512fp16_tests 1
3454 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
3455 verbose -log "$me: avx512fp16 hardware detected."
3456 set skip_avx512fp16_tests 0
3459 warning "\n$me: default case taken."
3460 set skip_avx512fp16_tests 1
3464 remote_file build delete $obj
3466 verbose "$me: returning $skip_avx512fp16_tests" 2
3467 return $skip_avx512fp16_tests
3470 # Run a test on the target to see if it supports btrace hardware. Return 0 if so,
3471 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
3473 gdb_caching_proc skip_btrace_tests {
3474 global srcdir subdir gdb_prompt inferior_exited_re
3476 set me "skip_btrace_tests"
3477 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
3478 verbose "$me: target does not support btrace, returning 1" 2
3482 # Compile a test program.
3483 set src { int main() { return 0; } }
3484 if {![gdb_simple_compile $me $src executable]} {
3488 # No error message, compilation succeeded so now run it via gdb.
3492 gdb_reinitialize_dir $srcdir/$subdir
3497 # In case of an unexpected output, we return 2 as a fail value.
3498 set skip_btrace_tests 2
3499 gdb_test_multiple "record btrace" "check btrace support" {
3500 -re "You can't do that when your target is.*\r\n$gdb_prompt $" {
3501 set skip_btrace_tests 1
3503 -re "Target does not support branch tracing.*\r\n$gdb_prompt $" {
3504 set skip_btrace_tests 1
3506 -re "Could not enable branch tracing.*\r\n$gdb_prompt $" {
3507 set skip_btrace_tests 1
3509 -re "^record btrace\r\n$gdb_prompt $" {
3510 set skip_btrace_tests 0
3514 remote_file build delete $obj
3516 verbose "$me: returning $skip_btrace_tests" 2
3517 return $skip_btrace_tests
3520 # Run a test on the target to see if it supports btrace pt hardware.
3521 # Return 0 if so, 1 if it does not. Based on 'check_vmx_hw_available'
3522 # from the GCC testsuite.
3524 gdb_caching_proc skip_btrace_pt_tests {
3525 global srcdir subdir gdb_prompt inferior_exited_re
3527 set me "skip_btrace_tests"
3528 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
3529 verbose "$me: target does not support btrace, returning 1" 2
3533 # Compile a test program.
3534 set src { int main() { return 0; } }
3535 if {![gdb_simple_compile $me $src executable]} {
3539 # No error message, compilation succeeded so now run it via gdb.
3543 gdb_reinitialize_dir $srcdir/$subdir
3548 # In case of an unexpected output, we return 2 as a fail value.
3549 set skip_btrace_tests 2
3550 gdb_test_multiple "record btrace pt" "check btrace pt support" {
3551 -re "You can't do that when your target is.*\r\n$gdb_prompt $" {
3552 set skip_btrace_tests 1
3554 -re "Target does not support branch tracing.*\r\n$gdb_prompt $" {
3555 set skip_btrace_tests 1
3557 -re "Could not enable branch tracing.*\r\n$gdb_prompt $" {
3558 set skip_btrace_tests 1
3560 -re "support was disabled at compile time.*\r\n$gdb_prompt $" {
3561 set skip_btrace_tests 1
3563 -re "^record btrace pt\r\n$gdb_prompt $" {
3564 set skip_btrace_tests 0
3568 remote_file build delete $obj
3570 verbose "$me: returning $skip_btrace_tests" 2
3571 return $skip_btrace_tests
3574 # Run a test on the target to see if it supports Aarch64 SVE hardware.
3575 # Return 0 if so, 1 if it does not. Note this causes a restart of GDB.
3577 gdb_caching_proc skip_aarch64_sve_tests {
3578 global srcdir subdir gdb_prompt inferior_exited_re
3580 set me "skip_aarch64_sve_tests"
3582 if { ![is_aarch64_target]} {
3586 set compile_flags "{additional_flags=-march=armv8-a+sve}"
3588 # Compile a test program containing SVE instructions.
3591 asm volatile ("ptrue p0.b");
3595 if {![gdb_simple_compile $me $src executable $compile_flags]} {
3599 # Compilation succeeded so now run it via gdb.
3603 -re ".*Illegal instruction.*${gdb_prompt} $" {
3604 verbose -log "\n$me sve hardware not detected"
3605 set skip_sve_tests 1
3607 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
3608 verbose -log "\n$me: sve hardware detected"
3609 set skip_sve_tests 0
3612 warning "\n$me: default case taken"
3613 set skip_sve_tests 1
3617 remote_file build delete $obj
3619 verbose "$me: returning $skip_sve_tests" 2
3620 return $skip_sve_tests
3624 # A helper that compiles a test case to see if __int128 is supported.
3625 proc gdb_int128_helper {lang} {
3626 return [gdb_can_simple_compile "i128-for-$lang" {
3628 int main() { return 0; }
3632 # Return true if the C compiler understands the __int128 type.
3633 gdb_caching_proc has_int128_c {
3634 return [gdb_int128_helper c]
3637 # Return true if the C++ compiler understands the __int128 type.
3638 gdb_caching_proc has_int128_cxx {
3639 return [gdb_int128_helper c++]
3642 # Return true if the IFUNC feature is unsupported.
3643 gdb_caching_proc skip_ifunc_tests {
3644 if [gdb_can_simple_compile ifunc {
3646 typedef void F (void);
3647 F* g (void) { return &f_; }
3648 void f () __attribute__ ((ifunc ("g")));
3656 # Return whether we should skip tests for showing inlined functions in
3657 # backtraces. Requires get_compiler_info and get_debug_format.
3659 proc skip_inline_frame_tests {} {
3660 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
3661 if { ! [test_debug_format "DWARF 2"] } {
3665 # GCC before 4.1 does not emit DW_AT_call_file / DW_AT_call_line.
3666 if { ([test_compiler_info "gcc-2-*"]
3667 || [test_compiler_info "gcc-3-*"]
3668 || [test_compiler_info "gcc-4-0-*"]) } {
3675 # Return whether we should skip tests for showing variables from
3676 # inlined functions. Requires get_compiler_info and get_debug_format.
3678 proc skip_inline_var_tests {} {
3679 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
3680 if { ! [test_debug_format "DWARF 2"] } {
3687 # Return a 1 if we should skip tests that require hardware breakpoints
3689 proc skip_hw_breakpoint_tests {} {
3690 # Skip tests if requested by the board (note that no_hardware_watchpoints
3691 # disables both watchpoints and breakpoints)
3692 if { [target_info exists gdb,no_hardware_watchpoints]} {
3696 # These targets support hardware breakpoints natively
3697 if { [istarget "i?86-*-*"]
3698 || [istarget "x86_64-*-*"]
3699 || [istarget "ia64-*-*"]
3700 || [istarget "arm*-*-*"]
3701 || [istarget "aarch64*-*-*"]
3702 || [istarget "s390*-*-*"] } {
3709 # Return a 1 if we should skip tests that require hardware watchpoints
3711 proc skip_hw_watchpoint_tests {} {
3712 # Skip tests if requested by the board
3713 if { [target_info exists gdb,no_hardware_watchpoints]} {
3717 # These targets support hardware watchpoints natively
3718 if { [istarget "i?86-*-*"]
3719 || [istarget "x86_64-*-*"]
3720 || [istarget "ia64-*-*"]
3721 || [istarget "arm*-*-*"]
3722 || [istarget "aarch64*-*-*"]
3723 || [istarget "powerpc*-*-linux*"]
3724 || [istarget "s390*-*-*"] } {
3731 # Return a 1 if we should skip tests that require *multiple* hardware
3732 # watchpoints to be active at the same time
3734 proc skip_hw_watchpoint_multi_tests {} {
3735 if { [skip_hw_watchpoint_tests] } {
3739 # These targets support just a single hardware watchpoint
3740 if { [istarget "arm*-*-*"]
3741 || [istarget "powerpc*-*-linux*"] } {
3748 # Return a 1 if we should skip tests that require read/access watchpoints
3750 proc skip_hw_watchpoint_access_tests {} {
3751 if { [skip_hw_watchpoint_tests] } {
3755 # These targets support just write watchpoints
3756 if { [istarget "s390*-*-*"] } {
3763 # Return 1 if we should skip tests that require the runtime unwinder
3764 # hook. This must be invoked while gdb is running, after shared
3765 # libraries have been loaded. This is needed because otherwise a
3766 # shared libgcc won't be visible.
3768 proc skip_unwinder_tests {} {
3772 gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook" {
3773 -re "= .*no debug info.*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
3775 -re "= .*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
3778 -re "No symbol .* in current context.\r\n$gdb_prompt $" {
3782 gdb_test_multiple "info probe" "check for stap probe in unwinder" {
3783 -re ".*libgcc.*unwind.*\r\n$gdb_prompt $" {
3786 -re "\r\n$gdb_prompt $" {
3793 # Return 1 if we should skip tests that require the libstdc++ stap
3794 # probes. This must be invoked while gdb is running, after shared
3795 # libraries have been loaded. PROMPT_REGEXP is the expected prompt.
3797 proc skip_libstdcxx_probe_tests_prompt { prompt_regexp } {
3799 gdb_test_multiple "info probe" "check for stap probe in libstdc++" \
3800 -prompt "$prompt_regexp" {
3801 -re ".*libstdcxx.*catch.*\r\n$prompt_regexp" {
3804 -re "\r\n$prompt_regexp" {
3807 set skip [expr !$supported]
3811 # As skip_libstdcxx_probe_tests_prompt, with gdb_prompt.
3813 proc skip_libstdcxx_probe_tests {} {
3815 return [skip_libstdcxx_probe_tests_prompt "$gdb_prompt $"]
3818 # Return 1 if we should skip tests of the "compile" feature.
3819 # This must be invoked after the inferior has been started.
3821 proc skip_compile_feature_tests {} {
3825 gdb_test_multiple "compile code -- ;" "check for working compile command" {
3826 "Could not load libcc1.*\r\n$gdb_prompt $" {
3829 -re "Command not supported on this host\\..*\r\n$gdb_prompt $" {
3832 -re "\r\n$gdb_prompt $" {
3838 # Helper for gdb_is_target_* procs. TARGET_NAME is the name of the target
3839 # we're looking for (used to build the test name). TARGET_STACK_REGEXP
3840 # is a regexp that will match the output of "maint print target-stack" if
3841 # the target in question is currently pushed. PROMPT_REGEXP is a regexp
3842 # matching the expected prompt after the command output.
3844 proc gdb_is_target_1 { target_name target_stack_regexp prompt_regexp } {
3845 set test "probe for target ${target_name}"
3846 gdb_test_multiple "maint print target-stack" $test \
3847 -prompt "$prompt_regexp" {
3848 -re "${target_stack_regexp}${prompt_regexp}" {
3852 -re "$prompt_regexp" {
3859 # Helper for gdb_is_target_remote where the expected prompt is variable.
3861 proc gdb_is_target_remote_prompt { prompt_regexp } {
3862 return [gdb_is_target_1 "remote" ".*emote serial target in gdb-specific protocol.*" $prompt_regexp]
3865 # Check whether we're testing with the remote or extended-remote
3868 proc gdb_is_target_remote { } {
3871 return [gdb_is_target_remote_prompt "$gdb_prompt $"]
3874 # Check whether we're testing with the native target.
3876 proc gdb_is_target_native { } {
3879 return [gdb_is_target_1 "native" ".*native \\(Native process\\).*" "$gdb_prompt $"]
3882 # Return the effective value of use_gdb_stub.
3884 # If the use_gdb_stub global has been set (it is set when the gdb process is
3885 # spawned), return that. Otherwise, return the value of the use_gdb_stub
3886 # property from the board file.
3888 # This is the preferred way of checking use_gdb_stub, since it allows to check
3889 # the value before the gdb has been spawned and it will return the correct value
3890 # even when it was overriden by the test.
3892 # Note that stub targets are not able to spawn new inferiors. Use this
3893 # check for skipping respective tests.
3895 proc use_gdb_stub {} {
3898 if [info exists use_gdb_stub] {
3899 return $use_gdb_stub
3902 return [target_info exists use_gdb_stub]
3905 # Return 1 if the current remote target is an instance of our GDBserver, 0
3906 # otherwise. Return -1 if there was an error and we can't tell.
3908 gdb_caching_proc target_is_gdbserver {
3912 set test "probing for GDBserver"
3914 gdb_test_multiple "monitor help" $test {
3915 -re "The following monitor commands are supported.*Quit GDBserver.*$gdb_prompt $" {
3918 -re "$gdb_prompt $" {
3923 if { $is_gdbserver == -1 } {
3924 verbose -log "Unable to tell whether we are using GDBserver or not."
3927 return $is_gdbserver
3930 # N.B. compiler_info is intended to be local to this file.
3931 # Call test_compiler_info with no arguments to fetch its value.
3932 # Yes, this is counterintuitive when there's get_compiler_info,
3933 # but that's the current API.
3934 if [info exists compiler_info] {
3940 # Figure out what compiler I am using.
3941 # The result is cached so only the first invocation runs the compiler.
3943 # ARG can be empty or "C++". If empty, "C" is assumed.
3945 # There are several ways to do this, with various problems.
3947 # [ gdb_compile -E $ifile -o $binfile.ci ]
3948 # source $binfile.ci
3950 # Single Unix Spec v3 says that "-E -o ..." together are not
3951 # specified. And in fact, the native compiler on hp-ux 11 (among
3952 # others) does not work with "-E -o ...". Most targets used to do
3953 # this, and it mostly worked, because it works with gcc.
3955 # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ]
3956 # source $binfile.ci
3958 # This avoids the problem with -E and -o together. This almost works
3959 # if the build machine is the same as the host machine, which is
3960 # usually true of the targets which are not gcc. But this code does
3961 # not figure which compiler to call, and it always ends up using the C
3962 # compiler. Not good for setting hp_aCC_compiler. Target
3963 # hppa*-*-hpux* used to do this.
3965 # [ gdb_compile -E $ifile > $binfile.ci ]
3966 # source $binfile.ci
3968 # dejagnu target_compile says that it supports output redirection,
3969 # but the code is completely different from the normal path and I
3970 # don't want to sweep the mines from that path. So I didn't even try
3973 # set cppout [ gdb_compile $ifile "" preprocess $args quiet ]
3976 # I actually do this for all targets now. gdb_compile runs the right
3977 # compiler, and TCL captures the output, and I eval the output.
3979 # Unfortunately, expect logs the output of the command as it goes by,
3980 # and dejagnu helpfully prints a second copy of it right afterwards.
3981 # So I turn off expect logging for a moment.
3983 # [ gdb_compile $ifile $ciexe_file executable $args ]
3984 # [ remote_exec $ciexe_file ]
3985 # [ source $ci_file.out ]
3987 # I could give up on -E and just do this.
3988 # I didn't get desperate enough to try this.
3990 # -- chastain 2004-01-06
3992 proc get_compiler_info {{arg ""}} {
3993 # For compiler.c and compiler.cc
3996 # I am going to play with the log to keep noise out.
4000 # These come from compiler.c or compiler.cc
4001 global compiler_info
4003 # Legacy global data symbols.
4006 if [info exists compiler_info] {
4011 # Choose which file to preprocess.
4012 set ifile "${srcdir}/lib/compiler.c"
4013 if { $arg == "c++" } {
4014 set ifile "${srcdir}/lib/compiler.cc"
4017 # Run $ifile through the right preprocessor.
4018 # Toggle gdb.log to keep the compiler output out of the log.
4019 set saved_log [log_file -info]
4021 if [is_remote host] {
4022 # We have to use -E and -o together, despite the comments
4023 # above, because of how DejaGnu handles remote host testing.
4024 set ppout "$outdir/compiler.i"
4025 gdb_compile "${ifile}" "$ppout" preprocess [list "$arg" quiet getting_compiler_info]
4026 set file [open $ppout r]
4027 set cppout [read $file]
4030 set cppout [ gdb_compile "${ifile}" "" preprocess [list "$arg" quiet getting_compiler_info] ]
4032 eval log_file $saved_log
4036 foreach cppline [ split "$cppout" "\n" ] {
4037 if { [ regexp "^#" "$cppline" ] } {
4039 } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } {
4041 } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } {
4043 verbose "get_compiler_info: $cppline" 2
4047 verbose -log "get_compiler_info: $cppline"
4052 # Set to unknown if for some reason compiler_info didn't get defined.
4053 if ![info exists compiler_info] {
4054 verbose -log "get_compiler_info: compiler_info not provided"
4055 set compiler_info "unknown"
4057 # Also set to unknown compiler if any diagnostics happened.
4059 verbose -log "get_compiler_info: got unexpected diagnostics"
4060 set compiler_info "unknown"
4063 # Set the legacy symbols.
4065 regexp "^gcc-(\[0-9\]+)-" "$compiler_info" matchall gcc_compiled
4067 # Log what happened.
4068 verbose -log "get_compiler_info: $compiler_info"
4070 # Most compilers will evaluate comparisons and other boolean
4071 # operations to 0 or 1.
4072 uplevel \#0 { set true 1 }
4073 uplevel \#0 { set false 0 }
4078 # Return the compiler_info string if no arg is provided.
4079 # Otherwise the argument is a glob-style expression to match against
4082 proc test_compiler_info { {compiler ""} } {
4083 global compiler_info
4086 # If no arg, return the compiler_info string.
4087 if [string match "" $compiler] {
4088 return $compiler_info
4091 return [string match $compiler $compiler_info]
4094 # Return the gcc major version, or -1.
4095 # For gcc 4.8.5, the major version is 4.8.
4096 # For gcc 7.5.0, the major version 7.
4098 proc gcc_major_version { } {
4099 global compiler_info
4101 if { ![test_compiler_info "gcc-*"] } {
4104 set res [regexp gcc-($decimal)-($decimal)- $compiler_info \
4105 dummy_var major minor]
4112 return $major.$minor
4115 proc current_target_name { } {
4117 if [info exists target_info(target,name)] {
4118 set answer $target_info(target,name)
4125 set gdb_wrapper_initialized 0
4126 set gdb_wrapper_target ""
4127 set gdb_wrapper_file ""
4128 set gdb_wrapper_flags ""
4130 proc gdb_wrapper_init { args } {
4131 global gdb_wrapper_initialized
4132 global gdb_wrapper_file
4133 global gdb_wrapper_flags
4134 global gdb_wrapper_target
4136 if { $gdb_wrapper_initialized == 1 } { return; }
4138 if {[target_info exists needs_status_wrapper] && \
4139 [target_info needs_status_wrapper] != "0"} {
4140 set result [build_wrapper "testglue.o"]
4141 if { $result != "" } {
4142 set gdb_wrapper_file [lindex $result 0]
4143 if ![is_remote host] {
4144 set gdb_wrapper_file [file join [pwd] $gdb_wrapper_file]
4146 set gdb_wrapper_flags [lindex $result 1]
4148 warning "Status wrapper failed to build."
4151 set gdb_wrapper_file ""
4152 set gdb_wrapper_flags ""
4154 verbose "set gdb_wrapper_file = $gdb_wrapper_file"
4155 set gdb_wrapper_initialized 1
4156 set gdb_wrapper_target [current_target_name]
4159 # Determine options that we always want to pass to the compiler.
4160 gdb_caching_proc universal_compile_options {
4161 set me "universal_compile_options"
4164 set src [standard_temp_file ccopts[pid].c]
4165 set obj [standard_temp_file ccopts[pid].o]
4167 gdb_produce_source $src {
4168 int foo(void) { return 0; }
4171 # Try an option for disabling colored diagnostics. Some compilers
4172 # yield colored diagnostics by default (when run from a tty) unless
4173 # such an option is specified.
4174 set opt "additional_flags=-fdiagnostics-color=never"
4175 set lines [target_compile $src $obj object [list "quiet" $opt]]
4176 if [string match "" $lines] then {
4177 # Seems to have worked; use the option.
4178 lappend options $opt
4183 verbose "$me: returning $options" 2
4187 # Compile the code in $code to a file based on $name, using the flags
4188 # $compile_flag as well as debug, nowarning and quiet.
4189 # Return 1 if code can be compiled
4190 # Leave the file name of the resulting object in the upvar object.
4192 proc gdb_simple_compile {name code {type object} {compile_flags {}} {object obj}} {
4195 switch -regexp -- $type {
4210 foreach flag $compile_flags {
4211 if { "$flag" == "go" } {
4216 set src [standard_temp_file $name-[pid].$ext]
4217 set obj [standard_temp_file $name-[pid].$postfix]
4218 set compile_flags [concat $compile_flags {debug nowarnings quiet}]
4220 gdb_produce_source $src $code
4222 verbose "$name: compiling testfile $src" 2
4223 set lines [gdb_compile $src $obj $type $compile_flags]
4227 if ![string match "" $lines] then {
4228 verbose "$name: compilation failed, returning 0" 2
4234 # Compile the code in $code to a file based on $name, using the flags
4235 # $compile_flag as well as debug, nowarning and quiet.
4236 # Return 1 if code can be compiled
4237 # Delete all created files and objects.
4239 proc gdb_can_simple_compile {name code {type object} {compile_flags ""}} {
4240 set ret [gdb_simple_compile $name $code $type $compile_flags temp_obj]
4241 file delete $temp_obj
4245 # Some targets need to always link a special object in. Save its path here.
4246 global gdb_saved_set_unbuffered_mode_obj
4247 set gdb_saved_set_unbuffered_mode_obj ""
4249 # Compile source files specified by SOURCE into a binary of type TYPE at path
4250 # DEST. gdb_compile is implemented using DejaGnu's target_compile, so the type
4251 # parameter and most options are passed directly to it.
4253 # The type can be one of the following:
4255 # - object: Compile into an object file.
4256 # - executable: Compile and link into an executable.
4257 # - preprocess: Preprocess the source files.
4258 # - assembly: Generate assembly listing.
4260 # The following options are understood and processed by gdb_compile:
4262 # - shlib=so_path: Add SO_PATH to the sources, and enable some target-specific
4263 # quirks to be able to use shared libraries.
4264 # - shlib_load: Link with appropriate libraries to allow the test to
4265 # dynamically load libraries at runtime. For example, on Linux, this adds
4266 # -ldl so that the test can use dlopen.
4267 # - nowarnings: Inhibit all compiler warnings.
4268 # - pie: Force creation of PIE executables.
4269 # - nopie: Prevent creation of PIE executables.
4271 # And here are some of the not too obscure options understood by DejaGnu that
4272 # influence the compilation:
4274 # - additional_flags=flag: Add FLAG to the compiler flags.
4275 # - libs=library: Add LIBRARY to the libraries passed to the linker. The
4276 # argument can be a file, in which case it's added to the sources, or a
4278 # - ldflags=flag: Add FLAG to the linker flags.
4279 # - incdir=path: Add PATH to the searched include directories.
4280 # - libdir=path: Add PATH to the linker searched directories.
4281 # - ada, c++, f77, f90, go, rust: Compile the file as Ada, C++,
4282 # Fortran 77, Fortran 90, Go or Rust.
4283 # - debug: Build with debug information.
4284 # - optimize: Build with optimization.
4286 proc gdb_compile {source dest type options} {
4287 global GDB_TESTCASE_OPTIONS
4288 global gdb_wrapper_file
4289 global gdb_wrapper_flags
4292 global gdb_saved_set_unbuffered_mode_obj
4294 set outdir [file dirname $dest]
4296 # Add platform-specific options if a shared library was specified using
4297 # "shlib=librarypath" in OPTIONS.
4299 if {[lsearch -exact $options rust] != -1} {
4300 # -fdiagnostics-color is not a rustcc option.
4302 set new_options [universal_compile_options]
4305 # Some C/C++ testcases unconditionally pass -Wno-foo as additional
4306 # options to disable some warning. That is OK with GCC, because
4307 # by design, GCC accepts any -Wno-foo option, even if it doesn't
4308 # support -Wfoo. Clang however warns about unknown -Wno-foo by
4309 # default, unless you pass -Wno-unknown-warning-option as well.
4310 # We do that here, so that individual testcases don't have to
4312 if {[lsearch -exact $options getting_compiler_info] == -1
4313 && [lsearch -exact $options rust] == -1
4314 && [lsearch -exact $options ada] == -1
4315 && [lsearch -exact $options f77] == -1
4316 && [lsearch -exact $options f90] == -1
4317 && [lsearch -exact $options go] == -1
4318 && [test_compiler_info "clang-*"]} {
4319 lappend new_options "additional_flags=-Wno-unknown-warning-option"
4322 # Treating .c input files as C++ is deprecated in Clang, so
4323 # explicitly force C++ language.
4324 if { [lsearch -exact $options getting_compiler_info] == -1
4325 && [lsearch -exact $options c++] != -1
4326 && [string match *.c $source] != 0 } {
4328 # gdb_compile cannot handle this combination of options, the
4329 # result is a command like "clang -x c++ foo.c bar.so -o baz"
4330 # which tells Clang to treat bar.so as C++. The solution is
4331 # to call gdb_compile twice--once to compile, once to link--
4332 # either directly, or via build_executable_from_specs.
4333 if { [lsearch $options shlib=*] != -1 } {
4334 error "incompatible gdb_compile options"
4337 if {[test_compiler_info "clang-*"]} {
4338 lappend new_options early_flags=-x\ c++
4342 # Place (and look for) Fortran `.mod` files in the output
4343 # directory for this specific test.
4344 if {[lsearch -exact $options f77] != -1 \
4345 || [lsearch -exact $options f90] != -1 } {
4347 set mod_path [standard_output_file ""]
4348 if [test_compiler_info "gcc-*"] {
4349 lappend new_options "additional_flags=-J${mod_path}"
4355 set getting_compiler_info 0
4356 foreach opt $options {
4357 if {[regexp {^shlib=(.*)} $opt dummy_var shlib_name]
4358 && $type == "executable"} {
4359 if [test_compiler_info "xlc-*"] {
4360 # IBM xlc compiler doesn't accept shared library named other
4361 # than .so: use "-Wl," to bypass this
4362 lappend source "-Wl,$shlib_name"
4363 } elseif { ([istarget "*-*-mingw*"]
4364 || [istarget *-*-cygwin*]
4365 || [istarget *-*-pe*])} {
4366 lappend source "${shlib_name}.a"
4368 lappend source $shlib_name
4370 if { $shlib_found == 0 } {
4372 if { ([istarget "*-*-mingw*"]
4373 || [istarget *-*-cygwin*]) } {
4374 lappend new_options "additional_flags=-Wl,--enable-auto-import"
4376 if { [test_compiler_info "gcc-*"] || [test_compiler_info "clang-*"] } {
4377 # Undo debian's change in the default.
4378 # Put it at the front to not override any user-provided
4379 # value, and to make sure it appears in front of all the
4381 lappend new_options "early_flags=-Wl,--no-as-needed"
4384 } elseif { $opt == "shlib_load" && $type == "executable" } {
4386 } elseif { $opt == "getting_compiler_info" } {
4387 # If this is set, calling test_compiler_info will cause recursion.
4388 set getting_compiler_info 1
4390 lappend new_options $opt
4394 # Ensure stack protector is disabled for GCC, as this causes problems with
4395 # DWARF line numbering.
4396 # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88432
4397 # This option defaults to on for Debian/Ubuntu.
4398 if { $getting_compiler_info == 0
4399 && [test_compiler_info {gcc-*-*}]
4400 && !([test_compiler_info {gcc-[0-3]-*}]
4401 || [test_compiler_info {gcc-4-0-*}])
4402 && [lsearch -exact $options rust] == -1} {
4403 # Put it at the front to not override any user-provided value.
4404 lappend new_options "early_flags=-fno-stack-protector"
4407 # Because we link with libraries using their basename, we may need
4408 # (depending on the platform) to set a special rpath value, to allow
4409 # the executable to find the libraries it depends on.
4410 if { $shlib_load || $shlib_found } {
4411 if { ([istarget "*-*-mingw*"]
4412 || [istarget *-*-cygwin*]
4413 || [istarget *-*-pe*]) } {
4414 # Do not need anything.
4415 } elseif { [istarget *-*-freebsd*] || [istarget *-*-openbsd*] } {
4416 lappend new_options "ldflags=-Wl,-rpath,${outdir}"
4418 if { $shlib_load } {
4419 lappend new_options "libs=-ldl"
4421 lappend new_options "ldflags=-Wl,-rpath,\\\$ORIGIN"
4424 set options $new_options
4426 if [info exists GDB_TESTCASE_OPTIONS] {
4427 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS"
4429 verbose "options are $options"
4430 verbose "source is $source $dest $type $options"
4434 if {[target_info exists needs_status_wrapper] && \
4435 [target_info needs_status_wrapper] != "0" && \
4436 $gdb_wrapper_file != "" } {
4437 lappend options "libs=${gdb_wrapper_file}"
4438 lappend options "ldflags=${gdb_wrapper_flags}"
4441 # Replace the "nowarnings" option with the appropriate additional_flags
4442 # to disable compiler warnings.
4443 set nowarnings [lsearch -exact $options nowarnings]
4444 if {$nowarnings != -1} {
4445 if [target_info exists gdb,nowarnings_flag] {
4446 set flag "additional_flags=[target_info gdb,nowarnings_flag]"
4448 set flag "additional_flags=-w"
4450 set options [lreplace $options $nowarnings $nowarnings $flag]
4453 # Replace the "pie" option with the appropriate compiler and linker flags
4454 # to enable PIE executables.
4455 set pie [lsearch -exact $options pie]
4457 if [target_info exists gdb,pie_flag] {
4458 set flag "additional_flags=[target_info gdb,pie_flag]"
4460 # For safety, use fPIE rather than fpie. On AArch64, m68k, PowerPC
4461 # and SPARC, fpie can cause compile errors due to the GOT exceeding
4462 # a maximum size. On other architectures the two flags are
4463 # identical (see the GCC manual). Note Debian9 and Ubuntu16.10
4464 # onwards default GCC to using fPIE. If you do require fpie, then
4465 # it can be set using the pie_flag.
4466 set flag "additional_flags=-fPIE"
4468 set options [lreplace $options $pie $pie $flag]
4470 if [target_info exists gdb,pie_ldflag] {
4471 set flag "ldflags=[target_info gdb,pie_ldflag]"
4473 set flag "ldflags=-pie"
4475 lappend options "$flag"
4478 # Replace the "nopie" option with the appropriate compiler and linker
4479 # flags to disable PIE executables.
4480 set nopie [lsearch -exact $options nopie]
4482 if [target_info exists gdb,nopie_flag] {
4483 set flag "additional_flags=[target_info gdb,nopie_flag]"
4485 set flag "additional_flags=-fno-pie"
4487 set options [lreplace $options $nopie $nopie $flag]
4489 if [target_info exists gdb,nopie_ldflag] {
4490 set flag "ldflags=[target_info gdb,nopie_ldflag]"
4492 set flag "ldflags=-no-pie"
4494 lappend options "$flag"
4497 if { $type == "executable" } {
4498 if { ([istarget "*-*-mingw*"]
4499 || [istarget "*-*-*djgpp"]
4500 || [istarget "*-*-cygwin*"])} {
4501 # Force output to unbuffered mode, by linking in an object file
4502 # with a global contructor that calls setvbuf.
4504 # Compile the special object separately for two reasons:
4505 # 1) Insulate it from $options.
4506 # 2) Avoid compiling it for every gdb_compile invocation,
4507 # which is time consuming, especially if we're remote
4510 if { $gdb_saved_set_unbuffered_mode_obj == "" } {
4511 verbose "compiling gdb_saved_set_unbuffered_obj"
4512 set unbuf_src ${srcdir}/lib/set_unbuffered_mode.c
4513 set unbuf_obj ${objdir}/set_unbuffered_mode.o
4515 set result [gdb_compile "${unbuf_src}" "${unbuf_obj}" object {nowarnings}]
4516 if { $result != "" } {
4519 if {[is_remote host]} {
4520 set gdb_saved_set_unbuffered_mode_obj set_unbuffered_mode_saved.o
4522 set gdb_saved_set_unbuffered_mode_obj ${objdir}/set_unbuffered_mode_saved.o
4524 # Link a copy of the output object, because the
4525 # original may be automatically deleted.
4526 remote_download host $unbuf_obj $gdb_saved_set_unbuffered_mode_obj
4528 verbose "gdb_saved_set_unbuffered_obj already compiled"
4531 # Rely on the internal knowledge that the global ctors are ran in
4532 # reverse link order. In that case, we can use ldflags to
4533 # avoid copying the object file to the host multiple
4535 # This object can only be added if standard libraries are
4536 # used. Thus, we need to disable it if -nostdlib option is used
4537 if {[lsearch -regexp $options "-nostdlib"] < 0 } {
4538 lappend options "ldflags=$gdb_saved_set_unbuffered_mode_obj"
4543 set result [target_compile $source $dest $type $options]
4545 # Prune uninteresting compiler (and linker) output.
4546 regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result
4548 regsub "\[\r\n\]*$" "$result" "" result
4549 regsub "^\[\r\n\]*" "$result" "" result
4551 if { $type == "executable" && $result == "" \
4552 && ($nopie != -1 || $pie != -1) } {
4553 set is_pie [exec_is_pie "$dest"]
4554 if { $nopie != -1 && $is_pie == 1 } {
4555 set result "nopie failed to prevent PIE executable"
4556 } elseif { $pie != -1 && $is_pie == 0 } {
4557 set result "pie failed to generate PIE executable"
4561 if {[lsearch $options quiet] < 0} {
4562 # We shall update this on a per language basis, to avoid
4563 # changing the entire testsuite in one go.
4564 if {[lsearch $options f77] >= 0} {
4565 gdb_compile_test $source $result
4566 } elseif { $result != "" } {
4567 clone_output "gdb compile failed, $result"
4574 # This is just like gdb_compile, above, except that it tries compiling
4575 # against several different thread libraries, to see which one this
4577 proc gdb_compile_pthreads {source dest type options} {
4578 if {$type != "executable"} {
4579 return [gdb_compile $source $dest $type $options]
4582 set why_msg "unrecognized error"
4583 foreach lib {-lpthreads -lpthread -lthread ""} {
4584 # This kind of wipes out whatever libs the caller may have
4585 # set. Or maybe theirs will override ours. How infelicitous.
4586 set options_with_lib [concat $options [list libs=$lib quiet]]
4587 set ccout [gdb_compile $source $dest $type $options_with_lib]
4588 switch -regexp -- $ccout {
4589 ".*no posix threads support.*" {
4590 set why_msg "missing threads include file"
4593 ".*cannot open -lpthread.*" {
4594 set why_msg "missing runtime threads library"
4596 ".*Can't find library for -lpthread.*" {
4597 set why_msg "missing runtime threads library"
4600 pass "successfully compiled posix threads test case"
4606 if {!$built_binfile} {
4607 unsupported "couldn't compile [file tail $source]: ${why_msg}"
4612 # Build a shared library from SOURCES.
4614 proc gdb_compile_shlib_1 {sources dest options} {
4615 set obj_options $options
4618 if { [lsearch -exact $options "ada"] >= 0 } {
4623 if { [lsearch -exact $options "c++"] >= 0 } {
4624 set info_options "c++"
4626 if [get_compiler_info ${info_options}] {
4630 switch -glob [test_compiler_info] {
4632 lappend obj_options "additional_flags=-qpic"
4635 if { [istarget "*-*-cygwin*"]
4636 || [istarget "*-*-mingw*"] } {
4637 lappend obj_options "additional_flags=-fPIC"
4639 lappend obj_options "additional_flags=-fpic"
4643 if { [istarget "powerpc*-*-aix*"]
4644 || [istarget "rs6000*-*-aix*"]
4645 || [istarget "*-*-cygwin*"]
4646 || [istarget "*-*-mingw*"]
4647 || [istarget "*-*-pe*"] } {
4648 lappend obj_options "additional_flags=-fPIC"
4650 lappend obj_options "additional_flags=-fpic"
4654 lappend obj_options "additional_flags=-fpic"
4657 # don't know what the compiler is...
4658 lappend obj_options "additional_flags=-fPIC"
4662 set outdir [file dirname $dest]
4664 foreach source $sources {
4665 if {[file extension $source] == ".o"} {
4666 # Already a .o file.
4667 lappend objects $source
4671 set sourcebase [file tail $source]
4674 # Gnatmake doesn't like object name foo.adb.o, use foo.o.
4675 set sourcebase [file rootname $sourcebase]
4677 set object ${outdir}/${sourcebase}.o
4680 # Use gdb_compile_ada_1 instead of gdb_compile_ada to avoid the
4682 if {[gdb_compile_ada_1 $source $object object \
4683 $obj_options] != ""} {
4687 if {[gdb_compile $source $object object \
4688 $obj_options] != ""} {
4693 lappend objects $object
4696 set link_options $options
4698 # If we try to use gnatmake for the link, it will interpret the
4699 # object file as an .adb file. Remove ada from the options to
4701 set idx [lsearch $link_options "ada"]
4702 set link_options [lreplace $link_options $idx $idx]
4704 if [test_compiler_info "xlc-*"] {
4705 lappend link_options "additional_flags=-qmkshrobj"
4707 lappend link_options "additional_flags=-shared"
4709 if { ([istarget "*-*-mingw*"]
4710 || [istarget *-*-cygwin*]
4711 || [istarget *-*-pe*]) } {
4712 if { [is_remote host] } {
4713 set name [file tail ${dest}]
4717 lappend link_options "additional_flags=-Wl,--out-implib,${name}.a"
4719 # Set the soname of the library. This causes the linker on ELF
4720 # systems to create the DT_NEEDED entry in the executable referring
4721 # to the soname of the library, and not its absolute path. This
4722 # (using the absolute path) would be problem when testing on a
4725 # In conjunction with setting the soname, we add the special
4726 # rpath=$ORIGIN value when building the executable, so that it's
4727 # able to find the library in its own directory.
4728 set destbase [file tail $dest]
4729 lappend link_options "additional_flags=-Wl,-soname,$destbase"
4732 if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
4735 if { [is_remote host]
4736 && ([istarget "*-*-mingw*"]
4737 || [istarget *-*-cygwin*]
4738 || [istarget *-*-pe*]) } {
4739 set dest_tail_name [file tail ${dest}]
4740 remote_upload host $dest_tail_name.a ${dest}.a
4741 remote_file host delete $dest_tail_name.a
4747 # Build a shared library from SOURCES. Ignore target boards PIE-related
4750 proc gdb_compile_shlib {sources dest options} {
4753 # Ignore PIE-related setting in multilib_flags.
4754 set board [target_info name]
4755 set multilib_flags_orig [board_info $board multilib_flags]
4756 set multilib_flags ""
4757 foreach op $multilib_flags_orig {
4758 if { $op == "-pie" || $op == "-no-pie" \
4759 || $op == "-fPIE" || $op == "-fno-PIE"} {
4761 append multilib_flags " $op"
4765 save_target_board_info { multilib_flags } {
4766 unset_board_info multilib_flags
4767 set_board_info multilib_flags "$multilib_flags"
4768 set result [gdb_compile_shlib_1 $sources $dest $options]
4774 # This is just like gdb_compile_shlib, above, except that it tries compiling
4775 # against several different thread libraries, to see which one this
4777 proc gdb_compile_shlib_pthreads {sources dest options} {
4779 set why_msg "unrecognized error"
4780 foreach lib {-lpthreads -lpthread -lthread ""} {
4781 # This kind of wipes out whatever libs the caller may have
4782 # set. Or maybe theirs will override ours. How infelicitous.
4783 set options_with_lib [concat $options [list libs=$lib quiet]]
4784 set ccout [gdb_compile_shlib $sources $dest $options_with_lib]
4785 switch -regexp -- $ccout {
4786 ".*no posix threads support.*" {
4787 set why_msg "missing threads include file"
4790 ".*cannot open -lpthread.*" {
4791 set why_msg "missing runtime threads library"
4793 ".*Can't find library for -lpthread.*" {
4794 set why_msg "missing runtime threads library"
4797 pass "successfully compiled posix threads shlib test case"
4803 if {!$built_binfile} {
4804 unsupported "couldn't compile $sources: ${why_msg}"
4809 # This is just like gdb_compile_pthreads, above, except that we always add the
4810 # objc library for compiling Objective-C programs
4811 proc gdb_compile_objc {source dest type options} {
4813 set why_msg "unrecognized error"
4814 foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} {
4815 # This kind of wipes out whatever libs the caller may have
4816 # set. Or maybe theirs will override ours. How infelicitous.
4817 if { $lib == "solaris" } {
4818 set lib "-lpthread -lposix4"
4820 if { $lib != "-lobjc" } {
4821 set lib "-lobjc $lib"
4823 set options_with_lib [concat $options [list libs=$lib quiet]]
4824 set ccout [gdb_compile $source $dest $type $options_with_lib]
4825 switch -regexp -- $ccout {
4826 ".*no posix threads support.*" {
4827 set why_msg "missing threads include file"
4830 ".*cannot open -lpthread.*" {
4831 set why_msg "missing runtime threads library"
4833 ".*Can't find library for -lpthread.*" {
4834 set why_msg "missing runtime threads library"
4837 pass "successfully compiled objc with posix threads test case"
4843 if {!$built_binfile} {
4844 unsupported "couldn't compile [file tail $source]: ${why_msg}"
4849 # Build an OpenMP program from SOURCE. See prefatory comment for
4850 # gdb_compile, above, for discussion of the parameters to this proc.
4852 proc gdb_compile_openmp {source dest type options} {
4853 lappend options "additional_flags=-fopenmp"
4854 return [gdb_compile $source $dest $type $options]
4857 # Send a command to GDB.
4858 # For options for TYPE see gdb_stdin_log_write
4860 proc send_gdb { string {type standard}} {
4861 gdb_stdin_log_write $string $type
4862 return [remote_send host "$string"]
4865 # Send STRING to the inferior's terminal.
4867 proc send_inferior { string } {
4868 global inferior_spawn_id
4870 if {[catch "send -i $inferior_spawn_id -- \$string" errorInfo]} {
4880 proc gdb_expect { args } {
4881 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
4882 set atimeout [lindex $args 0]
4883 set expcode [list [lindex $args 1]]
4888 # A timeout argument takes precedence, otherwise of all the timeouts
4889 # select the largest.
4890 if [info exists atimeout] {
4893 set tmt [get_largest_timeout]
4897 {uplevel remote_expect host $tmt $expcode} string]
4900 global errorInfo errorCode
4902 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
4904 return -code $code $string
4908 # gdb_expect_list TEST SENTINEL LIST -- expect a sequence of outputs
4910 # Check for long sequence of output by parts.
4911 # TEST: is the test message to be printed with the test success/fail.
4912 # SENTINEL: Is the terminal pattern indicating that output has finished.
4913 # LIST: is the sequence of outputs to match.
4914 # If the sentinel is recognized early, it is considered an error.
4917 # 1 if the test failed,
4918 # 0 if the test passes,
4919 # -1 if there was an internal error.
4921 proc gdb_expect_list {test sentinel list} {
4926 while { ${index} < [llength ${list}] } {
4927 set pattern [lindex ${list} ${index}]
4928 set index [expr ${index} + 1]
4929 verbose -log "gdb_expect_list pattern: /$pattern/" 2
4930 if { ${index} == [llength ${list}] } {
4933 -re "${pattern}${sentinel}" {
4934 # pass "${test}, pattern ${index} + sentinel"
4937 fail "${test} (pattern ${index} + sentinel)"
4940 -re ".*A problem internal to GDB has been detected" {
4941 fail "${test} (GDB internal error)"
4943 gdb_internal_error_resync
4946 fail "${test} (pattern ${index} + sentinel) (timeout)"
4951 # unresolved "${test}, pattern ${index} + sentinel"
4957 # pass "${test}, pattern ${index}"
4960 fail "${test} (pattern ${index})"
4963 -re ".*A problem internal to GDB has been detected" {
4964 fail "${test} (GDB internal error)"
4966 gdb_internal_error_resync
4969 fail "${test} (pattern ${index}) (timeout)"
4974 # unresolved "${test}, pattern ${index}"
4986 # Spawn the gdb process.
4988 # This doesn't expect any output or do any other initialization,
4989 # leaving those to the caller.
4991 # Overridable function -- you can override this function in your
4994 proc gdb_spawn { } {
4998 # Spawn GDB with CMDLINE_FLAGS appended to the GDBFLAGS global.
5000 proc gdb_spawn_with_cmdline_opts { cmdline_flags } {
5003 set saved_gdbflags $GDBFLAGS
5005 if {$GDBFLAGS != ""} {
5008 append GDBFLAGS $cmdline_flags
5012 set GDBFLAGS $saved_gdbflags
5017 # Start gdb running, wait for prompt, and disable the pagers.
5019 # Overridable function -- you can override this function in your
5022 proc gdb_start { } {
5027 catch default_gdb_exit
5030 # Return true if we can spawn a program on the target and attach to
5033 proc can_spawn_for_attach { } {
5034 # We use exp_pid to get the inferior's pid, assuming that gives
5035 # back the pid of the program. On remote boards, that would give
5036 # us instead the PID of e.g., the ssh client, etc.
5037 if [is_remote target] then {
5041 # The "attach" command doesn't make sense when the target is
5042 # stub-like, where GDB finds the program already started on
5043 # initial connection.
5044 if {[target_info exists use_gdb_stub]} {
5052 # Kill a progress previously started with spawn_wait_for_attach, and
5053 # reap its wait status. PROC_SPAWN_ID is the spawn id associated with
5056 proc kill_wait_spawned_process { proc_spawn_id } {
5057 set pid [exp_pid -i $proc_spawn_id]
5059 verbose -log "killing ${pid}"
5060 remote_exec build "kill -9 ${pid}"
5062 verbose -log "closing ${proc_spawn_id}"
5063 catch "close -i $proc_spawn_id"
5064 verbose -log "waiting for ${proc_spawn_id}"
5066 # If somehow GDB ends up still attached to the process here, a
5067 # blocking wait hangs until gdb is killed (or until gdb / the
5068 # ptracer reaps the exit status too, but that won't happen because
5069 # something went wrong.) Passing -nowait makes expect tell Tcl to
5070 # wait for the PID in the background. That's fine because we
5071 # don't care about the exit status. */
5072 wait -nowait -i $proc_spawn_id
5075 # Returns the process id corresponding to the given spawn id.
5077 proc spawn_id_get_pid { spawn_id } {
5078 set testpid [exp_pid -i $spawn_id]
5080 if { [istarget "*-*-cygwin*"] } {
5081 # testpid is the Cygwin PID, GDB uses the Windows PID, which
5082 # might be different due to the way fork/exec works.
5083 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
5089 # Start a set of programs running and then wait for a bit, to be sure
5090 # that they can be attached to. Return a list of processes spawn IDs,
5091 # one element for each process spawned. It's a test error to call
5092 # this when [can_spawn_for_attach] is false.
5094 proc spawn_wait_for_attach { executable_list } {
5095 set spawn_id_list {}
5097 if ![can_spawn_for_attach] {
5098 # The caller should have checked can_spawn_for_attach itself
5099 # before getting here.
5100 error "can't spawn for attach with this target/board"
5103 foreach {executable} $executable_list {
5104 # Note we use Expect's spawn, not Tcl's exec, because with
5105 # spawn we control when to wait for/reap the process. That
5106 # allows killing the process by PID without being subject to
5108 lappend spawn_id_list [remote_spawn target $executable]
5113 return $spawn_id_list
5117 # gdb_load_cmd -- load a file into the debugger.
5118 # ARGS - additional args to load command.
5119 # return a -1 if anything goes wrong.
5121 proc gdb_load_cmd { args } {
5124 if [target_info exists gdb_load_timeout] {
5125 set loadtimeout [target_info gdb_load_timeout]
5127 set loadtimeout 1600
5129 send_gdb "load $args\n"
5130 verbose "Timeout is now $loadtimeout seconds" 2
5131 gdb_expect $loadtimeout {
5132 -re "Loading section\[^\r\]*\r\n" {
5135 -re "Start address\[\r\]*\r\n" {
5138 -re "Transfer rate\[\r\]*\r\n" {
5141 -re "Memory access error\[^\r\]*\r\n" {
5142 perror "Failed to load program"
5145 -re "$gdb_prompt $" {
5148 -re "(.*)\r\n$gdb_prompt " {
5149 perror "Unexpected reponse from 'load' -- $expect_out(1,string)"
5153 perror "Timed out trying to load $args."
5160 # Invoke "gcore". CORE is the name of the core file to write. TEST
5161 # is the name of the test case. This will return 1 if the core file
5162 # was created, 0 otherwise. If this fails to make a core file because
5163 # this configuration of gdb does not support making core files, it
5164 # will call "unsupported", not "fail". However, if this fails to make
5165 # a core file for some other reason, then it will call "fail".
5167 proc gdb_gcore_cmd {core test} {
5171 gdb_test_multiple "gcore $core" $test {
5172 -re "Saved corefile .*\[\r\n\]+$gdb_prompt $" {
5176 -re "(?:Can't create a corefile|Target does not support core file generation\\.)\[\r\n\]+$gdb_prompt $" {
5184 # Load core file CORE. TEST is the name of the test case.
5185 # This will record a pass/fail for loading the core file.
5187 # 1 - core file is successfully loaded
5188 # 0 - core file loaded but has a non fatal error
5189 # -1 - core file failed to load
5191 proc gdb_core_cmd { core test } {
5194 gdb_test_multiple "core $core" "$test" {
5195 -re "\\\[Thread debugging using \[^ \r\n\]* enabled\\\]\r\n" {
5198 -re " is not a core dump:.*\r\n$gdb_prompt $" {
5199 fail "$test (bad file format)"
5202 -re -wrap "[string_to_regexp $core]: No such file or directory.*" {
5203 fail "$test (file not found)"
5206 -re "Couldn't find .* registers in core file.*\r\n$gdb_prompt $" {
5207 fail "$test (incomplete note section)"
5210 -re "Core was generated by .*\r\n$gdb_prompt $" {
5214 -re ".*$gdb_prompt $" {
5219 fail "$test (timeout)"
5223 fail "unsupported output from 'core' command"
5227 # Return the filename to download to the target and load on the target
5228 # for this shared library. Normally just LIBNAME, unless shared libraries
5229 # for this target have separate link and load images.
5231 proc shlib_target_file { libname } {
5235 # Return the filename GDB will load symbols from when debugging this
5236 # shared library. Normally just LIBNAME, unless shared libraries for
5237 # this target have separate link and load images.
5239 proc shlib_symbol_file { libname } {
5243 # Return the filename to download to the target and load for this
5244 # executable. Normally just BINFILE unless it is renamed to something
5245 # else for this target.
5247 proc exec_target_file { binfile } {
5251 # Return the filename GDB will load symbols from when debugging this
5252 # executable. Normally just BINFILE unless executables for this target
5253 # have separate files for symbols.
5255 proc exec_symbol_file { binfile } {
5259 # Rename the executable file. Normally this is just BINFILE1 being renamed
5260 # to BINFILE2, but some targets require multiple binary files.
5261 proc gdb_rename_execfile { binfile1 binfile2 } {
5262 file rename -force [exec_target_file ${binfile1}] \
5263 [exec_target_file ${binfile2}]
5264 if { [exec_target_file ${binfile1}] != [exec_symbol_file ${binfile1}] } {
5265 file rename -force [exec_symbol_file ${binfile1}] \
5266 [exec_symbol_file ${binfile2}]
5270 # "Touch" the executable file to update the date. Normally this is just
5271 # BINFILE, but some targets require multiple files.
5272 proc gdb_touch_execfile { binfile } {
5273 set time [clock seconds]
5274 file mtime [exec_target_file ${binfile}] $time
5275 if { [exec_target_file ${binfile}] != [exec_symbol_file ${binfile}] } {
5276 file mtime [exec_symbol_file ${binfile}] $time
5280 # Like remote_download but provides a gdb-specific behavior.
5282 # If the destination board is remote, the local file FROMFILE is transferred as
5283 # usual with remote_download to TOFILE on the remote board. The destination
5284 # filename is added to the CLEANFILES global, so it can be cleaned up at the
5287 # If the destination board is local, the destination path TOFILE is passed
5288 # through standard_output_file, and FROMFILE is copied there.
5290 # In both cases, if TOFILE is omitted, it defaults to the [file tail] of
5293 proc gdb_remote_download {dest fromfile {tofile {}}} {
5294 # If TOFILE is not given, default to the same filename as FROMFILE.
5295 if {[string length $tofile] == 0} {
5296 set tofile [file tail $fromfile]
5299 if {[is_remote $dest]} {
5300 # When the DEST is remote, we simply send the file to DEST.
5303 set destname [remote_download $dest $fromfile $tofile]
5304 lappend cleanfiles $destname
5308 # When the DEST is local, we copy the file to the test directory (where
5309 # the executable is).
5311 # Note that we pass TOFILE through standard_output_file, regardless of
5312 # whether it is absolute or relative, because we don't want the tests
5313 # to be able to write outside their standard output directory.
5315 set tofile [standard_output_file $tofile]
5317 file copy -force $fromfile $tofile
5323 # gdb_load_shlib LIB...
5325 # Copy the listed library to the target.
5327 proc gdb_load_shlib { file } {
5330 if ![info exists gdb_spawn_id] {
5331 perror "gdb_load_shlib: GDB is not running"
5334 set dest [gdb_remote_download target [shlib_target_file $file]]
5336 if {[is_remote target]} {
5337 # If the target is remote, we need to tell gdb where to find the
5340 # We could set this even when not testing remotely, but a user
5341 # generally won't set it unless necessary. In order to make the tests
5342 # more like the real-life scenarios, we don't set it for local testing.
5343 gdb_test "set solib-search-path [file dirname $file]" "" ""
5350 # gdb_load -- load a file into the debugger. Specifying no file
5351 # defaults to the executable currently being debugged.
5352 # The return value is 0 for success, -1 for failure.
5353 # Many files in config/*.exp override this procedure.
5355 proc gdb_load { arg } {
5357 return [gdb_file_cmd $arg]
5363 # with_complaints -- Execute BODY and set complaints temporary to N for the
5366 proc with_complaints { n body } {
5369 # Save current setting of complaints.
5371 set show_complaints_re \
5372 "Max number of complaints about incorrect symbols is ($decimal)\\."
5373 gdb_test_multiple "show complaints" "" {
5374 -re -wrap $show_complaints_re {
5375 set save $expect_out(1,string)
5379 if { $save == "" } {
5380 perror "Did not manage to set complaints"
5383 gdb_test_no_output "set complaints $n" ""
5386 set code [catch {uplevel 1 $body} result]
5388 # Restore saved setting of complaints.
5389 if { $save != "" } {
5390 gdb_test_no_output "set complaints $save" ""
5394 global errorInfo errorCode
5395 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
5397 return -code $code $result
5402 # gdb_load_no_complaints -- As gdb_load, but in addition verifies that
5403 # loading caused no symbol reading complaints.
5405 proc gdb_load_no_complaints { arg } {
5406 global gdb_prompt gdb_file_cmd_msg decimal
5408 # Temporarily set complaint to a small non-zero number.
5413 # Verify that there were no complaints.
5416 "^(Reading symbols from \[^\r\n\]*" \
5417 ")+(Expanding full symbols from \[^\r\n\]*" \
5419 gdb_assert {[regexp $re $gdb_file_cmd_msg]} "No complaints"
5422 # gdb_reload -- load a file into the target. Called before "running",
5423 # either the first time or after already starting the program once,
5424 # for remote targets. Most files that override gdb_load should now
5425 # override this instead.
5427 # INFERIOR_ARGS contains the arguments to pass to the inferiors, as a
5428 # single string to get interpreted by a shell. If the target board
5429 # overriding gdb_reload is a "stub", then it should arrange things such
5430 # these arguments make their way to the inferior process.
5432 proc gdb_reload { {inferior_args {}} } {
5433 # For the benefit of existing configurations, default to gdb_load.
5434 # Specifying no file defaults to the executable currently being
5436 return [gdb_load ""]
5439 proc gdb_continue { function } {
5442 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"]
5445 # Default implementation of gdb_init.
5446 proc default_gdb_init { test_file_name } {
5447 global gdb_wrapper_initialized
5448 global gdb_wrapper_target
5449 global gdb_test_file_name
5453 # Reset the timeout value to the default. This way, any testcase
5454 # that changes the timeout value without resetting it cannot affect
5455 # the timeout used in subsequent testcases.
5456 global gdb_test_timeout
5458 set timeout $gdb_test_timeout
5460 if { [regexp ".*gdb\.reverse\/.*" $test_file_name]
5461 && [target_info exists gdb_reverse_timeout] } {
5462 set timeout [target_info gdb_reverse_timeout]
5465 # If GDB_INOTIFY is given, check for writes to '.'. This is a
5466 # debugging tool to help confirm that the test suite is
5467 # parallel-safe. You need "inotifywait" from the
5468 # inotify-tools package to use this.
5469 global GDB_INOTIFY inotify_pid
5470 if {[info exists GDB_INOTIFY] && ![info exists inotify_pid]} {
5471 global outdir tool inotify_log_file
5473 set exclusions {outputs temp gdb[.](log|sum) cache}
5474 set exclusion_re ([join $exclusions |])
5476 set inotify_log_file [standard_temp_file inotify.out]
5477 set inotify_pid [exec inotifywait -r -m -e move,create,delete . \
5478 --exclude $exclusion_re \
5479 |& tee -a $outdir/$tool.log $inotify_log_file &]
5481 # Wait for the watches; hopefully this is long enough.
5484 # Clear the log so that we don't emit a warning the first time
5486 set fd [open $inotify_log_file w]
5490 # Block writes to all banned variables, and invocation of all
5491 # banned procedures...
5492 global banned_variables
5493 global banned_procedures
5494 global banned_traced
5495 if (!$banned_traced) {
5496 foreach banned_var $banned_variables {
5497 global "$banned_var"
5498 trace add variable "$banned_var" write error
5500 foreach banned_proc $banned_procedures {
5501 global "$banned_proc"
5502 trace add execution "$banned_proc" enter error
5507 # We set LC_ALL, LC_CTYPE, and LANG to C so that we get the same
5508 # messages as expected.
5513 # Don't let a .inputrc file or an existing setting of INPUTRC mess
5514 # up the test results. Certain tests (style tests and TUI tests)
5515 # want to set the terminal to a non-"dumb" value, and for those we
5516 # want to disable bracketed paste mode. Versions of Readline
5517 # before 8.0 will not understand this and will issue a warning.
5518 # We tried using a $if to guard it, but Readline 8.1 had a bug in
5519 # its version-comparison code that prevented this for working.
5520 setenv INPUTRC [cached_file inputrc "set enable-bracketed-paste off"]
5522 # This disables style output, which would interfere with many
5526 # If DEBUGINFOD_URLS is set, gdb will try to download sources and
5527 # debug info for f.i. system libraries. Prevent this.
5528 unset -nocomplain ::env(DEBUGINFOD_URLS)
5530 # Ensure that GDBHISTFILE and GDBHISTSIZE are removed from the
5531 # environment, we don't want these modifications to the history
5533 unset -nocomplain ::env(GDBHISTFILE)
5534 unset -nocomplain ::env(GDBHISTSIZE)
5536 # Ensure that XDG_CONFIG_HOME is not set. Some tests setup a fake
5537 # home directory in order to test loading settings from gdbinit.
5538 # If XDG_CONFIG_HOME is set then GDB will load a gdbinit from
5539 # there (if one is present) rather than the home directory setup
5541 unset -nocomplain ::env(XDG_CONFIG_HOME)
5543 # Initialize GDB's pty with a fixed size, to make sure we avoid pagination
5544 # during startup. See "man expect" for details about stty_init.
5546 set stty_init "rows 25 cols 80"
5548 # Some tests (for example gdb.base/maint.exp) shell out from gdb to use
5549 # grep. Clear GREP_OPTIONS to make the behavior predictable,
5550 # especially having color output turned on can cause tests to fail.
5551 setenv GREP_OPTIONS ""
5553 # Clear $gdbserver_reconnect_p.
5554 global gdbserver_reconnect_p
5555 set gdbserver_reconnect_p 1
5556 unset gdbserver_reconnect_p
5558 # Clear $last_loaded_file
5559 global last_loaded_file
5560 unset -nocomplain last_loaded_file
5562 # Reset GDB number of instances
5563 global gdb_instances
5568 set gdb_test_file_name [file rootname [file tail $test_file_name]]
5570 # Make sure that the wrapper is rebuilt
5571 # with the appropriate multilib option.
5572 if { $gdb_wrapper_target != [current_target_name] } {
5573 set gdb_wrapper_initialized 0
5576 # Unlike most tests, we have a small number of tests that generate
5577 # a very large amount of output. We therefore increase the expect
5578 # buffer size to be able to contain the entire test output. This
5579 # is especially needed by gdb.base/info-macros.exp.
5581 # Also set this value for the currently running GDB.
5582 match_max [match_max -d]
5584 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
5585 set pf_prefix "[file tail [file dirname $test_file_name]]/[file tail $test_file_name]:"
5588 if [target_info exists gdb_prompt] {
5589 set gdb_prompt [target_info gdb_prompt]
5591 set gdb_prompt "\\(gdb\\)"
5594 if [info exists use_gdb_stub] {
5598 gdb_setup_known_globals
5600 if { [info procs ::gdb_tcl_unknown] != "" } {
5601 # Dejagnu overrides proc unknown. The dejagnu version may trigger in a
5602 # test-case but abort the entire test run. To fix this, we install a
5603 # local version here, which reverts dejagnu's override, and restore
5604 # dejagnu's version in gdb_finish.
5605 rename ::unknown ::dejagnu_unknown
5606 proc unknown { args } {
5607 # Use tcl's unknown.
5608 set cmd [lindex $args 0]
5609 unresolved "testcase aborted due to invalid command name: $cmd"
5610 return [uplevel 1 ::gdb_tcl_unknown $args]
5615 # Return a path using GDB_PARALLEL.
5616 # ARGS is a list of path elements to append to "$objdir/$GDB_PARALLEL".
5617 # GDB_PARALLEL must be defined, the caller must check.
5619 # The default value for GDB_PARALLEL is, canonically, ".".
5620 # The catch is that tests don't expect an additional "./" in file paths so
5621 # omit any directory for the default case.
5622 # GDB_PARALLEL is written as "yes" for the default case in Makefile.in to mark
5623 # its special handling.
5625 proc make_gdb_parallel_path { args } {
5626 global GDB_PARALLEL objdir
5627 set joiner [list "file" "join" $objdir]
5628 if { [info exists GDB_PARALLEL] && $GDB_PARALLEL != "yes" } {
5629 lappend joiner $GDB_PARALLEL
5631 set joiner [concat $joiner $args]
5632 return [eval $joiner]
5635 # Turn BASENAME into a full file name in the standard output
5636 # directory. It is ok if BASENAME is the empty string; in this case
5637 # the directory is returned.
5639 proc standard_output_file {basename} {
5640 global objdir subdir gdb_test_file_name
5642 set dir [make_gdb_parallel_path outputs $subdir $gdb_test_file_name]
5644 # If running on MinGW, replace /c/foo with c:/foo
5645 if { [ishost *-*-mingw*] } {
5646 set dir [exec sh -c "cd ${dir} && pwd -W"]
5648 return [file join $dir $basename]
5651 # Turn BASENAME into a full file name in the standard output directory. If
5652 # GDB has been launched more than once then append the count, starting with
5655 proc standard_output_file_with_gdb_instance {basename} {
5656 global gdb_instances
5657 set count $gdb_instances
5660 return [standard_output_file $basename]
5662 return [standard_output_file ${basename}.${count}]
5665 # Return the name of a file in our standard temporary directory.
5667 proc standard_temp_file {basename} {
5668 # Since a particular runtest invocation is only executing a single test
5669 # file at any given time, we can use the runtest pid to build the
5670 # path of the temp directory.
5671 set dir [make_gdb_parallel_path temp [pid]]
5673 return [file join $dir $basename]
5676 # Rename file A to file B, if B does not already exists. Otherwise, leave B
5677 # as is and delete A. Return 1 if rename happened.
5679 proc tentative_rename { a b } {
5680 global errorInfo errorCode
5681 set code [catch {file rename -- $a $b} result]
5682 if { $code == 1 && [lindex $errorCode 0] == "POSIX" \
5683 && [lindex $errorCode 1] == "EEXIST" } {
5688 return -code error -errorinfo $errorInfo -errorcode $errorCode $result
5689 } elseif {$code > 1} {
5690 return -code $code $result
5695 # Create a file with name FILENAME and contents TXT in the cache directory.
5696 # If EXECUTABLE, mark the new file for execution.
5698 proc cached_file { filename txt {executable 0}} {
5699 set filename [make_gdb_parallel_path cache $filename]
5701 if { [file exists $filename] } {
5705 set dir [file dirname $filename]
5708 set tmp_filename $filename.[pid]
5709 set fd [open $tmp_filename w]
5713 if { $executable } {
5714 exec chmod +x $tmp_filename
5716 tentative_rename $tmp_filename $filename
5721 # Set 'testfile', 'srcfile', and 'binfile'.
5723 # ARGS is a list of source file specifications.
5724 # Without any arguments, the .exp file's base name is used to
5725 # compute the source file name. The ".c" extension is added in this case.
5726 # If ARGS is not empty, each entry is a source file specification.
5727 # If the specification starts with a "." or "-", it is treated as a suffix
5728 # to append to the .exp file's base name.
5729 # If the specification is the empty string, it is treated as if it
5731 # Otherwise it is a file name.
5732 # The first file in the list is used to set the 'srcfile' global.
5733 # Each subsequent name is used to set 'srcfile2', 'srcfile3', etc.
5735 # Most tests should call this without arguments.
5737 # If a completely different binary file name is needed, then it
5738 # should be handled in the .exp file with a suitable comment.
5740 proc standard_testfile {args} {
5741 global gdb_test_file_name
5743 global gdb_test_file_last_vars
5746 global testfile binfile
5748 set testfile $gdb_test_file_name
5749 set binfile [standard_output_file ${testfile}]
5751 if {[llength $args] == 0} {
5755 # Unset our previous output variables.
5756 # This can help catch hidden bugs.
5757 if {[info exists gdb_test_file_last_vars]} {
5758 foreach varname $gdb_test_file_last_vars {
5760 catch {unset $varname}
5763 # 'executable' is often set by tests.
5764 set gdb_test_file_last_vars {executable}
5768 set varname srcfile$suffix
5771 # Handle an extension.
5775 set first [string range $arg 0 0]
5776 if { $first == "." || $first == "-" } {
5777 set arg $testfile$arg
5782 lappend gdb_test_file_last_vars $varname
5784 if {$suffix == ""} {
5792 # The default timeout used when testing GDB commands. We want to use
5793 # the same timeout as the default dejagnu timeout, unless the user has
5794 # already provided a specific value (probably through a site.exp file).
5795 global gdb_test_timeout
5796 if ![info exists gdb_test_timeout] {
5797 set gdb_test_timeout $timeout
5800 # A list of global variables that GDB testcases should not use.
5801 # We try to prevent their use by monitoring write accesses and raising
5802 # an error when that happens.
5803 set banned_variables { bug_id prms_id }
5805 # A list of procedures that GDB testcases should not use.
5806 # We try to prevent their use by monitoring invocations and raising
5807 # an error when that happens.
5808 set banned_procedures { strace }
5810 # gdb_init is called by runtest at start, but also by several
5811 # tests directly; gdb_finish is only called from within runtest after
5812 # each test source execution.
5813 # Placing several traces by repetitive calls to gdb_init leads
5814 # to problems, as only one trace is removed in gdb_finish.
5815 # To overcome this possible problem, we add a variable that records
5816 # if the banned variables and procedures are already traced.
5819 # Global array that holds the name of all global variables at the time
5820 # a test script is started. After the test script has completed any
5821 # global not in this list is deleted.
5822 array set gdb_known_globals {}
5824 # Setup the GDB_KNOWN_GLOBALS array with the names of all current
5826 proc gdb_setup_known_globals {} {
5827 global gdb_known_globals
5829 array set gdb_known_globals {}
5830 foreach varname [info globals] {
5831 set gdb_known_globals($varname) 1
5835 # Cleanup the global namespace. Any global not in the
5836 # GDB_KNOWN_GLOBALS array is unset, this ensures we don't "leak"
5837 # globals from one test script to another.
5838 proc gdb_cleanup_globals {} {
5839 global gdb_known_globals gdb_persistent_globals
5841 foreach varname [info globals] {
5842 if {![info exists gdb_known_globals($varname)]} {
5843 if { [info exists gdb_persistent_globals($varname)] } {
5846 uplevel #0 unset $varname
5851 # Create gdb_tcl_unknown, a copy tcl's ::unknown, provided it's present as a
5853 set temp [interp create]
5854 if { [interp eval $temp "info procs ::unknown"] != "" } {
5855 set old_args [interp eval $temp "info args ::unknown"]
5856 set old_body [interp eval $temp "info body ::unknown"]
5857 eval proc gdb_tcl_unknown {$old_args} {$old_body}
5862 # GDB implementation of ${tool}_init. Called right before executing the
5864 # Overridable function -- you can override this function in your
5866 proc gdb_init { args } {
5867 # A baseboard file overriding this proc and calling the default version
5868 # should behave the same as this proc. So, don't add code here, but to
5869 # the default version instead.
5870 return [default_gdb_init {*}$args]
5873 # GDB implementation of ${tool}_finish. Called right after executing the
5875 proc gdb_finish { } {
5876 global gdbserver_reconnect_p
5879 global known_globals
5881 if { [info procs ::gdb_tcl_unknown] != "" } {
5882 # Restore dejagnu's version of proc unknown.
5884 rename ::dejagnu_unknown ::unknown
5887 # Exit first, so that the files are no longer in use.
5890 if { [llength $cleanfiles] > 0 } {
5891 eval remote_file target delete $cleanfiles
5895 # Unblock write access to the banned variables. Dejagnu typically
5896 # resets some of them between testcases.
5897 global banned_variables
5898 global banned_procedures
5899 global banned_traced
5900 if ($banned_traced) {
5901 foreach banned_var $banned_variables {
5902 global "$banned_var"
5903 trace remove variable "$banned_var" write error
5905 foreach banned_proc $banned_procedures {
5906 global "$banned_proc"
5907 trace remove execution "$banned_proc" enter error
5912 global gdb_finish_hooks
5913 foreach gdb_finish_hook $gdb_finish_hooks {
5916 set gdb_finish_hooks [list]
5922 set debug_format "unknown"
5924 # Run the gdb command "info source" and extract the debugging format
5925 # information from the output and save it in debug_format.
5927 proc get_debug_format { } {
5932 set debug_format "unknown"
5933 send_gdb "info source\n"
5935 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
5936 set debug_format $expect_out(1,string)
5937 verbose "debug format is $debug_format"
5940 -re "No current source file.\r\n$gdb_prompt $" {
5941 perror "get_debug_format used when no current source file"
5944 -re "$gdb_prompt $" {
5945 warning "couldn't check debug format (no valid response)."
5949 warning "couldn't check debug format (timeout)."
5955 # Return true if FORMAT matches the debug format the current test was
5956 # compiled with. FORMAT is a shell-style globbing pattern; it can use
5957 # `*', `[...]', and so on.
5959 # This function depends on variables set by `get_debug_format', above.
5961 proc test_debug_format {format} {
5964 return [expr [string match $format $debug_format] != 0]
5967 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
5968 # COFF, stabs, etc). If that format matches the format that the
5969 # current test was compiled with, then the next test is expected to
5970 # fail for any target. Returns 1 if the next test or set of tests is
5971 # expected to fail, 0 otherwise (or if it is unknown). Must have
5972 # previously called get_debug_format.
5973 proc setup_xfail_format { format } {
5974 set ret [test_debug_format $format]
5982 # gdb_get_line_number TEXT [FILE]
5984 # Search the source file FILE, and return the line number of the
5985 # first line containing TEXT. If no match is found, an error is thrown.
5987 # TEXT is a string literal, not a regular expression.
5989 # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is
5990 # specified, and does not start with "/", then it is assumed to be in
5991 # "$srcdir/$subdir". This is awkward, and can be fixed in the future,
5992 # by changing the callers and the interface at the same time.
5993 # In particular: gdb.base/break.exp, gdb.base/condbreak.exp,
5994 # gdb.base/ena-dis-br.exp.
5996 # Use this function to keep your test scripts independent of the
5997 # exact line numbering of the source file. Don't write:
5999 # send_gdb "break 20"
6001 # This means that if anyone ever edits your test's source file,
6002 # your test could break. Instead, put a comment like this on the
6003 # source file line you want to break at:
6005 # /* breakpoint spot: frotz.exp: test name */
6007 # and then write, in your test script (which we assume is named
6010 # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
6012 # (Yes, Tcl knows how to handle the nested quotes and brackets.
6015 # % puts "foo [lindex "bar baz" 1]"
6018 # Tcl is quite clever, for a little stringy language.)
6022 # The previous implementation of this procedure used the gdb search command.
6023 # This version is different:
6025 # . It works with MI, and it also works when gdb is not running.
6027 # . It operates on the build machine, not the host machine.
6029 # . For now, this implementation fakes a current directory of
6030 # $srcdir/$subdir to be compatible with the old implementation.
6031 # This will go away eventually and some callers will need to
6034 # . The TEXT argument is literal text and matches literally,
6035 # not a regular expression as it was before.
6037 # . State changes in gdb, such as changing the current file
6038 # and setting $_, no longer happen.
6040 # After a bit of time we can forget about the differences from the
6041 # old implementation.
6043 # --chastain 2004-08-05
6045 proc gdb_get_line_number { text { file "" } } {
6050 if { "$file" == "" } then {
6053 if { ! [regexp "^/" "$file"] } then {
6054 set file "$srcdir/$subdir/$file"
6057 if { [ catch { set fd [open "$file"] } message ] } then {
6062 for { set line 1 } { 1 } { incr line } {
6063 if { [ catch { set nchar [gets "$fd" body] } message ] } then {
6066 if { $nchar < 0 } then {
6069 if { [string first "$text" "$body"] >= 0 } then {
6075 if { [ catch { close "$fd" } message ] } then {
6080 error "undefined tag \"$text\""
6086 # Continue the program until it ends.
6088 # MSSG is the error message that gets printed. If not given, a
6090 # COMMAND is the command to invoke. If not given, "continue" is
6092 # ALLOW_EXTRA is a flag indicating whether the test should expect
6093 # extra output between the "Continuing." line and the program
6094 # exiting. By default it is zero; if nonzero, any extra output
6097 proc gdb_continue_to_end {{mssg ""} {command continue} {allow_extra 0}} {
6098 global inferior_exited_re use_gdb_stub
6101 set text "continue until exit"
6103 set text "continue until exit at $mssg"
6111 # By default, we don't rely on exit() behavior of remote stubs --
6112 # it's common for exit() to be implemented as a simple infinite
6113 # loop, or a forced crash/reset. For native targets, by default, we
6114 # assume process exit is reported as such. If a non-reliable target
6115 # is used, we set a breakpoint at exit, and continue to that.
6116 if { [target_info exists exit_is_reliable] } {
6117 set exit_is_reliable [target_info exit_is_reliable]
6119 set exit_is_reliable [expr ! $use_gdb_stub]
6122 if { ! $exit_is_reliable } {
6123 if {![gdb_breakpoint "exit"]} {
6126 gdb_test $command "Continuing..*Breakpoint .*exit.*" \
6129 # Continue until we exit. Should not stop again.
6130 # Don't bother to check the output of the program, that may be
6131 # extremely tough for some remote systems.
6133 "Continuing.\[\r\n0-9\]+${extra}(... EXIT code 0\[\r\n\]+|$inferior_exited_re normally).*"\
6138 proc rerun_to_main {} {
6139 global gdb_prompt use_gdb_stub
6144 -re ".*Breakpoint .*main .*$gdb_prompt $"\
6145 {pass "rerun to main" ; return 0}
6146 -re "$gdb_prompt $"\
6147 {fail "rerun to main" ; return 0}
6148 timeout {fail "(timeout) rerun to main" ; return 0}
6153 -re "The program .* has been started already.*y or n. $" {
6154 send_gdb "y\n" answer
6157 -re "Starting program.*$gdb_prompt $"\
6158 {pass "rerun to main" ; return 0}
6159 -re "$gdb_prompt $"\
6160 {fail "rerun to main" ; return 0}
6161 timeout {fail "(timeout) rerun to main" ; return 0}
6166 # Return true if EXECUTABLE contains a .gdb_index or .debug_names index section.
6168 proc exec_has_index_section { executable } {
6169 set readelf_program [gdb_find_readelf]
6170 set res [catch {exec $readelf_program -S $executable \
6171 | grep -E "\.gdb_index|\.debug_names" }]
6178 # Return list with major and minor version of readelf, or an empty list.
6179 gdb_caching_proc readelf_version {
6180 set readelf_program [gdb_find_readelf]
6181 set res [catch {exec $readelf_program --version} output]
6185 set lines [split $output \n]
6186 set line [lindex $lines 0]
6187 set res [regexp {[ \t]+([0-9]+)[.]([0-9]+)[^ \t]*$} \
6188 $line dummy major minor]
6192 return [list $major $minor]
6195 # Return 1 if readelf prints the PIE flag, 0 if is doesn't, and -1 if unknown.
6196 proc readelf_prints_pie { } {
6197 set version [readelf_version]
6198 if { [llength $version] == 0 } {
6201 set major [lindex $version 0]
6202 set minor [lindex $version 1]
6203 # It would be better to construct a PIE executable and test if the PIE
6204 # flag is printed by readelf, but we cannot reliably construct a PIE
6205 # executable if the multilib_flags dictate otherwise
6206 # (--target_board=unix/-no-pie/-fno-PIE).
6207 return [version_at_least $major $minor 2 26]
6210 # Return 1 if EXECUTABLE is a Position Independent Executable, 0 if it is not,
6211 # and -1 if unknown.
6213 proc exec_is_pie { executable } {
6214 set res [readelf_prints_pie]
6218 set readelf_program [gdb_find_readelf]
6219 # We're not testing readelf -d | grep "FLAGS_1.*Flags:.*PIE"
6220 # because the PIE flag is not set by all versions of gold, see PR
6222 set res [catch {exec $readelf_program -h $executable} output]
6226 set res [regexp -line {^[ \t]*Type:[ \t]*DYN \((Position-Independent Executable|Shared object) file\)$} \
6234 # Return true if a test should be skipped due to lack of floating
6235 # point support or GDB can't fetch the contents from floating point
6238 gdb_caching_proc gdb_skip_float_test {
6239 if [target_info exists gdb,skip_float_tests] {
6243 # There is an ARM kernel ptrace bug that hardware VFP registers
6244 # are not updated after GDB ptrace set VFP registers. The bug
6245 # was introduced by kernel commit 8130b9d7b9d858aa04ce67805e8951e3cb6e9b2f
6246 # in 2012 and is fixed in e2dfb4b880146bfd4b6aa8e138c0205407cebbaf
6247 # in May 2016. In other words, kernels older than 4.6.3, 4.4.14,
6248 # 4.1.27, 3.18.36, and 3.14.73 have this bug.
6249 # This kernel bug is detected by check how does GDB change the
6250 # program result by changing one VFP register.
6251 if { [istarget "arm*-*-linux*"] } {
6253 set compile_flags {debug nowarnings }
6255 # Set up, compile, and execute a test program having VFP
6257 set src [standard_temp_file arm_vfp[pid].c]
6258 set exe [standard_temp_file arm_vfp[pid].x]
6260 gdb_produce_source $src {
6265 asm ("vldr d0, [%0]" : : "r" (&d));
6266 asm ("vldr d1, [%0]" : : "r" (&d));
6267 asm (".global break_here\n"
6269 asm ("vcmp.f64 d0, d1\n"
6270 "vmrs APSR_nzcv, fpscr\n"
6271 "bne L_value_different\n"
6274 "L_value_different:\n"
6276 "L_end:\n" : "=r" (ret) :);
6278 /* Return $d0 != $d1. */
6283 verbose "compiling testfile $src" 2
6284 set lines [gdb_compile $src $exe executable $compile_flags]
6287 if ![string match "" $lines] then {
6288 verbose "testfile compilation failed, returning 1" 2
6292 # No error message, compilation succeeded so now run it via gdb.
6293 # Run the test up to 5 times to detect whether ptrace can
6294 # correctly update VFP registers or not.
6296 for {set i 0} {$i < 5} {incr i} {
6297 global gdb_prompt srcdir subdir
6301 gdb_reinitialize_dir $srcdir/$subdir
6305 gdb_test "break *break_here"
6306 gdb_continue_to_breakpoint "break_here"
6308 # Modify $d0 to a different value, so the exit code should
6310 gdb_test "set \$d0 = 5.0"
6312 set test "continue to exit"
6313 gdb_test_multiple "continue" "$test" {
6314 -re "exited with code 01.*$gdb_prompt $" {
6316 -re "exited normally.*$gdb_prompt $" {
6317 # However, the exit code is 0. That means something
6318 # wrong in setting VFP registers.
6326 remote_file build delete $exe
6328 return $skip_vfp_test
6333 # Print a message and return true if a test should be skipped
6334 # due to lack of stdio support.
6336 proc gdb_skip_stdio_test { msg } {
6337 if [target_info exists gdb,noinferiorio] {
6338 verbose "Skipping test '$msg': no inferior i/o."
6344 proc gdb_skip_bogus_test { msg } {
6348 # Return true if a test should be skipped due to lack of XML support
6350 # NOTE: This must be called while gdb is *not* running.
6352 gdb_caching_proc gdb_skip_xml_test {
6357 if { [info exists gdb_spawn_id] } {
6358 error "GDB must not be running in gdb_skip_xml_tests."
6361 set xml_file [gdb_remote_download host "${srcdir}/gdb.xml/trivial.xml"]
6365 gdb_test_multiple "set tdesc filename $xml_file" "" {
6366 -re ".*XML support was disabled at compile time.*$gdb_prompt $" {
6369 -re ".*$gdb_prompt $" { }
6375 # Return true if argv[0] is available.
6377 gdb_caching_proc gdb_has_argv0 {
6380 # Compile and execute a test program to check whether argv[0] is available.
6381 gdb_simple_compile has_argv0 {
6382 int main (int argc, char **argv) {
6389 proc gdb_has_argv0_1 { exe } {
6390 global srcdir subdir
6391 global gdb_prompt hex
6395 gdb_reinitialize_dir $srcdir/$subdir
6398 # Set breakpoint on main.
6399 gdb_test_multiple "break -q main" "break -q main" {
6400 -re "Breakpoint.*${gdb_prompt} $" {
6402 -re "${gdb_prompt} $" {
6409 gdb_test_multiple "" "run to main" {
6410 -re "Breakpoint.*${gdb_prompt} $" {
6412 -re "${gdb_prompt} $" {
6417 set old_elements "200"
6418 set test "show print elements"
6419 gdb_test_multiple $test $test {
6420 -re "Limit on string chars or array elements to print is (\[^\r\n\]+)\\.\r\n$gdb_prompt $" {
6421 set old_elements $expect_out(1,string)
6424 set old_repeats "200"
6425 set test "show print repeats"
6426 gdb_test_multiple $test $test {
6427 -re "Threshold for repeated print elements is (\[^\r\n\]+)\\.\r\n$gdb_prompt $" {
6428 set old_repeats $expect_out(1,string)
6431 gdb_test_no_output "set print elements unlimited" ""
6432 gdb_test_no_output "set print repeats unlimited" ""
6435 # Check whether argc is 1.
6436 gdb_test_multiple "p argc" "p argc" {
6437 -re " = 1\r\n${gdb_prompt} $" {
6439 gdb_test_multiple "p argv\[0\]" "p argv\[0\]" {
6440 -re " = $hex \".*[file tail $exe]\"\r\n${gdb_prompt} $" {
6443 -re "${gdb_prompt} $" {
6447 -re "${gdb_prompt} $" {
6451 gdb_test_no_output "set print elements $old_elements" ""
6452 gdb_test_no_output "set print repeats $old_repeats" ""
6457 set result [gdb_has_argv0_1 $obj]
6463 && ([istarget *-*-linux*]
6464 || [istarget *-*-freebsd*] || [istarget *-*-kfreebsd*]
6465 || [istarget *-*-netbsd*] || [istarget *-*-knetbsd*]
6466 || [istarget *-*-openbsd*]
6467 || [istarget *-*-darwin*]
6468 || [istarget *-*-solaris*]
6469 || [istarget *-*-aix*]
6470 || [istarget *-*-gnu*]
6471 || [istarget *-*-cygwin*] || [istarget *-*-mingw32*]
6472 || [istarget *-*-*djgpp*] || [istarget *-*-go32*]
6473 || [istarget *-wince-pe] || [istarget *-*-mingw32ce*]
6474 || [istarget *-*-osf*]
6475 || [istarget *-*-dicos*]
6476 || [istarget *-*-nto*]
6477 || [istarget *-*-*vms*]
6478 || [istarget *-*-lynx*178]) } {
6479 fail "argv\[0\] should be available on this target"
6485 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
6486 # ${binfile}.dbglnk, which is just like the executable ($binfile) but without
6487 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
6488 # the name of a debuginfo only file. This file will be stored in the same
6491 # Functions for separate debug info testing
6493 # starting with an executable:
6494 # foo --> original executable
6496 # at the end of the process we have:
6497 # foo.stripped --> foo w/o debug info
6498 # foo.debug --> foo's debug info
6499 # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug.
6501 # Fetch the build id from the file.
6502 # Returns "" if there is none.
6504 proc get_build_id { filename } {
6505 if { ([istarget "*-*-mingw*"]
6506 || [istarget *-*-cygwin*]) } {
6507 set objdump_program [gdb_find_objdump]
6508 set result [catch {set data [exec $objdump_program -p $filename | grep signature | cut "-d " -f4]} output]
6509 verbose "result is $result"
6510 verbose "output is $output"
6516 set tmp [standard_output_file "${filename}-tmp"]
6517 set objcopy_program [gdb_find_objcopy]
6518 set result [catch "exec $objcopy_program -j .note.gnu.build-id -O binary $filename $tmp" output]
6519 verbose "result is $result"
6520 verbose "output is $output"
6525 fconfigure $fi -translation binary
6526 # Skip the NOTE header.
6531 if ![string compare $data ""] then {
6534 # Convert it to hex.
6535 binary scan $data H* data
6540 # Return the build-id hex string (usually 160 bits as 40 hex characters)
6541 # converted to the form: .build-id/ab/cdef1234...89.debug
6542 # Return "" if no build-id found.
6543 proc build_id_debug_filename_get { filename } {
6544 set data [get_build_id $filename]
6545 if { $data == "" } {
6548 regsub {^..} $data {\0/} data
6549 return ".build-id/${data}.debug"
6552 # Create stripped files for DEST, replacing it. If ARGS is passed, it is a
6553 # list of optional flags. The only currently supported flag is no-main,
6554 # which removes the symbol entry for main from the separate debug file.
6556 # Function returns zero on success. Function will return non-zero failure code
6557 # on some targets not supporting separate debug info (such as i386-msdos).
6559 proc gdb_gnu_strip_debug { dest args } {
6561 # Use the first separate debug info file location searched by GDB so the
6562 # run cannot be broken by some stale file searched with higher precedence.
6563 set debug_file "${dest}.debug"
6565 set strip_to_file_program [transform strip]
6566 set objcopy_program [gdb_find_objcopy]
6568 set debug_link [file tail $debug_file]
6569 set stripped_file "${dest}.stripped"
6571 # Get rid of the debug info, and store result in stripped_file
6572 # something like gdb/testsuite/gdb.base/blah.stripped.
6573 set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
6574 verbose "result is $result"
6575 verbose "output is $output"
6580 # Workaround PR binutils/10802:
6581 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
6582 set perm [file attributes ${dest} -permissions]
6583 file attributes ${stripped_file} -permissions $perm
6585 # Get rid of everything but the debug info, and store result in debug_file
6586 # This will be in the .debug subdirectory, see above.
6587 set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
6588 verbose "result is $result"
6589 verbose "output is $output"
6594 # If no-main is passed, strip the symbol for main from the separate
6595 # file. This is to simulate the behavior of elfutils's eu-strip, which
6596 # leaves the symtab in the original file only. There's no way to get
6597 # objcopy or strip to remove the symbol table without also removing the
6598 # debugging sections, so this is as close as we can get.
6599 if { [llength $args] == 1 && [lindex $args 0] == "no-main" } {
6600 set result [catch "exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp" output]
6601 verbose "result is $result"
6602 verbose "output is $output"
6606 file delete "${debug_file}"
6607 file rename "${debug_file}-tmp" "${debug_file}"
6610 # Link the two previous output files together, adding the .gnu_debuglink
6611 # section to the stripped_file, containing a pointer to the debug_file,
6612 # save the new file in dest.
6613 # This will be the regular executable filename, in the usual location.
6614 set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
6615 verbose "result is $result"
6616 verbose "output is $output"
6621 # Workaround PR binutils/10802:
6622 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
6623 set perm [file attributes ${stripped_file} -permissions]
6624 file attributes ${dest} -permissions $perm
6629 # Test the output of GDB_COMMAND matches the pattern obtained
6630 # by concatenating all elements of EXPECTED_LINES. This makes
6631 # it possible to split otherwise very long string into pieces.
6632 # If third argument TESTNAME is not empty, it's used as the name of the
6633 # test to be printed on pass/fail.
6634 proc help_test_raw { gdb_command expected_lines {testname {}} } {
6635 set expected_output [join $expected_lines ""]
6636 if {$testname != {}} {
6637 gdb_test "${gdb_command}" "${expected_output}" $testname
6641 gdb_test "${gdb_command}" "${expected_output}"
6644 # A regexp that matches the end of help CLASS|PREFIX_COMMAND
6645 set help_list_trailer {
6646 "Type \"apropos word\" to search for commands related to \"word\"\.[\r\n]+"
6647 "Type \"apropos -v word\" for full documentation of commands related to \"word\"\.[\r\n]+"
6648 "Command name abbreviations are allowed if unambiguous\."
6651 # Test the output of "help COMMAND_CLASS". EXPECTED_INITIAL_LINES
6652 # are regular expressions that should match the beginning of output,
6653 # before the list of commands in that class.
6654 # LIST_OF_COMMANDS are regular expressions that should match the
6655 # list of commands in that class. If empty, the command list will be
6656 # matched automatically. The presence of standard epilogue will be tested
6658 # If last argument TESTNAME is not empty, it's used as the name of the
6659 # test to be printed on pass/fail.
6660 # Notice that the '[' and ']' characters don't need to be escaped for strings
6661 # wrapped in {} braces.
6662 proc test_class_help { command_class expected_initial_lines {list_of_commands {}} {testname {}} } {
6663 global help_list_trailer
6664 if {[llength $list_of_commands]>0} {
6665 set l_list_of_commands {"List of commands:[\r\n]+[\r\n]+"}
6666 set l_list_of_commands [concat $l_list_of_commands $list_of_commands]
6667 set l_list_of_commands [concat $l_list_of_commands {"[\r\n]+[\r\n]+"}]
6669 set l_list_of_commands {"List of commands\:.*[\r\n]+"}
6672 "Type \"help\" followed by command name for full documentation\.[\r\n]+"
6674 set l_entire_body [concat $expected_initial_lines $l_list_of_commands \
6675 $l_stock_body $help_list_trailer]
6677 help_test_raw "help ${command_class}" $l_entire_body $testname
6680 # Like test_class_help but specialised to test "help user-defined".
6681 proc test_user_defined_class_help { {list_of_commands {}} {testname {}} } {
6682 test_class_help "user-defined" {
6683 "User-defined commands\.[\r\n]+"
6684 "The commands in this class are those defined by the user\.[\r\n]+"
6685 "Use the \"define\" command to define a command\.[\r\n]+"
6686 } $list_of_commands $testname
6690 # COMMAND_LIST should have either one element -- command to test, or
6691 # two elements -- abbreviated command to test, and full command the first
6692 # element is abbreviation of.
6693 # The command must be a prefix command. EXPECTED_INITIAL_LINES
6694 # are regular expressions that should match the beginning of output,
6695 # before the list of subcommands. The presence of
6696 # subcommand list and standard epilogue will be tested automatically.
6697 proc test_prefix_command_help { command_list expected_initial_lines args } {
6698 global help_list_trailer
6699 set command [lindex $command_list 0]
6700 if {[llength $command_list]>1} {
6701 set full_command [lindex $command_list 1]
6703 set full_command $command
6705 # Use 'list' and not just {} because we want variables to
6706 # be expanded in this list.
6707 set l_stock_body [list\
6708 "List of $full_command subcommands\:.*\[\r\n\]+"\
6709 "Type \"help $full_command\" followed by $full_command subcommand name for full documentation\.\[\r\n\]+"]
6710 set l_entire_body [concat $expected_initial_lines $l_stock_body $help_list_trailer]
6711 if {[llength $args]>0} {
6712 help_test_raw "help ${command}" $l_entire_body [lindex $args 0]
6714 help_test_raw "help ${command}" $l_entire_body
6718 # Build executable named EXECUTABLE from specifications that allow
6719 # different options to be passed to different sub-compilations.
6720 # TESTNAME is the name of the test; this is passed to 'untested' if
6722 # OPTIONS is passed to the final link, using gdb_compile. If OPTIONS
6723 # contains the option "pthreads", then gdb_compile_pthreads is used.
6724 # ARGS is a flat list of source specifications, of the form:
6725 # { SOURCE1 OPTIONS1 [ SOURCE2 OPTIONS2 ]... }
6726 # Each SOURCE is compiled to an object file using its OPTIONS,
6727 # using gdb_compile.
6728 # Returns 0 on success, -1 on failure.
6729 proc build_executable_from_specs {testname executable options args} {
6733 set binfile [standard_output_file $executable]
6736 if { [lsearch -exact $options "c++"] >= 0 } {
6737 set info_options "c++"
6739 if [get_compiler_info ${info_options}] {
6743 set func gdb_compile
6744 set func_index [lsearch -regexp $options {^(pthreads|shlib|shlib_pthreads|openmp)$}]
6745 if {$func_index != -1} {
6746 set func "${func}_[lindex $options $func_index]"
6749 # gdb_compile_shlib and gdb_compile_shlib_pthreads do not use the 3rd
6750 # parameter. They also requires $sources while gdb_compile and
6751 # gdb_compile_pthreads require $objects. Moreover they ignore any options.
6752 if [string match gdb_compile_shlib* $func] {
6754 foreach {s local_options} $args {
6755 if { [regexp "^/" "$s"] } then {
6756 lappend sources_path "$s"
6758 lappend sources_path "$srcdir/$subdir/$s"
6761 set ret [$func $sources_path "${binfile}" $options]
6762 } elseif {[lsearch -exact $options rust] != -1} {
6764 foreach {s local_options} $args {
6765 if { [regexp "^/" "$s"] } then {
6766 lappend sources_path "$s"
6768 lappend sources_path "$srcdir/$subdir/$s"
6771 set ret [gdb_compile_rust $sources_path "${binfile}" $options]
6775 foreach {s local_options} $args {
6776 if { ! [regexp "^/" "$s"] } then {
6777 set s "$srcdir/$subdir/$s"
6779 if { [$func "${s}" "${binfile}${i}.o" object $local_options] != "" } {
6783 lappend objects "${binfile}${i}.o"
6786 set ret [$func $objects "${binfile}" executable $options]
6796 # Build executable named EXECUTABLE, from SOURCES. If SOURCES are not
6797 # provided, uses $EXECUTABLE.c. The TESTNAME paramer is the name of test
6798 # to pass to untested, if something is wrong. OPTIONS are passed
6799 # to gdb_compile directly.
6800 proc build_executable { testname executable {sources ""} {options {debug}} } {
6801 if {[llength $sources]==0} {
6802 set sources ${executable}.c
6805 set arglist [list $testname $executable $options]
6806 foreach source $sources {
6807 lappend arglist $source $options
6810 return [eval build_executable_from_specs $arglist]
6813 # Starts fresh GDB binary and loads an optional executable into GDB.
6814 # Usage: clean_restart [executable]
6815 # EXECUTABLE is the basename of the binary.
6816 # Return -1 if starting gdb or loading the executable failed.
6818 proc clean_restart { args } {
6824 if { [llength $args] > 1 } {
6825 error "bad number of args: [llength $args]"
6830 # This is a clean restart, so reset error and warning count.
6835 # if { [gdb_start] == -1 } {
6838 # but gdb_start is a ${tool}_start proc, which doesn't have a defined
6839 # return value. So instead, we test for errcnt.
6841 if { $errcnt > 0 } {
6845 gdb_reinitialize_dir $srcdir/$subdir
6847 if { [llength $args] >= 1 } {
6848 set executable [lindex $args 0]
6849 set binfile [standard_output_file ${executable}]
6850 return [gdb_load ${binfile}]
6856 # Prepares for testing by calling build_executable_full, then
6858 # TESTNAME is the name of the test.
6859 # Each element in ARGS is a list of the form
6860 # { EXECUTABLE OPTIONS SOURCE_SPEC... }
6861 # These are passed to build_executable_from_specs, which see.
6862 # The last EXECUTABLE is passed to clean_restart.
6863 # Returns 0 on success, non-zero on failure.
6864 proc prepare_for_testing_full {testname args} {
6865 foreach spec $args {
6866 if {[eval build_executable_from_specs [list $testname] $spec] == -1} {
6869 set executable [lindex $spec 0]
6871 clean_restart $executable
6875 # Prepares for testing, by calling build_executable, and then clean_restart.
6876 # Please refer to build_executable for parameter description.
6877 proc prepare_for_testing { testname executable {sources ""} {options {debug}}} {
6879 if {[build_executable $testname $executable $sources $options] == -1} {
6882 clean_restart $executable
6887 # Retrieve the value of EXP in the inferior, represented in format
6888 # specified in FMT (using "printFMT"). DEFAULT is used as fallback if
6889 # print fails. TEST is the test message to use. It can be omitted,
6890 # in which case a test message is built from EXP.
6892 proc get_valueof { fmt exp default {test ""} } {
6896 set test "get valueof \"${exp}\""
6900 gdb_test_multiple "print${fmt} ${exp}" "$test" {
6901 -re "\\$\[0-9\]* = (\[^\r\n\]*)\[\r\n\]*$gdb_prompt $" {
6902 set val $expect_out(1,string)
6906 fail "$test (timeout)"
6912 # Retrieve the value of local var EXP in the inferior. DEFAULT is used as
6913 # fallback if print fails. TEST is the test message to use. It can be
6914 # omitted, in which case a test message is built from EXP.
6916 proc get_local_valueof { exp default {test ""} } {
6920 set test "get local valueof \"${exp}\""
6924 gdb_test_multiple "info locals ${exp}" "$test" {
6925 -re "$exp = (\[^\r\n\]*)\[\r\n\]*$gdb_prompt $" {
6926 set val $expect_out(1,string)
6930 fail "$test (timeout)"
6936 # Retrieve the value of EXP in the inferior, as a signed decimal value
6937 # (using "print /d"). DEFAULT is used as fallback if print fails.
6938 # TEST is the test message to use. It can be omitted, in which case
6939 # a test message is built from EXP.
6941 proc get_integer_valueof { exp default {test ""} } {
6945 set test "get integer valueof \"${exp}\""
6949 gdb_test_multiple "print /d ${exp}" "$test" {
6950 -re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" {
6951 set val $expect_out(1,string)
6955 fail "$test (timeout)"
6961 # Retrieve the value of EXP in the inferior, as an hexadecimal value
6962 # (using "print /x"). DEFAULT is used as fallback if print fails.
6963 # TEST is the test message to use. It can be omitted, in which case
6964 # a test message is built from EXP.
6966 proc get_hexadecimal_valueof { exp default {test ""} } {
6970 set test "get hexadecimal valueof \"${exp}\""
6974 gdb_test_multiple "print /x ${exp}" $test {
6975 -re "\\$\[0-9\]* = (0x\[0-9a-zA-Z\]+).*$gdb_prompt $" {
6976 set val $expect_out(1,string)
6983 # Retrieve the size of TYPE in the inferior, as a decimal value. DEFAULT
6984 # is used as fallback if print fails. TEST is the test message to use.
6985 # It can be omitted, in which case a test message is 'sizeof (TYPE)'.
6987 proc get_sizeof { type default {test ""} } {
6988 return [get_integer_valueof "sizeof (${type})" $default $test]
6991 proc get_target_charset { } {
6994 gdb_test_multiple "show target-charset" "" {
6995 -re "The target character set is \"auto; currently (\[^\"\]*)\".*$gdb_prompt $" {
6996 return $expect_out(1,string)
6998 -re "The target character set is \"(\[^\"\]*)\".*$gdb_prompt $" {
6999 return $expect_out(1,string)
7003 # Pick a reasonable default.
7004 warning "Unable to read target-charset."
7008 # Get the address of VAR.
7010 proc get_var_address { var } {
7011 global gdb_prompt hex
7013 # Match output like:
7015 # $5 = (int (*)()) 0
7016 # $6 = (int (*)()) 0x24 <function_bar>
7018 gdb_test_multiple "print &${var}" "get address of ${var}" {
7019 -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $"
7021 pass "get address of ${var}"
7022 if { $expect_out(1,string) == "0" } {
7025 return $expect_out(1,string)
7032 # Return the frame number for the currently selected frame
7033 proc get_current_frame_number {{test_name ""}} {
7036 if { $test_name == "" } {
7037 set test_name "get current frame number"
7040 gdb_test_multiple "frame" $test_name {
7041 -re "#(\[0-9\]+) .*$gdb_prompt $" {
7042 set frame_num $expect_out(1,string)
7048 # Get the current value for remotetimeout and return it.
7049 proc get_remotetimeout { } {
7053 gdb_test_multiple "show remotetimeout" "" {
7054 -re "Timeout limit to wait for target to respond is ($decimal).*$gdb_prompt $" {
7055 return $expect_out(1,string)
7059 # Pick the default that gdb uses
7060 warning "Unable to read remotetimeout"
7064 # Set the remotetimeout to the specified timeout. Nothing is returned.
7065 proc set_remotetimeout { timeout } {
7068 gdb_test_multiple "set remotetimeout $timeout" "" {
7069 -re "$gdb_prompt $" {
7070 verbose "Set remotetimeout to $timeout\n"
7075 # Get the target's current endianness and return it.
7076 proc get_endianness { } {
7079 gdb_test_multiple "show endian" "determine endianness" {
7080 -re ".* (little|big) endian.*\r\n$gdb_prompt $" {
7082 return $expect_out(1,string)
7088 # Get the target's default endianness and return it.
7089 gdb_caching_proc target_endianness {
7092 set me "target_endianness"
7094 set src { int main() { return 0; } }
7095 if {![gdb_simple_compile $me $src executable]} {
7103 set res [get_endianness]
7106 remote_file build delete $obj
7111 # ROOT and FULL are file names. Returns the relative path from ROOT
7112 # to FULL. Note that FULL must be in a subdirectory of ROOT.
7113 # For example, given ROOT = /usr/bin and FULL = /usr/bin/ls, this
7116 proc relative_filename {root full} {
7117 set root_split [file split $root]
7118 set full_split [file split $full]
7120 set len [llength $root_split]
7122 if {[eval file join $root_split]
7123 != [eval file join [lrange $full_split 0 [expr {$len - 1}]]]} {
7124 error "$full not a subdir of $root"
7127 return [eval file join [lrange $full_split $len end]]
7130 # If GDB_PARALLEL exists, then set up the parallel-mode directories.
7131 if {[info exists GDB_PARALLEL]} {
7132 if {[is_remote host]} {
7136 [make_gdb_parallel_path outputs] \
7137 [make_gdb_parallel_path temp] \
7138 [make_gdb_parallel_path cache]
7142 proc core_find {binfile {deletefiles {}} {arg ""}} {
7143 global objdir subdir
7145 set destcore "$binfile.core"
7146 file delete $destcore
7148 # Create a core file named "$destcore" rather than just "core", to
7149 # avoid problems with sys admin types that like to regularly prune all
7150 # files named "core" from the system.
7152 # Arbitrarily try setting the core size limit to "unlimited" since
7153 # this does not hurt on systems where the command does not work and
7154 # allows us to generate a core on systems where it does.
7156 # Some systems append "core" to the name of the program; others append
7157 # the name of the program to "core"; still others (like Linux, as of
7158 # May 2003) create cores named "core.PID". In the latter case, we
7159 # could have many core files lying around, and it may be difficult to
7160 # tell which one is ours, so let's run the program in a subdirectory.
7162 set coredir [standard_output_file coredir.[getpid]]
7164 catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile} ${arg}; true) >/dev/null 2>&1\""
7165 # remote_exec host "${binfile}"
7166 foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
7167 if [remote_file build exists $i] {
7168 remote_exec build "mv $i $destcore"
7172 # Check for "core.PID".
7173 if { $found == 0 } {
7174 set names [glob -nocomplain -directory $coredir core.*]
7175 if {[llength $names] == 1} {
7176 set corefile [file join $coredir [lindex $names 0]]
7177 remote_exec build "mv $corefile $destcore"
7181 if { $found == 0 } {
7182 # The braindamaged HPUX shell quits after the ulimit -c above
7183 # without executing ${binfile}. So we try again without the
7184 # ulimit here if we didn't find a core file above.
7185 # Oh, I should mention that any "braindamaged" non-Unix system has
7186 # the same problem. I like the cd bit too, it's really neat'n stuff.
7187 catch "system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\""
7188 foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" {
7189 if [remote_file build exists $i] {
7190 remote_exec build "mv $i $destcore"
7196 # Try to clean up after ourselves.
7197 foreach deletefile $deletefiles {
7198 remote_file build delete [file join $coredir $deletefile]
7200 remote_exec build "rmdir $coredir"
7202 if { $found == 0 } {
7203 warning "can't generate a core file - core tests suppressed - check ulimit -c"
7209 # gdb_target_symbol_prefix compiles a test program and then examines
7210 # the output from objdump to determine the prefix (such as underscore)
7211 # for linker symbol prefixes.
7213 gdb_caching_proc gdb_target_symbol_prefix {
7214 # Compile a simple test program...
7215 set src { int main() { return 0; } }
7216 if {![gdb_simple_compile target_symbol_prefix $src executable]} {
7222 set objdump_program [gdb_find_objdump]
7223 set result [catch "exec $objdump_program --syms $obj" output]
7226 && ![regexp -lineanchor \
7227 { ([^ a-zA-Z0-9]*)main$} $output dummy prefix] } {
7228 verbose "gdb_target_symbol_prefix: Could not find main in objdump output; returning null prefix" 2
7236 # Return 1 if target supports scheduler locking, otherwise return 0.
7238 gdb_caching_proc target_supports_scheduler_locking {
7241 set me "gdb_target_supports_scheduler_locking"
7243 set src { int main() { return 0; } }
7244 if {![gdb_simple_compile $me $src executable]} {
7253 set supports_schedule_locking -1
7254 set current_schedule_locking_mode ""
7256 set test "reading current scheduler-locking mode"
7257 gdb_test_multiple "show scheduler-locking" $test {
7258 -re "Mode for locking scheduler during execution is \"(\[\^\"\]*)\".*$gdb_prompt" {
7259 set current_schedule_locking_mode $expect_out(1,string)
7261 -re "$gdb_prompt $" {
7262 set supports_schedule_locking 0
7265 set supports_schedule_locking 0
7269 if { $supports_schedule_locking == -1 } {
7270 set test "checking for scheduler-locking support"
7271 gdb_test_multiple "set scheduler-locking $current_schedule_locking_mode" $test {
7272 -re "Target '\[^'\]+' cannot support this command\..*$gdb_prompt $" {
7273 set supports_schedule_locking 0
7275 -re "$gdb_prompt $" {
7276 set supports_schedule_locking 1
7279 set supports_schedule_locking 0
7284 if { $supports_schedule_locking == -1 } {
7285 set supports_schedule_locking 0
7289 remote_file build delete $obj
7290 verbose "$me: returning $supports_schedule_locking" 2
7291 return $supports_schedule_locking
7294 # Return 1 if compiler supports use of nested functions. Otherwise,
7297 gdb_caching_proc support_nested_function_tests {
7298 # Compile a test program containing a nested function
7299 return [gdb_can_simple_compile nested_func {
7309 # gdb_target_symbol returns the provided symbol with the correct prefix
7310 # prepended. (See gdb_target_symbol_prefix, above.)
7312 proc gdb_target_symbol { symbol } {
7313 set prefix [gdb_target_symbol_prefix]
7314 return "${prefix}${symbol}"
7317 # gdb_target_symbol_prefix_flags_asm returns a string that can be
7318 # added to gdb_compile options to define the C-preprocessor macro
7319 # SYMBOL_PREFIX with a value that can be prepended to symbols
7320 # for targets which require a prefix, such as underscore.
7322 # This version (_asm) defines the prefix without double quotes
7323 # surrounding the prefix. It is used to define the macro
7324 # SYMBOL_PREFIX for assembly language files. Another version, below,
7325 # is used for symbols in inline assembler in C/C++ files.
7327 # The lack of quotes in this version (_asm) makes it possible to
7328 # define supporting macros in the .S file. (The version which
7329 # uses quotes for the prefix won't work for such files since it's
7330 # impossible to define a quote-stripping macro in C.)
7332 # It's possible to use this version (_asm) for C/C++ source files too,
7333 # but a string is usually required in such files; providing a version
7334 # (no _asm) which encloses the prefix with double quotes makes it
7335 # somewhat easier to define the supporting macros in the test case.
7337 proc gdb_target_symbol_prefix_flags_asm {} {
7338 set prefix [gdb_target_symbol_prefix]
7339 if {$prefix ne ""} {
7340 return "additional_flags=-DSYMBOL_PREFIX=$prefix"
7346 # gdb_target_symbol_prefix_flags returns the same string as
7347 # gdb_target_symbol_prefix_flags_asm, above, but with the prefix
7348 # enclosed in double quotes if there is a prefix.
7350 # See the comment for gdb_target_symbol_prefix_flags_asm for an
7351 # extended discussion.
7353 proc gdb_target_symbol_prefix_flags {} {
7354 set prefix [gdb_target_symbol_prefix]
7355 if {$prefix ne ""} {
7356 return "additional_flags=-DSYMBOL_PREFIX=\"$prefix\""
7362 # A wrapper for 'remote_exec host' that passes or fails a test.
7363 # Returns 0 if all went well, nonzero on failure.
7364 # TEST is the name of the test, other arguments are as for remote_exec.
7366 proc run_on_host { test program args } {
7367 verbose -log "run_on_host: $program $args"
7368 # remote_exec doesn't work properly if the output is set but the
7369 # input is the empty string -- so replace an empty input with
7371 if {[llength $args] > 1 && [lindex $args 1] == ""} {
7372 set args [lreplace $args 1 1 "/dev/null"]
7374 set result [eval remote_exec host [list $program] $args]
7375 verbose "result is $result"
7376 set status [lindex $result 0]
7377 set output [lindex $result 1]
7382 verbose -log "run_on_host failed: $output"
7383 if { $output == "spawn failed" } {
7392 # Return non-zero if "board_info debug_flags" mentions Fission.
7393 # http://gcc.gnu.org/wiki/DebugFission
7394 # Fission doesn't support everything yet.
7395 # This supports working around bug 15954.
7397 proc using_fission { } {
7398 set debug_flags [board_info [target_info name] debug_flags]
7399 return [regexp -- "-gsplit-dwarf" $debug_flags]
7402 # Search LISTNAME in uplevel LEVEL caller and set variables according to the
7403 # list of valid options with prefix PREFIX described by ARGSET.
7405 # The first member of each one- or two-element list in ARGSET defines the
7406 # name of a variable that will be added to the caller's scope.
7408 # If only one element is given to describe an option, it the value is
7409 # 0 if the option is not present in (the caller's) ARGS or 1 if
7412 # If two elements are given, the second element is the default value of
7413 # the variable. This is then overwritten if the option exists in ARGS.
7414 # If EVAL, then subst is called on the value, which allows variables
7417 # Any parse_args elements in (the caller's) ARGS will be removed, leaving
7418 # any optional components.
7421 # proc myproc {foo args} {
7422 # parse_list args 1 {{bar} {baz "abc"} {qux}} "-" false
7425 # myproc ABC -bar -baz DEF peanut butter
7426 # will define the following variables in myproc:
7427 # foo (=ABC), bar (=1), baz (=DEF), and qux (=0)
7428 # args will be the list {peanut butter}
7430 proc parse_list { level listname argset prefix eval } {
7431 upvar $level $listname args
7433 foreach argument $argset {
7434 if {[llength $argument] == 1} {
7435 # Normalize argument, strip leading/trailing whitespace.
7436 # Allows us to treat {foo} and { foo } the same.
7437 set argument [string trim $argument]
7439 # No default specified, so we assume that we should set
7440 # the value to 1 if the arg is present and 0 if it's not.
7441 # It is assumed that no value is given with the argument.
7442 set pattern "$prefix$argument"
7443 set result [lsearch -exact $args $pattern]
7445 if {$result != -1} then {
7447 set args [lreplace $args $result $result]
7451 uplevel $level [list set $argument $value]
7452 } elseif {[llength $argument] == 2} {
7453 # There are two items in the argument. The second is a
7454 # default value to use if the item is not present.
7455 # Otherwise, the variable is set to whatever is provided
7456 # after the item in the args.
7457 set arg [lindex $argument 0]
7458 set pattern "$prefix[lindex $arg 0]"
7459 set result [lsearch -exact $args $pattern]
7461 if {$result != -1} then {
7462 set value [lindex $args [expr $result+1]]
7464 set value [uplevel [expr $level + 1] [list subst $value]]
7466 set args [lreplace $args $result [expr $result+1]]
7468 set value [lindex $argument 1]
7470 set value [uplevel $level [list subst $value]]
7473 uplevel $level [list set $arg $value]
7475 error "Badly formatted argument \"$argument\" in argument set"
7480 # Search the caller's args variable and set variables according to the list of
7481 # valid options described by ARGSET.
7483 proc parse_args { argset } {
7484 parse_list 2 args $argset "-" false
7486 # The remaining args should be checked to see that they match the
7487 # number of items expected to be passed into the procedure...
7490 # Process the caller's options variable and set variables according
7491 # to the list of valid options described by OPTIONSET.
7493 proc parse_options { optionset } {
7494 parse_list 2 options $optionset "" true
7496 # Require no remaining options.
7497 upvar 1 options options
7498 if { [llength $options] != 0 } {
7499 error "Options left unparsed: $options"
7503 # Capture the output of COMMAND in a string ignoring PREFIX (a regexp);
7504 # return that string.
7506 proc capture_command_output { command prefix } {
7510 set output_string ""
7511 gdb_test_multiple "$command" "capture_command_output for $command" {
7512 -re "[string_to_regexp ${command}]\[\r\n\]+${prefix}(.*)\[\r\n\]+$gdb_prompt $" {
7513 set output_string $expect_out(1,string)
7516 return $output_string
7519 # A convenience function that joins all the arguments together, with a
7520 # regexp that matches exactly one end of line in between each argument.
7521 # This function is ideal to write the expected output of a GDB command
7522 # that generates more than a couple of lines, as this allows us to write
7523 # each line as a separate string, which is easier to read by a human
7526 proc multi_line { args } {
7527 if { [llength $args] == 1 } {
7528 set hint "forgot {*} before list argument?"
7529 error "multi_line called with one argument ($hint)"
7531 return [join $args "\r\n"]
7534 # Similar to the above, but while multi_line is meant to be used to
7535 # match GDB output, this one is meant to be used to build strings to
7536 # send as GDB input.
7538 proc multi_line_input { args } {
7539 return [join $args "\n"]
7542 # Return the version of the DejaGnu framework.
7544 # The return value is a list containing the major, minor and patch version
7545 # numbers. If the version does not contain a minor or patch number, they will
7546 # be set to 0. For example:
7552 proc dejagnu_version { } {
7553 # The frame_version variable is defined by DejaGnu, in runtest.exp.
7554 global frame_version
7556 verbose -log "DejaGnu version: $frame_version"
7557 verbose -log "Expect version: [exp_version]"
7558 verbose -log "Tcl version: [info tclversion]"
7560 set dg_ver [split $frame_version .]
7562 while { [llength $dg_ver] < 3 } {
7569 # Define user-defined command COMMAND using the COMMAND_LIST as the
7570 # command's definition. The terminating "end" is added automatically.
7572 proc gdb_define_cmd {command command_list} {
7575 set input [multi_line_input {*}$command_list "end"]
7576 set test "define $command"
7578 gdb_test_multiple "define $command" $test {
7580 gdb_test_multiple $input $test {
7581 -re "\r\n$gdb_prompt " {
7588 # Override the 'cd' builtin with a version that ensures that the
7589 # log file keeps pointing at the same file. We need this because
7590 # unfortunately the path to the log file is recorded using an
7591 # relative path name, and, we sometimes need to close/reopen the log
7592 # after changing the current directory. See get_compiler_info.
7594 rename cd builtin_cd
7598 # Get the existing log file flags.
7599 set log_file_info [log_file -info]
7601 # Split the flags into args and file name.
7602 set log_file_flags ""
7603 set log_file_file ""
7604 foreach arg [ split "$log_file_info" " "] {
7605 if [string match "-*" $arg] {
7606 lappend log_file_flags $arg
7608 lappend log_file_file $arg
7612 # If there was an existing file, ensure it is an absolute path, and then
7614 if { $log_file_file != "" } {
7615 set log_file_file [file normalize $log_file_file]
7617 log_file $log_file_flags "$log_file_file"
7620 # Call the builtin version of cd.
7624 # Return a list of all languages supported by GDB, suitable for use in
7625 # 'set language NAME'. This doesn't include either the 'local' or
7627 proc gdb_supported_languages {} {
7628 return [list c objective-c c++ d go fortran modula-2 asm pascal \
7629 opencl rust minimal ada]
7632 # Check if debugging is enabled for gdb.
7634 proc gdb_debug_enabled { } {
7637 # If not already read, get the debug setting from environment or board setting.
7638 if {![info exists gdbdebug]} {
7640 if [info exists env(GDB_DEBUG)] {
7641 set gdbdebug $env(GDB_DEBUG)
7642 } elseif [target_info exists gdb,debug] {
7643 set gdbdebug [target_info gdb,debug]
7649 # Ensure it not empty.
7650 return [expr { $gdbdebug != "" }]
7653 # Turn on debugging if enabled, or reset if already on.
7655 proc gdb_debug_init { } {
7659 if ![gdb_debug_enabled] {
7663 # First ensure logging is off.
7664 send_gdb "set logging enabled off\n"
7666 set debugfile [standard_output_file gdb.debug]
7667 send_gdb "set logging file $debugfile\n"
7669 send_gdb "set logging debugredirect\n"
7672 foreach entry [split $gdbdebug ,] {
7673 send_gdb "set debug $entry 1\n"
7676 # Now that everything is set, enable logging.
7677 send_gdb "set logging enabled on\n"
7679 -re "Copying output to $debugfile.*Redirecting debug output to $debugfile.*$gdb_prompt $" {}
7680 timeout { warning "Couldn't set logging file" }
7684 # Check if debugging is enabled for gdbserver.
7686 proc gdbserver_debug_enabled { } {
7687 # Always disabled for GDB only setups.
7691 # Open the file for logging gdb input
7693 proc gdb_stdin_log_init { } {
7694 gdb_persistent_global in_file
7696 if {[info exists in_file]} {
7697 # Close existing file.
7698 catch "close $in_file"
7701 set logfile [standard_output_file_with_gdb_instance gdb.in]
7702 set in_file [open $logfile w]
7705 # Write to the file for logging gdb input.
7706 # TYPE can be one of the following:
7707 # "standard" : Default. Standard message written to the log
7708 # "answer" : Answer to a question (eg "Y"). Not written the log.
7709 # "optional" : Optional message. Not written to the log.
7711 proc gdb_stdin_log_write { message {type standard} } {
7714 if {![info exists in_file]} {
7718 # Check message types.
7719 switch -regexp -- $type {
7728 # Write to the log and make sure the output is there, even in case
7730 puts -nonewline $in_file "$message"
7734 # Write the command line used to invocate gdb to the cmd file.
7736 proc gdb_write_cmd_file { cmdline } {
7737 set logfile [standard_output_file_with_gdb_instance gdb.cmd]
7738 set cmd_file [open $logfile w]
7739 puts $cmd_file $cmdline
7740 catch "close $cmd_file"
7743 # Compare contents of FILE to string STR. Pass with MSG if equal, otherwise
7746 proc cmp_file_string { file str msg } {
7747 if { ![file exists $file]} {
7752 set caught_error [catch {
7753 set fp [open "$file" r]
7754 set file_contents [read $fp]
7757 if { $caught_error } then {
7758 error "$error_message"
7763 if { $file_contents == $str } {
7770 # Does the compiler support CTF debug output using '-gctf' compiler
7771 # flag? If not then we should skip these tests. We should also
7772 # skip them if libctf was explicitly disabled.
7774 gdb_caching_proc skip_ctf_tests {
7775 global enable_libctf
7777 if {$enable_libctf eq "no"} {
7781 set can_ctf [gdb_can_simple_compile ctfdebug {
7785 } executable "additional_flags=-gctf"]
7787 return [expr {!$can_ctf}]
7790 # Return 1 if compiler supports -gstatement-frontiers. Otherwise,
7793 gdb_caching_proc supports_statement_frontiers {
7794 return [gdb_can_simple_compile supports_statement_frontiers {
7798 } executable "additional_flags=-gstatement-frontiers"]
7801 # Return 1 if compiler supports -mmpx -fcheck-pointer-bounds. Otherwise,
7804 gdb_caching_proc supports_mpx_check_pointer_bounds {
7805 set flags "additional_flags=-mmpx additional_flags=-fcheck-pointer-bounds"
7806 return [gdb_can_simple_compile supports_mpx_check_pointer_bounds {
7810 } executable $flags]
7813 # Return 1 if compiler supports -fcf-protection=. Otherwise,
7816 gdb_caching_proc supports_fcf_protection {
7817 return [gdb_can_simple_compile supports_fcf_protection {
7821 } executable "additional_flags=-fcf-protection=full"]
7824 # Return 1 if symbols were read in using -readnow. Otherwise, return 0.
7826 proc readnow { args } {
7827 if { [llength $args] == 1 } {
7828 set re [lindex $args 0]
7834 # Given the listing from the following command can be very verbose, match
7835 # the patterns line-by-line. This prevents timeouts from waiting for
7836 # too much data to come at once.
7837 set cmd "maint print objfiles $re"
7838 gdb_test_multiple $cmd "" -lbl {
7839 -re "\r\n.gdb_index: faked for \"readnow\"" {
7840 # Record the we've seen the above pattern.
7845 # We don't care about any other input.
7852 # Return index name if symbols were read in using an index.
7853 # Otherwise, return "".
7855 proc have_index { objfile } {
7858 set cmd "maint print objfiles $objfile"
7859 gdb_test_multiple $cmd "" -lbl {
7860 -re "\r\n.gdb_index: faked for \"readnow\"" {
7864 -re "\r\n.gdb_index:" {
7868 -re "\r\n.debug_names:" {
7869 set res "debug_names"
7873 # We don't care about any other input.
7880 # Return 1 if partial symbols are available. Otherwise, return 0.
7882 proc psymtabs_p { } {
7885 set cmd "maint info psymtab"
7886 gdb_test_multiple $cmd "" {
7887 -re "$cmd\r\n$gdb_prompt $" {
7898 # Verify that partial symtab expansion for $filename has state $readin.
7900 proc verify_psymtab_expanded { filename readin } {
7903 set cmd "maint info psymtab"
7904 set test "$cmd: $filename: $readin"
7905 set re [multi_line \
7906 " \{ psymtab \[^\r\n\]*$filename\[^\r\n\]*" \
7910 gdb_test_multiple $cmd $test {
7911 -re "$cmd\r\n$gdb_prompt $" {
7912 unsupported $gdb_test_name
7920 # Add a .gdb_index section to PROGRAM.
7921 # PROGRAM is assumed to be the output of standard_output_file.
7922 # Returns the 0 if there is a failure, otherwise 1.
7924 # STYLE controls which style of index to add, if needed. The empty
7925 # string (the default) means .gdb_index; "-dwarf-5" means .debug_names.
7927 proc add_gdb_index { program {style ""} } {
7928 global srcdir GDB env BUILD_DATA_DIRECTORY
7929 set contrib_dir "$srcdir/../contrib"
7930 set env(GDB) "$GDB --data-directory=$BUILD_DATA_DIRECTORY"
7931 set result [catch "exec $contrib_dir/gdb-add-index.sh $style $program" output]
7932 if { $result != 0 } {
7933 verbose -log "result is $result"
7934 verbose -log "output is $output"
7941 # Add a .gdb_index section to PROGRAM, unless it alread has an index
7942 # (.gdb_index/.debug_names). Gdb doesn't support building an index from a
7943 # program already using one. Return 1 if a .gdb_index was added, return 0
7944 # if it already contained an index, and -1 if an error occurred.
7946 # STYLE controls which style of index to add, if needed. The empty
7947 # string (the default) means .gdb_index; "-dwarf-5" means .debug_names.
7949 proc ensure_gdb_index { binfile {style ""} } {
7952 set testfile [file tail $binfile]
7953 set test "check if index present"
7956 gdb_test_multiple "mt print objfiles ${testfile}" $test -lbl {
7957 -re "\r\n\\.gdb_index: version ${decimal}(?=\r\n)" {
7959 gdb_test_lines "" $gdb_test_name ".*"
7961 -re "\r\n\\.debug_names: exists(?=\r\n)" {
7963 gdb_test_lines "" $gdb_test_name ".*"
7965 -re "\r\nPsymtabs:(?=\r\n)" {
7966 gdb_test_lines "" $gdb_test_name ".*"
7968 -re ".gdb_index: faked for \"readnow\"" {
7970 gdb_test_lines "" $gdb_test_name ".*"
7981 if { $has_readnow } {
7985 if { [add_gdb_index $binfile $style] == "1" } {
7992 # Return 1 if executable contains .debug_types section. Otherwise, return 0.
7994 proc debug_types { } {
7997 set cmd "maint info sections"
7998 gdb_test_multiple $cmd "" {
7999 -re -wrap "at $hex: .debug_types.*" {
8010 # Return the addresses in the line table for FILE for which is_stmt is true.
8012 proc is_stmt_addresses { file } {
8018 gdb_test_multiple "maint info line-table $file" "" {
8019 -re "\r\n$decimal\[ \t\]+$decimal\[ \t\]+($hex)\[ \t\]+Y\[^\r\n\]*" {
8020 lappend is_stmt $expect_out(1,string)
8030 # Return 1 if hex number VAL is an element of HEXLIST.
8032 proc hex_in_list { val hexlist } {
8033 # Normalize val by removing 0x prefix, and leading zeros.
8034 set val [regsub ^0x $val ""]
8035 set val [regsub ^0+ $val "0"]
8038 set index [lsearch -regexp $hexlist $re]
8039 return [expr $index != -1]
8042 # Override proc NAME to proc OVERRIDE for the duration of the execution of
8045 proc with_override { name override body } {
8046 # Implementation note: It's possible to implement the override using
8047 # rename, like this:
8048 # rename $name save_$name
8049 # rename $override $name
8050 # set code [catch {uplevel 1 $body} result]
8051 # rename $name $override
8052 # rename save_$name $name
8053 # but there are two issues here:
8054 # - the save_$name might clash with an existing proc
8055 # - the override is no longer available under its original name during
8057 # So, we use this more elaborate but cleaner mechanism.
8059 # Save the old proc, if it exists.
8060 if { [info procs $name] != "" } {
8061 set old_args [info args $name]
8062 set old_body [info body $name]
8068 # Install the override.
8069 set new_args [info args $override]
8070 set new_body [info body $override]
8071 eval proc $name {$new_args} {$new_body}
8074 set code [catch {uplevel 1 $body} result]
8076 # Restore old proc if it existed on entry, else delete it.
8078 eval proc $name {$old_args} {$old_body}
8083 # Return as appropriate.
8085 global errorInfo errorCode
8086 return -code error -errorinfo $errorInfo -errorcode $errorCode $result
8087 } elseif { $code > 1 } {
8088 return -code $code $result
8094 # Setup tuiterm.exp environment. To be used in test-cases instead of
8095 # "load_lib tuiterm.exp". Calls initialization function and schedules
8096 # finalization function.
8097 proc tuiterm_env { } {
8098 load_lib tuiterm.exp
8101 # Dejagnu has a version of note, but usage is not allowed outside of dejagnu.
8102 # Define a local version.
8103 proc gdb_note { message } {
8104 verbose -- "NOTE: $message" 0
8107 # Return 1 if compiler supports -fuse-ld=gold, otherwise return 0.
8108 gdb_caching_proc have_fuse_ld_gold {
8109 set me "have_fuse_ld_gold"
8110 set flags "additional_flags=-fuse-ld=gold"
8111 set src { int main() { return 0; } }
8112 return [gdb_simple_compile $me $src executable $flags]
8115 # Return 1 if compiler supports scalar_storage_order attribute, otherwise
8117 gdb_caching_proc supports_scalar_storage_order_attribute {
8118 set me "supports_scalar_storage_order_attribute"
8123 } __attribute__((scalar_storage_order("little-endian")));
8126 } __attribute__((scalar_storage_order("big-endian")));
8130 sle.v = sbe.v = 0x11223344;
8131 int same = memcmp (&sle, &sbe, sizeof (int)) == 0;
8136 if { ![gdb_simple_compile $me $src executable ""] } {
8140 set result [remote_exec target $obj]
8141 set status [lindex $result 0]
8142 set output [lindex $result 1]
8143 if { $output != "" } {
8150 # Return 1 if compiler supports __GNUC__, otherwise return 0.
8151 gdb_caching_proc supports_gnuc {
8152 set me "supports_gnuc"
8158 return [gdb_simple_compile $me $src object ""]
8161 # Return 1 if target supports mpx, otherwise return 0.
8162 gdb_caching_proc have_mpx {
8166 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
8167 verbose "$me: target does not support mpx, returning 0" 2
8171 # Compile a test program.
8173 #include "nat/x86-cpuid.h"
8176 unsigned int eax, ebx, ecx, edx;
8178 if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
8181 if ((ecx & bit_OSXSAVE) == bit_OSXSAVE)
8183 if (__get_cpuid_max (0, (void *)0) < 7)
8186 __cpuid_count (7, 0, eax, ebx, ecx, edx);
8188 if ((ebx & bit_MPX) == bit_MPX)
8195 set compile_flags "incdir=${srcdir}/.."
8196 if {![gdb_simple_compile $me $src executable $compile_flags]} {
8200 set result [remote_exec target $obj]
8201 set status [lindex $result 0]
8202 set output [lindex $result 1]
8203 if { $output != "" } {
8207 remote_file build delete $obj
8209 verbose "$me: returning $status" 2
8213 # Return 1 if target supports avx, otherwise return 0.
8214 gdb_caching_proc have_avx {
8218 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
8219 verbose "$me: target does not support avx, returning 0" 2
8223 # Compile a test program.
8225 #include "nat/x86-cpuid.h"
8228 unsigned int eax, ebx, ecx, edx;
8230 if (!x86_cpuid (1, &eax, &ebx, &ecx, &edx))
8233 if ((ecx & (bit_AVX | bit_OSXSAVE)) == (bit_AVX | bit_OSXSAVE))
8239 set compile_flags "incdir=${srcdir}/.."
8240 if {![gdb_simple_compile $me $src executable $compile_flags]} {
8244 set result [remote_exec target $obj]
8245 set status [lindex $result 0]
8246 set output [lindex $result 1]
8247 if { $output != "" } {
8251 remote_file build delete $obj
8253 verbose "$me: returning $status" 2
8258 # - require EXPR VAL
8259 # - require EXPR OP VAL
8260 # In the first case, OP is ==.
8262 # Require EXPR OP VAL, where EXPR is evaluated in caller context. If not,
8263 # return in the caller's context.
8265 proc require { fn arg1 {arg2 ""} } {
8266 if { $arg2 == "" } {
8273 set res [uplevel 1 $fn]
8274 if { [expr $res $op $val] } {
8278 switch "$fn $op $val" {
8279 "gdb_skip_xml_test == 0" { set msg "missing xml support" }
8280 "ensure_gdb_index $binfile != -1" -
8281 "ensure_gdb_index $binfile -dwarf-5 != -1" {
8282 set msg "Couldn't ensure index in binfile"
8284 "use_gdb_stub == 0" {
8285 set msg "Remote stub used"
8287 default { set msg "$fn != $val" }
8291 return -code return 0
8294 # Always load compatibility stuff.