1 # Copyright
1992-2023 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 #
Execute BODY
, if COND wrapped in proc WRAP.
29 # Instead of writing the verbose and repetitive
:
36 # cond_wrap $cond wrap $body
38 proc cond_wrap
{ cond wrap body
} {
48 # Add VAR_ID
=VAL to ENV_VAR
, unless ENV_VAR already contains a VAR_ID setting.
50 proc set_sanitizer_default
{ env_var var_id val
} {
53 if { ![info exists env
($env_var
) ]
54 || $env
($env_var
) == "" } {
55 #
Set var_id
(env_var non
-existing
/ empty case
).
56 append env
($env_var
) $var_id
=$val
60 if { [regexp $var_id
= $env
($env_var
)] } {
61 # Don
't set var_id. It's already
set by the user
, leave as is.
62 # Note that we could probably
get the same result by unconditionally
63 # prepending it
, but this way is less likely to cause confusion.
67 #
Set var_id
(env_var not empty case
).
68 append env
($env_var
) : $var_id
=$val
71 set_sanitizer_default TSAN_OPTIONS suppressions \
72 $srcdir
/..
/tsan
-suppressions.txt
74 #
If GDB is built with ASAN
(and because there are leaks
), it will output a
75 # leak
report when exiting as well as exit with a non
-zero
(failure
) status.
76 # This can affect tests that are sensitive to what GDB prints
on stderr or its
77 # exit
status. Add `detect_leaks
=0` to the ASAN_OPTIONS environment
variable
78 #
(which will affect
any spawned sub
-process
) to avoid this.
79 set_sanitizer_default ASAN_OPTIONS detect_leaks
0
81 # List of procs to run in gdb_finish.
82 set gdb_finish_hooks
[list
]
84 #
Variable in which we keep track of globals that are allowed to be live
86 array
set gdb_persistent_globals
{}
88 # Mark
variable names in
ARG as a persistent global
, and declare them as
89 # global in the calling
context. Can be used to rewrite
"global var_a var_b"
90 # into
"gdb_persistent_global var_a var_b".
91 proc gdb_persistent_global
{ args } {
92 global gdb_persistent_globals
93 foreach varname $
args {
94 uplevel
1 global $varname
95 set gdb_persistent_globals
($varname
) 1
99 # Mark
variable names in
ARG as a persistent global.
100 proc gdb_persistent_global_no_decl
{ args } {
101 global gdb_persistent_globals
102 foreach varname $
args {
103 set gdb_persistent_globals
($varname
) 1
107 # Override proc load_lib.
108 rename load_lib saved_load_lib
109 # Run the runtest version of load_lib
, and mark all variables that were
110 # created by this
call as persistent.
111 proc load_lib
{ file
} {
112 array
set known_global
{}
113 foreach varname
[info globals
] {
114 set known_globals
($varname
) 1
117 set code
[catch
"saved_load_lib $file" result]
119 foreach varname
[info globals
] {
120 if { ![info exists known_globals
($varname
)] } {
121 gdb_persistent_global_no_decl $varname
126 global errorInfo errorCode
127 return -code error
-errorinfo $errorInfo
-errorcode $errorCode $result
128 } elseif
{$code
> 1} {
129 return -code $code $result
135 load_lib libgloss.exp
137 load_lib gdb
-utils.exp
139 load_lib check
-test
-names.exp
141 # The path to the GDB binary to test.
144 # The data directory to use
for testing.
If this is the empty string
,
145 #
then we let GDB use its own configured data directory.
146 global GDB_DATA_DIRECTORY
148 # The spawn ID used
for I
/O interaction with the inferior.
For native
149 # targets
, or remote targets that can
do I
/O through GDB
150 #
(semi
-hosting
) this will be the same as the host
/GDB
's spawn ID.
151 # Otherwise, the board may set this to some other spawn ID. E.g.,
152 # when debugging with GDBserver, this is set to GDBserver's spawn ID
,
153 # so input
/output is done
on gdbserver
's tty.
154 global inferior_spawn_id
156 if [info exists TOOL_EXECUTABLE] {
157 set GDB $TOOL_EXECUTABLE
159 if ![info exists GDB] {
160 if ![is_remote host] {
161 set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]]
163 set GDB [transform gdb]
166 # If the user specifies GDB on the command line, and doesn't
167 # specify GDB_DATA_DIRECTORY
, then assume we
're testing an
168 # installed GDB, and let it use its own configured data directory.
169 if ![info exists GDB_DATA_DIRECTORY] {
170 set GDB_DATA_DIRECTORY ""
173 verbose "using GDB = $GDB" 2
175 # The data directory the testing GDB will use. By default, assume
176 # we're testing a non
-installed GDB in the build directory. Users may
177 # also explictly override the
-data
-directory from the command line.
178 if ![info exists GDB_DATA_DIRECTORY
] {
179 set GDB_DATA_DIRECTORY
[file normalize
"[pwd]/../data-directory"]
181 verbose
"using GDB_DATA_DIRECTORY = $GDB_DATA_DIRECTORY" 2
183 # GDBFLAGS is available
for the user to
set on the command line.
184 # E.g. make check RUNTESTFLAGS
=GDBFLAGS
=mumble
185 # Testcases may use it to add additional flags
, but they must
:
186 #
- append new flags
, not overwrite
187 #
- restore the original value when done
189 if ![info exists GDBFLAGS
] {
192 verbose
"using GDBFLAGS = $GDBFLAGS" 2
194 # Append the
-data
-directory option to pass to GDB to CMDLINE and
195 #
return the resulting string.
If GDB_DATA_DIRECTORY is empty
,
196 # nothing is appended.
197 proc append_gdb_data_directory_option
{cmdline
} {
198 global GDB_DATA_DIRECTORY
200 if { $GDB_DATA_DIRECTORY
!= "" } {
201 return "$cmdline -data-directory $GDB_DATA_DIRECTORY"
207 # INTERNAL_GDBFLAGS contains flags that the testsuite requires.
208 # `
-nw
' disables any of the windowed interfaces.
209 # `-nx' disables ~
/.gdbinit
, so that it doesn
't interfere with the tests.
210 # `-iex "set {height,width} 0"' disables pagination.
211 # `
-data
-directory
' points to the data directory, usually in the build
213 global INTERNAL_GDBFLAGS
214 if ![info exists INTERNAL_GDBFLAGS] {
215 set INTERNAL_GDBFLAGS \
219 {-iex "set height 0"} \
220 {-iex "set width 0"}]]
222 # If DEBUGINFOD_URLS is set, gdb will try to download sources and
223 # debug info for f.i. system libraries. Prevent this.
224 if { [is_remote host] } {
225 # Setting environment variables on build has no effect on remote host,
226 # so handle this using "set debuginfod enabled off" instead.
227 set INTERNAL_GDBFLAGS \
228 "$INTERNAL_GDBFLAGS -iex \"set debuginfod enabled off\""
230 # See default_gdb_init.
233 set INTERNAL_GDBFLAGS [append_gdb_data_directory_option $INTERNAL_GDBFLAGS]
236 # The variable gdb_prompt is a regexp which matches the gdb prompt.
237 # Set it if it is not already set. This is also set by default_gdb_init
238 # but it's not clear what removing one of them will
break.
239 # See with_gdb_prompt
for more details
on prompt handling.
241 if {![info exists gdb_prompt
]} {
242 set gdb_prompt
"\\(gdb\\)"
245 # A regexp that matches the pagination prompt.
246 set pagination_prompt \
247 "--Type <RET> for more, q to quit, c to continue without paging--"
249 # The
variable fullname_syntax_POSIX is a regexp which matches a POSIX
250 # absolute path ie.
/foo
/
251 set fullname_syntax_POSIX
{/[^
\n]*/}
252 # The
variable fullname_syntax_UNC is a regexp which matches a Windows
253 # UNC path ie.
\\D
\foo\
254 set fullname_syntax_UNC
{\\\\[^
\\]+\\[^
\n]+\\}
255 # The
variable fullname_syntax_DOS_CASE is a regexp which matches a
256 # particular DOS case that GDB most likely will output
257 # ie.
\foo\
, but don
't match \\.*\
258 set fullname_syntax_DOS_CASE {\\[^\\][^\n]*\\}
259 # The variable fullname_syntax_DOS is a regexp which matches a DOS path
260 # ie. a:\foo\ && a:foo\
261 set fullname_syntax_DOS {[a-zA-Z]:[^\n]*\\}
262 # The variable fullname_syntax is a regexp which matches what GDB considers
263 # an absolute path. It is currently debatable if the Windows style paths
264 # d:foo and \abc should be considered valid as an absolute path.
265 # Also, the purpse of this regexp is not to recognize a well formed
266 # absolute path, but to say with certainty that a path is absolute.
267 set fullname_syntax "($fullname_syntax_POSIX|$fullname_syntax_UNC|$fullname_syntax_DOS_CASE|$fullname_syntax_DOS)"
269 # Needed for some tests under Cygwin.
273 if ![info exists env(EXEEXT)] {
276 set EXEEXT $env(EXEEXT)
281 set inferior_exited_re "(?:\\\[Inferior \[0-9\]+ \\(\[^\n\r\]*\\) exited)"
283 # A regular expression that matches a value history number.
285 set valnum_re "\\\$$decimal"
287 # A regular expression that matches a breakpoint hit with a breakpoint
288 # having several code locations.
289 set bkptno_num_re "$decimal\\.$decimal"
291 # A regular expression that matches a breakpoint hit
292 # with one or several code locations.
293 set bkptno_numopt_re "($decimal\\.$decimal|$decimal)"
295 ### Only procedures should come after this point.
298 # gdb_version -- extract and print the version number of GDB
300 proc default_gdb_version {} {
302 global INTERNAL_GDBFLAGS GDBFLAGS
306 if {[info exists inotify_pid]} {
307 eval exec kill $inotify_pid
310 set output [remote_exec host "$GDB $INTERNAL_GDBFLAGS --version"]
311 set tmp [lindex $output 1]
313 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
314 if ![is_remote host] {
315 clone_output "[which $GDB] version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
317 clone_output "$GDB on remote host version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
321 proc gdb_version { } {
322 return [default_gdb_version]
325 # gdb_unload -- unload a file if one is loaded
327 # Returns the same as gdb_test_multiple.
329 proc gdb_unload { {msg "file"} } {
332 return [gdb_test_multiple "file" $msg {
333 -re "A program is being debugged already.\r\nAre you sure you want to change the file. .y or n. $" {
334 send_gdb "y\n" answer
338 -re "No executable file now\\.\r\n" {
342 -re "Discard symbol table from `.*'. .y or n. $
" {
343 send_gdb
"y\n" answer
347 -re
-wrap
"No symbol file now\\." {
353 # Many of the tests depend
on setting breakpoints at various places and
354 # running until that breakpoint is reached. At times
, we want to start
355 # with a clean
-slate with respect to breakpoints
, so this utility proc
356 # lets us
do this without duplicating this code everywhere.
359 proc delete_breakpoints
{} {
362 # we need a larger timeout value here or this thing just confuses
363 # itself. May need a better implementation
if possible.
- guo
367 set msg
"delete all breakpoints in delete_breakpoints"
369 gdb_test_multiple
"delete breakpoints" "$msg" {
370 -re
"Delete all breakpoints.*y or n.*$" {
371 send_gdb
"y\n" answer
374 -re
"$gdb_prompt $" {
380 # Confirm with
"info breakpoints".
382 set msg
"info breakpoints"
383 gdb_test_multiple $msg $msg
{
384 -re
"No breakpoints or watchpoints..*$gdb_prompt $" {
387 -re
"$gdb_prompt $" {
393 perror
"breakpoints not deleted"
397 # Returns true iff the target supports using the
"run" command.
399 proc target_can_use_run_cmd
{ {target_description
""} } {
400 if { $target_description
== "" } {
402 } elseif
{ $target_description
== "core" } {
403 # We could try to figure this out by issuing an
"info target" and
404 # checking
for "Local core dump file:", but it would mean the proc
405 # would start requiring a current target. Also
, uses
while gdb
406 # produces non
-standard output due to
, say annotations would
407 # have to be moved around or eliminated
, which would further
limit
411 error
"invalid argument: $target_description"
414 if [target_info
exists use_gdb_stub
] {
415 # In this case
, when we
connect, the inferior is already
420 if { $have_core
&& [target_info gdb_protocol
] == "extended-remote" } {
421 # In this case
, when we
connect, the inferior is not running but
422 # cannot be made to run.
430 # Generic run command.
432 #
Return 0 if we could start the
program, -1 if we could not.
434 # The second pattern below matches up to the first newline
*only
*.
435 # Using ``.
*$
'' could swallow up output that we attempt to match
438 # INFERIOR_ARGS is passed as arguments to the start command
, so may contain
439 # inferior arguments.
441 # N.B. This function does not wait
for gdb to
return to the prompt
,
442 # that is the caller
's responsibility.
444 proc gdb_run_cmd { {inferior_args {}} } {
445 global gdb_prompt use_gdb_stub
447 foreach command [gdb_init_commands] {
448 send_gdb "$command\n"
450 -re "$gdb_prompt $" { }
452 perror "gdb_init_command for target failed"
459 if [target_info exists gdb,do_reload_on_run] {
460 if { [gdb_reload $inferior_args] != 0 } {
463 send_gdb "continue\n"
465 -re "Continu\[^\r\n\]*\[\r\n\]" {}
471 if [target_info exists gdb,start_symbol] {
472 set start [target_info gdb,start_symbol]
476 send_gdb "jump *$start\n"
478 while { $start_attempt } {
479 # Cap (re)start attempts at three to ensure that this loop
480 # always eventually fails. Don't worry about trying to be
481 # clever and not send a command when it has failed.
482 if [expr $start_attempt
> 3] {
483 perror
"Jump to start() failed (retry count exceeded)"
486 set start_attempt
[expr $start_attempt
+ 1]
488 -re
"Continuing at \[^\r\n\]*\[\r\n\]" {
491 -re
"No symbol \"_start\" in current.*$gdb_prompt $" {
492 perror
"Can't find start symbol to run in gdb_run"
495 -re
"No symbol \"start\" in current.*$gdb_prompt $" {
496 send_gdb
"jump *_start\n"
498 -re
"No symbol.*context.*$gdb_prompt $" {
501 -re
"Line.* Jump anyway.*y or n. $" {
502 send_gdb
"y\n" answer
504 -re
"The program is not being run.*$gdb_prompt $" {
505 if { [gdb_reload $inferior_args
] != 0 } {
508 send_gdb
"jump *$start\n"
511 perror
"Jump to start() failed (timeout)"
520 if [target_info
exists gdb
,do_reload_on_run
] {
521 if { [gdb_reload $inferior_args
] != 0 } {
525 send_gdb
"run $inferior_args\n"
526 # This doesn
't work quite right yet.
527 # Use -notransfer here so that test cases (like chng-sym.exp)
528 # may test for additional start-up messages.
530 -re "The program .* has been started already.*y or n. $" {
531 send_gdb "y\n" answer
534 -notransfer -re "Starting program: \[^\r\n\]*" {}
535 -notransfer -re "$gdb_prompt $" {
536 # There is no more input expected.
538 -notransfer -re "A problem internal to GDB has been detected" {
539 # Let caller handle this.
546 # Generic start command. Return 0 if we could start the program, -1
549 # INFERIOR_ARGS is passed as arguments to the start command, so may contain
550 # inferior arguments.
552 # N.B. This function does not wait for gdb to return to the prompt,
553 # that is the caller's responsibility.
555 proc gdb_start_cmd
{ {inferior_args
{}} } {
556 global gdb_prompt use_gdb_stub
558 foreach command
[gdb_init_commands
] {
559 send_gdb
"$command\n"
561 -re
"$gdb_prompt $" { }
563 perror
"gdb_init_command for target failed"
573 send_gdb
"start $inferior_args\n"
574 # Use
-notransfer here so that test cases
(like chng
-sym.exp
)
575 # may test
for additional start
-up messages.
577 -re
"The program .* has been started already.*y or n. $" {
578 send_gdb
"y\n" answer
581 -notransfer
-re
"Starting program: \[^\r\n\]*" {
584 -re
"$gdb_prompt $" { }
589 # Generic starti command.
Return 0 if we could start the
program, -1
592 # INFERIOR_ARGS is passed as arguments to the starti command
, so may contain
593 # inferior arguments.
595 # N.B. This function does not wait
for gdb to
return to the prompt
,
596 # that is the caller
's responsibility.
598 proc gdb_starti_cmd { {inferior_args {}} } {
599 global gdb_prompt use_gdb_stub
601 foreach command [gdb_init_commands] {
602 send_gdb "$command\n"
604 -re "$gdb_prompt $" { }
606 perror "gdb_init_command for target failed"
616 send_gdb "starti $inferior_args\n"
618 -re "The program .* has been started already.*y or n. $" {
619 send_gdb "y\n" answer
622 -re "Starting program: \[^\r\n\]*" {
629 # Set a breakpoint using LINESPEC.
631 # If there is an additional argument it is a list of options; the supported
632 # options are allow-pending, temporary, message, no-message and qualified.
634 # The result is 1 for success, 0 for failure.
636 # Note: The handling of message vs no-message is messed up, but it's based
637 #
on historical usage. By default this function does not print passes
,
639 # no
-message
: turns
off printing of fails
(and passes
, but they
're already off)
640 # message: turns on printing of passes (and fails, but they're already
on)
642 proc gdb_breakpoint
{ linespec
args } {
646 set pending_response n
647 if {[lsearch
-exact $
args allow
-pending
] != -1} {
648 set pending_response y
651 set break_command
"break"
652 set break_message
"Breakpoint"
653 if {[lsearch
-exact $
args temporary
] != -1} {
654 set break_command
"tbreak"
655 set break_message
"Temporary breakpoint"
658 if {[lsearch
-exact $
args qualified
] != -1} {
659 append break_command
" -qualified"
664 set no_message_loc
[lsearch
-exact $
args no
-message
]
665 set message_loc
[lsearch
-exact $
args message
]
666 # The last one to appear in
args wins.
667 if { $no_message_loc
> $message_loc
} {
669 } elseif
{ $message_loc
> $no_message_loc
} {
673 set test_name
"gdb_breakpoint: set breakpoint at $linespec"
674 # The first two regexps are what we
get with
-g
, the third is without
-g.
675 gdb_test_multiple
"$break_command $linespec" $test_name {
676 -re
"$break_message \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
677 -re
"$break_message \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
678 -re
"$break_message \[0-9\]* at .*$gdb_prompt $" {}
679 -re
"$break_message \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" {
680 if {$pending_response
== "n"} {
687 -re
"Make breakpoint pending.*y or \\\[n\\\]. $" {
688 send_gdb
"$pending_response\n"
691 -re
"$gdb_prompt $" {
704 #
Set breakpoint at function and run gdb until it breaks there.
705 # Since this is the only breakpoint that will be
set, if it stops
706 # at a breakpoint
, we will assume it is the one we want. We can
't
707 # just compare to "function" because it might be a fully qualified,
708 # single quoted C++ function specifier.
710 # If there are additional arguments, pass them to gdb_breakpoint.
711 # We recognize no-message/message ourselves.
713 # no-message is messed up here, like gdb_breakpoint: to preserve
714 # historical usage fails are always printed by default.
715 # no-message: turns off printing of fails (and passes, but they're already
off)
716 # message
: turns
on printing of passes
(and fails
, but they
're already on)
718 proc runto { linespec args } {
720 global bkptno_numopt_re
727 set no_message_loc [lsearch -exact $args no-message]
728 set message_loc [lsearch -exact $args message]
729 # The last one to appear in args wins.
730 if { $no_message_loc > $message_loc } {
732 } elseif { $message_loc > $no_message_loc } {
736 set test_name "runto: run to $linespec"
738 if {![gdb_breakpoint $linespec {*}$args]} {
744 # the "at foo.c:36" output we get with -g.
745 # the "in func" output we get without -g.
747 -re "(?:Break|Temporary break).* at .*:$decimal.*$gdb_prompt $" {
753 -re "(?:Breakpoint|Temporary breakpoint) $bkptno_numopt_re, \[0-9xa-f\]* in .*$gdb_prompt $" {
759 -re "The target does not support running in non-stop mode.\r\n$gdb_prompt $" {
761 unsupported "non-stop mode not supported"
765 -re ".*A problem internal to GDB has been detected" {
766 # Always emit a FAIL if we encounter an internal error: internal
767 # errors are never expected.
768 fail "$test_name (GDB internal error)"
769 gdb_internal_error_resync
772 -re "$gdb_prompt $" {
780 fail "$test_name (eof)"
786 fail "$test_name (timeout)"
797 # Ask gdb to run until we hit a breakpoint at main.
799 # N.B. This function deletes all existing breakpoints.
800 # If you don't want that
, use gdb_start_cmd.
802 proc runto_main
{ } {
803 return [runto main qualified
]
806 ###
Continue, and expect to hit a breakpoint.
807 ###
Report a pass or fail
, depending
on whether it seems to have
808 ### worked. Use
NAME as part of the test
name; each
call to
809 ### continue_to_breakpoint should use a
NAME which is unique within
811 proc gdb_continue_to_breakpoint
{name {location_pattern .
*}} {
813 set full_name
"continue to breakpoint: $name"
815 set kfail_pattern
"Process record does not support instruction 0xfae64 at.*"
816 gdb_test_multiple
"continue" $full_name {
817 -re
"(?:Breakpoint|Temporary breakpoint) .* (at|in) $location_pattern\r\n$gdb_prompt $" {
820 -re
"\[\r\n\]*(?:$kfail_pattern)\[\r\n\]+$gdb_prompt $" {
821 kfail
"gdb/25038" $full_name
827 # gdb_internal_error_resync
:
829 # Answer the questions GDB asks after it reports an internal error
830 # until we
get back to a GDB prompt. Decline to quit the debugging
831 # session
, and decline to create a core file.
Return non
-zero
if the
834 # This procedure just answers whatever questions come up until it sees
835 # a GDB prompt
; it doesn
't require you to have matched the input up to
836 # any specific point. However, it only answers questions it sees in
837 # the output itself, so if you've matched a question
, you had better
838 # answer it yourself before calling this.
840 # You can use this function thus
:
844 #
-re
".*A problem internal to GDB has been detected" {
845 # gdb_internal_error_resync
850 proc gdb_internal_error_resync
{} {
853 verbose
-log "Resyncing due to internal error."
856 while {$
count < 10} {
858 -re
"Recursive internal problem\\." {
859 perror
"Could not resync from internal error (recursive internal problem)"
862 -re
"Quit this debugging session\\? \\(y or n\\) $" {
863 send_gdb
"n\n" answer
866 -re
"Create a core file of GDB\\? \\(y or n\\) $" {
867 send_gdb
"n\n" answer
870 -re
"$gdb_prompt $" {
871 # We
're resynchronized.
875 perror "Could not resync from internal error (timeout)"
879 perror "Could not resync from internal error (eof)"
884 perror "Could not resync from internal error (resync count exceeded)"
888 # Fill in the default prompt if PROMPT_REGEXP is empty.
890 # If WITH_ANCHOR is true and the default prompt is used, append a `$` at the end
891 # of the regexp, to anchor the match at the end of the buffer.
892 proc fill_in_default_prompt {prompt_regexp with_anchor} {
893 if { "$prompt_regexp" == "" } {
894 set prompt "$::gdb_prompt "
896 if { $with_anchor } {
902 return $prompt_regexp
905 # gdb_test_multiple COMMAND MESSAGE [ -prompt PROMPT_REGEXP] [ -lbl ]
907 # Send a command to gdb; test the result.
909 # COMMAND is the command to execute, send to GDB with send_gdb. If
910 # this is the null string no command is sent.
911 # MESSAGE is a message to be printed with the built-in failure patterns
912 # if one of them matches. If MESSAGE is empty COMMAND will be used.
913 # -prompt PROMPT_REGEXP specifies a regexp matching the expected prompt
914 # after the command output. If empty, defaults to "$gdb_prompt $".
915 # -lbl specifies that line-by-line matching will be used.
916 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
917 # patterns. Pattern elements will be evaluated in the caller's
918 #
context; action elements will be executed in the caller
's context.
919 # Unlike patterns for gdb_test, these patterns should generally include
920 # the final newline and prompt.
923 # 1 if the test failed, according to a built-in failure pattern
924 # 0 if only user-supplied patterns matched
925 # -1 if there was an internal error.
927 # You can use this function thus:
929 # gdb_test_multiple "print foo" "test foo" {
930 # -re "expected output 1" {
933 # -re "expected output 2" {
938 # Within action elements you can also make use of the variable
939 # gdb_test_name. This variable is setup automatically by
940 # gdb_test_multiple, and contains the value of MESSAGE. You can then
941 # write this, which is equivalent to the above:
943 # gdb_test_multiple "print foo" "test foo" {
944 # -re "expected output 1" {
945 # pass $gdb_test_name
947 # -re "expected output 2" {
948 # fail $gdb_test_name
952 # Like with "expect", you can also specify the spawn id to match with
953 # -i "$id". Interesting spawn ids are $inferior_spawn_id and
954 # $gdb_spawn_id. The former matches inferior I/O, while the latter
955 # matches GDB I/O. E.g.:
957 # send_inferior "hello\n"
958 # gdb_test_multiple "continue" "test echo" {
959 # -i "$inferior_spawn_id" -re "^hello\r\nhello\r\n$" {
962 # -i "$gdb_spawn_id" -re "Breakpoint.*$gdb_prompt $" {
963 # fail "hit breakpoint"
967 # The standard patterns, such as "Inferior exited..." and "A problem
968 # ...", all being implicitly appended to that list. These are always
969 # expected from $gdb_spawn_id. IOW, callers do not need to worry
970 # about resetting "-i" back to $gdb_spawn_id explicitly.
972 # In EXPECT_ARGUMENTS we can use a -wrap pattern flag, that wraps the regexp
973 # pattern as gdb_test wraps its message argument.
974 # This allows us to rewrite:
975 # gdb_test <command> <pattern> <message>
977 # gdb_test_multiple <command> <message> {
978 # -re -wrap <pattern> {
979 # pass $gdb_test_name
983 # In EXPECT_ARGUMENTS, a pattern flag -early can be used. It makes sure the
984 # pattern is inserted before any implicit pattern added by gdb_test_multiple.
985 # Using this pattern flag, we can f.i. setup a kfail for an assertion failure
986 # <assert> during gdb_continue_to_breakpoint by the rewrite:
987 # gdb_continue_to_breakpoint <msg> <pattern>
989 # set breakpoint_pattern "(?:Breakpoint|Temporary breakpoint) .* (at|in)"
990 # gdb_test_multiple "continue" "continue to breakpoint: <msg>" {
991 # -early -re "internal-error: <assert>" {
992 # setup_kfail gdb/nnnnn "*-*-*"
995 # -re "$breakpoint_pattern <pattern>\r\n$gdb_prompt $" {
996 # pass $gdb_test_name
1000 proc gdb_test_multiple { command message args } {
1001 global verbose use_gdb_stub
1002 global gdb_prompt pagination_prompt
1005 global inferior_exited_re
1006 upvar timeout timeout
1007 upvar expect_out expect_out
1011 set prompt_regexp ""
1012 for {set i 0} {$i < [llength $args]} {incr i} {
1013 set arg [lindex $args $i]
1014 if { $arg == "-prompt" } {
1016 set prompt_regexp [lindex $args $i]
1017 } elseif { $arg == "-lbl" } {
1024 if { [expr $i + 1] < [llength $args] } {
1025 error "Too many arguments to gdb_test_multiple"
1026 } elseif { ![info exists user_code] } {
1027 error "Too few arguments to gdb_test_multiple"
1030 set prompt_regexp [fill_in_default_prompt $prompt_regexp true]
1032 if { $message == "" } {
1033 set message $command
1036 if [string match "*\[\r\n\]" $command] {
1037 error "Invalid trailing newline in \"$command\" command"
1040 if [string match "*\[\003\004\]" $command] {
1041 error "Invalid trailing control code in \"$command\" command"
1044 if [string match "*\[\r\n\]*" $message] {
1045 error "Invalid newline in \"$message\" test"
1049 && [regexp -nocase {^\s*(r|run|star|start|at|att|atta|attac|attach)\M} \
1051 error "gdbserver does not support $command without extended-remote"
1054 # TCL/EXPECT WART ALERT
1055 # Expect does something very strange when it receives a single braced
1056 # argument. It splits it along word separators and performs substitutions.
1057 # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
1058 # evaluated as "\[ab\]". But that's not how TCL normally works
; inside a
1059 # double
-quoted list item
, "\[ab\]" is just a long way of representing
1060 #
"[ab]", because the backslashes will be removed by lindex.
1062 # Unfortunately
, there appears to be no easy way to duplicate the splitting
1063 # that expect will
do from within TCL. And many places make use of the
1064 #
"\[0-9\]" construct, so we need to support that; and some places make use
1065 # of the
"[func]" construct, so we need to support that too. In order to
1066 #
get this right we have to substitute quoted list elements differently
1067 # from braced list elements.
1069 # We
do this roughly the same way that Expect does it. We have to use two
1070 # lists
, because
if we leave unquoted newlines in the
argument to uplevel
1071 # they
'll be treated as command separators, and if we escape newlines
1072 # we mangle newlines inside of command blocks. This assumes that the
1073 # input doesn't contain a pattern which contains actual embedded newlines
1076 regsub
-all
{\n} $
{user_code
} { } subst_code
1077 set subst_code
[uplevel list $subst_code
]
1079 set processed_code
""
1080 set early_processed_code
""
1081 # The
variable current_list holds the
name of the currently processed
1082 # list
, either processed_code or early_processed_code.
1083 set current_list
"processed_code"
1085 set expecting_action
0
1088 foreach item $user_code subst_item $subst_code
{
1089 if { $item
== "-n" || $item == "-notransfer" || $item == "-nocase" } {
1090 lappend $current_list $item
1093 if { $item
== "-indices" || $item == "-re" || $item == "-ex" } {
1094 lappend $current_list $item
1097 if { $item
== "-early" } {
1098 set current_list
"early_processed_code"
1101 if { $item
== "-timeout" || $item == "-i" } {
1103 lappend $current_list $item
1106 if { $item
== "-wrap" } {
1110 if { $expecting_arg
} {
1112 lappend $current_list $subst_item
1115 if { $expecting_action
} {
1116 lappend $current_list
"uplevel [list $item]"
1117 set expecting_action
0
1118 # Cosmetic
, no effect
on the list.
1119 append $current_list
"\n"
1120 # End the effect of
-early
, it only applies to one action.
1121 set current_list
"processed_code"
1124 set expecting_action
1
1125 if { $wrap_pattern
} {
1126 # Wrap subst_item as is done
for the gdb_test PATTERN
argument.
1127 lappend $current_list \
1128 "\[\r\n\]*(?:$subst_item)\[\r\n\]+$gdb_prompt $"
1131 lappend $current_list $subst_item
1133 if {$patterns
!= ""} {
1134 append patterns
"; "
1136 append patterns
"\"$subst_item\""
1139 # Also purely cosmetic.
1140 regsub
-all
{\r} $patterns
{\\r
} patterns
1141 regsub
-all
{\n} $patterns
{\\n
} patterns
1144 send_user
"Sending \"$command\" to gdb\n"
1145 send_user
"Looking to match \"$patterns\"\n"
1146 send_user
"Message is \"$message\"\n"
1150 set string
"${command}\n"
1151 if { $command
!= "" } {
1152 set multi_line_re
"\[\r\n\] *>"
1153 while { "$string" != "" } {
1154 set foo
[string first
"\n" "$string"]
1155 set len
[string length
"$string"]
1156 if { $foo
< [expr $len
- 1] } {
1157 set str
[string range
"$string" 0 $foo]
1158 if { [send_gdb
"$str"] != "" } {
1159 verbose
-log "Couldn't send $command to GDB."
1163 # since we
're checking if each line of the multi-line
1164 # command are 'accepted
' by GDB here,
1165 # we need to set -notransfer expect option so that
1166 # command output is not lost for pattern matching
1169 -notransfer -re "$multi_line_re$" { verbose "partial: match" 3 }
1170 timeout { verbose "partial: timeout" 3 }
1172 set string [string range "$string" [expr $foo + 1] end]
1173 set multi_line_re "$multi_line_re.*\[\r\n\] *>"
1178 if { "$string" != "" } {
1179 if { [send_gdb "$string"] != "" } {
1180 verbose -log "Couldn't send $command to GDB.
"
1187 set code $early_processed_code
1189 -re
".*A problem internal to GDB has been detected" {
1190 fail
"$message (GDB internal error)"
1191 gdb_internal_error_resync
1194 -re
"\\*\\*\\* DOSEXIT code.*" {
1195 if { $message
!= "" } {
1200 -re
"Corrupted shared library list.*$prompt_regexp" {
1201 fail
"$message (shared library list corrupted)"
1204 -re
"Invalid cast\.\r\nwarning: Probes-based dynamic linker interface failed.*$prompt_regexp" {
1205 fail
"$message (probes interface failure)"
1209 append code $processed_code
1211 # Reset the spawn id
, in case the processed code used
-i.
1217 -re
"Ending remote debugging.*$prompt_regexp" {
1219 warning
"Can`t communicate to remote target."
1225 -re
"Undefined\[a-z\]* command:.*$prompt_regexp" {
1226 perror
"Undefined command \"$command\"."
1230 -re
"Ambiguous command.*$prompt_regexp" {
1231 perror
"\"$command\" is not a unique command name."
1235 -re
"$inferior_exited_re with code \[0-9\]+.*$prompt_regexp" {
1236 if {![string match
"" $message]} {
1237 set errmsg
"$message (the program exited)"
1239 set errmsg
"$command (the program exited)"
1244 -re
"$inferior_exited_re normally.*$prompt_regexp" {
1245 if {![string match
"" $message]} {
1246 set errmsg
"$message (the program exited)"
1248 set errmsg
"$command (the program exited)"
1253 -re
"The program is not being run.*$prompt_regexp" {
1254 if {![string match
"" $message]} {
1255 set errmsg
"$message (the program is no longer running)"
1257 set errmsg
"$command (the program is no longer running)"
1262 -re
"\r\n$prompt_regexp" {
1263 if {![string match
"" $message]} {
1268 -re
"$pagination_prompt" {
1270 perror
"Window too small."
1274 -re
"\\((y or n|y or \\\[n\\\]|\\\[y\\\] or n)\\) " {
1275 send_gdb
"n\n" answer
1276 gdb_expect
-re
"$prompt_regexp"
1277 fail
"$message (got interactive prompt)"
1280 -re
"\\\[0\\\] cancel\r\n\\\[1\\\] all.*\r\n> $" {
1282 gdb_expect
-re
"$prompt_regexp"
1283 fail
"$message (got breakpoint menu)"
1289 perror
"GDB process no longer exists"
1290 set wait_status
[wait
-i $gdb_spawn_id
]
1291 verbose
-log "GDB process exited with wait status $wait_status"
1292 if { $message
!= "" } {
1299 if {$line_by_line
} {
1301 -re
"\r\n\[^\r\n\]*(?=\r\n)" {
1307 # Now patterns that apply to
any spawn id specified.
1311 perror
"Process no longer exists"
1312 if { $message
!= "" } {
1318 perror
"internal buffer is full."
1323 if {![string match
"" $message]} {
1324 fail
"$message (timeout)"
1330 # remote_expect calls the eof section
if there is an error
on the
1331 # expect
call. We already have eof sections above
, and we don
't
1332 # want them to get called in that situation. Since the last eof
1333 # section becomes the error section, here we define another eof
1334 # section, but with an empty spawn_id list, so that it won't ever
1338 # This comment is here because the eof section must not be
1339 # the empty string
, otherwise remote_expect won
't realize
1344 # Create gdb_test_name in the parent scope. If this variable
1345 # already exists, which it might if we have nested calls to
1346 # gdb_test_multiple, then preserve the old value, otherwise,
1347 # create a new variable in the parent scope.
1348 upvar gdb_test_name gdb_test_name
1349 if { [info exists gdb_test_name] } {
1350 set gdb_test_name_old "$gdb_test_name"
1352 set gdb_test_name "$message"
1355 set code [catch {gdb_expect $code} string]
1357 # Clean up the gdb_test_name variable. If we had a
1358 # previous value then restore it, otherwise, delete the variable
1359 # from the parent scope.
1360 if { [info exists gdb_test_name_old] } {
1361 set gdb_test_name "$gdb_test_name_old"
1367 global errorInfo errorCode
1368 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
1369 } elseif {$code > 1} {
1370 return -code $code $string
1375 # Usage: gdb_test_multiline NAME INPUT RESULT {INPUT RESULT} ...
1376 # Run a test named NAME, consisting of multiple lines of input.
1377 # After each input line INPUT, search for result line RESULT.
1378 # Succeed if all results are seen; fail otherwise.
1380 proc gdb_test_multiline { name args } {
1383 foreach {input result} $args {
1385 if {[gdb_test_multiple $input "$name: input $inputnr: $input" {
1386 -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
1397 # gdb_test [-prompt PROMPT_REGEXP] [-lbl]
1398 # COMMAND [PATTERN] [MESSAGE] [QUESTION RESPONSE]
1399 # Send a command to gdb; test the result.
1401 # COMMAND is the command to execute, send to GDB with send_gdb. If
1402 # this is the null string no command is sent.
1403 # PATTERN is the pattern to match for a PASS, and must NOT include
1404 # the \r\n sequence immediately before the gdb prompt. This argument
1405 # may be omitted to just match the prompt, ignoring whatever output
1407 # MESSAGE is an optional message to be printed. If this is
1408 # omitted, then the pass/fail messages use the command string as the
1409 # message. (If this is the empty string, then sometimes we don't
1410 #
call pass or fail at all
; I don
't understand this at all.)
1411 # QUESTION is a question GDB should ask in response to COMMAND, like
1412 # "are you sure?" If this is specified, the test fails if GDB
1413 # doesn't print the question.
1414 # RESPONSE is the response to send when QUESTION appears.
1416 #
-prompt PROMPT_REGEXP specifies a regexp matching the expected prompt
1417 # after the command output.
If empty
, defaults to
"$gdb_prompt $".
1418 #
-no
-prompt
-anchor specifies that
if the default prompt regexp is used
, it
1419 # should not be anchored at the end of the buffer. This means that the
1420 # pattern can match even
if there is stuff output after the prompt. Does not
1421 # have
any effect
if -prompt is specified.
1422 #
-lbl specifies that line
-by
-line matching will be used.
1423 #
-nopass specifies that a PASS should not be issued.
1424 #
-nonl specifies that no
\r\n sequence is expected between PATTERN
1425 # and the gdb prompt.
1428 #
1 if the test failed
,
1429 #
0 if the test passes
,
1430 #
-1 if there was an internal error.
1432 proc gdb_test
{ args } {
1434 upvar timeout timeout
1444 lassign $
args command pattern message question response
1446 # Can
't have a question without a response.
1447 if { $question != "" && $response == "" || [llength $args] > 5 } {
1448 error "Unexpected arguments: $args"
1451 if { $message == "" } {
1452 set message $command
1455 set prompt [fill_in_default_prompt $prompt [expr !${no-prompt-anchor}]]
1456 set nl [expr ${nonl} ? {""} : {"\[\r\n\]+"}]
1462 -re "\[\r\n\]*(?:$pattern)$nl$prompt" {
1463 if { $question != "" & !$saw_question} {
1465 } elseif {!$nopass} {
1471 if { $question != "" } {
1475 send_gdb "$response\n"
1481 set user_code [join $user_code]
1484 lappend opts "-prompt" "$prompt"
1489 return [gdb_test_multiple $command $message {*}$opts $user_code]
1492 # Return 1 if version MAJOR.MINOR is at least AT_LEAST_MAJOR.AT_LEAST_MINOR.
1493 proc version_at_least { major minor at_least_major at_least_minor} {
1494 if { $major > $at_least_major } {
1496 } elseif { $major == $at_least_major \
1497 && $minor >= $at_least_minor } {
1504 # Return 1 if tcl version used is at least MAJOR.MINOR
1505 proc tcl_version_at_least { major minor } {
1507 regexp {^([0-9]+)\.([0-9]+)$} $tcl_version \
1508 dummy tcl_version_major tcl_version_minor
1509 return [version_at_least $tcl_version_major $tcl_version_minor \
1513 if { [tcl_version_at_least 8 5] == 0 } {
1514 # lrepeat was added in tcl 8.5. Only add if missing.
1515 proc lrepeat { n element } {
1516 if { [string is integer -strict $n] == 0 } {
1517 error "expected integer but got \"$n\""
1520 error "bad count \"$n\": must be integer >= 0"
1523 for {set i 0} {$i < $n} {incr i} {
1524 lappend res $element
1530 # gdb_test_no_output [-prompt PROMPT_REGEXP] [-nopass] COMMAND [MESSAGE]
1531 # Send a command to GDB and verify that this command generated no output.
1533 # See gdb_test for a description of the -prompt, -no-prompt-anchor, -nopass,
1534 # COMMAND, and MESSAGE parameters.
1536 proc gdb_test_no_output { args } {
1545 lassign $args command message
1547 set prompt [fill_in_default_prompt $prompt [expr !${no-prompt-anchor}]]
1549 set command_regex [string_to_regexp $command]
1550 gdb_test_multiple $command $message -prompt $prompt {
1551 -re "^$command_regex\r\n$prompt" {
1559 # Send a command and then wait for a sequence of outputs.
1560 # This is useful when the sequence is long and contains ".*", a single
1561 # regexp to match the entire output can get a timeout much easier.
1563 # COMMAND is the command to execute, send to GDB with send_gdb. If
1564 # this is the null string no command is sent.
1565 # TEST_NAME is passed to pass/fail. COMMAND is used if TEST_NAME is "".
1566 # EXPECTED_OUTPUT_LIST is a list of regexps of expected output, which are
1567 # processed in order, and all must be present in the output.
1569 # The -prompt switch can be used to override the prompt expected at the end of
1570 # the output sequence.
1572 # It is unnecessary to specify ".*" at the beginning or end of any regexp,
1573 # there is an implicit ".*" between each element of EXPECTED_OUTPUT_LIST.
1574 # There is also an implicit ".*" between the last regexp and the gdb prompt.
1576 # Like gdb_test and gdb_test_multiple, the output is expected to end with the
1577 # gdb prompt, which must not be specified in EXPECTED_OUTPUT_LIST.
1580 # 1 if the test failed,
1581 # 0 if the test passes,
1582 # -1 if there was an internal error.
1584 proc gdb_test_sequence { args } {
1587 parse_args {{prompt ""}}
1589 if { $prompt == "" } {
1590 set prompt "$gdb_prompt $"
1593 if { [llength $args] != 3 } {
1594 error "Unexpected # of arguments, expecting: COMMAND TEST_NAME EXPECTED_OUTPUT_LIST"
1597 lassign $args command test_name expected_output_list
1599 if { $test_name == "" } {
1600 set test_name $command
1603 lappend expected_output_list ""; # implicit ".*" before gdb prompt
1605 if { $command != "" } {
1606 send_gdb "$command\n"
1609 return [gdb_expect_list $test_name $prompt $expected_output_list]
1613 # Match output of COMMAND using RE. Read output line-by-line.
1614 # Report pass/fail with MESSAGE.
1615 # For a command foo with output:
1620 # the portion matched using RE is:
1625 # Optionally, additional -re-not <regexp> arguments can be specified, to
1626 # ensure that a regexp is not match by the COMMAND output.
1627 # Such an additional argument generates an additional PASS/FAIL of the form:
1628 # PASS: test-case.exp: $message: pattern not matched: <regexp>
1630 proc gdb_test_lines { command message re args } {
1633 for {set i 0} {$i < [llength $args]} {incr i} {
1634 set arg [lindex $args $i]
1635 if { $arg == "-re-not" } {
1637 if { [llength $args] == $i } {
1638 error "Missing argument for -re-not"
1641 set arg [lindex $args $i]
1644 error "Unhandled argument: $arg"
1648 if { $message == ""} {
1649 set message $command
1653 gdb_test_multiple $command $message {
1654 -re "\r\n(\[^\r\n\]*)(?=\r\n)" {
1655 set line $expect_out(1,string)
1656 if { $lines eq "" } {
1657 append lines "$line"
1659 append lines "\r\n$line"
1668 gdb_assert { [regexp $re $lines] } $message
1670 foreach re $re_not {
1671 gdb_assert { ![regexp $re $lines] } "$message: pattern not matched: $re"
1675 # Test that a command gives an error. For pass or fail, return
1676 # a 1 to indicate that more tests can proceed. However a timeout
1677 # is a serious error, generates a special fail message, and causes
1678 # a 0 to be returned to indicate that more tests are likely to fail
1681 proc test_print_reject { args } {
1685 if {[llength $args] == 2} {
1686 set expectthis [lindex $args 1]
1688 set expectthis "should never match this bogus string"
1690 set sendthis [lindex $args 0]
1692 send_user "Sending \"$sendthis\" to gdb\n"
1693 send_user "Looking to match \"$expectthis\"\n"
1695 send_gdb "$sendthis\n"
1696 #FIXME: Should add timeout as parameter.
1698 -re "A .* in expression.*\\.*$gdb_prompt $" {
1699 pass "reject $sendthis"
1702 -re "Invalid syntax in expression.*$gdb_prompt $" {
1703 pass "reject $sendthis"
1706 -re "Junk after end of expression.*$gdb_prompt $" {
1707 pass "reject $sendthis"
1710 -re "Invalid number.*$gdb_prompt $" {
1711 pass "reject $sendthis"
1714 -re "Invalid character constant.*$gdb_prompt $" {
1715 pass "reject $sendthis"
1718 -re "No symbol table is loaded.*$gdb_prompt $" {
1719 pass "reject $sendthis"
1722 -re "No symbol .* in current context.*$gdb_prompt $" {
1723 pass "reject $sendthis"
1726 -re "Unmatched single quote.*$gdb_prompt $" {
1727 pass "reject $sendthis"
1730 -re "A character constant must contain at least one character.*$gdb_prompt $" {
1731 pass "reject $sendthis"
1734 -re "$expectthis.*$gdb_prompt $" {
1735 pass "reject $sendthis"
1738 -re ".*$gdb_prompt $" {
1739 fail "reject $sendthis"
1743 fail "reject $sendthis (eof or timeout)"
1750 # Same as gdb_test, but the second parameter is not a regexp,
1751 # but a string that must match exactly.
1753 proc gdb_test_exact { args } {
1754 upvar timeout timeout
1756 set command [lindex $args 0]
1758 # This applies a special meaning to a null string pattern. Without
1759 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
1760 # messages from commands that should have no output except a new
1761 # prompt. With this, only results of a null string will match a null
1764 set pattern [lindex $args 1]
1765 if [string match $pattern ""] {
1766 set pattern [string_to_regexp [lindex $args 0]]
1768 set pattern [string_to_regexp [lindex $args 1]]
1771 # It is most natural to write the pattern argument with only
1772 # embedded \n's
, especially
if you are trying to avoid Tcl quoting
1773 # problems. But gdb_expect really wants to see
\r\n in patterns. So
1774 # transform the pattern here. First transform
\r\n back to
\n, in
1775 # case some users of gdb_test_exact already
do the right thing.
1776 regsub
-all
"\r\n" $pattern "\n" pattern
1777 regsub
-all
"\n" $pattern "\r\n" pattern
1778 if {[llength $
args] == 3} {
1779 set message
[lindex $
args 2]
1780 return [gdb_test $command $pattern $message
]
1783 return [gdb_test $command $pattern
]
1786 # Wrapper around gdb_test_multiple that looks
for a list of expected
1787 # output elements
, but which can appear in
any order.
1788 # CMD is the gdb command.
1789 #
NAME is the
name of the test.
1790 # ELM_FIND_REGEXP specifies how to partition the output into elements to
1792 # ELM_EXTRACT_REGEXP specifies the part of ELM_FIND_REGEXP to compare.
1793 # RESULT_MATCH_LIST is a list of exact matches
for each expected element.
1794 # All elements of RESULT_MATCH_LIST must appear
for the test to pass.
1796 # A typical use of ELM_FIND_REGEXP
/ELM_EXTRACT_REGEXP is to extract one line
1797 # of
text per element and
then strip trailing
\r\n's.
1799 # gdb_test_list_exact "foo" "bar" \
1800 # "\[^\r\n\]+\[\r\n\]+" \
1803 # {expected result 1} \
1804 # {expected result 2} \
1807 proc gdb_test_list_exact { cmd name elm_find_regexp elm_extract_regexp result_match_list } {
1810 set matches [lsort $result_match_list]
1812 gdb_test_multiple $cmd $name {
1813 "$cmd\[\r\n\]" { exp_continue }
1814 -re $elm_find_regexp {
1815 set str $expect_out(0,string)
1816 verbose -log "seen: $str" 3
1817 regexp -- $elm_extract_regexp $str elm_seen
1818 verbose -log "extracted: $elm_seen" 3
1819 lappend seen $elm_seen
1822 -re "$gdb_prompt $" {
1824 foreach got [lsort $seen] have $matches {
1825 if {![string equal $got $have]} {
1830 if {[string length $failed] != 0} {
1831 fail "$name ($failed not found)"
1839 # gdb_test_stdio COMMAND INFERIOR_PATTERN GDB_PATTERN MESSAGE
1840 # Send a command to gdb; expect inferior and gdb output.
1842 # See gdb_test_multiple for a description of the COMMAND and MESSAGE
1845 # INFERIOR_PATTERN is the pattern to match against inferior output.
1847 # GDB_PATTERN is the pattern to match against gdb output, and must NOT
1848 # include the \r\n sequence immediately before the gdb prompt, nor the
1849 # prompt. The default is empty.
1851 # Both inferior and gdb patterns must match for a PASS.
1853 # If MESSAGE is ommitted, then COMMAND will be used as the message.
1856 # 1 if the test failed,
1857 # 0 if the test passes,
1858 # -1 if there was an internal error.
1861 proc gdb_test_stdio {command inferior_pattern {gdb_pattern ""} {message ""}} {
1862 global inferior_spawn_id gdb_spawn_id
1865 if {$message == ""} {
1866 set message $command
1869 set inferior_matched 0
1872 # Use an indirect spawn id list, and remove the inferior spawn id
1873 # from the expected output as soon as it matches, in case
1874 # $inferior_pattern happens to be a prefix of the resulting full
1875 # gdb pattern below (e.g., "\r\n").
1876 global gdb_test_stdio_spawn_id_list
1877 set gdb_test_stdio_spawn_id_list "$inferior_spawn_id"
1879 # Note that if $inferior_spawn_id and $gdb_spawn_id are different,
1880 # then we may see gdb's output arriving before the inferior
's
1882 set res [gdb_test_multiple $command $message {
1883 -i gdb_test_stdio_spawn_id_list -re "$inferior_pattern" {
1884 set inferior_matched 1
1885 if {!$gdb_matched} {
1886 set gdb_test_stdio_spawn_id_list ""
1890 -i $gdb_spawn_id -re "$gdb_pattern\r\n$gdb_prompt $" {
1892 if {!$inferior_matched} {
1900 verbose -log "inferior_matched=$inferior_matched, gdb_matched=$gdb_matched"
1905 # Wrapper around gdb_test_multiple to be used when testing expression
1906 # evaluation while 'set debug expression
1' is in effect.
1907 # Looks for some patterns that indicates the expression was rejected.
1909 # CMD is the command to execute, which should include an expression
1910 # that GDB will need to parse.
1912 # OUTPUT is the expected output pattern.
1914 # TESTNAME is the name to be used for the test, defaults to CMD if not
1916 proc gdb_test_debug_expr { cmd output {testname "" }} {
1919 if { ${testname} == "" } {
1923 gdb_test_multiple $cmd $testname {
1924 -re ".*Invalid expression.*\r\n$gdb_prompt $" {
1927 -re ".*\[\r\n\]$output\r\n$gdb_prompt $" {
1933 # get_print_expr_at_depths EXP OUTPUTS
1935 # Used for testing 'set print
max-depth
'. Prints the expression EXP
1936 # with 'set print
max-depth
' set to various depths. OUTPUTS is a list
1937 # of `n` different patterns to match at each of the depths from 0 to
1940 # This proc does one final check with the max-depth set to 'unlimited
'
1941 # which is tested against the last pattern in the OUTPUTS list. The
1942 # OUTPUTS list is therefore required to match every depth from 0 to a
1943 # depth where the whole of EXP is printed with no ellipsis.
1945 # This proc leaves the 'set print
max-depth
' set to 'unlimited
'.
1946 proc gdb_print_expr_at_depths {exp outputs} {
1947 for { set depth 0 } { $depth <= [llength $outputs] } { incr depth } {
1948 if { $depth == [llength $outputs] } {
1949 set expected_result [lindex $outputs [expr [llength $outputs] - 1]]
1950 set depth_string "unlimited"
1952 set expected_result [lindex $outputs $depth]
1953 set depth_string $depth
1956 with_test_prefix "exp='$exp
': depth=${depth_string}" {
1957 gdb_test_no_output "set print max-depth ${depth_string}"
1958 gdb_test "p $exp" "$expected_result"
1965 # Issue a PASS and return true if evaluating CONDITION in the caller's
1966 # frame returns true
, and issue a FAIL and
return false otherwise.
1967 # MESSAGE is the pass
/fail message to be printed.
If MESSAGE is
1968 # omitted or is empty
, then the pass
/fail messages use the condition
1969 # string as the message.
1971 proc gdb_assert
{ condition
{message
""} } {
1972 if { $message
== ""} {
1973 set message $condition
1976 set code
[catch
{uplevel
1 [list expr $condition
]} res
]
1978 #
If code is
1 (TCL_ERROR
), it means evaluation failed and res contains
1979 # an error message. Print the error message
, and
set res to
0 since we
1980 # want to
return a
boolean.
1981 warning
"While evaluating expression in gdb_assert: $res"
1984 } elseif
{ !$res
} {
1992 proc gdb_reinitialize_dir
{ subdir
} {
1995 if [is_remote host
] {
2000 -re
"Reinitialize source path to empty.*y or n. " {
2001 send_gdb
"y\n" answer
2003 -re
"Source directories searched.*$gdb_prompt $" {
2004 send_gdb
"dir $subdir\n"
2006 -re
"Source directories searched.*$gdb_prompt $" {
2007 verbose
"Dir set to $subdir"
2009 -re
"$gdb_prompt $" {
2010 perror
"Dir \"$subdir\" failed."
2014 -re
"$gdb_prompt $" {
2015 perror
"Dir \"$subdir\" failed."
2019 -re
"$gdb_prompt $" {
2020 perror
"Dir \"$subdir\" failed."
2026 # gdb_exit
-- exit the GDB
, killing the target
program if necessary
2028 proc default_gdb_exit
{} {
2030 global INTERNAL_GDBFLAGS GDBFLAGS
2031 global gdb_spawn_id inferior_spawn_id
2032 global inotify_log_file
2034 if ![info exists gdb_spawn_id
] {
2038 verbose
"Quitting $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
2040 if {[info exists inotify_log_file
] && [file
exists $inotify_log_file
]} {
2041 set fd
[open $inotify_log_file
]
2042 set data
[read
-nonewline $fd
]
2045 if {[string compare $data
""] != 0} {
2046 warning
"parallel-unsafe file creations noticed"
2049 set fd
[open $inotify_log_file w
]
2054 if { [is_remote host
] && [board_info host
exists fileid
] } {
2058 send_gdb
"y\n" answer
2061 -re
"DOSEXIT code" { }
2066 if ![is_remote host
] {
2070 unset
::gdb_tty_name
2071 unset inferior_spawn_id
2074 #
Load a file into the debugger.
2075 # The
return value is
0 for success
, -1 for failure.
2077 # This procedure also
set the global
variable GDB_FILE_CMD_DEBUG_INFO
2078 # to one of these
values:
2080 # debug file was loaded successfully and has debug information
2081 # nodebug file was loaded successfully and has no debug information
2082 # lzma file was loaded
, .gnu_debugdata found
, but no LZMA support
2084 # fail file was not loaded
2086 # This procedure also
set the global
variable GDB_FILE_CMD_MSG to the
2087 # output of the file command in case of success.
2089 # I tried returning this information as part of the
return value
,
2090 # but ran into a mess because of the many re
-implementations of
2091 # gdb_load in config
/*.exp.
2093 # TODO
: gdb.base
/sepdebug.exp and gdb.stabs
/weird.exp might be able to use
2094 # this
if they can
get more information
set.
2096 proc gdb_file_cmd
{ arg } {
2099 global last_loaded_file
2101 # GCC
for Windows target may create foo.exe given
"-o foo".
2102 if { ![file
exists $
arg] && [file
exists "$arg.exe"] } {
2106 # Save this
for the benefit of gdbserver
-support.exp.
2107 set last_loaded_file $
arg
2109 #
Set whether debug
info was found.
2110 # Default to
"fail".
2111 global gdb_file_cmd_debug_info gdb_file_cmd_msg
2112 set gdb_file_cmd_debug_info
"fail"
2114 if [is_remote host
] {
2115 set arg [remote_download host $
arg]
2117 perror
"download failed"
2122 # The file command used to kill the remote target.
For the benefit
2123 # of the testsuite
, preserve this behavior. Mark as optional so it doesn
't
2124 # get written to the stdin log.
2125 send_gdb "kill\n" optional
2127 -re "Kill the program being debugged. .y or n. $" {
2128 send_gdb "y\n" answer
2129 verbose "\t\tKilling previous program being debugged"
2132 -re "$gdb_prompt $" {
2137 send_gdb "file $arg\n"
2138 set new_symbol_table 0
2139 set basename [file tail $arg]
2141 -re "(Reading symbols from.*LZMA support was disabled.*$gdb_prompt $)" {
2142 verbose "\t\tLoaded $arg into $GDB; .gnu_debugdata found but no LZMA available"
2143 set gdb_file_cmd_msg $expect_out(1,string)
2144 set gdb_file_cmd_debug_info "lzma"
2147 -re "(Reading symbols from.*No debugging symbols found.*$gdb_prompt $)" {
2148 verbose "\t\tLoaded $arg into $GDB with no debugging symbols"
2149 set gdb_file_cmd_msg $expect_out(1,string)
2150 set gdb_file_cmd_debug_info "nodebug"
2153 -re "(Reading symbols from.*$gdb_prompt $)" {
2154 verbose "\t\tLoaded $arg into $GDB"
2155 set gdb_file_cmd_msg $expect_out(1,string)
2156 set gdb_file_cmd_debug_info "debug"
2159 -re "Load new symbol table from \".*\".*y or n. $" {
2160 if { $new_symbol_table > 0 } {
2161 perror [join [list "Couldn't
load $basename
,"
2162 "interactive prompt loop detected."]]
2165 send_gdb
"y\n" answer
2166 incr new_symbol_table
2167 set suffix
"-- with new symbol table"
2168 set arg "$arg $suffix"
2169 set basename
"$basename $suffix"
2172 -re
"No such file or directory.*$gdb_prompt $" {
2173 perror
"($basename) No such file or directory"
2176 -re
"A problem internal to GDB has been detected" {
2177 perror
"Couldn't load $basename into GDB (GDB internal error)."
2178 gdb_internal_error_resync
2181 -re
"$gdb_prompt $" {
2182 perror
"Couldn't load $basename into GDB."
2186 perror
"Couldn't load $basename into GDB (timeout)."
2190 # This is an attempt to detect a core dump
, but seems not to
2191 # work. Perhaps we need to match .
* followed by eof
, in which
2192 # gdb_expect does not seem to have a way to
do that.
2193 perror
"Couldn't load $basename into GDB (eof)."
2199 # The expect
"spawn" function puts the tty name into the spawn_out
2200 # array
; but dejagnu doesn
't export this globally. So, we have to
2201 # wrap spawn with our own function and poke in the built-in spawn
2202 # so that we can capture this value.
2204 # If available, the TTY name is saved to the LAST_SPAWN_TTY_NAME global.
2205 # Otherwise, LAST_SPAWN_TTY_NAME is unset.
2207 proc spawn_capture_tty_name { args } {
2208 set result [uplevel builtin_spawn $args]
2209 upvar spawn_out spawn_out
2210 if { [info exists spawn_out(slave,name)] } {
2211 set ::last_spawn_tty_name $spawn_out(slave,name)
2213 # If a process is spawned as part of a pipe line (e.g. passing
2214 # -leaveopen to the spawn proc) then the spawned process is no
2215 # assigned a tty and spawn_out(slave,name) will not be set.
2216 # In that case we want to ensure that last_spawn_tty_name is
2219 # If the previous process spawned was also not assigned a tty
2220 # (e.g. multiple processed chained in a pipeline) then
2221 # last_spawn_tty_name will already be unset, so, if we don't
2222 # use
-nocomplain here we would otherwise
get an error.
2223 unset
-nocomplain
::last_spawn_tty_name
2228 rename spawn builtin_spawn
2229 rename spawn_capture_tty_name spawn
2231 # Default gdb_spawn procedure.
2233 proc default_gdb_spawn
{ } {
2236 global INTERNAL_GDBFLAGS GDBFLAGS
2239 #
Set the default value
, it may be overriden later by specific testfile.
2241 # Use `set_board_info use_gdb_stub
' for the board file to flag the inferior
2242 # is already started after connecting and run/attach are not supported.
2243 # This is used for the "remote" protocol. After GDB starts you should
2244 # check global $use_gdb_stub instead of the board as the testfile may force
2245 # a specific different target protocol itself.
2246 set use_gdb_stub [target_info exists use_gdb_stub]
2248 verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
2249 gdb_write_cmd_file "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
2251 if [info exists gdb_spawn_id] {
2255 if ![is_remote host] {
2256 if {[which $GDB] == 0} {
2257 perror "$GDB does not exist."
2262 # Put GDBFLAGS last so that tests can put "--args ..." in it.
2263 set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS [host_info gdb_opts] $GDBFLAGS"]
2264 if { $res < 0 || $res == "" } {
2265 perror "Spawning $GDB failed."
2269 set gdb_spawn_id $res
2270 set ::gdb_tty_name $::last_spawn_tty_name
2274 # Default gdb_start procedure.
2276 proc default_gdb_start { } {
2279 global inferior_spawn_id
2281 if [info exists gdb_spawn_id] {
2285 # Keep track of the number of times GDB has been launched.
2286 global gdb_instances
2296 # Default to assuming inferior I/O is done on GDB's terminal.
2297 if {![info exists inferior_spawn_id
]} {
2298 set inferior_spawn_id $gdb_spawn_id
2301 # When running over NFS
, particularly
if running many simultaneous
2302 # tests
on different hosts all using the same server
, things can
2303 #
get really slow. Give gdb at least
3 minutes to start up.
2305 -re
"\[\r\n\]$gdb_prompt $" {
2306 verbose
"GDB initialized."
2308 -re
"\[\r\n\]\033\\\[.2004h$gdb_prompt $" {
2309 # This special case detects what happens when GDB is
2310 # started with bracketed paste
mode enabled. This
mode is
2311 # usually forced
off (see setting of INPUTRC in
2312 # default_gdb_init
), but
for at least one test we turn
2313 # bracketed paste
mode back on, and
then start GDB. In
2314 # that case
, this case is hit.
2315 verbose
"GDB initialized."
2317 -re
"$gdb_prompt $" {
2318 perror
"GDB never initialized."
2323 perror
"(timeout) GDB never initialized after 10 seconds."
2329 perror
"(eof) GDB never initialized."
2335 # force the height to
"unlimited", so no pagers get used
2337 send_gdb
"set height 0\n"
2339 -re
"$gdb_prompt $" {
2340 verbose
"Setting height to 0." 2
2343 warning
"Couldn't set the height to 0"
2346 # force the width to
"unlimited", so no wraparound occurs
2347 send_gdb
"set width 0\n"
2349 -re
"$gdb_prompt $" {
2350 verbose
"Setting width to 0." 2
2353 warning
"Couldn't set the width to 0."
2361 # Utility procedure to give user control of the gdb prompt in a script. It is
2362 # meant to be used
for debugging test cases
, and should not be left in the
2365 proc gdb_interact
{ } {
2367 set spawn_id $gdb_spawn_id
2369 send_user
"+------------------------------------------+\n"
2370 send_user
"| Script interrupted, you can now interact |\n"
2371 send_user
"| with by gdb. Type >>> to continue. |\n"
2372 send_user
"+------------------------------------------+\n"
2379 # Examine the output of compilation to determine whether compilation
2380 # failed or not.
If it failed determine whether it is due to missing
2381 # compiler or due to compiler error.
Report pass
, fail or unsupported
2384 proc gdb_compile_test
{src output
} {
2385 set msg
"compilation [file tail $src]"
2387 if { $output
== "" } {
2392 if { [regexp
{^
[a
-zA
-Z_0
-9]+: Can
't find [^ ]+\.$} $output]
2393 || [regexp {.*: command not found[\r|\n]*$} $output]
2394 || [regexp {.*: [^\r\n]*compiler not installed[^\r\n]*[\r|\n]*$} $output] } {
2395 unsupported "$msg (missing compiler)"
2399 set gcc_re ".*: error: unrecognized command line option "
2400 set clang_re ".*: error: unsupported option "
2401 if { [regexp "(?:$gcc_re|$clang_re)(\[^ \t;\r\n\]*)" $output dummy option]
2402 && $option != "" } {
2403 unsupported "$msg (unsupported option $option)"
2407 # Unclassified compilation failure, be more verbose.
2408 verbose -log "compilation failed: $output" 2
2412 # Return a 1 for configurations for which we want to try to test C++.
2414 proc allow_cplus_tests {} {
2415 if { [istarget "h8300-*-*"] } {
2419 # The C++ IO streams are too large for HC11/HC12 and are thus not
2420 # available. The gdb C++ tests use them and don't
compile.
2421 if { [istarget
"m6811-*-*"] } {
2424 if { [istarget
"m6812-*-*"] } {
2430 #
Return a
0 for configurations which are missing either C
++ or the STL.
2432 proc allow_stl_tests
{} {
2433 return [allow_cplus_tests
]
2436 #
Return a
1 if I want to try to test FORTRAN.
2438 proc allow_fortran_tests
{} {
2442 #
Return a
1 if I want to try to test ada.
2444 proc allow_ada_tests
{} {
2445 if { [is_remote host
] } {
2446 # Currently gdb_ada_compile doesn
't support remote host.
2452 # Return a 1 if I want to try to test GO.
2454 proc allow_go_tests {} {
2458 # Return a 1 if I even want to try to test D.
2460 proc allow_d_tests {} {
2464 # Return 1 to try Rust tests, 0 to skip them.
2465 proc allow_rust_tests {} {
2466 if { ![isnative] } {
2470 # The rust compiler does not support "-m32", skip.
2471 global board board_info
2472 set board [target_info name]
2473 if {[board_info $board exists multilib_flags]} {
2474 foreach flag [board_info $board multilib_flags] {
2475 if { $flag == "-m32" } {
2484 # Return a 1 for configurations that support Python scripting.
2486 gdb_caching_proc allow_python_tests {} {
2487 set output [remote_exec host $::GDB "$::INTERNAL_GDBFLAGS --configuration"]
2488 return [expr {[string first "--with-python" $output] != -1}]
2491 # Return a 1 if we should run shared library tests.
2493 proc allow_shlib_tests {} {
2494 # Run the shared library tests on native systems.
2499 # An abbreviated list of remote targets where we should be able to
2500 # run shared library tests.
2501 if {([istarget *-*-linux*]
2502 || [istarget *-*-*bsd*]
2503 || [istarget *-*-solaris2*]
2504 || [istarget *-*-mingw*]
2505 || [istarget *-*-cygwin*]
2506 || [istarget *-*-pe*])} {
2513 # Return 1 if we should run dlmopen tests, 0 if we should not.
2515 gdb_caching_proc allow_dlmopen_tests {} {
2516 global srcdir subdir gdb_prompt inferior_exited_re
2518 # We need shared library support.
2519 if { ![allow_shlib_tests] } {
2523 set me "allow_dlmopen_tests"
2537 struct r_debug *r_debug;
2541 /* The version is kept at 1 until we create a new namespace. */
2542 handle = dlmopen (LM_ID_NEWLM, DSO_NAME, RTLD_LAZY | RTLD_LOCAL);
2544 printf ("dlmopen failed: %s.\n", dlerror ());
2549 /* Taken from /usr/include/link.h. */
2550 for (dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn)
2551 if (dyn->d_tag == DT_DEBUG)
2552 r_debug = (struct r_debug *) dyn->d_un.d_ptr;
2555 printf ("r_debug not found.\n");
2558 if (r_debug->r_version < 2) {
2559 printf ("dlmopen debug not supported.\n");
2562 printf ("dlmopen debug supported.\n");
2567 set libsrc [standard_temp_file "libfoo.c"]
2568 set libout [standard_temp_file "libfoo.so"]
2569 gdb_produce_source $libsrc $lib
2571 if { [gdb_compile_shlib $libsrc $libout {debug}] != "" } {
2572 verbose -log "failed to build library"
2575 if { ![gdb_simple_compile $me $src executable \
2576 [list shlib_load debug \
2577 additional_flags=-DDSO_NAME=\"$libout\"]] } {
2578 verbose -log "failed to build executable"
2584 gdb_reinitialize_dir $srcdir/$subdir
2587 if { [gdb_run_cmd] != 0 } {
2588 verbose -log "failed to start skip test"
2592 -re "$inferior_exited_re normally.*${gdb_prompt} $" {
2593 set allow_dlmopen_tests 1
2595 -re "$inferior_exited_re with code.*${gdb_prompt} $" {
2596 set allow_dlmopen_tests 0
2599 warning "\n$me: default case taken"
2600 set allow_dlmopen_tests 0
2605 verbose "$me: returning $allow_dlmopen_tests" 2
2606 return $allow_dlmopen_tests
2609 # Return 1 if we should allow TUI-related tests.
2611 gdb_caching_proc allow_tui_tests {} {
2612 set output [remote_exec host $::GDB "$::INTERNAL_GDBFLAGS --configuration"]
2613 return [expr {[string first "--enable-tui" $output] != -1}]
2616 # Test files shall make sure all the test result lines in gdb.sum are
2617 # unique in a test run, so that comparing the gdb.sum files of two
2618 # test runs gives correct results. Test files that exercise
2619 # variations of the same tests more than once, shall prefix the
2620 # different test invocations with different identifying strings in
2621 # order to make them unique.
2623 # About test prefixes:
2625 # $pf_prefix is the string that dejagnu prints after the result (FAIL,
2626 # PASS, etc.), and before the test message/name in gdb.sum. E.g., the
2627 # underlined substring in
2629 # PASS: gdb.base/mytest.exp: some test
2630 # ^^^^^^^^^^^^^^^^^^^^
2634 # The easiest way to adjust the test prefix is to append a test
2635 # variation prefix to the $pf_prefix, using the with_test_prefix
2638 # proc do_tests {} {
2639 # gdb_test ... ... "test foo"
2640 # gdb_test ... ... "test bar"
2642 # with_test_prefix "subvariation a" {
2643 # gdb_test ... ... "test x"
2646 # with_test_prefix "subvariation b" {
2647 # gdb_test ... ... "test x"
2651 # with_test_prefix "variation1" {
2652 # ...do setup for variation 1...
2656 # with_test_prefix "variation2" {
2657 # ...do setup for variation 2...
2663 # PASS: gdb.base/mytest.exp: variation1: test foo
2664 # PASS: gdb.base/mytest.exp: variation1: test bar
2665 # PASS: gdb.base/mytest.exp: variation1: subvariation a: test x
2666 # PASS: gdb.base/mytest.exp: variation1: subvariation b: test x
2667 # PASS: gdb.base/mytest.exp: variation2: test foo
2668 # PASS: gdb.base/mytest.exp: variation2: test bar
2669 # PASS: gdb.base/mytest.exp: variation2: subvariation a: test x
2670 # PASS: gdb.base/mytest.exp: variation2: subvariation b: test x
2672 # If for some reason more flexibility is necessary, one can also
2673 # manipulate the pf_prefix global directly, treating it as a string.
2677 # set saved_pf_prefix
2678 # append pf_prefix "${foo}: bar"
2679 # ... actual tests ...
2680 # set pf_prefix $saved_pf_prefix
2683 # Run BODY in the context of the caller, with the current test prefix
2684 # (pf_prefix) appended with one space, then PREFIX, and then a colon.
2685 # Returns the result of BODY.
2687 proc with_test_prefix { prefix body } {
2690 set saved $pf_prefix
2691 append pf_prefix " " $prefix ":"
2692 set code [catch {uplevel 1 $body} result]
2693 set pf_prefix $saved
2696 global errorInfo errorCode
2697 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2699 return -code $code $result
2703 # Wrapper for foreach that calls with_test_prefix on each iteration,
2704 # including the iterator's
name and current value in the prefix.
2706 proc foreach_with_prefix
{var list body
} {
2708 foreach myvar $list
{
2709 with_test_prefix
"$var=$myvar" {
2710 set code
[catch
{uplevel
1 $body
} result
]
2714 global errorInfo errorCode
2715 return -code $code
-errorinfo $errorInfo
-errorcode $errorCode $result
2716 } elseif
{$code
== 3} {
2718 } elseif
{$code
== 2} {
2719 return -code $code $result
2724 # Like TCL
's native proc, but defines a procedure that wraps its body
2725 # within 'with_test_prefix
"$proc_name" { ... }'.
2726 proc proc_with_prefix
{name arguments body
} {
2727 #
Define the advertised proc.
2728 proc $
name $arguments
[list with_test_prefix $
name $body
]
2731 #
Return an id corresponding to the test prefix stored in $pf_prefix
, which
2732 # is more suitable
for use in a file
name.
2733 # F.i.
, for a pf_prefix
:
2734 # gdb.dwarf2
/dw2
-lines.exp
: \
2735 # cv
=5: cdw
=64: lv
=5: ldw
=64: string_form
=line_strp
:
2737 # cv
-5-cdw
-32-lv
-5-ldw
-64-string_form
-line_strp
2743 #
Strip ".exp: " prefix.
2744 set id
[regsub
{.
*\.exp
: } $id
{}]
2746 #
Strip colon suffix.
2747 set id
[regsub
{:$
} $id
{}]
2750 set id
[regsub
-all
{ } $id
{}]
2752 # Replace colons
, equal signs.
2753 set id
[regsub
-all \
[:=\
] $id
-]
2758 # Run BODY in the
context of the caller. After BODY is run
, the variables
2759 # listed in VARS will be reset to the
values they had before BODY was run.
2761 # This is useful
for providing a scope in which it is safe to temporarily
2762 # modify global variables
, e.g.
2764 # global INTERNAL_GDBFLAGS
2767 #
set foo GDBHISTSIZE
2769 # save_vars
{ INTERNAL_GDBFLAGS env
($foo
) env
(HOME
) } {
2770 # append INTERNAL_GDBFLAGS
" -nx"
2771 # unset
-nocomplain env
(GDBHISTSIZE
)
2776 # Here
, although INTERNAL_GDBFLAGS
, env
(GDBHISTSIZE
) and env
(HOME
) may be
2777 # modified inside BODY
, this proc guarantees that the modifications will be
2778 # undone after BODY finishes executing.
2780 proc save_vars
{ vars body
} {
2781 array
set saved_scalars
{ }
2782 array
set saved_arrays
{ }
2786 # First evaluate VAR in the
context of the caller in case the
variable
2787 #
name may be a not
-yet
-interpolated string like env
($foo
)
2788 set var
[uplevel
1 list $var
]
2790 if [uplevel
1 [list
info exists $var
]] {
2791 if [uplevel
1 [list array
exists $var
]] {
2792 set saved_arrays
($var
) [uplevel
1 [list array
get $var
]]
2794 set saved_scalars
($var
) [uplevel
1 [list
set $var
]]
2797 lappend unset_vars $var
2801 set code
[catch
{uplevel
1 $body
} result
]
2803 foreach
{var value
} [array
get saved_scalars
] {
2804 uplevel
1 [list
set $var $value
]
2807 foreach
{var value
} [array
get saved_arrays
] {
2808 uplevel
1 [list unset $var
]
2809 uplevel
1 [list array
set $var $value
]
2812 foreach var $unset_vars
{
2813 uplevel
1 [list unset
-nocomplain $var
]
2817 global errorInfo errorCode
2818 return -code $code
-errorinfo $errorInfo
-errorcode $errorCode $result
2820 return -code $code $result
2824 # As save_vars
, but
for variables stored in the board_info
for the
2829 # save_target_board_info
{ multilib_flags
} {
2831 #
set board
[target_info
name]
2832 # unset_board_info multilib_flags
2833 # set_board_info multilib_flags
"$multilib_flags"
2837 proc save_target_board_info
{ vars body
} {
2838 global board board_info
2839 set board
[target_info
name]
2841 array
set saved_target_board_info
{ }
2842 set unset_target_board_info
{ }
2845 if { [info exists board_info
($board
,$var
)] } {
2846 set saved_target_board_info
($var
) [board_info $board $var
]
2848 lappend unset_target_board_info $var
2852 set code
[catch
{uplevel
1 $body
} result
]
2854 foreach
{var value
} [array
get saved_target_board_info
] {
2855 unset_board_info $var
2856 set_board_info $var $value
2859 foreach var $unset_target_board_info
{
2860 unset_board_info $var
2864 global errorInfo errorCode
2865 return -code $code
-errorinfo $errorInfo
-errorcode $errorCode $result
2867 return -code $code $result
2871 # Run tests in BODY with the current working directory
(CWD
) set to
2872 #
DIR. When BODY is finished
, restore the original CWD.
Return the
2875 # This procedure doesn
't check if DIR is a valid directory, so you
2876 # have to make sure of that.
2878 proc with_cwd { dir body } {
2880 verbose -log "Switching to directory $dir (saved CWD: $saved_dir)."
2883 set code [catch {uplevel 1 $body} result]
2885 verbose -log "Switching back to $saved_dir."
2889 global errorInfo errorCode
2890 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2892 return -code $code $result
2896 # Use GDB's
'cd' command to
switch to
DIR.
Return true
if the
switch
2897 # was successful
, otherwise
, call perror and
return false.
2899 proc gdb_cd
{ dir } {
2901 gdb_test_multiple
"cd $dir" "" {
2902 -re
"^cd \[^\r\n\]+\r\n" {
2906 -re
"^Working directory (\[^\r\n\]+)\\.\r\n" {
2907 set new_dir $expect_out
(1,string
)
2911 -re
"^$::gdb_prompt $" {
2912 if { $new_dir
== "" || $new_dir != $dir } {
2913 perror
"failed to switch to $dir"
2922 # Use GDB
's 'pwd
' command to figure out the current working directory.
2923 # Return the directory as a string. If we can't figure out the
2924 # current working directory
, then call perror
, and
return the empty
2929 gdb_test_multiple
"pwd" "" {
2934 -re
"^Working directory (\[^\r\n\]+)\\.\r\n" {
2935 set dir $expect_out
(1,string
)
2939 -re
"^$::gdb_prompt $" {
2944 perror
"failed to read GDB's current working directory"
2950 # Similar to the with_cwd proc
, this proc runs BODY with the current
2951 # working directory changed to CWD.
2953 # Unlike with_cwd
, the directory change here is done within GDB
2954 # itself
, so GDB must be running before this proc is called.
2956 proc with_gdb_cwd
{ dir body
} {
2957 set saved_dir
[gdb_pwd
]
2958 if { $saved_dir
== "" } {
2962 verbose
-log "Switching to directory $dir (saved CWD: $saved_dir)."
2967 set code
[catch
{uplevel
1 $body
} result
]
2969 verbose
-log "Switching back to $saved_dir."
2970 if ![gdb_cd $saved_dir
] {
2974 # Check that GDB is still alive.
If GDB crashed in the above code
2975 #
then any corefile will have been left in
DIR, not the root
2976 # testsuite directory. As a result the corefile will not be
2977 # brought to the users attention. Instead
, if GDB crashed
, then
2978 # this check should cause a FAIL
, which should be enough to alert
2980 set saw_result false
2981 gdb_test_multiple
"p 123" "" {
2986 -re
"^\\\$$::decimal = 123\r\n" {
2991 -re
"^$::gdb_prompt $" {
2992 if { !$saw_result
} {
2993 fail
"check gdb is alive in with_gdb_cwd"
2999 global errorInfo errorCode
3000 return -code $code
-errorinfo $errorInfo
-errorcode $errorCode $result
3002 return -code $code $result
3006 # Run tests in BODY with GDB prompt and
variable $gdb_prompt
set to
3007 # PROMPT. When BODY is finished
, restore GDB prompt and
variable
3009 # Returns the result of BODY.
3013 #
1) If you want to use
, for example
, "(foo)" as the prompt you must pass it
3014 # as
"(foo)", and not the regexp form "\(foo\)" (expressed as "\\(foo\\)" in
3015 # TCL
). PROMPT is internally converted to a suitable regexp
for matching.
3016 # We
do the conversion from
"(foo)" to "\(foo\)" here for a few reasons:
3017 # a
) It
's more intuitive for callers to pass the plain text form.
3018 # b) We need two forms of the prompt:
3019 # - a regexp to use in output matching,
3020 # - a value to pass to the "set prompt" command.
3021 # c) It's easier to
convert the plain
text form to its regexp form.
3023 #
2) Don
't add a trailing space, we do that here.
3025 proc with_gdb_prompt { prompt body } {
3028 # Convert "(foo)" to "\(foo\)".
3029 # We don't use string_to_regexp because
while it works
today it
's not
3030 # clear it will work tomorrow: the value we need must work as both a
3031 # regexp *and* as the argument to the "set prompt" command, at least until
3032 # we start recording both forms separately instead of just $gdb_prompt.
3033 # The testsuite is pretty-much hardwired to interpret $gdb_prompt as the
3035 regsub -all {[]*+.|()^$\[\\]} $prompt {\\&} prompt
3037 set saved $gdb_prompt
3039 verbose -log "Setting gdb prompt to \"$prompt \"."
3040 set gdb_prompt $prompt
3041 gdb_test_no_output "set prompt $prompt " ""
3043 set code [catch {uplevel 1 $body} result]
3045 verbose -log "Restoring gdb prompt to \"$saved \"."
3046 set gdb_prompt $saved
3047 gdb_test_no_output "set prompt $saved " ""
3050 global errorInfo errorCode
3051 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
3053 return -code $code $result
3057 # Run tests in BODY with target-charset setting to TARGET_CHARSET. When
3058 # BODY is finished, restore target-charset.
3060 proc with_target_charset { target_charset body } {
3064 gdb_test_multiple "show target-charset" "" {
3065 -re "The target character set is \".*; currently (.*)\"\..*$gdb_prompt " {
3066 set saved $expect_out(1,string)
3068 -re "The target character set is \"(.*)\".*$gdb_prompt " {
3069 set saved $expect_out(1,string)
3071 -re ".*$gdb_prompt " {
3072 fail "get target-charset"
3076 gdb_test_no_output -nopass "set target-charset $target_charset"
3078 set code [catch {uplevel 1 $body} result]
3080 gdb_test_no_output -nopass "set target-charset $saved"
3083 global errorInfo errorCode
3084 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
3086 return -code $code $result
3090 # Switch the default spawn id to SPAWN_ID, so that gdb_test,
3091 # mi_gdb_test etc. default to using it.
3093 proc switch_gdb_spawn_id {spawn_id} {
3095 global board board_info
3097 set gdb_spawn_id $spawn_id
3098 set board [host_info name]
3099 set board_info($board,fileid) $spawn_id
3102 # Clear the default spawn id.
3104 proc clear_gdb_spawn_id {} {
3106 global board board_info
3108 unset -nocomplain gdb_spawn_id
3109 set board [host_info name]
3110 unset -nocomplain board_info($board,fileid)
3113 # Run BODY with SPAWN_ID as current spawn id.
3115 proc with_spawn_id { spawn_id body } {
3118 if [info exists gdb_spawn_id] {
3119 set saved_spawn_id $gdb_spawn_id
3122 switch_gdb_spawn_id $spawn_id
3124 set code [catch {uplevel 1 $body} result]
3126 if [info exists saved_spawn_id] {
3127 switch_gdb_spawn_id $saved_spawn_id
3133 global errorInfo errorCode
3134 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
3136 return -code $code $result
3140 # Select the largest timeout from all the timeouts:
3141 # - the local "timeout" variable of the scope two levels above,
3142 # - the global "timeout" variable,
3143 # - the board variable "gdb,timeout".
3145 proc get_largest_timeout {} {
3146 upvar #0 timeout gtimeout
3147 upvar 2 timeout timeout
3150 if [info exists timeout] {
3153 if { [info exists gtimeout] && $gtimeout > $tmt } {
3156 if { [target_info exists gdb,timeout]
3157 && [target_info gdb,timeout] > $tmt } {
3158 set tmt [target_info gdb,timeout]
3168 # Run tests in BODY with timeout increased by factor of FACTOR. When
3169 # BODY is finished, restore timeout.
3171 proc with_timeout_factor { factor body } {
3174 set savedtimeout $timeout
3176 set timeout [expr [get_largest_timeout] * $factor]
3177 set code [catch {uplevel 1 $body} result]
3179 set timeout $savedtimeout
3181 global errorInfo errorCode
3182 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
3184 return -code $code $result
3188 # Run BODY with timeout factor FACTOR if check-read1 is used.
3190 proc with_read1_timeout_factor { factor body } {
3191 if { [info exists ::env(READ1)] == 1 && $::env(READ1) == 1 } {
3192 # Use timeout factor
3194 # Reset timeout factor
3197 return [uplevel [list with_timeout_factor $factor $body]]
3200 # Return 1 if _Complex types are supported, otherwise, return 0.
3202 gdb_caching_proc support_complex_tests {} {
3204 if { ![allow_float_test] } {
3205 # If floating point is not supported, _Complex is not
3210 # Compile a test program containing _Complex types.
3212 return [gdb_can_simple_compile complex {
3216 _Complex long double cld;
3222 # Return 1 if compiling go is supported.
3223 gdb_caching_proc support_go_compile {} {
3225 return [gdb_can_simple_compile go-hello {
3229 fmt.Println("hello world")
3234 # Return 1 if GDB can get a type for siginfo from the target, otherwise
3237 proc supports_get_siginfo_type {} {
3238 if { [istarget "*-*-linux*"] } {
3245 # Return 1 if memory tagging is supported at runtime, otherwise return 0.
3247 gdb_caching_proc supports_memtag {} {
3250 gdb_test_multiple "memory-tag check" "" {
3251 -re "Memory tagging not supported or disabled by the current architecture\..*$gdb_prompt $" {
3254 -re "Argument required \\(address or pointer\\).*$gdb_prompt $" {
3261 # Return 1 if the target supports hardware single stepping.
3263 proc can_hardware_single_step {} {
3265 if { [istarget "arm*-*-*"] || [istarget "mips*-*-*"]
3266 || [istarget "tic6x-*-*"] || [istarget "sparc*-*-linux*"]
3267 || [istarget "nios2-*-*"] || [istarget "riscv*-*-linux*"] } {
3274 # Return 1 if target hardware or OS supports single stepping to signal
3275 # handler, otherwise, return 0.
3277 proc can_single_step_to_signal_handler {} {
3278 # Targets don't have hardware single step.
On these targets
, when
3279 # a
signal is delivered during software single step
, gdb is unable
3280 # to determine the next instruction addresses
, because start of
signal
3281 # handler is one of them.
3282 return [can_hardware_single_step
]
3285 #
Return 1 if target supports process record
, otherwise
return 0.
3287 proc supports_process_record
{} {
3289 if [target_info
exists gdb
,use_precord
] {
3290 return [target_info gdb
,use_precord
]
3293 if { [istarget
"arm*-*-linux*"] || [istarget "x86_64-*-linux*"]
3294 ||
[istarget
"i\[34567\]86-*-linux*"]
3295 ||
[istarget
"aarch64*-*-linux*"]
3296 ||
[istarget
"powerpc*-*-linux*"]
3297 ||
[istarget
"s390*-*-linux*"] } {
3304 #
Return 1 if target supports reverse debugging
, otherwise
return 0.
3306 proc supports_reverse
{} {
3308 if [target_info
exists gdb
,can_reverse
] {
3309 return [target_info gdb
,can_reverse
]
3312 if { [istarget
"arm*-*-linux*"] || [istarget "x86_64-*-linux*"]
3313 ||
[istarget
"i\[34567\]86-*-linux*"]
3314 ||
[istarget
"aarch64*-*-linux*"]
3315 ||
[istarget
"powerpc*-*-linux*"]
3316 ||
[istarget
"s390*-*-linux*"] } {
3323 #
Return 1 if readline library is used.
3325 proc readline_is_used
{ } {
3328 gdb_test_multiple
"show editing" "" {
3329 -re
".*Editing of command lines as they are typed is on\..*$gdb_prompt $" {
3332 -re
".*$gdb_prompt $" {
3338 #
Return 1 if target is ELF.
3339 gdb_caching_proc is_elf_target
{} {
3340 set me
"is_elf_target"
3342 set src
{ int foo
() {return 0;} }
3343 if {![gdb_simple_compile elf_target $src
]} {
3347 set fp_obj
[open $
obj "r"]
3348 fconfigure $fp_obj
-translation binary
3349 set data
[read $fp_obj
]
3354 set ELFMAG
"\u007FELF"
3356 if {[string compare
-length
4 $data $ELFMAG
] != 0} {
3357 verbose
"$me: returning 0" 2
3361 verbose
"$me: returning 1" 2
3365 #
Return 1 if the memory at address zero is readable.
3367 gdb_caching_proc is_address_zero_readable
{} {
3371 gdb_test_multiple
"x 0" "" {
3372 -re
"Cannot access memory at address 0x0.*$gdb_prompt $" {
3375 -re
".*$gdb_prompt $" {
3383 # Produce source file
NAME and write SOURCES into it.
3385 proc gdb_produce_source
{ name sources
} {
3387 set f
[open $
name "w"]
3393 #
Return 1 if target is ILP32.
3394 # This cannot be decided simply from looking at the target string
,
3395 # as it might depend
on externally passed compiler options like
-m64.
3396 gdb_caching_proc is_ilp32_target
{} {
3397 return [gdb_can_simple_compile is_ilp32_target
{
3398 int dummy
[sizeof
(int) == 4
3399 && sizeof
(void
*) == 4
3400 && sizeof
(long
) == 4 ?
1 : -1];
3404 #
Return 1 if target is LP64.
3405 # This cannot be decided simply from looking at the target string
,
3406 # as it might depend
on externally passed compiler options like
-m64.
3407 gdb_caching_proc is_lp64_target
{} {
3408 return [gdb_can_simple_compile is_lp64_target
{
3409 int dummy
[sizeof
(int) == 4
3410 && sizeof
(void
*) == 8
3411 && sizeof
(long
) == 8 ?
1 : -1];
3415 #
Return 1 if target has
64 bit addresses.
3416 # This cannot be decided simply from looking at the target string
,
3417 # as it might depend
on externally passed compiler options like
-m64.
3418 gdb_caching_proc is_64_target
{} {
3419 return [gdb_can_simple_compile is_64_target
{
3420 int function
(void
) { return 3; }
3421 int dummy
[sizeof
(&function
) == 8 ?
1 : -1];
3425 #
Return 1 if target has x86_64 registers
- either amd64 or x32.
3426 # x32 target identifies as x86_64
-*-linux
*, therefore it cannot be determined
3427 # just from the target string.
3428 gdb_caching_proc is_amd64_regs_target
{} {
3429 if {![istarget
"x86_64-*-*"] && ![istarget "i?86-*"]} {
3433 return [gdb_can_simple_compile is_amd64_regs_target
{
3443 #
Return 1 if this target is an x86 or x86
-64 with
-m32.
3444 proc is_x86_like_target
{} {
3445 if {![istarget
"x86_64-*-*"] && ![istarget i?86-*]} {
3448 return [expr
[is_ilp32_target
] && ![is_amd64_regs_target
]]
3451 #
Return 1 if this target is an x86_64 with
-m64.
3452 proc is_x86_64_m64_target
{} {
3453 return [expr
[istarget x86_64
-*-* ] && [is_lp64_target
]]
3456 #
Return 1 if this target is an arm or aarch32
on aarch64.
3458 gdb_caching_proc is_aarch32_target
{} {
3459 if { [istarget
"arm*-*-*"] } {
3463 if { ![istarget
"aarch64*-*-*"] } {
3470 lappend list
"\tmov $reg, $reg"
3473 return [gdb_can_simple_compile aarch32
[join $list
\n]]
3476 #
Return 1 if this target is an aarch64
, either lp64 or ilp32.
3478 proc is_aarch64_target
{} {
3479 if { ![istarget
"aarch64*-*-*"] } {
3483 return [expr
![is_aarch32_target
]]
3486 #
Return 1 if displaced stepping is supported
on target
, otherwise
, return 0.
3487 proc support_displaced_stepping
{} {
3489 if { [istarget
"x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"]
3490 ||
[istarget
"arm*-*-linux*"] || [istarget "powerpc-*-linux*"]
3491 ||
[istarget
"powerpc64-*-linux*"] || [istarget "s390*-*-*"]
3492 ||
[istarget
"aarch64*-*-linux*"] || [istarget "loongarch*-*-linux*"] } {
3499 # Run a test
on the target to see
if it supports vmx hardware.
Return 1 if so
,
3500 #
0 if it does not. Based
on 'check_vmx_hw_available' from the GCC testsuite.
3502 gdb_caching_proc allow_altivec_tests
{} {
3503 global srcdir subdir gdb_prompt inferior_exited_re
3505 set me
"allow_altivec_tests"
3507 # Some simulators are known to not support VMX instructions.
3508 if { [istarget powerpc
-*-eabi
] ||
[istarget powerpc
*-*-eabispe
] } {
3509 verbose
"$me: target known to not support VMX, returning 0" 2
3513 if {![istarget powerpc
*]} {
3514 verbose
"$me: PPC target required, returning 0" 2
3518 # Make sure we have a compiler that understands altivec.
3519 if [test_compiler_info gcc
*] {
3520 set compile_flags
"additional_flags=-maltivec"
3521 } elseif
[test_compiler_info xlc
*] {
3522 set compile_flags
"additional_flags=-qaltivec"
3524 verbose
"Could not compile with altivec support, returning 0" 2
3528 #
Compile a test
program containing VMX instructions.
3532 asm volatile
("vor v0,v0,v0");
3534 asm volatile
("vor 0,0,0");
3539 if {![gdb_simple_compile $me $src executable $compile_flags
]} {
3543 # Compilation succeeded so now run it via gdb.
3547 gdb_reinitialize_dir $srcdir
/$subdir
3551 -re
".*Illegal instruction.*${gdb_prompt} $" {
3552 verbose
-log "\n$me altivec hardware not detected"
3553 set allow_vmx_tests
0
3555 -re
".*$inferior_exited_re normally.*${gdb_prompt} $" {
3556 verbose
-log "\n$me: altivec hardware detected"
3557 set allow_vmx_tests
1
3560 warning
"\n$me: default case taken"
3561 set allow_vmx_tests
0
3565 remote_file build
delete $
obj
3567 verbose
"$me: returning $allow_vmx_tests" 2
3568 return $allow_vmx_tests
3571 # Run a test
on the power target to see
if it supports ISA
3.1 instructions
3572 gdb_caching_proc allow_power_isa_3_1_tests
{} {
3573 global srcdir subdir gdb_prompt inferior_exited_re
3575 set me
"allow_power_isa_3_1_tests"
3577 #
Compile a test
program containing ISA
3.1 instructions.
3580 asm volatile
("pnop"); // marker
3581 asm volatile
("nop");
3586 if {![gdb_simple_compile $me $src executable
]} {
3590 # No error message
, compilation succeeded so now run it via gdb.
3594 gdb_reinitialize_dir $srcdir
/$subdir
3598 -re
".*Illegal instruction.*${gdb_prompt} $" {
3599 verbose
-log "\n$me Power ISA 3.1 hardware not detected"
3600 set allow_power_isa_3_1_tests
0
3602 -re
".*$inferior_exited_re normally.*${gdb_prompt} $" {
3603 verbose
-log "\n$me: Power ISA 3.1 hardware detected"
3604 set allow_power_isa_3_1_tests
1
3607 warning
"\n$me: default case taken"
3608 set allow_power_isa_3_1_tests
0
3612 remote_file build
delete $
obj
3614 verbose
"$me: returning $allow_power_isa_3_1_tests" 2
3615 return $allow_power_isa_3_1_tests
3618 # Run a test
on the target to see
if it supports vmx hardware.
Return 1 if so
,
3619 #
0 if it does not. Based
on 'check_vmx_hw_available' from the GCC testsuite.
3621 gdb_caching_proc allow_vsx_tests
{} {
3622 global srcdir subdir gdb_prompt inferior_exited_re
3624 set me
"allow_vsx_tests"
3626 # Some simulators are known to not support Altivec instructions
, so
3627 # they won
't support VSX instructions as well.
3628 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
3629 verbose "$me: target known to not support VSX, returning 0" 2
3633 # Make sure we have a compiler that understands altivec.
3634 if [test_compiler_info gcc*] {
3635 set compile_flags "additional_flags=-mvsx"
3636 } elseif [test_compiler_info xlc*] {
3637 set compile_flags "additional_flags=-qasm=gcc"
3639 verbose "Could not compile with vsx support, returning 0" 2
3643 # Compile a test program containing VSX instructions.
3646 double a[2] = { 1.0, 2.0 };
3648 asm volatile ("lxvd2x v0,v0,%[addr]" : : [addr] "r" (a));
3650 asm volatile ("lxvd2x 0,0,%[addr]" : : [addr] "r" (a));
3655 if {![gdb_simple_compile $me $src executable $compile_flags]} {
3659 # No error message, compilation succeeded so now run it via gdb.
3663 gdb_reinitialize_dir $srcdir/$subdir
3667 -re ".*Illegal instruction.*${gdb_prompt} $" {
3668 verbose -log "\n$me VSX hardware not detected"
3669 set allow_vsx_tests 0
3671 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
3672 verbose -log "\n$me: VSX hardware detected"
3673 set allow_vsx_tests 1
3676 warning "\n$me: default case taken"
3677 set allow_vsx_tests 0
3681 remote_file build delete $obj
3683 verbose "$me: returning $allow_vsx_tests" 2
3684 return $allow_vsx_tests
3687 # Run a test on the target to see if it supports TSX hardware. Return 1 if so,
3688 # 0 if it does not. Based on 'check_vmx_hw_available
' from the GCC testsuite.
3690 gdb_caching_proc allow_tsx_tests {} {
3691 global srcdir subdir gdb_prompt inferior_exited_re
3693 set me "allow_tsx_tests"
3695 # Compile a test program.
3698 asm volatile ("xbegin .L0");
3699 asm volatile ("xend");
3700 asm volatile (".L0: nop");
3704 if {![gdb_simple_compile $me $src executable]} {
3708 # No error message, compilation succeeded so now run it via gdb.
3712 gdb_reinitialize_dir $srcdir/$subdir
3716 -re ".*Illegal instruction.*${gdb_prompt} $" {
3717 verbose -log "$me: TSX hardware not detected."
3718 set allow_tsx_tests 0
3720 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
3721 verbose -log "$me: TSX hardware detected."
3722 set allow_tsx_tests 1
3725 warning "\n$me: default case taken."
3726 set allow_tsx_tests 0
3730 remote_file build delete $obj
3732 verbose "$me: returning $allow_tsx_tests" 2
3733 return $allow_tsx_tests
3736 # Run a test on the target to see if it supports avx512bf16. Return 1 if so,
3737 # 0 if it does not. Based on 'check_vmx_hw_available
' from the GCC testsuite.
3739 gdb_caching_proc allow_avx512bf16_tests {} {
3740 global srcdir subdir gdb_prompt inferior_exited_re
3742 set me "allow_avx512bf16_tests"
3743 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
3744 verbose "$me: target does not support avx512bf16, returning 0" 2
3748 # Compile a test program.
3751 asm volatile ("vcvtne2ps2bf16 %xmm0, %xmm1, %xmm0");
3755 if {![gdb_simple_compile $me $src executable]} {
3759 # No error message, compilation succeeded so now run it via gdb.
3763 gdb_reinitialize_dir $srcdir/$subdir
3767 -re ".*Illegal instruction.*${gdb_prompt} $" {
3768 verbose -log "$me: avx512bf16 hardware not detected."
3769 set allow_avx512bf16_tests 0
3771 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
3772 verbose -log "$me: avx512bf16 hardware detected."
3773 set allow_avx512bf16_tests 1
3776 warning "\n$me: default case taken."
3777 set allow_avx512bf16_tests 0
3781 remote_file build delete $obj
3783 verbose "$me: returning $allow_avx512bf16_tests" 2
3784 return $allow_avx512bf16_tests
3787 # Run a test on the target to see if it supports avx512fp16. Return 1 if so,
3788 # 0 if it does not. Based on 'check_vmx_hw_available
' from the GCC testsuite.
3790 gdb_caching_proc allow_avx512fp16_tests {} {
3791 global srcdir subdir gdb_prompt inferior_exited_re
3793 set me "allow_avx512fp16_tests"
3794 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
3795 verbose "$me: target does not support avx512fp16, returning 0" 2
3799 # Compile a test program.
3802 asm volatile ("vcvtps2phx %xmm1, %xmm0");
3806 if {![gdb_simple_compile $me $src executable]} {
3810 # No error message, compilation succeeded so now run it via gdb.
3814 gdb_reinitialize_dir $srcdir/$subdir
3818 -re ".*Illegal instruction.*${gdb_prompt} $" {
3819 verbose -log "$me: avx512fp16 hardware not detected."
3820 set allow_avx512fp16_tests 0
3822 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
3823 verbose -log "$me: avx512fp16 hardware detected."
3824 set allow_avx512fp16_tests 1
3827 warning "\n$me: default case taken."
3828 set allow_avx512fp16_tests 0
3832 remote_file build delete $obj
3834 verbose "$me: returning $allow_avx512fp16_tests" 2
3835 return $allow_avx512fp16_tests
3838 # Run a test on the target to see if it supports btrace hardware. Return 1 if so,
3839 # 0 if it does not. Based on 'check_vmx_hw_available
' from the GCC testsuite.
3841 gdb_caching_proc allow_btrace_tests {} {
3842 global srcdir subdir gdb_prompt inferior_exited_re
3844 set me "allow_btrace_tests"
3845 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
3846 verbose "$me: target does not support btrace, returning 0" 2
3850 # Compile a test program.
3851 set src { int main() { return 0; } }
3852 if {![gdb_simple_compile $me $src executable]} {
3856 # No error message, compilation succeeded so now run it via gdb.
3860 gdb_reinitialize_dir $srcdir/$subdir
3865 # In case of an unexpected output, we return 2 as a fail value.
3866 set allow_btrace_tests 2
3867 gdb_test_multiple "record btrace" "check btrace support" {
3868 -re "You can't
do that when your target is.
*\r\n$gdb_prompt $
" {
3869 set allow_btrace_tests
0
3871 -re
"Target does not support branch tracing.*\r\n$gdb_prompt $" {
3872 set allow_btrace_tests
0
3874 -re
"Could not enable branch tracing.*\r\n$gdb_prompt $" {
3875 set allow_btrace_tests
0
3877 -re
"^record btrace\r\n$gdb_prompt $" {
3878 set allow_btrace_tests
1
3882 remote_file build
delete $
obj
3884 verbose
"$me: returning $allow_btrace_tests" 2
3885 return $allow_btrace_tests
3888 # Run a test
on the target to see
if it supports btrace pt hardware.
3889 #
Return 1 if so
, 0 if it does not. Based
on 'check_vmx_hw_available'
3890 # from the GCC testsuite.
3892 gdb_caching_proc allow_btrace_pt_tests
{} {
3893 global srcdir subdir gdb_prompt inferior_exited_re
3895 set me
"allow_btrace_pt_tests"
3896 if { ![istarget
"i?86-*-*"] && ![istarget "x86_64-*-*"] } {
3897 verbose
"$me: target does not support btrace, returning 1" 2
3901 #
Compile a test
program.
3902 set src
{ int main
() { return 0; } }
3903 if {![gdb_simple_compile $me $src executable
]} {
3907 # No error message
, compilation succeeded so now run it via gdb.
3911 gdb_reinitialize_dir $srcdir
/$subdir
3916 # In case of an unexpected output
, we
return 2 as a fail value.
3917 set allow_btrace_pt_tests
2
3918 gdb_test_multiple
"record btrace pt" "check btrace pt support" {
3919 -re
"You can't do that when your target is.*\r\n$gdb_prompt $" {
3920 set allow_btrace_pt_tests
0
3922 -re
"Target does not support branch tracing.*\r\n$gdb_prompt $" {
3923 set allow_btrace_pt_tests
0
3925 -re
"Could not enable branch tracing.*\r\n$gdb_prompt $" {
3926 set allow_btrace_pt_tests
0
3928 -re
"support was disabled at compile time.*\r\n$gdb_prompt $" {
3929 set allow_btrace_pt_tests
0
3931 -re
"^record btrace pt\r\n$gdb_prompt $" {
3932 set allow_btrace_pt_tests
1
3936 remote_file build
delete $
obj
3938 verbose
"$me: returning $allow_btrace_pt_tests" 2
3939 return $allow_btrace_pt_tests
3942 # Run a test
on the target to see
if it supports Aarch64 SVE hardware.
3943 #
Return 1 if so
, 0 if it does not. Note this causes a restart of GDB.
3945 gdb_caching_proc allow_aarch64_sve_tests
{} {
3946 global srcdir subdir gdb_prompt inferior_exited_re
3948 set me
"allow_aarch64_sve_tests"
3950 if { ![is_aarch64_target
]} {
3954 set compile_flags
"{additional_flags=-march=armv8-a+sve}"
3956 #
Compile a test
program containing SVE instructions.
3959 asm volatile
("ptrue p0.b");
3963 if {![gdb_simple_compile $me $src executable $compile_flags
]} {
3967 # Compilation succeeded so now run it via gdb.
3971 -re
".*Illegal instruction.*${gdb_prompt} $" {
3972 verbose
-log "\n$me sve hardware not detected"
3973 set allow_sve_tests
0
3975 -re
".*$inferior_exited_re normally.*${gdb_prompt} $" {
3976 verbose
-log "\n$me: sve hardware detected"
3977 set allow_sve_tests
1
3980 warning
"\n$me: default case taken"
3981 set allow_sve_tests
0
3985 remote_file build
delete $
obj
3987 verbose
"$me: returning $allow_sve_tests" 2
3988 return $allow_sve_tests
3992 # A helper that compiles a test case to see
if __int128 is supported.
3993 proc gdb_int128_helper
{lang
} {
3994 return [gdb_can_simple_compile
"i128-for-$lang" {
3996 int main
() { return 0; }
4000 #
Return true
if the C compiler understands the __int128 type.
4001 gdb_caching_proc has_int128_c
{} {
4002 return [gdb_int128_helper c
]
4005 #
Return true
if the C
++ compiler understands the __int128 type.
4006 gdb_caching_proc has_int128_cxx
{} {
4007 return [gdb_int128_helper c
++]
4010 #
Return true
if the IFUNC feature is supported.
4011 gdb_caching_proc allow_ifunc_tests
{} {
4012 if [gdb_can_simple_compile ifunc
{
4014 typedef void F
(void
);
4015 F
* g
(void
) { return &f_
; }
4016 void f
() __attribute__
((ifunc
("g")));
4024 #
Return whether we should skip tests
for showing inlined functions in
4025 # backtraces. Requires get_compiler_info and get_debug_format.
4027 proc skip_inline_frame_tests
{} {
4028 # GDB only recognizes inlining information in DWARF.
4029 if { ! [test_debug_format
"DWARF \[0-9\]"] } {
4033 # GCC before
4.1 does not emit DW_AT_call_file
/ DW_AT_call_line.
4034 if { ([test_compiler_info
"gcc-2-*"]
4035 ||
[test_compiler_info
"gcc-3-*"]
4036 ||
[test_compiler_info
"gcc-4-0-*"]) } {
4043 #
Return whether we should skip tests
for showing variables from
4044 # inlined functions. Requires get_compiler_info and get_debug_format.
4046 proc skip_inline_var_tests
{} {
4047 # GDB only recognizes inlining information in DWARF.
4048 if { ! [test_debug_format
"DWARF \[0-9\]"] } {
4055 #
Return a
1 if we should run tests that require hardware breakpoints
4057 proc allow_hw_breakpoint_tests
{} {
4058 # Skip tests
if requested by the board
(note that no_hardware_watchpoints
4059 # disables both watchpoints and breakpoints
)
4060 if { [target_info
exists gdb
,no_hardware_watchpoints
]} {
4064 # These targets support hardware breakpoints natively
4065 if { [istarget
"i?86-*-*"]
4066 ||
[istarget
"x86_64-*-*"]
4067 ||
[istarget
"ia64-*-*"]
4068 ||
[istarget
"arm*-*-*"]
4069 ||
[istarget
"aarch64*-*-*"]
4070 ||
[istarget
"s390*-*-*"] } {
4077 #
Return a
1 if we should run tests that require hardware watchpoints
4079 proc allow_hw_watchpoint_tests
{} {
4080 # Skip tests
if requested by the board
4081 if { [target_info
exists gdb
,no_hardware_watchpoints
]} {
4085 # These targets support hardware watchpoints natively
4086 # Note
, not all Power
9 processors support hardware watchpoints due to a HW
4087 # bug. Use has_hw_wp_support to check
do a runtime check
for hardware
4088 # watchpoint support
on Powerpc.
4089 if { [istarget
"i?86-*-*"]
4090 ||
[istarget
"x86_64-*-*"]
4091 ||
[istarget
"ia64-*-*"]
4092 ||
[istarget
"arm*-*-*"]
4093 ||
[istarget
"aarch64*-*-*"]
4094 ||
([istarget
"powerpc*-*-linux*"] && [has_hw_wp_support])
4095 ||
[istarget
"s390*-*-*"] } {
4102 #
Return a
1 if we should run tests that require
*multiple
* hardware
4103 # watchpoints to be active at the same time
4105 proc allow_hw_watchpoint_multi_tests
{} {
4106 if { ![allow_hw_watchpoint_tests
] } {
4110 # These targets support just a single hardware watchpoint
4111 if { [istarget
"arm*-*-*"]
4112 ||
[istarget
"powerpc*-*-linux*"] } {
4119 #
Return a
1 if we should run tests that require read
/access watchpoints
4121 proc allow_hw_watchpoint_access_tests
{} {
4122 if { ![allow_hw_watchpoint_tests
] } {
4126 # These targets support just write watchpoints
4127 if { [istarget
"s390*-*-*"] } {
4134 #
Return 1 if we should skip tests that require the runtime unwinder
4135 # hook. This must be invoked
while gdb is running
, after shared
4136 # libraries have been loaded. This is needed because otherwise a
4137 # shared libgcc won
't be visible.
4139 proc skip_unwinder_tests {} {
4143 gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook" {
4144 -re "= .*no debug info.*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
4146 -re "= .*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
4149 -re "No symbol .* in current context.\r\n$gdb_prompt $" {
4153 gdb_test_multiple "info probe" "check for stap probe in unwinder" {
4154 -re ".*libgcc.*unwind.*\r\n$gdb_prompt $" {
4157 -re "\r\n$gdb_prompt $" {
4164 # Return 1 if we should skip tests that require the libstdc++ stap
4165 # probes. This must be invoked while gdb is running, after shared
4166 # libraries have been loaded. PROMPT_REGEXP is the expected prompt.
4168 proc skip_libstdcxx_probe_tests_prompt { prompt_regexp } {
4170 gdb_test_multiple "info probe" "check for stap probe in libstdc++" \
4171 -prompt "$prompt_regexp" {
4172 -re ".*libstdcxx.*catch.*\r\n$prompt_regexp" {
4175 -re "\r\n$prompt_regexp" {
4178 set skip [expr !$supported]
4182 # As skip_libstdcxx_probe_tests_prompt, with gdb_prompt.
4184 proc skip_libstdcxx_probe_tests {} {
4186 return [skip_libstdcxx_probe_tests_prompt "$gdb_prompt $"]
4189 # Helper for gdb_is_target_* procs. TARGET_NAME is the name of the target
4190 # we're looking
for (used to build the test
name). TARGET_STACK_REGEXP
4191 # is a regexp that will match the output of
"maint print target-stack" if
4192 # the target in question is currently pushed. PROMPT_REGEXP is a regexp
4193 # matching the expected prompt after the command output.
4195 # NOTE
: GDB must be running BEFORE this procedure is called
!
4197 proc gdb_is_target_1
{ target_name target_stack_regexp prompt_regexp
} {
4200 # Throw a Tcl error
if gdb isn
't already started.
4201 if {![info exists gdb_spawn_id]} {
4202 error "gdb_is_target_1 called with no running gdb instance"
4205 set test "probe for target ${target_name}"
4206 gdb_test_multiple "maint print target-stack" $test \
4207 -prompt "$prompt_regexp" {
4208 -re "${target_stack_regexp}${prompt_regexp}" {
4212 -re "$prompt_regexp" {
4219 # Helper for gdb_is_target_remote where the expected prompt is variable.
4221 # NOTE: GDB must be running BEFORE this procedure is called!
4223 proc gdb_is_target_remote_prompt { prompt_regexp } {
4224 return [gdb_is_target_1 "remote" ".*emote target using gdb-specific protocol.*" $prompt_regexp]
4227 # Check whether we're testing with the remote or extended
-remote
4230 # NOTE
: GDB must be running BEFORE this procedure is called
!
4232 proc gdb_is_target_remote
{ } {
4235 return [gdb_is_target_remote_prompt
"$gdb_prompt $"]
4238 # Check whether we
're testing with the native target.
4240 # NOTE: GDB must be running BEFORE this procedure is called!
4242 proc gdb_is_target_native { } {
4245 return [gdb_is_target_1 "native" ".*native \\(Native process\\).*" "$gdb_prompt $"]
4248 # Like istarget, but checks a list of targets.
4249 proc is_any_target {args} {
4250 foreach targ $args {
4251 if {[istarget $targ]} {
4258 # Return the effective value of use_gdb_stub.
4260 # If the use_gdb_stub global has been set (it is set when the gdb process is
4261 # spawned), return that. Otherwise, return the value of the use_gdb_stub
4262 # property from the board file.
4264 # This is the preferred way of checking use_gdb_stub, since it allows to check
4265 # the value before the gdb has been spawned and it will return the correct value
4266 # even when it was overriden by the test.
4268 # Note that stub targets are not able to spawn new inferiors. Use this
4269 # check for skipping respective tests.
4271 proc use_gdb_stub {} {
4274 if [info exists use_gdb_stub] {
4275 return $use_gdb_stub
4278 return [target_info exists use_gdb_stub]
4281 # Return 1 if the current remote target is an instance of our GDBserver, 0
4282 # otherwise. Return -1 if there was an error and we can't tell.
4284 gdb_caching_proc target_is_gdbserver
{} {
4288 set test
"probing for GDBserver"
4290 gdb_test_multiple
"monitor help" $test {
4291 -re
"The following monitor commands are supported.*Quit GDBserver.*$gdb_prompt $" {
4294 -re
"$gdb_prompt $" {
4299 if { $is_gdbserver
== -1 } {
4300 verbose
-log "Unable to tell whether we are using GDBserver or not."
4303 return $is_gdbserver
4306 # N.B. compiler_info is intended to be local to this file.
4307 #
Call test_compiler_info with no arguments to
fetch its value.
4308 # Yes
, this is counterintuitive when there
's get_compiler_info,
4309 # but that's the current API.
4310 if [info exists compiler_info
] {
4314 # Figure out what compiler I am using.
4315 # The result is cached so only the first invocation runs the compiler.
4317 #
ARG can be empty or
"C++". If empty, "C" is assumed.
4319 # There are several ways to
do this
, with various problems.
4321 #
[ gdb_compile
-E $ifile
-o $binfile.ci
]
4322 # source $binfile.ci
4324 # Single Unix Spec v3 says that
"-E -o ..." together are not
4325 # specified. And in fact
, the native compiler
on hp
-ux
11 (among
4326 # others
) does not work with
"-E -o ...". Most targets used to do
4327 # this
, and it mostly worked
, because it works with gcc.
4329 #
[ catch
"exec $compiler -E $ifile > $binfile.ci" exec_output ]
4330 # source $binfile.ci
4332 # This avoids the problem with
-E and
-o together. This almost works
4333 #
if the build machine is the same as the host machine
, which is
4334 # usually true of the targets which are not gcc. But this code does
4335 # not figure which compiler to
call, and it always ends up using the C
4336 # compiler. Not good
for setting hp_aCC_compiler. Target
4337 # hppa
*-*-hpux
* used to
do this.
4339 #
[ gdb_compile
-E $ifile
> $binfile.ci
]
4340 # source $binfile.ci
4342 # dejagnu target_compile says that it supports output redirection
,
4343 # but the code is completely different from the
normal path and I
4344 # don
't want to sweep the mines from that path. So I didn't even try
4347 #
set cppout
[ gdb_compile $ifile
"" preprocess $args quiet ]
4350 # I actually
do this
for all targets now. gdb_compile runs the right
4351 # compiler
, and TCL captures the output
, and I eval the output.
4353 # Unfortunately
, expect logs the output of the command as it goes by
,
4354 # and dejagnu helpfully prints a second copy of it right afterwards.
4355 # So I turn
off expect logging
for a moment.
4357 #
[ gdb_compile $ifile $ciexe_file executable $
args ]
4358 #
[ remote_exec $ciexe_file
]
4359 #
[ source $ci_file.out
]
4361 # I could give up
on -E and just
do this.
4362 # I didn
't get desperate enough to try this.
4364 # -- chastain 2004-01-06
4366 proc get_compiler_info {{language "c"}} {
4368 # For compiler.c, compiler.cc and compiler.F90.
4371 # I am going to play with the log to keep noise out.
4375 # These come from compiler.c, compiler.cc or compiler.F90.
4376 gdb_persistent_global compiler_info_cache
4378 if [info exists compiler_info_cache($language)] {
4383 # Choose which file to preprocess.
4384 if { $language == "c++" } {
4385 set ifile "${srcdir}/lib/compiler.cc"
4386 } elseif { $language == "f90" } {
4387 set ifile "${srcdir}/lib/compiler.F90"
4388 } elseif { $language == "c" } {
4389 set ifile "${srcdir}/lib/compiler.c"
4391 perror "Unable to fetch compiler version for language: $language"
4395 # Run $ifile through the right preprocessor.
4396 # Toggle gdb.log to keep the compiler output out of the log.
4397 set saved_log [log_file -info]
4399 if [is_remote host] {
4400 # We have to use -E and -o together, despite the comments
4401 # above, because of how DejaGnu handles remote host testing.
4402 set ppout "$outdir/compiler.i"
4403 gdb_compile "${ifile}" "$ppout" preprocess [list "$language" quiet getting_compiler_info]
4404 set file [open $ppout r]
4405 set cppout [read $file]
4408 # Copy $ifile to temp dir, to work around PR gcc/60447. This will leave the
4409 # superfluous .s file in the temp dir instead of in the source dir.
4410 set tofile [file tail $ifile]
4411 set tofile [standard_temp_file $tofile]
4412 file copy -force $ifile $tofile
4414 set cppout [ gdb_compile "${ifile}" "" preprocess [list "$language" quiet getting_compiler_info] ]
4416 eval log_file $saved_log
4420 foreach cppline [ split "$cppout" "\n" ] {
4421 if { [ regexp "^#" "$cppline" ] } {
4423 } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } {
4425 } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } {
4427 verbose "get_compiler_info: $cppline" 2
4429 } elseif { [ regexp "flang.*warning.*'-fdiagnostics
-color
=never
'" "$cppline"] } {
4430 # Both flang preprocessors (llvm flang and classic flang) print a
4431 # warning for the unused -fdiagnostics-color=never, so we skip this
4435 verbose -log "get_compiler_info: $cppline"
4440 # Set to unknown if for some reason compiler_info didn't
get defined.
4441 if ![info exists compiler_info
] {
4442 verbose
-log "get_compiler_info: compiler_info not provided"
4443 set compiler_info
"unknown"
4445 # Also
set to unknown compiler
if any diagnostics happened.
4447 verbose
-log "get_compiler_info: got unexpected diagnostics"
4448 set compiler_info
"unknown"
4451 set compiler_info_cache
($language
) $compiler_info
4453 #
Log what happened.
4454 verbose
-log "get_compiler_info: $compiler_info"
4459 #
Return the compiler_info string
if no
arg is provided.
4460 # Otherwise the
argument is a glob
-style expression to match against
4463 proc test_compiler_info
{ {compiler
""} {language "c"} } {
4464 gdb_persistent_global compiler_info_cache
4466 if [get_compiler_info $language
] {
4467 # An error will already have been printed in this case. Just
4468 #
return a suitable result depending
on how the user called
4470 if [string match
"" $compiler] {
4477 #
If no
arg, return the compiler_info string.
4478 if [string match
"" $compiler] {
4479 return $compiler_info_cache
($language
)
4482 return [string match $compiler $compiler_info_cache
($language
)]
4485 #
Return true
if the C compiler is GCC
, otherwise
, return false.
4487 proc is_c_compiler_gcc
{} {
4488 set compiler_info
[test_compiler_info
]
4489 set gcc_compiled false
4490 regexp
"^gcc-(\[0-9\]+)-" "$compiler_info" matchall gcc_compiled
4491 return $gcc_compiled
4494 #
Return the gcc major version
, or
-1.
4495 #
For gcc
4.8.5, the major version is
4.8.
4496 #
For gcc
7.5.0, the major version
7.
4497 # The COMPILER and LANGUAGE arguments are as
for test_compiler_info.
4499 proc gcc_major_version
{ {compiler
"gcc-*"} {language "c"} } {
4501 if { ![test_compiler_info $compiler $language
] } {
4504 #
Strip "gcc-*" to "gcc".
4505 regsub
-- {-.
*} $compiler
"" compiler
4506 set res
[regexp $compiler
-($decimal
)-($decimal
)- \
4507 [test_compiler_info
"" $language] \
4508 dummy_var major minor
]
4515 return $major.$minor
4518 proc current_target_name
{ } {
4520 if [info exists target_info
(target
,name)] {
4521 set answer $target_info
(target
,name)
4528 set gdb_wrapper_initialized
0
4529 set gdb_wrapper_target
""
4530 set gdb_wrapper_file
""
4531 set gdb_wrapper_flags
""
4533 proc gdb_wrapper_init
{ args } {
4534 global gdb_wrapper_initialized
4535 global gdb_wrapper_file
4536 global gdb_wrapper_flags
4537 global gdb_wrapper_target
4539 if { $gdb_wrapper_initialized
== 1 } { return; }
4541 if {[target_info
exists needs_status_wrapper
] && \
4542 [target_info needs_status_wrapper
] != "0"} {
4543 set result
[build_wrapper
"testglue.o"]
4544 if { $result
!= "" } {
4545 set gdb_wrapper_file
[lindex $result
0]
4546 if ![is_remote host
] {
4547 set gdb_wrapper_file
[file join
[pwd
] $gdb_wrapper_file
]
4549 set gdb_wrapper_flags
[lindex $result
1]
4551 warning
"Status wrapper failed to build."
4554 set gdb_wrapper_file
""
4555 set gdb_wrapper_flags
""
4557 verbose
"set gdb_wrapper_file = $gdb_wrapper_file"
4558 set gdb_wrapper_initialized
1
4559 set gdb_wrapper_target
[current_target_name
]
4562 # Determine options that we always want to pass to the compiler.
4563 gdb_caching_proc universal_compile_options
{} {
4564 set me
"universal_compile_options"
4567 set src
[standard_temp_file ccopts
[pid
].c
]
4568 set obj [standard_temp_file ccopts
[pid
].o
]
4570 gdb_produce_source $src
{
4571 int foo
(void
) { return 0; }
4574 # Try an option
for disabling colored diagnostics. Some compilers
4575 # yield colored diagnostics by default
(when run from a tty
) unless
4576 # such an option is specified.
4577 set opt
"additional_flags=-fdiagnostics-color=never"
4578 set lines
[target_compile $src $
obj object
[list
"quiet" $opt]]
4579 if {[string match
"" $lines]} {
4580 # Seems to have worked
; use the option.
4581 lappend options $opt
4586 verbose
"$me: returning $options" 2
4590 #
Compile the code in $code to a file based
on $
name, using the flags
4591 # $compile_flag as well as debug
, nowarning and quiet.
4592 #
Return 1 if code can be compiled
4593 # Leave the file
name of the resulting object in the upvar object.
4595 proc gdb_simple_compile
{name code
{type object
} {compile_flags
{}} {object
obj}} {
4598 switch -regexp
-- $type
{
4613 foreach flag $compile_flags
{
4614 if { "$flag" == "go" } {
4618 if { "$flag" eq "hip" } {
4623 set src
[standard_temp_file $
name-[pid
].$ext
]
4624 set obj [standard_temp_file $
name-[pid
].$postfix
]
4625 set compile_flags
[concat $compile_flags
{debug nowarnings quiet
}]
4627 gdb_produce_source $src $code
4629 verbose
"$name: compiling testfile $src" 2
4630 set lines
[gdb_compile $src $
obj $type $compile_flags
]
4634 if {![string match
"" $lines]} {
4635 verbose
"$name: compilation failed, returning 0" 2
4641 #
Compile the code in $code to a file based
on $
name, using the flags
4642 # $compile_flag as well as debug
, nowarning and quiet.
4643 #
Return 1 if code can be compiled
4644 #
Delete all created files and objects.
4646 proc gdb_can_simple_compile
{name code
{type object
} {compile_flags
""}} {
4647 set ret
[gdb_simple_compile $
name $code $type $compile_flags temp_obj
]
4648 file
delete $temp_obj
4652 # Some targets need to always link a special object in. Save its path here.
4653 global gdb_saved_set_unbuffered_mode_obj
4654 set gdb_saved_set_unbuffered_mode_obj
""
4656 # Escape STR sufficiently
for use
on host commandline.
4658 proc escape_for_host
{ str
} {
4659 if { [is_remote host
] } {
4669 return [string map $map $str
]
4672 #
Compile source files specified by SOURCE into a binary of type TYPE at path
4673 # DEST. gdb_compile is implemented using DejaGnu
's target_compile, so the type
4674 # parameter and most options are passed directly to it.
4676 # The type can be one of the following:
4678 # - object: Compile into an object file.
4679 # - executable: Compile and link into an executable.
4680 # - preprocess: Preprocess the source files.
4681 # - assembly: Generate assembly listing.
4683 # The following options are understood and processed by gdb_compile:
4685 # - shlib=so_path: Add SO_PATH to the sources, and enable some target-specific
4686 # quirks to be able to use shared libraries.
4687 # - shlib_load: Link with appropriate libraries to allow the test to
4688 # dynamically load libraries at runtime. For example, on Linux, this adds
4689 # -ldl so that the test can use dlopen.
4690 # - nowarnings: Inhibit all compiler warnings.
4691 # - pie: Force creation of PIE executables.
4692 # - nopie: Prevent creation of PIE executables.
4693 # - macros: Add the required compiler flag to include macro information in
4695 # - text_segment=addr: Tell the linker to place the text segment at ADDR.
4696 # - build-id: Ensure the final binary includes a build-id.
4698 # And here are some of the not too obscure options understood by DejaGnu that
4699 # influence the compilation:
4701 # - additional_flags=flag: Add FLAG to the compiler flags.
4702 # - libs=library: Add LIBRARY to the libraries passed to the linker. The
4703 # argument can be a file, in which case it's added to the sources
, or a
4705 #
- ldflags
=flag
: Add FLAG to the linker flags.
4706 #
- incdir
=path
: Add PATH to the searched
include directories.
4707 #
- libdir
=path
: Add PATH to the linker searched directories.
4708 #
- ada
, c
++, f90
, go
, rust
: Compile the file as Ada
, C
++,
4709 # Fortran
90, Go or Rust.
4710 #
- debug
: Build with debug information.
4711 #
- optimize
: Build with optimization.
4713 proc gdb_compile
{source dest type options
} {
4714 global GDB_TESTCASE_OPTIONS
4715 global gdb_wrapper_file
4716 global gdb_wrapper_flags
4719 global gdb_saved_set_unbuffered_mode_obj
4721 set outdir
[file dirname $dest
]
4723 #
If this is
set, calling test_compiler_info will cause recursion.
4724 if { [lsearch
-exact $options getting_compiler_info
] == -1 } {
4725 set getting_compiler_info false
4727 set getting_compiler_info true
4730 # Add platform
-specific options
if a shared library was specified using
4731 #
"shlib=librarypath" in OPTIONS.
4733 if {[lsearch
-exact $options rust
] != -1} {
4734 #
-fdiagnostics
-color is not a rustcc option.
4736 set new_options
[universal_compile_options
]
4739 # C
/C
++ specific settings.
4740 if {!$getting_compiler_info
4741 && [lsearch
-exact $options rust
] == -1
4742 && [lsearch
-exact $options ada
] == -1
4743 && [lsearch
-exact $options f90
] == -1
4744 && [lsearch
-exact $options go
] == -1} {
4746 # Some C
/C
++ testcases unconditionally pass
-Wno
-foo as additional
4747 # options to disable some warning. That is OK with GCC
, because
4748 # by design
, GCC accepts
any -Wno
-foo option
, even
if it doesn
't
4749 # support -Wfoo. Clang however warns about unknown -Wno-foo by
4750 # default, unless you pass -Wno-unknown-warning-option as well.
4751 # We do that here, so that individual testcases don't have to
4753 if {[test_compiler_info
"clang-*"] || [test_compiler_info "icx-*"]} {
4754 lappend new_options
"additional_flags=-Wno-unknown-warning-option"
4755 } elseif
{[test_compiler_info
"icc-*"]} {
4756 # This is the equivalent
for the icc compiler.
4757 lappend new_options
"additional_flags=-diag-disable=10148"
4760 # icpx
/icx give the following warning
if '-g' is used without
'-O'.
4762 # icpx
: remark
: Note that use of
'-g' without
any
4763 # optimization
-level option will turn
off most compiler
4764 # optimizations similar to use of
'-O0'
4766 # The warning makes dejagnu think that compilation has failed.
4768 # Furthermore
, if no
-O flag is passed
, icx and icc optimize
4769 # the code by default. This breaks assumptions in many GDB
4770 # tests that the code is unoptimized by default.
4772 # To fix both problems
, pass the
-O0 flag explicitly
, if no
4773 # optimization option is given.
4774 if {[test_compiler_info
"icx-*"] || [test_compiler_info "icc-*"]} {
4775 if {[lsearch $options optimize
=*] == -1
4776 && [lsearch $options additional_flags
=-O
*] == -1} {
4777 lappend new_options
"optimize=-O0"
4781 # Starting with
2021.7.0 (recognized as icc
-20-21-7 by GDB
) icc and
4782 # icpc are marked as deprecated and both compilers emit the remark
4783 # #
10441. To let GDB still
compile successfully
, we disable these
4785 if {([lsearch
-exact $options c
++] != -1
4786 && [test_compiler_info
{icc
-20-21-[7-9]} c
++])
4787 ||
[test_compiler_info
{icc
-20-21-[7-9]}]} {
4788 lappend new_options
"additional_flags=-diag-disable=10441"
4792 #
If the
'build-id' option is used
, then ensure that we generate a
4793 # build
-id. GCC does this by default
, but Clang does not
, so
4795 if {[lsearch
-exact $options build
-id
] > 0
4796 && [test_compiler_info
"clang-*"]} {
4797 lappend new_options
"additional_flags=-Wl,--build-id"
4800 # Treating .c input files as C
++ is deprecated in Clang
, so
4801 # explicitly force C
++ language.
4802 if { !$getting_compiler_info
4803 && [lsearch
-exact $options c
++] != -1
4804 && [string match
*.c $source
] != 0 } {
4806 # gdb_compile cannot handle this combination of options
, the
4807 # result is a command like
"clang -x c++ foo.c bar.so -o baz"
4808 # which tells Clang to treat bar.so as C
++. The solution is
4809 # to
call gdb_compile twice
--once to
compile, once to link
--
4810 # either directly
, or via build_executable_from_specs.
4811 if { [lsearch $options shlib
=*] != -1 } {
4812 error
"incompatible gdb_compile options"
4815 if {[test_compiler_info
"clang-*"]} {
4816 lappend new_options early_flags
=-x\ c
++
4820 # Place
(and look
for) Fortran `.mod` files in the output
4821 # directory
for this specific test.
For Intel compilers the
-J
4822 # option is not supported so instead use the
-module flag.
4823 # Additionally
, Intel compilers need the
-debug
-parameters flag
set to
4824 # emit debug
info for all parameters in modules.
4826 # ifx gives the following warning
if '-g' is used without
'-O'.
4828 # ifx
: remark #
10440: Note that use of a debug option
4829 # without
any optimization
-level option will turnoff most
4830 # compiler optimizations similar to use of
'-O0'
4832 # The warning makes dejagnu think that compilation has failed.
4834 # Furthermore
, if no
-O flag is passed
, Intel compilers optimize
4835 # the code by default. This breaks assumptions in many GDB
4836 # tests that the code is unoptimized by default.
4838 # To fix both problems
, pass the
-O0 flag explicitly
, if no
4839 # optimization option is given.
4840 if { !$getting_compiler_info
&& [lsearch
-exact $options f90
] != -1 } {
4842 set mod_path
[standard_output_file
""]
4843 if { [test_compiler_info
{gfortran
-*} f90
] } {
4844 lappend new_options
"additional_flags=-J${mod_path}"
4845 } elseif
{ [test_compiler_info
{ifort
-*} f90
]
4846 ||
[test_compiler_info
{ifx
-*} f90
] } {
4847 lappend new_options
"additional_flags=-module ${mod_path}"
4848 lappend new_options
"additional_flags=-debug-parameters all"
4850 if {[lsearch $options optimize
=*] == -1
4851 && [lsearch $options additional_flags
=-O
*] == -1} {
4852 lappend new_options
"optimize=-O0"
4859 foreach opt $options
{
4860 if {[regexp
{^shlib
=(.
*)} $opt dummy_var shlib_name
]
4861 && $type
== "executable"} {
4862 if [test_compiler_info
"xlc-*"] {
4863 # IBM xlc compiler doesn
't accept shared library named other
4864 # than .so: use "-Wl," to bypass this
4865 lappend source "-Wl,$shlib_name"
4866 } elseif { ([istarget "*-*-mingw*"]
4867 || [istarget *-*-cygwin*]
4868 || [istarget *-*-pe*])} {
4869 lappend source "${shlib_name}.a"
4871 lappend source $shlib_name
4873 if { $shlib_found == 0 } {
4875 if { ([istarget "*-*-mingw*"]
4876 || [istarget *-*-cygwin*]) } {
4877 lappend new_options "ldflags=-Wl,--enable-auto-import"
4879 if { [test_compiler_info "gcc-*"] || [test_compiler_info "clang-*"] } {
4880 # Undo debian's change in the default.
4881 # Put it at the front to not override
any user
-provided
4882 # value
, and to make sure it appears in front of all the
4884 lappend new_options
"early_flags=-Wl,--no-as-needed"
4887 } elseif
{ $opt
== "shlib_load" && $type == "executable" } {
4889 } elseif
{ $opt
== "getting_compiler_info" } {
4890 # Ignore this setting here as it has been handled earlier in this
4891 # procedure.
Do not append it to new_options as this will cause
4893 } elseif
{[regexp
"^text_segment=(.*)" $opt dummy_var addr]} {
4894 if { [linker_supports_Ttext_segment_flag
] } {
4896 lappend new_options
"ldflags=-Wl,-Ttext-segment=$addr"
4897 } elseif
{ [linker_supports_image_base_flag
] } {
4899 lappend new_options "ldflags=-Wl,--image-base=$addr"
4900 } elseif { [linker_supports_Ttext_flag] } {
4901 # For old GNU gold versions.
4902 lappend new_options "ldflags=-Wl,-Ttext=$addr"
4904 error "Don't know how to handle text_segment option.
"
4907 lappend new_options $opt
4911 # Ensure stack protector is disabled
for GCC
, as this causes problems with
4912 # DWARF line numbering.
4913 # See https
://gcc.gnu.org
/bugzilla
/show_bug.cgi?id
=88432
4914 # This option defaults to
on for Debian
/Ubuntu.
4915 if { !$getting_compiler_info
4916 && [test_compiler_info
{gcc
-*-*}]
4917 && !([test_compiler_info
{gcc
-[0-3]-*}]
4918 ||
[test_compiler_info
{gcc
-4-0-*}])
4919 && [lsearch
-exact $options rust
] == -1} {
4920 # Put it at the front to not override
any user
-provided value.
4921 lappend new_options
"early_flags=-fno-stack-protector"
4924 # hipcc defaults to
-O2
, so add
-O0 to early flags
for the hip language.
4925 #
If "optimize" is also requested, another -O flag (e.g. -O2) will be added
4926 # to the flags
, overriding this
-O0.
4927 if {[lsearch
-exact $options hip
] != -1} {
4928 lappend new_options
"early_flags=-O0"
4931 # Because we link with libraries using their basename
, we may need
4932 #
(depending
on the platform
) to
set a special rpath value
, to allow
4933 # the executable to find the libraries it depends
on.
4934 if { $shlib_load || $shlib_found
} {
4935 if { ([istarget
"*-*-mingw*"]
4936 ||
[istarget
*-*-cygwin
*]
4937 ||
[istarget
*-*-pe
*]) } {
4938 #
Do not need anything.
4939 } elseif
{ [istarget
*-*-freebsd
*] ||
[istarget
*-*-openbsd
*] } {
4940 lappend new_options
"ldflags=-Wl,-rpath,${outdir}"
4942 if { $shlib_load
} {
4943 lappend new_options
"libs=-ldl"
4945 lappend new_options
[escape_for_host
{ldflags
=-Wl
,-rpath
,$ORIGIN
}]
4948 set options $new_options
4950 if [info exists GDB_TESTCASE_OPTIONS
] {
4951 lappend options
"additional_flags=$GDB_TESTCASE_OPTIONS"
4953 verbose
"options are $options"
4954 verbose
"source is $source $dest $type $options"
4958 if {[target_info
exists needs_status_wrapper
] && \
4959 [target_info needs_status_wrapper
] != "0" && \
4960 $gdb_wrapper_file
!= "" } {
4961 lappend options
"libs=${gdb_wrapper_file}"
4962 lappend options
"ldflags=${gdb_wrapper_flags}"
4965 # Replace the
"nowarnings" option with the appropriate additional_flags
4966 # to disable compiler warnings.
4967 set nowarnings
[lsearch
-exact $options nowarnings
]
4968 if {$nowarnings
!= -1} {
4969 if [target_info
exists gdb
,nowarnings_flag
] {
4970 set flag
"additional_flags=[target_info gdb,nowarnings_flag]"
4972 set flag
"additional_flags=-w"
4974 set options
[lreplace $options $nowarnings $nowarnings $flag
]
4977 # Replace the
"pie" option with the appropriate compiler and linker flags
4978 # to enable PIE executables.
4979 set pie
[lsearch
-exact $options pie
]
4981 if [target_info
exists gdb
,pie_flag
] {
4982 set flag
"additional_flags=[target_info gdb,pie_flag]"
4984 #
For safety
, use fPIE rather than fpie.
On AArch64
, m68k
, PowerPC
4985 # and SPARC
, fpie can cause
compile errors due to the GOT exceeding
4986 # a maximum size.
On other architectures the two flags are
4987 # identical
(see the GCC manual
). Note Debian9 and Ubuntu16.10
4988 # onwards default GCC to using fPIE.
If you
do require fpie
, then
4989 # it can be
set using the pie_flag.
4990 set flag
"additional_flags=-fPIE"
4992 set options
[lreplace $options $pie $pie $flag
]
4994 if [target_info
exists gdb
,pie_ldflag
] {
4995 set flag
"ldflags=[target_info gdb,pie_ldflag]"
4997 set flag
"ldflags=-pie"
4999 lappend options
"$flag"
5002 # Replace the
"nopie" option with the appropriate compiler and linker
5003 # flags to disable PIE executables.
5004 set nopie
[lsearch
-exact $options nopie
]
5006 if [target_info
exists gdb
,nopie_flag
] {
5007 set flag
"additional_flags=[target_info gdb,nopie_flag]"
5009 set flag
"additional_flags=-fno-pie"
5011 set options
[lreplace $options $nopie $nopie $flag
]
5013 if [target_info
exists gdb
,nopie_ldflag
] {
5014 set flag
"ldflags=[target_info gdb,nopie_ldflag]"
5016 set flag
"ldflags=-no-pie"
5018 lappend options
"$flag"
5021 set macros
[lsearch
-exact $options macros
]
5022 if {$macros
!= -1} {
5023 if { [test_compiler_info
"clang-*"] } {
5024 set flag
"additional_flags=-fdebug-macro"
5026 set flag
"additional_flags=-g3"
5029 set options
[lreplace $options $macros $macros $flag
]
5032 if { $type
== "executable" } {
5033 if { ([istarget
"*-*-mingw*"]
5034 ||
[istarget
"*-*-*djgpp"]
5035 ||
[istarget
"*-*-cygwin*"])} {
5036 # Force output to unbuffered
mode, by linking in an object file
5037 # with a global contructor that calls setvbuf.
5039 #
Compile the special object separately
for two reasons
:
5040 #
1) Insulate it from $options.
5041 #
2) Avoid compiling it
for every gdb_compile invocation
,
5042 # which is time consuming
, especially
if we
're remote
5045 if { $gdb_saved_set_unbuffered_mode_obj == "" } {
5046 verbose "compiling gdb_saved_set_unbuffered_obj"
5047 set unbuf_src ${srcdir}/lib/set_unbuffered_mode.c
5048 set unbuf_obj ${objdir}/set_unbuffered_mode.o
5050 set result [gdb_compile "${unbuf_src}" "${unbuf_obj}" object {nowarnings}]
5051 if { $result != "" } {
5054 if {[is_remote host]} {
5055 set gdb_saved_set_unbuffered_mode_obj set_unbuffered_mode_saved.o
5057 set gdb_saved_set_unbuffered_mode_obj ${objdir}/set_unbuffered_mode_saved.o
5059 # Link a copy of the output object, because the
5060 # original may be automatically deleted.
5061 remote_download host $unbuf_obj $gdb_saved_set_unbuffered_mode_obj
5063 verbose "gdb_saved_set_unbuffered_obj already compiled"
5066 # Rely on the internal knowledge that the global ctors are ran in
5067 # reverse link order. In that case, we can use ldflags to
5068 # avoid copying the object file to the host multiple
5070 # This object can only be added if standard libraries are
5071 # used. Thus, we need to disable it if -nostdlib option is used
5072 if {[lsearch -regexp $options "-nostdlib"] < 0 } {
5073 lappend options "ldflags=$gdb_saved_set_unbuffered_mode_obj"
5078 cond_wrap [expr $pie != -1 || $nopie != -1] \
5079 with_PIE_multilib_flags_filtered {
5080 set result [target_compile $source $dest $type $options]
5083 # Prune uninteresting compiler (and linker) output.
5084 regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result
5086 # Starting with 2021.7.0 icc and icpc are marked as deprecated and both
5087 # compilers emit a remark #10441. To let GDB still compile successfully,
5088 # we disable these warnings. When $getting_compiler_info is true however,
5089 # we do not yet know the compiler (nor its version) and instead prune these
5090 # lines from the compiler output to let the get_compiler_info pass.
5091 if {$getting_compiler_info} {
5093 "(icc|icpc): remark #10441: The Intel\\(R\\) C\\+\\+ Compiler Classic \\(ICC\\) is deprecated\[^\r\n\]*" \
5097 regsub "\[\r\n\]*$" "$result" "" result
5098 regsub "^\[\r\n\]*" "$result" "" result
5100 if { $type == "executable" && $result == "" \
5101 && ($nopie != -1 || $pie != -1) } {
5102 set is_pie [exec_is_pie "$dest"]
5103 if { $nopie != -1 && $is_pie == 1 } {
5104 set result "nopie failed to prevent PIE executable"
5105 } elseif { $pie != -1 && $is_pie == 0 } {
5106 set result "pie failed to generate PIE executable"
5110 if {[lsearch $options quiet] < 0} {
5111 if { $result != "" } {
5112 clone_output "gdb compile failed, $result"
5119 # This is just like gdb_compile, above, except that it tries compiling
5120 # against several different thread libraries, to see which one this
5122 proc gdb_compile_pthreads {source dest type options} {
5123 if {$type != "executable"} {
5124 return [gdb_compile $source $dest $type $options]
5127 set why_msg "unrecognized error"
5128 foreach lib {-lpthreads -lpthread -lthread ""} {
5129 # This kind of wipes out whatever libs the caller may have
5130 # set. Or maybe theirs will override ours. How infelicitous.
5131 set options_with_lib [concat $options [list libs=$lib quiet]]
5132 set ccout [gdb_compile $source $dest $type $options_with_lib]
5133 switch -regexp -- $ccout {
5134 ".*no posix threads support.*" {
5135 set why_msg "missing threads include file"
5138 ".*cannot open -lpthread.*" {
5139 set why_msg "missing runtime threads library"
5141 ".*Can't find library
for -lpthread.
*" {
5142 set why_msg
"missing runtime threads library"
5145 pass
"successfully compiled posix threads test case"
5151 if {!$built_binfile
} {
5152 unsupported
"couldn't compile [file tail $source]: ${why_msg}"
5157 # Build a shared library from SOURCES.
5159 proc gdb_compile_shlib_1
{sources dest options
} {
5160 set obj_options $options
5163 if { [lsearch
-exact $options
"ada"] >= 0 } {
5167 if { [lsearch
-exact $options
"c++"] >= 0 } {
5168 set info_options
"c++"
5169 } elseif
{ [lsearch
-exact $options
"f90"] >= 0 } {
5170 set info_options
"f90"
5172 set info_options
"c"
5175 switch -glob
[test_compiler_info
"" ${info_options}] {
5177 lappend obj_options
"additional_flags=-qpic"
5180 if { [istarget
"*-*-cygwin*"]
5181 ||
[istarget
"*-*-mingw*"] } {
5182 lappend obj_options
"additional_flags=-fPIC"
5184 lappend obj_options
"additional_flags=-fpic"
5188 if { [istarget
"powerpc*-*-aix*"]
5189 ||
[istarget
"rs6000*-*-aix*"]
5190 ||
[istarget
"*-*-cygwin*"]
5191 ||
[istarget
"*-*-mingw*"]
5192 ||
[istarget
"*-*-pe*"] } {
5193 lappend obj_options
"additional_flags=-fPIC"
5195 lappend obj_options
"additional_flags=-fpic"
5199 lappend obj_options
"additional_flags=-fpic"
5202 # don
't know what the compiler is...
5203 lappend obj_options "additional_flags=-fPIC"
5207 set outdir [file dirname $dest]
5209 foreach source $sources {
5210 if {[file extension $source] == ".o"} {
5211 # Already a .o file.
5212 lappend objects $source
5216 set sourcebase [file tail $source]
5219 # Gnatmake doesn't like object
name foo.adb.o
, use foo.o.
5220 set sourcebase
[file rootname $sourcebase
]
5222 set object $
{outdir
}/$
{sourcebase
}.o
5225 # Use gdb_compile_ada_1 instead of gdb_compile_ada to avoid the
5227 if {[gdb_compile_ada_1 $source $object object \
5228 $obj_options
] != ""} {
5232 if {[gdb_compile $source $object object \
5233 $obj_options
] != ""} {
5238 lappend objects $object
5241 set link_options $options
5243 #
If we try to use gnatmake
for the link
, it will interpret the
5244 # object file as an .adb file. Remove ada from the options to
5246 set idx
[lsearch $link_options
"ada"]
5247 set link_options
[lreplace $link_options $idx $idx
]
5249 if [test_compiler_info
"xlc-*"] {
5250 lappend link_options
"additional_flags=-qmkshrobj"
5252 lappend link_options
"additional_flags=-shared"
5254 if { ([istarget
"*-*-mingw*"]
5255 ||
[istarget
*-*-cygwin
*]
5256 ||
[istarget
*-*-pe
*]) } {
5257 if { [is_remote host
] } {
5258 set name [file tail $
{dest
}]
5262 lappend link_options
"ldflags=-Wl,--out-implib,${name}.a"
5264 #
Set the soname of the library. This causes the linker
on ELF
5265 # systems to create the DT_NEEDED entry in the executable referring
5266 # to the soname of the library
, and not its absolute path. This
5267 #
(using the absolute path
) would be problem when testing
on a
5270 # In conjunction with setting the soname
, we add the special
5271 # rpath
=$ORIGIN value when building the executable
, so that it
's
5272 # able to find the library in its own directory.
5273 set destbase [file tail $dest]
5274 lappend link_options "ldflags=-Wl,-soname,$destbase"
5277 if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
5280 if { [is_remote host]
5281 && ([istarget "*-*-mingw*"]
5282 || [istarget *-*-cygwin*]
5283 || [istarget *-*-pe*]) } {
5284 set dest_tail_name [file tail ${dest}]
5285 remote_upload host $dest_tail_name.a ${dest}.a
5286 remote_file host delete $dest_tail_name.a
5292 # Ignore FLAGS in target board multilib_flags while executing BODY.
5294 proc with_multilib_flags_filtered { flags body } {
5297 # Ignore flags in multilib_flags.
5298 set board [target_info name]
5299 set multilib_flags_orig [board_info $board multilib_flags]
5300 set multilib_flags ""
5301 foreach op $multilib_flags_orig {
5302 if { [lsearch -exact $flags $op] == -1 } {
5303 append multilib_flags " $op"
5307 save_target_board_info { multilib_flags } {
5308 unset_board_info multilib_flags
5309 set_board_info multilib_flags "$multilib_flags"
5310 set result [uplevel 1 $body]
5316 # Ignore PIE-related flags in target board multilib_flags while executing BODY.
5318 proc with_PIE_multilib_flags_filtered { body } {
5319 set pie_flags [list "-pie" "-no-pie" "-fPIE" "-fno-PIE"]
5320 return [uplevel 1 [list with_multilib_flags_filtered $pie_flags $body]]
5323 # Build a shared library from SOURCES. Ignore target boards PIE-related
5326 proc gdb_compile_shlib {sources dest options} {
5327 with_PIE_multilib_flags_filtered {
5328 set result [gdb_compile_shlib_1 $sources $dest $options]
5334 # This is just like gdb_compile_shlib, above, except that it tries compiling
5335 # against several different thread libraries, to see which one this
5337 proc gdb_compile_shlib_pthreads {sources dest options} {
5339 set why_msg "unrecognized error"
5340 foreach lib {-lpthreads -lpthread -lthread ""} {
5341 # This kind of wipes out whatever libs the caller may have
5342 # set. Or maybe theirs will override ours. How infelicitous.
5343 set options_with_lib [concat $options [list libs=$lib quiet]]
5344 set ccout [gdb_compile_shlib $sources $dest $options_with_lib]
5345 switch -regexp -- $ccout {
5346 ".*no posix threads support.*" {
5347 set why_msg "missing threads include file"
5350 ".*cannot open -lpthread.*" {
5351 set why_msg "missing runtime threads library"
5353 ".*Can't find library
for -lpthread.
*" {
5354 set why_msg
"missing runtime threads library"
5357 pass
"successfully compiled posix threads shlib test case"
5363 if {!$built_binfile
} {
5364 unsupported
"couldn't compile $sources: ${why_msg}"
5369 # This is just like gdb_compile_pthreads
, above
, except that we always add the
5370 # objc library
for compiling Objective
-C programs
5371 proc gdb_compile_objc
{source dest type options
} {
5373 set why_msg
"unrecognized error"
5374 foreach lib
{-lobjc
-lpthreads
-lpthread
-lthread solaris
} {
5375 # This kind of wipes out whatever libs the caller may have
5376 #
set. Or maybe theirs will override ours. How infelicitous.
5377 if { $lib
== "solaris" } {
5378 set lib
"-lpthread -lposix4"
5380 if { $lib
!= "-lobjc" } {
5381 set lib
"-lobjc $lib"
5383 set options_with_lib
[concat $options
[list libs
=$lib quiet
]]
5384 set ccout
[gdb_compile $source $dest $type $options_with_lib
]
5385 switch -regexp
-- $ccout
{
5386 ".*no posix threads support.*" {
5387 set why_msg
"missing threads include file"
5390 ".*cannot open -lpthread.*" {
5391 set why_msg
"missing runtime threads library"
5393 ".*Can't find library for -lpthread.*" {
5394 set why_msg
"missing runtime threads library"
5397 pass
"successfully compiled objc with posix threads test case"
5403 if {!$built_binfile
} {
5404 unsupported
"couldn't compile [file tail $source]: ${why_msg}"
5409 # Build an OpenMP
program from SOURCE. See prefatory comment
for
5410 # gdb_compile
, above
, for discussion of the parameters to this proc.
5412 proc gdb_compile_openmp
{source dest type options
} {
5413 lappend options
"additional_flags=-fopenmp"
5414 return [gdb_compile $source $dest $type $options
]
5417 # Send a command to GDB.
5418 #
For options
for TYPE see gdb_stdin_log_write
5420 proc send_gdb
{ string
{type standard
}} {
5421 gdb_stdin_log_write $string $type
5422 return [remote_send host
"$string"]
5425 # Send STRING to the inferior
's terminal.
5427 proc send_inferior { string } {
5428 global inferior_spawn_id
5430 if {[catch "send -i $inferior_spawn_id -- \$string" errorInfo]} {
5440 proc gdb_expect { args } {
5441 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
5442 set atimeout [lindex $args 0]
5443 set expcode [list [lindex $args 1]]
5448 # A timeout argument takes precedence, otherwise of all the timeouts
5449 # select the largest.
5450 if [info exists atimeout] {
5453 set tmt [get_largest_timeout]
5457 {uplevel remote_expect host $tmt $expcode} string]
5460 global errorInfo errorCode
5462 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
5464 return -code $code $string
5468 # gdb_expect_list TEST SENTINEL LIST -- expect a sequence of outputs
5470 # Check for long sequence of output by parts.
5471 # TEST: is the test message to be printed with the test success/fail.
5472 # SENTINEL: Is the terminal pattern indicating that output has finished.
5473 # LIST: is the sequence of outputs to match.
5474 # If the sentinel is recognized early, it is considered an error.
5477 # 1 if the test failed,
5478 # 0 if the test passes,
5479 # -1 if there was an internal error.
5481 proc gdb_expect_list {test sentinel list} {
5486 while { ${index} < [llength ${list}] } {
5487 set pattern [lindex ${list} ${index}]
5488 set index [expr ${index} + 1]
5489 verbose -log "gdb_expect_list pattern: /$pattern/" 2
5490 if { ${index} == [llength ${list}] } {
5493 -re "${pattern}${sentinel}" {
5494 # pass "${test}, pattern ${index} + sentinel"
5497 fail "${test} (pattern ${index} + sentinel)"
5500 -re ".*A problem internal to GDB has been detected" {
5501 fail "${test} (GDB internal error)"
5503 gdb_internal_error_resync
5506 fail "${test} (pattern ${index} + sentinel) (timeout)"
5511 # unresolved "${test}, pattern ${index} + sentinel"
5517 # pass "${test}, pattern ${index}"
5520 fail "${test} (pattern ${index})"
5523 -re ".*A problem internal to GDB has been detected" {
5524 fail "${test} (GDB internal error)"
5526 gdb_internal_error_resync
5529 fail "${test} (pattern ${index}) (timeout)"
5534 # unresolved "${test}, pattern ${index}"
5546 # Spawn the gdb process.
5548 # This doesn't expect
any output or
do any other initialization
,
5549 # leaving those to the caller.
5551 # Overridable function
-- you can override this function in your
5554 proc gdb_spawn
{ } {
5558 # Spawn GDB with CMDLINE_FLAGS appended to the GDBFLAGS global.
5560 proc gdb_spawn_with_cmdline_opts
{ cmdline_flags
} {
5563 set saved_gdbflags $GDBFLAGS
5565 if {$GDBFLAGS
!= ""} {
5568 append GDBFLAGS $cmdline_flags
5572 set GDBFLAGS $saved_gdbflags
5577 # Start gdb running
, wait
for prompt
, and disable the pagers.
5579 # Overridable function
-- you can override this function in your
5582 proc gdb_start
{ } {
5587 catch default_gdb_exit
5590 #
Return true
if we can spawn a
program on the target and attach to
5593 proc can_spawn_for_attach
{ } {
5594 # We use exp_pid to
get the inferior
's pid, assuming that gives
5595 # back the pid of the program. On remote boards, that would give
5596 # us instead the PID of e.g., the ssh client, etc.
5597 if {[is_remote target]} {
5598 verbose -log "can't spawn
for attach
(target is remote
)"
5602 # The
"attach" command doesn't make sense when the target is
5603 # stub
-like
, where GDB finds the
program already started
on
5604 # initial connection.
5605 if {[target_info
exists use_gdb_stub
]} {
5606 verbose
-log "can't spawn for attach (target is stub)"
5614 # Centralize the failure checking of
"attach" command.
5615 #
Return 0 if attach failed
, otherwise
return 1.
5617 proc gdb_attach
{ testpid
args } {
5622 if { [llength $
args] != 0 } {
5623 error
"Unexpected arguments: $args"
5626 gdb_test_multiple
"attach $testpid" "attach" {
5627 -re
-wrap
"Attaching to.*ptrace: Operation not permitted\\." {
5628 unsupported
"$gdb_test_name (Operation not permitted)"
5631 -re
-wrap
"$pattern" {
5640 # Start gdb with
"--pid $TESTPID" on the command line and wait for the prompt.
5641 #
Return 1 if GDB managed to start and attach to the process
, 0 otherwise.
5643 proc_with_prefix gdb_spawn_attach_cmdline
{ testpid
} {
5644 if ![can_spawn_for_attach
] {
5645 # The caller should have checked can_spawn_for_attach itself
5646 # before getting here.
5647 error
"can't spawn for attach with this target/board"
5650 set test
"start gdb with --pid"
5651 set res
[gdb_spawn_with_cmdline_opts
"-quiet --pid=$testpid"]
5657 gdb_test_multiple
"" "$test" {
5658 -re
-wrap
"ptrace: Operation not permitted\\." {
5659 unsupported
"$gdb_test_name (operation not permitted)"
5662 -re
-wrap
"ptrace: No such process\\." {
5663 fail
"$gdb_test_name (no such process)"
5666 -re
-wrap
"Attaching to process $testpid\r\n.*" {
5671 # Check that we actually attached to a process
, in case the
5672 # error message is not caught by the patterns above.
5673 gdb_test_multiple
"info thread" "" {
5674 -re
-wrap
"No threads\\." {
5675 fail
"$gdb_test_name (no thread)"
5686 # Kill a progress previously started with spawn_wait_for_attach
, and
5687 # reap its wait
status. PROC_SPAWN_ID is the spawn id associated with
5690 proc kill_wait_spawned_process
{ proc_spawn_id
} {
5691 set pid
[exp_pid
-i $proc_spawn_id
]
5693 verbose
-log "killing ${pid}"
5694 remote_exec build
"kill -9 ${pid}"
5696 verbose
-log "closing ${proc_spawn_id}"
5697 catch
"close -i $proc_spawn_id"
5698 verbose
-log "waiting for ${proc_spawn_id}"
5700 #
If somehow GDB ends up still attached to the process here
, a
5701 # blocking wait hangs until gdb is killed
(or until gdb
/ the
5702 # ptracer reaps the exit
status too
, but that won
't happen because
5703 # something went wrong.) Passing -nowait makes expect tell Tcl to
5704 # wait for the PID in the background. That's fine because we
5705 # don
't care about the exit status. */
5706 wait -nowait -i $proc_spawn_id
5709 # Returns the process id corresponding to the given spawn id.
5711 proc spawn_id_get_pid { spawn_id } {
5712 set testpid [exp_pid -i $spawn_id]
5714 if { [istarget "*-*-cygwin*"] } {
5715 # testpid is the Cygwin PID, GDB uses the Windows PID, which
5716 # might be different due to the way fork/exec works.
5717 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
5723 # Start a set of programs running and then wait for a bit, to be sure
5724 # that they can be attached to. Return a list of processes spawn IDs,
5725 # one element for each process spawned. It's a test error to
call
5726 # this when
[can_spawn_for_attach
] is false.
5728 proc spawn_wait_for_attach
{ executable_list
} {
5729 set spawn_id_list
{}
5731 if ![can_spawn_for_attach
] {
5732 # The caller should have checked can_spawn_for_attach itself
5733 # before getting here.
5734 error
"can't spawn for attach with this target/board"
5737 foreach
{executable
} $executable_list
{
5738 # Note we use Expect
's spawn, not Tcl's exec
, because with
5739 # spawn we control when to wait
for/reap the process. That
5740 # allows killing the process by PID without being subject to
5742 lappend spawn_id_list
[remote_spawn target $executable
]
5747 return $spawn_id_list
5751 # gdb_load_cmd
-- load a file into the debugger.
5752 #
ARGS - additional
args to
load command.
5753 #
return a
-1 if anything goes wrong.
5755 proc gdb_load_cmd
{ args } {
5758 if [target_info
exists gdb_load_timeout
] {
5759 set loadtimeout
[target_info gdb_load_timeout
]
5761 set loadtimeout
1600
5763 send_gdb
"load $args\n"
5764 verbose
"Timeout is now $loadtimeout seconds" 2
5765 gdb_expect $loadtimeout
{
5766 -re
"Loading section\[^\r\]*\r\n" {
5769 -re
"Start address\[\r\]*\r\n" {
5772 -re
"Transfer rate\[\r\]*\r\n" {
5775 -re
"Memory access error\[^\r\]*\r\n" {
5776 perror
"Failed to load program"
5779 -re
"$gdb_prompt $" {
5782 -re
"(.*)\r\n$gdb_prompt " {
5783 perror
"Unexpected reponse from 'load' -- $expect_out(1,string)"
5787 perror
"Timed out trying to load $args."
5794 # Invoke
"gcore". CORE is the name of the core file to write. TEST
5795 # is the
name of the test case. This will
return 1 if the core file
5796 # was created
, 0 otherwise.
If this fails to make a core file because
5797 # this configuration of gdb does not support making core files
, it
5798 # will
call "unsupported", not "fail". However, if this fails to make
5799 # a core file
for some other reason
, then it will
call "fail".
5801 proc gdb_gcore_cmd
{core test
} {
5806 set re_unsupported \
5807 "(?:Can't create a corefile|Target does not support core file generation\\.)"
5809 with_timeout_factor
3 {
5810 gdb_test_multiple
"gcore $core" $test {
5811 -re
-wrap
"Saved corefile .*" {
5815 -re
-wrap $re_unsupported
{
5824 #
Load core file CORE. TEST is the
name of the test case.
5825 # This will record a pass
/fail
for loading the core file.
5827 #
1 - core file is successfully loaded
5828 #
0 - core file loaded but has a non fatal error
5829 #
-1 - core file failed to
load
5831 proc gdb_core_cmd
{ core test
} {
5834 gdb_test_multiple
"core $core" "$test" {
5835 -re
"\\\[Thread debugging using \[^ \r\n\]* enabled\\\]\r\n" {
5838 -re
" is not a core dump:.*\r\n$gdb_prompt $" {
5839 fail
"$test (bad file format)"
5842 -re
-wrap
"[string_to_regexp $core]: No such file or directory.*" {
5843 fail
"$test (file not found)"
5846 -re
"Couldn't find .* registers in core file.*\r\n$gdb_prompt $" {
5847 fail
"$test (incomplete note section)"
5850 -re
"Core was generated by .*\r\n$gdb_prompt $" {
5854 -re
".*$gdb_prompt $" {
5859 fail
"$test (timeout)"
5863 fail
"unsupported output from 'core' command"
5867 #
Return the filename to download to the target and
load on the target
5868 #
for this shared library. Normally just LIBNAME
, unless shared libraries
5869 #
for this target have separate link and
load images.
5871 proc shlib_target_file
{ libname
} {
5875 #
Return the filename GDB will
load symbols from when debugging this
5876 # shared library. Normally just LIBNAME
, unless shared libraries
for
5877 # this target have separate link and
load images.
5879 proc shlib_symbol_file
{ libname
} {
5883 #
Return the filename to download to the target and
load for this
5884 # executable. Normally just BINFILE unless it is renamed to something
5885 #
else for this target.
5887 proc exec_target_file
{ binfile
} {
5891 #
Return the filename GDB will
load symbols from when debugging this
5892 # executable. Normally just BINFILE unless executables
for this target
5893 # have separate files
for symbols.
5895 proc exec_symbol_file
{ binfile
} {
5899 #
Rename the executable file. Normally this is just BINFILE1 being renamed
5900 # to BINFILE2
, but some targets require multiple binary files.
5901 proc gdb_rename_execfile
{ binfile1 binfile2
} {
5902 file
rename -force
[exec_target_file $
{binfile1
}] \
5903 [exec_target_file $
{binfile2
}]
5904 if { [exec_target_file $
{binfile1
}] != [exec_symbol_file $
{binfile1
}] } {
5905 file
rename -force
[exec_symbol_file $
{binfile1
}] \
5906 [exec_symbol_file $
{binfile2
}]
5910 #
"Touch" the executable file to update the date. Normally this is just
5911 # BINFILE
, but some targets require multiple files.
5912 proc gdb_touch_execfile
{ binfile
} {
5913 set time
[clock
seconds]
5914 file mtime
[exec_target_file $
{binfile
}] $time
5915 if { [exec_target_file $
{binfile
}] != [exec_symbol_file $
{binfile
}] } {
5916 file mtime
[exec_symbol_file $
{binfile
}] $time
5920 # Override of dejagnu
's remote_upload, which doesn't handle remotedir.
5922 rename remote_upload dejagnu_remote_upload
5923 proc remote_upload
{ dest srcfile
args } {
5924 if { [is_remote $dest
] && [board_info $dest
exists remotedir
] } {
5925 set remotedir
[board_info $dest remotedir
]
5926 if { ![string match
"$remotedir*" $srcfile] } {
5927 # Use hardcoded
'/' as separator
, as in dejagnu
's remote_download.
5928 set srcfile $remotedir/$srcfile
5932 return [dejagnu_remote_upload $dest $srcfile {*}$args]
5935 # Like remote_download but provides a gdb-specific behavior.
5937 # If the destination board is remote, the local file FROMFILE is transferred as
5938 # usual with remote_download to TOFILE on the remote board. The destination
5939 # filename is added to the CLEANFILES global, so it can be cleaned up at the
5942 # If the destination board is local, the destination path TOFILE is passed
5943 # through standard_output_file, and FROMFILE is copied there.
5945 # In both cases, if TOFILE is omitted, it defaults to the [file tail] of
5948 proc gdb_remote_download {dest fromfile {tofile {}}} {
5949 # If TOFILE is not given, default to the same filename as FROMFILE.
5950 if {[string length $tofile] == 0} {
5951 set tofile [file tail $fromfile]
5954 if {[is_remote $dest]} {
5955 # When the DEST is remote, we simply send the file to DEST.
5956 global cleanfiles_target cleanfiles_host
5958 set destname [remote_download $dest $fromfile $tofile]
5959 if { $dest == "target" } {
5960 lappend cleanfiles_target $destname
5961 } elseif { $dest == "host" } {
5962 lappend cleanfiles_host $destname
5967 # When the DEST is local, we copy the file to the test directory (where
5968 # the executable is).
5970 # Note that we pass TOFILE through standard_output_file, regardless of
5971 # whether it is absolute or relative, because we don't want the tests
5972 # to be able to write outside their standard output directory.
5974 set tofile
[standard_output_file $tofile
]
5976 file copy
-force $fromfile $tofile
5982 # Copy shlib FILE to the target.
5984 proc gdb_download_shlib
{ file
} {
5985 set target_file
[shlib_target_file $file
]
5986 if { [is_remote host
] } {
5987 remote_download host $target_file
5989 return [gdb_remote_download target $target_file
]
5992 #
Set solib
-search
-path to allow gdb to locate shlib FILE.
5994 proc gdb_locate_shlib
{ file
} {
5997 if ![info exists gdb_spawn_id
] {
5998 perror
"gdb_load_shlib: GDB is not running"
6001 if { [is_remote target
] ||
[is_remote host
] } {
6002 #
If the target or host is remote
, we need to tell gdb where to find
6008 # We could
set this even when not testing remotely
, but a user
6009 # generally won
't set it unless necessary. In order to make the tests
6010 # more like the real-life scenarios, we don't
set it
for local testing.
6011 if { [is_remote host
] } {
6012 set solib_search_path
[board_info host remotedir
]
6013 if { $solib_search_path
== "" } {
6014 set solib_search_path .
6017 set solib_search_path
[file dirname $file
]
6020 gdb_test_no_output
"set solib-search-path $solib_search_path" \
6021 "set solib-search-path for [file tail $file]"
6024 # Copy shlib FILE to the target and
set solib
-search
-path to allow gdb to
6027 proc gdb_load_shlib
{ file
} {
6028 set dest
[gdb_download_shlib $file
]
6029 gdb_locate_shlib $file
6034 # gdb_load
-- load a file into the debugger. Specifying no file
6035 # defaults to the executable currently being debugged.
6036 # The
return value is
0 for success
, -1 for failure.
6037 # Many files in config
/*.exp override this procedure.
6039 proc gdb_load
{ arg } {
6041 return [gdb_file_cmd $
arg]
6047 # with_set
-- Execute BODY and
set VAR temporary to VAL
for the
6050 proc with_set
{ var val body
} {
6053 "is (\[^\r\n\]+)\\."
6054 gdb_test_multiple
"show $var" "" {
6055 -re
-wrap $show_re
{
6056 set save $expect_out
(1,string
)
6060 # Handle
'set to "auto" (currently "i386")'.
6061 set save
[regsub
{^
set to
} $save
""]
6062 set save
[regsub
{\
([^
\r\n]+\
)$
} $save
""]
6063 set save
[string trim $save
]
6064 set save
[regsub
-all
{^
"|"$} $save ""]
6066 if { $save
== "" } {
6067 perror
"Did not manage to set $var"
6070 set cmd
"set $var $val"
6071 gdb_test_multiple $cmd
"" {
6074 -re
-wrap
" is set to \"?$val\"?\\." {
6079 set code
[catch
{uplevel
1 $body
} result
]
6081 # Restore saved setting.
6082 if { $save
!= "" } {
6083 set cmd
"set $var $save"
6084 gdb_test_multiple $cmd
"" {
6087 -re
-wrap
"is set to \"?$save\"?( \\(\[^)\]*\\))?\\." {
6093 global errorInfo errorCode
6094 return -code $code
-errorinfo $errorInfo
-errorcode $errorCode $result
6096 return -code $code $result
6101 # with_complaints
-- Execute BODY and
set complaints temporary to N
for the
6104 proc with_complaints
{ n body
} {
6105 return [uplevel
[list with_set complaints $n $body
]]
6109 # gdb_load_no_complaints
-- As gdb_load
, but in addition verifies that
6110 # loading caused no symbol reading complaints.
6112 proc gdb_load_no_complaints
{ arg } {
6113 global gdb_prompt gdb_file_cmd_msg decimal
6115 # Temporarily
set complaint to a small non
-zero number.
6120 # Verify that there were no complaints.
6123 "^(Reading symbols from \[^\r\n\]*" \
6124 ")+(Expanding full symbols from \[^\r\n\]*" \
6126 gdb_assert
{[regexp $re $gdb_file_cmd_msg
]} "No complaints"
6129 # gdb_reload
-- load a file into the target. Called before
"running",
6130 # either the first time or after already starting the
program once
,
6131 #
for remote targets. Most files that override gdb_load should now
6132 # override this instead.
6134 # INFERIOR_ARGS contains the arguments to pass to the inferiors
, as a
6135 # single string to
get interpreted by a
shell.
If the target board
6136 # overriding gdb_reload is a
"stub", then it should arrange things such
6137 # these arguments make their way to the inferior process.
6139 proc gdb_reload
{ {inferior_args
{}} } {
6140 #
For the benefit of existing configurations
, default to gdb_load.
6141 # Specifying no file defaults to the executable currently being
6143 return [gdb_load
""]
6146 proc gdb_continue
{ function
} {
6149 return [gdb_test
"continue" ".*Breakpoint $decimal, $function .*" "continue to $function"]
6152 # Default implementation of gdb_init.
6153 proc default_gdb_init
{ test_file_name
} {
6154 global gdb_wrapper_initialized
6155 global gdb_wrapper_target
6156 global gdb_test_file_name
6157 global cleanfiles_target
6158 global cleanfiles_host
6161 # Reset the timeout value to the default. This way
, any testcase
6162 # that changes the timeout value without resetting it cannot affect
6163 # the timeout used in subsequent testcases.
6164 global gdb_test_timeout
6166 set timeout $gdb_test_timeout
6168 if { [regexp
".*gdb\.reverse\/.*" $test_file_name]
6169 && [target_info
exists gdb_reverse_timeout
] } {
6170 set timeout
[target_info gdb_reverse_timeout
]
6173 #
If GDB_INOTIFY is given
, check
for writes to
'.'. This is a
6174 # debugging tool to help confirm that the test suite is
6175 # parallel
-safe. You need
"inotifywait" from the
6176 # inotify
-tools package to use this.
6177 global GDB_INOTIFY inotify_pid
6178 if {[info exists GDB_INOTIFY
] && ![info exists inotify_pid
]} {
6179 global outdir tool inotify_log_file
6181 set exclusions
{outputs temp gdb
[.
](log|sum
) cache}
6182 set exclusion_re
([join $exclusions |
])
6184 set inotify_log_file
[standard_temp_file inotify.out
]
6185 set inotify_pid
[exec inotifywait
-r
-m
-e
move,create
,delete . \
6186 --exclude $exclusion_re \
6187 |
& tee
-a $outdir
/$tool.
log $inotify_log_file
&]
6189 # Wait
for the watches
; hopefully this is long enough.
6192 # Clear the
log so that we don
't emit a warning the first time
6194 set fd [open $inotify_log_file w]
6198 # Block writes to all banned variables, and invocation of all
6199 # banned procedures...
6200 global banned_variables
6201 global banned_procedures
6202 global banned_traced
6203 if (!$banned_traced) {
6204 foreach banned_var $banned_variables {
6205 global "$banned_var"
6206 trace add variable "$banned_var" write error
6208 foreach banned_proc $banned_procedures {
6209 global "$banned_proc"
6210 trace add execution "$banned_proc" enter error
6215 # We set LC_ALL, LC_CTYPE, and LANG to C so that we get the same
6216 # messages as expected.
6221 # Don't let a .inputrc file or an existing setting of INPUTRC mess
6222 # up the test results. Certain tests
(style tests and TUI tests
)
6223 # want to
set the terminal to a non
-"dumb" value, and for those we
6224 # want to disable bracketed paste
mode. Versions of Readline
6225 # before
8.0 will not understand this and will issue a warning.
6226 # We tried using a $
if to guard it
, but Readline
8.1 had a bug in
6227 # its version
-comparison code that prevented this
for working.
6228 setenv INPUTRC
[cached_file inputrc
"set enable-bracketed-paste off"]
6230 # This disables style output
, which would interfere with many
6234 #
If DEBUGINFOD_URLS is
set, gdb will try to download sources and
6235 # debug
info for f.i.
system libraries. Prevent this.
6236 if { [is_remote host
] } {
6237 # See initialization of INTERNAL_GDBFLAGS.
6239 # Using
"set debuginfod enabled off" in INTERNAL_GDBFLAGS interferes
6240 # with the gdb.debuginfod test
-cases
, so use the unsetenv method
for
6242 unset
-nocomplain
::env
(DEBUGINFOD_URLS
)
6245 # Ensure that GDBHISTFILE and GDBHISTSIZE are removed from the
6246 # environment
, we don
't want these modifications to the history
6248 unset -nocomplain ::env(GDBHISTFILE)
6249 unset -nocomplain ::env(GDBHISTSIZE)
6251 # Ensure that XDG_CONFIG_HOME is not set. Some tests setup a fake
6252 # home directory in order to test loading settings from gdbinit.
6253 # If XDG_CONFIG_HOME is set then GDB will load a gdbinit from
6254 # there (if one is present) rather than the home directory setup
6256 unset -nocomplain ::env(XDG_CONFIG_HOME)
6258 # Initialize GDB's pty with a fixed size
, to make sure we avoid pagination
6259 # during startup. See
"man expect" for details about stty_init.
6261 set stty_init
"rows 25 cols 80"
6263 # Some tests
(for example gdb.base
/maint.exp
) shell out from gdb to use
6264 # grep. Clear GREP_OPTIONS to make the behavior predictable
,
6265 # especially having color output turned
on can cause tests to fail.
6266 setenv GREP_OPTIONS
""
6268 # Clear $gdbserver_reconnect_p.
6269 global gdbserver_reconnect_p
6270 set gdbserver_reconnect_p
1
6271 unset gdbserver_reconnect_p
6273 # Clear $last_loaded_file
6274 global last_loaded_file
6275 unset
-nocomplain last_loaded_file
6277 # Reset GDB number of instances
6278 global gdb_instances
6281 set cleanfiles_target
{}
6282 set cleanfiles_host
{}
6284 set gdb_test_file_name
[file rootname
[file tail $test_file_name
]]
6286 # Make sure that the wrapper is rebuilt
6287 # with the appropriate multilib option.
6288 if { $gdb_wrapper_target
!= [current_target_name
] } {
6289 set gdb_wrapper_initialized
0
6292 # Unlike most tests
, we have a small number of tests that generate
6293 # a very large amount of output. We therefore increase the expect
6294 # buffer size to be able to contain the entire test output. This
6295 # is especially needed by gdb.base
/info-macros.exp.
6297 # Also
set this value
for the currently running GDB.
6298 match_max
[match_max
-d
]
6300 # We want to add the
name of the TCL testcase to the PASS
/FAIL messages.
6301 set pf_prefix
"[file tail [file dirname $test_file_name]]/[file tail $test_file_name]:"
6304 if [target_info
exists gdb_prompt
] {
6305 set gdb_prompt
[target_info gdb_prompt
]
6307 set gdb_prompt
"\\(gdb\\)"
6310 if [info exists use_gdb_stub
] {
6314 gdb_setup_known_globals
6316 if { [info procs
::gdb_tcl_unknown
] != "" } {
6317 # Dejagnu overrides proc unknown. The dejagnu version may trigger in a
6318 # test
-case but abort the entire test run. To fix this
, we install a
6319 # local version here
, which reverts dejagnu
's override, and restore
6320 # dejagnu's version in gdb_finish.
6321 rename ::unknown
::dejagnu_unknown
6322 proc unknown
{ args } {
6323 # Use tcl
's unknown.
6324 set cmd [lindex $args 0]
6325 unresolved "testcase aborted due to invalid command name: $cmd"
6326 return [uplevel 1 ::gdb_tcl_unknown $args]
6331 # Return a path using GDB_PARALLEL.
6332 # ARGS is a list of path elements to append to "$objdir/$GDB_PARALLEL".
6333 # GDB_PARALLEL must be defined, the caller must check.
6335 # The default value for GDB_PARALLEL is, canonically, ".".
6336 # The catch is that tests don't expect an additional
"./" in file paths so
6337 # omit
any directory
for the default case.
6338 # GDB_PARALLEL is written as
"yes" for the default case in Makefile.in to mark
6339 # its special handling.
6341 proc make_gdb_parallel_path
{ args } {
6342 global GDB_PARALLEL objdir
6343 set joiner
[list
"file" "join" $objdir]
6344 if { [info exists GDB_PARALLEL
] && $GDB_PARALLEL
!= "yes" } {
6345 lappend joiner $GDB_PARALLEL
6347 set joiner
[concat $joiner $
args]
6348 return [eval $joiner
]
6351 # Turn BASENAME into a full file
name in the standard output
6352 # directory. It is ok
if BASENAME is the empty string
; in this case
6353 # the directory is returned.
6355 proc standard_output_file
{basename
} {
6356 global objdir subdir gdb_test_file_name
6358 set dir [make_gdb_parallel_path outputs $subdir $gdb_test_file_name
]
6360 #
If running
on MinGW
, replace
/c
/foo with c
:/foo
6361 if { [ishost
*-*-mingw
*] } {
6362 set dir [exec sh
-c
"cd ${dir} && pwd -W"]
6364 return [file join $
dir $basename
]
6367 # Turn BASENAME into a file
name on host.
6369 proc host_standard_output_file
{ basename
} {
6370 if { [is_remote host
] } {
6373 return [standard_output_file $basename
]
6377 # Turn BASENAME into a full file
name in the standard output directory.
If
6378 # GDB has been launched more than once
then append the
count, starting with
6381 proc standard_output_file_with_gdb_instance
{basename
} {
6382 global gdb_instances
6383 set count $gdb_instances
6386 return [standard_output_file $basename
]
6388 return [standard_output_file $
{basename
}.$
{count}]
6391 #
Return the
name of a file in our standard temporary directory.
6393 proc standard_temp_file
{basename
} {
6394 # Since a particular runtest invocation is only executing a single test
6395 # file at
any given time
, we can use the runtest pid to build the
6396 # path of the temp directory.
6397 set dir [make_gdb_parallel_path temp
[pid
]]
6399 return [file join $
dir $basename
]
6402 #
Rename file A to file B
, if B does not already
exists. Otherwise
, leave B
6403 # as is and
delete A.
Return 1 if rename happened.
6405 proc tentative_rename
{ a b
} {
6406 global errorInfo errorCode
6407 set code
[catch
{file
rename -- $a $b
} result
]
6408 if { $code
== 1 && [lindex $errorCode
0] == "POSIX" \
6409 && [lindex $errorCode
1] == "EEXIST" } {
6414 return -code error
-errorinfo $errorInfo
-errorcode $errorCode $result
6415 } elseif
{$code
> 1} {
6416 return -code $code $result
6421 # Create a file with
name FILENAME and contents TXT in the
cache directory.
6422 #
If EXECUTABLE
, mark the new file
for execution.
6424 proc cached_file
{ filename txt
{executable
0}} {
6425 set filename
[make_gdb_parallel_path
cache $filename
]
6427 if { [file
exists $filename
] } {
6431 set dir [file dirname $filename
]
6434 set tmp_filename $filename.
[pid
]
6435 set fd
[open $tmp_filename w
]
6439 if { $executable
} {
6440 exec chmod
+x $tmp_filename
6442 tentative_rename $tmp_filename $filename
6447 #
Return a wrapper around gdb that prevents generating a core file.
6449 proc gdb_no_core
{ } {
6453 [join
[list exec $
::GDB
{"$@"}]]]
6454 set script
[join $script
"\n"]
6455 return [cached_file gdb
-no
-core.sh $script
1]
6458 #
Set 'testfile', 'srcfile', and
'binfile'.
6460 #
ARGS is a list of source file specifications.
6461 # Without
any arguments
, the .exp file
's base name is used to
6462 # compute the source file name. The ".c" extension is added in this case.
6463 # If ARGS is not empty, each entry is a source file specification.
6464 # If the specification starts with a "." or "-", it is treated as a suffix
6465 # to append to the .exp file's base
name.
6466 #
If the specification is the empty string
, it is treated as
if it
6468 # Otherwise it is a file
name.
6469 # The first file in the list is used to
set the
'srcfile' global.
6470 # Each subsequent
name is used to
set 'srcfile2', 'srcfile3', etc.
6472 # Most tests should
call this without arguments.
6474 #
If a completely different binary file
name is needed
, then it
6475 # should be handled in the .exp file with a suitable comment.
6477 proc standard_testfile
{args} {
6478 global gdb_test_file_name
6480 global gdb_test_file_last_vars
6483 global testfile binfile
6485 set testfile $gdb_test_file_name
6486 set binfile
[standard_output_file $
{testfile
}]
6488 if {[llength $
args] == 0} {
6492 # Unset our previous output variables.
6493 # This can help catch hidden bugs.
6494 if {[info exists gdb_test_file_last_vars
]} {
6495 foreach varname $gdb_test_file_last_vars
{
6497 catch
{unset $varname
}
6500 #
'executable' is often
set by tests.
6501 set gdb_test_file_last_vars
{executable
}
6505 set varname srcfile$suffix
6508 # Handle an extension.
6512 set first
[string range $
arg 0 0]
6513 if { $first
== "." || $first == "-" } {
6514 set arg $testfile$
arg
6519 lappend gdb_test_file_last_vars $varname
6521 if {$suffix
== ""} {
6529 # The default timeout used when testing GDB commands. We want to use
6530 # the same timeout as the default dejagnu timeout
, unless the user has
6531 # already provided a specific value
(probably through a site.exp file
).
6532 global gdb_test_timeout
6533 if ![info exists gdb_test_timeout
] {
6534 set gdb_test_timeout $timeout
6537 # A list of global variables that GDB testcases should not use.
6538 # We try to prevent their use by monitoring write accesses and raising
6539 # an error when that happens.
6540 set banned_variables
{ bug_id prms_id
}
6542 # A list of procedures that GDB testcases should not use.
6543 # We try to prevent their use by monitoring invocations and raising
6544 # an error when that happens.
6545 set banned_procedures
{ strace
}
6547 # gdb_init is called by runtest at start
, but also by several
6548 # tests directly
; gdb_finish is only called from within runtest after
6549 # each test source execution.
6550 # Placing several traces by repetitive calls to gdb_init leads
6551 # to problems
, as only one
trace is removed in gdb_finish.
6552 # To overcome this possible problem
, we add a
variable that records
6553 #
if the banned variables and procedures are already traced.
6556 # Global array that holds the
name of all global variables at the time
6557 # a test script is started. After the test script has completed
any
6558 # global not in this list is deleted.
6559 array
set gdb_known_globals
{}
6561 # Setup the GDB_KNOWN_GLOBALS array with the names of all current
6563 proc gdb_setup_known_globals
{} {
6564 global gdb_known_globals
6566 array
set gdb_known_globals
{}
6567 foreach varname
[info globals
] {
6568 set gdb_known_globals
($varname
) 1
6572 # Cleanup the global namespace.
Any global not in the
6573 # GDB_KNOWN_GLOBALS array is unset
, this ensures we don
't "leak"
6574 # globals from one test script to another.
6575 proc gdb_cleanup_globals {} {
6576 global gdb_known_globals gdb_persistent_globals
6578 foreach varname [info globals] {
6579 if {![info exists gdb_known_globals($varname)]} {
6580 if { [info exists gdb_persistent_globals($varname)] } {
6583 uplevel #0 unset $varname
6588 # Create gdb_tcl_unknown, a copy tcl's
::unknown
, provided it
's present as a
6590 set temp [interp create]
6591 if { [interp eval $temp "info procs ::unknown"] != "" } {
6592 set old_args [interp eval $temp "info args ::unknown"]
6593 set old_body [interp eval $temp "info body ::unknown"]
6594 eval proc gdb_tcl_unknown {$old_args} {$old_body}
6599 # GDB implementation of ${tool}_init. Called right before executing the
6601 # Overridable function -- you can override this function in your
6603 proc gdb_init { args } {
6604 # A baseboard file overriding this proc and calling the default version
6605 # should behave the same as this proc. So, don't add code here
, but to
6606 # the default version instead.
6607 return [default_gdb_init
{*}$
args]
6610 # GDB implementation of $
{tool
}_finish. Called right after executing the
6612 proc gdb_finish
{ } {
6613 global gdbserver_reconnect_p
6615 global cleanfiles_target
6616 global cleanfiles_host
6617 global known_globals
6619 if { [info procs
::gdb_tcl_unknown
] != "" } {
6620 # Restore dejagnu
's version of proc unknown.
6622 rename ::dejagnu_unknown ::unknown
6625 # Exit first, so that the files are no longer in use.
6628 if { [llength $cleanfiles_target] > 0 } {
6629 eval remote_file target delete $cleanfiles_target
6630 set cleanfiles_target {}
6632 if { [llength $cleanfiles_host] > 0 } {
6633 eval remote_file host delete $cleanfiles_host
6634 set cleanfiles_host {}
6637 # Unblock write access to the banned variables. Dejagnu typically
6638 # resets some of them between testcases.
6639 global banned_variables
6640 global banned_procedures
6641 global banned_traced
6642 if ($banned_traced) {
6643 foreach banned_var $banned_variables {
6644 global "$banned_var"
6645 trace remove variable "$banned_var" write error
6647 foreach banned_proc $banned_procedures {
6648 global "$banned_proc"
6649 trace remove execution "$banned_proc" enter error
6654 global gdb_finish_hooks
6655 foreach gdb_finish_hook $gdb_finish_hooks {
6658 set gdb_finish_hooks [list]
6664 set debug_format "unknown"
6666 # Run the gdb command "info source" and extract the debugging format
6667 # information from the output and save it in debug_format.
6669 proc get_debug_format { } {
6674 set debug_format "unknown"
6675 send_gdb "info source\n"
6677 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
6678 set debug_format $expect_out(1,string)
6679 verbose "debug format is $debug_format"
6682 -re "No current source file.\r\n$gdb_prompt $" {
6683 perror "get_debug_format used when no current source file"
6686 -re "$gdb_prompt $" {
6687 warning "couldn't check debug format
(no valid response
).
"
6691 warning
"couldn't check debug format (timeout)."
6697 #
Return true
if FORMAT matches the debug format the current test was
6698 # compiled with. FORMAT is a
shell-style globbing pattern
; it can use
6699 # `
*', `[...]', and so
on.
6701 # This function depends
on variables
set by `get_debug_format
', above.
6703 proc test_debug_format {format} {
6706 return [expr [string match $format $debug_format] != 0]
6709 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
6710 # COFF, stabs, etc). If that format matches the format that the
6711 # current test was compiled with, then the next test is expected to
6712 # fail for any target. Returns 1 if the next test or set of tests is
6713 # expected to fail, 0 otherwise (or if it is unknown). Must have
6714 # previously called get_debug_format.
6715 proc setup_xfail_format { format } {
6716 set ret [test_debug_format $format]
6724 # gdb_get_line_number TEXT [FILE]
6726 # Search the source file FILE, and return the line number of the
6727 # first line containing TEXT. If no match is found, an error is thrown.
6729 # TEXT is a string literal, not a regular expression.
6731 # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is
6732 # specified, and does not start with "/", then it is assumed to be in
6733 # "$srcdir/$subdir". This is awkward, and can be fixed in the future,
6734 # by changing the callers and the interface at the same time.
6735 # In particular: gdb.base/break.exp, gdb.base/condbreak.exp,
6736 # gdb.base/ena-dis-br.exp.
6738 # Use this function to keep your test scripts independent of the
6739 # exact line numbering of the source file. Don't write
:
6741 # send_gdb
"break 20"
6743 # This means that
if anyone ever edits your test
's source file,
6744 # your test could break. Instead, put a comment like this on the
6745 # source file line you want to break at:
6747 # /* breakpoint spot: frotz.exp: test name */
6749 # and then write, in your test script (which we assume is named
6752 # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
6754 # (Yes, Tcl knows how to handle the nested quotes and brackets.
6757 # % puts "foo [lindex "bar baz" 1]"
6760 # Tcl is quite clever, for a little stringy language.)
6764 # The previous implementation of this procedure used the gdb search command.
6765 # This version is different:
6767 # . It works with MI, and it also works when gdb is not running.
6769 # . It operates on the build machine, not the host machine.
6771 # . For now, this implementation fakes a current directory of
6772 # $srcdir/$subdir to be compatible with the old implementation.
6773 # This will go away eventually and some callers will need to
6776 # . The TEXT argument is literal text and matches literally,
6777 # not a regular expression as it was before.
6779 # . State changes in gdb, such as changing the current file
6780 # and setting $_, no longer happen.
6782 # After a bit of time we can forget about the differences from the
6783 # old implementation.
6785 # --chastain 2004-08-05
6787 proc gdb_get_line_number { text { file "" } } {
6792 if {"$file" == ""} {
6795 if {![regexp "^/" "$file"]} {
6796 set file "$srcdir/$subdir/$file"
6799 if {[catch { set fd [open "$file"] } message]} {
6804 for { set line 1 } { 1 } { incr line } {
6805 if {[catch { set nchar [gets "$fd" body] } message]} {
6811 if {[string first "$text" "$body"] >= 0} {
6817 if {[catch { close "$fd" } message]} {
6822 error "undefined tag \"$text\""
6828 # Continue the program until it ends.
6830 # MSSG is the error message that gets printed. If not given, a
6832 # COMMAND is the command to invoke. If not given, "continue" is
6834 # ALLOW_EXTRA is a flag indicating whether the test should expect
6835 # extra output between the "Continuing." line and the program
6836 # exiting. By default it is zero; if nonzero, any extra output
6839 proc gdb_continue_to_end {{mssg ""} {command continue} {allow_extra 0}} {
6840 global inferior_exited_re use_gdb_stub
6843 set text "continue until exit"
6845 set text "continue until exit at $mssg"
6853 # By default, we don't rely
on exit
() behavior of remote stubs
--
6854 # it
's common for exit() to be implemented as a simple infinite
6855 # loop, or a forced crash/reset. For native targets, by default, we
6856 # assume process exit is reported as such. If a non-reliable target
6857 # is used, we set a breakpoint at exit, and continue to that.
6858 if { [target_info exists exit_is_reliable] } {
6859 set exit_is_reliable [target_info exit_is_reliable]
6861 set exit_is_reliable [expr ! $use_gdb_stub]
6864 if { ! $exit_is_reliable } {
6865 if {![gdb_breakpoint "exit"]} {
6868 gdb_test $command "Continuing..*Breakpoint .*exit.*" \
6871 # Continue until we exit. Should not stop again.
6872 # Don't bother to check the output of the
program, that may be
6873 # extremely tough
for some remote systems.
6875 "Continuing.\[\r\n0-9\]+${extra}(... EXIT code 0\[\r\n\]+|$inferior_exited_re normally).*"\
6880 proc rerun_to_main
{} {
6881 global gdb_prompt use_gdb_stub
6886 -re
".*Breakpoint .*main .*$gdb_prompt $"\
6887 {pass
"rerun to main" ; return 0}
6888 -re
"$gdb_prompt $"\
6889 {fail
"rerun to main" ; return 0}
6890 timeout
{fail
"(timeout) rerun to main" ; return 0}
6895 -re
"The program .* has been started already.*y or n. $" {
6896 send_gdb
"y\n" answer
6899 -re
"Starting program.*$gdb_prompt $"\
6900 {pass
"rerun to main" ; return 0}
6901 -re
"$gdb_prompt $"\
6902 {fail
"rerun to main" ; return 0}
6903 timeout
{fail
"(timeout) rerun to main" ; return 0}
6908 #
Return true
if EXECUTABLE contains a .gdb_index or .debug_names index section.
6910 proc exec_has_index_section
{ executable
} {
6911 set readelf_program
[gdb_find_readelf
]
6912 set res
[catch
{exec $readelf_program
-S $executable \
6913 | grep
-E
"\.gdb_index|\.debug_names" }]
6920 #
Return list with major and minor version of readelf
, or an empty list.
6921 gdb_caching_proc readelf_version
{} {
6922 set readelf_program
[gdb_find_readelf
]
6923 set res
[catch
{exec $readelf_program
--version
} output
]
6927 set lines
[split $output
\n]
6928 set line
[lindex $lines
0]
6929 set res
[regexp
{[ \t]+([0-9]+)[.
]([0-9]+)[^
\t]*$
} \
6930 $line dummy major minor
]
6934 return [list $major $minor
]
6937 #
Return 1 if readelf prints the PIE flag
, 0 if is doesn
't, and -1 if unknown.
6938 proc readelf_prints_pie { } {
6939 set version [readelf_version]
6940 if { [llength $version] == 0 } {
6943 set major [lindex $version 0]
6944 set minor [lindex $version 1]
6945 # It would be better to construct a PIE executable and test if the PIE
6946 # flag is printed by readelf, but we cannot reliably construct a PIE
6947 # executable if the multilib_flags dictate otherwise
6948 # (--target_board=unix/-no-pie/-fno-PIE).
6949 return [version_at_least $major $minor 2 26]
6952 # Return 1 if EXECUTABLE is a Position Independent Executable, 0 if it is not,
6953 # and -1 if unknown.
6955 proc exec_is_pie { executable } {
6956 set res [readelf_prints_pie]
6960 set readelf_program [gdb_find_readelf]
6961 # We're not testing readelf
-d | grep
"FLAGS_1.*Flags:.*PIE"
6962 # because the PIE flag is not
set by all versions of gold
, see PR
6964 set res
[catch
{exec $readelf_program
-h $executable
} output
]
6968 set res
[regexp
-line
{^
[ \t]*Type
:[ \t]*DYN \
((Position
-Independent Executable|Shared object
) file\
)$
} \
6976 #
Return false
if a test should be skipped due to lack of floating
6977 # point support or GDB can
't fetch the contents from floating point
6980 gdb_caching_proc allow_float_test {} {
6981 if [target_info exists gdb,skip_float_tests] {
6985 # There is an ARM kernel ptrace bug that hardware VFP registers
6986 # are not updated after GDB ptrace set VFP registers. The bug
6987 # was introduced by kernel commit 8130b9d7b9d858aa04ce67805e8951e3cb6e9b2f
6988 # in 2012 and is fixed in e2dfb4b880146bfd4b6aa8e138c0205407cebbaf
6989 # in May 2016. In other words, kernels older than 4.6.3, 4.4.14,
6990 # 4.1.27, 3.18.36, and 3.14.73 have this bug.
6991 # This kernel bug is detected by check how does GDB change the
6992 # program result by changing one VFP register.
6993 if { [istarget "arm*-*-linux*"] } {
6995 set compile_flags {debug nowarnings }
6997 # Set up, compile, and execute a test program having VFP
6999 set src [standard_temp_file arm_vfp[pid].c]
7000 set exe [standard_temp_file arm_vfp[pid].x]
7002 gdb_produce_source $src {
7007 asm ("vldr d0, [%0]" : : "r" (&d));
7008 asm ("vldr d1, [%0]" : : "r" (&d));
7009 asm (".global break_here\n"
7011 asm ("vcmp.f64 d0, d1\n"
7012 "vmrs APSR_nzcv, fpscr\n"
7013 "bne L_value_different\n"
7016 "L_value_different:\n"
7018 "L_end:\n" : "=r" (ret) :);
7020 /* Return $d0 != $d1. */
7025 verbose "compiling testfile $src" 2
7026 set lines [gdb_compile $src $exe executable $compile_flags]
7029 if {![string match "" $lines]} {
7030 verbose "testfile compilation failed, returning 1" 2
7034 # No error message, compilation succeeded so now run it via gdb.
7035 # Run the test up to 5 times to detect whether ptrace can
7036 # correctly update VFP registers or not.
7037 set allow_vfp_test 1
7038 for {set i 0} {$i < 5} {incr i} {
7039 global gdb_prompt srcdir subdir
7043 gdb_reinitialize_dir $srcdir/$subdir
7047 gdb_test "break *break_here"
7048 gdb_continue_to_breakpoint "break_here"
7050 # Modify $d0 to a different value, so the exit code should
7052 gdb_test "set \$d0 = 5.0"
7054 set test "continue to exit"
7055 gdb_test_multiple "continue" "$test" {
7056 -re "exited with code 01.*$gdb_prompt $" {
7058 -re "exited normally.*$gdb_prompt $" {
7059 # However, the exit code is 0. That means something
7060 # wrong in setting VFP registers.
7061 set allow_vfp_test 0
7068 remote_file build delete $exe
7070 return $allow_vfp_test
7075 # Print a message and return true if a test should be skipped
7076 # due to lack of stdio support.
7078 proc gdb_skip_stdio_test { msg } {
7079 if [target_info exists gdb,noinferiorio] {
7080 verbose "Skipping test '$msg
': no inferior i/o."
7086 proc gdb_skip_bogus_test { msg } {
7090 # Return true if XML support is enabled in the host GDB.
7091 # NOTE: This must be called while gdb is *not* running.
7093 gdb_caching_proc allow_xml_test {} {
7098 if { [info exists gdb_spawn_id] } {
7099 error "GDB must not be running in allow_xml_tests."
7102 set xml_file [gdb_remote_download host "${srcdir}/gdb.xml/trivial.xml"]
7106 gdb_test_multiple "set tdesc filename $xml_file" "" {
7107 -re ".*XML support was disabled at compile time.*$gdb_prompt $" {
7110 -re ".*$gdb_prompt $" { }
7113 return [expr {!$xml_missing}]
7116 # Return true if argv[0] is available.
7118 gdb_caching_proc gdb_has_argv0 {} {
7121 # Compile and execute a test program to check whether argv[0] is available.
7122 gdb_simple_compile has_argv0 {
7123 int main (int argc, char **argv) {
7130 proc gdb_has_argv0_1 { exe } {
7131 global srcdir subdir
7132 global gdb_prompt hex
7136 gdb_reinitialize_dir $srcdir/$subdir
7139 # Set breakpoint on main.
7140 gdb_test_multiple "break -q main" "break -q main" {
7141 -re "Breakpoint.*${gdb_prompt} $" {
7143 -re "${gdb_prompt} $" {
7150 gdb_test_multiple "" "run to main" {
7151 -re "Breakpoint.*${gdb_prompt} $" {
7153 -re "${gdb_prompt} $" {
7158 set old_elements "200"
7159 set test "show print elements"
7160 gdb_test_multiple $test $test {
7161 -re "Limit on string chars or array elements to print is (\[^\r\n\]+)\\.\r\n$gdb_prompt $" {
7162 set old_elements $expect_out(1,string)
7165 set old_repeats "200"
7166 set test "show print repeats"
7167 gdb_test_multiple $test $test {
7168 -re "Threshold for repeated print elements is (\[^\r\n\]+)\\.\r\n$gdb_prompt $" {
7169 set old_repeats $expect_out(1,string)
7172 gdb_test_no_output "set print elements unlimited" ""
7173 gdb_test_no_output "set print repeats unlimited" ""
7176 # Check whether argc is 1.
7177 gdb_test_multiple "p argc" "p argc" {
7178 -re " = 1\r\n${gdb_prompt} $" {
7180 gdb_test_multiple "p argv\[0\]" "p argv\[0\]" {
7181 -re " = $hex \".*[file tail $exe]\"\r\n${gdb_prompt} $" {
7184 -re "${gdb_prompt} $" {
7188 -re "${gdb_prompt} $" {
7192 gdb_test_no_output "set print elements $old_elements" ""
7193 gdb_test_no_output "set print repeats $old_repeats" ""
7198 set result [gdb_has_argv0_1 $obj]
7204 && ([istarget *-*-linux*]
7205 || [istarget *-*-freebsd*] || [istarget *-*-kfreebsd*]
7206 || [istarget *-*-netbsd*] || [istarget *-*-knetbsd*]
7207 || [istarget *-*-openbsd*]
7208 || [istarget *-*-darwin*]
7209 || [istarget *-*-solaris*]
7210 || [istarget *-*-aix*]
7211 || [istarget *-*-gnu*]
7212 || [istarget *-*-cygwin*] || [istarget *-*-mingw32*]
7213 || [istarget *-*-*djgpp*] || [istarget *-*-go32*]
7214 || [istarget *-wince-pe] || [istarget *-*-mingw32ce*]
7215 || [istarget *-*-osf*]
7216 || [istarget *-*-dicos*]
7217 || [istarget *-*-nto*]
7218 || [istarget *-*-*vms*]
7219 || [istarget *-*-lynx*178]) } {
7220 fail "argv\[0\] should be available on this target"
7226 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
7227 # ${binfile}.dbglnk, which is just like the executable ($binfile) but without
7228 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
7229 # the name of a debuginfo only file. This file will be stored in the same
7232 # Functions for separate debug info testing
7234 # starting with an executable:
7235 # foo --> original executable
7237 # at the end of the process we have:
7238 # foo.stripped --> foo w/o debug info
7239 # foo.debug --> foo's debug
info
7240 # foo
--> like foo
, but with a new .gnu_debuglink section pointing to foo.debug.
7242 #
Fetch the build id from the file.
7243 # Returns
"" if there is none.
7245 proc get_build_id
{ filename
} {
7246 if { ([istarget
"*-*-mingw*"]
7247 ||
[istarget
*-*-cygwin
*]) } {
7248 set objdump_program
[gdb_find_objdump
]
7249 set result
[catch
{set data
[exec $objdump_program
-p $filename | grep signature | cut
"-d " -f4]} output]
7250 verbose
"result is $result"
7251 verbose
"output is $output"
7257 set tmp
[standard_output_file
"${filename}-tmp"]
7258 set objcopy_program
[gdb_find_objcopy
]
7259 set result
[catch
"exec $objcopy_program -j .note.gnu.build-id -O binary $filename $tmp" output]
7260 verbose
"result is $result"
7261 verbose
"output is $output"
7266 fconfigure $fi
-translation binary
7267 # Skip the NOTE header.
7272 if {![string compare $data
""]} {
7275 #
Convert it to hex.
7276 binary scan $data H
* data
7281 #
Return the build
-id hex string
(usually
160 bits as
40 hex characters
)
7282 # converted to the form
: .build
-id
/ab
/cdef1234..
.89.debug
7283 #
Return "" if no build-id found.
7284 proc build_id_debug_filename_get
{ filename
} {
7285 set data
[get_build_id $filename
]
7286 if { $data
== "" } {
7289 regsub
{^..
} $data
{\
0/} data
7290 return ".build-id/${data}.debug"
7293 # DEST should be a file compiled with debug information. This proc
7294 # creates two new files DEST.debug which contains the debug
7295 # information extracted from DEST
, and DEST.stripped
, which is a copy
7296 # of DEST with the debug information removed. A
'.gnu_debuglink'
7297 # section will be added to DEST.stripped that points to DEST.debug.
7299 #
If ARGS is passed
, it is a list of optional flags. The currently
7300 # supported flags are
:
7302 #
- no
-main
: remove the symbol entry
for main from the separate
7303 # debug file DEST.debug
,
7304 #
- no
-debuglink
: don
't add the '.gnu_debuglink
' section to
7307 # Function returns zero on success. Function will return non-zero failure code
7308 # on some targets not supporting separate debug info (such as i386-msdos).
7310 proc gdb_gnu_strip_debug { dest args } {
7312 # Use the first separate debug info file location searched by GDB so the
7313 # run cannot be broken by some stale file searched with higher precedence.
7314 set debug_file "${dest}.debug"
7316 set strip_to_file_program [transform strip]
7317 set objcopy_program [gdb_find_objcopy]
7319 set debug_link [file tail $debug_file]
7320 set stripped_file "${dest}.stripped"
7322 # Get rid of the debug info, and store result in stripped_file
7323 # something like gdb/testsuite/gdb.base/blah.stripped.
7324 set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
7325 verbose "result is $result"
7326 verbose "output is $output"
7331 # Workaround PR binutils/10802:
7332 # Preserve the 'x
' bit also for PIEs (Position Independent Executables).
7333 set perm [file attributes ${dest} -permissions]
7334 file attributes ${stripped_file} -permissions $perm
7336 # Get rid of everything but the debug info, and store result in debug_file
7337 # This will be in the .debug subdirectory, see above.
7338 set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
7339 verbose "result is $result"
7340 verbose "output is $output"
7345 # If no-main is passed, strip the symbol for main from the separate
7346 # file. This is to simulate the behavior of elfutils's eu
-strip, which
7347 # leaves the symtab in the original file only. There
's no way to get
7348 # objcopy or strip to remove the symbol table without also removing the
7349 # debugging sections, so this is as close as we can get.
7350 if {[lsearch -exact $args "no-main"] != -1} {
7351 set result [catch "exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp" output]
7352 verbose "result is $result"
7353 verbose "output is $output"
7357 file delete "${debug_file}"
7358 file rename "${debug_file}-tmp" "${debug_file}"
7361 # Unless the "no-debuglink" flag is passed, then link the two
7362 # previous output files together, adding the .gnu_debuglink
7363 # section to the stripped_file, containing a pointer to the
7364 # debug_file, save the new file in dest.
7365 if {[lsearch -exact $args "no-debuglink"] == -1} {
7366 set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
7367 verbose "result is $result"
7368 verbose "output is $output"
7374 # Workaround PR binutils/10802:
7375 # Preserve the 'x
' bit also for PIEs (Position Independent Executables).
7376 set perm [file attributes ${stripped_file} -permissions]
7377 file attributes ${dest} -permissions $perm
7382 # Test the output of GDB_COMMAND matches the pattern obtained
7383 # by concatenating all elements of EXPECTED_LINES. This makes
7384 # it possible to split otherwise very long string into pieces.
7385 # If third argument TESTNAME is not empty, it's used as the
name of the
7386 # test to be printed
on pass
/fail.
7387 proc help_test_raw
{ gdb_command expected_lines
{testname
{}} } {
7388 set expected_output
[join $expected_lines
""]
7389 if {$testname
!= {}} {
7390 gdb_test
"${gdb_command}" "${expected_output}" $testname
7394 gdb_test
"${gdb_command}" "${expected_output}"
7397 # A regexp that matches the end of help CLASS|PREFIX_COMMAND
7398 set help_list_trailer
{
7399 "Type \"apropos word\" to search for commands related to \"word\"\.[\r\n]+"
7400 "Type \"apropos -v word\" for full documentation of commands related to \"word\"\.[\r\n]+"
7401 "Command name abbreviations are allowed if unambiguous\."
7404 # Test the output of
"help COMMAND_CLASS". EXPECTED_INITIAL_LINES
7405 # are regular expressions that should match the beginning of output
,
7406 # before the list of commands in that class.
7407 # LIST_OF_COMMANDS are regular expressions that should match the
7408 # list of commands in that class.
If empty
, the command list will be
7409 # matched automatically. The presence of standard epilogue will be tested
7411 #
If last
argument TESTNAME is not empty
, it
's used as the name of the
7412 # test to be printed on pass/fail.
7413 # Notice that the '[' and ']' characters don't need to be escaped
for strings
7414 # wrapped in
{} braces.
7415 proc test_class_help
{ command_class expected_initial_lines
{list_of_commands
{}} {testname
{}} } {
7416 global help_list_trailer
7417 if {[llength $list_of_commands
]>0} {
7418 set l_list_of_commands
{"List of commands:[\r\n]+[\r\n]+"}
7419 set l_list_of_commands
[concat $l_list_of_commands $list_of_commands
]
7420 set l_list_of_commands
[concat $l_list_of_commands
{"[\r\n]+[\r\n]+"}]
7422 set l_list_of_commands
{"List of commands\:.*[\r\n]+"}
7425 "Type \"help\" followed by command name for full documentation\.[\r\n]+"
7427 set l_entire_body
[concat $expected_initial_lines $l_list_of_commands \
7428 $l_stock_body $help_list_trailer
]
7430 help_test_raw
"help ${command_class}" $l_entire_body $testname
7433 # Like test_class_help but specialised to test
"help user-defined".
7434 proc test_user_defined_class_help
{ {list_of_commands
{}} {testname
{}} } {
7435 test_class_help
"user-defined" {
7436 "User-defined commands\.[\r\n]+"
7437 "The commands in this class are those defined by the user\.[\r\n]+"
7438 "Use the \"define\" command to define a command\.[\r\n]+"
7439 } $list_of_commands $testname
7443 # COMMAND_LIST should have either one element
-- command to test
, or
7444 # two elements
-- abbreviated command to test
, and full command the first
7445 # element is abbreviation of.
7446 # The command must be a prefix command. EXPECTED_INITIAL_LINES
7447 # are regular expressions that should match the beginning of output
,
7448 # before the list of subcommands. The presence of
7449 # subcommand list and standard epilogue will be tested automatically.
7450 proc test_prefix_command_help
{ command_list expected_initial_lines
args } {
7451 global help_list_trailer
7452 set command
[lindex $command_list
0]
7453 if {[llength $command_list
]>1} {
7454 set full_command
[lindex $command_list
1]
7456 set full_command $command
7458 # Use
'list' and not just
{} because we want variables to
7459 # be expanded in this list.
7460 set l_stock_body
[list\
7461 "List of $full_command subcommands\:.*\[\r\n\]+"\
7462 "Type \"help $full_command\" followed by $full_command subcommand name for full documentation\.\[\r\n\]+"]
7463 set l_entire_body
[concat $expected_initial_lines $l_stock_body $help_list_trailer
]
7464 if {[llength $
args]>0} {
7465 help_test_raw
"help ${command}" $l_entire_body [lindex $args 0]
7467 help_test_raw
"help ${command}" $l_entire_body
7471 # Build executable named EXECUTABLE from specifications that allow
7472 # different options to be passed to different sub
-compilations.
7473 # TESTNAME is the
name of the test
; this is passed to
'untested' if
7475 # OPTIONS is passed to the final link
, using gdb_compile.
If OPTIONS
7476 # contains the option
"pthreads", then gdb_compile_pthreads is used.
7477 #
ARGS is a flat list of source specifications
, of the form
:
7478 #
{ SOURCE1 OPTIONS1
[ SOURCE2 OPTIONS2
]...
}
7479 # Each SOURCE is compiled to an object file using its OPTIONS
,
7480 # using gdb_compile.
7481 # Returns
0 on success
, -1 on failure.
7482 proc build_executable_from_specs
{testname executable options
args} {
7486 set binfile
[standard_output_file $executable
]
7488 set func gdb_compile
7489 set func_index
[lsearch
-regexp $options
{^
(pthreads|shlib|shlib_pthreads|openmp
)$
}]
7490 if {$func_index
!= -1} {
7491 set func
"${func}_[lindex $options $func_index]"
7494 # gdb_compile_shlib and gdb_compile_shlib_pthreads
do not use the
3rd
7495 # parameter. They also requires $sources
while gdb_compile and
7496 # gdb_compile_pthreads require $objects. Moreover they ignore
any options.
7497 if [string match gdb_compile_shlib
* $func
] {
7499 foreach
{s local_options
} $
args {
7500 if {[regexp
"^/" "$s"]} {
7501 lappend sources_path
"$s"
7503 lappend sources_path
"$srcdir/$subdir/$s"
7506 set ret
[$func $sources_path
"${binfile}" $options]
7507 } elseif
{[lsearch
-exact $options rust
] != -1} {
7509 foreach
{s local_options
} $
args {
7510 if {[regexp
"^/" "$s"]} {
7511 lappend sources_path
"$s"
7513 lappend sources_path
"$srcdir/$subdir/$s"
7516 set ret
[gdb_compile_rust $sources_path
"${binfile}" $options]
7520 foreach
{s local_options
} $
args {
7521 if {![regexp
"^/" "$s"]} {
7522 set s
"$srcdir/$subdir/$s"
7524 if { [$func
"${s}" "${binfile}${i}.o" object $local_options] != "" } {
7528 lappend objects
"${binfile}${i}.o"
7531 set ret
[$func $objects
"${binfile}" executable $options]
7541 # Build executable named EXECUTABLE
, from SOURCES.
If SOURCES are not
7542 # provided
, uses $EXECUTABLE.c. The TESTNAME paramer is the
name of test
7543 # to pass to untested
, if something is wrong. OPTIONS are passed
7544 # to gdb_compile directly.
7545 proc build_executable
{ testname executable
{sources
""} {options {debug}} } {
7546 if {[llength $sources
]==0} {
7547 set sources $
{executable
}.c
7550 set arglist
[list $testname $executable $options
]
7551 foreach source $sources
{
7552 lappend arglist $source $options
7555 return [eval build_executable_from_specs $arglist
]
7558 # Starts fresh GDB binary and loads an optional executable into GDB.
7559 # Usage
: clean_restart
[EXECUTABLE
]
7560 # EXECUTABLE is the basename of the binary.
7561 #
Return -1 if starting gdb or loading the executable failed.
7563 proc clean_restart
{{executable
""}} {
7571 # This is a clean restart
, so reset error and warning
count.
7576 # if { [gdb_start] == -1 } {
7579 # but gdb_start is a ${tool}_start proc, which doesn't have a defined
7580 #
return value. So instead
, we test
for errcnt.
7582 if { $errcnt
> 0 } {
7586 gdb_reinitialize_dir $srcdir
/$subdir
7588 if {$executable
!= ""} {
7589 set binfile
[standard_output_file $
{executable
}]
7590 return [gdb_load $
{binfile
}]
7596 # Prepares
for testing by calling build_executable_full
, then
7598 # TESTNAME is the
name of the test.
7599 # Each element in
ARGS is a list of the form
7600 #
{ EXECUTABLE OPTIONS SOURCE_SPEC...
}
7601 # These are passed to build_executable_from_specs
, which see.
7602 # The last EXECUTABLE is passed to clean_restart.
7603 # Returns
0 on success
, non
-zero
on failure.
7604 proc prepare_for_testing_full
{testname
args} {
7605 foreach spec $
args {
7606 if {[eval build_executable_from_specs
[list $testname
] $spec
] == -1} {
7609 set executable
[lindex $spec
0]
7611 clean_restart $executable
7615 # Prepares
for testing
, by calling build_executable
, and
then clean_restart.
7616 # Please refer to build_executable
for parameter description.
7617 proc prepare_for_testing
{ testname executable
{sources
""} {options {debug}}} {
7619 if {[build_executable $testname $executable $sources $options
] == -1} {
7622 clean_restart $executable
7627 #
Retrieve the value of EXP in the inferior
, represented in format
7628 # specified in FMT
(using
"printFMT"). DEFAULT is used as fallback if
7629 # print fails. TEST is the test message to use. It can be omitted
,
7630 # in which case a test message is built from EXP.
7632 proc get_valueof
{ fmt exp default
{test
""} } {
7636 set test
"get valueof \"${exp}\""
7640 gdb_test_multiple
"print${fmt} ${exp}" "$test" {
7641 -re
"\\$\[0-9\]* = (\[^\r\n\]*)\[\r\n\]*$gdb_prompt $" {
7642 set val $expect_out
(1,string
)
7646 fail
"$test (timeout)"
7652 #
Retrieve the value of local var EXP in the inferior. DEFAULT is used as
7653 # fallback
if print fails. TEST is the test message to use. It can be
7654 # omitted
, in which case a test message is built from EXP.
7656 proc get_local_valueof
{ exp default
{test
""} } {
7660 set test
"get local valueof \"${exp}\""
7664 gdb_test_multiple
"info locals ${exp}" "$test" {
7665 -re
"$exp = (\[^\r\n\]*)\[\r\n\]*$gdb_prompt $" {
7666 set val $expect_out
(1,string
)
7670 fail
"$test (timeout)"
7676 #
Retrieve the value of EXP in the inferior
, as a signed decimal value
7677 #
(using
"print /d"). DEFAULT is used as fallback if print fails.
7678 # TEST is the test message to use. It can be omitted
, in which case
7679 # a test message is built from EXP.
7681 proc get_integer_valueof
{ exp default
{test
""} } {
7685 set test
"get integer valueof \"${exp}\""
7689 gdb_test_multiple
"print /d ${exp}" "$test" {
7690 -re
"\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" {
7691 set val $expect_out
(1,string
)
7695 fail
"$test (timeout)"
7701 #
Retrieve the value of EXP in the inferior
, as an hexadecimal value
7702 #
(using
"print /x"). DEFAULT is used as fallback if print fails.
7703 # TEST is the test message to use. It can be omitted
, in which case
7704 # a test message is built from EXP.
7706 proc get_hexadecimal_valueof
{ exp default
{test
""} } {
7710 set test
"get hexadecimal valueof \"${exp}\""
7714 gdb_test_multiple
"print /x ${exp}" $test {
7715 -re
"\\$\[0-9\]* = (0x\[0-9a-zA-Z\]+).*$gdb_prompt $" {
7716 set val $expect_out
(1,string
)
7723 #
Retrieve the size of TYPE in the inferior
, as a decimal value. DEFAULT
7724 # is used as fallback
if print fails. TEST is the test message to use.
7725 # It can be omitted
, in which case a test message is
'sizeof (TYPE)'.
7727 proc get_sizeof
{ type default
{test
""} } {
7728 return [get_integer_valueof
"sizeof (${type})" $default $test]
7731 proc get_target_charset
{ } {
7734 gdb_test_multiple
"show target-charset" "" {
7735 -re
"The target character set is \"auto; currently (\[^\"\]*)\".*$gdb_prompt $" {
7736 return $expect_out
(1,string
)
7738 -re
"The target character set is \"(\[^\"\]*)\".*$gdb_prompt $" {
7739 return $expect_out
(1,string
)
7743 # Pick a reasonable default.
7744 warning
"Unable to read target-charset."
7748 #
Get the address of VAR.
7750 proc get_var_address
{ var
} {
7751 global gdb_prompt hex
7753 # Match output like
:
7755 # $
5 = (int (*)()) 0
7756 # $
6 = (int (*)()) 0x24 <function_bar
>
7758 gdb_test_multiple
"print &${var}" "get address of ${var}" {
7759 -re
"\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $"
7761 pass
"get address of ${var}"
7762 if { $expect_out
(1,string
) == "0" } {
7765 return $expect_out
(1,string
)
7772 #
Return the frame number
for the currently selected frame
7773 proc get_current_frame_number
{{test_name
""}} {
7776 if { $test_name
== "" } {
7777 set test_name
"get current frame number"
7780 gdb_test_multiple
"frame" $test_name {
7781 -re
"#(\[0-9\]+) .*$gdb_prompt $" {
7782 set frame_num $expect_out
(1,string
)
7788 #
Get the current value
for remotetimeout and
return it.
7789 proc get_remotetimeout
{ } {
7793 gdb_test_multiple
"show remotetimeout" "" {
7794 -re
"Timeout limit to wait for target to respond is ($decimal).*$gdb_prompt $" {
7795 return $expect_out
(1,string
)
7799 # Pick the default that gdb uses
7800 warning
"Unable to read remotetimeout"
7804 #
Set the remotetimeout to the specified timeout. Nothing is returned.
7805 proc set_remotetimeout
{ timeout
} {
7808 gdb_test_multiple
"set remotetimeout $timeout" "" {
7809 -re
"$gdb_prompt $" {
7810 verbose
"Set remotetimeout to $timeout\n"
7815 #
Get the target
's current endianness and return it.
7816 proc get_endianness { } {
7819 gdb_test_multiple "show endian" "determine endianness" {
7820 -re ".* (little|big) endian.*\r\n$gdb_prompt $" {
7822 return $expect_out(1,string)
7828 # Get the target's default endianness and
return it.
7829 gdb_caching_proc target_endianness
{} {
7832 set me
"target_endianness"
7834 set src
{ int main
() { return 0; } }
7835 if {![gdb_simple_compile $me $src executable
]} {
7843 set res
[get_endianness
]
7846 remote_file build
delete $
obj
7851 # ROOT and FULL are file names. Returns the relative path from ROOT
7852 # to FULL. Note that FULL must be in a subdirectory of ROOT.
7853 #
For example
, given ROOT
= /usr
/bin and FULL
= /usr
/bin
/ls
, this
7856 proc relative_filename
{root full
} {
7857 set root_split
[file split $root
]
7858 set full_split
[file split $full
]
7860 set len
[llength $root_split
]
7862 if {[eval file join $root_split
]
7863 != [eval file join
[lrange $full_split
0 [expr
{$len
- 1}]]]} {
7864 error
"$full not a subdir of $root"
7867 return [eval file join
[lrange $full_split $len end
]]
7870 #
If GDB_PARALLEL
exists, then set up the parallel
-mode directories.
7871 if {[info exists GDB_PARALLEL
]} {
7872 if {[is_remote host
]} {
7876 [make_gdb_parallel_path outputs
] \
7877 [make_gdb_parallel_path temp
] \
7878 [make_gdb_parallel_path
cache]
7882 #
Set the inferior
's cwd to the output directory, in order to have it
7883 # dump core there. This must be called before the inferior is
7886 proc set_inferior_cwd_to_output_dir {} {
7887 # Note this sets the inferior's cwd
("set cwd"), not GDB's ("cd").
7888 #
If GDB crashes
, we want its core dump in gdb
/testsuite
/, not in
7889 # the testcase
's dir, so we can detect the unexpected core at the
7890 # end of the test run.
7891 if {![is_remote host]} {
7892 set output_dir [standard_output_file ""]
7893 gdb_test_no_output "set cwd $output_dir" \
7894 "set inferior cwd to test directory"
7898 # Get the inferior's PID.
7900 proc get_inferior_pid
{} {
7902 gdb_test_multiple
"inferior" "get inferior pid" {
7903 -re
"process (\[0-9\]*).*$::gdb_prompt $" {
7904 set pid $expect_out
(1,string
)
7911 # Find the kernel
-produced core file dumped
for the current testfile
7912 #
program. PID was the inferior
's pid, saved before the inferior
7913 # exited with a signal, or -1 if not known. If not on a remote host,
7914 # this assumes the core was generated in the output directory.
7915 # Returns the name of the core dump, or empty string if not found.
7917 proc find_core_file {pid} {
7918 # For non-remote hosts, since cores are assumed to be in the
7919 # output dir, which we control, we use a laxer "core.*" glob. For
7920 # remote hosts, as we don't know whether the
dir is being reused
7921 #
for parallel runs
, we use stricter names with no globs. It is
7922 # not clear whether this is really important
, but it preserves
7925 if {![is_remote host
]} {
7926 lappend files core.
*
7927 } elseif
{$pid
!= -1} {
7928 lappend files core.$pid
7930 lappend files $
{::testfile
}.core
7933 foreach file $files
{
7934 if {![is_remote host
]} {
7935 set names
[glob
-nocomplain
[standard_output_file $file
]]
7936 if {[llength $names
] == 1} {
7937 return [lindex $names
0]
7940 if {[remote_file host
exists $file
]} {
7948 # Check
for production of a core file and remove it. PID is the
7949 # inferior
's pid or -1 if not known. TEST is the test's message.
7951 proc remove_core
{pid
{test
""}} {
7953 set test
"cleanup core file"
7956 set file
[find_core_file $pid
]
7958 remote_file host
delete $file
7959 pass
"$test (removed)"
7961 pass
"$test (not found)"
7965 proc core_find
{binfile
{deletefiles
{}} {arg ""}} {
7966 global objdir subdir
7968 set destcore
"$binfile.core"
7969 file
delete $destcore
7971 # Create a core file named
"$destcore" rather than just "core", to
7972 # avoid problems with sys admin types that like to regularly prune all
7973 # files named
"core" from the system.
7975 # Arbitrarily try setting the core size
limit to
"unlimited" since
7976 # this does not hurt
on systems where the command does not work and
7977 # allows us to generate a core
on systems where it does.
7979 # Some systems append
"core" to the name of the program; others append
7980 # the
name of the
program to
"core"; still others (like Linux, as of
7981 # May
2003) create cores named
"core.PID". In the latter case, we
7982 # could have many core files lying around
, and it may be difficult to
7983 # tell which one is ours
, so let
's run the program in a subdirectory.
7985 set coredir [standard_output_file coredir.[getpid]]
7987 catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile} ${arg}; true) >/dev/null 2>&1\""
7988 # remote_exec host "${binfile}"
7989 foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
7990 if [remote_file build exists $i] {
7991 remote_exec build "mv $i $destcore"
7995 # Check for "core.PID", "core.EXEC.PID.HOST.TIME", etc. It's fine
7996 # to use a glob here as we
're looking inside a directory we
7997 # created. Also, this procedure only works on non-remote hosts.
7998 if { $found == 0 } {
7999 set names [glob -nocomplain -directory $coredir core.*]
8000 if {[llength $names] == 1} {
8001 set corefile [file join $coredir [lindex $names 0]]
8002 remote_exec build "mv $corefile $destcore"
8006 if { $found == 0 } {
8007 # The braindamaged HPUX shell quits after the ulimit -c above
8008 # without executing ${binfile}. So we try again without the
8009 # ulimit here if we didn't find a core file above.
8010 # Oh
, I should mention that
any "braindamaged" non-Unix system has
8011 # the same problem. I like the cd bit too
, it
's really neat'n stuff.
8012 catch
"system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\""
8013 foreach i
"${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" {
8014 if [remote_file build
exists $i
] {
8015 remote_exec build
"mv $i $destcore"
8021 # Try to clean up after ourselves.
8022 foreach deletefile $deletefiles
{
8023 remote_file build
delete [file join $coredir $deletefile
]
8025 remote_exec build
"rmdir $coredir"
8027 if { $found
== 0 } {
8028 warning
"can't generate a core file - core tests suppressed - check ulimit -c"
8034 # gdb_target_symbol_prefix compiles a test
program and
then examines
8035 # the output from objdump to determine the prefix
(such as underscore
)
8036 #
for linker symbol prefixes.
8038 gdb_caching_proc gdb_target_symbol_prefix
{} {
8039 #
Compile a simple test
program...
8040 set src
{ int main
() { return 0; } }
8041 if {![gdb_simple_compile target_symbol_prefix $src executable
]} {
8047 set objdump_program
[gdb_find_objdump
]
8048 set result
[catch
"exec $objdump_program --syms $obj" output]
8051 && ![regexp
-lineanchor \
8052 { ([^ a
-zA
-Z0
-9]*)main$
} $output dummy prefix
] } {
8053 verbose
"gdb_target_symbol_prefix: Could not find main in objdump output; returning null prefix" 2
8061 #
Return 1 if target supports scheduler locking
, otherwise
return 0.
8063 gdb_caching_proc target_supports_scheduler_locking
{} {
8066 set me
"gdb_target_supports_scheduler_locking"
8068 set src
{ int main
() { return 0; } }
8069 if {![gdb_simple_compile $me $src executable
]} {
8078 set supports_schedule_locking
-1
8079 set current_schedule_locking_mode
""
8081 set test
"reading current scheduler-locking mode"
8082 gdb_test_multiple
"show scheduler-locking" $test {
8083 -re
"Mode for locking scheduler during execution is \"(\[\^\"\]*)\".*$gdb_prompt" {
8084 set current_schedule_locking_mode $expect_out
(1,string
)
8086 -re
"$gdb_prompt $" {
8087 set supports_schedule_locking
0
8090 set supports_schedule_locking
0
8094 if { $supports_schedule_locking
== -1 } {
8095 set test
"checking for scheduler-locking support"
8096 gdb_test_multiple
"set scheduler-locking $current_schedule_locking_mode" $test {
8097 -re
"Target '\[^'\]+' cannot support this command\..*$gdb_prompt $" {
8098 set supports_schedule_locking
0
8100 -re
"$gdb_prompt $" {
8101 set supports_schedule_locking
1
8104 set supports_schedule_locking
0
8109 if { $supports_schedule_locking
== -1 } {
8110 set supports_schedule_locking
0
8114 remote_file build
delete $
obj
8115 verbose
"$me: returning $supports_schedule_locking" 2
8116 return $supports_schedule_locking
8119 #
Return 1 if compiler supports use of nested functions. Otherwise
,
8122 gdb_caching_proc support_nested_function_tests
{} {
8123 #
Compile a test
program containing a nested function
8124 return [gdb_can_simple_compile nested_func
{
8134 # gdb_target_symbol returns the provided symbol with the correct prefix
8135 # prepended.
(See gdb_target_symbol_prefix
, above.
)
8137 proc gdb_target_symbol
{ symbol
} {
8138 set prefix
[gdb_target_symbol_prefix
]
8139 return "${prefix}${symbol}"
8142 # gdb_target_symbol_prefix_flags_asm returns a string that can be
8143 # added to gdb_compile options to
define the C
-preprocessor macro
8144 # SYMBOL_PREFIX with a value that can be prepended to symbols
8145 #
for targets which require a prefix
, such as underscore.
8147 # This version
(_asm
) defines the prefix without double quotes
8148 # surrounding the prefix. It is used to
define the macro
8149 # SYMBOL_PREFIX
for assembly language files. Another version
, below
,
8150 # is used
for symbols in inline assembler in C
/C
++ files.
8152 # The lack of quotes in this version
(_asm
) makes it possible to
8153 #
define supporting macros in the .S file.
(The version which
8154 # uses quotes
for the prefix won
't work for such files since it's
8155 # impossible to
define a quote
-stripping macro in C.
)
8157 # It
's possible to use this version (_asm) for C/C++ source files too,
8158 # but a string is usually required in such files; providing a version
8159 # (no _asm) which encloses the prefix with double quotes makes it
8160 # somewhat easier to define the supporting macros in the test case.
8162 proc gdb_target_symbol_prefix_flags_asm {} {
8163 set prefix [gdb_target_symbol_prefix]
8164 if {$prefix ne ""} {
8165 return "additional_flags=-DSYMBOL_PREFIX=$prefix"
8171 # gdb_target_symbol_prefix_flags returns the same string as
8172 # gdb_target_symbol_prefix_flags_asm, above, but with the prefix
8173 # enclosed in double quotes if there is a prefix.
8175 # See the comment for gdb_target_symbol_prefix_flags_asm for an
8176 # extended discussion.
8178 proc gdb_target_symbol_prefix_flags {} {
8179 set prefix [gdb_target_symbol_prefix]
8180 if {$prefix ne ""} {
8181 return "additional_flags=-DSYMBOL_PREFIX=\"$prefix\""
8187 # A wrapper for 'remote_exec host
' that passes or fails a test.
8188 # Returns 0 if all went well, nonzero on failure.
8189 # TEST is the name of the test, other arguments are as for remote_exec.
8191 proc run_on_host { test program args } {
8192 verbose -log "run_on_host: $program $args"
8193 # remote_exec doesn't work properly
if the output is
set but the
8194 # input is the empty string
-- so replace an empty input with
8196 if {[llength $
args] > 1 && [lindex $
args 1] == ""} {
8197 set args [lreplace $
args 1 1 "/dev/null"]
8199 set result
[eval remote_exec host
[list $
program] $
args]
8200 verbose
"result is $result"
8201 set status [lindex $result
0]
8202 set output
[lindex $result
1]
8207 verbose
-log "run_on_host failed: $output"
8208 if { $output
== "spawn failed" } {
8217 #
Return non
-zero
if "board_info debug_flags" mentions Fission.
8218 # http
://gcc.gnu.org
/wiki
/DebugFission
8219 # Fission doesn
't support everything yet.
8220 # This supports working around bug 15954.
8222 proc using_fission { } {
8223 set debug_flags [board_info [target_info name] debug_flags]
8224 return [regexp -- "-gsplit-dwarf" $debug_flags]
8227 # Search LISTNAME in uplevel LEVEL caller and set variables according to the
8228 # list of valid options with prefix PREFIX described by ARGSET.
8230 # The first member of each one- or two-element list in ARGSET defines the
8231 # name of a variable that will be added to the caller's scope.
8233 #
If only one element is given to
describe an option
, it the value is
8234 #
0 if the option is not present in
(the caller
's) ARGS or 1 if
8237 # If two elements are given, the second element is the default value of
8238 # the variable. This is then overwritten if the option exists in ARGS.
8239 # If EVAL, then subst is called on the value, which allows variables
8242 # Any parse_args elements in (the caller's
) ARGS will be removed
, leaving
8243 #
any optional components.
8246 # proc myproc
{foo
args} {
8247 # parse_list
args 1 {{bar
} {baz
"abc"} {qux}} "-" false
8250 # myproc ABC
-bar
-baz DEF peanut butter
8251 # will
define the following variables in myproc
:
8252 # foo
(=ABC
), bar
(=1), baz
(=DEF
), and qux
(=0)
8253 #
args will be the list
{peanut butter
}
8255 proc parse_list
{ level listname argset prefix eval
} {
8256 upvar $level $listname
args
8258 foreach
argument $argset
{
8259 if {[llength $
argument] == 1} {
8260 # Normalize
argument, strip leading
/trailing whitespace.
8261 # Allows us to treat
{foo
} and
{ foo
} the same.
8262 set argument [string trim $
argument]
8264 # No default specified
, so we assume that we should
set
8265 # the value to
1 if the
arg is present and
0 if it
's not.
8266 # It is assumed that no value is given with the argument.
8267 set pattern "$prefix$argument"
8268 set result [lsearch -exact $args $pattern]
8270 if {$result != -1} {
8272 set args [lreplace $args $result $result]
8276 uplevel $level [list set $argument $value]
8277 } elseif {[llength $argument] == 2} {
8278 # There are two items in the argument. The second is a
8279 # default value to use if the item is not present.
8280 # Otherwise, the variable is set to whatever is provided
8281 # after the item in the args.
8282 set arg [lindex $argument 0]
8283 set pattern "$prefix[lindex $arg 0]"
8284 set result [lsearch -exact $args $pattern]
8286 if {$result != -1} {
8287 set value [lindex $args [expr $result+1]]
8289 set value [uplevel [expr $level + 1] [list subst $value]]
8291 set args [lreplace $args $result [expr $result+1]]
8293 set value [lindex $argument 1]
8295 set value [uplevel $level [list subst $value]]
8298 uplevel $level [list set $arg $value]
8300 error "Badly formatted argument \"$argument\" in argument set"
8305 # Search the caller's
args variable and
set variables according to the list of
8306 # valid options described by ARGSET.
8308 proc parse_args
{ argset
} {
8309 parse_list
2 args $argset
"-" false
8311 # The remaining
args should be checked to see that they match the
8312 # number of items expected to be passed into the procedure...
8315 # Process the caller
's options variable and set variables according
8316 # to the list of valid options described by OPTIONSET.
8318 proc parse_options { optionset } {
8319 parse_list 2 options $optionset "" true
8321 # Require no remaining options.
8322 upvar 1 options options
8323 if { [llength $options] != 0 } {
8324 error "Options left unparsed: $options"
8328 # Capture the output of COMMAND in a string ignoring PREFIX (a regexp);
8329 # return that string.
8331 proc capture_command_output { command prefix } {
8335 set test "capture_command_output for $command"
8337 set output_string ""
8338 gdb_test_multiple $command $test {
8339 -re "^(\[^\r\n\]+\r\n)" {
8340 if { ![string equal $output_string ""] } {
8341 set output_string [join [list $output_string $expect_out(1,string)] ""]
8343 set output_string $expect_out(1,string)
8348 -re "^$gdb_prompt $" {
8352 # Strip the command.
8353 set command_re [string_to_regexp ${command}]
8354 set output_string [regsub ^$command_re\r\n $output_string ""]
8357 if { $prefix != "" } {
8358 set output_string [regsub ^$prefix $output_string ""]
8361 # Strip a trailing newline.
8362 set output_string [regsub "\r\n$" $output_string ""]
8364 return $output_string
8367 # A convenience function that joins all the arguments together, with a
8368 # regexp that matches exactly one end of line in between each argument.
8369 # This function is ideal to write the expected output of a GDB command
8370 # that generates more than a couple of lines, as this allows us to write
8371 # each line as a separate string, which is easier to read by a human
8374 proc multi_line { args } {
8375 if { [llength $args] == 1 } {
8376 set hint "forgot {*} before list argument?"
8377 error "multi_line called with one argument ($hint)"
8379 return [join $args "\r\n"]
8382 # Similar to the above, but while multi_line is meant to be used to
8383 # match GDB output, this one is meant to be used to build strings to
8384 # send as GDB input.
8386 proc multi_line_input { args } {
8387 return [join $args "\n"]
8390 # Return how many newlines there are in the given string.
8392 proc count_newlines { string } {
8393 return [regexp -all "\n" $string]
8396 # Return the version of the DejaGnu framework.
8398 # The return value is a list containing the major, minor and patch version
8399 # numbers. If the version does not contain a minor or patch number, they will
8400 # be set to 0. For example:
8406 proc dejagnu_version { } {
8407 # The frame_version variable is defined by DejaGnu, in runtest.exp.
8408 global frame_version
8410 verbose -log "DejaGnu version: $frame_version"
8411 verbose -log "Expect version: [exp_version]"
8412 verbose -log "Tcl version: [info tclversion]"
8414 set dg_ver [split $frame_version .]
8416 while { [llength $dg_ver] < 3 } {
8423 # Define user-defined command COMMAND using the COMMAND_LIST as the
8424 # command's definition. The terminating
"end" is added automatically.
8426 proc gdb_define_cmd
{command command_list
} {
8429 set input
[multi_line_input
{*}$command_list
"end"]
8430 set test
"define $command"
8432 gdb_test_multiple
"define $command" $test {
8434 gdb_test_multiple $input $test
{
8435 -re
"\r\n$gdb_prompt " {
8442 # Override the
'cd' builtin with a version that ensures that the
8443 #
log file keeps pointing at the same file. We need this because
8444 # unfortunately the path to the
log file is recorded using an
8445 # relative path
name, and
, we sometimes need to close
/reopen the
log
8446 # after changing the current directory. See get_compiler_info.
8448 rename cd builtin_cd
8452 #
Get the existing
log file flags.
8453 set log_file_info
[log_file
-info]
8455 # Split the flags into
args and file
name.
8456 set log_file_flags
""
8457 set log_file_file
""
8458 foreach
arg [ split
"$log_file_info" " "] {
8459 if [string match
"-*" $arg] {
8460 lappend log_file_flags $
arg
8462 lappend log_file_file $
arg
8466 #
If there was an existing file
, ensure it is an absolute path
, and
then
8468 if { $log_file_file
!= "" } {
8469 set log_file_file
[file normalize $log_file_file
]
8471 log_file $log_file_flags
"$log_file_file"
8474 #
Call the builtin version of cd.
8478 #
Return a list of all languages supported by GDB
, suitable
for use in
8479 #
'set language NAME'. This doesn
't include either the 'local
' or
8481 proc gdb_supported_languages {} {
8482 return [list c objective-c c++ d go fortran modula-2 asm pascal \
8483 opencl rust minimal ada]
8486 # Check if debugging is enabled for gdb.
8488 proc gdb_debug_enabled { } {
8491 # If not already read, get the debug setting from environment or board setting.
8492 if {![info exists gdbdebug]} {
8494 if [info exists env(GDB_DEBUG)] {
8495 set gdbdebug $env(GDB_DEBUG)
8496 } elseif [target_info exists gdb,debug] {
8497 set gdbdebug [target_info gdb,debug]
8503 # Ensure it not empty.
8504 return [expr { $gdbdebug != "" }]
8507 # Turn on debugging if enabled, or reset if already on.
8509 proc gdb_debug_init { } {
8513 if ![gdb_debug_enabled] {
8517 # First ensure logging is off.
8518 send_gdb "set logging enabled off\n"
8520 set debugfile [standard_output_file gdb.debug]
8521 send_gdb "set logging file $debugfile\n"
8523 send_gdb "set logging debugredirect\n"
8526 foreach entry [split $gdbdebug ,] {
8527 send_gdb "set debug $entry 1\n"
8530 # Now that everything is set, enable logging.
8531 send_gdb "set logging enabled on\n"
8533 -re "Copying output to $debugfile.*Redirecting debug output to $debugfile.*$gdb_prompt $" {}
8534 timeout { warning "Couldn't
set logging file
" }
8538 # Check
if debugging is enabled
for gdbserver.
8540 proc gdbserver_debug_enabled
{ } {
8541 # Always disabled
for GDB only setups.
8545 # Open the file
for logging gdb input
8547 proc gdb_stdin_log_init
{ } {
8548 gdb_persistent_global in_file
8550 if {[info exists in_file
]} {
8551 # Close existing file.
8552 catch
"close $in_file"
8555 set logfile
[standard_output_file_with_gdb_instance gdb.in
]
8556 set in_file
[open $logfile w
]
8559 # Write to the file
for logging gdb input.
8560 # TYPE can be one of the following
:
8561 #
"standard" : Default. Standard message written to the log
8562 #
"answer" : Answer to a question (eg "Y"). Not written the log.
8563 #
"optional" : Optional message. Not written to the log.
8565 proc gdb_stdin_log_write
{ message
{type standard
} } {
8568 if {![info exists in_file
]} {
8572 # Check message types.
8573 switch -regexp
-- $type
{
8582 # Write to the
log and make sure the output is there
, even in case
8584 puts
-nonewline $in_file
"$message"
8588 # Write the command line used to invocate gdb to the cmd file.
8590 proc gdb_write_cmd_file
{ cmdline
} {
8591 set logfile
[standard_output_file_with_gdb_instance gdb.cmd
]
8592 set cmd_file
[open $logfile w
]
8593 puts $cmd_file $cmdline
8594 catch
"close $cmd_file"
8597 # Compare contents of FILE to string STR. Pass with MSG
if equal
, otherwise
8600 proc cmp_file_string
{ file str msg
} {
8601 if { ![file
exists $file
]} {
8606 set caught_error
[catch
{
8607 set fp
[open
"$file" r]
8608 set file_contents
[read $fp
]
8611 if {$caught_error
} {
8612 error
"$error_message"
8617 if { $file_contents
== $str
} {
8624 # Compare FILE1 and FILE2 as binary files.
Return 0 if the files are
8625 # equal
, otherwise
, return non
-zero.
8627 proc cmp_binary_files
{ file1 file2
} {
8628 set fd1
[open $file1
]
8629 fconfigure $fd1
-translation binary
8630 set fd2
[open $file2
]
8631 fconfigure $fd2
-translation binary
8635 set blk1
[read $fd1 $blk_size
]
8636 set blk2
[read $fd2 $blk_size
]
8637 set diff
[string compare $blk1 $blk2
]
8638 if {$diff
!= 0 ||
[eof $fd1
] ||
[eof $fd2
]} {
8646 # Does the compiler support CTF debug output using
'-gctf' compiler
8647 # flag?
If not
then we should skip these tests. We should also
8648 # skip them
if libctf was explicitly disabled.
8650 gdb_caching_proc allow_ctf_tests
{} {
8651 global enable_libctf
8653 if {$enable_libctf eq
"no"} {
8657 set can_ctf
[gdb_can_simple_compile ctfdebug
{
8661 } executable
"additional_flags=-gctf"]
8666 #
Return 1 if compiler supports
-gstatement
-frontiers. Otherwise
,
8669 gdb_caching_proc supports_statement_frontiers
{} {
8670 return [gdb_can_simple_compile supports_statement_frontiers
{
8674 } executable
"additional_flags=-gstatement-frontiers"]
8677 #
Return 1 if compiler supports
-mmpx
-fcheck
-pointer
-bounds. Otherwise
,
8680 gdb_caching_proc supports_mpx_check_pointer_bounds
{} {
8681 set flags
"additional_flags=-mmpx additional_flags=-fcheck-pointer-bounds"
8682 return [gdb_can_simple_compile supports_mpx_check_pointer_bounds
{
8686 } executable $flags
]
8689 #
Return 1 if compiler supports
-fcf
-protection
=. Otherwise
,
8692 gdb_caching_proc supports_fcf_protection
{} {
8693 return [gdb_can_simple_compile supports_fcf_protection
{
8697 } executable
"additional_flags=-fcf-protection=full"]
8700 #
Return true
if symbols were read in using
-readnow. Otherwise
,
8704 return [expr
{[lsearch
-exact $
::GDBFLAGS
-readnow
] != -1
8705 ||
[lsearch
-exact $
::GDBFLAGS
--readnow
] != -1}]
8708 #
Return index
name if symbols were read in using an index.
8709 # Otherwise
, return "".
8711 proc have_index
{ objfile
} {
8714 set cmd
"maint print objfiles $objfile"
8715 gdb_test_multiple $cmd
"" -lbl {
8716 -re
"\r\n.gdb_index: faked for \"readnow\"" {
8720 -re
"\r\n.gdb_index:" {
8724 -re
"\r\n.debug_names:" {
8725 set res
"debug_names"
8729 # We don
't care about any other input.
8736 # Return 1 if partial symbols are available. Otherwise, return 0.
8738 proc psymtabs_p { } {
8741 set cmd "maint info psymtab"
8742 gdb_test_multiple $cmd "" {
8743 -re "$cmd\r\n$gdb_prompt $" {
8754 # Verify that partial symtab expansion for $filename has state $readin.
8756 proc verify_psymtab_expanded { filename readin } {
8759 set cmd "maint info psymtab"
8760 set test "$cmd: $filename: $readin"
8761 set re [multi_line \
8762 " \{ psymtab \[^\r\n\]*$filename\[^\r\n\]*" \
8766 gdb_test_multiple $cmd $test {
8767 -re "$cmd\r\n$gdb_prompt $" {
8768 unsupported $gdb_test_name
8776 # Add a .gdb_index section to PROGRAM.
8777 # PROGRAM is assumed to be the output of standard_output_file.
8778 # Returns the 0 if there is a failure, otherwise 1.
8780 # STYLE controls which style of index to add, if needed. The empty
8781 # string (the default) means .gdb_index; "-dwarf-5" means .debug_names.
8783 proc add_gdb_index { program {style ""} } {
8784 global srcdir GDB env
8785 set contrib_dir "$srcdir/../contrib"
8786 set env(GDB) [append_gdb_data_directory_option $GDB]
8787 set result [catch "exec $contrib_dir/gdb-add-index.sh $style $program" output]
8788 if { $result != 0 } {
8789 verbose -log "result is $result"
8790 verbose -log "output is $output"
8797 # Add a .gdb_index section to PROGRAM, unless it alread has an index
8798 # (.gdb_index/.debug_names). Gdb doesn't support building an index from a
8799 #
program already using one.
Return 1 if a .gdb_index was added
, return 0
8800 #
if it already contained an index
, and
-1 if an error occurred.
8802 # STYLE controls which style of index to add
, if needed. The empty
8803 # string
(the default
) means .gdb_index
; "-dwarf-5" means .debug_names.
8805 proc ensure_gdb_index
{ binfile
{style
""} } {
8808 set testfile
[file tail $binfile
]
8809 set test
"check if index present"
8812 gdb_test_multiple
"mt print objfiles ${testfile}" $test -lbl {
8813 -re
"\r\n\\.gdb_index: version ${decimal}(?=\r\n)" {
8815 gdb_test_lines
"" $gdb_test_name ".*"
8817 -re
"\r\n\\.debug_names: exists(?=\r\n)" {
8819 gdb_test_lines
"" $gdb_test_name ".*"
8821 -re
"\r\n(Cooked index in use:|Psymtabs)(?=\r\n)" {
8822 gdb_test_lines
"" $gdb_test_name ".*"
8824 -re
".gdb_index: faked for \"readnow\"" {
8826 gdb_test_lines
"" $gdb_test_name ".*"
8837 if { $has_readnow
} {
8841 if { [add_gdb_index $binfile $style
] == "1" } {
8848 #
Return 1 if executable contains .debug_types section. Otherwise
, return 0.
8850 proc debug_types
{ } {
8853 set cmd
"maint info sections"
8854 gdb_test_multiple $cmd
"" {
8855 -re
-wrap
"at $hex: .debug_types.*" {
8866 #
Return the addresses in the line table
for FILE
for which is_stmt is true.
8868 proc is_stmt_addresses
{ file
} {
8874 gdb_test_multiple
"maint info line-table $file" "" {
8875 -re
"\r\n$decimal\[ \t\]+$decimal\[ \t\]+($hex)\[ \t\]+$hex\[ \t\]+Y\[^\r\n\]*" {
8876 lappend is_stmt $expect_out
(1,string
)
8886 #
Return 1 if hex number VAL is an element of HEXLIST.
8888 proc hex_in_list
{ val hexlist
} {
8889 # Normalize val by removing
0x prefix
, and leading zeros.
8890 set val
[regsub ^
0x $val
""]
8891 set val
[regsub ^
0+ $val
"0"]
8894 set index
[lsearch
-regexp $hexlist $re
]
8895 return [expr $index
!= -1]
8898 # Override proc
NAME to proc OVERRIDE
for the duration of the execution of
8901 proc with_override
{ name override body
} {
8902 # Implementation note
: It
's possible to implement the override using
8903 # rename, like this:
8904 # rename $name save_$name
8905 # rename $override $name
8906 # set code [catch {uplevel 1 $body} result]
8907 # rename $name $override
8908 # rename save_$name $name
8909 # but there are two issues here:
8910 # - the save_$name might clash with an existing proc
8911 # - the override is no longer available under its original name during
8913 # So, we use this more elaborate but cleaner mechanism.
8915 # Save the old proc, if it exists.
8916 if { [info procs $name] != "" } {
8917 set old_args [info args $name]
8918 set old_body [info body $name]
8924 # Install the override.
8925 set new_args [info args $override]
8926 set new_body [info body $override]
8927 eval proc $name {$new_args} {$new_body}
8930 set code [catch {uplevel 1 $body} result]
8932 # Restore old proc if it existed on entry, else delete it.
8934 eval proc $name {$old_args} {$old_body}
8939 # Return as appropriate.
8941 global errorInfo errorCode
8942 return -code error -errorinfo $errorInfo -errorcode $errorCode $result
8943 } elseif { $code > 1 } {
8944 return -code $code $result
8950 # Setup tuiterm.exp environment. To be used in test-cases instead of
8951 # "load_lib tuiterm.exp". Calls initialization function and schedules
8952 # finalization function.
8953 proc tuiterm_env { } {
8954 load_lib tuiterm.exp
8957 # Dejagnu has a version of note, but usage is not allowed outside of dejagnu.
8958 # Define a local version.
8959 proc gdb_note { message } {
8960 verbose -- "NOTE: $message" 0
8963 # Return 1 if compiler supports -fuse-ld=gold, otherwise return 0.
8964 gdb_caching_proc have_fuse_ld_gold {} {
8965 set me "have_fuse_ld_gold"
8966 set flags "additional_flags=-fuse-ld=gold"
8967 set src { int main() { return 0; } }
8968 return [gdb_simple_compile $me $src executable $flags]
8971 # Return 1 if compiler supports fvar-tracking, otherwise return 0.
8972 gdb_caching_proc have_fvar_tracking {} {
8973 set me "have_fvar_tracking"
8974 set flags "additional_flags=-fvar-tracking"
8975 set src { int main() { return 0; } }
8976 return [gdb_simple_compile $me $src executable $flags]
8979 # Return 1 if linker supports -Ttext-segment, otherwise return 0.
8980 gdb_caching_proc linker_supports_Ttext_segment_flag {} {
8981 set me "linker_supports_Ttext_segment_flag"
8982 set flags ldflags="-Wl,-Ttext-segment=0x7000000"
8983 set src { int main() { return 0; } }
8984 return [gdb_simple_compile $me $src executable $flags]
8987 # Return 1 if linker supports -Ttext, otherwise return 0.
8988 gdb_caching_proc linker_supports_Ttext_flag {} {
8989 set me "linker_supports_Ttext_flag"
8990 set flags ldflags="-Wl,-Ttext=0x7000000"
8991 set src { int main() { return 0; } }
8992 return [gdb_simple_compile $me $src executable $flags]
8995 # Return 1 if linker supports --image-base, otherwise 0.
8996 gdb_caching_proc linker_supports_image_base_flag {} {
8997 set me "linker_supports_image_base_flag"
8998 set flags ldflags="-Wl,--image-base=0x7000000"
8999 set src { int main() { return 0; } }
9000 return [gdb_simple_compile $me $src executable $flags]
9004 # Return 1 if compiler supports scalar_storage_order attribute, otherwise
9006 gdb_caching_proc supports_scalar_storage_order_attribute {} {
9007 set me "supports_scalar_storage_order_attribute"
9012 } __attribute__((scalar_storage_order("little-endian")));
9015 } __attribute__((scalar_storage_order("big-endian")));
9019 sle.v = sbe.v = 0x11223344;
9020 int same = memcmp (&sle, &sbe, sizeof (int)) == 0;
9025 if { ![gdb_simple_compile $me $src executable ""] } {
9029 set target_obj [gdb_remote_download target $obj]
9030 set result [remote_exec target $target_obj]
9031 set status [lindex $result 0]
9032 set output [lindex $result 1]
9033 if { $output != "" } {
9040 # Return 1 if compiler supports __GNUC__, otherwise return 0.
9041 gdb_caching_proc supports_gnuc {} {
9042 set me "supports_gnuc"
9048 return [gdb_simple_compile $me $src object ""]
9051 # Return 1 if target supports mpx, otherwise return 0.
9052 gdb_caching_proc have_mpx {} {
9056 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
9057 verbose "$me: target does not support mpx, returning 0" 2
9061 # Compile a test program.
9063 #include "nat/x86-cpuid.h"
9066 unsigned int eax, ebx, ecx, edx;
9068 if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
9071 if ((ecx & bit_OSXSAVE) == bit_OSXSAVE)
9073 if (__get_cpuid_max (0, (void *)0) < 7)
9076 __cpuid_count (7, 0, eax, ebx, ecx, edx);
9078 if ((ebx & bit_MPX) == bit_MPX)
9085 set compile_flags "incdir=${srcdir}/.."
9086 if {![gdb_simple_compile $me $src executable $compile_flags]} {
9090 set target_obj [gdb_remote_download target $obj]
9091 set result [remote_exec target $target_obj]
9092 set status [lindex $result 0]
9093 set output [lindex $result 1]
9094 if { $output != "" } {
9098 remote_file build delete $obj
9100 if { $status == 0 } {
9101 verbose "$me: returning $status" 2
9105 # Compile program with -mmpx -fcheck-pointer-bounds, try to trigger
9106 # 'No MPX support
', in other words, see if kernel supports mpx.
9107 set src { int main (void) { return 0; } }
9109 append comp_flags " additional_flags=-mmpx"
9110 append comp_flags " additional_flags=-fcheck-pointer-bounds"
9111 if {![gdb_simple_compile $me-2 $src executable $comp_flags]} {
9115 set target_obj [gdb_remote_download target $obj]
9116 set result [remote_exec target $target_obj]
9117 set status [lindex $result 0]
9118 set output [lindex $result 1]
9119 set status [expr ($status == 0) \
9120 && ![regexp "^No MPX support\r?\n" $output]]
9122 remote_file build delete $obj
9124 verbose "$me: returning $status" 2
9128 # Return 1 if target supports avx, otherwise return 0.
9129 gdb_caching_proc have_avx {} {
9133 if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
9134 verbose "$me: target does not support avx, returning 0" 2
9138 # Compile a test program.
9140 #include "nat/x86-cpuid.h"
9143 unsigned int eax, ebx, ecx, edx;
9145 if (!x86_cpuid (1, &eax, &ebx, &ecx, &edx))
9148 if ((ecx & (bit_AVX | bit_OSXSAVE)) == (bit_AVX | bit_OSXSAVE))
9154 set compile_flags "incdir=${srcdir}/.."
9155 if {![gdb_simple_compile $me $src executable $compile_flags]} {
9159 set target_obj [gdb_remote_download target $obj]
9160 set result [remote_exec target $target_obj]
9161 set status [lindex $result 0]
9162 set output [lindex $result 1]
9163 if { $output != "" } {
9167 remote_file build delete $obj
9169 verbose "$me: returning $status" 2
9176 # ARG can either be a name, or of the form !NAME.
9178 # Each name is a proc to evaluate in the caller's
context. It returns
9179 # a
boolean, and a
"!" means to invert the result. If this is
9180 # nonzero
, all is well.
If it is zero
, an
"untested" is emitted and
9181 # this proc causes the caller to
return.
9183 proc require
{ args } {
9185 if {[string index $
arg 0] == "!"} {
9187 set fn
[string range $
arg 1 end
]
9192 if {$ok
!= !![uplevel
1 $fn
]} {
9193 unsupported
"require failed: $arg"
9194 return -code
return 0
9199 # Wait up to
::TIMEOUT
seconds for file PATH to exist
on the target
system.
9200 #
Return 1 if it does exist
, 0 otherwise.
9202 proc target_file_exists_with_timeout
{ path
} {
9203 for {set i
0} {$i
< $
::timeout
} {incr i
} {
9204 if { [remote_file target
exists $path
] } {
9214 gdb_caching_proc has_hw_wp_support
{} {
9215 # Power
9, proc rev
2.2 does not support HW watchpoints due to HW bug.
9216 # Need to use a runtime test to determine
if the Power processor has
9217 # support
for HW watchpoints.
9218 global srcdir subdir gdb_prompt inferior_exited_re
9220 set me
"has_hw_wp_support"
9223 if { [info exists gdb_spawn_id
] } {
9224 error
"$me called with running gdb instance"
9227 set compile_flags
{debug nowarnings quiet
}
9229 #
Compile a test
program to test
if HW watchpoints are supported
9240 if {![gdb_simple_compile $me $src executable $compile_flags
]} {
9245 gdb_reinitialize_dir $srcdir
/$subdir
9250 remote_file build
delete $
obj
9252 set has_hw_wp_support
0
9253 return $has_hw_wp_support
9256 # The goal is to determine
if HW watchpoints are available in general.
9257 # Use
"watch" and then check if gdb responds with hardware watch point.
9258 set test
"watch local"
9260 gdb_test_multiple $test
"Check for HW watchpoint support" {
9261 -re
".*Hardware watchpoint.*" {
9262 # HW watchpoint supported by platform
9263 verbose
-log "\n$me: Hardware watchpoint detected"
9264 set has_hw_wp_support
1
9266 -re
".*$gdb_prompt $" {
9267 set has_hw_wp_support
0
9268 verbose
-log "\n$me: Default, hardware watchpoint not deteced"
9273 remote_file build
delete $
obj
9275 verbose
"$me: returning $has_hw_wp_support" 2
9276 return $has_hw_wp_support
9279 #
Return a list of all the accepted
values of the
set command
9280 #
"SET_CMD SET_ARG".
9281 #
For example get_set_option_choices
"set architecture" "i386".
9283 proc get_set_option_choices
{ set_cmd
{set_arg
""} } {
9286 if { $set_arg
== "" } {
9287 # Add trailing space to
signal that we need completion of the choices
,
9288 # not of set_cmd itself.
9289 set cmd
"complete $set_cmd "
9291 set cmd
"complete $set_cmd $set_arg"
9294 #
Set test
name without trailing space.
9295 set test
[string trim $cmd
]
9297 with_set
max-completions unlimited
{
9298 gdb_test_multiple $cmd $test
{
9299 -re
"^[string_to_regexp $cmd]\r\n" {
9303 -re
"^$set_cmd (\[^\r\n\]+)\r\n" {
9304 lappend
values $expect_out
(1,string
)
9308 -re
"^$::gdb_prompt $" {
9317 #
Return the compiler that can generate
32-bit ARM executables. Used
9318 # when testing biarch support
on Aarch64.
If ARM_CC_FOR_TARGET is
9319 #
set, use that.
If not
, try a few common compiler names
, making sure
9320 # that the executable they produce can run.
9322 gdb_caching_proc arm_cc_for_target
{} {
9323 if {[info exists ::ARM_CC_FOR_TARGET
]} {
9324 #
If the user specified the compiler explicitly
, then don
't
9325 # check whether the resulting binary runs outside GDB. Assume
9326 # that it does, and if it turns out it doesn't
, then the user
9327 # should
get loud FAILs
, instead of UNSUPPORTED.
9328 return $
::ARM_CC_FOR_TARGET
9331 # Fallback to a few common compiler names. Also confirm the
9332 # produced binary actually runs
on the
system before declaring
9333 # we
've found the right compiler.
9335 if [istarget "*-linux*-*"] {
9337 arm-linux-gnueabi-gcc
9338 arm-none-linux-gnueabi-gcc
9339 arm-linux-gnueabihf-gcc
9345 foreach compiler $compilers {
9346 if {![is_remote host] && [which $compiler] == 0} {
9347 # Avoid "default_target_compile: Can't find
9348 # $compiler.
" warning issued from gdb_compile.
9352 set src
{ int main
() { return 0; } }
9353 if {[gdb_simple_compile aarch64
-32bit \
9355 executable
[list compiler
=$compiler
]]} {
9357 set target_obj
[gdb_remote_download target $
obj]
9358 set result
[remote_exec target $target_obj
]
9359 set status [lindex $result
0]
9360 set output
[lindex $result
1]
9364 if { $output
== "" && $status == 0} {
9373 # Step until the pattern REGEXP is found. Step at most
9374 # MAX_STEPS times
, but stop stepping once REGEXP is found.
9375 # CURRENT matches current location
9376 #
If REGEXP is found
then a single pass is emitted
, otherwise
, after
9377 # MAX_STEPS steps
, a single fail is emitted.
9379 # TEST_NAME is the
name used in the pass
/fail calls.
9381 proc gdb_step_until
{ regexp
{test_name
"stepping until regexp"} \
9382 {current
"\}"} { max_steps 10 } } {
9383 repeat_cmd_until
"step" $current $regexp $test_name "10"
9386 #
Do repeated stepping COMMANDs in order to reach TARGET from CURRENT
9388 # COMMAND is a stepping command
9389 # CURRENT is a string matching the current location
9390 # TARGET is a string matching the target location
9391 # TEST_NAME is the test
name
9392 # MAX_STEPS is number of steps attempted before fail is emitted
9394 # The function issues repeated COMMANDs as long as the location matches
9395 # CURRENT up to a maximum of MAX_STEPS.
9397 # TEST_NAME passes
if the resulting location matches TARGET and fails
9400 proc repeat_cmd_until
{ command current target \
9401 {test_name
"stepping until regexp"} \
9406 gdb_test_multiple
"$command" "$test_name" {
9407 -re
"$current.*$gdb_prompt $" {
9409 if { $
count < $max_steps
} {
9410 send_gdb
"$command\n"
9416 -re
"$target.*$gdb_prompt $" {
9422 #
Return false
if the current target is not operating in non
-stop
9423 #
mode, otherwise
, return true.
9425 # The inferior will need to have started running in order to
get the
9428 proc is_target_non_stop
{ {testname
""} } {
9429 #
For historical reasons we assume non
-stop
mode is
on.
If the
9430 # maintenance command fails
for any reason
then we
're going to
9432 set is_non_stop true
9433 gdb_test_multiple "maint show target-non-stop" $testname {
9434 -wrap -re "(is|currently) on.*" {
9435 set is_non_stop true
9437 -wrap -re "(is|currently) off.*" {
9438 set is_non_stop false
9444 # Check if the compiler emits epilogue information associated
9445 # with the closing brace or with the last statement line.
9447 # This proc restarts GDB
9449 # Returns True if it is associated with the closing brace,
9450 # False if it is the last statement
9451 gdb_caching_proc have_epilogue_line_info {} {
9460 if {![gdb_simple_compile "simple_program" $main]} {
9466 gdb_test_multiple "info line 6" "epilogue test" {
9467 -re -wrap ".*starts at address.*and ends at.*" {
9476 # Decompress file BZ2, and return it.
9478 proc decompress_bz2 { bz2 } {
9479 set copy [standard_output_file [file tail $bz2]]
9480 set copy [remote_download build $bz2 $copy]
9481 if { $copy == "" } {
9485 set res [remote_exec build "bzip2" "-df $copy"]
9486 if { [lindex $res 0] == -1 } {
9490 set copy [regsub {.bz2$} $copy ""]
9491 if { ![remote_file build exists $copy] } {
9498 # Return 1 if the output of "ldd FILE" contains regexp DEP, 0 if it doesn't
,
9499 # and
-1 if there was a problem running the command.
9501 proc has_dependency
{ file dep
} {
9502 set ldd
[gdb_find_ldd
]
9503 set command
"$ldd $file"
9504 set result
[remote_exec host $command
]
9505 set status [lindex $result
0]
9506 set output
[lindex $result
1]
9507 verbose
-log "status of $command is $status"
9508 verbose
-log "output of $command is $output"
9509 if { $
status != 0 || $output
== "" } {
9512 return [regexp $dep $output
]
9515 # Detect linux kernel version and
return as list of
3 numbers
: major
, minor
,
9516 # and patchlevel.
On failure
, return an empty list.
9518 gdb_caching_proc linux_kernel_version
{} {
9519 if { ![istarget
*-*-linux
*] } {
9523 set res
[remote_exec target
"uname -r"]
9524 set status [lindex $res
0]
9525 set output
[lindex $res
1]
9526 if { $
status != 0 } {
9530 set re ^
($
::decimal
)\\.
($
::decimal
)\\.
($
::decimal
)
9531 if { [regexp $re $output dummy v1 v2 v3
] != 1 } {
9535 return [list $v1 $v2 $v3
]
9538 #
Return 1 if syscall
NAME is supported.
9540 proc have_syscall
{ name } {
9543 "#include <sys/syscall.h>" \
9544 "int var = SYS_$name;"]
9545 set src
[join $src
"\n"]
9546 return [gdb_can_simple_compile have_syscall_$
name $src object
]
9549 #
Return 1 if compile flag FLAG is supported.
9551 gdb_caching_proc have_compile_flag
{ flag
} {
9552 set src
{ void foo
() {} }
9553 return [gdb_can_simple_compile have_compile_flag_$flag $src object \
9554 additional_flags
=$flag
]
9557 # Handle
include file $srcdir
/$subdir
/FILE.
9559 proc include_file
{ file
} {
9560 set file
[file join $
::srcdir $
::subdir $file
]
9561 if { [is_remote host
] } {
9562 set res
[remote_download host $file
]
9570 # Handle
include file FILE
, and
if necessary
update compiler flags
variable
9573 proc lappend_include_file
{ flags file
} {
9574 upvar $flags up_flags
9575 if { [is_remote host
] } {
9576 gdb_remote_download host $file
9578 set dir [file dirname $file
]
9579 if { $
dir != [file join $
::srcdir $
::subdir
] } {
9580 lappend up_flags
"additional_flags=-I$dir"
9585 # Always
load compatibility stuff.