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 ### Only procedures should come after this point.
105 # gdb_version -- extract and print the version number of GDB
107 proc default_gdb_version {} {
109 global INTERNAL_GDBFLAGS GDBFLAGS
111 set output [remote_exec host "$GDB $INTERNAL_GDBFLAGS --version"]
112 set tmp [lindex $output 1];
114 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
115 if ![is_remote host] {
116 clone_output "[which $GDB] version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
118 clone_output "$GDB on remote host version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
122 proc gdb_version { } {
123 return [default_gdb_version];
127 # gdb_unload -- unload a file if one is loaded
136 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
137 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
138 -re "A program is being debugged already..*Kill it.*y or n. $"\
140 verbose "\t\tKilling previous program being debugged"
143 -re "Discard symbol table from .*y or n.*$" {
147 -re "$gdb_prompt $" {}
149 perror "couldn't unload file in $GDB (timed out)."
155 # Many of the tests depend on setting breakpoints at various places and
156 # running until that breakpoint is reached. At times, we want to start
157 # with a clean-slate with respect to breakpoints, so this utility proc
158 # lets us do this without duplicating this code everywhere.
161 proc delete_breakpoints {} {
164 # we need a larger timeout value here or this thing just confuses
165 # itself. May need a better implementation if possible. - guo
167 send_gdb "delete breakpoints\n"
169 -re "Delete all breakpoints.*y or n.*$" {
173 -re "$gdb_prompt $" { # This happens if there were no breakpoints
175 timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
177 send_gdb "info breakpoints\n"
179 -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
180 -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
181 -re "Delete all breakpoints.*or n.*$" {
185 timeout { perror "info breakpoints (timeout)" ; return }
191 # Generic run command.
193 # The second pattern below matches up to the first newline *only*.
194 # Using ``.*$'' could swallow up output that we attempt to match
197 proc gdb_run_cmd {args} {
200 if [target_info exists gdb_init_command] {
201 send_gdb "[target_info gdb_init_command]\n";
203 -re "$gdb_prompt $" { }
205 perror "gdb_init_command for target failed";
211 if [target_info exists use_gdb_stub] {
212 if [target_info exists gdb,do_reload_on_run] {
213 if { [gdb_reload] != 0 } {
216 send_gdb "continue\n";
218 -re "Continu\[^\r\n\]*\[\r\n\]" {}
224 if [target_info exists gdb,start_symbol] {
225 set start [target_info gdb,start_symbol];
229 send_gdb "jump *$start\n"
231 while { $start_attempt } {
232 # Cap (re)start attempts at three to ensure that this loop
233 # always eventually fails. Don't worry about trying to be
234 # clever and not send a command when it has failed.
235 if [expr $start_attempt > 3] {
236 perror "Jump to start() failed (retry count exceeded)";
239 set start_attempt [expr $start_attempt + 1];
241 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
244 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
245 perror "Can't find start symbol to run in gdb_run";
248 -re "No symbol \"start\" in current.*$gdb_prompt $" {
249 send_gdb "jump *_start\n";
251 -re "No symbol.*context.*$gdb_prompt $" {
254 -re "Line.* Jump anyway.*y or n. $" {
257 -re "The program is not being run.*$gdb_prompt $" {
258 if { [gdb_reload] != 0 } {
261 send_gdb "jump *$start\n";
264 perror "Jump to start() failed (timeout)";
269 if [target_info exists gdb_stub] {
271 -re "$gdb_prompt $" {
272 send_gdb "continue\n"
279 if [target_info exists gdb,do_reload_on_run] {
280 if { [gdb_reload] != 0 } {
284 send_gdb "run $args\n"
285 # This doesn't work quite right yet.
286 # Use -notransfer here so that test cases (like chng-sym.exp)
287 # may test for additional start-up messages.
289 -re "The program .* has been started already.*y or n. $" {
293 -notransfer -re "Starting program: \[^\r\n\]*" {}
294 -notransfer -re "$gdb_prompt $" {
295 # There is no more input expected.
300 # Generic start command. Return 0 if we could start the program, -1
303 proc gdb_start_cmd {args} {
306 if [target_info exists gdb_init_command] {
307 send_gdb "[target_info gdb_init_command]\n";
309 -re "$gdb_prompt $" { }
311 perror "gdb_init_command for target failed";
317 if [target_info exists use_gdb_stub] {
321 send_gdb "start $args\n"
322 # Use -notransfer here so that test cases (like chng-sym.exp)
323 # may test for additional start-up messages.
325 -re "The program .* has been started already.*y or n. $" {
329 -notransfer -re "Starting program: \[^\r\n\]*" {
336 # Set a breakpoint at FUNCTION. If there is an additional argument it is
337 # a list of options; the supported options are allow-pending, temporary,
340 proc gdb_breakpoint { function args } {
344 set pending_response n
345 if {[lsearch -exact [lindex $args 0] allow-pending] != -1} {
346 set pending_response y
349 set break_command "break"
350 set break_message "Breakpoint"
351 if {[lsearch -exact [lindex $args 0] temporary] != -1} {
352 set break_command "tbreak"
353 set break_message "Temporary breakpoint"
357 if {[lsearch -exact [lindex $args 0] no-message] != -1} {
361 send_gdb "$break_command $function\n"
362 # The first two regexps are what we get with -g, the third is without -g.
364 -re "$break_message \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
365 -re "$break_message \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
366 -re "$break_message \[0-9\]* at .*$gdb_prompt $" {}
367 -re "$break_message \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" {
368 if {$pending_response == "n"} {
369 if { $no_message == 0 } {
370 fail "setting breakpoint at $function"
375 -re "Make breakpoint pending.*y or \\\[n\\\]. $" {
376 send_gdb "$pending_response\n"
379 -re "$gdb_prompt $" {
380 if { $no_message == 0 } {
381 fail "setting breakpoint at $function"
386 if { $no_message == 0 } {
387 fail "setting breakpoint at $function (timeout)"
395 # Set breakpoint at function and run gdb until it breaks there.
396 # Since this is the only breakpoint that will be set, if it stops
397 # at a breakpoint, we will assume it is the one we want. We can't
398 # just compare to "function" because it might be a fully qualified,
399 # single quoted C++ function specifier. If there's an additional argument,
400 # pass it to gdb_breakpoint.
402 proc runto { function args } {
408 if ![gdb_breakpoint $function [lindex $args 0]] {
414 # the "at foo.c:36" output we get with -g.
415 # the "in func" output we get without -g.
417 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
420 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
423 -re "The target does not support running in non-stop mode.\r\n$gdb_prompt $" {
424 unsupported "Non-stop mode not supported"
427 -re ".*A problem internal to GDB has been detected" {
428 fail "running to $function in runto (GDB internal error)"
429 gdb_internal_error_resync
432 -re "$gdb_prompt $" {
433 fail "running to $function in runto"
437 fail "running to $function in runto (end of file)"
441 fail "running to $function in runto (timeout)"
449 # runto_main -- ask gdb to run until we hit a breakpoint at main.
450 # The case where the target uses stubs has to be handled
451 # specially--if it uses stubs, assuming we hit
452 # breakpoint() and just step out of the function.
454 proc runto_main { } {
458 if ![target_info exists gdb_stub] {
470 ### Continue, and expect to hit a breakpoint.
471 ### Report a pass or fail, depending on whether it seems to have
472 ### worked. Use NAME as part of the test name; each call to
473 ### continue_to_breakpoint should use a NAME which is unique within
475 proc gdb_continue_to_breakpoint {name {location_pattern .*}} {
477 set full_name "continue to breakpoint: $name"
479 send_gdb "continue\n"
481 -re "Breakpoint .* (at|in) $location_pattern\r\n$gdb_prompt $" {
484 -re ".*$gdb_prompt $" {
488 fail "$full_name (timeout)"
494 # gdb_internal_error_resync:
496 # Answer the questions GDB asks after it reports an internal error
497 # until we get back to a GDB prompt. Decline to quit the debugging
498 # session, and decline to create a core file. Return non-zero if the
501 # This procedure just answers whatever questions come up until it sees
502 # a GDB prompt; it doesn't require you to have matched the input up to
503 # any specific point. However, it only answers questions it sees in
504 # the output itself, so if you've matched a question, you had better
505 # answer it yourself before calling this.
507 # You can use this function thus:
511 # -re ".*A problem internal to GDB has been detected" {
512 # gdb_internal_error_resync
517 proc gdb_internal_error_resync {} {
521 while {$count < 10} {
523 -re "Quit this debugging session\\? \\(y or n\\) $" {
527 -re "Create a core file of GDB\\? \\(y or n\\) $" {
531 -re "$gdb_prompt $" {
532 # We're resynchronized.
536 perror "Could not resync from internal error (timeout)"
541 perror "Could not resync from internal error (resync count exceeded)"
546 # gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS
547 # Send a command to gdb; test the result.
549 # COMMAND is the command to execute, send to GDB with send_gdb. If
550 # this is the null string no command is sent.
551 # MESSAGE is a message to be printed with the built-in failure patterns
552 # if one of them matches. If MESSAGE is empty COMMAND will be used.
553 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
554 # patterns. Pattern elements will be evaluated in the caller's
555 # context; action elements will be executed in the caller's context.
556 # Unlike patterns for gdb_test, these patterns should generally include
557 # the final newline and prompt.
560 # 1 if the test failed, according to a built-in failure pattern
561 # 0 if only user-supplied patterns matched
562 # -1 if there was an internal error.
564 # You can use this function thus:
566 # gdb_test_multiple "print foo" "test foo" {
567 # -re "expected output 1" {
570 # -re "expected output 2" {
575 # The standard patterns, such as "Program exited..." and "A problem
576 # ...", all being implicitly appended to that list.
578 proc gdb_test_multiple { command message user_code } {
582 upvar timeout timeout
583 upvar expect_out expect_out
585 if { $message == "" } {
589 if [string match "*\[\r\n\]" $command] {
590 error "Invalid trailing newline in \"$message\" test"
593 # TCL/EXPECT WART ALERT
594 # Expect does something very strange when it receives a single braced
595 # argument. It splits it along word separators and performs substitutions.
596 # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
597 # evaluated as "\[ab\]". But that's not how TCL normally works; inside a
598 # double-quoted list item, "\[ab\]" is just a long way of representing
599 # "[ab]", because the backslashes will be removed by lindex.
601 # Unfortunately, there appears to be no easy way to duplicate the splitting
602 # that expect will do from within TCL. And many places make use of the
603 # "\[0-9\]" construct, so we need to support that; and some places make use
604 # of the "[func]" construct, so we need to support that too. In order to
605 # get this right we have to substitute quoted list elements differently
606 # from braced list elements.
608 # We do this roughly the same way that Expect does it. We have to use two
609 # lists, because if we leave unquoted newlines in the argument to uplevel
610 # they'll be treated as command separators, and if we escape newlines
611 # we mangle newlines inside of command blocks. This assumes that the
612 # input doesn't contain a pattern which contains actual embedded newlines
615 regsub -all {\n} ${user_code} { } subst_code
616 set subst_code [uplevel list $subst_code]
618 set processed_code ""
620 set expecting_action 0
622 foreach item $user_code subst_item $subst_code {
623 if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } {
624 lappend processed_code $item
627 if { $item == "-indices" || $item == "-re" || $item == "-ex" } {
628 lappend processed_code $item
631 if { $item == "-timeout" } {
633 lappend processed_code $item
636 if { $expecting_arg } {
638 lappend processed_code $item
641 if { $expecting_action } {
642 lappend processed_code "uplevel [list $item]"
643 set expecting_action 0
644 # Cosmetic, no effect on the list.
645 append processed_code "\n"
648 set expecting_action 1
649 lappend processed_code $subst_item
650 if {$patterns != ""} {
653 append patterns "\"$subst_item\""
656 # Also purely cosmetic.
657 regsub -all {\r} $patterns {\\r} patterns
658 regsub -all {\n} $patterns {\\n} patterns
661 send_user "Sending \"$command\" to gdb\n"
662 send_user "Looking to match \"$patterns\"\n"
663 send_user "Message is \"$message\"\n"
667 set string "${command}\n";
668 if { $command != "" } {
669 while { "$string" != "" } {
670 set foo [string first "\n" "$string"];
671 set len [string length "$string"];
672 if { $foo < [expr $len - 1] } {
673 set str [string range "$string" 0 $foo];
674 if { [send_gdb "$str"] != "" } {
675 global suppress_flag;
677 if { ! $suppress_flag } {
678 perror "Couldn't send $command to GDB.";
683 # since we're checking if each line of the multi-line
684 # command are 'accepted' by GDB here,
685 # we need to set -notransfer expect option so that
686 # command output is not lost for pattern matching
689 -notransfer -re "\[\r\n\]" { verbose "partial: match" 3 }
690 timeout { verbose "partial: timeout" 3 }
692 set string [string range "$string" [expr $foo + 1] end];
697 if { "$string" != "" } {
698 if { [send_gdb "$string"] != "" } {
699 global suppress_flag;
701 if { ! $suppress_flag } {
702 perror "Couldn't send $command to GDB.";
710 if [target_info exists gdb,timeout] {
711 set tmt [target_info gdb,timeout];
713 if [info exists timeout] {
717 if [info exists timeout] {
726 -re ".*A problem internal to GDB has been detected" {
727 fail "$message (GDB internal error)"
728 gdb_internal_error_resync
730 -re "\\*\\*\\* DOSEXIT code.*" {
731 if { $message != "" } {
734 gdb_suppress_entire_file "GDB died";
738 append code $processed_code
740 -re "Ending remote debugging.*$gdb_prompt $" {
741 if ![isnative] then {
742 warning "Can`t communicate to remote target."
748 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
749 perror "Undefined command \"$command\"."
753 -re "Ambiguous command.*$gdb_prompt $" {
754 perror "\"$command\" is not a unique command name."
758 -re "Program exited with code \[0-9\]+.*$gdb_prompt $" {
759 if ![string match "" $message] then {
760 set errmsg "$message (the program exited)"
762 set errmsg "$command (the program exited)"
767 -re "Program exited normally.*$gdb_prompt $" {
768 if ![string match "" $message] then {
769 set errmsg "$message (the program exited)"
771 set errmsg "$command (the program exited)"
776 -re "The program is not being run.*$gdb_prompt $" {
777 if ![string match "" $message] then {
778 set errmsg "$message (the program is no longer running)"
780 set errmsg "$command (the program is no longer running)"
785 -re "\r\n$gdb_prompt $" {
786 if ![string match "" $message] then {
793 perror "Window too small."
797 -re "\\((y or n|y or \\\[n\\\]|\\\[y\\\] or n)\\) " {
799 gdb_expect -re "$gdb_prompt $"
800 fail "$message (got interactive prompt)"
803 -re "\\\[0\\\] cancel\r\n\\\[1\\\] all.*\r\n> $" {
805 gdb_expect -re "$gdb_prompt $"
806 fail "$message (got breakpoint menu)"
810 perror "Process no longer exists"
811 if { $message != "" } {
817 perror "internal buffer is full."
822 if ![string match "" $message] then {
823 fail "$message (timeout)"
830 set code [catch {gdb_expect $tmt $code} string]
832 global errorInfo errorCode;
833 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
834 } elseif {$code == 2} {
835 return -code return $string
836 } elseif {$code == 3} {
838 } elseif {$code > 4} {
839 return -code $code $string
844 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
845 # Send a command to gdb; test the result.
847 # COMMAND is the command to execute, send to GDB with send_gdb. If
848 # this is the null string no command is sent.
849 # PATTERN is the pattern to match for a PASS, and must NOT include
850 # the \r\n sequence immediately before the gdb prompt.
851 # MESSAGE is an optional message to be printed. If this is
852 # omitted, then the pass/fail messages use the command string as the
853 # message. (If this is the empty string, then sometimes we don't
854 # call pass or fail at all; I don't understand this at all.)
855 # QUESTION is a question GDB may ask in response to COMMAND, like
857 # RESPONSE is the response to send if QUESTION appears.
860 # 1 if the test failed,
861 # 0 if the test passes,
862 # -1 if there was an internal error.
864 proc gdb_test { args } {
868 upvar timeout timeout
870 if [llength $args]>2 then {
871 set message [lindex $args 2]
873 set message [lindex $args 0]
875 set command [lindex $args 0]
876 set pattern [lindex $args 1]
878 if [llength $args]==5 {
879 set question_string [lindex $args 3];
880 set response_string [lindex $args 4];
882 set question_string "^FOOBAR$"
885 return [gdb_test_multiple $command $message {
886 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
887 if ![string match "" $message] then {
891 -re "(${question_string})$" {
892 send_gdb "$response_string\n";
898 # gdb_test_no_output COMMAND MESSAGE
899 # Send a command to GDB and verify that this command generated no output.
901 # See gdb_test_multiple for a description of the COMMAND and MESSAGE
902 # parameters. If MESSAGE is ommitted, then COMMAND will be used as
903 # the message. (If MESSAGE is the empty string, then sometimes we do not
904 # call pass or fail at all; I don't understand this at all.)
906 proc gdb_test_no_output { args } {
908 set command [lindex $args 0]
909 if [llength $args]>1 then {
910 set message [lindex $args 1]
915 set command_regex [string_to_regexp $command]
916 gdb_test_multiple $command $message {
917 -re "^$command_regex\r\n$gdb_prompt $" {
918 if ![string match "" $message] then {
925 # Send a command and then wait for a sequence of outputs.
926 # This is useful when the sequence is long and contains ".*", a single
927 # regexp to match the entire output can get a timeout much easier.
929 # COMMAND is the command to send.
930 # TEST_NAME is passed to pass/fail. COMMAND is used if TEST_NAME is "".
931 # EXPECTED_OUTPUT_LIST is a list of regexps of expected output, which are
932 # processed in order, and all must be present in the output.
934 # It is unnecessary to specify ".*" at the beginning or end of any regexp,
935 # there is an implicit ".*" between each element of EXPECTED_OUTPUT_LIST.
936 # There is also an implicit ".*" between the last regexp and the gdb prompt.
938 # Like gdb_test and gdb_test_multiple, the output is expected to end with the
939 # gdb prompt, which must not be specified in EXPECTED_OUTPUT_LIST.
942 # 1 if the test failed,
943 # 0 if the test passes,
944 # -1 if there was an internal error.
946 proc gdb_test_sequence { command test_name expected_output_list } {
948 if { $test_name == "" } {
949 set test_name $command
951 lappend expected_output_list ""; # implicit ".*" before gdb prompt
952 send_gdb "$command\n"
953 return [gdb_expect_list $test_name "$gdb_prompt $" $expected_output_list]
957 # Test that a command gives an error. For pass or fail, return
958 # a 1 to indicate that more tests can proceed. However a timeout
959 # is a serious error, generates a special fail message, and causes
960 # a 0 to be returned to indicate that more tests are likely to fail
963 proc test_print_reject { args } {
967 if [llength $args]==2 then {
968 set expectthis [lindex $args 1]
970 set expectthis "should never match this bogus string"
972 set sendthis [lindex $args 0]
974 send_user "Sending \"$sendthis\" to gdb\n"
975 send_user "Looking to match \"$expectthis\"\n"
977 send_gdb "$sendthis\n"
978 #FIXME: Should add timeout as parameter.
980 -re "A .* in expression.*\\.*$gdb_prompt $" {
981 pass "reject $sendthis"
984 -re "Invalid syntax in expression.*$gdb_prompt $" {
985 pass "reject $sendthis"
988 -re "Junk after end of expression.*$gdb_prompt $" {
989 pass "reject $sendthis"
992 -re "Invalid number.*$gdb_prompt $" {
993 pass "reject $sendthis"
996 -re "Invalid character constant.*$gdb_prompt $" {
997 pass "reject $sendthis"
1000 -re "No symbol table is loaded.*$gdb_prompt $" {
1001 pass "reject $sendthis"
1004 -re "No symbol .* in current context.*$gdb_prompt $" {
1005 pass "reject $sendthis"
1008 -re "Unmatched single quote.*$gdb_prompt $" {
1009 pass "reject $sendthis"
1012 -re "A character constant must contain at least one character.*$gdb_prompt $" {
1013 pass "reject $sendthis"
1016 -re "$expectthis.*$gdb_prompt $" {
1017 pass "reject $sendthis"
1020 -re ".*$gdb_prompt $" {
1021 fail "reject $sendthis"
1025 fail "reject $sendthis (eof or timeout)"
1031 # Given an input string, adds backslashes as needed to create a
1032 # regexp that will match the string.
1034 proc string_to_regexp {str} {
1036 regsub -all {[]*+.|()^$\[\\]} $str {\\&} result
1040 # Same as gdb_test, but the second parameter is not a regexp,
1041 # but a string that must match exactly.
1043 proc gdb_test_exact { args } {
1044 upvar timeout timeout
1046 set command [lindex $args 0]
1048 # This applies a special meaning to a null string pattern. Without
1049 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
1050 # messages from commands that should have no output except a new
1051 # prompt. With this, only results of a null string will match a null
1054 set pattern [lindex $args 1]
1055 if [string match $pattern ""] {
1056 set pattern [string_to_regexp [lindex $args 0]]
1058 set pattern [string_to_regexp [lindex $args 1]]
1061 # It is most natural to write the pattern argument with only
1062 # embedded \n's, especially if you are trying to avoid Tcl quoting
1063 # problems. But gdb_expect really wants to see \r\n in patterns. So
1064 # transform the pattern here. First transform \r\n back to \n, in
1065 # case some users of gdb_test_exact already do the right thing.
1066 regsub -all "\r\n" $pattern "\n" pattern
1067 regsub -all "\n" $pattern "\r\n" pattern
1068 if [llength $args]==3 then {
1069 set message [lindex $args 2]
1071 set message $command
1074 return [gdb_test $command $pattern $message]
1077 # Wrapper around gdb_test_multiple that looks for a list of expected
1078 # output elements, but which can appear in any order.
1079 # CMD is the gdb command.
1080 # NAME is the name of the test.
1081 # ELM_FIND_REGEXP specifies how to partition the output into elements to
1083 # ELM_EXTRACT_REGEXP specifies the part of ELM_FIND_REGEXP to compare.
1084 # RESULT_MATCH_LIST is a list of exact matches for each expected element.
1085 # All elements of RESULT_MATCH_LIST must appear for the test to pass.
1087 # A typical use of ELM_FIND_REGEXP/ELM_EXTRACT_REGEXP is to extract one line
1088 # of text per element and then strip trailing \r\n's.
1090 # gdb_test_list_exact "foo" "bar" \
1091 # {[^\r\n]+[\r\n]+} \
1094 # {expected result 1} \
1095 # {expected result 2} \
1098 proc gdb_test_list_exact { cmd name elm_find_regexp elm_extract_regexp result_match_list } {
1101 set matches [lsort $result_match_list]
1103 gdb_test_multiple $cmd $name {
1104 "$cmd\[\r\n\]" { exp_continue }
1105 -re $elm_find_regexp {
1106 set str $expect_out(0,string)
1107 verbose -log "seen: $str" 3
1108 regexp -- $elm_extract_regexp $str elm_seen
1109 verbose -log "extracted: $elm_seen" 3
1110 lappend seen $elm_seen
1113 -re "$gdb_prompt $" {
1115 foreach got [lsort $seen] have $matches {
1116 if {![string equal $got $have]} {
1121 if {[string length $failed] != 0} {
1122 fail "$name ($failed not found)"
1130 proc gdb_reinitialize_dir { subdir } {
1133 if [is_remote host] {
1138 -re "Reinitialize source path to empty.*y or n. " {
1141 -re "Source directories searched.*$gdb_prompt $" {
1142 send_gdb "dir $subdir\n"
1144 -re "Source directories searched.*$gdb_prompt $" {
1145 verbose "Dir set to $subdir"
1147 -re "$gdb_prompt $" {
1148 perror "Dir \"$subdir\" failed."
1152 -re "$gdb_prompt $" {
1153 perror "Dir \"$subdir\" failed."
1157 -re "$gdb_prompt $" {
1158 perror "Dir \"$subdir\" failed."
1164 # gdb_exit -- exit the GDB, killing the target program if necessary
1166 proc default_gdb_exit {} {
1168 global INTERNAL_GDBFLAGS GDBFLAGS
1170 global gdb_spawn_id;
1172 gdb_stop_suppressing_tests;
1174 if ![info exists gdb_spawn_id] {
1178 verbose "Quitting $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1180 if { [is_remote host] && [board_info host exists fileid] } {
1187 -re "DOSEXIT code" { }
1192 if ![is_remote host] {
1198 # Load a file into the debugger.
1199 # The return value is 0 for success, -1 for failure.
1201 # This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO
1202 # to one of these values:
1204 # debug file was loaded successfully and has debug information
1205 # nodebug file was loaded successfully and has no debug information
1206 # fail file was not loaded
1208 # I tried returning this information as part of the return value,
1209 # but ran into a mess because of the many re-implementations of
1210 # gdb_load in config/*.exp.
1212 # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use
1213 # this if they can get more information set.
1215 proc gdb_file_cmd { arg } {
1219 global last_loaded_file
1221 set last_loaded_file $arg
1223 # Set whether debug info was found.
1224 # Default to "fail".
1225 global gdb_file_cmd_debug_info
1226 set gdb_file_cmd_debug_info "fail"
1228 if [is_remote host] {
1229 set arg [remote_download host $arg]
1231 perror "download failed"
1236 # The file command used to kill the remote target. For the benefit
1237 # of the testsuite, preserve this behavior.
1240 -re "Kill the program being debugged. .y or n. $" {
1242 verbose "\t\tKilling previous program being debugged"
1245 -re "$gdb_prompt $" {
1250 send_gdb "file $arg\n"
1252 -re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" {
1253 verbose "\t\tLoaded $arg into the $GDB with no debugging symbols"
1254 set gdb_file_cmd_debug_info "nodebug"
1257 -re "Reading symbols from.*done.*$gdb_prompt $" {
1258 verbose "\t\tLoaded $arg into the $GDB"
1259 set gdb_file_cmd_debug_info "debug"
1262 -re "Load new symbol table from \".*\".*y or n. $" {
1265 -re "Reading symbols from.*done.*$gdb_prompt $" {
1266 verbose "\t\tLoaded $arg with new symbol table into $GDB"
1267 set gdb_file_cmd_debug_info "debug"
1271 perror "(timeout) Couldn't load $arg, other program already loaded."
1276 -re "No such file or directory.*$gdb_prompt $" {
1277 perror "($arg) No such file or directory"
1280 -re "$gdb_prompt $" {
1281 perror "couldn't load $arg into $GDB."
1285 perror "couldn't load $arg into $GDB (timed out)."
1289 # This is an attempt to detect a core dump, but seems not to
1290 # work. Perhaps we need to match .* followed by eof, in which
1291 # gdb_expect does not seem to have a way to do that.
1292 perror "couldn't load $arg into $GDB (end of file)."
1299 # start gdb -- start gdb running, default procedure
1301 # When running over NFS, particularly if running many simultaneous
1302 # tests on different hosts all using the same server, things can
1303 # get really slow. Give gdb at least 3 minutes to start up.
1305 proc default_gdb_start { } {
1308 global INTERNAL_GDBFLAGS GDBFLAGS
1311 global gdb_spawn_id;
1314 gdb_stop_suppressing_tests;
1318 # Don't let a .inputrc file or an existing setting of INPUTRC mess up
1319 # the test results. Even if /dev/null doesn't exist on the particular
1320 # platform, the readline library will use the default setting just by
1321 # failing to open the file. OTOH, opening /dev/null successfully will
1322 # also result in the default settings being used since nothing will be
1323 # read from this file.
1324 set env(INPUTRC) "/dev/null"
1326 # The gdb.base/readline.exp arrow key test relies on the standard VT100
1327 # bindings, so make sure that an appropriate terminal is selected.
1328 # The same bug doesn't show up if we use ^P / ^N instead.
1329 set env(TERM) "vt100"
1331 verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1333 if [info exists gdb_spawn_id] {
1337 if ![is_remote host] {
1338 if { [which $GDB] == 0 } then {
1339 perror "$GDB does not exist."
1343 set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"];
1344 if { $res < 0 || $res == "" } {
1345 perror "Spawning $GDB failed."
1349 -re "\[\r\n\]$gdb_prompt $" {
1350 verbose "GDB initialized."
1352 -re "$gdb_prompt $" {
1353 perror "GDB never initialized."
1357 perror "(timeout) GDB never initialized after 10 seconds."
1362 set gdb_spawn_id -1;
1363 # force the height to "unlimited", so no pagers get used
1365 send_gdb "set height 0\n"
1367 -re "$gdb_prompt $" {
1368 verbose "Setting height to 0." 2
1371 warning "Couldn't set the height to 0"
1374 # force the width to "unlimited", so no wraparound occurs
1375 send_gdb "set width 0\n"
1377 -re "$gdb_prompt $" {
1378 verbose "Setting width to 0." 2
1381 warning "Couldn't set the width to 0."
1387 # Examine the output of compilation to determine whether compilation
1388 # failed or not. If it failed determine whether it is due to missing
1389 # compiler or due to compiler error. Report pass, fail or unsupported
1392 proc gdb_compile_test {src output} {
1393 if { $output == "" } {
1394 pass "compilation [file tail $src]"
1395 } elseif { [regexp {^[a-zA-Z_0-9]+: Can't find [^ ]+\.$} $output] } {
1396 unsupported "compilation [file tail $src]"
1397 } elseif { [regexp {.*: command not found[\r|\n]*$} $output] } {
1398 unsupported "compilation [file tail $src]"
1399 } elseif { [regexp {.*: [^\r\n]*compiler not installed[^\r\n]*[\r|\n]*$} $output] } {
1400 unsupported "compilation [file tail $src]"
1402 verbose -log "compilation failed: $output" 2
1403 fail "compilation [file tail $src]"
1407 # Return a 1 for configurations for which we don't even want to try to
1410 proc skip_cplus_tests {} {
1411 if { [istarget "h8300-*-*"] } {
1415 # The C++ IO streams are too large for HC11/HC12 and are thus not
1416 # available. The gdb C++ tests use them and don't compile.
1417 if { [istarget "m6811-*-*"] } {
1420 if { [istarget "m6812-*-*"] } {
1426 # Return a 1 for configurations for which don't have both C++ and the STL.
1428 proc skip_stl_tests {} {
1429 # Symbian supports the C++ language, but the STL is missing
1430 # (both headers and libraries).
1431 if { [istarget "arm*-*-symbianelf*"] } {
1435 return [skip_cplus_tests]
1438 # Return a 1 if I don't even want to try to test FORTRAN.
1440 proc skip_fortran_tests {} {
1444 # Return a 1 if I don't even want to try to test ada.
1446 proc skip_ada_tests {} {
1450 # Return a 1 if I don't even want to try to test java.
1452 proc skip_java_tests {} {
1456 # Return a 1 for configurations that do not support Python scripting.
1458 proc skip_python_tests {} {
1460 gdb_test_multiple "python print 'test'" "verify python support" {
1461 -re "not supported.*$gdb_prompt $" {
1462 unsupported "Python support is disabled."
1465 -re "$gdb_prompt $" {}
1471 # Return a 1 if we should skip shared library tests.
1473 proc skip_shlib_tests {} {
1474 # Run the shared library tests on native systems.
1479 # An abbreviated list of remote targets where we should be able to
1480 # run shared library tests.
1481 if {([istarget *-*-linux*]
1482 || [istarget *-*-*bsd*]
1483 || [istarget *-*-solaris2*]
1484 || [istarget arm*-*-symbianelf*]
1485 || [istarget *-*-mingw*]
1486 || [istarget *-*-cygwin*]
1487 || [istarget *-*-pe*])} {
1494 # Return 1 if target is ILP32.
1495 # This cannot be decided simply from looking at the target string,
1496 # as it might depend on externally passed compiler options like -m64.
1497 proc is_ilp32_target {} {
1498 global is_ilp32_target_saved
1500 # Use the cached value, if it exists. Cache value per "board" to handle
1501 # runs with multiple options (e.g. unix/{-m32,-64}) correctly.
1502 set me "is_ilp32_target"
1503 set board [target_info name]
1504 if [info exists is_ilp32_target_saved($board)] {
1505 verbose "$me: returning saved $is_ilp32_target_saved($board)" 2
1506 return $is_ilp32_target_saved($board)
1510 set src ilp32[pid].c
1511 set obj ilp32[pid].o
1513 set f [open $src "w"]
1514 puts $f "int dummy\[sizeof (int) == 4"
1515 puts $f " && sizeof (void *) == 4"
1516 puts $f " && sizeof (long) == 4 ? 1 : -1\];"
1519 verbose "$me: compiling testfile $src" 2
1520 set lines [gdb_compile $src $obj object {quiet}]
1524 if ![string match "" $lines] then {
1525 verbose "$me: testfile compilation failed, returning 0" 2
1526 return [set is_ilp32_target_saved($board) 0]
1529 verbose "$me: returning 1" 2
1530 return [set is_ilp32_target_saved($board) 1]
1533 # Return 1 if target is LP64.
1534 # This cannot be decided simply from looking at the target string,
1535 # as it might depend on externally passed compiler options like -m64.
1536 proc is_lp64_target {} {
1537 global is_lp64_target_saved
1539 # Use the cached value, if it exists. Cache value per "board" to handle
1540 # runs with multiple options (e.g. unix/{-m32,-64}) correctly.
1541 set me "is_lp64_target"
1542 set board [target_info name]
1543 if [info exists is_lp64_target_saved($board)] {
1544 verbose "$me: returning saved $is_lp64_target_saved($board)" 2
1545 return $is_lp64_target_saved($board)
1551 set f [open $src "w"]
1552 puts $f "int dummy\[sizeof (int) == 4"
1553 puts $f " && sizeof (void *) == 8"
1554 puts $f " && sizeof (long) == 8 ? 1 : -1\];"
1557 verbose "$me: compiling testfile $src" 2
1558 set lines [gdb_compile $src $obj object {quiet}]
1562 if ![string match "" $lines] then {
1563 verbose "$me: testfile compilation failed, returning 0" 2
1564 return [set is_lp64_target_saved($board) 0]
1567 verbose "$me: returning 1" 2
1568 return [set is_lp64_target_saved($board) 1]
1571 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
1572 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
1574 proc skip_altivec_tests {} {
1575 global skip_vmx_tests_saved
1576 global srcdir subdir gdb_prompt
1578 # Use the cached value, if it exists.
1579 set me "skip_altivec_tests"
1580 if [info exists skip_vmx_tests_saved] {
1581 verbose "$me: returning saved $skip_vmx_tests_saved" 2
1582 return $skip_vmx_tests_saved
1585 # Some simulators are known to not support VMX instructions.
1586 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1587 verbose "$me: target known to not support VMX, returning 1" 2
1588 return [set skip_vmx_tests_saved 1]
1591 # Make sure we have a compiler that understands altivec.
1592 set compile_flags {debug nowarnings}
1593 if [get_compiler_info not-used] {
1594 warning "Could not get compiler info"
1597 if [test_compiler_info gcc*] {
1598 set compile_flags "$compile_flags additional_flags=-maltivec"
1599 } elseif [test_compiler_info xlc*] {
1600 set compile_flags "$compile_flags additional_flags=-qaltivec"
1602 verbose "Could not compile with altivec support, returning 1" 2
1606 # Set up, compile, and execute a test program containing VMX instructions.
1607 # Include the current process ID in the file names to prevent conflicts
1608 # with invocations for multiple testsuites.
1612 set f [open $src "w"]
1613 puts $f "int main() {"
1614 puts $f "#ifdef __MACH__"
1615 puts $f " asm volatile (\"vor v0,v0,v0\");"
1617 puts $f " asm volatile (\"vor 0,0,0\");"
1619 puts $f " return 0; }"
1622 verbose "$me: compiling testfile $src" 2
1623 set lines [gdb_compile $src $exe executable $compile_flags]
1626 if ![string match "" $lines] then {
1627 verbose "$me: testfile compilation failed, returning 1" 2
1628 return [set skip_vmx_tests_saved 1]
1631 # No error message, compilation succeeded so now run it via gdb.
1635 gdb_reinitialize_dir $srcdir/$subdir
1639 -re ".*Illegal instruction.*${gdb_prompt} $" {
1640 verbose -log "\n$me altivec hardware not detected"
1641 set skip_vmx_tests_saved 1
1643 -re ".*Program exited normally.*${gdb_prompt} $" {
1644 verbose -log "\n$me: altivec hardware detected"
1645 set skip_vmx_tests_saved 0
1648 warning "\n$me: default case taken"
1649 set skip_vmx_tests_saved 1
1653 remote_file build delete $exe
1655 verbose "$me: returning $skip_vmx_tests_saved" 2
1656 return $skip_vmx_tests_saved
1659 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
1660 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
1662 proc skip_vsx_tests {} {
1663 global skip_vsx_tests_saved
1664 global srcdir subdir gdb_prompt
1666 # Use the cached value, if it exists.
1667 set me "skip_vsx_tests"
1668 if [info exists skip_vsx_tests_saved] {
1669 verbose "$me: returning saved $skip_vsx_tests_saved" 2
1670 return $skip_vsx_tests_saved
1673 # Some simulators are known to not support Altivec instructions, so
1674 # they won't support VSX instructions as well.
1675 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1676 verbose "$me: target known to not support VSX, returning 1" 2
1677 return [set skip_vsx_tests_saved 1]
1680 # Make sure we have a compiler that understands altivec.
1681 set compile_flags {debug nowarnings quiet}
1682 if [get_compiler_info not-used] {
1683 warning "Could not get compiler info"
1686 if [test_compiler_info gcc*] {
1687 set compile_flags "$compile_flags additional_flags=-mvsx"
1688 } elseif [test_compiler_info xlc*] {
1689 set compile_flags "$compile_flags additional_flags=-qasm=gcc"
1691 verbose "Could not compile with vsx support, returning 1" 2
1698 set f [open $src "w"]
1699 puts $f "int main() {"
1700 puts $f " double a\[2\] = { 1.0, 2.0 };"
1701 puts $f "#ifdef __MACH__"
1702 puts $f " asm volatile (\"lxvd2x v0,v0,%\[addr\]\" : : \[addr\] \"r\" (a));"
1704 puts $f " asm volatile (\"lxvd2x 0,0,%\[addr\]\" : : \[addr\] \"r\" (a));"
1706 puts $f " return 0; }"
1709 verbose "$me: compiling testfile $src" 2
1710 set lines [gdb_compile $src $exe executable $compile_flags]
1713 if ![string match "" $lines] then {
1714 verbose "$me: testfile compilation failed, returning 1" 2
1715 return [set skip_vsx_tests_saved 1]
1718 # No error message, compilation succeeded so now run it via gdb.
1722 gdb_reinitialize_dir $srcdir/$subdir
1726 -re ".*Illegal instruction.*${gdb_prompt} $" {
1727 verbose -log "\n$me VSX hardware not detected"
1728 set skip_vsx_tests_saved 1
1730 -re ".*Program exited normally.*${gdb_prompt} $" {
1731 verbose -log "\n$me: VSX hardware detected"
1732 set skip_vsx_tests_saved 0
1735 warning "\n$me: default case taken"
1736 set skip_vsx_tests_saved 1
1740 remote_file build delete $exe
1742 verbose "$me: returning $skip_vsx_tests_saved" 2
1743 return $skip_vsx_tests_saved
1746 # Skip all the tests in the file if you are not on an hppa running
1749 proc skip_hp_tests {} {
1750 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
1751 verbose "Skip hp tests is $skip_hp"
1755 # Return whether we should skip tests for showing inlined functions in
1756 # backtraces. Requires get_compiler_info and get_debug_format.
1758 proc skip_inline_frame_tests {} {
1759 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
1760 if { ! [test_debug_format "DWARF 2"] } {
1764 # GCC before 4.1 does not emit DW_AT_call_file / DW_AT_call_line.
1765 if { ([test_compiler_info "gcc-2-*"]
1766 || [test_compiler_info "gcc-3-*"]
1767 || [test_compiler_info "gcc-4-0-*"]) } {
1774 # Return whether we should skip tests for showing variables from
1775 # inlined functions. Requires get_compiler_info and get_debug_format.
1777 proc skip_inline_var_tests {} {
1778 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
1779 if { ! [test_debug_format "DWARF 2"] } {
1786 # Return a 1 if we should skip tests that require hardware breakpoints
1788 proc skip_hw_breakpoint_tests {} {
1789 # Skip tests if requested by the board (note that no_hardware_watchpoints
1790 # disables both watchpoints and breakpoints)
1791 if { [target_info exists gdb,no_hardware_watchpoints]} {
1795 # These targets support hardware breakpoints natively
1796 if { [istarget "i?86-*-*"]
1797 || [istarget "x86_64-*-*"]
1798 || [istarget "ia64-*-*"] } {
1805 # Return a 1 if we should skip tests that require hardware watchpoints
1807 proc skip_hw_watchpoint_tests {} {
1808 # Skip tests if requested by the board
1809 if { [target_info exists gdb,no_hardware_watchpoints]} {
1813 # These targets support hardware watchpoints natively
1814 if { [istarget "i?86-*-*"]
1815 || [istarget "x86_64-*-*"]
1816 || [istarget "ia64-*-*"]
1817 || [istarget "powerpc*-*-linux*"]
1818 || [istarget "s390*-*-*"] } {
1825 # Return a 1 if we should skip tests that require *multiple* hardware
1826 # watchpoints to be active at the same time
1828 proc skip_hw_watchpoint_multi_tests {} {
1829 if { [skip_hw_watchpoint_tests] } {
1833 # These targets support just a single hardware watchpoint
1834 if { [istarget "powerpc*-*-linux*"] } {
1841 # Return a 1 if we should skip tests that require read/access watchpoints
1843 proc skip_hw_watchpoint_access_tests {} {
1844 if { [skip_hw_watchpoint_tests] } {
1848 # These targets support just write watchpoints
1849 if { [istarget "s390*-*-*"] } {
1856 set compiler_info "unknown"
1858 set hp_cc_compiler 0
1859 set hp_aCC_compiler 0
1861 # Figure out what compiler I am using.
1863 # BINFILE is a "compiler information" output file. This implementation
1864 # does not use BINFILE.
1866 # ARGS can be empty or "C++". If empty, "C" is assumed.
1868 # There are several ways to do this, with various problems.
1870 # [ gdb_compile -E $ifile -o $binfile.ci ]
1871 # source $binfile.ci
1873 # Single Unix Spec v3 says that "-E -o ..." together are not
1874 # specified. And in fact, the native compiler on hp-ux 11 (among
1875 # others) does not work with "-E -o ...". Most targets used to do
1876 # this, and it mostly worked, because it works with gcc.
1878 # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ]
1879 # source $binfile.ci
1881 # This avoids the problem with -E and -o together. This almost works
1882 # if the build machine is the same as the host machine, which is
1883 # usually true of the targets which are not gcc. But this code does
1884 # not figure which compiler to call, and it always ends up using the C
1885 # compiler. Not good for setting hp_aCC_compiler. Targets
1886 # hppa*-*-hpux* and mips*-*-irix* used to do this.
1888 # [ gdb_compile -E $ifile > $binfile.ci ]
1889 # source $binfile.ci
1891 # dejagnu target_compile says that it supports output redirection,
1892 # but the code is completely different from the normal path and I
1893 # don't want to sweep the mines from that path. So I didn't even try
1896 # set cppout [ gdb_compile $ifile "" preprocess $args quiet ]
1899 # I actually do this for all targets now. gdb_compile runs the right
1900 # compiler, and TCL captures the output, and I eval the output.
1902 # Unfortunately, expect logs the output of the command as it goes by,
1903 # and dejagnu helpfully prints a second copy of it right afterwards.
1904 # So I turn off expect logging for a moment.
1906 # [ gdb_compile $ifile $ciexe_file executable $args ]
1907 # [ remote_exec $ciexe_file ]
1908 # [ source $ci_file.out ]
1910 # I could give up on -E and just do this.
1911 # I didn't get desperate enough to try this.
1913 # -- chastain 2004-01-06
1915 proc get_compiler_info {binfile args} {
1916 # For compiler.c and compiler.cc
1919 # I am going to play with the log to keep noise out.
1923 # These come from compiler.c or compiler.cc
1924 global compiler_info
1926 # Legacy global data symbols.
1928 global hp_cc_compiler
1929 global hp_aCC_compiler
1931 # Choose which file to preprocess.
1932 set ifile "${srcdir}/lib/compiler.c"
1933 if { [llength $args] > 0 && [lindex $args 0] == "c++" } {
1934 set ifile "${srcdir}/lib/compiler.cc"
1937 # Run $ifile through the right preprocessor.
1938 # Toggle gdb.log to keep the compiler output out of the log.
1940 if [is_remote host] {
1941 # We have to use -E and -o together, despite the comments
1942 # above, because of how DejaGnu handles remote host testing.
1943 set ppout "$outdir/compiler.i"
1944 gdb_compile "${ifile}" "$ppout" preprocess [list "$args" quiet]
1945 set file [open $ppout r]
1946 set cppout [read $file]
1949 set cppout [ gdb_compile "${ifile}" "" preprocess [list "$args" quiet] ]
1951 log_file -a "$outdir/$tool.log"
1955 foreach cppline [ split "$cppout" "\n" ] {
1956 if { [ regexp "^#" "$cppline" ] } {
1958 } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } {
1960 } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } {
1962 verbose "get_compiler_info: $cppline" 2
1966 verbose -log "get_compiler_info: $cppline"
1971 # Reset to unknown compiler if any diagnostics happened.
1973 set compiler_info "unknown"
1976 # Set the legacy symbols.
1978 set hp_cc_compiler 0
1979 set hp_aCC_compiler 0
1980 if { [regexp "^gcc-1-" "$compiler_info" ] } { set gcc_compiled 1 }
1981 if { [regexp "^gcc-2-" "$compiler_info" ] } { set gcc_compiled 2 }
1982 if { [regexp "^gcc-3-" "$compiler_info" ] } { set gcc_compiled 3 }
1983 if { [regexp "^gcc-4-" "$compiler_info" ] } { set gcc_compiled 4 }
1984 if { [regexp "^gcc-5-" "$compiler_info" ] } { set gcc_compiled 5 }
1985 if { [regexp "^hpcc-" "$compiler_info" ] } { set hp_cc_compiler 1 }
1986 if { [regexp "^hpacc-" "$compiler_info" ] } { set hp_aCC_compiler 1 }
1988 # Log what happened.
1989 verbose -log "get_compiler_info: $compiler_info"
1991 # Most compilers will evaluate comparisons and other boolean
1992 # operations to 0 or 1.
1993 uplevel \#0 { set true 1 }
1994 uplevel \#0 { set false 0 }
1996 # Use of aCC results in boolean results being displayed as
1998 if { $hp_aCC_compiler } {
1999 uplevel \#0 { set true true }
2000 uplevel \#0 { set false false }
2006 proc test_compiler_info { {compiler ""} } {
2007 global compiler_info
2009 # if no arg, return the compiler_info string
2011 if [string match "" $compiler] {
2012 if [info exists compiler_info] {
2013 return $compiler_info
2015 perror "No compiler info found."
2019 return [string match $compiler $compiler_info]
2022 proc current_target_name { } {
2024 if [info exists target_info(target,name)] {
2025 set answer $target_info(target,name)
2032 set gdb_wrapper_initialized 0
2033 set gdb_wrapper_target ""
2035 proc gdb_wrapper_init { args } {
2036 global gdb_wrapper_initialized;
2037 global gdb_wrapper_file;
2038 global gdb_wrapper_flags;
2039 global gdb_wrapper_target
2041 if { $gdb_wrapper_initialized == 1 } { return; }
2043 if {[target_info exists needs_status_wrapper] && \
2044 [target_info needs_status_wrapper] != "0"} {
2045 set result [build_wrapper "testglue.o"];
2046 if { $result != "" } {
2047 set gdb_wrapper_file [lindex $result 0];
2048 set gdb_wrapper_flags [lindex $result 1];
2050 warning "Status wrapper failed to build."
2053 set gdb_wrapper_initialized 1
2054 set gdb_wrapper_target [current_target_name]
2057 # Some targets need to always link a special object in. Save its path here.
2058 global gdb_saved_set_unbuffered_mode_obj
2059 set gdb_saved_set_unbuffered_mode_obj ""
2061 proc gdb_compile {source dest type options} {
2062 global GDB_TESTCASE_OPTIONS;
2063 global gdb_wrapper_file;
2064 global gdb_wrapper_flags;
2065 global gdb_wrapper_initialized;
2068 global gdb_saved_set_unbuffered_mode_obj
2070 set outdir [file dirname $dest]
2072 # Add platform-specific options if a shared library was specified using
2073 # "shlib=librarypath" in OPTIONS.
2077 foreach opt $options {
2078 if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] {
2079 if [test_compiler_info "xlc-*"] {
2080 # IBM xlc compiler doesn't accept shared library named other
2081 # than .so: use "-Wl," to bypass this
2082 lappend source "-Wl,$shlib_name"
2083 } elseif { ([istarget "*-*-mingw*"]
2084 || [istarget *-*-cygwin*]
2085 || [istarget *-*-pe*])} {
2086 lappend source "${shlib_name}.a"
2088 lappend source $shlib_name
2090 if { $shlib_found == 0 } {
2092 if { ([istarget "*-*-mingw*"]
2093 || [istarget *-*-cygwin*]) } {
2094 lappend new_options "additional_flags=-Wl,--enable-auto-import"
2097 } elseif { $opt == "shlib_load" } {
2100 lappend new_options $opt
2104 # We typically link to shared libraries using an absolute path, and
2105 # that's how they are found at runtime. If we are going to
2106 # dynamically load one by basename, we must specify rpath. If we
2107 # are using a remote host, DejaGNU will link to the shared library
2108 # using a relative path, so again we must specify an rpath.
2109 if { $shlib_load || ($shlib_found && [is_remote host]) } {
2110 if { ([istarget "*-*-mingw*"]
2111 || [istarget *-*-cygwin*]
2112 || [istarget *-*-pe*]
2113 || [istarget hppa*-*-hpux*])} {
2114 # Do not need anything.
2115 } elseif { [istarget *-*-openbsd*] } {
2116 lappend new_options "ldflags=-Wl,-rpath,${outdir}"
2117 } elseif { [istarget arm*-*-symbianelf*] } {
2118 if { $shlib_load } {
2119 lappend new_options "libs=-ldl"
2122 if { $shlib_load } {
2123 lappend new_options "libs=-ldl"
2125 lappend new_options "ldflags=-Wl,-rpath,\\\$ORIGIN"
2128 set options $new_options
2130 if [target_info exists gdb_stub] {
2131 set options2 { "additional_flags=-Dusestubs" }
2132 lappend options "libs=[target_info gdb_stub]";
2133 set options [concat $options2 $options]
2135 if [target_info exists is_vxworks] {
2136 set options2 { "additional_flags=-Dvxworks" }
2137 lappend options "libs=[target_info gdb_stub]";
2138 set options [concat $options2 $options]
2140 if [info exists GDB_TESTCASE_OPTIONS] {
2141 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
2143 verbose "options are $options"
2144 verbose "source is $source $dest $type $options"
2146 if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init }
2148 if {[target_info exists needs_status_wrapper] && \
2149 [target_info needs_status_wrapper] != "0" && \
2150 [info exists gdb_wrapper_file]} {
2151 lappend options "libs=${gdb_wrapper_file}"
2152 lappend options "ldflags=${gdb_wrapper_flags}"
2155 # Replace the "nowarnings" option with the appropriate additional_flags
2156 # to disable compiler warnings.
2157 set nowarnings [lsearch -exact $options nowarnings]
2158 if {$nowarnings != -1} {
2159 if [target_info exists gdb,nowarnings_flag] {
2160 set flag "additional_flags=[target_info gdb,nowarnings_flag]"
2162 set flag "additional_flags=-w"
2164 set options [lreplace $options $nowarnings $nowarnings $flag]
2167 if { $type == "executable" } {
2168 if { ([istarget "*-*-mingw*"]
2169 || [istarget "*-*-*djgpp"]
2170 || [istarget "*-*-cygwin*"])} {
2171 # Force output to unbuffered mode, by linking in an object file
2172 # with a global contructor that calls setvbuf.
2174 # Compile the special object seperatelly for two reasons:
2175 # 1) Insulate it from $options.
2176 # 2) Avoid compiling it for every gdb_compile invocation,
2177 # which is time consuming, especially if we're remote
2180 if { $gdb_saved_set_unbuffered_mode_obj == "" } {
2181 verbose "compiling gdb_saved_set_unbuffered_obj"
2182 set unbuf_src ${srcdir}/lib/set_unbuffered_mode.c
2183 set unbuf_obj ${objdir}/set_unbuffered_mode.o
2185 set result [gdb_compile "${unbuf_src}" "${unbuf_obj}" object {nowarnings}]
2186 if { $result != "" } {
2190 set gdb_saved_set_unbuffered_mode_obj ${objdir}/set_unbuffered_mode_saved.o
2191 # Link a copy of the output object, because the
2192 # original may be automatically deleted.
2193 remote_exec host "cp -f $unbuf_obj $gdb_saved_set_unbuffered_mode_obj"
2195 verbose "gdb_saved_set_unbuffered_obj already compiled"
2198 # Rely on the internal knowledge that the global ctors are ran in
2199 # reverse link order. In that case, we can use ldflags to
2200 # avoid copying the object file to the host multiple
2202 # This object can only be added if standard libraries are
2203 # used. Thus, we need to disable it if -nostdlib option is used
2204 if {[lsearch -regexp $options "-nostdlib"] < 0 } {
2205 lappend options "ldflags=$gdb_saved_set_unbuffered_mode_obj"
2210 set result [target_compile $source $dest $type $options];
2212 # Prune uninteresting compiler (and linker) output.
2213 regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result
2215 regsub "\[\r\n\]*$" "$result" "" result;
2216 regsub "^\[\r\n\]*" "$result" "" result;
2218 if {[lsearch $options quiet] < 0} {
2219 # We shall update this on a per language basis, to avoid
2220 # changing the entire testsuite in one go.
2221 if {[lsearch $options f77] >= 0} {
2222 gdb_compile_test $source $result
2223 } elseif { $result != "" } {
2224 clone_output "gdb compile failed, $result"
2231 # This is just like gdb_compile, above, except that it tries compiling
2232 # against several different thread libraries, to see which one this
2234 proc gdb_compile_pthreads {source dest type options} {
2236 set why_msg "unrecognized error"
2237 foreach lib {-lpthreads -lpthread -lthread ""} {
2238 # This kind of wipes out whatever libs the caller may have
2239 # set. Or maybe theirs will override ours. How infelicitous.
2240 set options_with_lib [concat $options [list libs=$lib quiet]]
2241 set ccout [gdb_compile $source $dest $type $options_with_lib]
2242 switch -regexp -- $ccout {
2243 ".*no posix threads support.*" {
2244 set why_msg "missing threads include file"
2247 ".*cannot open -lpthread.*" {
2248 set why_msg "missing runtime threads library"
2250 ".*Can't find library for -lpthread.*" {
2251 set why_msg "missing runtime threads library"
2254 pass "successfully compiled posix threads test case"
2260 if {!$built_binfile} {
2261 unsupported "Couldn't compile $source: ${why_msg}"
2266 # Build a shared library from SOURCES. You must use get_compiler_info
2269 proc gdb_compile_shlib {sources dest options} {
2270 set obj_options $options
2272 switch -glob [test_compiler_info] {
2274 lappend obj_options "additional_flags=-qpic"
2277 if { !([istarget "powerpc*-*-aix*"]
2278 || [istarget "rs6000*-*-aix*"]
2279 || [istarget "*-*-cygwin*"]
2280 || [istarget "*-*-mingw*"]
2281 || [istarget "*-*-pe*"]) } {
2282 lappend obj_options "additional_flags=-fpic"
2286 switch -glob [istarget] {
2288 lappend obj_options "additional_flags=+z"
2291 # Disable SGI compiler's implicit -Dsgi
2292 lappend obj_options "additional_flags=-Usgi"
2295 # don't know what the compiler is...
2301 set outdir [file dirname $dest]
2303 foreach source $sources {
2304 set sourcebase [file tail $source]
2305 if {[gdb_compile $source "${outdir}/${sourcebase}.o" object $obj_options] != ""} {
2308 lappend objects ${outdir}/${sourcebase}.o
2311 if [istarget "hppa*-*-hpux*"] {
2312 remote_exec build "ld -b ${objects} -o ${dest}"
2314 set link_options $options
2315 if [test_compiler_info "xlc-*"] {
2316 lappend link_options "additional_flags=-qmkshrobj"
2318 lappend link_options "additional_flags=-shared"
2320 if { ([istarget "*-*-mingw*"]
2321 || [istarget *-*-cygwin*]
2322 || [istarget *-*-pe*])} {
2323 lappend link_options "additional_flags=-Wl,--out-implib,${dest}.a"
2326 if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
2332 # This is just like gdb_compile_pthreads, above, except that we always add the
2333 # objc library for compiling Objective-C programs
2334 proc gdb_compile_objc {source dest type options} {
2336 set why_msg "unrecognized error"
2337 foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} {
2338 # This kind of wipes out whatever libs the caller may have
2339 # set. Or maybe theirs will override ours. How infelicitous.
2340 if { $lib == "solaris" } {
2341 set lib "-lpthread -lposix4"
2343 if { $lib != "-lobjc" } {
2344 set lib "-lobjc $lib"
2346 set options_with_lib [concat $options [list libs=$lib quiet]]
2347 set ccout [gdb_compile $source $dest $type $options_with_lib]
2348 switch -regexp -- $ccout {
2349 ".*no posix threads support.*" {
2350 set why_msg "missing threads include file"
2353 ".*cannot open -lpthread.*" {
2354 set why_msg "missing runtime threads library"
2356 ".*Can't find library for -lpthread.*" {
2357 set why_msg "missing runtime threads library"
2360 pass "successfully compiled objc with posix threads test case"
2366 if {!$built_binfile} {
2367 unsupported "Couldn't compile $source: ${why_msg}"
2372 proc send_gdb { string } {
2373 global suppress_flag;
2374 if { $suppress_flag } {
2375 return "suppressed";
2377 return [remote_send host "$string"];
2383 proc gdb_expect { args } {
2384 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
2385 set atimeout [lindex $args 0];
2386 set expcode [list [lindex $args 1]];
2391 upvar timeout timeout;
2393 if [target_info exists gdb,timeout] {
2394 if [info exists timeout] {
2395 if { $timeout < [target_info gdb,timeout] } {
2396 set gtimeout [target_info gdb,timeout];
2398 set gtimeout $timeout;
2401 set gtimeout [target_info gdb,timeout];
2405 if ![info exists gtimeout] {
2407 if [info exists timeout] {
2408 set gtimeout $timeout;
2412 if [info exists atimeout] {
2413 if { ![info exists gtimeout] || $gtimeout < $atimeout } {
2414 set gtimeout $atimeout;
2417 if ![info exists gtimeout] {
2423 global suppress_flag;
2424 global remote_suppress_flag;
2425 if [info exists remote_suppress_flag] {
2426 set old_val $remote_suppress_flag;
2428 if [info exists suppress_flag] {
2429 if { $suppress_flag } {
2430 set remote_suppress_flag 1;
2434 {uplevel remote_expect host $gtimeout $expcode} string];
2435 if [info exists old_val] {
2436 set remote_suppress_flag $old_val;
2438 if [info exists remote_suppress_flag] {
2439 unset remote_suppress_flag;
2444 global errorInfo errorCode;
2446 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
2447 } elseif {$code == 2} {
2448 return -code return $string
2449 } elseif {$code == 3} {
2451 } elseif {$code > 4} {
2452 return -code $code $string
2456 # gdb_expect_list TEST SENTINEL LIST -- expect a sequence of outputs
2458 # Check for long sequence of output by parts.
2459 # TEST: is the test message to be printed with the test success/fail.
2460 # SENTINEL: Is the terminal pattern indicating that output has finished.
2461 # LIST: is the sequence of outputs to match.
2462 # If the sentinel is recognized early, it is considered an error.
2465 # 1 if the test failed,
2466 # 0 if the test passes,
2467 # -1 if there was an internal error.
2469 proc gdb_expect_list {test sentinel list} {
2471 global suppress_flag
2474 if { $suppress_flag } {
2476 unresolved "${test}"
2478 while { ${index} < [llength ${list}] } {
2479 set pattern [lindex ${list} ${index}]
2480 set index [expr ${index} + 1]
2481 verbose -log "gdb_expect_list pattern: /$pattern/" 2
2482 if { ${index} == [llength ${list}] } {
2485 -re "${pattern}${sentinel}" {
2486 # pass "${test}, pattern ${index} + sentinel"
2489 fail "${test} (pattern ${index} + sentinel)"
2492 -re ".*A problem internal to GDB has been detected" {
2493 fail "${test} (GDB internal error)"
2495 gdb_internal_error_resync
2498 fail "${test} (pattern ${index} + sentinel) (timeout)"
2503 # unresolved "${test}, pattern ${index} + sentinel"
2509 # pass "${test}, pattern ${index}"
2512 fail "${test} (pattern ${index})"
2515 -re ".*A problem internal to GDB has been detected" {
2516 fail "${test} (GDB internal error)"
2518 gdb_internal_error_resync
2521 fail "${test} (pattern ${index}) (timeout)"
2526 # unresolved "${test}, pattern ${index}"
2540 proc gdb_suppress_entire_file { reason } {
2541 global suppress_flag;
2543 warning "$reason\n";
2544 set suppress_flag -1;
2548 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
2549 # gdb_expect to fail immediately (until the next call to
2550 # gdb_stop_suppressing_tests).
2552 proc gdb_suppress_tests { args } {
2553 global suppress_flag;
2555 return; # fnf - disable pending review of results where
2556 # testsuite ran better without this
2559 if { $suppress_flag == 1 } {
2560 if { [llength $args] > 0 } {
2561 warning "[lindex $args 0]\n";
2563 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
2569 # Clear suppress_flag.
2571 proc gdb_stop_suppressing_tests { } {
2572 global suppress_flag;
2574 if [info exists suppress_flag] {
2575 if { $suppress_flag > 0 } {
2576 set suppress_flag 0;
2577 clone_output "Tests restarted.\n";
2580 set suppress_flag 0;
2584 proc gdb_clear_suppressed { } {
2585 global suppress_flag;
2587 set suppress_flag 0;
2590 proc gdb_start { } {
2595 catch default_gdb_exit
2599 # gdb_load_cmd -- load a file into the debugger.
2600 # ARGS - additional args to load command.
2601 # return a -1 if anything goes wrong.
2603 proc gdb_load_cmd { args } {
2606 if [target_info exists gdb_load_timeout] {
2607 set loadtimeout [target_info gdb_load_timeout]
2609 set loadtimeout 1600
2611 send_gdb "load $args\n"
2612 verbose "Timeout is now $loadtimeout seconds" 2
2613 gdb_expect $loadtimeout {
2614 -re "Loading section\[^\r\]*\r\n" {
2617 -re "Start address\[\r\]*\r\n" {
2620 -re "Transfer rate\[\r\]*\r\n" {
2623 -re "Memory access error\[^\r\]*\r\n" {
2624 perror "Failed to load program"
2627 -re "$gdb_prompt $" {
2630 -re "(.*)\r\n$gdb_prompt " {
2631 perror "Unexpected reponse from 'load' -- $expect_out(1,string)"
2635 perror "Timed out trying to load $args."
2642 # Return the filename to download to the target and load on the target
2643 # for this shared library. Normally just LIBNAME, unless shared libraries
2644 # for this target have separate link and load images.
2646 proc shlib_target_file { libname } {
2650 # Return the filename GDB will load symbols from when debugging this
2651 # shared library. Normally just LIBNAME, unless shared libraries for
2652 # this target have separate link and load images.
2654 proc shlib_symbol_file { libname } {
2660 # Copy a file to the remote target and return its target filename.
2661 # Schedule the file to be deleted at the end of this test.
2663 proc gdb_download { filename } {
2666 set destname [remote_download target $filename]
2667 lappend cleanfiles $destname
2671 # gdb_load_shlibs LIB...
2673 # Copy the listed libraries to the target.
2675 proc gdb_load_shlibs { args } {
2676 if {![is_remote target]} {
2680 foreach file $args {
2681 gdb_download [shlib_target_file $file]
2684 # Even if the target supplies full paths for shared libraries,
2685 # they may not be paths for this system.
2686 gdb_test "set solib-search-path [file dirname [lindex $args 0]]" "" ""
2690 # gdb_load -- load a file into the debugger.
2691 # Many files in config/*.exp override this procedure.
2693 proc gdb_load { arg } {
2694 return [gdb_file_cmd $arg]
2697 # gdb_reload -- load a file into the target. Called before "running",
2698 # either the first time or after already starting the program once,
2699 # for remote targets. Most files that override gdb_load should now
2700 # override this instead.
2702 proc gdb_reload { } {
2703 # For the benefit of existing configurations, default to gdb_load.
2704 # Specifying no file defaults to the executable currently being
2706 return [gdb_load ""]
2709 proc gdb_continue { function } {
2712 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
2715 proc default_gdb_init { args } {
2716 global gdb_wrapper_initialized
2717 global gdb_wrapper_target
2722 gdb_clear_suppressed;
2724 # Make sure that the wrapper is rebuilt
2725 # with the appropriate multilib option.
2726 if { $gdb_wrapper_target != [current_target_name] } {
2727 set gdb_wrapper_initialized 0
2730 # Unlike most tests, we have a small number of tests that generate
2731 # a very large amount of output. We therefore increase the expect
2732 # buffer size to be able to contain the entire test output.
2734 # Also set this value for the currently running GDB.
2735 match_max [match_max -d]
2737 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
2738 if { [llength $args] > 0 } {
2741 set file [lindex $args 0];
2743 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
2746 if [target_info exists gdb_prompt] {
2747 set gdb_prompt [target_info gdb_prompt];
2749 set gdb_prompt "\\(gdb\\)"
2753 # The default timeout used when testing GDB commands. We want to use
2754 # the same timeout as the default dejagnu timeout, unless the user has
2755 # already provided a specific value (probably through a site.exp file).
2756 global gdb_test_timeout
2757 if ![info exists gdb_test_timeout] {
2758 set gdb_test_timeout $timeout
2761 # A list of global variables that GDB testcases should not use.
2762 # We try to prevent their use by monitoring write accesses and raising
2763 # an error when that happens.
2764 set banned_variables { bug_id prms_id }
2766 # gdb_init is called by runtest at start, but also by several
2767 # tests directly; gdb_finish is only called from within runtest after
2768 # each test source execution.
2769 # Placing several traces by repetitive calls to gdb_init leads
2770 # to problems, as only one trace is removed in gdb_finish.
2771 # To overcome this possible problem, we add a variable that records
2772 # if the banned variables are traced.
2773 set banned_variables_traced 0
2775 proc gdb_init { args } {
2776 # Reset the timeout value to the default. This way, any testcase
2777 # that changes the timeout value without resetting it cannot affect
2778 # the timeout used in subsequent testcases.
2779 global gdb_test_timeout
2781 set timeout $gdb_test_timeout
2783 # Block writes to all banned variables...
2784 global banned_variables
2785 global banned_variables_traced
2786 if (!$banned_variables_traced) {
2787 foreach banned_var $banned_variables {
2788 global "$banned_var"
2789 trace add variable "$banned_var" write error
2791 set banned_variables_traced 1
2794 # We set LC_ALL and LANG to C so that we get the same messages as
2799 return [eval default_gdb_init $args];
2802 proc gdb_finish { } {
2805 # Exit first, so that the files are no longer in use.
2808 if { [llength $cleanfiles] > 0 } {
2809 eval remote_file target delete $cleanfiles
2813 # Unblock write access to the banned variables. Dejagnu typically
2814 # resets some of them between testcases.
2815 global banned_variables
2816 global banned_variables_traced
2817 if ($banned_variables_traced) {
2818 foreach banned_var $banned_variables {
2819 global "$banned_var"
2820 trace remove variable "$banned_var" write error
2822 set banned_variables_traced 0
2827 set debug_format "unknown"
2829 # Run the gdb command "info source" and extract the debugging format
2830 # information from the output and save it in debug_format.
2832 proc get_debug_format { } {
2838 set debug_format "unknown"
2839 send_gdb "info source\n"
2841 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
2842 set debug_format $expect_out(1,string)
2843 verbose "debug format is $debug_format"
2846 -re "No current source file.\r\n$gdb_prompt $" {
2847 perror "get_debug_format used when no current source file"
2850 -re "$gdb_prompt $" {
2851 warning "couldn't check debug format (no valid response)."
2855 warning "couldn't check debug format (timed out)."
2861 # Return true if FORMAT matches the debug format the current test was
2862 # compiled with. FORMAT is a shell-style globbing pattern; it can use
2863 # `*', `[...]', and so on.
2865 # This function depends on variables set by `get_debug_format', above.
2867 proc test_debug_format {format} {
2870 return [expr [string match $format $debug_format] != 0]
2873 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
2874 # COFF, stabs, etc). If that format matches the format that the
2875 # current test was compiled with, then the next test is expected to
2876 # fail for any target. Returns 1 if the next test or set of tests is
2877 # expected to fail, 0 otherwise (or if it is unknown). Must have
2878 # previously called get_debug_format.
2879 proc setup_xfail_format { format } {
2880 set ret [test_debug_format $format];
2888 proc gdb_step_for_stub { } {
2891 if ![target_info exists gdb,use_breakpoint_for_stub] {
2892 if [target_info exists gdb_stub_step_command] {
2893 set command [target_info gdb_stub_step_command];
2897 send_gdb "${command}\n";
2900 -re "(main.* at |.*in .*start).*$gdb_prompt" {
2903 -re ".*$gdb_prompt" {
2905 if { $tries == 5 } {
2906 fail "stepping out of breakpoint function";
2909 send_gdb "${command}\n";
2913 fail "stepping out of breakpoint function";
2920 -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" {
2921 set file $expect_out(1,string);
2922 set linenum [expr $expect_out(2,string) + 1];
2923 set breakplace "${file}:${linenum}";
2927 send_gdb "break ${breakplace}\n";
2929 -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" {
2930 set breakpoint $expect_out(1,string);
2932 -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" {
2933 set breakpoint $expect_out(1,string);
2937 send_gdb "continue\n";
2939 -re "Breakpoint ${breakpoint},.*$gdb_prompt" {
2940 gdb_test "delete $breakpoint" ".*" "";
2947 # gdb_get_line_number TEXT [FILE]
2949 # Search the source file FILE, and return the line number of the
2950 # first line containing TEXT. If no match is found, return -1.
2952 # TEXT is a string literal, not a regular expression.
2954 # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is
2955 # specified, and does not start with "/", then it is assumed to be in
2956 # "$srcdir/$subdir". This is awkward, and can be fixed in the future,
2957 # by changing the callers and the interface at the same time.
2958 # In particular: gdb.base/break.exp, gdb.base/condbreak.exp,
2959 # gdb.base/ena-dis-br.exp.
2961 # Use this function to keep your test scripts independent of the
2962 # exact line numbering of the source file. Don't write:
2964 # send_gdb "break 20"
2966 # This means that if anyone ever edits your test's source file,
2967 # your test could break. Instead, put a comment like this on the
2968 # source file line you want to break at:
2970 # /* breakpoint spot: frotz.exp: test name */
2972 # and then write, in your test script (which we assume is named
2975 # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
2977 # (Yes, Tcl knows how to handle the nested quotes and brackets.
2980 # % puts "foo [lindex "bar baz" 1]"
2983 # Tcl is quite clever, for a little stringy language.)
2987 # The previous implementation of this procedure used the gdb search command.
2988 # This version is different:
2990 # . It works with MI, and it also works when gdb is not running.
2992 # . It operates on the build machine, not the host machine.
2994 # . For now, this implementation fakes a current directory of
2995 # $srcdir/$subdir to be compatible with the old implementation.
2996 # This will go away eventually and some callers will need to
2999 # . The TEXT argument is literal text and matches literally,
3000 # not a regular expression as it was before.
3002 # . State changes in gdb, such as changing the current file
3003 # and setting $_, no longer happen.
3005 # After a bit of time we can forget about the differences from the
3006 # old implementation.
3008 # --chastain 2004-08-05
3010 proc gdb_get_line_number { text { file "" } } {
3015 if { "$file" == "" } then {
3018 if { ! [regexp "^/" "$file"] } then {
3019 set file "$srcdir/$subdir/$file"
3022 if { [ catch { set fd [open "$file"] } message ] } then {
3028 for { set line 1 } { 1 } { incr line } {
3029 if { [ catch { set nchar [gets "$fd" body] } message ] } then {
3033 if { $nchar < 0 } then {
3036 if { [string first "$text" "$body"] >= 0 } then {
3042 if { [ catch { close "$fd" } message ] } then {
3050 # gdb_continue_to_end:
3051 # The case where the target uses stubs has to be handled specially. If a
3052 # stub is used, we set a breakpoint at exit because we cannot rely on
3053 # exit() behavior of a remote target.
3055 # mssg is the error message that gets printed.
3057 proc gdb_continue_to_end {mssg} {
3058 if [target_info exists use_gdb_stub] {
3059 if {![gdb_breakpoint "exit"]} {
3062 gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \
3063 "continue until exit at $mssg"
3065 # Continue until we exit. Should not stop again.
3066 # Don't bother to check the output of the program, that may be
3067 # extremely tough for some remote systems.
3068 gdb_test "continue"\
3069 "Continuing.\[\r\n0-9\]+(... EXIT code 0\[\r\n\]+|Program exited normally\\.).*"\
3070 "continue until exit at $mssg"
3074 proc rerun_to_main {} {
3077 if [target_info exists use_gdb_stub] {
3080 -re ".*Breakpoint .*main .*$gdb_prompt $"\
3081 {pass "rerun to main" ; return 0}
3082 -re "$gdb_prompt $"\
3083 {fail "rerun to main" ; return 0}
3084 timeout {fail "(timeout) rerun to main" ; return 0}
3089 -re "The program .* has been started already.*y or n. $" {
3093 -re "Starting program.*$gdb_prompt $"\
3094 {pass "rerun to main" ; return 0}
3095 -re "$gdb_prompt $"\
3096 {fail "rerun to main" ; return 0}
3097 timeout {fail "(timeout) rerun to main" ; return 0}
3102 # Print a message and return true if a test should be skipped
3103 # due to lack of floating point suport.
3105 proc gdb_skip_float_test { msg } {
3106 if [target_info exists gdb,skip_float_tests] {
3107 verbose "Skipping test '$msg': no float tests.";
3113 # Print a message and return true if a test should be skipped
3114 # due to lack of stdio support.
3116 proc gdb_skip_stdio_test { msg } {
3117 if [target_info exists gdb,noinferiorio] {
3118 verbose "Skipping test '$msg': no inferior i/o.";
3124 proc gdb_skip_bogus_test { msg } {
3128 # Return true if a test should be skipped due to lack of XML support
3130 # NOTE: This must be called while gdb is *not* running.
3132 proc gdb_skip_xml_test { } {
3135 global xml_missing_cached
3137 if {[info exists xml_missing_cached]} {
3138 return $xml_missing_cached
3142 set xml_missing_cached 0
3143 gdb_test_multiple "set tdesc filename ${srcdir}/gdb.xml/trivial.xml" "" {
3144 -re ".*XML support was disabled at compile time.*$gdb_prompt $" {
3145 set xml_missing_cached 1
3147 -re ".*$gdb_prompt $" { }
3150 return $xml_missing_cached
3153 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
3154 # ${binfile}.dbglnk, which is just like the executable ($binfile) but without
3155 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
3156 # the name of a debuginfo only file. This file will be stored in the same
3159 # Functions for separate debug info testing
3161 # starting with an executable:
3162 # foo --> original executable
3164 # at the end of the process we have:
3165 # foo.stripped --> foo w/o debug info
3166 # foo.debug --> foo's debug info
3167 # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug.
3169 # Return the build-id hex string (usually 160 bits as 40 hex characters)
3170 # converted to the form: .build-id/ab/cdef1234...89.debug
3171 # Return "" if no build-id found.
3172 proc build_id_debug_filename_get { exec } {
3173 set tmp "${exec}-tmp"
3174 set objcopy_program [transform objcopy]
3176 set result [catch "exec $objcopy_program -j .note.gnu.build-id -O binary $exec $tmp" output]
3177 verbose "result is $result"
3178 verbose "output is $output"
3183 fconfigure $fi -translation binary
3184 # Skip the NOTE header.
3189 if ![string compare $data ""] then {
3192 # Convert it to hex.
3193 binary scan $data H* data
3194 regsub {^..} $data {\0/} data
3195 return ".build-id/${data}.debug";
3198 # Create stripped files for DEST, replacing it. If ARGS is passed, it is a
3199 # list of optional flags. The only currently supported flag is no-main,
3200 # which removes the symbol entry for main from the separate debug file.
3202 # Function returns zero on success. Function will return non-zero failure code
3203 # on some targets not supporting separate debug info (such as i386-msdos).
3205 proc gdb_gnu_strip_debug { dest args } {
3207 # Use the first separate debug info file location searched by GDB so the
3208 # run cannot be broken by some stale file searched with higher precedence.
3209 set debug_file "${dest}.debug"
3211 set strip_to_file_program [transform strip]
3212 set objcopy_program [transform objcopy]
3214 set debug_link [file tail $debug_file]
3215 set stripped_file "${dest}.stripped"
3217 # Get rid of the debug info, and store result in stripped_file
3218 # something like gdb/testsuite/gdb.base/blah.stripped.
3219 set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
3220 verbose "result is $result"
3221 verbose "output is $output"
3226 # Workaround PR binutils/10802:
3227 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
3228 set perm [file attributes ${dest} -permissions]
3229 file attributes ${stripped_file} -permissions $perm
3231 # Get rid of everything but the debug info, and store result in debug_file
3232 # This will be in the .debug subdirectory, see above.
3233 set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
3234 verbose "result is $result"
3235 verbose "output is $output"
3240 # If no-main is passed, strip the symbol for main from the separate
3241 # file. This is to simulate the behavior of elfutils's eu-strip, which
3242 # leaves the symtab in the original file only. There's no way to get
3243 # objcopy or strip to remove the symbol table without also removing the
3244 # debugging sections, so this is as close as we can get.
3245 if { [llength $args] == 1 && [lindex $args 0] == "no-main" } {
3246 set result [catch "exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp" output]
3247 verbose "result is $result"
3248 verbose "output is $output"
3252 file delete "${debug_file}"
3253 file rename "${debug_file}-tmp" "${debug_file}"
3256 # Link the two previous output files together, adding the .gnu_debuglink
3257 # section to the stripped_file, containing a pointer to the debug_file,
3258 # save the new file in dest.
3259 # This will be the regular executable filename, in the usual location.
3260 set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
3261 verbose "result is $result"
3262 verbose "output is $output"
3267 # Workaround PR binutils/10802:
3268 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
3269 set perm [file attributes ${stripped_file} -permissions]
3270 file attributes ${dest} -permissions $perm
3275 # Test the output of GDB_COMMAND matches the pattern obtained
3276 # by concatenating all elements of EXPECTED_LINES. This makes
3277 # it possible to split otherwise very long string into pieces.
3278 # If third argument is not empty, it's used as the name of the
3279 # test to be printed on pass/fail.
3280 proc help_test_raw { gdb_command expected_lines args } {
3281 set message $gdb_command
3282 if [llength $args]>0 then {
3283 set message [lindex $args 0]
3285 set expected_output [join $expected_lines ""]
3286 gdb_test "${gdb_command}" "${expected_output}" $message
3289 # Test the output of "help COMMNAD_CLASS". EXPECTED_INITIAL_LINES
3290 # are regular expressions that should match the beginning of output,
3291 # before the list of commands in that class. The presence of
3292 # command list and standard epilogue will be tested automatically.
3293 proc test_class_help { command_class expected_initial_lines args } {
3295 "List of commands\:.*\[\r\n\]+"
3296 "Type \"help\" followed by command name for full documentation\.\[\r\n\]+"
3297 "Type \"apropos word\" to search for commands related to \"word\"\.[\r\n\]+"
3298 "Command name abbreviations are allowed if unambiguous\."
3300 set l_entire_body [concat $expected_initial_lines $l_stock_body]
3302 eval [list help_test_raw "help ${command_class}" $l_entire_body] $args
3305 # COMMAND_LIST should have either one element -- command to test, or
3306 # two elements -- abbreviated command to test, and full command the first
3307 # element is abbreviation of.
3308 # The command must be a prefix command. EXPECTED_INITIAL_LINES
3309 # are regular expressions that should match the beginning of output,
3310 # before the list of subcommands. The presence of
3311 # subcommand list and standard epilogue will be tested automatically.
3312 proc test_prefix_command_help { command_list expected_initial_lines args } {
3313 set command [lindex $command_list 0]
3314 if {[llength $command_list]>1} {
3315 set full_command [lindex $command_list 1]
3317 set full_command $command
3319 # Use 'list' and not just {} because we want variables to
3320 # be expanded in this list.
3321 set l_stock_body [list\
3322 "List of $full_command subcommands\:.*\[\r\n\]+"\
3323 "Type \"help $full_command\" followed by $full_command subcommand name for full documentation\.\[\r\n\]+"\
3324 "Type \"apropos word\" to search for commands related to \"word\"\.\[\r\n\]+"\
3325 "Command name abbreviations are allowed if unambiguous\."]
3326 set l_entire_body [concat $expected_initial_lines $l_stock_body]
3327 if {[llength $args]>0} {
3328 help_test_raw "help ${command}" $l_entire_body [lindex $args 0]
3330 help_test_raw "help ${command}" $l_entire_body
3334 # Build executable named EXECUTABLE, from SOURCES. If SOURCES are not
3335 # provided, uses $EXECUTABLE.c. The TESTNAME paramer is the name of test
3336 # to pass to untested, if something is wrong. OPTIONS are passed
3337 # to gdb_compile directly.
3338 proc build_executable { testname executable {sources ""} {options {debug}} } {
3343 if {[llength $sources]==0} {
3344 set sources ${executable}.c
3347 set binfile ${objdir}/${subdir}/${executable}
3350 for {set i 0} "\$i<[llength $sources]" {incr i} {
3351 set s [lindex $sources $i]
3352 if { [gdb_compile "${srcdir}/${subdir}/${s}" "${binfile}${i}.o" object $options] != "" } {
3356 lappend objects "${binfile}${i}.o"
3359 if { [gdb_compile $objects "${binfile}" executable $options] != "" } {
3365 if { [lsearch -exact $options "c++"] >= 0 } {
3366 set info_options "c++"
3368 if [get_compiler_info ${binfile} ${info_options}] {
3374 # Starts fresh GDB binary and loads EXECUTABLE into GDB. EXECUTABLE is
3375 # the name of binary in ${objdir}/${subdir}.
3376 proc clean_restart { executable } {
3380 set binfile ${objdir}/${subdir}/${executable}
3384 gdb_reinitialize_dir $srcdir/$subdir
3387 if [target_info exists gdb_stub] {
3392 # Prepares for testing, by calling build_executable, and then clean_restart.
3393 # Please refer to build_executable for parameter description.
3394 proc prepare_for_testing { testname executable {sources ""} {options {debug}}} {
3396 if {[build_executable $testname $executable $sources $options] == -1} {
3399 clean_restart $executable
3404 proc get_valueof { fmt exp default } {
3407 set test "get valueof \"${exp}\""
3409 gdb_test_multiple "print${fmt} ${exp}" "$test" {
3410 -re "\\$\[0-9\]* = (.*)\[\r\n\]*$gdb_prompt $" {
3411 set val $expect_out(1,string)
3415 fail "$test (timeout)"
3421 proc get_integer_valueof { exp default } {
3424 set test "get integer valueof \"${exp}\""
3426 gdb_test_multiple "print /d ${exp}" "$test" {
3427 -re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" {
3428 set val $expect_out(1,string)
3432 fail "$test (timeout)"
3438 proc get_hexadecimal_valueof { exp default } {
3440 send_gdb "print /x ${exp}\n"
3441 set test "get hexadecimal valueof \"${exp}\""
3443 -re "\\$\[0-9\]* = (0x\[0-9a-zA-Z\]+).*$gdb_prompt $" {
3444 set val $expect_out(1,string)
3449 fail "$test (timeout)"
3455 proc get_sizeof { type default } {
3456 return [get_integer_valueof "sizeof (${type})" $default]
3459 # Log gdb command line and script if requested.
3460 if {[info exists TRANSCRIPT]} {
3461 rename send_gdb real_send_gdb
3462 rename remote_spawn real_remote_spawn
3463 rename remote_close real_remote_close
3465 global gdb_transcript
3466 set gdb_transcript ""
3468 global gdb_trans_count
3469 set gdb_trans_count 1
3471 proc remote_spawn {args} {
3472 global gdb_transcript gdb_trans_count outdir
3474 if {$gdb_transcript != ""} {
3475 close $gdb_transcript
3477 set gdb_transcript [open [file join $outdir transcript.$gdb_trans_count] w]
3478 puts $gdb_transcript [lindex $args 1]
3479 incr gdb_trans_count
3481 return [uplevel real_remote_spawn $args]
3484 proc remote_close {args} {
3485 global gdb_transcript
3487 if {$gdb_transcript != ""} {
3488 close $gdb_transcript
3489 set gdb_transcript ""
3492 return [uplevel real_remote_close $args]
3495 proc send_gdb {args} {
3496 global gdb_transcript
3498 if {$gdb_transcript != ""} {
3499 puts -nonewline $gdb_transcript [lindex $args 0]
3502 return [uplevel real_send_gdb $args]
3506 proc core_find {binfile {deletefiles {}} {arg ""}} {
3507 global objdir subdir
3509 set destcore "$binfile.core"
3510 file delete $destcore
3512 # Create a core file named "$destcore" rather than just "core", to
3513 # avoid problems with sys admin types that like to regularly prune all
3514 # files named "core" from the system.
3516 # Arbitrarily try setting the core size limit to "unlimited" since
3517 # this does not hurt on systems where the command does not work and
3518 # allows us to generate a core on systems where it does.
3520 # Some systems append "core" to the name of the program; others append
3521 # the name of the program to "core"; still others (like Linux, as of
3522 # May 2003) create cores named "core.PID". In the latter case, we
3523 # could have many core files lying around, and it may be difficult to
3524 # tell which one is ours, so let's run the program in a subdirectory.
3526 set coredir "${objdir}/${subdir}/coredir.[getpid]"
3528 catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile} ${arg}; true) >/dev/null 2>&1\""
3529 # remote_exec host "${binfile}"
3530 foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
3531 if [remote_file build exists $i] {
3532 remote_exec build "mv $i $destcore"
3536 # Check for "core.PID".
3537 if { $found == 0 } {
3538 set names [glob -nocomplain -directory $coredir core.*]
3539 if {[llength $names] == 1} {
3540 set corefile [file join $coredir [lindex $names 0]]
3541 remote_exec build "mv $corefile $destcore"
3545 if { $found == 0 } {
3546 # The braindamaged HPUX shell quits after the ulimit -c above
3547 # without executing ${binfile}. So we try again without the
3548 # ulimit here if we didn't find a core file above.
3549 # Oh, I should mention that any "braindamaged" non-Unix system has
3550 # the same problem. I like the cd bit too, it's really neat'n stuff.
3551 catch "system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\""
3552 foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" {
3553 if [remote_file build exists $i] {
3554 remote_exec build "mv $i $destcore"
3560 # Try to clean up after ourselves.
3561 foreach deletefile $deletefiles {
3562 remote_file build delete [file join $coredir $deletefile]
3564 remote_exec build "rmdir $coredir"
3566 if { $found == 0 } {
3567 warning "can't generate a core file - core tests suppressed - check ulimit -c"