1 # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
2 # 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
3 # Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # This file was written by Fred Fish. (fnf@cygnus.com)
20 # Generic gdb subroutines that should work for any target. If these
21 # need to be modified for any target, it can be done with a variable
22 # or by passing arguments.
25 # Tests would fail, logs on get_compiler_info() would be missing.
26 send_error "`site.exp' not found, run `make site.exp'!\n"
34 if [info exists TOOL_EXECUTABLE] {
35 set GDB $TOOL_EXECUTABLE;
37 if ![info exists GDB] {
38 if ![is_remote host] {
39 set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]]
41 set GDB [transform gdb];
44 verbose "using GDB = $GDB" 2
46 # GDBFLAGS is available for the user to set on the command line.
47 # E.g. make check RUNTESTFLAGS=GDBFLAGS=mumble
48 # Testcases may use it to add additional flags, but they must:
49 # - append new flags, not overwrite
50 # - restore the original value when done
52 if ![info exists GDBFLAGS] {
55 verbose "using GDBFLAGS = $GDBFLAGS" 2
57 # INTERNAL_GDBFLAGS contains flags that the testsuite requires.
58 global INTERNAL_GDBFLAGS
59 if ![info exists INTERNAL_GDBFLAGS] {
60 set INTERNAL_GDBFLAGS "-nw -nx -data-directory [pwd]/../data-directory"
63 # The variable gdb_prompt is a regexp which matches the gdb prompt.
64 # Set it if it is not already set.
66 if ![info exists gdb_prompt] then {
67 set gdb_prompt "\[(\]gdb\[)\]"
70 # The variable fullname_syntax_POSIX is a regexp which matches a POSIX
71 # absolute path ie. /foo/
72 set fullname_syntax_POSIX {/[^\n]*/}
73 # The variable fullname_syntax_UNC is a regexp which matches a Windows
74 # UNC path ie. \\D\foo\
75 set fullname_syntax_UNC {\\\\[^\\]+\\[^\n]+\\}
76 # The variable fullname_syntax_DOS_CASE is a regexp which matches a
77 # particular DOS case that GDB most likely will output
78 # ie. \foo\, but don't match \\.*\
79 set fullname_syntax_DOS_CASE {\\[^\\][^\n]*\\}
80 # The variable fullname_syntax_DOS is a regexp which matches a DOS path
81 # ie. a:\foo\ && a:foo\
82 set fullname_syntax_DOS {[a-zA-Z]:[^\n]*\\}
83 # The variable fullname_syntax is a regexp which matches what GDB considers
84 # an absolute path. It is currently debatable if the Windows style paths
85 # d:foo and \abc should be considered valid as an absolute path.
86 # Also, the purpse of this regexp is not to recognize a well formed
87 # absolute path, but to say with certainty that a path is absolute.
88 set fullname_syntax "($fullname_syntax_POSIX|$fullname_syntax_UNC|$fullname_syntax_DOS_CASE|$fullname_syntax_DOS)"
90 # Needed for some tests under Cygwin.
94 if ![info exists env(EXEEXT)] {
97 set EXEEXT $env(EXEEXT)
102 set inferior_exited_re "(\\\[Inferior \[0-9\]+ \\(.*\\) exited)"
104 ### Only procedures should come after this point.
107 # gdb_version -- extract and print the version number of GDB
109 proc default_gdb_version {} {
111 global INTERNAL_GDBFLAGS GDBFLAGS
113 set output [remote_exec host "$GDB $INTERNAL_GDBFLAGS --version"]
114 set tmp [lindex $output 1];
116 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
117 if ![is_remote host] {
118 clone_output "[which $GDB] version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
120 clone_output "$GDB on remote host version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
124 proc gdb_version { } {
125 return [default_gdb_version];
129 # gdb_unload -- unload a file if one is loaded
138 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
139 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
140 -re "A program is being debugged already.*Are you sure you want to change the file.*y or n. $" {
144 -re "Discard symbol table from .*y or n.*$" {
148 -re "$gdb_prompt $" {}
150 perror "couldn't unload file in $GDB (timed out)."
156 # Many of the tests depend on setting breakpoints at various places and
157 # running until that breakpoint is reached. At times, we want to start
158 # with a clean-slate with respect to breakpoints, so this utility proc
159 # lets us do this without duplicating this code everywhere.
162 proc delete_breakpoints {} {
165 # we need a larger timeout value here or this thing just confuses
166 # itself. May need a better implementation if possible. - guo
168 send_gdb "delete breakpoints\n"
170 -re "Delete all breakpoints.*y or n.*$" {
174 -re "$gdb_prompt $" { # This happens if there were no breakpoints
176 timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
178 send_gdb "info breakpoints\n"
180 -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
181 -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
182 -re "Delete all breakpoints.*or n.*$" {
186 timeout { perror "info breakpoints (timeout)" ; return }
192 # Generic run command.
194 # The second pattern below matches up to the first newline *only*.
195 # Using ``.*$'' could swallow up output that we attempt to match
198 proc gdb_run_cmd {args} {
201 if [target_info exists gdb_init_command] {
202 send_gdb "[target_info gdb_init_command]\n";
204 -re "$gdb_prompt $" { }
206 perror "gdb_init_command for target failed";
212 if [target_info exists use_gdb_stub] {
213 if [target_info exists gdb,do_reload_on_run] {
214 if { [gdb_reload] != 0 } {
217 send_gdb "continue\n";
219 -re "Continu\[^\r\n\]*\[\r\n\]" {}
225 if [target_info exists gdb,start_symbol] {
226 set start [target_info gdb,start_symbol];
230 send_gdb "jump *$start\n"
232 while { $start_attempt } {
233 # Cap (re)start attempts at three to ensure that this loop
234 # always eventually fails. Don't worry about trying to be
235 # clever and not send a command when it has failed.
236 if [expr $start_attempt > 3] {
237 perror "Jump to start() failed (retry count exceeded)";
240 set start_attempt [expr $start_attempt + 1];
242 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
245 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
246 perror "Can't find start symbol to run in gdb_run";
249 -re "No symbol \"start\" in current.*$gdb_prompt $" {
250 send_gdb "jump *_start\n";
252 -re "No symbol.*context.*$gdb_prompt $" {
255 -re "Line.* Jump anyway.*y or n. $" {
258 -re "The program is not being run.*$gdb_prompt $" {
259 if { [gdb_reload] != 0 } {
262 send_gdb "jump *$start\n";
265 perror "Jump to start() failed (timeout)";
270 if [target_info exists gdb_stub] {
272 -re "$gdb_prompt $" {
273 send_gdb "continue\n"
280 if [target_info exists gdb,do_reload_on_run] {
281 if { [gdb_reload] != 0 } {
285 send_gdb "run $args\n"
286 # This doesn't work quite right yet.
287 # Use -notransfer here so that test cases (like chng-sym.exp)
288 # may test for additional start-up messages.
290 -re "The program .* has been started already.*y or n. $" {
294 -notransfer -re "Starting program: \[^\r\n\]*" {}
295 -notransfer -re "$gdb_prompt $" {
296 # There is no more input expected.
301 # Generic start command. Return 0 if we could start the program, -1
304 proc gdb_start_cmd {args} {
307 if [target_info exists gdb_init_command] {
308 send_gdb "[target_info gdb_init_command]\n";
310 -re "$gdb_prompt $" { }
312 perror "gdb_init_command for target failed";
318 if [target_info exists use_gdb_stub] {
322 send_gdb "start $args\n"
323 # Use -notransfer here so that test cases (like chng-sym.exp)
324 # may test for additional start-up messages.
326 -re "The program .* has been started already.*y or n. $" {
330 -notransfer -re "Starting program: \[^\r\n\]*" {
337 # Set a breakpoint at FUNCTION. If there is an additional argument it is
338 # a list of options; the supported options are allow-pending, temporary,
341 proc gdb_breakpoint { function args } {
345 set pending_response n
346 if {[lsearch -exact [lindex $args 0] allow-pending] != -1} {
347 set pending_response y
350 set break_command "break"
351 set break_message "Breakpoint"
352 if {[lsearch -exact [lindex $args 0] temporary] != -1} {
353 set break_command "tbreak"
354 set break_message "Temporary breakpoint"
358 if {[lsearch -exact [lindex $args 0] no-message] != -1} {
362 send_gdb "$break_command $function\n"
363 # The first two regexps are what we get with -g, the third is without -g.
365 -re "$break_message \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
366 -re "$break_message \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
367 -re "$break_message \[0-9\]* at .*$gdb_prompt $" {}
368 -re "$break_message \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" {
369 if {$pending_response == "n"} {
370 if { $no_message == 0 } {
371 fail "setting breakpoint at $function"
376 -re "Make breakpoint pending.*y or \\\[n\\\]. $" {
377 send_gdb "$pending_response\n"
380 -re "A problem internal to GDB has been detected" {
381 fail "setting breakpoint at $function in runto (GDB internal error)"
382 gdb_internal_error_resync
385 -re "$gdb_prompt $" {
386 if { $no_message == 0 } {
387 fail "setting breakpoint at $function"
392 if { $no_message == 0 } {
393 fail "setting breakpoint at $function (timeout)"
401 # Set breakpoint at function and run gdb until it breaks there.
402 # Since this is the only breakpoint that will be set, if it stops
403 # at a breakpoint, we will assume it is the one we want. We can't
404 # just compare to "function" because it might be a fully qualified,
405 # single quoted C++ function specifier. If there's an additional argument,
406 # pass it to gdb_breakpoint.
408 proc runto { function args } {
414 if ![gdb_breakpoint $function [lindex $args 0]] {
420 # the "at foo.c:36" output we get with -g.
421 # the "in func" output we get without -g.
423 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
426 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
429 -re "The target does not support running in non-stop mode.\r\n$gdb_prompt $" {
430 unsupported "Non-stop mode not supported"
433 -re ".*A problem internal to GDB has been detected" {
434 fail "running to $function in runto (GDB internal error)"
435 gdb_internal_error_resync
438 -re "$gdb_prompt $" {
439 fail "running to $function in runto"
443 fail "running to $function in runto (end of file)"
447 fail "running to $function in runto (timeout)"
455 # runto_main -- ask gdb to run until we hit a breakpoint at main.
456 # The case where the target uses stubs has to be handled
457 # specially--if it uses stubs, assuming we hit
458 # breakpoint() and just step out of the function.
460 proc runto_main { } {
464 if ![target_info exists gdb_stub] {
476 ### Continue, and expect to hit a breakpoint.
477 ### Report a pass or fail, depending on whether it seems to have
478 ### worked. Use NAME as part of the test name; each call to
479 ### continue_to_breakpoint should use a NAME which is unique within
481 proc gdb_continue_to_breakpoint {name {location_pattern .*}} {
483 set full_name "continue to breakpoint: $name"
485 send_gdb "continue\n"
487 -re "Breakpoint .* (at|in) $location_pattern\r\n$gdb_prompt $" {
490 -re ".*$gdb_prompt $" {
494 fail "$full_name (timeout)"
500 # gdb_internal_error_resync:
502 # Answer the questions GDB asks after it reports an internal error
503 # until we get back to a GDB prompt. Decline to quit the debugging
504 # session, and decline to create a core file. Return non-zero if the
507 # This procedure just answers whatever questions come up until it sees
508 # a GDB prompt; it doesn't require you to have matched the input up to
509 # any specific point. However, it only answers questions it sees in
510 # the output itself, so if you've matched a question, you had better
511 # answer it yourself before calling this.
513 # You can use this function thus:
517 # -re ".*A problem internal to GDB has been detected" {
518 # gdb_internal_error_resync
523 proc gdb_internal_error_resync {} {
527 while {$count < 10} {
529 -re "Quit this debugging session\\? \\(y or n\\) $" {
533 -re "Create a core file of GDB\\? \\(y or n\\) $" {
537 -re "$gdb_prompt $" {
538 # We're resynchronized.
542 perror "Could not resync from internal error (timeout)"
547 perror "Could not resync from internal error (resync count exceeded)"
552 # gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS
553 # Send a command to gdb; test the result.
555 # COMMAND is the command to execute, send to GDB with send_gdb. If
556 # this is the null string no command is sent.
557 # MESSAGE is a message to be printed with the built-in failure patterns
558 # if one of them matches. If MESSAGE is empty COMMAND will be used.
559 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
560 # patterns. Pattern elements will be evaluated in the caller's
561 # context; action elements will be executed in the caller's context.
562 # Unlike patterns for gdb_test, these patterns should generally include
563 # the final newline and prompt.
566 # 1 if the test failed, according to a built-in failure pattern
567 # 0 if only user-supplied patterns matched
568 # -1 if there was an internal error.
570 # You can use this function thus:
572 # gdb_test_multiple "print foo" "test foo" {
573 # -re "expected output 1" {
576 # -re "expected output 2" {
581 # The standard patterns, such as "Inferior exited..." and "A problem
582 # ...", all being implicitly appended to that list.
584 proc gdb_test_multiple { command message user_code } {
588 global inferior_exited_re
589 upvar timeout timeout
590 upvar expect_out expect_out
592 if { $message == "" } {
596 if [string match "*\[\r\n\]" $command] {
597 error "Invalid trailing newline in \"$message\" test"
600 if [string match "*\[\r\n\]*" $message] {
601 error "Invalid newline in \"$message\" test"
604 # TCL/EXPECT WART ALERT
605 # Expect does something very strange when it receives a single braced
606 # argument. It splits it along word separators and performs substitutions.
607 # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
608 # evaluated as "\[ab\]". But that's not how TCL normally works; inside a
609 # double-quoted list item, "\[ab\]" is just a long way of representing
610 # "[ab]", because the backslashes will be removed by lindex.
612 # Unfortunately, there appears to be no easy way to duplicate the splitting
613 # that expect will do from within TCL. And many places make use of the
614 # "\[0-9\]" construct, so we need to support that; and some places make use
615 # of the "[func]" construct, so we need to support that too. In order to
616 # get this right we have to substitute quoted list elements differently
617 # from braced list elements.
619 # We do this roughly the same way that Expect does it. We have to use two
620 # lists, because if we leave unquoted newlines in the argument to uplevel
621 # they'll be treated as command separators, and if we escape newlines
622 # we mangle newlines inside of command blocks. This assumes that the
623 # input doesn't contain a pattern which contains actual embedded newlines
626 regsub -all {\n} ${user_code} { } subst_code
627 set subst_code [uplevel list $subst_code]
629 set processed_code ""
631 set expecting_action 0
633 foreach item $user_code subst_item $subst_code {
634 if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } {
635 lappend processed_code $item
638 if { $item == "-indices" || $item == "-re" || $item == "-ex" } {
639 lappend processed_code $item
642 if { $item == "-timeout" } {
644 lappend processed_code $item
647 if { $expecting_arg } {
649 lappend processed_code $item
652 if { $expecting_action } {
653 lappend processed_code "uplevel [list $item]"
654 set expecting_action 0
655 # Cosmetic, no effect on the list.
656 append processed_code "\n"
659 set expecting_action 1
660 lappend processed_code $subst_item
661 if {$patterns != ""} {
664 append patterns "\"$subst_item\""
667 # Also purely cosmetic.
668 regsub -all {\r} $patterns {\\r} patterns
669 regsub -all {\n} $patterns {\\n} patterns
672 send_user "Sending \"$command\" to gdb\n"
673 send_user "Looking to match \"$patterns\"\n"
674 send_user "Message is \"$message\"\n"
678 set string "${command}\n";
679 if { $command != "" } {
680 while { "$string" != "" } {
681 set foo [string first "\n" "$string"];
682 set len [string length "$string"];
683 if { $foo < [expr $len - 1] } {
684 set str [string range "$string" 0 $foo];
685 if { [send_gdb "$str"] != "" } {
686 global suppress_flag;
688 if { ! $suppress_flag } {
689 perror "Couldn't send $command to GDB.";
694 # since we're checking if each line of the multi-line
695 # command are 'accepted' by GDB here,
696 # we need to set -notransfer expect option so that
697 # command output is not lost for pattern matching
700 -notransfer -re "\[\r\n\]" { verbose "partial: match" 3 }
701 timeout { verbose "partial: timeout" 3 }
703 set string [string range "$string" [expr $foo + 1] end];
708 if { "$string" != "" } {
709 if { [send_gdb "$string"] != "" } {
710 global suppress_flag;
712 if { ! $suppress_flag } {
713 perror "Couldn't send $command to GDB.";
721 if [target_info exists gdb,timeout] {
722 set tmt [target_info gdb,timeout];
724 if [info exists timeout] {
728 if [info exists timeout] {
737 -re ".*A problem internal to GDB has been detected" {
738 fail "$message (GDB internal error)"
739 gdb_internal_error_resync
741 -re "\\*\\*\\* DOSEXIT code.*" {
742 if { $message != "" } {
745 gdb_suppress_entire_file "GDB died";
749 append code $processed_code
751 -re "Ending remote debugging.*$gdb_prompt $" {
752 if ![isnative] then {
753 warning "Can`t communicate to remote target."
759 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
760 perror "Undefined command \"$command\"."
764 -re "Ambiguous command.*$gdb_prompt $" {
765 perror "\"$command\" is not a unique command name."
769 -re "$inferior_exited_re with code \[0-9\]+.*$gdb_prompt $" {
770 if ![string match "" $message] then {
771 set errmsg "$message (the program exited)"
773 set errmsg "$command (the program exited)"
778 -re "$inferior_exited_re normally.*$gdb_prompt $" {
779 if ![string match "" $message] then {
780 set errmsg "$message (the program exited)"
782 set errmsg "$command (the program exited)"
787 -re "The program is not being run.*$gdb_prompt $" {
788 if ![string match "" $message] then {
789 set errmsg "$message (the program is no longer running)"
791 set errmsg "$command (the program is no longer running)"
796 -re "\r\n$gdb_prompt $" {
797 if ![string match "" $message] then {
804 perror "Window too small."
808 -re "\\((y or n|y or \\\[n\\\]|\\\[y\\\] or n)\\) " {
810 gdb_expect -re "$gdb_prompt $"
811 fail "$message (got interactive prompt)"
814 -re "\\\[0\\\] cancel\r\n\\\[1\\\] all.*\r\n> $" {
816 gdb_expect -re "$gdb_prompt $"
817 fail "$message (got breakpoint menu)"
821 perror "Process no longer exists"
822 if { $message != "" } {
828 perror "internal buffer is full."
833 if ![string match "" $message] then {
834 fail "$message (timeout)"
841 set code [catch {gdb_expect $tmt $code} string]
843 global errorInfo errorCode;
844 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
845 } elseif {$code == 2} {
846 return -code return $string
847 } elseif {$code == 3} {
849 } elseif {$code > 4} {
850 return -code $code $string
855 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
856 # Send a command to gdb; test the result.
858 # COMMAND is the command to execute, send to GDB with send_gdb. If
859 # this is the null string no command is sent.
860 # PATTERN is the pattern to match for a PASS, and must NOT include
861 # the \r\n sequence immediately before the gdb prompt.
862 # MESSAGE is an optional message to be printed. If this is
863 # omitted, then the pass/fail messages use the command string as the
864 # message. (If this is the empty string, then sometimes we don't
865 # call pass or fail at all; I don't understand this at all.)
866 # QUESTION is a question GDB may ask in response to COMMAND, like
868 # RESPONSE is the response to send if QUESTION appears.
871 # 1 if the test failed,
872 # 0 if the test passes,
873 # -1 if there was an internal error.
875 proc gdb_test { args } {
879 upvar timeout timeout
881 if [llength $args]>2 then {
882 set message [lindex $args 2]
884 set message [lindex $args 0]
886 set command [lindex $args 0]
887 set pattern [lindex $args 1]
889 if [llength $args]==5 {
890 set question_string [lindex $args 3];
891 set response_string [lindex $args 4];
893 set question_string "^FOOBAR$"
896 return [gdb_test_multiple $command $message {
897 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
898 if ![string match "" $message] then {
902 -re "(${question_string})$" {
903 send_gdb "$response_string\n";
909 # gdb_test_no_output COMMAND MESSAGE
910 # Send a command to GDB and verify that this command generated no output.
912 # See gdb_test_multiple for a description of the COMMAND and MESSAGE
913 # parameters. If MESSAGE is ommitted, then COMMAND will be used as
914 # the message. (If MESSAGE is the empty string, then sometimes we do not
915 # call pass or fail at all; I don't understand this at all.)
917 proc gdb_test_no_output { args } {
919 set command [lindex $args 0]
920 if [llength $args]>1 then {
921 set message [lindex $args 1]
926 set command_regex [string_to_regexp $command]
927 gdb_test_multiple $command $message {
928 -re "^$command_regex\r\n$gdb_prompt $" {
929 if ![string match "" $message] then {
936 # Send a command and then wait for a sequence of outputs.
937 # This is useful when the sequence is long and contains ".*", a single
938 # regexp to match the entire output can get a timeout much easier.
940 # COMMAND is the command to send.
941 # TEST_NAME is passed to pass/fail. COMMAND is used if TEST_NAME is "".
942 # EXPECTED_OUTPUT_LIST is a list of regexps of expected output, which are
943 # processed in order, and all must be present in the output.
945 # It is unnecessary to specify ".*" at the beginning or end of any regexp,
946 # there is an implicit ".*" between each element of EXPECTED_OUTPUT_LIST.
947 # There is also an implicit ".*" between the last regexp and the gdb prompt.
949 # Like gdb_test and gdb_test_multiple, the output is expected to end with the
950 # gdb prompt, which must not be specified in EXPECTED_OUTPUT_LIST.
953 # 1 if the test failed,
954 # 0 if the test passes,
955 # -1 if there was an internal error.
957 proc gdb_test_sequence { command test_name expected_output_list } {
959 if { $test_name == "" } {
960 set test_name $command
962 lappend expected_output_list ""; # implicit ".*" before gdb prompt
963 send_gdb "$command\n"
964 return [gdb_expect_list $test_name "$gdb_prompt $" $expected_output_list]
968 # Test that a command gives an error. For pass or fail, return
969 # a 1 to indicate that more tests can proceed. However a timeout
970 # is a serious error, generates a special fail message, and causes
971 # a 0 to be returned to indicate that more tests are likely to fail
974 proc test_print_reject { args } {
978 if [llength $args]==2 then {
979 set expectthis [lindex $args 1]
981 set expectthis "should never match this bogus string"
983 set sendthis [lindex $args 0]
985 send_user "Sending \"$sendthis\" to gdb\n"
986 send_user "Looking to match \"$expectthis\"\n"
988 send_gdb "$sendthis\n"
989 #FIXME: Should add timeout as parameter.
991 -re "A .* in expression.*\\.*$gdb_prompt $" {
992 pass "reject $sendthis"
995 -re "Invalid syntax in expression.*$gdb_prompt $" {
996 pass "reject $sendthis"
999 -re "Junk after end of expression.*$gdb_prompt $" {
1000 pass "reject $sendthis"
1003 -re "Invalid number.*$gdb_prompt $" {
1004 pass "reject $sendthis"
1007 -re "Invalid character constant.*$gdb_prompt $" {
1008 pass "reject $sendthis"
1011 -re "No symbol table is loaded.*$gdb_prompt $" {
1012 pass "reject $sendthis"
1015 -re "No symbol .* in current context.*$gdb_prompt $" {
1016 pass "reject $sendthis"
1019 -re "Unmatched single quote.*$gdb_prompt $" {
1020 pass "reject $sendthis"
1023 -re "A character constant must contain at least one character.*$gdb_prompt $" {
1024 pass "reject $sendthis"
1027 -re "$expectthis.*$gdb_prompt $" {
1028 pass "reject $sendthis"
1031 -re ".*$gdb_prompt $" {
1032 fail "reject $sendthis"
1036 fail "reject $sendthis (eof or timeout)"
1042 # Given an input string, adds backslashes as needed to create a
1043 # regexp that will match the string.
1045 proc string_to_regexp {str} {
1047 regsub -all {[]*+.|()^$\[\\]} $str {\\&} result
1051 # Same as gdb_test, but the second parameter is not a regexp,
1052 # but a string that must match exactly.
1054 proc gdb_test_exact { args } {
1055 upvar timeout timeout
1057 set command [lindex $args 0]
1059 # This applies a special meaning to a null string pattern. Without
1060 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
1061 # messages from commands that should have no output except a new
1062 # prompt. With this, only results of a null string will match a null
1065 set pattern [lindex $args 1]
1066 if [string match $pattern ""] {
1067 set pattern [string_to_regexp [lindex $args 0]]
1069 set pattern [string_to_regexp [lindex $args 1]]
1072 # It is most natural to write the pattern argument with only
1073 # embedded \n's, especially if you are trying to avoid Tcl quoting
1074 # problems. But gdb_expect really wants to see \r\n in patterns. So
1075 # transform the pattern here. First transform \r\n back to \n, in
1076 # case some users of gdb_test_exact already do the right thing.
1077 regsub -all "\r\n" $pattern "\n" pattern
1078 regsub -all "\n" $pattern "\r\n" pattern
1079 if [llength $args]==3 then {
1080 set message [lindex $args 2]
1082 set message $command
1085 return [gdb_test $command $pattern $message]
1088 # Wrapper around gdb_test_multiple that looks for a list of expected
1089 # output elements, but which can appear in any order.
1090 # CMD is the gdb command.
1091 # NAME is the name of the test.
1092 # ELM_FIND_REGEXP specifies how to partition the output into elements to
1094 # ELM_EXTRACT_REGEXP specifies the part of ELM_FIND_REGEXP to compare.
1095 # RESULT_MATCH_LIST is a list of exact matches for each expected element.
1096 # All elements of RESULT_MATCH_LIST must appear for the test to pass.
1098 # A typical use of ELM_FIND_REGEXP/ELM_EXTRACT_REGEXP is to extract one line
1099 # of text per element and then strip trailing \r\n's.
1101 # gdb_test_list_exact "foo" "bar" \
1102 # "\[^\r\n\]+\[\r\n\]+" \
1105 # {expected result 1} \
1106 # {expected result 2} \
1109 proc gdb_test_list_exact { cmd name elm_find_regexp elm_extract_regexp result_match_list } {
1112 set matches [lsort $result_match_list]
1114 gdb_test_multiple $cmd $name {
1115 "$cmd\[\r\n\]" { exp_continue }
1116 -re $elm_find_regexp {
1117 set str $expect_out(0,string)
1118 verbose -log "seen: $str" 3
1119 regexp -- $elm_extract_regexp $str elm_seen
1120 verbose -log "extracted: $elm_seen" 3
1121 lappend seen $elm_seen
1124 -re "$gdb_prompt $" {
1126 foreach got [lsort $seen] have $matches {
1127 if {![string equal $got $have]} {
1132 if {[string length $failed] != 0} {
1133 fail "$name ($failed not found)"
1141 proc gdb_reinitialize_dir { subdir } {
1144 if [is_remote host] {
1149 -re "Reinitialize source path to empty.*y or n. " {
1152 -re "Source directories searched.*$gdb_prompt $" {
1153 send_gdb "dir $subdir\n"
1155 -re "Source directories searched.*$gdb_prompt $" {
1156 verbose "Dir set to $subdir"
1158 -re "$gdb_prompt $" {
1159 perror "Dir \"$subdir\" failed."
1163 -re "$gdb_prompt $" {
1164 perror "Dir \"$subdir\" failed."
1168 -re "$gdb_prompt $" {
1169 perror "Dir \"$subdir\" failed."
1175 # gdb_exit -- exit the GDB, killing the target program if necessary
1177 proc default_gdb_exit {} {
1179 global INTERNAL_GDBFLAGS GDBFLAGS
1181 global gdb_spawn_id;
1183 gdb_stop_suppressing_tests;
1185 if ![info exists gdb_spawn_id] {
1189 verbose "Quitting $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1191 if { [is_remote host] && [board_info host exists fileid] } {
1198 -re "DOSEXIT code" { }
1203 if ![is_remote host] {
1209 # Load a file into the debugger.
1210 # The return value is 0 for success, -1 for failure.
1212 # This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO
1213 # to one of these values:
1215 # debug file was loaded successfully and has debug information
1216 # nodebug file was loaded successfully and has no debug information
1217 # fail file was not loaded
1219 # I tried returning this information as part of the return value,
1220 # but ran into a mess because of the many re-implementations of
1221 # gdb_load in config/*.exp.
1223 # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use
1224 # this if they can get more information set.
1226 proc gdb_file_cmd { arg } {
1230 global last_loaded_file
1232 set last_loaded_file $arg
1234 # Set whether debug info was found.
1235 # Default to "fail".
1236 global gdb_file_cmd_debug_info
1237 set gdb_file_cmd_debug_info "fail"
1239 if [is_remote host] {
1240 set arg [remote_download host $arg]
1242 perror "download failed"
1247 # The file command used to kill the remote target. For the benefit
1248 # of the testsuite, preserve this behavior.
1251 -re "Kill the program being debugged. .y or n. $" {
1253 verbose "\t\tKilling previous program being debugged"
1256 -re "$gdb_prompt $" {
1261 send_gdb "file $arg\n"
1263 -re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" {
1264 verbose "\t\tLoaded $arg into the $GDB with no debugging symbols"
1265 set gdb_file_cmd_debug_info "nodebug"
1268 -re "Reading symbols from.*done.*$gdb_prompt $" {
1269 verbose "\t\tLoaded $arg into the $GDB"
1270 set gdb_file_cmd_debug_info "debug"
1273 -re "Load new symbol table from \".*\".*y or n. $" {
1276 -re "Reading symbols from.*done.*$gdb_prompt $" {
1277 verbose "\t\tLoaded $arg with new symbol table into $GDB"
1278 set gdb_file_cmd_debug_info "debug"
1282 perror "(timeout) Couldn't load $arg, other program already loaded."
1287 -re "No such file or directory.*$gdb_prompt $" {
1288 perror "($arg) No such file or directory"
1291 -re "$gdb_prompt $" {
1292 perror "couldn't load $arg into $GDB."
1296 perror "couldn't load $arg into $GDB (timed out)."
1300 # This is an attempt to detect a core dump, but seems not to
1301 # work. Perhaps we need to match .* followed by eof, in which
1302 # gdb_expect does not seem to have a way to do that.
1303 perror "couldn't load $arg into $GDB (end of file)."
1310 # start gdb -- start gdb running, default procedure
1312 # When running over NFS, particularly if running many simultaneous
1313 # tests on different hosts all using the same server, things can
1314 # get really slow. Give gdb at least 3 minutes to start up.
1316 proc default_gdb_start { } {
1319 global INTERNAL_GDBFLAGS GDBFLAGS
1322 global gdb_spawn_id;
1324 gdb_stop_suppressing_tests;
1326 verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1328 if [info exists gdb_spawn_id] {
1332 if ![is_remote host] {
1333 if { [which $GDB] == 0 } then {
1334 perror "$GDB does not exist."
1338 set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"];
1339 if { $res < 0 || $res == "" } {
1340 perror "Spawning $GDB failed."
1344 -re "\[\r\n\]$gdb_prompt $" {
1345 verbose "GDB initialized."
1347 -re "$gdb_prompt $" {
1348 perror "GDB never initialized."
1352 perror "(timeout) GDB never initialized after 10 seconds."
1357 set gdb_spawn_id -1;
1358 # force the height to "unlimited", so no pagers get used
1360 send_gdb "set height 0\n"
1362 -re "$gdb_prompt $" {
1363 verbose "Setting height to 0." 2
1366 warning "Couldn't set the height to 0"
1369 # force the width to "unlimited", so no wraparound occurs
1370 send_gdb "set width 0\n"
1372 -re "$gdb_prompt $" {
1373 verbose "Setting width to 0." 2
1376 warning "Couldn't set the width to 0."
1382 # Examine the output of compilation to determine whether compilation
1383 # failed or not. If it failed determine whether it is due to missing
1384 # compiler or due to compiler error. Report pass, fail or unsupported
1387 proc gdb_compile_test {src output} {
1388 if { $output == "" } {
1389 pass "compilation [file tail $src]"
1390 } elseif { [regexp {^[a-zA-Z_0-9]+: Can't find [^ ]+\.$} $output] } {
1391 unsupported "compilation [file tail $src]"
1392 } elseif { [regexp {.*: command not found[\r|\n]*$} $output] } {
1393 unsupported "compilation [file tail $src]"
1394 } elseif { [regexp {.*: [^\r\n]*compiler not installed[^\r\n]*[\r|\n]*$} $output] } {
1395 unsupported "compilation [file tail $src]"
1397 verbose -log "compilation failed: $output" 2
1398 fail "compilation [file tail $src]"
1402 # Return a 1 for configurations for which we don't even want to try to
1405 proc skip_cplus_tests {} {
1406 if { [istarget "h8300-*-*"] } {
1410 # The C++ IO streams are too large for HC11/HC12 and are thus not
1411 # available. The gdb C++ tests use them and don't compile.
1412 if { [istarget "m6811-*-*"] } {
1415 if { [istarget "m6812-*-*"] } {
1421 # Return a 1 for configurations for which don't have both C++ and the STL.
1423 proc skip_stl_tests {} {
1424 # Symbian supports the C++ language, but the STL is missing
1425 # (both headers and libraries).
1426 if { [istarget "arm*-*-symbianelf*"] } {
1430 return [skip_cplus_tests]
1433 # Return a 1 if I don't even want to try to test FORTRAN.
1435 proc skip_fortran_tests {} {
1439 # Return a 1 if I don't even want to try to test ada.
1441 proc skip_ada_tests {} {
1445 # Return a 1 if I don't even want to try to test java.
1447 proc skip_java_tests {} {
1451 # Return a 1 for configurations that do not support Python scripting.
1453 proc skip_python_tests {} {
1455 gdb_test_multiple "python print 'test'" "verify python support" {
1456 -re "not supported.*$gdb_prompt $" {
1457 unsupported "Python support is disabled."
1460 -re "$gdb_prompt $" {}
1466 # Return a 1 if we should skip shared library tests.
1468 proc skip_shlib_tests {} {
1469 # Run the shared library tests on native systems.
1474 # An abbreviated list of remote targets where we should be able to
1475 # run shared library tests.
1476 if {([istarget *-*-linux*]
1477 || [istarget *-*-*bsd*]
1478 || [istarget *-*-solaris2*]
1479 || [istarget arm*-*-symbianelf*]
1480 || [istarget *-*-mingw*]
1481 || [istarget *-*-cygwin*]
1482 || [istarget *-*-pe*])} {
1489 # Return 1 if _Complex types are supported, otherwise, return 0.
1491 proc support_complex_tests {} {
1492 global support_complex_tests_saved
1494 # Use the cached value, if it exists.
1495 if [info exists support_complex_tests_saved] {
1496 verbose "returning saved $support_complex_tests_saved" 2
1497 return $support_complex_tests_saved
1500 # Set up, compile, and execute a test program containing _Complex types.
1501 # Include the current process ID in the file names to prevent conflicts
1502 # with invocations for multiple testsuites.
1503 set src complex[pid].c
1504 set exe complex[pid].x
1506 set f [open $src "w"]
1507 puts $f "int main() {"
1508 puts $f "_Complex float cf;"
1509 puts $f "_Complex double cd;"
1510 puts $f "_Complex long double cld;"
1511 puts $f " return 0; }"
1514 verbose "compiling testfile $src" 2
1515 set compile_flags {debug nowarnings quiet}
1516 set lines [gdb_compile $src $exe executable $compile_flags]
1520 if ![string match "" $lines] then {
1521 verbose "testfile compilation failed, returning 0" 2
1522 set support_complex_tests_saved 0
1524 set support_complex_tests_saved 1
1527 return $support_complex_tests_saved
1530 # Return 1 if target hardware or OS supports single stepping to signal
1531 # handler, otherwise, return 0.
1533 proc can_single_step_to_signal_handler {} {
1535 # Targets don't have hardware single step. On these targets, when
1536 # a signal is delivered during software single step, gdb is unable
1537 # to determine the next instruction addresses, because start of signal
1538 # handler is one of them.
1539 if { [istarget "arm*-*-*"] || [istarget "mips*-*-*"] } {
1546 # Return 1 if target is ILP32.
1547 # This cannot be decided simply from looking at the target string,
1548 # as it might depend on externally passed compiler options like -m64.
1549 proc is_ilp32_target {} {
1550 global is_ilp32_target_saved
1552 # Use the cached value, if it exists. Cache value per "board" to handle
1553 # runs with multiple options (e.g. unix/{-m32,-64}) correctly.
1554 set me "is_ilp32_target"
1555 set board [target_info name]
1556 if [info exists is_ilp32_target_saved($board)] {
1557 verbose "$me: returning saved $is_ilp32_target_saved($board)" 2
1558 return $is_ilp32_target_saved($board)
1562 set src ilp32[pid].c
1563 set obj ilp32[pid].o
1565 set f [open $src "w"]
1566 puts $f "int dummy\[sizeof (int) == 4"
1567 puts $f " && sizeof (void *) == 4"
1568 puts $f " && sizeof (long) == 4 ? 1 : -1\];"
1571 verbose "$me: compiling testfile $src" 2
1572 set lines [gdb_compile $src $obj object {quiet}]
1576 if ![string match "" $lines] then {
1577 verbose "$me: testfile compilation failed, returning 0" 2
1578 return [set is_ilp32_target_saved($board) 0]
1581 verbose "$me: returning 1" 2
1582 return [set is_ilp32_target_saved($board) 1]
1585 # Return 1 if target is LP64.
1586 # This cannot be decided simply from looking at the target string,
1587 # as it might depend on externally passed compiler options like -m64.
1588 proc is_lp64_target {} {
1589 global is_lp64_target_saved
1591 # Use the cached value, if it exists. Cache value per "board" to handle
1592 # runs with multiple options (e.g. unix/{-m32,-64}) correctly.
1593 set me "is_lp64_target"
1594 set board [target_info name]
1595 if [info exists is_lp64_target_saved($board)] {
1596 verbose "$me: returning saved $is_lp64_target_saved($board)" 2
1597 return $is_lp64_target_saved($board)
1603 set f [open $src "w"]
1604 puts $f "int dummy\[sizeof (int) == 4"
1605 puts $f " && sizeof (void *) == 8"
1606 puts $f " && sizeof (long) == 8 ? 1 : -1\];"
1609 verbose "$me: compiling testfile $src" 2
1610 set lines [gdb_compile $src $obj object {quiet}]
1614 if ![string match "" $lines] then {
1615 verbose "$me: testfile compilation failed, returning 0" 2
1616 return [set is_lp64_target_saved($board) 0]
1619 verbose "$me: returning 1" 2
1620 return [set is_lp64_target_saved($board) 1]
1623 # Return 1 if target has x86_64 registers - either amd64 or x32.
1624 # x32 target identifies as x86_64-*-linux*, therefore it cannot be determined
1625 # just from the target string.
1626 proc is_amd64_regs_target {} {
1627 global is_amd64_regs_target_saved
1629 if {![istarget "x86_64-*-*"] && ![istarget "i?86-*"]} {
1633 # Use the cached value, if it exists. Cache value per "board" to handle
1634 # runs with multiple options (e.g. unix/{-m32,-64}) correctly.
1635 set me "is_amd64_regs_target"
1636 set board [target_info name]
1637 if [info exists is_amd64_regs_target_saved($board)] {
1638 verbose "$me: returning saved $is_amd64_regs_target_saved($board)" 2
1639 return $is_amd64_regs_target_saved($board)
1642 set src reg64[pid].s
1643 set obj reg64[pid].o
1645 set f [open $src "w"]
1647 {rax rbx rcx rdx rsi rdi rbp rsp r8 r9 r10 r11 r12 r13 r14 r15} {
1648 puts $f "\tincq %$reg"
1652 verbose "$me: compiling testfile $src" 2
1653 set lines [gdb_compile $src $obj object {quiet}]
1657 if ![string match "" $lines] then {
1658 verbose "$me: testfile compilation failed, returning 0" 2
1659 return [set is_amd64_regs_target_saved($board) 0]
1662 verbose "$me: returning 1" 2
1663 return [set is_amd64_regs_target_saved($board) 1]
1666 # Return 1 if this target is an x86 or x86-64 with -m32.
1667 proc is_x86_like_target {} {
1668 if {![istarget "x86_64-*-*"] && ![istarget i?86-*]} {
1671 return [expr [is_ilp32_target] && ![is_amd64_regs_target]]
1674 # Return 1 if displaced stepping is supported on target, otherwise, return 0.
1675 proc support_displaced_stepping {} {
1677 if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"]
1678 || [istarget "arm*-*-linux*"] || [istarget "powerpc-*-linux*"]
1679 || [istarget "powerpc64-*-linux*"] || [istarget "s390*-*-*"] } {
1686 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
1687 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
1689 proc skip_altivec_tests {} {
1690 global skip_vmx_tests_saved
1691 global srcdir subdir gdb_prompt inferior_exited_re
1693 # Use the cached value, if it exists.
1694 set me "skip_altivec_tests"
1695 if [info exists skip_vmx_tests_saved] {
1696 verbose "$me: returning saved $skip_vmx_tests_saved" 2
1697 return $skip_vmx_tests_saved
1700 # Some simulators are known to not support VMX instructions.
1701 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1702 verbose "$me: target known to not support VMX, returning 1" 2
1703 return [set skip_vmx_tests_saved 1]
1706 # Make sure we have a compiler that understands altivec.
1707 set compile_flags {debug nowarnings}
1708 if [get_compiler_info not-used] {
1709 warning "Could not get compiler info"
1712 if [test_compiler_info gcc*] {
1713 set compile_flags "$compile_flags additional_flags=-maltivec"
1714 } elseif [test_compiler_info xlc*] {
1715 set compile_flags "$compile_flags additional_flags=-qaltivec"
1717 verbose "Could not compile with altivec support, returning 1" 2
1721 # Set up, compile, and execute a test program containing VMX instructions.
1722 # Include the current process ID in the file names to prevent conflicts
1723 # with invocations for multiple testsuites.
1727 set f [open $src "w"]
1728 puts $f "int main() {"
1729 puts $f "#ifdef __MACH__"
1730 puts $f " asm volatile (\"vor v0,v0,v0\");"
1732 puts $f " asm volatile (\"vor 0,0,0\");"
1734 puts $f " return 0; }"
1737 verbose "$me: compiling testfile $src" 2
1738 set lines [gdb_compile $src $exe executable $compile_flags]
1741 if ![string match "" $lines] then {
1742 verbose "$me: testfile compilation failed, returning 1" 2
1743 return [set skip_vmx_tests_saved 1]
1746 # No error message, compilation succeeded so now run it via gdb.
1750 gdb_reinitialize_dir $srcdir/$subdir
1754 -re ".*Illegal instruction.*${gdb_prompt} $" {
1755 verbose -log "\n$me altivec hardware not detected"
1756 set skip_vmx_tests_saved 1
1758 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
1759 verbose -log "\n$me: altivec hardware detected"
1760 set skip_vmx_tests_saved 0
1763 warning "\n$me: default case taken"
1764 set skip_vmx_tests_saved 1
1768 remote_file build delete $exe
1770 verbose "$me: returning $skip_vmx_tests_saved" 2
1771 return $skip_vmx_tests_saved
1774 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
1775 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
1777 proc skip_vsx_tests {} {
1778 global skip_vsx_tests_saved
1779 global srcdir subdir gdb_prompt inferior_exited_re
1781 # Use the cached value, if it exists.
1782 set me "skip_vsx_tests"
1783 if [info exists skip_vsx_tests_saved] {
1784 verbose "$me: returning saved $skip_vsx_tests_saved" 2
1785 return $skip_vsx_tests_saved
1788 # Some simulators are known to not support Altivec instructions, so
1789 # they won't support VSX instructions as well.
1790 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1791 verbose "$me: target known to not support VSX, returning 1" 2
1792 return [set skip_vsx_tests_saved 1]
1795 # Make sure we have a compiler that understands altivec.
1796 set compile_flags {debug nowarnings quiet}
1797 if [get_compiler_info not-used] {
1798 warning "Could not get compiler info"
1801 if [test_compiler_info gcc*] {
1802 set compile_flags "$compile_flags additional_flags=-mvsx"
1803 } elseif [test_compiler_info xlc*] {
1804 set compile_flags "$compile_flags additional_flags=-qasm=gcc"
1806 verbose "Could not compile with vsx support, returning 1" 2
1813 set f [open $src "w"]
1814 puts $f "int main() {"
1815 puts $f " double a\[2\] = { 1.0, 2.0 };"
1816 puts $f "#ifdef __MACH__"
1817 puts $f " asm volatile (\"lxvd2x v0,v0,%\[addr\]\" : : \[addr\] \"r\" (a));"
1819 puts $f " asm volatile (\"lxvd2x 0,0,%\[addr\]\" : : \[addr\] \"r\" (a));"
1821 puts $f " return 0; }"
1824 verbose "$me: compiling testfile $src" 2
1825 set lines [gdb_compile $src $exe executable $compile_flags]
1828 if ![string match "" $lines] then {
1829 verbose "$me: testfile compilation failed, returning 1" 2
1830 return [set skip_vsx_tests_saved 1]
1833 # No error message, compilation succeeded so now run it via gdb.
1837 gdb_reinitialize_dir $srcdir/$subdir
1841 -re ".*Illegal instruction.*${gdb_prompt} $" {
1842 verbose -log "\n$me VSX hardware not detected"
1843 set skip_vsx_tests_saved 1
1845 -re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
1846 verbose -log "\n$me: VSX hardware detected"
1847 set skip_vsx_tests_saved 0
1850 warning "\n$me: default case taken"
1851 set skip_vsx_tests_saved 1
1855 remote_file build delete $exe
1857 verbose "$me: returning $skip_vsx_tests_saved" 2
1858 return $skip_vsx_tests_saved
1861 # Skip all the tests in the file if you are not on an hppa running
1864 proc skip_hp_tests {} {
1865 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
1866 verbose "Skip hp tests is $skip_hp"
1870 # Return whether we should skip tests for showing inlined functions in
1871 # backtraces. Requires get_compiler_info and get_debug_format.
1873 proc skip_inline_frame_tests {} {
1874 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
1875 if { ! [test_debug_format "DWARF 2"] } {
1879 # GCC before 4.1 does not emit DW_AT_call_file / DW_AT_call_line.
1880 if { ([test_compiler_info "gcc-2-*"]
1881 || [test_compiler_info "gcc-3-*"]
1882 || [test_compiler_info "gcc-4-0-*"]) } {
1889 # Return whether we should skip tests for showing variables from
1890 # inlined functions. Requires get_compiler_info and get_debug_format.
1892 proc skip_inline_var_tests {} {
1893 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
1894 if { ! [test_debug_format "DWARF 2"] } {
1901 # Return a 1 if we should skip tests that require hardware breakpoints
1903 proc skip_hw_breakpoint_tests {} {
1904 # Skip tests if requested by the board (note that no_hardware_watchpoints
1905 # disables both watchpoints and breakpoints)
1906 if { [target_info exists gdb,no_hardware_watchpoints]} {
1910 # These targets support hardware breakpoints natively
1911 if { [istarget "i?86-*-*"]
1912 || [istarget "x86_64-*-*"]
1913 || [istarget "ia64-*-*"]
1914 || [istarget "arm*-*-*"]} {
1921 # Return a 1 if we should skip tests that require hardware watchpoints
1923 proc skip_hw_watchpoint_tests {} {
1924 # Skip tests if requested by the board
1925 if { [target_info exists gdb,no_hardware_watchpoints]} {
1929 # These targets support hardware watchpoints natively
1930 if { [istarget "i?86-*-*"]
1931 || [istarget "x86_64-*-*"]
1932 || [istarget "ia64-*-*"]
1933 || [istarget "arm*-*-*"]
1934 || [istarget "powerpc*-*-linux*"]
1935 || [istarget "s390*-*-*"] } {
1942 # Return a 1 if we should skip tests that require *multiple* hardware
1943 # watchpoints to be active at the same time
1945 proc skip_hw_watchpoint_multi_tests {} {
1946 if { [skip_hw_watchpoint_tests] } {
1950 # These targets support just a single hardware watchpoint
1951 if { [istarget "arm*-*-*"]
1952 || [istarget "powerpc*-*-linux*"] } {
1959 # Return a 1 if we should skip tests that require read/access watchpoints
1961 proc skip_hw_watchpoint_access_tests {} {
1962 if { [skip_hw_watchpoint_tests] } {
1966 # These targets support just write watchpoints
1967 if { [istarget "s390*-*-*"] } {
1974 set compiler_info "unknown"
1976 set hp_cc_compiler 0
1977 set hp_aCC_compiler 0
1979 # Figure out what compiler I am using.
1981 # BINFILE is a "compiler information" output file. This implementation
1982 # does not use BINFILE.
1984 # ARGS can be empty or "C++". If empty, "C" is assumed.
1986 # There are several ways to do this, with various problems.
1988 # [ gdb_compile -E $ifile -o $binfile.ci ]
1989 # source $binfile.ci
1991 # Single Unix Spec v3 says that "-E -o ..." together are not
1992 # specified. And in fact, the native compiler on hp-ux 11 (among
1993 # others) does not work with "-E -o ...". Most targets used to do
1994 # this, and it mostly worked, because it works with gcc.
1996 # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ]
1997 # source $binfile.ci
1999 # This avoids the problem with -E and -o together. This almost works
2000 # if the build machine is the same as the host machine, which is
2001 # usually true of the targets which are not gcc. But this code does
2002 # not figure which compiler to call, and it always ends up using the C
2003 # compiler. Not good for setting hp_aCC_compiler. Targets
2004 # hppa*-*-hpux* and mips*-*-irix* used to do this.
2006 # [ gdb_compile -E $ifile > $binfile.ci ]
2007 # source $binfile.ci
2009 # dejagnu target_compile says that it supports output redirection,
2010 # but the code is completely different from the normal path and I
2011 # don't want to sweep the mines from that path. So I didn't even try
2014 # set cppout [ gdb_compile $ifile "" preprocess $args quiet ]
2017 # I actually do this for all targets now. gdb_compile runs the right
2018 # compiler, and TCL captures the output, and I eval the output.
2020 # Unfortunately, expect logs the output of the command as it goes by,
2021 # and dejagnu helpfully prints a second copy of it right afterwards.
2022 # So I turn off expect logging for a moment.
2024 # [ gdb_compile $ifile $ciexe_file executable $args ]
2025 # [ remote_exec $ciexe_file ]
2026 # [ source $ci_file.out ]
2028 # I could give up on -E and just do this.
2029 # I didn't get desperate enough to try this.
2031 # -- chastain 2004-01-06
2033 proc get_compiler_info {binfile args} {
2034 # For compiler.c and compiler.cc
2037 # I am going to play with the log to keep noise out.
2041 # These come from compiler.c or compiler.cc
2042 global compiler_info
2044 # Legacy global data symbols.
2046 global hp_cc_compiler
2047 global hp_aCC_compiler
2049 # Choose which file to preprocess.
2050 set ifile "${srcdir}/lib/compiler.c"
2051 if { [llength $args] > 0 && [lindex $args 0] == "c++" } {
2052 set ifile "${srcdir}/lib/compiler.cc"
2055 # Run $ifile through the right preprocessor.
2056 # Toggle gdb.log to keep the compiler output out of the log.
2058 if [is_remote host] {
2059 # We have to use -E and -o together, despite the comments
2060 # above, because of how DejaGnu handles remote host testing.
2061 set ppout "$outdir/compiler.i"
2062 gdb_compile "${ifile}" "$ppout" preprocess [list "$args" quiet]
2063 set file [open $ppout r]
2064 set cppout [read $file]
2067 set cppout [ gdb_compile "${ifile}" "" preprocess [list "$args" quiet] ]
2069 log_file -a "$outdir/$tool.log"
2073 foreach cppline [ split "$cppout" "\n" ] {
2074 if { [ regexp "^#" "$cppline" ] } {
2076 } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } {
2078 } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } {
2080 verbose "get_compiler_info: $cppline" 2
2084 verbose -log "get_compiler_info: $cppline"
2089 # Reset to unknown compiler if any diagnostics happened.
2091 set compiler_info "unknown"
2094 # Set the legacy symbols.
2096 set hp_cc_compiler 0
2097 set hp_aCC_compiler 0
2098 if { [regexp "^gcc-1-" "$compiler_info" ] } { set gcc_compiled 1 }
2099 if { [regexp "^gcc-2-" "$compiler_info" ] } { set gcc_compiled 2 }
2100 if { [regexp "^gcc-3-" "$compiler_info" ] } { set gcc_compiled 3 }
2101 if { [regexp "^gcc-4-" "$compiler_info" ] } { set gcc_compiled 4 }
2102 if { [regexp "^gcc-5-" "$compiler_info" ] } { set gcc_compiled 5 }
2103 if { [regexp "^hpcc-" "$compiler_info" ] } { set hp_cc_compiler 1 }
2104 if { [regexp "^hpacc-" "$compiler_info" ] } { set hp_aCC_compiler 1 }
2106 # Log what happened.
2107 verbose -log "get_compiler_info: $compiler_info"
2109 # Most compilers will evaluate comparisons and other boolean
2110 # operations to 0 or 1.
2111 uplevel \#0 { set true 1 }
2112 uplevel \#0 { set false 0 }
2114 # Use of aCC results in boolean results being displayed as
2116 if { $hp_aCC_compiler } {
2117 uplevel \#0 { set true true }
2118 uplevel \#0 { set false false }
2124 proc test_compiler_info { {compiler ""} } {
2125 global compiler_info
2127 # if no arg, return the compiler_info string
2129 if [string match "" $compiler] {
2130 if [info exists compiler_info] {
2131 return $compiler_info
2133 perror "No compiler info found."
2137 return [string match $compiler $compiler_info]
2140 proc current_target_name { } {
2142 if [info exists target_info(target,name)] {
2143 set answer $target_info(target,name)
2150 set gdb_wrapper_initialized 0
2151 set gdb_wrapper_target ""
2153 proc gdb_wrapper_init { args } {
2154 global gdb_wrapper_initialized;
2155 global gdb_wrapper_file;
2156 global gdb_wrapper_flags;
2157 global gdb_wrapper_target
2159 if { $gdb_wrapper_initialized == 1 } { return; }
2161 if {[target_info exists needs_status_wrapper] && \
2162 [target_info needs_status_wrapper] != "0"} {
2163 set result [build_wrapper "testglue.o"];
2164 if { $result != "" } {
2165 set gdb_wrapper_file [lindex $result 0];
2166 set gdb_wrapper_flags [lindex $result 1];
2168 warning "Status wrapper failed to build."
2171 set gdb_wrapper_initialized 1
2172 set gdb_wrapper_target [current_target_name]
2175 # Some targets need to always link a special object in. Save its path here.
2176 global gdb_saved_set_unbuffered_mode_obj
2177 set gdb_saved_set_unbuffered_mode_obj ""
2179 proc gdb_compile {source dest type options} {
2180 global GDB_TESTCASE_OPTIONS;
2181 global gdb_wrapper_file;
2182 global gdb_wrapper_flags;
2183 global gdb_wrapper_initialized;
2186 global gdb_saved_set_unbuffered_mode_obj
2188 set outdir [file dirname $dest]
2190 # Add platform-specific options if a shared library was specified using
2191 # "shlib=librarypath" in OPTIONS.
2195 foreach opt $options {
2196 if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] {
2197 if [test_compiler_info "xlc-*"] {
2198 # IBM xlc compiler doesn't accept shared library named other
2199 # than .so: use "-Wl," to bypass this
2200 lappend source "-Wl,$shlib_name"
2201 } elseif { ([istarget "*-*-mingw*"]
2202 || [istarget *-*-cygwin*]
2203 || [istarget *-*-pe*])} {
2204 lappend source "${shlib_name}.a"
2206 lappend source $shlib_name
2208 if { $shlib_found == 0 } {
2210 if { ([istarget "*-*-mingw*"]
2211 || [istarget *-*-cygwin*]) } {
2212 lappend new_options "additional_flags=-Wl,--enable-auto-import"
2215 } elseif { $opt == "shlib_load" } {
2218 lappend new_options $opt
2222 # We typically link to shared libraries using an absolute path, and
2223 # that's how they are found at runtime. If we are going to
2224 # dynamically load one by basename, we must specify rpath. If we
2225 # are using a remote host, DejaGNU will link to the shared library
2226 # using a relative path, so again we must specify an rpath.
2227 if { $shlib_load || ($shlib_found && [is_remote target]) } {
2228 if { ([istarget "*-*-mingw*"]
2229 || [istarget *-*-cygwin*]
2230 || [istarget *-*-pe*]
2231 || [istarget hppa*-*-hpux*])} {
2232 # Do not need anything.
2233 } elseif { [istarget *-*-freebsd*] || [istarget *-*-openbsd*] } {
2234 lappend new_options "ldflags=-Wl,-rpath,${outdir}"
2235 } elseif { [istarget arm*-*-symbianelf*] } {
2236 if { $shlib_load } {
2237 lappend new_options "libs=-ldl"
2240 if { $shlib_load } {
2241 lappend new_options "libs=-ldl"
2243 lappend new_options "ldflags=-Wl,-rpath,\\\$ORIGIN"
2246 set options $new_options
2248 if [target_info exists gdb_stub] {
2249 set options2 { "additional_flags=-Dusestubs" }
2250 lappend options "libs=[target_info gdb_stub]";
2251 set options [concat $options2 $options]
2253 if [target_info exists is_vxworks] {
2254 set options2 { "additional_flags=-Dvxworks" }
2255 lappend options "libs=[target_info gdb_stub]";
2256 set options [concat $options2 $options]
2258 if [info exists GDB_TESTCASE_OPTIONS] {
2259 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
2261 verbose "options are $options"
2262 verbose "source is $source $dest $type $options"
2264 if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init }
2266 if {[target_info exists needs_status_wrapper] && \
2267 [target_info needs_status_wrapper] != "0" && \
2268 [info exists gdb_wrapper_file]} {
2269 lappend options "libs=${gdb_wrapper_file}"
2270 lappend options "ldflags=${gdb_wrapper_flags}"
2273 # Replace the "nowarnings" option with the appropriate additional_flags
2274 # to disable compiler warnings.
2275 set nowarnings [lsearch -exact $options nowarnings]
2276 if {$nowarnings != -1} {
2277 if [target_info exists gdb,nowarnings_flag] {
2278 set flag "additional_flags=[target_info gdb,nowarnings_flag]"
2280 set flag "additional_flags=-w"
2282 set options [lreplace $options $nowarnings $nowarnings $flag]
2285 if { $type == "executable" } {
2286 if { ([istarget "*-*-mingw*"]
2287 || [istarget "*-*-*djgpp"]
2288 || [istarget "*-*-cygwin*"])} {
2289 # Force output to unbuffered mode, by linking in an object file
2290 # with a global contructor that calls setvbuf.
2292 # Compile the special object seperatelly for two reasons:
2293 # 1) Insulate it from $options.
2294 # 2) Avoid compiling it for every gdb_compile invocation,
2295 # which is time consuming, especially if we're remote
2298 if { $gdb_saved_set_unbuffered_mode_obj == "" } {
2299 verbose "compiling gdb_saved_set_unbuffered_obj"
2300 set unbuf_src ${srcdir}/lib/set_unbuffered_mode.c
2301 set unbuf_obj ${objdir}/set_unbuffered_mode.o
2303 set result [gdb_compile "${unbuf_src}" "${unbuf_obj}" object {nowarnings}]
2304 if { $result != "" } {
2308 set gdb_saved_set_unbuffered_mode_obj ${objdir}/set_unbuffered_mode_saved.o
2309 # Link a copy of the output object, because the
2310 # original may be automatically deleted.
2311 remote_exec host "cp -f $unbuf_obj $gdb_saved_set_unbuffered_mode_obj"
2313 verbose "gdb_saved_set_unbuffered_obj already compiled"
2316 # Rely on the internal knowledge that the global ctors are ran in
2317 # reverse link order. In that case, we can use ldflags to
2318 # avoid copying the object file to the host multiple
2320 # This object can only be added if standard libraries are
2321 # used. Thus, we need to disable it if -nostdlib option is used
2322 if {[lsearch -regexp $options "-nostdlib"] < 0 } {
2323 lappend options "ldflags=$gdb_saved_set_unbuffered_mode_obj"
2328 set result [target_compile $source $dest $type $options];
2330 # Prune uninteresting compiler (and linker) output.
2331 regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result
2333 regsub "\[\r\n\]*$" "$result" "" result;
2334 regsub "^\[\r\n\]*" "$result" "" result;
2336 if {[lsearch $options quiet] < 0} {
2337 # We shall update this on a per language basis, to avoid
2338 # changing the entire testsuite in one go.
2339 if {[lsearch $options f77] >= 0} {
2340 gdb_compile_test $source $result
2341 } elseif { $result != "" } {
2342 clone_output "gdb compile failed, $result"
2349 # This is just like gdb_compile, above, except that it tries compiling
2350 # against several different thread libraries, to see which one this
2352 proc gdb_compile_pthreads {source dest type options} {
2354 set why_msg "unrecognized error"
2355 foreach lib {-lpthreads -lpthread -lthread ""} {
2356 # This kind of wipes out whatever libs the caller may have
2357 # set. Or maybe theirs will override ours. How infelicitous.
2358 set options_with_lib [concat $options [list libs=$lib quiet]]
2359 set ccout [gdb_compile $source $dest $type $options_with_lib]
2360 switch -regexp -- $ccout {
2361 ".*no posix threads support.*" {
2362 set why_msg "missing threads include file"
2365 ".*cannot open -lpthread.*" {
2366 set why_msg "missing runtime threads library"
2368 ".*Can't find library for -lpthread.*" {
2369 set why_msg "missing runtime threads library"
2372 pass "successfully compiled posix threads test case"
2378 if {!$built_binfile} {
2379 unsupported "Couldn't compile $source: ${why_msg}"
2384 # Build a shared library from SOURCES. You must use get_compiler_info
2387 proc gdb_compile_shlib {sources dest options} {
2388 set obj_options $options
2390 switch -glob [test_compiler_info] {
2392 lappend obj_options "additional_flags=-qpic"
2395 if { !([istarget "powerpc*-*-aix*"]
2396 || [istarget "rs6000*-*-aix*"]
2397 || [istarget "*-*-cygwin*"]
2398 || [istarget "*-*-mingw*"]
2399 || [istarget "*-*-pe*"]) } {
2400 lappend obj_options "additional_flags=-fpic"
2404 switch -glob [istarget] {
2406 lappend obj_options "additional_flags=+z"
2409 # Disable SGI compiler's implicit -Dsgi
2410 lappend obj_options "additional_flags=-Usgi"
2413 # don't know what the compiler is...
2419 set outdir [file dirname $dest]
2421 foreach source $sources {
2422 set sourcebase [file tail $source]
2423 if {[gdb_compile $source "${outdir}/${sourcebase}.o" object $obj_options] != ""} {
2426 lappend objects ${outdir}/${sourcebase}.o
2429 if [istarget "hppa*-*-hpux*"] {
2430 remote_exec build "ld -b ${objects} -o ${dest}"
2432 set link_options $options
2433 if [test_compiler_info "xlc-*"] {
2434 lappend link_options "additional_flags=-qmkshrobj"
2436 lappend link_options "additional_flags=-shared"
2438 if { ([istarget "*-*-mingw*"]
2439 || [istarget *-*-cygwin*]
2440 || [istarget *-*-pe*])} {
2441 lappend link_options "additional_flags=-Wl,--out-implib,${dest}.a"
2442 } elseif [is_remote target] {
2443 # By default, we do not set the soname. This causes the linker
2444 # on ELF systems to create a DT_NEEDED entry in the executable
2445 # refering to the full path name of the library. This is a
2446 # problem in remote testing if the library is in a different
2447 # directory there. To fix this, we set a soname of just the
2448 # base filename for the library, and add an appropriate -rpath
2449 # to the main executable (in gdb_compile).
2450 set destbase [file tail $dest]
2451 lappend link_options "additional_flags=-Wl,-soname,$destbase"
2454 if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
2460 # This is just like gdb_compile_shlib, above, except that it tries compiling
2461 # against several different thread libraries, to see which one this
2463 proc gdb_compile_shlib_pthreads {sources dest options} {
2465 set why_msg "unrecognized error"
2466 foreach lib {-lpthreads -lpthread -lthread ""} {
2467 # This kind of wipes out whatever libs the caller may have
2468 # set. Or maybe theirs will override ours. How infelicitous.
2469 set options_with_lib [concat $options [list libs=$lib quiet]]
2470 set ccout [gdb_compile_shlib $sources $dest $options_with_lib]
2471 switch -regexp -- $ccout {
2472 ".*no posix threads support.*" {
2473 set why_msg "missing threads include file"
2476 ".*cannot open -lpthread.*" {
2477 set why_msg "missing runtime threads library"
2479 ".*Can't find library for -lpthread.*" {
2480 set why_msg "missing runtime threads library"
2483 pass "successfully compiled posix threads test case"
2489 if {!$built_binfile} {
2490 unsupported "Couldn't compile $sources: ${why_msg}"
2495 # This is just like gdb_compile_pthreads, above, except that we always add the
2496 # objc library for compiling Objective-C programs
2497 proc gdb_compile_objc {source dest type options} {
2499 set why_msg "unrecognized error"
2500 foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} {
2501 # This kind of wipes out whatever libs the caller may have
2502 # set. Or maybe theirs will override ours. How infelicitous.
2503 if { $lib == "solaris" } {
2504 set lib "-lpthread -lposix4"
2506 if { $lib != "-lobjc" } {
2507 set lib "-lobjc $lib"
2509 set options_with_lib [concat $options [list libs=$lib quiet]]
2510 set ccout [gdb_compile $source $dest $type $options_with_lib]
2511 switch -regexp -- $ccout {
2512 ".*no posix threads support.*" {
2513 set why_msg "missing threads include file"
2516 ".*cannot open -lpthread.*" {
2517 set why_msg "missing runtime threads library"
2519 ".*Can't find library for -lpthread.*" {
2520 set why_msg "missing runtime threads library"
2523 pass "successfully compiled objc with posix threads test case"
2529 if {!$built_binfile} {
2530 unsupported "Couldn't compile $source: ${why_msg}"
2535 proc send_gdb { string } {
2536 global suppress_flag;
2537 if { $suppress_flag } {
2538 return "suppressed";
2540 return [remote_send host "$string"];
2546 proc gdb_expect { args } {
2547 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
2548 set atimeout [lindex $args 0];
2549 set expcode [list [lindex $args 1]];
2554 upvar timeout timeout;
2556 if [target_info exists gdb,timeout] {
2557 if [info exists timeout] {
2558 if { $timeout < [target_info gdb,timeout] } {
2559 set gtimeout [target_info gdb,timeout];
2561 set gtimeout $timeout;
2564 set gtimeout [target_info gdb,timeout];
2568 if ![info exists gtimeout] {
2570 if [info exists timeout] {
2571 set gtimeout $timeout;
2575 if [info exists atimeout] {
2576 if { ![info exists gtimeout] || $gtimeout < $atimeout } {
2577 set gtimeout $atimeout;
2580 if ![info exists gtimeout] {
2586 global suppress_flag;
2587 global remote_suppress_flag;
2588 if [info exists remote_suppress_flag] {
2589 set old_val $remote_suppress_flag;
2591 if [info exists suppress_flag] {
2592 if { $suppress_flag } {
2593 set remote_suppress_flag 1;
2597 {uplevel remote_expect host $gtimeout $expcode} string];
2598 if [info exists old_val] {
2599 set remote_suppress_flag $old_val;
2601 if [info exists remote_suppress_flag] {
2602 unset remote_suppress_flag;
2607 global errorInfo errorCode;
2609 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
2610 } elseif {$code == 2} {
2611 return -code return $string
2612 } elseif {$code == 3} {
2614 } elseif {$code > 4} {
2615 return -code $code $string
2619 # gdb_expect_list TEST SENTINEL LIST -- expect a sequence of outputs
2621 # Check for long sequence of output by parts.
2622 # TEST: is the test message to be printed with the test success/fail.
2623 # SENTINEL: Is the terminal pattern indicating that output has finished.
2624 # LIST: is the sequence of outputs to match.
2625 # If the sentinel is recognized early, it is considered an error.
2628 # 1 if the test failed,
2629 # 0 if the test passes,
2630 # -1 if there was an internal error.
2632 proc gdb_expect_list {test sentinel list} {
2634 global suppress_flag
2637 if { $suppress_flag } {
2639 unresolved "${test}"
2641 while { ${index} < [llength ${list}] } {
2642 set pattern [lindex ${list} ${index}]
2643 set index [expr ${index} + 1]
2644 verbose -log "gdb_expect_list pattern: /$pattern/" 2
2645 if { ${index} == [llength ${list}] } {
2648 -re "${pattern}${sentinel}" {
2649 # pass "${test}, pattern ${index} + sentinel"
2652 fail "${test} (pattern ${index} + sentinel)"
2655 -re ".*A problem internal to GDB has been detected" {
2656 fail "${test} (GDB internal error)"
2658 gdb_internal_error_resync
2661 fail "${test} (pattern ${index} + sentinel) (timeout)"
2666 # unresolved "${test}, pattern ${index} + sentinel"
2672 # pass "${test}, pattern ${index}"
2675 fail "${test} (pattern ${index})"
2678 -re ".*A problem internal to GDB has been detected" {
2679 fail "${test} (GDB internal error)"
2681 gdb_internal_error_resync
2684 fail "${test} (pattern ${index}) (timeout)"
2689 # unresolved "${test}, pattern ${index}"
2703 proc gdb_suppress_entire_file { reason } {
2704 global suppress_flag;
2706 warning "$reason\n";
2707 set suppress_flag -1;
2711 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
2712 # gdb_expect to fail immediately (until the next call to
2713 # gdb_stop_suppressing_tests).
2715 proc gdb_suppress_tests { args } {
2716 global suppress_flag;
2718 return; # fnf - disable pending review of results where
2719 # testsuite ran better without this
2722 if { $suppress_flag == 1 } {
2723 if { [llength $args] > 0 } {
2724 warning "[lindex $args 0]\n";
2726 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
2732 # Clear suppress_flag.
2734 proc gdb_stop_suppressing_tests { } {
2735 global suppress_flag;
2737 if [info exists suppress_flag] {
2738 if { $suppress_flag > 0 } {
2739 set suppress_flag 0;
2740 clone_output "Tests restarted.\n";
2743 set suppress_flag 0;
2747 proc gdb_clear_suppressed { } {
2748 global suppress_flag;
2750 set suppress_flag 0;
2753 proc gdb_start { } {
2758 catch default_gdb_exit
2762 # gdb_load_cmd -- load a file into the debugger.
2763 # ARGS - additional args to load command.
2764 # return a -1 if anything goes wrong.
2766 proc gdb_load_cmd { args } {
2769 if [target_info exists gdb_load_timeout] {
2770 set loadtimeout [target_info gdb_load_timeout]
2772 set loadtimeout 1600
2774 send_gdb "load $args\n"
2775 verbose "Timeout is now $loadtimeout seconds" 2
2776 gdb_expect $loadtimeout {
2777 -re "Loading section\[^\r\]*\r\n" {
2780 -re "Start address\[\r\]*\r\n" {
2783 -re "Transfer rate\[\r\]*\r\n" {
2786 -re "Memory access error\[^\r\]*\r\n" {
2787 perror "Failed to load program"
2790 -re "$gdb_prompt $" {
2793 -re "(.*)\r\n$gdb_prompt " {
2794 perror "Unexpected reponse from 'load' -- $expect_out(1,string)"
2798 perror "Timed out trying to load $args."
2805 # Return the filename to download to the target and load on the target
2806 # for this shared library. Normally just LIBNAME, unless shared libraries
2807 # for this target have separate link and load images.
2809 proc shlib_target_file { libname } {
2813 # Return the filename GDB will load symbols from when debugging this
2814 # shared library. Normally just LIBNAME, unless shared libraries for
2815 # this target have separate link and load images.
2817 proc shlib_symbol_file { libname } {
2821 # Return the filename to download to the target and load for this
2822 # executable. Normally just BINFILE unless it is renamed to something
2823 # else for this target.
2825 proc exec_target_file { binfile } {
2829 # Return the filename GDB will load symbols from when debugging this
2830 # executable. Normally just BINFILE unless executables for this target
2831 # have separate files for symbols.
2833 proc exec_symbol_file { binfile } {
2837 # Rename the executable file. Normally this is just BINFILE1 being renamed
2838 # to BINFILE2, but some targets require multiple binary files.
2839 proc gdb_rename_execfile { binfile1 binfile2 } {
2840 file rename -force [exec_target_file ${binfile1}] \
2841 [exec_target_file ${binfile2}]
2842 if { [exec_target_file ${binfile1}] != [exec_symbol_file ${binfile1}] } {
2843 file rename -force [exec_symbol_file ${binfile1}] \
2844 [exec_symbol_file ${binfile2}]
2848 # "Touch" the executable file to update the date. Normally this is just
2849 # BINFILE, but some targets require multiple files.
2850 proc gdb_touch_execfile { binfile } {
2851 set time [clock seconds]
2852 file mtime [exec_target_file ${binfile}] $time
2853 if { [exec_target_file ${binfile}] != [exec_symbol_file ${binfile}] } {
2854 file mtime [exec_symbol_file ${binfile}] $time
2860 # Copy a file to the remote target and return its target filename.
2861 # Schedule the file to be deleted at the end of this test.
2863 proc gdb_download { filename } {
2866 set destname [remote_download target $filename]
2867 lappend cleanfiles $destname
2871 # gdb_load_shlibs LIB...
2873 # Copy the listed libraries to the target.
2875 proc gdb_load_shlibs { args } {
2876 if {![is_remote target]} {
2880 foreach file $args {
2881 gdb_download [shlib_target_file $file]
2884 # Even if the target supplies full paths for shared libraries,
2885 # they may not be paths for this system.
2886 gdb_test "set solib-search-path [file dirname [lindex $args 0]]" "" ""
2890 # gdb_load -- load a file into the debugger.
2891 # Many files in config/*.exp override this procedure.
2893 proc gdb_load { arg } {
2894 return [gdb_file_cmd $arg]
2897 # gdb_reload -- load a file into the target. Called before "running",
2898 # either the first time or after already starting the program once,
2899 # for remote targets. Most files that override gdb_load should now
2900 # override this instead.
2902 proc gdb_reload { } {
2903 # For the benefit of existing configurations, default to gdb_load.
2904 # Specifying no file defaults to the executable currently being
2906 return [gdb_load ""]
2909 proc gdb_continue { function } {
2912 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
2915 proc default_gdb_init { args } {
2916 global gdb_wrapper_initialized
2917 global gdb_wrapper_target
2922 gdb_clear_suppressed;
2924 # Make sure that the wrapper is rebuilt
2925 # with the appropriate multilib option.
2926 if { $gdb_wrapper_target != [current_target_name] } {
2927 set gdb_wrapper_initialized 0
2930 # Unlike most tests, we have a small number of tests that generate
2931 # a very large amount of output. We therefore increase the expect
2932 # buffer size to be able to contain the entire test output.
2934 # Also set this value for the currently running GDB.
2935 match_max [match_max -d]
2937 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
2938 if { [llength $args] > 0 } {
2941 set file [lindex $args 0];
2943 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
2946 if [target_info exists gdb_prompt] {
2947 set gdb_prompt [target_info gdb_prompt];
2949 set gdb_prompt "\\(gdb\\)"
2953 # The default timeout used when testing GDB commands. We want to use
2954 # the same timeout as the default dejagnu timeout, unless the user has
2955 # already provided a specific value (probably through a site.exp file).
2956 global gdb_test_timeout
2957 if ![info exists gdb_test_timeout] {
2958 set gdb_test_timeout $timeout
2961 # A list of global variables that GDB testcases should not use.
2962 # We try to prevent their use by monitoring write accesses and raising
2963 # an error when that happens.
2964 set banned_variables { bug_id prms_id }
2966 # gdb_init is called by runtest at start, but also by several
2967 # tests directly; gdb_finish is only called from within runtest after
2968 # each test source execution.
2969 # Placing several traces by repetitive calls to gdb_init leads
2970 # to problems, as only one trace is removed in gdb_finish.
2971 # To overcome this possible problem, we add a variable that records
2972 # if the banned variables are traced.
2973 set banned_variables_traced 0
2975 proc gdb_init { args } {
2976 # Reset the timeout value to the default. This way, any testcase
2977 # that changes the timeout value without resetting it cannot affect
2978 # the timeout used in subsequent testcases.
2979 global gdb_test_timeout
2981 set timeout $gdb_test_timeout
2983 # Block writes to all banned variables...
2984 global banned_variables
2985 global banned_variables_traced
2986 if (!$banned_variables_traced) {
2987 foreach banned_var $banned_variables {
2988 global "$banned_var"
2989 trace add variable "$banned_var" write error
2991 set banned_variables_traced 1
2994 # We set LC_ALL, LC_CTYPE, and LANG to C so that we get the same
2995 # messages as expected.
3000 # Don't let a .inputrc file or an existing setting of INPUTRC mess up
3001 # the test results. Even if /dev/null doesn't exist on the particular
3002 # platform, the readline library will use the default setting just by
3003 # failing to open the file. OTOH, opening /dev/null successfully will
3004 # also result in the default settings being used since nothing will be
3005 # read from this file.
3006 setenv INPUTRC "/dev/null"
3008 # The gdb.base/readline.exp arrow key test relies on the standard VT100
3009 # bindings, so make sure that an appropriate terminal is selected.
3010 # The same bug doesn't show up if we use ^P / ^N instead.
3013 # Some tests (for example gdb.base/maint.exp) shell out from gdb to use
3014 # grep. Clear GREP_OPTIONS to make the behavoiur predictable,
3015 # especially having color output turned on can cause tests to fail.
3016 setenv GREP_OPTIONS ""
3018 # Clear $gdbserver_reconnect_p.
3019 global gdbserver_reconnect_p
3020 set gdbserver_reconnect_p 1
3021 unset gdbserver_reconnect_p
3023 return [eval default_gdb_init $args];
3026 proc gdb_finish { } {
3029 # Exit first, so that the files are no longer in use.
3032 if { [llength $cleanfiles] > 0 } {
3033 eval remote_file target delete $cleanfiles
3037 # Unblock write access to the banned variables. Dejagnu typically
3038 # resets some of them between testcases.
3039 global banned_variables
3040 global banned_variables_traced
3041 if ($banned_variables_traced) {
3042 foreach banned_var $banned_variables {
3043 global "$banned_var"
3044 trace remove variable "$banned_var" write error
3046 set banned_variables_traced 0
3051 set debug_format "unknown"
3053 # Run the gdb command "info source" and extract the debugging format
3054 # information from the output and save it in debug_format.
3056 proc get_debug_format { } {
3062 set debug_format "unknown"
3063 send_gdb "info source\n"
3065 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
3066 set debug_format $expect_out(1,string)
3067 verbose "debug format is $debug_format"
3070 -re "No current source file.\r\n$gdb_prompt $" {
3071 perror "get_debug_format used when no current source file"
3074 -re "$gdb_prompt $" {
3075 warning "couldn't check debug format (no valid response)."
3079 warning "couldn't check debug format (timed out)."
3085 # Return true if FORMAT matches the debug format the current test was
3086 # compiled with. FORMAT is a shell-style globbing pattern; it can use
3087 # `*', `[...]', and so on.
3089 # This function depends on variables set by `get_debug_format', above.
3091 proc test_debug_format {format} {
3094 return [expr [string match $format $debug_format] != 0]
3097 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
3098 # COFF, stabs, etc). If that format matches the format that the
3099 # current test was compiled with, then the next test is expected to
3100 # fail for any target. Returns 1 if the next test or set of tests is
3101 # expected to fail, 0 otherwise (or if it is unknown). Must have
3102 # previously called get_debug_format.
3103 proc setup_xfail_format { format } {
3104 set ret [test_debug_format $format];
3112 # Like setup_kfail, but only call setup_kfail conditionally if
3113 # istarget[TARGET] returns true.
3114 proc setup_kfail_for_target { PR target } {
3115 if { [istarget $target] } {
3116 setup_kfail $PR $target
3120 proc gdb_step_for_stub { } {
3123 if ![target_info exists gdb,use_breakpoint_for_stub] {
3124 if [target_info exists gdb_stub_step_command] {
3125 set command [target_info gdb_stub_step_command];
3129 send_gdb "${command}\n";
3132 -re "(main.* at |.*in .*start).*$gdb_prompt" {
3135 -re ".*$gdb_prompt" {
3137 if { $tries == 5 } {
3138 fail "stepping out of breakpoint function";
3141 send_gdb "${command}\n";
3145 fail "stepping out of breakpoint function";
3152 -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" {
3153 set file $expect_out(1,string);
3154 set linenum [expr $expect_out(2,string) + 1];
3155 set breakplace "${file}:${linenum}";
3159 send_gdb "break ${breakplace}\n";
3161 -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" {
3162 set breakpoint $expect_out(1,string);
3164 -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" {
3165 set breakpoint $expect_out(1,string);
3169 send_gdb "continue\n";
3171 -re "Breakpoint ${breakpoint},.*$gdb_prompt" {
3172 gdb_test "delete $breakpoint" ".*" "";
3179 # gdb_get_line_number TEXT [FILE]
3181 # Search the source file FILE, and return the line number of the
3182 # first line containing TEXT. If no match is found, return -1.
3184 # TEXT is a string literal, not a regular expression.
3186 # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is
3187 # specified, and does not start with "/", then it is assumed to be in
3188 # "$srcdir/$subdir". This is awkward, and can be fixed in the future,
3189 # by changing the callers and the interface at the same time.
3190 # In particular: gdb.base/break.exp, gdb.base/condbreak.exp,
3191 # gdb.base/ena-dis-br.exp.
3193 # Use this function to keep your test scripts independent of the
3194 # exact line numbering of the source file. Don't write:
3196 # send_gdb "break 20"
3198 # This means that if anyone ever edits your test's source file,
3199 # your test could break. Instead, put a comment like this on the
3200 # source file line you want to break at:
3202 # /* breakpoint spot: frotz.exp: test name */
3204 # and then write, in your test script (which we assume is named
3207 # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
3209 # (Yes, Tcl knows how to handle the nested quotes and brackets.
3212 # % puts "foo [lindex "bar baz" 1]"
3215 # Tcl is quite clever, for a little stringy language.)
3219 # The previous implementation of this procedure used the gdb search command.
3220 # This version is different:
3222 # . It works with MI, and it also works when gdb is not running.
3224 # . It operates on the build machine, not the host machine.
3226 # . For now, this implementation fakes a current directory of
3227 # $srcdir/$subdir to be compatible with the old implementation.
3228 # This will go away eventually and some callers will need to
3231 # . The TEXT argument is literal text and matches literally,
3232 # not a regular expression as it was before.
3234 # . State changes in gdb, such as changing the current file
3235 # and setting $_, no longer happen.
3237 # After a bit of time we can forget about the differences from the
3238 # old implementation.
3240 # --chastain 2004-08-05
3242 proc gdb_get_line_number { text { file "" } } {
3247 if { "$file" == "" } then {
3250 if { ! [regexp "^/" "$file"] } then {
3251 set file "$srcdir/$subdir/$file"
3254 if { [ catch { set fd [open "$file"] } message ] } then {
3260 for { set line 1 } { 1 } { incr line } {
3261 if { [ catch { set nchar [gets "$fd" body] } message ] } then {
3265 if { $nchar < 0 } then {
3268 if { [string first "$text" "$body"] >= 0 } then {
3274 if { [ catch { close "$fd" } message ] } then {
3282 # gdb_continue_to_end:
3283 # The case where the target uses stubs has to be handled specially. If a
3284 # stub is used, we set a breakpoint at exit because we cannot rely on
3285 # exit() behavior of a remote target.
3287 # MSSG is the error message that gets printed. If not given, a
3289 # COMMAND is the command to invoke. If not given, "continue" is
3291 # ALLOW_EXTRA is a flag indicating whether the test should expect
3292 # extra output between the "Continuing." line and the program
3293 # exiting. By default it is zero; if nonzero, any extra output
3296 proc gdb_continue_to_end {{mssg ""} {command continue} {allow_extra 0}} {
3297 global inferior_exited_re
3300 set text "continue until exit"
3302 set text "continue until exit at $mssg"
3309 if [target_info exists use_gdb_stub] {
3310 if {![gdb_breakpoint "exit"]} {
3313 gdb_test $command "Continuing..*Breakpoint .*exit.*" \
3316 # Continue until we exit. Should not stop again.
3317 # Don't bother to check the output of the program, that may be
3318 # extremely tough for some remote systems.
3320 "Continuing.\[\r\n0-9\]+${extra}(... EXIT code 0\[\r\n\]+|$inferior_exited_re normally).*"\
3325 proc rerun_to_main {} {
3328 if [target_info exists use_gdb_stub] {
3331 -re ".*Breakpoint .*main .*$gdb_prompt $"\
3332 {pass "rerun to main" ; return 0}
3333 -re "$gdb_prompt $"\
3334 {fail "rerun to main" ; return 0}
3335 timeout {fail "(timeout) rerun to main" ; return 0}
3340 -re "The program .* has been started already.*y or n. $" {
3344 -re "Starting program.*$gdb_prompt $"\
3345 {pass "rerun to main" ; return 0}
3346 -re "$gdb_prompt $"\
3347 {fail "rerun to main" ; return 0}
3348 timeout {fail "(timeout) rerun to main" ; return 0}
3353 # Print a message and return true if a test should be skipped
3354 # due to lack of floating point suport.
3356 proc gdb_skip_float_test { msg } {
3357 if [target_info exists gdb,skip_float_tests] {
3358 verbose "Skipping test '$msg': no float tests.";
3364 # Print a message and return true if a test should be skipped
3365 # due to lack of stdio support.
3367 proc gdb_skip_stdio_test { msg } {
3368 if [target_info exists gdb,noinferiorio] {
3369 verbose "Skipping test '$msg': no inferior i/o.";
3375 proc gdb_skip_bogus_test { msg } {
3379 # Return true if a test should be skipped due to lack of XML support
3381 # NOTE: This must be called while gdb is *not* running.
3383 proc gdb_skip_xml_test { } {
3386 global xml_missing_cached
3388 if {[info exists xml_missing_cached]} {
3389 return $xml_missing_cached
3393 set xml_missing_cached 0
3394 gdb_test_multiple "set tdesc filename ${srcdir}/gdb.xml/trivial.xml" "" {
3395 -re ".*XML support was disabled at compile time.*$gdb_prompt $" {
3396 set xml_missing_cached 1
3398 -re ".*$gdb_prompt $" { }
3401 return $xml_missing_cached
3404 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
3405 # ${binfile}.dbglnk, which is just like the executable ($binfile) but without
3406 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
3407 # the name of a debuginfo only file. This file will be stored in the same
3410 # Functions for separate debug info testing
3412 # starting with an executable:
3413 # foo --> original executable
3415 # at the end of the process we have:
3416 # foo.stripped --> foo w/o debug info
3417 # foo.debug --> foo's debug info
3418 # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug.
3420 # Return the build-id hex string (usually 160 bits as 40 hex characters)
3421 # converted to the form: .build-id/ab/cdef1234...89.debug
3422 # Return "" if no build-id found.
3423 proc build_id_debug_filename_get { exec } {
3424 set tmp "${exec}-tmp"
3425 set objcopy_program [transform objcopy]
3427 set result [catch "exec $objcopy_program -j .note.gnu.build-id -O binary $exec $tmp" output]
3428 verbose "result is $result"
3429 verbose "output is $output"
3434 fconfigure $fi -translation binary
3435 # Skip the NOTE header.
3440 if ![string compare $data ""] then {
3443 # Convert it to hex.
3444 binary scan $data H* data
3445 regsub {^..} $data {\0/} data
3446 return ".build-id/${data}.debug";
3449 # Create stripped files for DEST, replacing it. If ARGS is passed, it is a
3450 # list of optional flags. The only currently supported flag is no-main,
3451 # which removes the symbol entry for main from the separate debug file.
3453 # Function returns zero on success. Function will return non-zero failure code
3454 # on some targets not supporting separate debug info (such as i386-msdos).
3456 proc gdb_gnu_strip_debug { dest args } {
3458 # Use the first separate debug info file location searched by GDB so the
3459 # run cannot be broken by some stale file searched with higher precedence.
3460 set debug_file "${dest}.debug"
3462 set strip_to_file_program [transform strip]
3463 set objcopy_program [transform objcopy]
3465 set debug_link [file tail $debug_file]
3466 set stripped_file "${dest}.stripped"
3468 # Get rid of the debug info, and store result in stripped_file
3469 # something like gdb/testsuite/gdb.base/blah.stripped.
3470 set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
3471 verbose "result is $result"
3472 verbose "output is $output"
3477 # Workaround PR binutils/10802:
3478 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
3479 set perm [file attributes ${dest} -permissions]
3480 file attributes ${stripped_file} -permissions $perm
3482 # Get rid of everything but the debug info, and store result in debug_file
3483 # This will be in the .debug subdirectory, see above.
3484 set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
3485 verbose "result is $result"
3486 verbose "output is $output"
3491 # If no-main is passed, strip the symbol for main from the separate
3492 # file. This is to simulate the behavior of elfutils's eu-strip, which
3493 # leaves the symtab in the original file only. There's no way to get
3494 # objcopy or strip to remove the symbol table without also removing the
3495 # debugging sections, so this is as close as we can get.
3496 if { [llength $args] == 1 && [lindex $args 0] == "no-main" } {
3497 set result [catch "exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp" output]
3498 verbose "result is $result"
3499 verbose "output is $output"
3503 file delete "${debug_file}"
3504 file rename "${debug_file}-tmp" "${debug_file}"
3507 # Link the two previous output files together, adding the .gnu_debuglink
3508 # section to the stripped_file, containing a pointer to the debug_file,
3509 # save the new file in dest.
3510 # This will be the regular executable filename, in the usual location.
3511 set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
3512 verbose "result is $result"
3513 verbose "output is $output"
3518 # Workaround PR binutils/10802:
3519 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
3520 set perm [file attributes ${stripped_file} -permissions]
3521 file attributes ${dest} -permissions $perm
3526 # Test the output of GDB_COMMAND matches the pattern obtained
3527 # by concatenating all elements of EXPECTED_LINES. This makes
3528 # it possible to split otherwise very long string into pieces.
3529 # If third argument is not empty, it's used as the name of the
3530 # test to be printed on pass/fail.
3531 proc help_test_raw { gdb_command expected_lines args } {
3532 set message $gdb_command
3533 if [llength $args]>0 then {
3534 set message [lindex $args 0]
3536 set expected_output [join $expected_lines ""]
3537 gdb_test "${gdb_command}" "${expected_output}" $message
3540 # Test the output of "help COMMAND_CLASS". EXPECTED_INITIAL_LINES
3541 # are regular expressions that should match the beginning of output,
3542 # before the list of commands in that class. The presence of
3543 # command list and standard epilogue will be tested automatically.
3544 proc test_class_help { command_class expected_initial_lines args } {
3546 "List of commands\:.*\[\r\n\]+"
3547 "Type \"help\" followed by command name for full documentation\.\[\r\n\]+"
3548 "Type \"apropos word\" to search for commands related to \"word\"\.[\r\n\]+"
3549 "Command name abbreviations are allowed if unambiguous\."
3551 set l_entire_body [concat $expected_initial_lines $l_stock_body]
3553 eval [list help_test_raw "help ${command_class}" $l_entire_body] $args
3556 # COMMAND_LIST should have either one element -- command to test, or
3557 # two elements -- abbreviated command to test, and full command the first
3558 # element is abbreviation of.
3559 # The command must be a prefix command. EXPECTED_INITIAL_LINES
3560 # are regular expressions that should match the beginning of output,
3561 # before the list of subcommands. The presence of
3562 # subcommand list and standard epilogue will be tested automatically.
3563 proc test_prefix_command_help { command_list expected_initial_lines args } {
3564 set command [lindex $command_list 0]
3565 if {[llength $command_list]>1} {
3566 set full_command [lindex $command_list 1]
3568 set full_command $command
3570 # Use 'list' and not just {} because we want variables to
3571 # be expanded in this list.
3572 set l_stock_body [list\
3573 "List of $full_command subcommands\:.*\[\r\n\]+"\
3574 "Type \"help $full_command\" followed by $full_command subcommand name for full documentation\.\[\r\n\]+"\
3575 "Type \"apropos word\" to search for commands related to \"word\"\.\[\r\n\]+"\
3576 "Command name abbreviations are allowed if unambiguous\."]
3577 set l_entire_body [concat $expected_initial_lines $l_stock_body]
3578 if {[llength $args]>0} {
3579 help_test_raw "help ${command}" $l_entire_body [lindex $args 0]
3581 help_test_raw "help ${command}" $l_entire_body
3585 # Build executable named EXECUTABLE, from SOURCES. If SOURCES are not
3586 # provided, uses $EXECUTABLE.c. The TESTNAME paramer is the name of test
3587 # to pass to untested, if something is wrong. OPTIONS are passed
3588 # to gdb_compile directly.
3589 proc build_executable { testname executable {sources ""} {options {debug}} } {
3594 if {[llength $sources]==0} {
3595 set sources ${executable}.c
3598 set binfile ${objdir}/${subdir}/${executable}
3601 for {set i 0} "\$i<[llength $sources]" {incr i} {
3602 set s [lindex $sources $i]
3603 if { [gdb_compile "${srcdir}/${subdir}/${s}" "${binfile}${i}.o" object $options] != "" } {
3607 lappend objects "${binfile}${i}.o"
3610 if { [gdb_compile $objects "${binfile}" executable $options] != "" } {
3616 if { [lsearch -exact $options "c++"] >= 0 } {
3617 set info_options "c++"
3619 if [get_compiler_info ${binfile} ${info_options}] {
3625 # Starts fresh GDB binary and loads EXECUTABLE into GDB. EXECUTABLE is
3626 # the name of binary in ${objdir}/${subdir}.
3627 proc clean_restart { executable } {
3631 set binfile ${objdir}/${subdir}/${executable}
3635 gdb_reinitialize_dir $srcdir/$subdir
3638 if [target_info exists gdb_stub] {
3643 # Prepares for testing, by calling build_executable, and then clean_restart.
3644 # Please refer to build_executable for parameter description.
3645 proc prepare_for_testing { testname executable {sources ""} {options {debug}}} {
3647 if {[build_executable $testname $executable $sources $options] == -1} {
3650 clean_restart $executable
3655 proc get_valueof { fmt exp default } {
3658 set test "get valueof \"${exp}\""
3660 gdb_test_multiple "print${fmt} ${exp}" "$test" {
3661 -re "\\$\[0-9\]* = (.*)\[\r\n\]*$gdb_prompt $" {
3662 set val $expect_out(1,string)
3666 fail "$test (timeout)"
3672 proc get_integer_valueof { exp default } {
3675 set test "get integer valueof \"${exp}\""
3677 gdb_test_multiple "print /d ${exp}" "$test" {
3678 -re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" {
3679 set val $expect_out(1,string)
3683 fail "$test (timeout)"
3689 proc get_hexadecimal_valueof { exp default } {
3691 send_gdb "print /x ${exp}\n"
3692 set test "get hexadecimal valueof \"${exp}\""
3694 -re "\\$\[0-9\]* = (0x\[0-9a-zA-Z\]+).*$gdb_prompt $" {
3695 set val $expect_out(1,string)
3700 fail "$test (timeout)"
3706 proc get_sizeof { type default } {
3707 return [get_integer_valueof "sizeof (${type})" $default]
3710 # Get the current value for remotetimeout and return it.
3711 proc get_remotetimeout { } {
3715 gdb_test_multiple "show remotetimeout" "" {
3716 -re "Timeout limit to wait for target to respond is ($decimal).*$gdb_prompt $" {
3717 return $expect_out(1,string);
3721 # Pick the default that gdb uses
3722 warning "Unable to read remotetimeout"
3726 # Set the remotetimeout to the specified timeout. Nothing is returned.
3727 proc set_remotetimeout { timeout } {
3730 gdb_test_multiple "set remotetimeout $timeout" "" {
3731 -re "$gdb_prompt $" {
3732 verbose "Set remotetimeout to $timeout\n"
3737 # Log gdb command line and script if requested.
3738 if {[info exists TRANSCRIPT]} {
3739 rename send_gdb real_send_gdb
3740 rename remote_spawn real_remote_spawn
3741 rename remote_close real_remote_close
3743 global gdb_transcript
3744 set gdb_transcript ""
3746 global gdb_trans_count
3747 set gdb_trans_count 1
3749 proc remote_spawn {args} {
3750 global gdb_transcript gdb_trans_count outdir
3752 if {$gdb_transcript != ""} {
3753 close $gdb_transcript
3755 set gdb_transcript [open [file join $outdir transcript.$gdb_trans_count] w]
3756 puts $gdb_transcript [lindex $args 1]
3757 incr gdb_trans_count
3759 return [uplevel real_remote_spawn $args]
3762 proc remote_close {args} {
3763 global gdb_transcript
3765 if {$gdb_transcript != ""} {
3766 close $gdb_transcript
3767 set gdb_transcript ""
3770 return [uplevel real_remote_close $args]
3773 proc send_gdb {args} {
3774 global gdb_transcript
3776 if {$gdb_transcript != ""} {
3777 puts -nonewline $gdb_transcript [lindex $args 0]
3780 return [uplevel real_send_gdb $args]
3784 proc core_find {binfile {deletefiles {}} {arg ""}} {
3785 global objdir subdir
3787 set destcore "$binfile.core"
3788 file delete $destcore
3790 # Create a core file named "$destcore" rather than just "core", to
3791 # avoid problems with sys admin types that like to regularly prune all
3792 # files named "core" from the system.
3794 # Arbitrarily try setting the core size limit to "unlimited" since
3795 # this does not hurt on systems where the command does not work and
3796 # allows us to generate a core on systems where it does.
3798 # Some systems append "core" to the name of the program; others append
3799 # the name of the program to "core"; still others (like Linux, as of
3800 # May 2003) create cores named "core.PID". In the latter case, we
3801 # could have many core files lying around, and it may be difficult to
3802 # tell which one is ours, so let's run the program in a subdirectory.
3804 set coredir "${objdir}/${subdir}/coredir.[getpid]"
3806 catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile} ${arg}; true) >/dev/null 2>&1\""
3807 # remote_exec host "${binfile}"
3808 foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
3809 if [remote_file build exists $i] {
3810 remote_exec build "mv $i $destcore"
3814 # Check for "core.PID".
3815 if { $found == 0 } {
3816 set names [glob -nocomplain -directory $coredir core.*]
3817 if {[llength $names] == 1} {
3818 set corefile [file join $coredir [lindex $names 0]]
3819 remote_exec build "mv $corefile $destcore"
3823 if { $found == 0 } {
3824 # The braindamaged HPUX shell quits after the ulimit -c above
3825 # without executing ${binfile}. So we try again without the
3826 # ulimit here if we didn't find a core file above.
3827 # Oh, I should mention that any "braindamaged" non-Unix system has
3828 # the same problem. I like the cd bit too, it's really neat'n stuff.
3829 catch "system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\""
3830 foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" {
3831 if [remote_file build exists $i] {
3832 remote_exec build "mv $i $destcore"
3838 # Try to clean up after ourselves.
3839 foreach deletefile $deletefiles {
3840 remote_file build delete [file join $coredir $deletefile]
3842 remote_exec build "rmdir $coredir"
3844 if { $found == 0 } {
3845 warning "can't generate a core file - core tests suppressed - check ulimit -c"
3851 # gdb_target_symbol_prefix_flags returns a string that can be added
3852 # to gdb_compile options to define SYMBOL_PREFIX macro value
3853 # symbol_prefix_flags returns a string that can be added
3854 # for targets that use underscore as symbol prefix.
3855 # TODO: find out automatically if the target needs this.
3857 proc gdb_target_symbol_prefix_flags {} {
3858 if { [istarget "*-*-cygwin*"] || [istarget "i?86-*-mingw*"]
3859 || [istarget "*-*-msdosdjgpp*"] || [istarget "*-*-go32*"] } {
3860 return "additional_flags=-DSYMBOL_PREFIX=\"_\""
3866 # Always load compatibility stuff.