1 # Copyright 1992-2005, 2007-2012 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"
32 if [info exists TOOL_EXECUTABLE] {
33 set GDB $TOOL_EXECUTABLE;
35 if ![info exists GDB] {
36 if ![is_remote host] {
37 set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]]
39 set GDB [transform gdb];
42 verbose "using GDB = $GDB" 2
44 # GDBFLAGS is available for the user to set on the command line.
45 # E.g. make check RUNTESTFLAGS=GDBFLAGS=mumble
46 # Testcases may use it to add additional flags, but they must:
47 # - append new flags, not overwrite
48 # - restore the original value when done
50 if ![info exists GDBFLAGS] {
53 verbose "using GDBFLAGS = $GDBFLAGS" 2
55 # INTERNAL_GDBFLAGS contains flags that the testsuite requires.
56 global INTERNAL_GDBFLAGS
57 if ![info exists INTERNAL_GDBFLAGS] {
58 set INTERNAL_GDBFLAGS "-nw -nx -data-directory [pwd]/../data-directory"
61 # The variable gdb_prompt is a regexp which matches the gdb prompt.
62 # Set it if it is not already set.
64 if ![info exists gdb_prompt] then {
65 set gdb_prompt "\[(\]gdb\[)\]"
68 # The variable fullname_syntax_POSIX is a regexp which matches a POSIX
69 # absolute path ie. /foo/
70 set fullname_syntax_POSIX {/[^\n]*/}
71 # The variable fullname_syntax_UNC is a regexp which matches a Windows
72 # UNC path ie. \\D\foo\
73 set fullname_syntax_UNC {\\\\[^\\]+\\[^\n]+\\}
74 # The variable fullname_syntax_DOS_CASE is a regexp which matches a
75 # particular DOS case that GDB most likely will output
76 # ie. \foo\, but don't match \\.*\
77 set fullname_syntax_DOS_CASE {\\[^\\][^\n]*\\}
78 # The variable fullname_syntax_DOS is a regexp which matches a DOS path
79 # ie. a:\foo\ && a:foo\
80 set fullname_syntax_DOS {[a-zA-Z]:[^\n]*\\}
81 # The variable fullname_syntax is a regexp which matches what GDB considers
82 # an absolute path. It is currently debatable if the Windows style paths
83 # d:foo and \abc should be considered valid as an absolute path.
84 # Also, the purpse of this regexp is not to recognize a well formed
85 # absolute path, but to say with certainty that a path is absolute.
86 set fullname_syntax "($fullname_syntax_POSIX|$fullname_syntax_UNC|$fullname_syntax_DOS_CASE|$fullname_syntax_DOS)"
88 # Needed for some tests under Cygwin.
92 if ![info exists env(EXEEXT)] {
95 set EXEEXT $env(EXEEXT)
100 set inferior_exited_re "(\\\[Inferior \[0-9\]+ \\(.*\\) exited)"
102 ### Only procedures should come after this point.
105 # gdb_version -- extract and print the version number of GDB
107 proc default_gdb_version {} {
109 global INTERNAL_GDBFLAGS GDBFLAGS
111 set output [remote_exec host "$GDB $INTERNAL_GDBFLAGS --version"]
112 set tmp [lindex $output 1];
114 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
115 if ![is_remote host] {
116 clone_output "[which $GDB] version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
118 clone_output "$GDB on remote host version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
122 proc gdb_version { } {
123 return [default_gdb_version];
127 # gdb_unload -- unload a file if one is loaded
136 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
137 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
138 -re "A program is being debugged already.*Are you sure you want to change the file.*y or n. $" {
142 -re "Discard symbol table from .*y or n.*$" {
146 -re "$gdb_prompt $" {}
148 perror "couldn't unload file in $GDB (timed out)."
154 # Many of the tests depend on setting breakpoints at various places and
155 # running until that breakpoint is reached. At times, we want to start
156 # with a clean-slate with respect to breakpoints, so this utility proc
157 # lets us do this without duplicating this code everywhere.
160 proc delete_breakpoints {} {
163 # we need a larger timeout value here or this thing just confuses
164 # itself. May need a better implementation if possible. - guo
166 send_gdb "delete breakpoints\n"
168 -re "Delete all breakpoints.*y or n.*$" {
172 -re "$gdb_prompt $" { # This happens if there were no breakpoints
174 timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
176 send_gdb "info breakpoints\n"
178 -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
179 -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
180 -re "Delete all breakpoints.*or n.*$" {
184 timeout { perror "info breakpoints (timeout)" ; return }
188 # Generic run command.
190 # The second pattern below matches up to the first newline *only*.
191 # Using ``.*$'' could swallow up output that we attempt to match
194 # N.B. This function does not wait for gdb to return to the prompt,
195 # that is the caller's responsibility.
197 proc gdb_run_cmd {args} {
198 global gdb_prompt use_gdb_stub
200 if [target_info exists gdb_init_command] {
201 send_gdb "[target_info gdb_init_command]\n";
203 -re "$gdb_prompt $" { }
205 perror "gdb_init_command for target failed";
212 if [target_info exists gdb,do_reload_on_run] {
213 if { [gdb_reload] != 0 } {
216 send_gdb "continue\n";
218 -re "Continu\[^\r\n\]*\[\r\n\]" {}
224 if [target_info exists gdb,start_symbol] {
225 set start [target_info gdb,start_symbol];
229 send_gdb "jump *$start\n"
231 while { $start_attempt } {
232 # Cap (re)start attempts at three to ensure that this loop
233 # always eventually fails. Don't worry about trying to be
234 # clever and not send a command when it has failed.
235 if [expr $start_attempt > 3] {
236 perror "Jump to start() failed (retry count exceeded)";
239 set start_attempt [expr $start_attempt + 1];
241 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
244 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
245 perror "Can't find start symbol to run in gdb_run";
248 -re "No symbol \"start\" in current.*$gdb_prompt $" {
249 send_gdb "jump *_start\n";
251 -re "No symbol.*context.*$gdb_prompt $" {
254 -re "Line.* Jump anyway.*y or n. $" {
257 -re "The program is not being run.*$gdb_prompt $" {
258 if { [gdb_reload] != 0 } {
261 send_gdb "jump *$start\n";
264 perror "Jump to start() failed (timeout)";
272 if [target_info exists gdb,do_reload_on_run] {
273 if { [gdb_reload] != 0 } {
277 send_gdb "run $args\n"
278 # This doesn't work quite right yet.
279 # Use -notransfer here so that test cases (like chng-sym.exp)
280 # may test for additional start-up messages.
282 -re "The program .* has been started already.*y or n. $" {
286 -notransfer -re "Starting program: \[^\r\n\]*" {}
287 -notransfer -re "$gdb_prompt $" {
288 # There is no more input expected.
293 # Generic start command. Return 0 if we could start the program, -1
296 # N.B. This function does not wait for gdb to return to the prompt,
297 # that is the caller's responsibility.
299 proc gdb_start_cmd {args} {
300 global gdb_prompt use_gdb_stub
302 if [target_info exists gdb_init_command] {
303 send_gdb "[target_info gdb_init_command]\n";
305 -re "$gdb_prompt $" { }
307 perror "gdb_init_command for target failed";
317 send_gdb "start $args\n"
318 # Use -notransfer here so that test cases (like chng-sym.exp)
319 # may test for additional start-up messages.
321 -re "The program .* has been started already.*y or n. $" {
325 -notransfer -re "Starting program: \[^\r\n\]*" {
332 # Set a breakpoint at FUNCTION. If there is an additional argument it is
333 # a list of options; the supported options are allow-pending, temporary,
336 proc gdb_breakpoint { function args } {
340 set pending_response n
341 if {[lsearch -exact [lindex $args 0] allow-pending] != -1} {
342 set pending_response y
345 set break_command "break"
346 set break_message "Breakpoint"
347 if {[lsearch -exact [lindex $args 0] temporary] != -1} {
348 set break_command "tbreak"
349 set break_message "Temporary breakpoint"
353 if {[lsearch -exact [lindex $args 0] no-message] != -1} {
357 send_gdb "$break_command $function\n"
358 # The first two regexps are what we get with -g, the third is without -g.
360 -re "$break_message \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
361 -re "$break_message \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
362 -re "$break_message \[0-9\]* at .*$gdb_prompt $" {}
363 -re "$break_message \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" {
364 if {$pending_response == "n"} {
365 if { $no_message == 0 } {
366 fail "setting breakpoint at $function"
371 -re "Make breakpoint pending.*y or \\\[n\\\]. $" {
372 send_gdb "$pending_response\n"
375 -re "A problem internal to GDB has been detected" {
376 fail "setting breakpoint at $function in runto (GDB internal error)"
377 gdb_internal_error_resync
380 -re "$gdb_prompt $" {
381 if { $no_message == 0 } {
382 fail "setting breakpoint at $function"
387 if { $no_message == 0 } {
388 fail "setting breakpoint at $function (timeout)"
396 # Set breakpoint at function and run gdb until it breaks there.
397 # Since this is the only breakpoint that will be set, if it stops
398 # at a breakpoint, we will assume it is the one we want. We can't
399 # just compare to "function" because it might be a fully qualified,
400 # single quoted C++ function specifier. If there's an additional argument,
401 # pass it to gdb_breakpoint.
403 proc runto { function args } {
409 if ![gdb_breakpoint $function [lindex $args 0]] {
415 # the "at foo.c:36" output we get with -g.
416 # the "in func" output we get without -g.
418 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
421 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
424 -re "The target does not support running in non-stop mode.\r\n$gdb_prompt $" {
425 unsupported "Non-stop mode not supported"
428 -re ".*A problem internal to GDB has been detected" {
429 fail "running to $function in runto (GDB internal error)"
430 gdb_internal_error_resync
433 -re "$gdb_prompt $" {
434 fail "running to $function in runto"
438 fail "running to $function in runto (end of file)"
442 fail "running to $function in runto (timeout)"
449 # Ask gdb to run until we hit a breakpoint at main.
451 # N.B. This function deletes all existing breakpoints.
452 # If you don't want that, use gdb_start_cmd.
454 proc runto_main { } {
458 ### Continue, and expect to hit a breakpoint.
459 ### Report a pass or fail, depending on whether it seems to have
460 ### worked. Use NAME as part of the test name; each call to
461 ### continue_to_breakpoint should use a NAME which is unique within
463 proc gdb_continue_to_breakpoint {name {location_pattern .*}} {
465 set full_name "continue to breakpoint: $name"
467 send_gdb "continue\n"
469 -re "Breakpoint .* (at|in) $location_pattern\r\n$gdb_prompt $" {
472 -re ".*$gdb_prompt $" {
476 fail "$full_name (timeout)"
482 # gdb_internal_error_resync:
484 # Answer the questions GDB asks after it reports an internal error
485 # until we get back to a GDB prompt. Decline to quit the debugging
486 # session, and decline to create a core file. Return non-zero if the
489 # This procedure just answers whatever questions come up until it sees
490 # a GDB prompt; it doesn't require you to have matched the input up to
491 # any specific point. However, it only answers questions it sees in
492 # the output itself, so if you've matched a question, you had better
493 # answer it yourself before calling this.
495 # You can use this function thus:
499 # -re ".*A problem internal to GDB has been detected" {
500 # gdb_internal_error_resync
505 proc gdb_internal_error_resync {} {
509 while {$count < 10} {
511 -re "Quit this debugging session\\? \\(y or n\\) $" {
515 -re "Create a core file of GDB\\? \\(y or n\\) $" {
519 -re "$gdb_prompt $" {
520 # We're resynchronized.
524 perror "Could not resync from internal error (timeout)"
529 perror "Could not resync from internal error (resync count exceeded)"
534 # gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS
535 # Send a command to gdb; test the result.
537 # COMMAND is the command to execute, send to GDB with send_gdb. If
538 # this is the null string no command is sent.
539 # MESSAGE is a message to be printed with the built-in failure patterns
540 # if one of them matches. If MESSAGE is empty COMMAND will be used.
541 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
542 # patterns. Pattern elements will be evaluated in the caller's
543 # context; action elements will be executed in the caller's context.
544 # Unlike patterns for gdb_test, these patterns should generally include
545 # the final newline and prompt.
548 # 1 if the test failed, according to a built-in failure pattern
549 # 0 if only user-supplied patterns matched
550 # -1 if there was an internal error.
552 # You can use this function thus:
554 # gdb_test_multiple "print foo" "test foo" {
555 # -re "expected output 1" {
558 # -re "expected output 2" {
563 # The standard patterns, such as "Inferior exited..." and "A problem
564 # ...", all being implicitly appended to that list.
566 proc gdb_test_multiple { command message user_code } {
567 global verbose use_gdb_stub
570 global inferior_exited_re
571 upvar timeout timeout
572 upvar expect_out expect_out
574 if { $message == "" } {
578 if [string match "*\[\r\n\]" $command] {
579 error "Invalid trailing newline in \"$message\" test"
582 if [string match "*\[\r\n\]*" $message] {
583 error "Invalid newline in \"$message\" test"
587 && [regexp -nocase {^\s*(r|run|star|start|at|att|atta|attac|attach)\M} \
589 error "gdbserver does not support $command without extended-remote"
592 # TCL/EXPECT WART ALERT
593 # Expect does something very strange when it receives a single braced
594 # argument. It splits it along word separators and performs substitutions.
595 # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
596 # evaluated as "\[ab\]". But that's not how TCL normally works; inside a
597 # double-quoted list item, "\[ab\]" is just a long way of representing
598 # "[ab]", because the backslashes will be removed by lindex.
600 # Unfortunately, there appears to be no easy way to duplicate the splitting
601 # that expect will do from within TCL. And many places make use of the
602 # "\[0-9\]" construct, so we need to support that; and some places make use
603 # of the "[func]" construct, so we need to support that too. In order to
604 # get this right we have to substitute quoted list elements differently
605 # from braced list elements.
607 # We do this roughly the same way that Expect does it. We have to use two
608 # lists, because if we leave unquoted newlines in the argument to uplevel
609 # they'll be treated as command separators, and if we escape newlines
610 # we mangle newlines inside of command blocks. This assumes that the
611 # input doesn't contain a pattern which contains actual embedded newlines
614 regsub -all {\n} ${user_code} { } subst_code
615 set subst_code [uplevel list $subst_code]
617 set processed_code ""
619 set expecting_action 0
621 foreach item $user_code subst_item $subst_code {
622 if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } {
623 lappend processed_code $item
626 if { $item == "-indices" || $item == "-re" || $item == "-ex" } {
627 lappend processed_code $item
630 if { $item == "-timeout" } {
632 lappend processed_code $item
635 if { $expecting_arg } {
637 lappend processed_code $item
640 if { $expecting_action } {
641 lappend processed_code "uplevel [list $item]"
642 set expecting_action 0
643 # Cosmetic, no effect on the list.
644 append processed_code "\n"
647 set expecting_action 1
648 lappend processed_code $subst_item
649 if {$patterns != ""} {
652 append patterns "\"$subst_item\""
655 # Also purely cosmetic.
656 regsub -all {\r} $patterns {\\r} patterns
657 regsub -all {\n} $patterns {\\n} patterns
660 send_user "Sending \"$command\" to gdb\n"
661 send_user "Looking to match \"$patterns\"\n"
662 send_user "Message is \"$message\"\n"
666 set string "${command}\n";
667 if { $command != "" } {
668 set multi_line_re "\[\r\n\] *>"
669 while { "$string" != "" } {
670 set foo [string first "\n" "$string"];
671 set len [string length "$string"];
672 if { $foo < [expr $len - 1] } {
673 set str [string range "$string" 0 $foo];
674 if { [send_gdb "$str"] != "" } {
675 global suppress_flag;
677 if { ! $suppress_flag } {
678 perror "Couldn't send $command to GDB.";
683 # since we're checking if each line of the multi-line
684 # command are 'accepted' by GDB here,
685 # we need to set -notransfer expect option so that
686 # command output is not lost for pattern matching
689 -notransfer -re "$multi_line_re$" { verbose "partial: match" 3 }
690 timeout { verbose "partial: timeout" 3 }
692 set string [string range "$string" [expr $foo + 1] end];
693 set multi_line_re "$multi_line_re.*\[\r\n\] *>"
698 if { "$string" != "" } {
699 if { [send_gdb "$string"] != "" } {
700 global suppress_flag;
702 if { ! $suppress_flag } {
703 perror "Couldn't send $command to GDB.";
711 if [target_info exists gdb,timeout] {
712 set tmt [target_info gdb,timeout];
714 if [info exists timeout] {
718 if [info exists timeout] {
727 -re ".*A problem internal to GDB has been detected" {
728 fail "$message (GDB internal error)"
729 gdb_internal_error_resync
731 -re "\\*\\*\\* DOSEXIT code.*" {
732 if { $message != "" } {
735 gdb_suppress_entire_file "GDB died";
739 append code $processed_code
741 -re "Ending remote debugging.*$gdb_prompt $" {
742 if ![isnative] then {
743 warning "Can`t communicate to remote target."
749 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
750 perror "Undefined command \"$command\"."
754 -re "Ambiguous command.*$gdb_prompt $" {
755 perror "\"$command\" is not a unique command name."
759 -re "$inferior_exited_re with code \[0-9\]+.*$gdb_prompt $" {
760 if ![string match "" $message] then {
761 set errmsg "$message (the program exited)"
763 set errmsg "$command (the program exited)"
768 -re "$inferior_exited_re normally.*$gdb_prompt $" {
769 if ![string match "" $message] then {
770 set errmsg "$message (the program exited)"
772 set errmsg "$command (the program exited)"
777 -re "The program is not being run.*$gdb_prompt $" {
778 if ![string match "" $message] then {
779 set errmsg "$message (the program is no longer running)"
781 set errmsg "$command (the program is no longer running)"
786 -re "\r\n$gdb_prompt $" {
787 if ![string match "" $message] then {
794 perror "Window too small."
798 -re "\\((y or n|y or \\\[n\\\]|\\\[y\\\] or n)\\) " {
800 gdb_expect -re "$gdb_prompt $"
801 fail "$message (got interactive prompt)"
804 -re "\\\[0\\\] cancel\r\n\\\[1\\\] all.*\r\n> $" {
806 gdb_expect -re "$gdb_prompt $"
807 fail "$message (got breakpoint menu)"
811 perror "Process no longer exists"
812 if { $message != "" } {
818 perror "internal buffer is full."
823 if ![string match "" $message] then {
824 fail "$message (timeout)"
831 set code [catch {gdb_expect $tmt $code} string]
833 global errorInfo errorCode;
834 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
835 } elseif {$code > 1} {
836 return -code $code $string
841 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
842 # Send a command to gdb; test the result.
844 # COMMAND is the command to execute, send to GDB with send_gdb. If
845 # this is the null string no command is sent.
846 # PATTERN is the pattern to match for a PASS, and must NOT include
847 # the \r\n sequence immediately before the gdb prompt.
848 # MESSAGE is an optional message to be printed. If this is
849 # omitted, then the pass/fail messages use the command string as the
850 # message. (If this is the empty string, then sometimes we don't
851 # call pass or fail at all; I don't understand this at all.)
852 # QUESTION is a question GDB may ask in response to COMMAND, like
854 # RESPONSE is the response to send if QUESTION appears.
857 # 1 if the test failed,
858 # 0 if the test passes,
859 # -1 if there was an internal error.
861 proc gdb_test { args } {
865 upvar timeout timeout
867 if [llength $args]>2 then {
868 set message [lindex $args 2]
870 set message [lindex $args 0]
872 set command [lindex $args 0]
873 set pattern [lindex $args 1]
875 if [llength $args]==5 {
876 set question_string [lindex $args 3];
877 set response_string [lindex $args 4];
879 set question_string "^FOOBAR$"
882 return [gdb_test_multiple $command $message {
883 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
884 if ![string match "" $message] then {
888 -re "(${question_string})$" {
889 send_gdb "$response_string\n";
895 # gdb_test_no_output COMMAND MESSAGE
896 # Send a command to GDB and verify that this command generated no output.
898 # See gdb_test_multiple for a description of the COMMAND and MESSAGE
899 # parameters. If MESSAGE is ommitted, then COMMAND will be used as
900 # the message. (If MESSAGE is the empty string, then sometimes we do not
901 # call pass or fail at all; I don't understand this at all.)
903 proc gdb_test_no_output { args } {
905 set command [lindex $args 0]
906 if [llength $args]>1 then {
907 set message [lindex $args 1]
912 set command_regex [string_to_regexp $command]
913 gdb_test_multiple $command $message {
914 -re "^$command_regex\r\n$gdb_prompt $" {
915 if ![string match "" $message] then {
922 # Send a command and then wait for a sequence of outputs.
923 # This is useful when the sequence is long and contains ".*", a single
924 # regexp to match the entire output can get a timeout much easier.
926 # COMMAND is the command to send.
927 # TEST_NAME is passed to pass/fail. COMMAND is used if TEST_NAME is "".
928 # EXPECTED_OUTPUT_LIST is a list of regexps of expected output, which are
929 # processed in order, and all must be present in the output.
931 # It is unnecessary to specify ".*" at the beginning or end of any regexp,
932 # there is an implicit ".*" between each element of EXPECTED_OUTPUT_LIST.
933 # There is also an implicit ".*" between the last regexp and the gdb prompt.
935 # Like gdb_test and gdb_test_multiple, the output is expected to end with the
936 # gdb prompt, which must not be specified in EXPECTED_OUTPUT_LIST.
939 # 1 if the test failed,
940 # 0 if the test passes,
941 # -1 if there was an internal error.
943 proc gdb_test_sequence { command test_name expected_output_list } {
945 if { $test_name == "" } {
946 set test_name $command
948 lappend expected_output_list ""; # implicit ".*" before gdb prompt
949 send_gdb "$command\n"
950 return [gdb_expect_list $test_name "$gdb_prompt $" $expected_output_list]
954 # Test that a command gives an error. For pass or fail, return
955 # a 1 to indicate that more tests can proceed. However a timeout
956 # is a serious error, generates a special fail message, and causes
957 # a 0 to be returned to indicate that more tests are likely to fail
960 proc test_print_reject { args } {
964 if [llength $args]==2 then {
965 set expectthis [lindex $args 1]
967 set expectthis "should never match this bogus string"
969 set sendthis [lindex $args 0]
971 send_user "Sending \"$sendthis\" to gdb\n"
972 send_user "Looking to match \"$expectthis\"\n"
974 send_gdb "$sendthis\n"
975 #FIXME: Should add timeout as parameter.
977 -re "A .* in expression.*\\.*$gdb_prompt $" {
978 pass "reject $sendthis"
981 -re "Invalid syntax in expression.*$gdb_prompt $" {
982 pass "reject $sendthis"
985 -re "Junk after end of expression.*$gdb_prompt $" {
986 pass "reject $sendthis"
989 -re "Invalid number.*$gdb_prompt $" {
990 pass "reject $sendthis"
993 -re "Invalid character constant.*$gdb_prompt $" {
994 pass "reject $sendthis"
997 -re "No symbol table is loaded.*$gdb_prompt $" {
998 pass "reject $sendthis"
1001 -re "No symbol .* in current context.*$gdb_prompt $" {
1002 pass "reject $sendthis"
1005 -re "Unmatched single quote.*$gdb_prompt $" {
1006 pass "reject $sendthis"
1009 -re "A character constant must contain at least one character.*$gdb_prompt $" {
1010 pass "reject $sendthis"
1013 -re "$expectthis.*$gdb_prompt $" {
1014 pass "reject $sendthis"
1017 -re ".*$gdb_prompt $" {
1018 fail "reject $sendthis"
1022 fail "reject $sendthis (eof or timeout)"
1028 # Given an input string, adds backslashes as needed to create a
1029 # regexp that will match the string.
1031 proc string_to_regexp {str} {
1033 regsub -all {[]*+.|()^$\[\\]} $str {\\&} result
1037 # Same as gdb_test, but the second parameter is not a regexp,
1038 # but a string that must match exactly.
1040 proc gdb_test_exact { args } {
1041 upvar timeout timeout
1043 set command [lindex $args 0]
1045 # This applies a special meaning to a null string pattern. Without
1046 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
1047 # messages from commands that should have no output except a new
1048 # prompt. With this, only results of a null string will match a null
1051 set pattern [lindex $args 1]
1052 if [string match $pattern ""] {
1053 set pattern [string_to_regexp [lindex $args 0]]
1055 set pattern [string_to_regexp [lindex $args 1]]
1058 # It is most natural to write the pattern argument with only
1059 # embedded \n's, especially if you are trying to avoid Tcl quoting
1060 # problems. But gdb_expect really wants to see \r\n in patterns. So
1061 # transform the pattern here. First transform \r\n back to \n, in
1062 # case some users of gdb_test_exact already do the right thing.
1063 regsub -all "\r\n" $pattern "\n" pattern
1064 regsub -all "\n" $pattern "\r\n" pattern
1065 if [llength $args]==3 then {
1066 set message [lindex $args 2]
1068 set message $command
1071 return [gdb_test $command $pattern $message]
1074 # Wrapper around gdb_test_multiple that looks for a list of expected
1075 # output elements, but which can appear in any order.
1076 # CMD is the gdb command.
1077 # NAME is the name of the test.
1078 # ELM_FIND_REGEXP specifies how to partition the output into elements to
1080 # ELM_EXTRACT_REGEXP specifies the part of ELM_FIND_REGEXP to compare.
1081 # RESULT_MATCH_LIST is a list of exact matches for each expected element.
1082 # All elements of RESULT_MATCH_LIST must appear for the test to pass.
1084 # A typical use of ELM_FIND_REGEXP/ELM_EXTRACT_REGEXP is to extract one line
1085 # of text per element and then strip trailing \r\n's.
1087 # gdb_test_list_exact "foo" "bar" \
1088 # "\[^\r\n\]+\[\r\n\]+" \
1091 # {expected result 1} \
1092 # {expected result 2} \
1095 proc gdb_test_list_exact { cmd name elm_find_regexp elm_extract_regexp result_match_list } {
1098 set matches [lsort $result_match_list]
1100 gdb_test_multiple $cmd $name {
1101 "$cmd\[\r\n\]" { exp_continue }
1102 -re $elm_find_regexp {
1103 set str $expect_out(0,string)
1104 verbose -log "seen: $str" 3
1105 regexp -- $elm_extract_regexp $str elm_seen
1106 verbose -log "extracted: $elm_seen" 3
1107 lappend seen $elm_seen
1110 -re "$gdb_prompt $" {
1112 foreach got [lsort $seen] have $matches {
1113 if {![string equal $got $have]} {
1118 if {[string length $failed] != 0} {
1119 fail "$name ($failed not found)"
1127 proc gdb_reinitialize_dir { subdir } {
1130 if [is_remote host] {
1135 -re "Reinitialize source path to empty.*y or n. " {
1138 -re "Source directories searched.*$gdb_prompt $" {
1139 send_gdb "dir $subdir\n"
1141 -re "Source directories searched.*$gdb_prompt $" {
1142 verbose "Dir set to $subdir"
1144 -re "$gdb_prompt $" {
1145 perror "Dir \"$subdir\" failed."
1149 -re "$gdb_prompt $" {
1150 perror "Dir \"$subdir\" failed."
1154 -re "$gdb_prompt $" {
1155 perror "Dir \"$subdir\" failed."
1161 # gdb_exit -- exit the GDB, killing the target program if necessary
1163 proc default_gdb_exit {} {
1165 global INTERNAL_GDBFLAGS GDBFLAGS
1167 global gdb_spawn_id;
1169 gdb_stop_suppressing_tests;
1171 if ![info exists gdb_spawn_id] {
1175 verbose "Quitting $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1177 if { [is_remote host] && [board_info host exists fileid] } {
1184 -re "DOSEXIT code" { }
1189 if ![is_remote host] {
1195 # Load a file into the debugger.
1196 # The return value is 0 for success, -1 for failure.
1198 # This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO
1199 # to one of these values:
1201 # debug file was loaded successfully and has debug information
1202 # nodebug file was loaded successfully and has no debug information
1203 # fail file was not loaded
1205 # I tried returning this information as part of the return value,
1206 # but ran into a mess because of the many re-implementations of
1207 # gdb_load in config/*.exp.
1209 # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use
1210 # this if they can get more information set.
1212 proc gdb_file_cmd { arg } {
1216 global last_loaded_file
1218 set last_loaded_file $arg
1220 # Set whether debug info was found.
1221 # Default to "fail".
1222 global gdb_file_cmd_debug_info
1223 set gdb_file_cmd_debug_info "fail"
1225 if [is_remote host] {
1226 set arg [remote_download host $arg]
1228 perror "download failed"
1233 # The file command used to kill the remote target. For the benefit
1234 # of the testsuite, preserve this behavior.
1237 -re "Kill the program being debugged. .y or n. $" {
1239 verbose "\t\tKilling previous program being debugged"
1242 -re "$gdb_prompt $" {
1247 send_gdb "file $arg\n"
1249 -re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" {
1250 verbose "\t\tLoaded $arg into the $GDB with no debugging symbols"
1251 set gdb_file_cmd_debug_info "nodebug"
1254 -re "Reading symbols from.*done.*$gdb_prompt $" {
1255 verbose "\t\tLoaded $arg into the $GDB"
1256 set gdb_file_cmd_debug_info "debug"
1259 -re "Load new symbol table from \".*\".*y or n. $" {
1262 -re "Reading symbols from.*done.*$gdb_prompt $" {
1263 verbose "\t\tLoaded $arg with new symbol table into $GDB"
1264 set gdb_file_cmd_debug_info "debug"
1268 perror "(timeout) Couldn't load $arg, other program already loaded."
1273 -re "No such file or directory.*$gdb_prompt $" {
1274 perror "($arg) No such file or directory"
1277 -re "$gdb_prompt $" {
1278 perror "couldn't load $arg into $GDB."
1282 perror "couldn't load $arg into $GDB (timed out)."
1286 # This is an attempt to detect a core dump, but seems not to
1287 # work. Perhaps we need to match .* followed by eof, in which
1288 # gdb_expect does not seem to have a way to do that.
1289 perror "couldn't load $arg into $GDB (end of file)."
1296 # start gdb -- start gdb running, default procedure
1298 # When running over NFS, particularly if running many simultaneous
1299 # tests on different hosts all using the same server, things can
1300 # get really slow. Give gdb at least 3 minutes to start up.
1302 proc default_gdb_start { } {
1303 global verbose use_gdb_stub
1305 global INTERNAL_GDBFLAGS GDBFLAGS
1308 global gdb_spawn_id;
1310 gdb_stop_suppressing_tests;
1312 # Set the default value, it may be overriden later by specific testfile.
1314 # Use `set_board_info use_gdb_stub' for the board file to flag the inferior
1315 # is already started after connecting and run/attach are not supported.
1316 # This is used for the "remote" protocol. After GDB starts you should
1317 # check global $use_gdb_stub instead of the board as the testfile may force
1318 # a specific different target protocol itself.
1319 set use_gdb_stub [target_info exists use_gdb_stub]
1321 verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1323 if [info exists gdb_spawn_id] {
1327 if ![is_remote host] {
1328 if { [which $GDB] == 0 } then {
1329 perror "$GDB does not exist."
1333 set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"];
1334 if { $res < 0 || $res == "" } {
1335 perror "Spawning $GDB failed."
1339 -re "\[\r\n\]$gdb_prompt $" {
1340 verbose "GDB initialized."
1342 -re "$gdb_prompt $" {
1343 perror "GDB never initialized."
1347 perror "(timeout) GDB never initialized after 10 seconds."
1352 set gdb_spawn_id -1;
1353 # force the height to "unlimited", so no pagers get used
1355 send_gdb "set height 0\n"
1357 -re "$gdb_prompt $" {
1358 verbose "Setting height to 0." 2
1361 warning "Couldn't set the height to 0"
1364 # force the width to "unlimited", so no wraparound occurs
1365 send_gdb "set width 0\n"
1367 -re "$gdb_prompt $" {
1368 verbose "Setting width to 0." 2
1371 warning "Couldn't set the width to 0."
1377 # Examine the output of compilation to determine whether compilation
1378 # failed or not. If it failed determine whether it is due to missing
1379 # compiler or due to compiler error. Report pass, fail or unsupported
1382 proc gdb_compile_test {src output} {
1383 if { $output == "" } {
1384 pass "compilation [file tail $src]"
1385 } elseif { [regexp {^[a-zA-Z_0-9]+: Can't find [^ ]+\.$} $output] } {
1386 unsupported "compilation [file tail $src]"
1387 } elseif { [regexp {.*: command not found[\r|\n]*$} $output] } {
1388 unsupported "compilation [file tail $src]"
1389 } elseif { [regexp {.*: [^\r\n]*compiler not installed[^\r\n]*[\r|\n]*$} $output] } {
1390 unsupported "compilation [file tail $src]"
1392 verbose -log "compilation failed: $output" 2
1393 fail "compilation [file tail $src]"
1397 # Return a 1 for configurations for which we don't even want to try to
1400 proc skip_cplus_tests {} {
1401 if { [istarget "h8300-*-*"] } {
1405 # The C++ IO streams are too large for HC11/HC12 and are thus not
1406 # available. The gdb C++ tests use them and don't compile.
1407 if { [istarget "m6811-*-*"] } {
1410 if { [istarget "m6812-*-*"] } {
1416 # Return a 1 for configurations for which don't have both C++ and the STL.
1418 proc skip_stl_tests {} {
1419 # Symbian supports the C++ language, but the STL is missing
1420 # (both headers and libraries).
1421 if { [istarget "arm*-*-symbianelf*"] } {
1425 return [skip_cplus_tests]
1428 # Return a 1 if I don't even want to try to test FORTRAN.
1430 proc skip_fortran_tests {} {
1434 # Return a 1 if I don't even want to try to test ada.
1436 proc skip_ada_tests {} {
1440 # Return a 1 if I don't even want to try to test java.
1442 proc skip_java_tests {} {
1446 # Return a 1 for configurations that do not support Python scripting.
1448 proc skip_python_tests {} {
1450 gdb_test_multiple "python print 'test'" "verify python support" {
1451 -re "not supported.*$gdb_prompt $" {
1452 unsupported "Python support is disabled."
1455 -re "$gdb_prompt $" {}
1461 # Return a 1 if we should skip shared library tests.
1463 proc skip_shlib_tests {} {
1464 # Run the shared library tests on native systems.
1469 # An abbreviated list of remote targets where we should be able to
1470 # run shared library tests.
1471 if {([istarget *-*-linux*]
1472 || [istarget *-*-*bsd*]
1473 || [istarget *-*-solaris2*]
1474 || [istarget arm*-*-symbianelf*]
1475 || [istarget *-*-mingw*]
1476 || [istarget *-*-cygwin*]
1477 || [istarget *-*-pe*])} {
1484 # Return 1 if _Complex types are supported, otherwise, return 0.
1486 proc support_complex_tests {} {
1487 global support_complex_tests_saved
1489 # Use the cached value, if it exists.
1490 if [info exists support_complex_tests_saved] {
1491 verbose "returning saved $support_complex_tests_saved" 2
1492 return $support_complex_tests_saved
1495 # Set up, compile, and execute a test program containing _Complex types.
1496 # Include the current process ID in the file names to prevent conflicts
1497 # with invocations for multiple testsuites.
1498 set src complex[pid].c
1499 set exe complex[pid].x
1501 set f [open $src "w"]
1502 puts $f "int main() {"
1503 puts $f "_Complex float cf;"
1504 puts $f "_Complex double cd;"
1505 puts $f "_Complex long double cld;"
1506 puts $f " return 0; }"
1509 verbose "compiling testfile $src" 2
1510 set compile_flags {debug nowarnings quiet}
1511 set lines [gdb_compile $src $exe executable $compile_flags]
1515 if ![string match "" $lines] then {
1516 verbose "testfile compilation failed, returning 0" 2
1517 set support_complex_tests_saved 0
1519 set support_complex_tests_saved 1
1522 return $support_complex_tests_saved
1525 # Return 1 if target hardware or OS supports single stepping to signal
1526 # handler, otherwise, return 0.
1528 proc can_single_step_to_signal_handler {} {
1530 # Targets don't have hardware single step. On these targets, when
1531 # a signal is delivered during software single step, gdb is unable
1532 # to determine the next instruction addresses, because start of signal
1533 # handler is one of them.
1534 if { [istarget "arm*-*-*"] || [istarget "mips*-*-*"]
1535 || [istarget "tic6x-*-*"] || [istarget "sparc*-*-linux*"] } {
1542 # Return 1 if target supports process record, otherwise return 0.
1544 proc supports_process_record {} {
1546 if [target_info exists gdb,use_precord] {
1547 return [target_info gdb,use_precord]
1550 if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"] } {
1557 # Return 1 if target supports reverse debugging, otherwise return 0.
1559 proc supports_reverse {} {
1561 if [target_info exists gdb,can_reverse] {
1562 return [target_info gdb,can_reverse]
1565 if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"] } {
1572 # Return 1 if target is ILP32.
1573 # This cannot be decided simply from looking at the target string,
1574 # as it might depend on externally passed compiler options like -m64.
1575 proc is_ilp32_target {} {
1576 global is_ilp32_target_saved
1578 # Use the cached value, if it exists. Cache value per "board" to handle
1579 # runs with multiple options (e.g. unix/{-m32,-64}) correctly.
1580 set me "is_ilp32_target"
1581 set board [target_info name]
1582 if [info exists is_ilp32_target_saved($board)] {
1583 verbose "$me: returning saved $is_ilp32_target_saved($board)" 2
1584 return $is_ilp32_target_saved($board)
1588 set src ilp32[pid].c
1589 set obj ilp32[pid].o
1591 set f [open $src "w"]
1592 puts $f "int dummy\[sizeof (int) == 4"
1593 puts $f " && sizeof (void *) == 4"
1594 puts $f " && sizeof (long) == 4 ? 1 : -1\];"
1597 verbose "$me: compiling testfile $src" 2
1598 set lines [gdb_compile $src $obj object {quiet}]
1602 if ![string match "" $lines] then {
1603 verbose "$me: testfile compilation failed, returning 0" 2
1604 return [set is_ilp32_target_saved($board) 0]
1607 verbose "$me: returning 1" 2
1608 return [set is_ilp32_target_saved($board) 1]
1611 # Return 1 if target is LP64.
1612 # This cannot be decided simply from looking at the target string,
1613 # as it might depend on externally passed compiler options like -m64.
1614 proc is_lp64_target {} {
1615 global is_lp64_target_saved
1617 # Use the cached value, if it exists. Cache value per "board" to handle
1618 # runs with multiple options (e.g. unix/{-m32,-64}) correctly.
1619 set me "is_lp64_target"
1620 set board [target_info name]
1621 if [info exists is_lp64_target_saved($board)] {
1622 verbose "$me: returning saved $is_lp64_target_saved($board)" 2
1623 return $is_lp64_target_saved($board)
1629 set f [open $src "w"]
1630 puts $f "int dummy\[sizeof (int) == 4"
1631 puts $f " && sizeof (void *) == 8"
1632 puts $f " && sizeof (long) == 8 ? 1 : -1\];"
1635 verbose "$me: compiling testfile $src" 2
1636 set lines [gdb_compile $src $obj object {quiet}]
1640 if ![string match "" $lines] then {
1641 verbose "$me: testfile compilation failed, returning 0" 2
1642 return [set is_lp64_target_saved($board) 0]
1645 verbose "$me: returning 1" 2
1646 return [set is_lp64_target_saved($board) 1]
1649 # Return 1 if target has x86_64 registers - either amd64 or x32.
1650 # x32 target identifies as x86_64-*-linux*, therefore it cannot be determined
1651 # just from the target string.
1652 proc is_amd64_regs_target {} {
1653 global is_amd64_regs_target_saved
1655 if {![istarget "x86_64-*-*"] && ![istarget "i?86-*"]} {
1659 # Use the cached value, if it exists. Cache value per "board" to handle
1660 # runs with multiple options (e.g. unix/{-m32,-64}) correctly.
1661 set me "is_amd64_regs_target"
1662 set board [target_info name]
1663 if [info exists is_amd64_regs_target_saved($board)] {
1664 verbose "$me: returning saved $is_amd64_regs_target_saved($board)" 2
1665 return $is_amd64_regs_target_saved($board)
1668 set src reg64[pid].s
1669 set obj reg64[pid].o
1671 set f [open $src "w"]
1673 {rax rbx rcx rdx rsi rdi rbp rsp r8 r9 r10 r11 r12 r13 r14 r15} {
1674 puts $f "\tincq %$reg"
1678 verbose "$me: compiling testfile $src" 2
1679 set lines [gdb_compile $src $obj object {quiet}]
1683 if ![string match "" $lines] then {
1684 verbose "$me: testfile compilation failed, returning 0" 2
1685 return [set is_amd64_regs_target_saved($board) 0]
1688 verbose "$me: returning 1" 2
1689 return [set is_amd64_regs_target_saved($board) 1]
1692 # Return 1 if this target is an x86 or x86-64 with -m32.
1693 proc is_x86_like_target {} {
1694 if {![istarget "x86_64-*-*"] && ![istarget i?86-*]} {
1697 return [expr [is_ilp32_target] && ![is_amd64_regs_target]]
1700 # Return 1 if displaced stepping is supported on target, otherwise, return 0.
1701 proc support_displaced_stepping {} {
1703 if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"]
1704 || [istarget "arm*-*-linux*"] || [istarget "powerpc-*-linux*"]
1705 || [istarget "powerpc64-*-linux*"] || [istarget "s390*-*-*"] } {
1712 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
1713 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
1715 proc skip_altivec_tests {} {
1716 global skip_vmx_tests_saved
1717 global srcdir subdir gdb_prompt inferior_exited_re
1719 # Use the cached value, if it exists.
1720 set me "skip_altivec_tests"
1721 if [info exists skip_vmx_tests_saved] {
1722 verbose "$me: returning saved $skip_vmx_tests_saved" 2
1723 return $skip_vmx_tests_saved
1726 # Some simulators are known to not support VMX instructions.
1727 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1728 verbose "$me: target known to not support VMX, returning 1" 2
1729 return [set skip_vmx_tests_saved 1]
1732 # Make sure we have a compiler that understands altivec.
1733 set compile_flags {debug nowarnings}
1734 if [get_compiler_info not-used] {
1735 warning "Could not get compiler info"
1738 if [test_compiler_info gcc*] {
1739 set compile_flags "$compile_flags additional_flags=-maltivec"
1740 } elseif [test_compiler_info xlc*] {
1741 set compile_flags "$compile_flags additional_flags=-qaltivec"
1743 verbose "Could not compile with altivec support, returning 1" 2
1747 # Set up, compile, and execute a test program containing VMX instructions.
1748 # Include the current process ID in the file names to prevent conflicts
1749 # with invocations for multiple testsuites.
1753 set f [open $src "w"]
1754 puts $f "int main() {"
1755 puts $f "#ifdef __MACH__"
1756 puts $f " asm volatile (\"vor v0,v0,v0\");"
1758 puts $f " asm volatile (\"vor 0,0,0\");"
1760 puts $f " return 0; }"
1763 verbose "$me: compiling testfile $src" 2
1764 set lines [gdb_compile $src $exe executable $compile_flags]
1767 if ![string match "" $lines] then {
1768 verbose "$me: testfile compilation failed, returning 1" 2
1769 return [set skip_vmx_tests_saved 1]
1772 # No error message, compilation succeeded so now run it via gdb.
1776 gdb_reinitialize_dir $srcdir/$subdir
1780 -re ".*Illegal instruction.*${gdb_prompt} $" {
1781 verbose -log "\n$me altivec hardware not detected"
1782 set skip_vmx_tests_saved 1
1784 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
1785 verbose -log "\n$me: altivec hardware detected"
1786 set skip_vmx_tests_saved 0
1789 warning "\n$me: default case taken"
1790 set skip_vmx_tests_saved 1
1794 remote_file build delete $exe
1796 verbose "$me: returning $skip_vmx_tests_saved" 2
1797 return $skip_vmx_tests_saved
1800 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
1801 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
1803 proc skip_vsx_tests {} {
1804 global skip_vsx_tests_saved
1805 global srcdir subdir gdb_prompt inferior_exited_re
1807 # Use the cached value, if it exists.
1808 set me "skip_vsx_tests"
1809 if [info exists skip_vsx_tests_saved] {
1810 verbose "$me: returning saved $skip_vsx_tests_saved" 2
1811 return $skip_vsx_tests_saved
1814 # Some simulators are known to not support Altivec instructions, so
1815 # they won't support VSX instructions as well.
1816 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1817 verbose "$me: target known to not support VSX, returning 1" 2
1818 return [set skip_vsx_tests_saved 1]
1821 # Make sure we have a compiler that understands altivec.
1822 set compile_flags {debug nowarnings quiet}
1823 if [get_compiler_info not-used] {
1824 warning "Could not get compiler info"
1827 if [test_compiler_info gcc*] {
1828 set compile_flags "$compile_flags additional_flags=-mvsx"
1829 } elseif [test_compiler_info xlc*] {
1830 set compile_flags "$compile_flags additional_flags=-qasm=gcc"
1832 verbose "Could not compile with vsx support, returning 1" 2
1839 set f [open $src "w"]
1840 puts $f "int main() {"
1841 puts $f " double a\[2\] = { 1.0, 2.0 };"
1842 puts $f "#ifdef __MACH__"
1843 puts $f " asm volatile (\"lxvd2x v0,v0,%\[addr\]\" : : \[addr\] \"r\" (a));"
1845 puts $f " asm volatile (\"lxvd2x 0,0,%\[addr\]\" : : \[addr\] \"r\" (a));"
1847 puts $f " return 0; }"
1850 verbose "$me: compiling testfile $src" 2
1851 set lines [gdb_compile $src $exe executable $compile_flags]
1854 if ![string match "" $lines] then {
1855 verbose "$me: testfile compilation failed, returning 1" 2
1856 return [set skip_vsx_tests_saved 1]
1859 # No error message, compilation succeeded so now run it via gdb.
1863 gdb_reinitialize_dir $srcdir/$subdir
1867 -re ".*Illegal instruction.*${gdb_prompt} $" {
1868 verbose -log "\n$me VSX hardware not detected"
1869 set skip_vsx_tests_saved 1
1871 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
1872 verbose -log "\n$me: VSX hardware detected"
1873 set skip_vsx_tests_saved 0
1876 warning "\n$me: default case taken"
1877 set skip_vsx_tests_saved 1
1881 remote_file build delete $exe
1883 verbose "$me: returning $skip_vsx_tests_saved" 2
1884 return $skip_vsx_tests_saved
1887 # Skip all the tests in the file if you are not on an hppa running
1890 proc skip_hp_tests {} {
1891 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
1892 verbose "Skip hp tests is $skip_hp"
1896 # Return whether we should skip tests for showing inlined functions in
1897 # backtraces. Requires get_compiler_info and get_debug_format.
1899 proc skip_inline_frame_tests {} {
1900 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
1901 if { ! [test_debug_format "DWARF 2"] } {
1905 # GCC before 4.1 does not emit DW_AT_call_file / DW_AT_call_line.
1906 if { ([test_compiler_info "gcc-2-*"]
1907 || [test_compiler_info "gcc-3-*"]
1908 || [test_compiler_info "gcc-4-0-*"]) } {
1915 # Return whether we should skip tests for showing variables from
1916 # inlined functions. Requires get_compiler_info and get_debug_format.
1918 proc skip_inline_var_tests {} {
1919 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
1920 if { ! [test_debug_format "DWARF 2"] } {
1927 # Return a 1 if we should skip tests that require hardware breakpoints
1929 proc skip_hw_breakpoint_tests {} {
1930 # Skip tests if requested by the board (note that no_hardware_watchpoints
1931 # disables both watchpoints and breakpoints)
1932 if { [target_info exists gdb,no_hardware_watchpoints]} {
1936 # These targets support hardware breakpoints natively
1937 if { [istarget "i?86-*-*"]
1938 || [istarget "x86_64-*-*"]
1939 || [istarget "ia64-*-*"]
1940 || [istarget "arm*-*-*"]} {
1947 # Return a 1 if we should skip tests that require hardware watchpoints
1949 proc skip_hw_watchpoint_tests {} {
1950 # Skip tests if requested by the board
1951 if { [target_info exists gdb,no_hardware_watchpoints]} {
1955 # These targets support hardware watchpoints natively
1956 if { [istarget "i?86-*-*"]
1957 || [istarget "x86_64-*-*"]
1958 || [istarget "ia64-*-*"]
1959 || [istarget "arm*-*-*"]
1960 || [istarget "powerpc*-*-linux*"]
1961 || [istarget "s390*-*-*"] } {
1968 # Return a 1 if we should skip tests that require *multiple* hardware
1969 # watchpoints to be active at the same time
1971 proc skip_hw_watchpoint_multi_tests {} {
1972 if { [skip_hw_watchpoint_tests] } {
1976 # These targets support just a single hardware watchpoint
1977 if { [istarget "arm*-*-*"]
1978 || [istarget "powerpc*-*-linux*"] } {
1985 # Return a 1 if we should skip tests that require read/access watchpoints
1987 proc skip_hw_watchpoint_access_tests {} {
1988 if { [skip_hw_watchpoint_tests] } {
1992 # These targets support just write watchpoints
1993 if { [istarget "s390*-*-*"] } {
2000 set compiler_info "unknown"
2002 set hp_cc_compiler 0
2003 set hp_aCC_compiler 0
2005 # Figure out what compiler I am using.
2007 # BINFILE is a "compiler information" output file. This implementation
2008 # does not use BINFILE.
2010 # ARGS can be empty or "C++". If empty, "C" is assumed.
2012 # There are several ways to do this, with various problems.
2014 # [ gdb_compile -E $ifile -o $binfile.ci ]
2015 # source $binfile.ci
2017 # Single Unix Spec v3 says that "-E -o ..." together are not
2018 # specified. And in fact, the native compiler on hp-ux 11 (among
2019 # others) does not work with "-E -o ...". Most targets used to do
2020 # this, and it mostly worked, because it works with gcc.
2022 # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ]
2023 # source $binfile.ci
2025 # This avoids the problem with -E and -o together. This almost works
2026 # if the build machine is the same as the host machine, which is
2027 # usually true of the targets which are not gcc. But this code does
2028 # not figure which compiler to call, and it always ends up using the C
2029 # compiler. Not good for setting hp_aCC_compiler. Targets
2030 # hppa*-*-hpux* and mips*-*-irix* used to do this.
2032 # [ gdb_compile -E $ifile > $binfile.ci ]
2033 # source $binfile.ci
2035 # dejagnu target_compile says that it supports output redirection,
2036 # but the code is completely different from the normal path and I
2037 # don't want to sweep the mines from that path. So I didn't even try
2040 # set cppout [ gdb_compile $ifile "" preprocess $args quiet ]
2043 # I actually do this for all targets now. gdb_compile runs the right
2044 # compiler, and TCL captures the output, and I eval the output.
2046 # Unfortunately, expect logs the output of the command as it goes by,
2047 # and dejagnu helpfully prints a second copy of it right afterwards.
2048 # So I turn off expect logging for a moment.
2050 # [ gdb_compile $ifile $ciexe_file executable $args ]
2051 # [ remote_exec $ciexe_file ]
2052 # [ source $ci_file.out ]
2054 # I could give up on -E and just do this.
2055 # I didn't get desperate enough to try this.
2057 # -- chastain 2004-01-06
2059 proc get_compiler_info {binfile args} {
2060 # For compiler.c and compiler.cc
2063 # I am going to play with the log to keep noise out.
2067 # These come from compiler.c or compiler.cc
2068 global compiler_info
2070 # Legacy global data symbols.
2072 global hp_cc_compiler
2073 global hp_aCC_compiler
2075 # Choose which file to preprocess.
2076 set ifile "${srcdir}/lib/compiler.c"
2077 if { [llength $args] > 0 && [lindex $args 0] == "c++" } {
2078 set ifile "${srcdir}/lib/compiler.cc"
2081 # Run $ifile through the right preprocessor.
2082 # Toggle gdb.log to keep the compiler output out of the log.
2084 if [is_remote host] {
2085 # We have to use -E and -o together, despite the comments
2086 # above, because of how DejaGnu handles remote host testing.
2087 set ppout "$outdir/compiler.i"
2088 gdb_compile "${ifile}" "$ppout" preprocess [list "$args" quiet]
2089 set file [open $ppout r]
2090 set cppout [read $file]
2093 set cppout [ gdb_compile "${ifile}" "" preprocess [list "$args" quiet] ]
2095 log_file -a "$outdir/$tool.log"
2099 foreach cppline [ split "$cppout" "\n" ] {
2100 if { [ regexp "^#" "$cppline" ] } {
2102 } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } {
2104 } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } {
2106 verbose "get_compiler_info: $cppline" 2
2110 verbose -log "get_compiler_info: $cppline"
2115 # Reset to unknown compiler if any diagnostics happened.
2117 set compiler_info "unknown"
2120 # Set the legacy symbols.
2122 set hp_cc_compiler 0
2123 set hp_aCC_compiler 0
2124 if { [regexp "^gcc-1-" "$compiler_info" ] } { set gcc_compiled 1 }
2125 if { [regexp "^gcc-2-" "$compiler_info" ] } { set gcc_compiled 2 }
2126 if { [regexp "^gcc-3-" "$compiler_info" ] } { set gcc_compiled 3 }
2127 if { [regexp "^gcc-4-" "$compiler_info" ] } { set gcc_compiled 4 }
2128 if { [regexp "^gcc-5-" "$compiler_info" ] } { set gcc_compiled 5 }
2129 if { [regexp "^hpcc-" "$compiler_info" ] } { set hp_cc_compiler 1 }
2130 if { [regexp "^hpacc-" "$compiler_info" ] } { set hp_aCC_compiler 1 }
2132 # Log what happened.
2133 verbose -log "get_compiler_info: $compiler_info"
2135 # Most compilers will evaluate comparisons and other boolean
2136 # operations to 0 or 1.
2137 uplevel \#0 { set true 1 }
2138 uplevel \#0 { set false 0 }
2140 # Use of aCC results in boolean results being displayed as
2142 if { $hp_aCC_compiler } {
2143 uplevel \#0 { set true true }
2144 uplevel \#0 { set false false }
2150 proc test_compiler_info { {compiler ""} } {
2151 global compiler_info
2153 # if no arg, return the compiler_info string
2155 if [string match "" $compiler] {
2156 if [info exists compiler_info] {
2157 return $compiler_info
2159 perror "No compiler info found."
2163 return [string match $compiler $compiler_info]
2166 proc current_target_name { } {
2168 if [info exists target_info(target,name)] {
2169 set answer $target_info(target,name)
2176 set gdb_wrapper_initialized 0
2177 set gdb_wrapper_target ""
2179 proc gdb_wrapper_init { args } {
2180 global gdb_wrapper_initialized;
2181 global gdb_wrapper_file;
2182 global gdb_wrapper_flags;
2183 global gdb_wrapper_target
2185 if { $gdb_wrapper_initialized == 1 } { return; }
2187 if {[target_info exists needs_status_wrapper] && \
2188 [target_info needs_status_wrapper] != "0"} {
2189 set result [build_wrapper "testglue.o"];
2190 if { $result != "" } {
2191 set gdb_wrapper_file [lindex $result 0];
2192 set gdb_wrapper_flags [lindex $result 1];
2194 warning "Status wrapper failed to build."
2197 set gdb_wrapper_initialized 1
2198 set gdb_wrapper_target [current_target_name]
2201 # Some targets need to always link a special object in. Save its path here.
2202 global gdb_saved_set_unbuffered_mode_obj
2203 set gdb_saved_set_unbuffered_mode_obj ""
2205 proc gdb_compile {source dest type options} {
2206 global GDB_TESTCASE_OPTIONS;
2207 global gdb_wrapper_file;
2208 global gdb_wrapper_flags;
2209 global gdb_wrapper_initialized;
2212 global gdb_saved_set_unbuffered_mode_obj
2214 set outdir [file dirname $dest]
2216 # Add platform-specific options if a shared library was specified using
2217 # "shlib=librarypath" in OPTIONS.
2221 foreach opt $options {
2222 if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] {
2223 if [test_compiler_info "xlc-*"] {
2224 # IBM xlc compiler doesn't accept shared library named other
2225 # than .so: use "-Wl," to bypass this
2226 lappend source "-Wl,$shlib_name"
2227 } elseif { ([istarget "*-*-mingw*"]
2228 || [istarget *-*-cygwin*]
2229 || [istarget *-*-pe*])} {
2230 lappend source "${shlib_name}.a"
2232 lappend source $shlib_name
2234 if { $shlib_found == 0 } {
2236 if { ([istarget "*-*-mingw*"]
2237 || [istarget *-*-cygwin*]) } {
2238 lappend new_options "additional_flags=-Wl,--enable-auto-import"
2241 } elseif { $opt == "shlib_load" } {
2244 lappend new_options $opt
2248 # We typically link to shared libraries using an absolute path, and
2249 # that's how they are found at runtime. If we are going to
2250 # dynamically load one by basename, we must specify rpath. If we
2251 # are using a remote host, DejaGNU will link to the shared library
2252 # using a relative path, so again we must specify an rpath.
2253 if { $shlib_load || ($shlib_found && [is_remote target]) } {
2254 if { ([istarget "*-*-mingw*"]
2255 || [istarget *-*-cygwin*]
2256 || [istarget *-*-pe*]
2257 || [istarget hppa*-*-hpux*])} {
2258 # Do not need anything.
2259 } elseif { [istarget *-*-freebsd*] || [istarget *-*-openbsd*] } {
2260 lappend new_options "ldflags=-Wl,-rpath,${outdir}"
2261 } elseif { [istarget arm*-*-symbianelf*] } {
2262 if { $shlib_load } {
2263 lappend new_options "libs=-ldl"
2266 if { $shlib_load } {
2267 lappend new_options "libs=-ldl"
2269 lappend new_options "ldflags=-Wl,-rpath,\\\$ORIGIN"
2272 set options $new_options
2274 if [target_info exists is_vxworks] {
2275 set options2 { "additional_flags=-Dvxworks" }
2276 set options [concat $options2 $options]
2278 if [info exists GDB_TESTCASE_OPTIONS] {
2279 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
2281 verbose "options are $options"
2282 verbose "source is $source $dest $type $options"
2284 if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init }
2286 if {[target_info exists needs_status_wrapper] && \
2287 [target_info needs_status_wrapper] != "0" && \
2288 [info exists gdb_wrapper_file]} {
2289 lappend options "libs=${gdb_wrapper_file}"
2290 lappend options "ldflags=${gdb_wrapper_flags}"
2293 # Replace the "nowarnings" option with the appropriate additional_flags
2294 # to disable compiler warnings.
2295 set nowarnings [lsearch -exact $options nowarnings]
2296 if {$nowarnings != -1} {
2297 if [target_info exists gdb,nowarnings_flag] {
2298 set flag "additional_flags=[target_info gdb,nowarnings_flag]"
2300 set flag "additional_flags=-w"
2302 set options [lreplace $options $nowarnings $nowarnings $flag]
2305 if { $type == "executable" } {
2306 if { ([istarget "*-*-mingw*"]
2307 || [istarget "*-*-*djgpp"]
2308 || [istarget "*-*-cygwin*"])} {
2309 # Force output to unbuffered mode, by linking in an object file
2310 # with a global contructor that calls setvbuf.
2312 # Compile the special object seperatelly for two reasons:
2313 # 1) Insulate it from $options.
2314 # 2) Avoid compiling it for every gdb_compile invocation,
2315 # which is time consuming, especially if we're remote
2318 if { $gdb_saved_set_unbuffered_mode_obj == "" } {
2319 verbose "compiling gdb_saved_set_unbuffered_obj"
2320 set unbuf_src ${srcdir}/lib/set_unbuffered_mode.c
2321 set unbuf_obj ${objdir}/set_unbuffered_mode.o
2323 set result [gdb_compile "${unbuf_src}" "${unbuf_obj}" object {nowarnings}]
2324 if { $result != "" } {
2328 set gdb_saved_set_unbuffered_mode_obj ${objdir}/set_unbuffered_mode_saved.o
2329 # Link a copy of the output object, because the
2330 # original may be automatically deleted.
2331 remote_exec host "cp -f $unbuf_obj $gdb_saved_set_unbuffered_mode_obj"
2333 verbose "gdb_saved_set_unbuffered_obj already compiled"
2336 # Rely on the internal knowledge that the global ctors are ran in
2337 # reverse link order. In that case, we can use ldflags to
2338 # avoid copying the object file to the host multiple
2340 # This object can only be added if standard libraries are
2341 # used. Thus, we need to disable it if -nostdlib option is used
2342 if {[lsearch -regexp $options "-nostdlib"] < 0 } {
2343 lappend options "ldflags=$gdb_saved_set_unbuffered_mode_obj"
2348 set result [target_compile $source $dest $type $options];
2350 # Prune uninteresting compiler (and linker) output.
2351 regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result
2353 regsub "\[\r\n\]*$" "$result" "" result;
2354 regsub "^\[\r\n\]*" "$result" "" result;
2356 if {[lsearch $options quiet] < 0} {
2357 # We shall update this on a per language basis, to avoid
2358 # changing the entire testsuite in one go.
2359 if {[lsearch $options f77] >= 0} {
2360 gdb_compile_test $source $result
2361 } elseif { $result != "" } {
2362 clone_output "gdb compile failed, $result"
2369 # This is just like gdb_compile, above, except that it tries compiling
2370 # against several different thread libraries, to see which one this
2372 proc gdb_compile_pthreads {source dest type options} {
2374 set why_msg "unrecognized error"
2375 foreach lib {-lpthreads -lpthread -lthread ""} {
2376 # This kind of wipes out whatever libs the caller may have
2377 # set. Or maybe theirs will override ours. How infelicitous.
2378 set options_with_lib [concat $options [list libs=$lib quiet]]
2379 set ccout [gdb_compile $source $dest $type $options_with_lib]
2380 switch -regexp -- $ccout {
2381 ".*no posix threads support.*" {
2382 set why_msg "missing threads include file"
2385 ".*cannot open -lpthread.*" {
2386 set why_msg "missing runtime threads library"
2388 ".*Can't find library for -lpthread.*" {
2389 set why_msg "missing runtime threads library"
2392 pass "successfully compiled posix threads test case"
2398 if {!$built_binfile} {
2399 unsupported "Couldn't compile $source: ${why_msg}"
2404 # Build a shared library from SOURCES. You must use get_compiler_info
2407 proc gdb_compile_shlib {sources dest options} {
2408 set obj_options $options
2410 switch -glob [test_compiler_info] {
2412 lappend obj_options "additional_flags=-qpic"
2415 if { !([istarget "powerpc*-*-aix*"]
2416 || [istarget "rs6000*-*-aix*"]
2417 || [istarget "*-*-cygwin*"]
2418 || [istarget "*-*-mingw*"]
2419 || [istarget "*-*-pe*"]) } {
2420 lappend obj_options "additional_flags=-fpic"
2424 switch -glob [istarget] {
2426 lappend obj_options "additional_flags=+z"
2429 # Disable SGI compiler's implicit -Dsgi
2430 lappend obj_options "additional_flags=-Usgi"
2433 # don't know what the compiler is...
2439 set outdir [file dirname $dest]
2441 foreach source $sources {
2442 set sourcebase [file tail $source]
2443 if {[gdb_compile $source "${outdir}/${sourcebase}.o" object $obj_options] != ""} {
2446 lappend objects ${outdir}/${sourcebase}.o
2449 if [istarget "hppa*-*-hpux*"] {
2450 remote_exec build "ld -b ${objects} -o ${dest}"
2452 set link_options $options
2453 if [test_compiler_info "xlc-*"] {
2454 lappend link_options "additional_flags=-qmkshrobj"
2456 lappend link_options "additional_flags=-shared"
2458 if { ([istarget "*-*-mingw*"]
2459 || [istarget *-*-cygwin*]
2460 || [istarget *-*-pe*])} {
2461 lappend link_options "additional_flags=-Wl,--out-implib,${dest}.a"
2462 } elseif [is_remote target] {
2463 # By default, we do not set the soname. This causes the linker
2464 # on ELF systems to create a DT_NEEDED entry in the executable
2465 # refering to the full path name of the library. This is a
2466 # problem in remote testing if the library is in a different
2467 # directory there. To fix this, we set a soname of just the
2468 # base filename for the library, and add an appropriate -rpath
2469 # to the main executable (in gdb_compile).
2470 set destbase [file tail $dest]
2471 lappend link_options "additional_flags=-Wl,-soname,$destbase"
2474 if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
2480 # This is just like gdb_compile_shlib, above, except that it tries compiling
2481 # against several different thread libraries, to see which one this
2483 proc gdb_compile_shlib_pthreads {sources dest options} {
2485 set why_msg "unrecognized error"
2486 foreach lib {-lpthreads -lpthread -lthread ""} {
2487 # This kind of wipes out whatever libs the caller may have
2488 # set. Or maybe theirs will override ours. How infelicitous.
2489 set options_with_lib [concat $options [list libs=$lib quiet]]
2490 set ccout [gdb_compile_shlib $sources $dest $options_with_lib]
2491 switch -regexp -- $ccout {
2492 ".*no posix threads support.*" {
2493 set why_msg "missing threads include file"
2496 ".*cannot open -lpthread.*" {
2497 set why_msg "missing runtime threads library"
2499 ".*Can't find library for -lpthread.*" {
2500 set why_msg "missing runtime threads library"
2503 pass "successfully compiled posix threads test case"
2509 if {!$built_binfile} {
2510 unsupported "Couldn't compile $sources: ${why_msg}"
2515 # This is just like gdb_compile_pthreads, above, except that we always add the
2516 # objc library for compiling Objective-C programs
2517 proc gdb_compile_objc {source dest type options} {
2519 set why_msg "unrecognized error"
2520 foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} {
2521 # This kind of wipes out whatever libs the caller may have
2522 # set. Or maybe theirs will override ours. How infelicitous.
2523 if { $lib == "solaris" } {
2524 set lib "-lpthread -lposix4"
2526 if { $lib != "-lobjc" } {
2527 set lib "-lobjc $lib"
2529 set options_with_lib [concat $options [list libs=$lib quiet]]
2530 set ccout [gdb_compile $source $dest $type $options_with_lib]
2531 switch -regexp -- $ccout {
2532 ".*no posix threads support.*" {
2533 set why_msg "missing threads include file"
2536 ".*cannot open -lpthread.*" {
2537 set why_msg "missing runtime threads library"
2539 ".*Can't find library for -lpthread.*" {
2540 set why_msg "missing runtime threads library"
2543 pass "successfully compiled objc with posix threads test case"
2549 if {!$built_binfile} {
2550 unsupported "Couldn't compile $source: ${why_msg}"
2555 proc send_gdb { string } {
2556 global suppress_flag;
2557 if { $suppress_flag } {
2558 return "suppressed";
2560 return [remote_send host "$string"];
2566 proc gdb_expect { args } {
2567 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
2568 set atimeout [lindex $args 0];
2569 set expcode [list [lindex $args 1]];
2574 upvar timeout timeout;
2576 if [target_info exists gdb,timeout] {
2577 if [info exists timeout] {
2578 if { $timeout < [target_info gdb,timeout] } {
2579 set gtimeout [target_info gdb,timeout];
2581 set gtimeout $timeout;
2584 set gtimeout [target_info gdb,timeout];
2588 if ![info exists gtimeout] {
2590 if [info exists timeout] {
2591 set gtimeout $timeout;
2595 if [info exists atimeout] {
2596 if { ![info exists gtimeout] || $gtimeout < $atimeout } {
2597 set gtimeout $atimeout;
2600 if ![info exists gtimeout] {
2606 global suppress_flag;
2607 global remote_suppress_flag;
2608 if [info exists remote_suppress_flag] {
2609 set old_val $remote_suppress_flag;
2611 if [info exists suppress_flag] {
2612 if { $suppress_flag } {
2613 set remote_suppress_flag 1;
2617 {uplevel remote_expect host $gtimeout $expcode} string];
2618 if [info exists old_val] {
2619 set remote_suppress_flag $old_val;
2621 if [info exists remote_suppress_flag] {
2622 unset remote_suppress_flag;
2627 global errorInfo errorCode;
2629 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
2631 return -code $code $string
2635 # gdb_expect_list TEST SENTINEL LIST -- expect a sequence of outputs
2637 # Check for long sequence of output by parts.
2638 # TEST: is the test message to be printed with the test success/fail.
2639 # SENTINEL: Is the terminal pattern indicating that output has finished.
2640 # LIST: is the sequence of outputs to match.
2641 # If the sentinel is recognized early, it is considered an error.
2644 # 1 if the test failed,
2645 # 0 if the test passes,
2646 # -1 if there was an internal error.
2648 proc gdb_expect_list {test sentinel list} {
2650 global suppress_flag
2653 if { $suppress_flag } {
2655 unresolved "${test}"
2657 while { ${index} < [llength ${list}] } {
2658 set pattern [lindex ${list} ${index}]
2659 set index [expr ${index} + 1]
2660 verbose -log "gdb_expect_list pattern: /$pattern/" 2
2661 if { ${index} == [llength ${list}] } {
2664 -re "${pattern}${sentinel}" {
2665 # pass "${test}, pattern ${index} + sentinel"
2668 fail "${test} (pattern ${index} + sentinel)"
2671 -re ".*A problem internal to GDB has been detected" {
2672 fail "${test} (GDB internal error)"
2674 gdb_internal_error_resync
2677 fail "${test} (pattern ${index} + sentinel) (timeout)"
2682 # unresolved "${test}, pattern ${index} + sentinel"
2688 # pass "${test}, pattern ${index}"
2691 fail "${test} (pattern ${index})"
2694 -re ".*A problem internal to GDB has been detected" {
2695 fail "${test} (GDB internal error)"
2697 gdb_internal_error_resync
2700 fail "${test} (pattern ${index}) (timeout)"
2705 # unresolved "${test}, pattern ${index}"
2719 proc gdb_suppress_entire_file { reason } {
2720 global suppress_flag;
2722 warning "$reason\n";
2723 set suppress_flag -1;
2727 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
2728 # gdb_expect to fail immediately (until the next call to
2729 # gdb_stop_suppressing_tests).
2731 proc gdb_suppress_tests { args } {
2732 global suppress_flag;
2734 return; # fnf - disable pending review of results where
2735 # testsuite ran better without this
2738 if { $suppress_flag == 1 } {
2739 if { [llength $args] > 0 } {
2740 warning "[lindex $args 0]\n";
2742 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
2748 # Clear suppress_flag.
2750 proc gdb_stop_suppressing_tests { } {
2751 global suppress_flag;
2753 if [info exists suppress_flag] {
2754 if { $suppress_flag > 0 } {
2755 set suppress_flag 0;
2756 clone_output "Tests restarted.\n";
2759 set suppress_flag 0;
2763 proc gdb_clear_suppressed { } {
2764 global suppress_flag;
2766 set suppress_flag 0;
2769 proc gdb_start { } {
2774 catch default_gdb_exit
2778 # gdb_load_cmd -- load a file into the debugger.
2779 # ARGS - additional args to load command.
2780 # return a -1 if anything goes wrong.
2782 proc gdb_load_cmd { args } {
2785 if [target_info exists gdb_load_timeout] {
2786 set loadtimeout [target_info gdb_load_timeout]
2788 set loadtimeout 1600
2790 send_gdb "load $args\n"
2791 verbose "Timeout is now $loadtimeout seconds" 2
2792 gdb_expect $loadtimeout {
2793 -re "Loading section\[^\r\]*\r\n" {
2796 -re "Start address\[\r\]*\r\n" {
2799 -re "Transfer rate\[\r\]*\r\n" {
2802 -re "Memory access error\[^\r\]*\r\n" {
2803 perror "Failed to load program"
2806 -re "$gdb_prompt $" {
2809 -re "(.*)\r\n$gdb_prompt " {
2810 perror "Unexpected reponse from 'load' -- $expect_out(1,string)"
2814 perror "Timed out trying to load $args."
2821 # Return the filename to download to the target and load on the target
2822 # for this shared library. Normally just LIBNAME, unless shared libraries
2823 # for this target have separate link and load images.
2825 proc shlib_target_file { libname } {
2829 # Return the filename GDB will load symbols from when debugging this
2830 # shared library. Normally just LIBNAME, unless shared libraries for
2831 # this target have separate link and load images.
2833 proc shlib_symbol_file { libname } {
2837 # Return the filename to download to the target and load for this
2838 # executable. Normally just BINFILE unless it is renamed to something
2839 # else for this target.
2841 proc exec_target_file { binfile } {
2845 # Return the filename GDB will load symbols from when debugging this
2846 # executable. Normally just BINFILE unless executables for this target
2847 # have separate files for symbols.
2849 proc exec_symbol_file { binfile } {
2853 # Rename the executable file. Normally this is just BINFILE1 being renamed
2854 # to BINFILE2, but some targets require multiple binary files.
2855 proc gdb_rename_execfile { binfile1 binfile2 } {
2856 file rename -force [exec_target_file ${binfile1}] \
2857 [exec_target_file ${binfile2}]
2858 if { [exec_target_file ${binfile1}] != [exec_symbol_file ${binfile1}] } {
2859 file rename -force [exec_symbol_file ${binfile1}] \
2860 [exec_symbol_file ${binfile2}]
2864 # "Touch" the executable file to update the date. Normally this is just
2865 # BINFILE, but some targets require multiple files.
2866 proc gdb_touch_execfile { binfile } {
2867 set time [clock seconds]
2868 file mtime [exec_target_file ${binfile}] $time
2869 if { [exec_target_file ${binfile}] != [exec_symbol_file ${binfile}] } {
2870 file mtime [exec_symbol_file ${binfile}] $time
2876 # Copy a file to the remote target and return its target filename.
2877 # Schedule the file to be deleted at the end of this test.
2879 proc gdb_download { filename } {
2882 set destname [remote_download target $filename]
2883 lappend cleanfiles $destname
2887 # gdb_load_shlibs LIB...
2889 # Copy the listed libraries to the target.
2891 proc gdb_load_shlibs { args } {
2892 if {![is_remote target]} {
2896 foreach file $args {
2897 gdb_download [shlib_target_file $file]
2900 # Even if the target supplies full paths for shared libraries,
2901 # they may not be paths for this system.
2902 gdb_test "set solib-search-path [file dirname [lindex $args 0]]" "" ""
2906 # gdb_load -- load a file into the debugger.
2907 # Many files in config/*.exp override this procedure.
2909 proc gdb_load { arg } {
2910 return [gdb_file_cmd $arg]
2913 # gdb_reload -- load a file into the target. Called before "running",
2914 # either the first time or after already starting the program once,
2915 # for remote targets. Most files that override gdb_load should now
2916 # override this instead.
2918 proc gdb_reload { } {
2919 # For the benefit of existing configurations, default to gdb_load.
2920 # Specifying no file defaults to the executable currently being
2922 return [gdb_load ""]
2925 proc gdb_continue { function } {
2928 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
2931 proc default_gdb_init { args } {
2932 global gdb_wrapper_initialized
2933 global gdb_wrapper_target
2938 gdb_clear_suppressed;
2940 # Make sure that the wrapper is rebuilt
2941 # with the appropriate multilib option.
2942 if { $gdb_wrapper_target != [current_target_name] } {
2943 set gdb_wrapper_initialized 0
2946 # Unlike most tests, we have a small number of tests that generate
2947 # a very large amount of output. We therefore increase the expect
2948 # buffer size to be able to contain the entire test output.
2950 # Also set this value for the currently running GDB.
2951 match_max [match_max -d]
2953 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
2954 if { [llength $args] > 0 } {
2957 set file [lindex $args 0];
2959 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
2962 if [target_info exists gdb_prompt] {
2963 set gdb_prompt [target_info gdb_prompt];
2965 set gdb_prompt "\\(gdb\\)"
2968 if [info exists use_gdb_stub] {
2973 # The default timeout used when testing GDB commands. We want to use
2974 # the same timeout as the default dejagnu timeout, unless the user has
2975 # already provided a specific value (probably through a site.exp file).
2976 global gdb_test_timeout
2977 if ![info exists gdb_test_timeout] {
2978 set gdb_test_timeout $timeout
2981 # A list of global variables that GDB testcases should not use.
2982 # We try to prevent their use by monitoring write accesses and raising
2983 # an error when that happens.
2984 set banned_variables { bug_id prms_id }
2986 # A list of procedures that GDB testcases should not use.
2987 # We try to prevent their use by monitoring invocations and raising
2988 # an error when that happens.
2989 set banned_procedures { strace }
2991 # gdb_init is called by runtest at start, but also by several
2992 # tests directly; gdb_finish is only called from within runtest after
2993 # each test source execution.
2994 # Placing several traces by repetitive calls to gdb_init leads
2995 # to problems, as only one trace is removed in gdb_finish.
2996 # To overcome this possible problem, we add a variable that records
2997 # if the banned variables and procedures are already traced.
3000 proc gdb_init { args } {
3001 # Reset the timeout value to the default. This way, any testcase
3002 # that changes the timeout value without resetting it cannot affect
3003 # the timeout used in subsequent testcases.
3004 global gdb_test_timeout
3006 set timeout $gdb_test_timeout
3008 # Block writes to all banned variables, and invocation of all
3009 # banned procedures...
3010 global banned_variables
3011 global banned_procedures
3012 global banned_traced
3013 if (!$banned_traced) {
3014 foreach banned_var $banned_variables {
3015 global "$banned_var"
3016 trace add variable "$banned_var" write error
3018 foreach banned_proc $banned_procedures {
3019 global "$banned_proc"
3020 trace add execution "$banned_proc" enter error
3025 # We set LC_ALL, LC_CTYPE, and LANG to C so that we get the same
3026 # messages as expected.
3031 # Don't let a .inputrc file or an existing setting of INPUTRC mess up
3032 # the test results. Even if /dev/null doesn't exist on the particular
3033 # platform, the readline library will use the default setting just by
3034 # failing to open the file. OTOH, opening /dev/null successfully will
3035 # also result in the default settings being used since nothing will be
3036 # read from this file.
3037 setenv INPUTRC "/dev/null"
3039 # The gdb.base/readline.exp arrow key test relies on the standard VT100
3040 # bindings, so make sure that an appropriate terminal is selected.
3041 # The same bug doesn't show up if we use ^P / ^N instead.
3044 # Some tests (for example gdb.base/maint.exp) shell out from gdb to use
3045 # grep. Clear GREP_OPTIONS to make the behavoiur predictable,
3046 # especially having color output turned on can cause tests to fail.
3047 setenv GREP_OPTIONS ""
3049 # Clear $gdbserver_reconnect_p.
3050 global gdbserver_reconnect_p
3051 set gdbserver_reconnect_p 1
3052 unset gdbserver_reconnect_p
3054 return [eval default_gdb_init $args];
3057 proc gdb_finish { } {
3060 # Exit first, so that the files are no longer in use.
3063 if { [llength $cleanfiles] > 0 } {
3064 eval remote_file target delete $cleanfiles
3068 # Unblock write access to the banned variables. Dejagnu typically
3069 # resets some of them between testcases.
3070 global banned_variables
3071 global banned_procedures
3072 global banned_traced
3073 if ($banned_traced) {
3074 foreach banned_var $banned_variables {
3075 global "$banned_var"
3076 trace remove variable "$banned_var" write error
3078 foreach banned_proc $banned_procedures {
3079 global "$banned_proc"
3080 trace remove execution "$banned_proc" enter error
3087 set debug_format "unknown"
3089 # Run the gdb command "info source" and extract the debugging format
3090 # information from the output and save it in debug_format.
3092 proc get_debug_format { } {
3098 set debug_format "unknown"
3099 send_gdb "info source\n"
3101 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
3102 set debug_format $expect_out(1,string)
3103 verbose "debug format is $debug_format"
3106 -re "No current source file.\r\n$gdb_prompt $" {
3107 perror "get_debug_format used when no current source file"
3110 -re "$gdb_prompt $" {
3111 warning "couldn't check debug format (no valid response)."
3115 warning "couldn't check debug format (timed out)."
3121 # Return true if FORMAT matches the debug format the current test was
3122 # compiled with. FORMAT is a shell-style globbing pattern; it can use
3123 # `*', `[...]', and so on.
3125 # This function depends on variables set by `get_debug_format', above.
3127 proc test_debug_format {format} {
3130 return [expr [string match $format $debug_format] != 0]
3133 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
3134 # COFF, stabs, etc). If that format matches the format that the
3135 # current test was compiled with, then the next test is expected to
3136 # fail for any target. Returns 1 if the next test or set of tests is
3137 # expected to fail, 0 otherwise (or if it is unknown). Must have
3138 # previously called get_debug_format.
3139 proc setup_xfail_format { format } {
3140 set ret [test_debug_format $format];
3148 # Like setup_kfail, but only call setup_kfail conditionally if
3149 # istarget[TARGET] returns true.
3150 proc setup_kfail_for_target { PR target } {
3151 if { [istarget $target] } {
3152 setup_kfail $PR $target
3156 # gdb_get_line_number TEXT [FILE]
3158 # Search the source file FILE, and return the line number of the
3159 # first line containing TEXT. If no match is found, return -1.
3161 # TEXT is a string literal, not a regular expression.
3163 # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is
3164 # specified, and does not start with "/", then it is assumed to be in
3165 # "$srcdir/$subdir". This is awkward, and can be fixed in the future,
3166 # by changing the callers and the interface at the same time.
3167 # In particular: gdb.base/break.exp, gdb.base/condbreak.exp,
3168 # gdb.base/ena-dis-br.exp.
3170 # Use this function to keep your test scripts independent of the
3171 # exact line numbering of the source file. Don't write:
3173 # send_gdb "break 20"
3175 # This means that if anyone ever edits your test's source file,
3176 # your test could break. Instead, put a comment like this on the
3177 # source file line you want to break at:
3179 # /* breakpoint spot: frotz.exp: test name */
3181 # and then write, in your test script (which we assume is named
3184 # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
3186 # (Yes, Tcl knows how to handle the nested quotes and brackets.
3189 # % puts "foo [lindex "bar baz" 1]"
3192 # Tcl is quite clever, for a little stringy language.)
3196 # The previous implementation of this procedure used the gdb search command.
3197 # This version is different:
3199 # . It works with MI, and it also works when gdb is not running.
3201 # . It operates on the build machine, not the host machine.
3203 # . For now, this implementation fakes a current directory of
3204 # $srcdir/$subdir to be compatible with the old implementation.
3205 # This will go away eventually and some callers will need to
3208 # . The TEXT argument is literal text and matches literally,
3209 # not a regular expression as it was before.
3211 # . State changes in gdb, such as changing the current file
3212 # and setting $_, no longer happen.
3214 # After a bit of time we can forget about the differences from the
3215 # old implementation.
3217 # --chastain 2004-08-05
3219 proc gdb_get_line_number { text { file "" } } {
3224 if { "$file" == "" } then {
3227 if { ! [regexp "^/" "$file"] } then {
3228 set file "$srcdir/$subdir/$file"
3231 if { [ catch { set fd [open "$file"] } message ] } then {
3237 for { set line 1 } { 1 } { incr line } {
3238 if { [ catch { set nchar [gets "$fd" body] } message ] } then {
3242 if { $nchar < 0 } then {
3245 if { [string first "$text" "$body"] >= 0 } then {
3251 if { [ catch { close "$fd" } message ] } then {
3259 # gdb_continue_to_end:
3260 # The case where the target uses stubs has to be handled specially. If a
3261 # stub is used, we set a breakpoint at exit because we cannot rely on
3262 # exit() behavior of a remote target.
3264 # MSSG is the error message that gets printed. If not given, a
3266 # COMMAND is the command to invoke. If not given, "continue" is
3268 # ALLOW_EXTRA is a flag indicating whether the test should expect
3269 # extra output between the "Continuing." line and the program
3270 # exiting. By default it is zero; if nonzero, any extra output
3273 proc gdb_continue_to_end {{mssg ""} {command continue} {allow_extra 0}} {
3274 global inferior_exited_re use_gdb_stub
3277 set text "continue until exit"
3279 set text "continue until exit at $mssg"
3287 if {![gdb_breakpoint "exit"]} {
3290 gdb_test $command "Continuing..*Breakpoint .*exit.*" \
3293 # Continue until we exit. Should not stop again.
3294 # Don't bother to check the output of the program, that may be
3295 # extremely tough for some remote systems.
3297 "Continuing.\[\r\n0-9\]+${extra}(... EXIT code 0\[\r\n\]+|$inferior_exited_re normally).*"\
3302 proc rerun_to_main {} {
3303 global gdb_prompt use_gdb_stub
3308 -re ".*Breakpoint .*main .*$gdb_prompt $"\
3309 {pass "rerun to main" ; return 0}
3310 -re "$gdb_prompt $"\
3311 {fail "rerun to main" ; return 0}
3312 timeout {fail "(timeout) rerun to main" ; return 0}
3317 -re "The program .* has been started already.*y or n. $" {
3321 -re "Starting program.*$gdb_prompt $"\
3322 {pass "rerun to main" ; return 0}
3323 -re "$gdb_prompt $"\
3324 {fail "rerun to main" ; return 0}
3325 timeout {fail "(timeout) rerun to main" ; return 0}
3330 # Print a message and return true if a test should be skipped
3331 # due to lack of floating point suport.
3333 proc gdb_skip_float_test { msg } {
3334 if [target_info exists gdb,skip_float_tests] {
3335 verbose "Skipping test '$msg': no float tests.";
3341 # Print a message and return true if a test should be skipped
3342 # due to lack of stdio support.
3344 proc gdb_skip_stdio_test { msg } {
3345 if [target_info exists gdb,noinferiorio] {
3346 verbose "Skipping test '$msg': no inferior i/o.";
3352 proc gdb_skip_bogus_test { msg } {
3356 # Return true if a test should be skipped due to lack of XML support
3358 # NOTE: This must be called while gdb is *not* running.
3360 proc gdb_skip_xml_test { } {
3363 global xml_missing_cached
3365 if {[info exists xml_missing_cached]} {
3366 return $xml_missing_cached
3370 set xml_missing_cached 0
3371 gdb_test_multiple "set tdesc filename ${srcdir}/gdb.xml/trivial.xml" "" {
3372 -re ".*XML support was disabled at compile time.*$gdb_prompt $" {
3373 set xml_missing_cached 1
3375 -re ".*$gdb_prompt $" { }
3378 return $xml_missing_cached
3381 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
3382 # ${binfile}.dbglnk, which is just like the executable ($binfile) but without
3383 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
3384 # the name of a debuginfo only file. This file will be stored in the same
3387 # Functions for separate debug info testing
3389 # starting with an executable:
3390 # foo --> original executable
3392 # at the end of the process we have:
3393 # foo.stripped --> foo w/o debug info
3394 # foo.debug --> foo's debug info
3395 # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug.
3397 # Return the build-id hex string (usually 160 bits as 40 hex characters)
3398 # converted to the form: .build-id/ab/cdef1234...89.debug
3399 # Return "" if no build-id found.
3400 proc build_id_debug_filename_get { exec } {
3401 set tmp "${exec}-tmp"
3402 set objcopy_program [transform objcopy]
3404 set result [catch "exec $objcopy_program -j .note.gnu.build-id -O binary $exec $tmp" output]
3405 verbose "result is $result"
3406 verbose "output is $output"
3411 fconfigure $fi -translation binary
3412 # Skip the NOTE header.
3417 if ![string compare $data ""] then {
3420 # Convert it to hex.
3421 binary scan $data H* data
3422 regsub {^..} $data {\0/} data
3423 return ".build-id/${data}.debug";
3426 # Create stripped files for DEST, replacing it. If ARGS is passed, it is a
3427 # list of optional flags. The only currently supported flag is no-main,
3428 # which removes the symbol entry for main from the separate debug file.
3430 # Function returns zero on success. Function will return non-zero failure code
3431 # on some targets not supporting separate debug info (such as i386-msdos).
3433 proc gdb_gnu_strip_debug { dest args } {
3435 # Use the first separate debug info file location searched by GDB so the
3436 # run cannot be broken by some stale file searched with higher precedence.
3437 set debug_file "${dest}.debug"
3439 set strip_to_file_program [transform strip]
3440 set objcopy_program [transform objcopy]
3442 set debug_link [file tail $debug_file]
3443 set stripped_file "${dest}.stripped"
3445 # Get rid of the debug info, and store result in stripped_file
3446 # something like gdb/testsuite/gdb.base/blah.stripped.
3447 set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
3448 verbose "result is $result"
3449 verbose "output is $output"
3454 # Workaround PR binutils/10802:
3455 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
3456 set perm [file attributes ${dest} -permissions]
3457 file attributes ${stripped_file} -permissions $perm
3459 # Get rid of everything but the debug info, and store result in debug_file
3460 # This will be in the .debug subdirectory, see above.
3461 set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
3462 verbose "result is $result"
3463 verbose "output is $output"
3468 # If no-main is passed, strip the symbol for main from the separate
3469 # file. This is to simulate the behavior of elfutils's eu-strip, which
3470 # leaves the symtab in the original file only. There's no way to get
3471 # objcopy or strip to remove the symbol table without also removing the
3472 # debugging sections, so this is as close as we can get.
3473 if { [llength $args] == 1 && [lindex $args 0] == "no-main" } {
3474 set result [catch "exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp" output]
3475 verbose "result is $result"
3476 verbose "output is $output"
3480 file delete "${debug_file}"
3481 file rename "${debug_file}-tmp" "${debug_file}"
3484 # Link the two previous output files together, adding the .gnu_debuglink
3485 # section to the stripped_file, containing a pointer to the debug_file,
3486 # save the new file in dest.
3487 # This will be the regular executable filename, in the usual location.
3488 set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
3489 verbose "result is $result"
3490 verbose "output is $output"
3495 # Workaround PR binutils/10802:
3496 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
3497 set perm [file attributes ${stripped_file} -permissions]
3498 file attributes ${dest} -permissions $perm
3503 # Test the output of GDB_COMMAND matches the pattern obtained
3504 # by concatenating all elements of EXPECTED_LINES. This makes
3505 # it possible to split otherwise very long string into pieces.
3506 # If third argument is not empty, it's used as the name of the
3507 # test to be printed on pass/fail.
3508 proc help_test_raw { gdb_command expected_lines args } {
3509 set message $gdb_command
3510 if [llength $args]>0 then {
3511 set message [lindex $args 0]
3513 set expected_output [join $expected_lines ""]
3514 gdb_test "${gdb_command}" "${expected_output}" $message
3517 # Test the output of "help COMMAND_CLASS". EXPECTED_INITIAL_LINES
3518 # are regular expressions that should match the beginning of output,
3519 # before the list of commands in that class. The presence of
3520 # command list and standard epilogue will be tested automatically.
3521 proc test_class_help { command_class expected_initial_lines args } {
3523 "List of commands\:.*\[\r\n\]+"
3524 "Type \"help\" followed by command name for full documentation\.\[\r\n\]+"
3525 "Type \"apropos word\" to search for commands related to \"word\"\.[\r\n\]+"
3526 "Command name abbreviations are allowed if unambiguous\."
3528 set l_entire_body [concat $expected_initial_lines $l_stock_body]
3530 eval [list help_test_raw "help ${command_class}" $l_entire_body] $args
3533 # COMMAND_LIST should have either one element -- command to test, or
3534 # two elements -- abbreviated command to test, and full command the first
3535 # element is abbreviation of.
3536 # The command must be a prefix command. EXPECTED_INITIAL_LINES
3537 # are regular expressions that should match the beginning of output,
3538 # before the list of subcommands. The presence of
3539 # subcommand list and standard epilogue will be tested automatically.
3540 proc test_prefix_command_help { command_list expected_initial_lines args } {
3541 set command [lindex $command_list 0]
3542 if {[llength $command_list]>1} {
3543 set full_command [lindex $command_list 1]
3545 set full_command $command
3547 # Use 'list' and not just {} because we want variables to
3548 # be expanded in this list.
3549 set l_stock_body [list\
3550 "List of $full_command subcommands\:.*\[\r\n\]+"\
3551 "Type \"help $full_command\" followed by $full_command subcommand name for full documentation\.\[\r\n\]+"\
3552 "Type \"apropos word\" to search for commands related to \"word\"\.\[\r\n\]+"\
3553 "Command name abbreviations are allowed if unambiguous\."]
3554 set l_entire_body [concat $expected_initial_lines $l_stock_body]
3555 if {[llength $args]>0} {
3556 help_test_raw "help ${command}" $l_entire_body [lindex $args 0]
3558 help_test_raw "help ${command}" $l_entire_body
3562 # Build executable named EXECUTABLE, from SOURCES. If SOURCES are not
3563 # provided, uses $EXECUTABLE.c. The TESTNAME paramer is the name of test
3564 # to pass to untested, if something is wrong. OPTIONS are passed
3565 # to gdb_compile directly.
3566 proc build_executable { testname executable {sources ""} {options {debug}} } {
3571 if {[llength $sources]==0} {
3572 set sources ${executable}.c
3575 set binfile ${objdir}/${subdir}/${executable}
3578 for {set i 0} "\$i<[llength $sources]" {incr i} {
3579 set s [lindex $sources $i]
3580 if { [gdb_compile "${srcdir}/${subdir}/${s}" "${binfile}${i}.o" object $options] != "" } {
3584 lappend objects "${binfile}${i}.o"
3587 if { [gdb_compile $objects "${binfile}" executable $options] != "" } {
3593 if { [lsearch -exact $options "c++"] >= 0 } {
3594 set info_options "c++"
3596 if [get_compiler_info ${binfile} ${info_options}] {
3602 # Starts fresh GDB binary and loads EXECUTABLE into GDB. EXECUTABLE is
3603 # the name of binary in ${objdir}/${subdir}.
3604 proc clean_restart { executable } {
3608 set binfile ${objdir}/${subdir}/${executable}
3612 gdb_reinitialize_dir $srcdir/$subdir
3616 # Prepares for testing, by calling build_executable, and then clean_restart.
3617 # Please refer to build_executable for parameter description.
3618 proc prepare_for_testing { testname executable {sources ""} {options {debug}}} {
3620 if {[build_executable $testname $executable $sources $options] == -1} {
3623 clean_restart $executable
3628 proc get_valueof { fmt exp default } {
3631 set test "get valueof \"${exp}\""
3633 gdb_test_multiple "print${fmt} ${exp}" "$test" {
3634 -re "\\$\[0-9\]* = (.*)\[\r\n\]*$gdb_prompt $" {
3635 set val $expect_out(1,string)
3639 fail "$test (timeout)"
3645 proc get_integer_valueof { exp default } {
3648 set test "get integer valueof \"${exp}\""
3650 gdb_test_multiple "print /d ${exp}" "$test" {
3651 -re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" {
3652 set val $expect_out(1,string)
3656 fail "$test (timeout)"
3662 proc get_hexadecimal_valueof { exp default } {
3664 send_gdb "print /x ${exp}\n"
3665 set test "get hexadecimal valueof \"${exp}\""
3667 -re "\\$\[0-9\]* = (0x\[0-9a-zA-Z\]+).*$gdb_prompt $" {
3668 set val $expect_out(1,string)
3673 fail "$test (timeout)"
3679 proc get_sizeof { type default } {
3680 return [get_integer_valueof "sizeof (${type})" $default]
3683 # Get the current value for remotetimeout and return it.
3684 proc get_remotetimeout { } {
3688 gdb_test_multiple "show remotetimeout" "" {
3689 -re "Timeout limit to wait for target to respond is ($decimal).*$gdb_prompt $" {
3690 return $expect_out(1,string);
3694 # Pick the default that gdb uses
3695 warning "Unable to read remotetimeout"
3699 # Set the remotetimeout to the specified timeout. Nothing is returned.
3700 proc set_remotetimeout { timeout } {
3703 gdb_test_multiple "set remotetimeout $timeout" "" {
3704 -re "$gdb_prompt $" {
3705 verbose "Set remotetimeout to $timeout\n"
3710 # Log gdb command line and script if requested.
3711 if {[info exists TRANSCRIPT]} {
3712 rename send_gdb real_send_gdb
3713 rename remote_spawn real_remote_spawn
3714 rename remote_close real_remote_close
3716 global gdb_transcript
3717 set gdb_transcript ""
3719 global gdb_trans_count
3720 set gdb_trans_count 1
3722 proc remote_spawn {args} {
3723 global gdb_transcript gdb_trans_count outdir
3725 if {$gdb_transcript != ""} {
3726 close $gdb_transcript
3728 set gdb_transcript [open [file join $outdir transcript.$gdb_trans_count] w]
3729 puts $gdb_transcript [lindex $args 1]
3730 incr gdb_trans_count
3732 return [uplevel real_remote_spawn $args]
3735 proc remote_close {args} {
3736 global gdb_transcript
3738 if {$gdb_transcript != ""} {
3739 close $gdb_transcript
3740 set gdb_transcript ""
3743 return [uplevel real_remote_close $args]
3746 proc send_gdb {args} {
3747 global gdb_transcript
3749 if {$gdb_transcript != ""} {
3750 puts -nonewline $gdb_transcript [lindex $args 0]
3753 return [uplevel real_send_gdb $args]
3757 proc core_find {binfile {deletefiles {}} {arg ""}} {
3758 global objdir subdir
3760 set destcore "$binfile.core"
3761 file delete $destcore
3763 # Create a core file named "$destcore" rather than just "core", to
3764 # avoid problems with sys admin types that like to regularly prune all
3765 # files named "core" from the system.
3767 # Arbitrarily try setting the core size limit to "unlimited" since
3768 # this does not hurt on systems where the command does not work and
3769 # allows us to generate a core on systems where it does.
3771 # Some systems append "core" to the name of the program; others append
3772 # the name of the program to "core"; still others (like Linux, as of
3773 # May 2003) create cores named "core.PID". In the latter case, we
3774 # could have many core files lying around, and it may be difficult to
3775 # tell which one is ours, so let's run the program in a subdirectory.
3777 set coredir "${objdir}/${subdir}/coredir.[getpid]"
3779 catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile} ${arg}; true) >/dev/null 2>&1\""
3780 # remote_exec host "${binfile}"
3781 foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
3782 if [remote_file build exists $i] {
3783 remote_exec build "mv $i $destcore"
3787 # Check for "core.PID".
3788 if { $found == 0 } {
3789 set names [glob -nocomplain -directory $coredir core.*]
3790 if {[llength $names] == 1} {
3791 set corefile [file join $coredir [lindex $names 0]]
3792 remote_exec build "mv $corefile $destcore"
3796 if { $found == 0 } {
3797 # The braindamaged HPUX shell quits after the ulimit -c above
3798 # without executing ${binfile}. So we try again without the
3799 # ulimit here if we didn't find a core file above.
3800 # Oh, I should mention that any "braindamaged" non-Unix system has
3801 # the same problem. I like the cd bit too, it's really neat'n stuff.
3802 catch "system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\""
3803 foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" {
3804 if [remote_file build exists $i] {
3805 remote_exec build "mv $i $destcore"
3811 # Try to clean up after ourselves.
3812 foreach deletefile $deletefiles {
3813 remote_file build delete [file join $coredir $deletefile]
3815 remote_exec build "rmdir $coredir"
3817 if { $found == 0 } {
3818 warning "can't generate a core file - core tests suppressed - check ulimit -c"
3824 # gdb_target_symbol_prefix_flags returns a string that can be added
3825 # to gdb_compile options to define SYMBOL_PREFIX macro value
3826 # symbol_prefix_flags returns a string that can be added
3827 # for targets that use underscore as symbol prefix.
3828 # TODO: find out automatically if the target needs this.
3830 proc gdb_target_symbol_prefix_flags {} {
3831 if { [istarget "*-*-cygwin*"] || [istarget "i?86-*-mingw*"]
3832 || [istarget "*-*-msdosdjgpp*"] || [istarget "*-*-go32*"] } {
3833 return "additional_flags=-DSYMBOL_PREFIX=\"_\""
3839 # Always load compatibility stuff.