1 # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
2 # 2003, 2004, 2005, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # This file was written by Fred Fish. (fnf@cygnus.com)
19 # Generic gdb subroutines that should work for any target. If these
20 # need to be modified for any target, it can be done with a variable
21 # or by passing arguments.
24 # Tests would fail, logs on get_compiler_info() would be missing.
25 send_error "`site.exp' not found, run `make site.exp'!\n"
33 if [info exists TOOL_EXECUTABLE] {
34 set GDB $TOOL_EXECUTABLE;
36 if ![info exists GDB] {
37 if ![is_remote host] {
38 set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]]
40 set GDB [transform gdb];
43 verbose "using GDB = $GDB" 2
45 # GDBFLAGS is available for the user to set on the command line.
46 # E.g. make check RUNTESTFLAGS=GDBFLAGS=mumble
47 # Testcases may use it to add additional flags, but they must:
48 # - append new flags, not overwrite
49 # - restore the original value when done
51 if ![info exists GDBFLAGS] {
54 verbose "using GDBFLAGS = $GDBFLAGS" 2
56 # INTERNAL_GDBFLAGS contains flags that the testsuite requires.
57 global INTERNAL_GDBFLAGS
58 if ![info exists INTERNAL_GDBFLAGS] {
59 set INTERNAL_GDBFLAGS "-nw -nx"
62 # The variable gdb_prompt is a regexp which matches the gdb prompt.
63 # Set it if it is not already set.
65 if ![info exists gdb_prompt] then {
66 set gdb_prompt "\[(\]gdb\[)\]"
69 # The variable fullname_syntax_POSIX is a regexp which matches a POSIX
70 # absolute path ie. /foo/
71 set fullname_syntax_POSIX {/[^\n]*/}
72 # The variable fullname_syntax_UNC is a regexp which matches a Windows
73 # UNC path ie. \\D\foo\
74 set fullname_syntax_UNC {\\\\[^\\]+\\[^\n]+\\}
75 # The variable fullname_syntax_DOS_CASE is a regexp which matches a
76 # particular DOS case that GDB most likely will output
77 # ie. \foo\, but don't match \\.*\
78 set fullname_syntax_DOS_CASE {\\[^\\][^\n]*\\}
79 # The variable fullname_syntax_DOS is a regexp which matches a DOS path
80 # ie. a:\foo\ && a:foo\
81 set fullname_syntax_DOS {[a-zA-Z]:[^\n]*\\}
82 # The variable fullname_syntax is a regexp which matches what GDB considers
83 # an absolute path. It is currently debatable if the Windows style paths
84 # d:foo and \abc should be considered valid as an absolute path.
85 # Also, the purpse of this regexp is not to recognize a well formed
86 # absolute path, but to say with certainty that a path is absolute.
87 set fullname_syntax "($fullname_syntax_POSIX|$fullname_syntax_UNC|$fullname_syntax_DOS_CASE|$fullname_syntax_DOS)"
89 # Needed for some tests under Cygwin.
93 if ![info exists env(EXEEXT)] {
96 set EXEEXT $env(EXEEXT)
101 ### Only procedures should come after this point.
104 # gdb_version -- extract and print the version number of GDB
106 proc default_gdb_version {} {
108 global INTERNAL_GDBFLAGS GDBFLAGS
110 set output [remote_exec host "$GDB $INTERNAL_GDBFLAGS --version"]
111 set tmp [lindex $output 1];
113 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
114 if ![is_remote host] {
115 clone_output "[which $GDB] version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
117 clone_output "$GDB on remote host version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n"
121 proc gdb_version { } {
122 return [default_gdb_version];
126 # gdb_unload -- unload a file if one is loaded
135 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
136 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
137 -re "A program is being debugged already..*Kill it.*y or n. $"\
139 verbose "\t\tKilling previous program being debugged"
142 -re "Discard symbol table from .*y or n.*$" {
146 -re "$gdb_prompt $" {}
148 perror "couldn't unload file in $GDB (timed out)."
154 # Many of the tests depend on setting breakpoints at various places and
155 # running until that breakpoint is reached. At times, we want to start
156 # with a clean-slate with respect to breakpoints, so this utility proc
157 # lets us do this without duplicating this code everywhere.
160 proc delete_breakpoints {} {
163 # we need a larger timeout value here or this thing just confuses
164 # itself. May need a better implementation if possible. - guo
166 send_gdb "delete breakpoints\n"
168 -re "Delete all breakpoints.*y or n.*$" {
172 -re "$gdb_prompt $" { # This happens if there were no breakpoints
174 timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
176 send_gdb "info breakpoints\n"
178 -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
179 -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
180 -re "Delete all breakpoints.*or n.*$" {
184 timeout { perror "info breakpoints (timeout)" ; return }
190 # Generic run command.
192 # The second pattern below matches up to the first newline *only*.
193 # Using ``.*$'' could swallow up output that we attempt to match
196 proc gdb_run_cmd {args} {
199 if [target_info exists gdb_init_command] {
200 send_gdb "[target_info gdb_init_command]\n";
202 -re "$gdb_prompt $" { }
204 perror "gdb_init_command for target failed";
210 if [target_info exists use_gdb_stub] {
211 if [target_info exists gdb,do_reload_on_run] {
212 if { [gdb_reload] != 0 } {
215 send_gdb "continue\n";
217 -re "Continu\[^\r\n\]*\[\r\n\]" {}
223 if [target_info exists gdb,start_symbol] {
224 set start [target_info gdb,start_symbol];
228 send_gdb "jump *$start\n"
230 while { $start_attempt } {
231 # Cap (re)start attempts at three to ensure that this loop
232 # always eventually fails. Don't worry about trying to be
233 # clever and not send a command when it has failed.
234 if [expr $start_attempt > 3] {
235 perror "Jump to start() failed (retry count exceeded)";
238 set start_attempt [expr $start_attempt + 1];
240 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
243 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
244 perror "Can't find start symbol to run in gdb_run";
247 -re "No symbol \"start\" in current.*$gdb_prompt $" {
248 send_gdb "jump *_start\n";
250 -re "No symbol.*context.*$gdb_prompt $" {
253 -re "Line.* Jump anyway.*y or n. $" {
256 -re "The program is not being run.*$gdb_prompt $" {
257 if { [gdb_reload] != 0 } {
260 send_gdb "jump *$start\n";
263 perror "Jump to start() failed (timeout)";
268 if [target_info exists gdb_stub] {
270 -re "$gdb_prompt $" {
271 send_gdb "continue\n"
278 if [target_info exists gdb,do_reload_on_run] {
279 if { [gdb_reload] != 0 } {
283 send_gdb "run $args\n"
284 # This doesn't work quite right yet.
285 # Use -notransfer here so that test cases (like chng-sym.exp)
286 # may test for additional start-up messages.
288 -re "The program .* has been started already.*y or n. $" {
292 -notransfer -re "Starting program: \[^\r\n\]*" {}
296 # Generic start command. Return 0 if we could start the program, -1
299 proc gdb_start_cmd {args} {
302 if [target_info exists gdb_init_command] {
303 send_gdb "[target_info gdb_init_command]\n";
305 -re "$gdb_prompt $" { }
307 perror "gdb_init_command for target failed";
313 if [target_info exists use_gdb_stub] {
317 send_gdb "start $args\n"
318 # Use -notransfer here so that test cases (like chng-sym.exp)
319 # may test for additional start-up messages.
321 -re "The program .* has been started already.*y or n. $" {
325 -notransfer -re "Starting program: \[^\r\n\]*" {
332 # Set a breakpoint at FUNCTION. If there is an additional argument it is
333 # a list of options; the supported options are allow-pending, temporary,
336 proc gdb_breakpoint { function args } {
340 set pending_response n
341 if {[lsearch -exact [lindex $args 0] allow-pending] != -1} {
342 set pending_response y
345 set break_command "break"
346 set break_message "Breakpoint"
347 if {[lsearch -exact [lindex $args 0] temporary] != -1} {
348 set break_command "tbreak"
349 set break_message "Temporary breakpoint"
353 if {[lsearch -exact [lindex $args 0] no-message] != -1} {
357 send_gdb "$break_command $function\n"
358 # The first two regexps are what we get with -g, the third is without -g.
360 -re "$break_message \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
361 -re "$break_message \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
362 -re "$break_message \[0-9\]* at .*$gdb_prompt $" {}
363 -re "$break_message \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" {
364 if {$pending_response == "n"} {
365 if { $no_message == 0 } {
366 fail "setting breakpoint at $function"
371 -re "Make breakpoint pending.*y or \\\[n\\\]. $" {
372 send_gdb "$pending_response\n"
375 -re "$gdb_prompt $" {
376 if { $no_message == 0 } {
377 fail "setting breakpoint at $function"
382 if { $no_message == 0 } {
383 fail "setting breakpoint at $function (timeout)"
391 # Set breakpoint at function and run gdb until it breaks there.
392 # Since this is the only breakpoint that will be set, if it stops
393 # at a breakpoint, we will assume it is the one we want. We can't
394 # just compare to "function" because it might be a fully qualified,
395 # single quoted C++ function specifier. If there's an additional argument,
396 # pass it to gdb_breakpoint.
398 proc runto { function args } {
404 if ![gdb_breakpoint $function [lindex $args 0]] {
410 # the "at foo.c:36" output we get with -g.
411 # the "in func" output we get without -g.
413 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
416 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
419 -re "$gdb_prompt $" {
420 fail "running to $function in runto"
424 fail "running to $function in runto (end of file)"
428 fail "running to $function in runto (timeout)"
436 # runto_main -- ask gdb to run until we hit a breakpoint at main.
437 # The case where the target uses stubs has to be handled
438 # specially--if it uses stubs, assuming we hit
439 # breakpoint() and just step out of the function.
441 proc runto_main { } {
445 if ![target_info exists gdb_stub] {
457 ### Continue, and expect to hit a breakpoint.
458 ### Report a pass or fail, depending on whether it seems to have
459 ### worked. Use NAME as part of the test name; each call to
460 ### continue_to_breakpoint should use a NAME which is unique within
462 proc gdb_continue_to_breakpoint {name {location_pattern .*}} {
464 set full_name "continue to breakpoint: $name"
466 send_gdb "continue\n"
468 -re "Breakpoint .* (at|in) $location_pattern\r\n$gdb_prompt $" {
471 -re ".*$gdb_prompt $" {
475 fail "$full_name (timeout)"
481 # gdb_internal_error_resync:
483 # Answer the questions GDB asks after it reports an internal error
484 # until we get back to a GDB prompt. Decline to quit the debugging
485 # session, and decline to create a core file. Return non-zero if the
488 # This procedure just answers whatever questions come up until it sees
489 # a GDB prompt; it doesn't require you to have matched the input up to
490 # any specific point. However, it only answers questions it sees in
491 # the output itself, so if you've matched a question, you had better
492 # answer it yourself before calling this.
494 # You can use this function thus:
498 # -re ".*A problem internal to GDB has been detected" {
499 # gdb_internal_error_resync
504 proc gdb_internal_error_resync {} {
508 while {$count < 10} {
510 -re "Quit this debugging session\\? \\(y or n\\) $" {
514 -re "Create a core file of GDB\\? \\(y or n\\) $" {
518 -re "$gdb_prompt $" {
519 # We're resynchronized.
523 perror "Could not resync from internal error (timeout)"
528 perror "Could not resync from internal error (resync count exceeded)"
533 # gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS
534 # Send a command to gdb; test the result.
536 # COMMAND is the command to execute, send to GDB with send_gdb. If
537 # this is the null string no command is sent.
538 # MESSAGE is a message to be printed with the built-in failure patterns
539 # if one of them matches. If MESSAGE is empty COMMAND will be used.
540 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
541 # patterns. Pattern elements will be evaluated in the caller's
542 # context; action elements will be executed in the caller's context.
543 # Unlike patterns for gdb_test, these patterns should generally include
544 # the final newline and prompt.
547 # 1 if the test failed, according to a built-in failure pattern
548 # 0 if only user-supplied patterns matched
549 # -1 if there was an internal error.
551 # You can use this function thus:
553 # gdb_test_multiple "print foo" "test foo" {
554 # -re "expected output 1" {
557 # -re "expected output 2" {
562 # The standard patterns, such as "Program exited..." and "A problem
563 # ...", all being implicitly appended to that list.
565 proc gdb_test_multiple { command message user_code } {
569 upvar timeout timeout
570 upvar expect_out expect_out
572 if { $message == "" } {
576 # TCL/EXPECT WART ALERT
577 # Expect does something very strange when it receives a single braced
578 # argument. It splits it along word separators and performs substitutions.
579 # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
580 # evaluated as "\[ab\]". But that's not how TCL normally works; inside a
581 # double-quoted list item, "\[ab\]" is just a long way of representing
582 # "[ab]", because the backslashes will be removed by lindex.
584 # Unfortunately, there appears to be no easy way to duplicate the splitting
585 # that expect will do from within TCL. And many places make use of the
586 # "\[0-9\]" construct, so we need to support that; and some places make use
587 # of the "[func]" construct, so we need to support that too. In order to
588 # get this right we have to substitute quoted list elements differently
589 # from braced list elements.
591 # We do this roughly the same way that Expect does it. We have to use two
592 # lists, because if we leave unquoted newlines in the argument to uplevel
593 # they'll be treated as command separators, and if we escape newlines
594 # we mangle newlines inside of command blocks. This assumes that the
595 # input doesn't contain a pattern which contains actual embedded newlines
598 regsub -all {\n} ${user_code} { } subst_code
599 set subst_code [uplevel list $subst_code]
601 set processed_code ""
603 set expecting_action 0
604 foreach item $user_code subst_item $subst_code {
605 if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } {
606 lappend processed_code $item
609 if {$item == "-indices" || $item == "-re" || $item == "-ex"} {
610 lappend processed_code $item
613 if { $expecting_action } {
614 lappend processed_code "uplevel [list $item]"
615 set expecting_action 0
616 # Cosmetic, no effect on the list.
617 append processed_code "\n"
620 set expecting_action 1
621 lappend processed_code $subst_item
622 if {$patterns != ""} {
625 append patterns "\"$subst_item\""
628 # Also purely cosmetic.
629 regsub -all {\r} $patterns {\\r} patterns
630 regsub -all {\n} $patterns {\\n} patterns
633 send_user "Sending \"$command\" to gdb\n"
634 send_user "Looking to match \"$patterns\"\n"
635 send_user "Message is \"$message\"\n"
639 set string "${command}\n";
640 if { $command != "" } {
641 while { "$string" != "" } {
642 set foo [string first "\n" "$string"];
643 set len [string length "$string"];
644 if { $foo < [expr $len - 1] } {
645 set str [string range "$string" 0 $foo];
646 if { [send_gdb "$str"] != "" } {
647 global suppress_flag;
649 if { ! $suppress_flag } {
650 perror "Couldn't send $command to GDB.";
655 # since we're checking if each line of the multi-line
656 # command are 'accepted' by GDB here,
657 # we need to set -notransfer expect option so that
658 # command output is not lost for pattern matching
661 -notransfer -re "\[\r\n\]" { verbose "partial: match" 3 }
662 timeout { verbose "partial: timeout" 3 }
664 set string [string range "$string" [expr $foo + 1] end];
669 if { "$string" != "" } {
670 if { [send_gdb "$string"] != "" } {
671 global suppress_flag;
673 if { ! $suppress_flag } {
674 perror "Couldn't send $command to GDB.";
682 if [target_info exists gdb,timeout] {
683 set tmt [target_info gdb,timeout];
685 if [info exists timeout] {
689 if [info exists timeout] {
698 -re ".*A problem internal to GDB has been detected" {
699 fail "$message (GDB internal error)"
700 gdb_internal_error_resync
702 -re "\\*\\*\\* DOSEXIT code.*" {
703 if { $message != "" } {
706 gdb_suppress_entire_file "GDB died";
710 append code $processed_code
712 -re "Ending remote debugging.*$gdb_prompt $" {
713 if ![isnative] then {
714 warning "Can`t communicate to remote target."
720 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
721 perror "Undefined command \"$command\"."
725 -re "Ambiguous command.*$gdb_prompt $" {
726 perror "\"$command\" is not a unique command name."
730 -re "Program exited with code \[0-9\]+.*$gdb_prompt $" {
731 if ![string match "" $message] then {
732 set errmsg "$message (the program exited)"
734 set errmsg "$command (the program exited)"
739 -re "EXIT code \[0-9\r\n\]+Program exited normally.*$gdb_prompt $" {
740 if ![string match "" $message] then {
741 set errmsg "$message (the program exited)"
743 set errmsg "$command (the program exited)"
748 -re "The program is not being run.*$gdb_prompt $" {
749 if ![string match "" $message] then {
750 set errmsg "$message (the program is no longer running)"
752 set errmsg "$command (the program is no longer running)"
757 -re "\r\n$gdb_prompt $" {
758 if ![string match "" $message] then {
765 perror "Window too small."
769 -re "\\((y or n|y or \\\[n\\\]|\\\[y\\\] or n)\\) " {
771 gdb_expect -re "$gdb_prompt $"
772 fail "$message (got interactive prompt)"
775 -re "\\\[0\\\] cancel\r\n\\\[1\\\] all.*\r\n> $" {
777 gdb_expect -re "$gdb_prompt $"
778 fail "$message (got breakpoint menu)"
782 perror "Process no longer exists"
783 if { $message != "" } {
789 perror "internal buffer is full."
794 if ![string match "" $message] then {
795 fail "$message (timeout)"
802 set code [catch {gdb_expect $tmt $code} string]
804 global errorInfo errorCode;
805 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
806 } elseif {$code == 2} {
807 return -code return $string
808 } elseif {$code == 3} {
810 } elseif {$code > 4} {
811 return -code $code $string
816 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
817 # Send a command to gdb; test the result.
819 # COMMAND is the command to execute, send to GDB with send_gdb. If
820 # this is the null string no command is sent.
821 # PATTERN is the pattern to match for a PASS, and must NOT include
822 # the \r\n sequence immediately before the gdb prompt.
823 # MESSAGE is an optional message to be printed. If this is
824 # omitted, then the pass/fail messages use the command string as the
825 # message. (If this is the empty string, then sometimes we don't
826 # call pass or fail at all; I don't understand this at all.)
827 # QUESTION is a question GDB may ask in response to COMMAND, like
829 # RESPONSE is the response to send if QUESTION appears.
832 # 1 if the test failed,
833 # 0 if the test passes,
834 # -1 if there was an internal error.
836 proc gdb_test { args } {
840 upvar timeout timeout
842 if [llength $args]>2 then {
843 set message [lindex $args 2]
845 set message [lindex $args 0]
847 set command [lindex $args 0]
848 set pattern [lindex $args 1]
850 if [llength $args]==5 {
851 set question_string [lindex $args 3];
852 set response_string [lindex $args 4];
854 set question_string "^FOOBAR$"
857 return [gdb_test_multiple $command $message {
858 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
859 if ![string match "" $message] then {
863 -re "(${question_string})$" {
864 send_gdb "$response_string\n";
870 # Test that a command gives an error. For pass or fail, return
871 # a 1 to indicate that more tests can proceed. However a timeout
872 # is a serious error, generates a special fail message, and causes
873 # a 0 to be returned to indicate that more tests are likely to fail
876 proc test_print_reject { args } {
880 if [llength $args]==2 then {
881 set expectthis [lindex $args 1]
883 set expectthis "should never match this bogus string"
885 set sendthis [lindex $args 0]
887 send_user "Sending \"$sendthis\" to gdb\n"
888 send_user "Looking to match \"$expectthis\"\n"
890 send_gdb "$sendthis\n"
891 #FIXME: Should add timeout as parameter.
893 -re "A .* in expression.*\\.*$gdb_prompt $" {
894 pass "reject $sendthis"
897 -re "Invalid syntax in expression.*$gdb_prompt $" {
898 pass "reject $sendthis"
901 -re "Junk after end of expression.*$gdb_prompt $" {
902 pass "reject $sendthis"
905 -re "Invalid number.*$gdb_prompt $" {
906 pass "reject $sendthis"
909 -re "Invalid character constant.*$gdb_prompt $" {
910 pass "reject $sendthis"
913 -re "No symbol table is loaded.*$gdb_prompt $" {
914 pass "reject $sendthis"
917 -re "No symbol .* in current context.*$gdb_prompt $" {
918 pass "reject $sendthis"
921 -re "Unmatched single quote.*$gdb_prompt $" {
922 pass "reject $sendthis"
925 -re "A character constant must contain at least one character.*$gdb_prompt $" {
926 pass "reject $sendthis"
929 -re "$expectthis.*$gdb_prompt $" {
930 pass "reject $sendthis"
933 -re ".*$gdb_prompt $" {
934 fail "reject $sendthis"
938 fail "reject $sendthis (eof or timeout)"
944 # Given an input string, adds backslashes as needed to create a
945 # regexp that will match the string.
947 proc string_to_regexp {str} {
949 regsub -all {[]*+.|()^$\[\\]} $str {\\&} result
953 # Same as gdb_test, but the second parameter is not a regexp,
954 # but a string that must match exactly.
956 proc gdb_test_exact { args } {
957 upvar timeout timeout
959 set command [lindex $args 0]
961 # This applies a special meaning to a null string pattern. Without
962 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
963 # messages from commands that should have no output except a new
964 # prompt. With this, only results of a null string will match a null
967 set pattern [lindex $args 1]
968 if [string match $pattern ""] {
969 set pattern [string_to_regexp [lindex $args 0]]
971 set pattern [string_to_regexp [lindex $args 1]]
974 # It is most natural to write the pattern argument with only
975 # embedded \n's, especially if you are trying to avoid Tcl quoting
976 # problems. But gdb_expect really wants to see \r\n in patterns. So
977 # transform the pattern here. First transform \r\n back to \n, in
978 # case some users of gdb_test_exact already do the right thing.
979 regsub -all "\r\n" $pattern "\n" pattern
980 regsub -all "\n" $pattern "\r\n" pattern
981 if [llength $args]==3 then {
982 set message [lindex $args 2]
987 return [gdb_test $command $pattern $message]
990 proc gdb_reinitialize_dir { subdir } {
993 if [is_remote host] {
998 -re "Reinitialize source path to empty.*y or n. " {
1001 -re "Source directories searched.*$gdb_prompt $" {
1002 send_gdb "dir $subdir\n"
1004 -re "Source directories searched.*$gdb_prompt $" {
1005 verbose "Dir set to $subdir"
1007 -re "$gdb_prompt $" {
1008 perror "Dir \"$subdir\" failed."
1012 -re "$gdb_prompt $" {
1013 perror "Dir \"$subdir\" failed."
1017 -re "$gdb_prompt $" {
1018 perror "Dir \"$subdir\" failed."
1024 # gdb_exit -- exit the GDB, killing the target program if necessary
1026 proc default_gdb_exit {} {
1028 global INTERNAL_GDBFLAGS GDBFLAGS
1030 global gdb_spawn_id;
1032 gdb_stop_suppressing_tests;
1034 if ![info exists gdb_spawn_id] {
1038 verbose "Quitting $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1040 if { [is_remote host] && [board_info host exists fileid] } {
1047 -re "DOSEXIT code" { }
1052 if ![is_remote host] {
1058 # Load a file into the debugger.
1059 # The return value is 0 for success, -1 for failure.
1061 # This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO
1062 # to one of these values:
1064 # debug file was loaded successfully and has debug information
1065 # nodebug file was loaded successfully and has no debug information
1066 # fail file was not loaded
1068 # I tried returning this information as part of the return value,
1069 # but ran into a mess because of the many re-implementations of
1070 # gdb_load in config/*.exp.
1072 # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use
1073 # this if they can get more information set.
1075 proc gdb_file_cmd { arg } {
1079 global last_loaded_file
1081 set last_loaded_file $arg
1083 # Set whether debug info was found.
1084 # Default to "fail".
1085 global gdb_file_cmd_debug_info
1086 set gdb_file_cmd_debug_info "fail"
1088 if [is_remote host] {
1089 set arg [remote_download host $arg]
1091 perror "download failed"
1096 # The file command used to kill the remote target. For the benefit
1097 # of the testsuite, preserve this behavior.
1100 -re "Kill the program being debugged. .y or n. $" {
1102 verbose "\t\tKilling previous program being debugged"
1105 -re "$gdb_prompt $" {
1110 send_gdb "file $arg\n"
1112 -re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" {
1113 verbose "\t\tLoaded $arg into the $GDB with no debugging symbols"
1114 set gdb_file_cmd_debug_info "nodebug"
1117 -re "Reading symbols from.*done.*$gdb_prompt $" {
1118 verbose "\t\tLoaded $arg into the $GDB"
1119 set gdb_file_cmd_debug_info "debug"
1122 -re "Load new symbol table from \".*\".*y or n. $" {
1125 -re "Reading symbols from.*done.*$gdb_prompt $" {
1126 verbose "\t\tLoaded $arg with new symbol table into $GDB"
1127 set gdb_file_cmd_debug_info "debug"
1131 perror "(timeout) Couldn't load $arg, other program already loaded."
1136 -re "No such file or directory.*$gdb_prompt $" {
1137 perror "($arg) No such file or directory"
1140 -re "$gdb_prompt $" {
1141 perror "couldn't load $arg into $GDB."
1145 perror "couldn't load $arg into $GDB (timed out)."
1149 # This is an attempt to detect a core dump, but seems not to
1150 # work. Perhaps we need to match .* followed by eof, in which
1151 # gdb_expect does not seem to have a way to do that.
1152 perror "couldn't load $arg into $GDB (end of file)."
1159 # start gdb -- start gdb running, default procedure
1161 # When running over NFS, particularly if running many simultaneous
1162 # tests on different hosts all using the same server, things can
1163 # get really slow. Give gdb at least 3 minutes to start up.
1165 proc default_gdb_start { } {
1168 global INTERNAL_GDBFLAGS GDBFLAGS
1171 global gdb_spawn_id;
1174 gdb_stop_suppressing_tests;
1178 # Don't let a .inputrc file or an existing setting of INPUTRC mess up
1179 # the test results. Even if /dev/null doesn't exist on the particular
1180 # platform, the readline library will use the default setting just by
1181 # failing to open the file. OTOH, opening /dev/null successfully will
1182 # also result in the default settings being used since nothing will be
1183 # read from this file.
1184 set env(INPUTRC) "/dev/null"
1186 # The gdb.base/readline.exp arrow key test relies on the standard VT100
1187 # bindings, so make sure that an appropriate terminal is selected.
1188 # The same bug doesn't show up if we use ^P / ^N instead.
1189 set env(TERM) "vt100"
1191 verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
1193 if [info exists gdb_spawn_id] {
1197 if ![is_remote host] {
1198 if { [which $GDB] == 0 } then {
1199 perror "$GDB does not exist."
1203 set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"];
1204 if { $res < 0 || $res == "" } {
1205 perror "Spawning $GDB failed."
1209 -re "\[\r\n\]$gdb_prompt $" {
1210 verbose "GDB initialized."
1212 -re "$gdb_prompt $" {
1213 perror "GDB never initialized."
1217 perror "(timeout) GDB never initialized after 10 seconds."
1222 set gdb_spawn_id -1;
1223 # force the height to "unlimited", so no pagers get used
1225 send_gdb "set height 0\n"
1227 -re "$gdb_prompt $" {
1228 verbose "Setting height to 0." 2
1231 warning "Couldn't set the height to 0"
1234 # force the width to "unlimited", so no wraparound occurs
1235 send_gdb "set width 0\n"
1237 -re "$gdb_prompt $" {
1238 verbose "Setting width to 0." 2
1241 warning "Couldn't set the width to 0."
1247 # Examine the output of compilation to determine whether compilation
1248 # failed or not. If it failed determine whether it is due to missing
1249 # compiler or due to compiler error. Report pass, fail or unsupported
1252 proc gdb_compile_test {src output} {
1253 if { $output == "" } {
1254 pass "compilation [file tail $src]"
1255 } elseif { [regexp {^[a-zA-Z_0-9]+: Can't find [^ ]+\.$} $output] } {
1256 unsupported "compilation [file tail $src]"
1257 } elseif { [regexp {.*: command not found[\r|\n]*$} $output] } {
1258 unsupported "compilation [file tail $src]"
1260 verbose -log "compilation failed: $output" 2
1261 fail "compilation [file tail $src]"
1265 # Return a 1 for configurations for which we don't even want to try to
1268 proc skip_cplus_tests {} {
1269 if { [istarget "h8300-*-*"] } {
1273 # The C++ IO streams are too large for HC11/HC12 and are thus not
1274 # available. The gdb C++ tests use them and don't compile.
1275 if { [istarget "m6811-*-*"] } {
1278 if { [istarget "m6812-*-*"] } {
1284 # Return a 1 if I don't even want to try to test FORTRAN.
1286 proc skip_fortran_tests {} {
1290 # Return a 1 if I don't even want to try to test ada.
1292 proc skip_ada_tests {} {
1296 # Return a 1 if I don't even want to try to test java.
1298 proc skip_java_tests {} {
1302 # Return a 1 for configurations that do not support Python scripting.
1304 proc skip_python_tests {} {
1306 gdb_test_multiple "python print 'test'" "verify python support" {
1307 -re "not supported.*$gdb_prompt $" {
1308 unsupported "Python support is disabled."
1311 -re "$gdb_prompt $" {}
1317 # Return a 1 if we should skip shared library tests.
1319 proc skip_shlib_tests {} {
1320 # Run the shared library tests on native systems.
1325 # An abbreviated list of remote targets where we should be able to
1326 # run shared library tests.
1327 if {([istarget *-*-linux*]
1328 || [istarget *-*-*bsd*]
1329 || [istarget *-*-solaris2*]
1330 || [istarget arm*-*-symbianelf*]
1331 || [istarget *-*-mingw*]
1332 || [istarget *-*-cygwin*]
1333 || [istarget *-*-pe*])} {
1340 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
1341 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
1343 proc skip_altivec_tests {} {
1344 global skip_vmx_tests_saved
1345 global srcdir subdir gdb_prompt
1347 # Use the cached value, if it exists.
1348 set me "skip_altivec_tests"
1349 if [info exists skip_vmx_tests_saved] {
1350 verbose "$me: returning saved $skip_vmx_tests_saved" 2
1351 return $skip_vmx_tests_saved
1354 # Some simulators are known to not support VMX instructions.
1355 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1356 verbose "$me: target known to not support VMX, returning 1" 2
1357 return [set skip_vmx_tests_saved 1]
1360 # Make sure we have a compiler that understands altivec.
1361 set compile_flags {debug nowarnings}
1362 if [get_compiler_info not-used] {
1363 warning "Could not get compiler info"
1366 if [test_compiler_info gcc*] {
1367 set compile_flags "$compile_flags additional_flags=-maltivec"
1368 } elseif [test_compiler_info xlc*] {
1369 set compile_flags "$compile_flags additional_flags=-qaltivec"
1371 verbose "Could not compile with altivec support, returning 1" 2
1375 # Set up, compile, and execute a test program containing VMX instructions.
1376 # Include the current process ID in the file names to prevent conflicts
1377 # with invocations for multiple testsuites.
1381 set f [open $src "w"]
1382 puts $f "int main() {"
1383 puts $f "#ifdef __MACH__"
1384 puts $f " asm volatile (\"vor v0,v0,v0\");"
1386 puts $f " asm volatile (\"vor 0,0,0\");"
1388 puts $f " return 0; }"
1391 verbose "$me: compiling testfile $src" 2
1392 set lines [gdb_compile $src $exe executable $compile_flags]
1395 if ![string match "" $lines] then {
1396 verbose "$me: testfile compilation failed, returning 1" 2
1397 return [set skip_vmx_tests_saved 1]
1400 # No error message, compilation succeeded so now run it via gdb.
1404 gdb_reinitialize_dir $srcdir/$subdir
1408 -re ".*Illegal instruction.*${gdb_prompt} $" {
1409 verbose -log "\n$me altivec hardware not detected"
1410 set skip_vmx_tests_saved 1
1412 -re ".*Program exited normally.*${gdb_prompt} $" {
1413 verbose -log "\n$me: altivec hardware detected"
1414 set skip_vmx_tests_saved 0
1417 warning "\n$me: default case taken"
1418 set skip_vmx_tests_saved 1
1422 remote_file build delete $exe
1424 verbose "$me: returning $skip_vmx_tests_saved" 2
1425 return $skip_vmx_tests_saved
1428 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
1429 # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite.
1431 proc skip_vsx_tests {} {
1432 global skip_vsx_tests_saved
1433 global srcdir subdir gdb_prompt
1435 # Use the cached value, if it exists.
1436 set me "skip_vsx_tests"
1437 if [info exists skip_vsx_tests_saved] {
1438 verbose "$me: returning saved $skip_vsx_tests_saved" 2
1439 return $skip_vsx_tests_saved
1442 # Some simulators are known to not support Altivec instructions, so
1443 # they won't support VSX instructions as well.
1444 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1445 verbose "$me: target known to not support VSX, returning 1" 2
1446 return [set skip_vsx_tests_saved 1]
1449 # Make sure we have a compiler that understands altivec.
1450 set compile_flags {debug nowarnings quiet}
1451 if [get_compiler_info not-used] {
1452 warning "Could not get compiler info"
1455 if [test_compiler_info gcc*] {
1456 set compile_flags "$compile_flags additional_flags=-mvsx"
1457 } elseif [test_compiler_info xlc*] {
1458 set compile_flags "$compile_flags additional_flags=-qvsx"
1460 verbose "Could not compile with vsx support, returning 1" 2
1467 set f [open $src "w"]
1468 puts $f "int main() {"
1469 puts $f "#ifdef __MACH__"
1470 puts $f " asm volatile (\"lxvd2x v0,v0,v0\");"
1472 puts $f " asm volatile (\"lxvd2x 0,0,0\");"
1474 puts $f " return 0; }"
1477 verbose "$me: compiling testfile $src" 2
1478 set lines [gdb_compile $src $exe executable $compile_flags]
1481 if ![string match "" $lines] then {
1482 verbose "$me: testfile compilation failed, returning 1" 2
1483 return [set skip_vsx_tests_saved 1]
1486 # No error message, compilation succeeded so now run it via gdb.
1490 gdb_reinitialize_dir $srcdir/$subdir
1494 -re ".*Illegal instruction.*${gdb_prompt} $" {
1495 verbose -log "\n$me VSX hardware not detected"
1496 set skip_vsx_tests_saved 1
1498 -re ".*Program exited normally.*${gdb_prompt} $" {
1499 verbose -log "\n$me: VSX hardware detected"
1500 set skip_vsx_tests_saved 0
1503 warning "\n$me: default case taken"
1504 set skip_vsx_tests_saved 1
1508 remote_file build delete $exe
1510 verbose "$me: returning $skip_vsx_tests_saved" 2
1511 return $skip_vsx_tests_saved
1514 # Skip all the tests in the file if you are not on an hppa running
1517 proc skip_hp_tests {} {
1518 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
1519 verbose "Skip hp tests is $skip_hp"
1523 # Return whether we should skip tests for showing inlined functions in
1524 # backtraces. Requires get_compiler_info and get_debug_format.
1526 proc skip_inline_frame_tests {} {
1527 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
1528 if { ! [test_debug_format "DWARF 2"] } {
1532 # GCC before 4.1 does not emit DW_AT_call_file / DW_AT_call_line.
1533 if { ([test_compiler_info "gcc-2-*"]
1534 || [test_compiler_info "gcc-3-*"]
1535 || [test_compiler_info "gcc-4-0-*"]) } {
1542 # Return whether we should skip tests for showing variables from
1543 # inlined functions. Requires get_compiler_info and get_debug_format.
1545 proc skip_inline_var_tests {} {
1546 # GDB only recognizes inlining information in DWARF 2 (DWARF 3).
1547 if { ! [test_debug_format "DWARF 2"] } {
1554 set compiler_info "unknown"
1556 set hp_cc_compiler 0
1557 set hp_aCC_compiler 0
1559 # Figure out what compiler I am using.
1561 # BINFILE is a "compiler information" output file. This implementation
1562 # does not use BINFILE.
1564 # ARGS can be empty or "C++". If empty, "C" is assumed.
1566 # There are several ways to do this, with various problems.
1568 # [ gdb_compile -E $ifile -o $binfile.ci ]
1569 # source $binfile.ci
1571 # Single Unix Spec v3 says that "-E -o ..." together are not
1572 # specified. And in fact, the native compiler on hp-ux 11 (among
1573 # others) does not work with "-E -o ...". Most targets used to do
1574 # this, and it mostly worked, because it works with gcc.
1576 # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ]
1577 # source $binfile.ci
1579 # This avoids the problem with -E and -o together. This almost works
1580 # if the build machine is the same as the host machine, which is
1581 # usually true of the targets which are not gcc. But this code does
1582 # not figure which compiler to call, and it always ends up using the C
1583 # compiler. Not good for setting hp_aCC_compiler. Targets
1584 # hppa*-*-hpux* and mips*-*-irix* used to do this.
1586 # [ gdb_compile -E $ifile > $binfile.ci ]
1587 # source $binfile.ci
1589 # dejagnu target_compile says that it supports output redirection,
1590 # but the code is completely different from the normal path and I
1591 # don't want to sweep the mines from that path. So I didn't even try
1594 # set cppout [ gdb_compile $ifile "" preprocess $args quiet ]
1597 # I actually do this for all targets now. gdb_compile runs the right
1598 # compiler, and TCL captures the output, and I eval the output.
1600 # Unfortunately, expect logs the output of the command as it goes by,
1601 # and dejagnu helpfully prints a second copy of it right afterwards.
1602 # So I turn off expect logging for a moment.
1604 # [ gdb_compile $ifile $ciexe_file executable $args ]
1605 # [ remote_exec $ciexe_file ]
1606 # [ source $ci_file.out ]
1608 # I could give up on -E and just do this.
1609 # I didn't get desperate enough to try this.
1611 # -- chastain 2004-01-06
1613 proc get_compiler_info {binfile args} {
1614 # For compiler.c and compiler.cc
1617 # I am going to play with the log to keep noise out.
1621 # These come from compiler.c or compiler.cc
1622 global compiler_info
1624 # Legacy global data symbols.
1626 global hp_cc_compiler
1627 global hp_aCC_compiler
1629 # Choose which file to preprocess.
1630 set ifile "${srcdir}/lib/compiler.c"
1631 if { [llength $args] > 0 && [lindex $args 0] == "c++" } {
1632 set ifile "${srcdir}/lib/compiler.cc"
1635 # Run $ifile through the right preprocessor.
1636 # Toggle gdb.log to keep the compiler output out of the log.
1638 if [is_remote host] {
1639 # We have to use -E and -o together, despite the comments
1640 # above, because of how DejaGnu handles remote host testing.
1641 set ppout "$outdir/compiler.i"
1642 gdb_compile "${ifile}" "$ppout" preprocess [list "$args" quiet]
1643 set file [open $ppout r]
1644 set cppout [read $file]
1647 set cppout [ gdb_compile "${ifile}" "" preprocess [list "$args" quiet] ]
1649 log_file -a "$outdir/$tool.log"
1653 foreach cppline [ split "$cppout" "\n" ] {
1654 if { [ regexp "^#" "$cppline" ] } {
1656 } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } {
1658 } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } {
1660 verbose "get_compiler_info: $cppline" 2
1664 verbose -log "get_compiler_info: $cppline"
1669 # Reset to unknown compiler if any diagnostics happened.
1671 set compiler_info "unknown"
1674 # Set the legacy symbols.
1676 set hp_cc_compiler 0
1677 set hp_aCC_compiler 0
1678 if { [regexp "^gcc-1-" "$compiler_info" ] } { set gcc_compiled 1 }
1679 if { [regexp "^gcc-2-" "$compiler_info" ] } { set gcc_compiled 2 }
1680 if { [regexp "^gcc-3-" "$compiler_info" ] } { set gcc_compiled 3 }
1681 if { [regexp "^gcc-4-" "$compiler_info" ] } { set gcc_compiled 4 }
1682 if { [regexp "^gcc-5-" "$compiler_info" ] } { set gcc_compiled 5 }
1683 if { [regexp "^hpcc-" "$compiler_info" ] } { set hp_cc_compiler 1 }
1684 if { [regexp "^hpacc-" "$compiler_info" ] } { set hp_aCC_compiler 1 }
1686 # Log what happened.
1687 verbose -log "get_compiler_info: $compiler_info"
1689 # Most compilers will evaluate comparisons and other boolean
1690 # operations to 0 or 1.
1691 uplevel \#0 { set true 1 }
1692 uplevel \#0 { set false 0 }
1694 # Use of aCC results in boolean results being displayed as
1696 if { $hp_aCC_compiler } {
1697 uplevel \#0 { set true true }
1698 uplevel \#0 { set false false }
1704 proc test_compiler_info { {compiler ""} } {
1705 global compiler_info
1707 # if no arg, return the compiler_info string
1709 if [string match "" $compiler] {
1710 if [info exists compiler_info] {
1711 return $compiler_info
1713 perror "No compiler info found."
1717 return [string match $compiler $compiler_info]
1720 proc current_target_name { } {
1722 if [info exists target_info(target,name)] {
1723 set answer $target_info(target,name)
1730 set gdb_wrapper_initialized 0
1731 set gdb_wrapper_target ""
1733 proc gdb_wrapper_init { args } {
1734 global gdb_wrapper_initialized;
1735 global gdb_wrapper_file;
1736 global gdb_wrapper_flags;
1737 global gdb_wrapper_target
1739 if { $gdb_wrapper_initialized == 1 } { return; }
1741 if {[target_info exists needs_status_wrapper] && \
1742 [target_info needs_status_wrapper] != "0"} {
1743 set result [build_wrapper "testglue.o"];
1744 if { $result != "" } {
1745 set gdb_wrapper_file [lindex $result 0];
1746 set gdb_wrapper_flags [lindex $result 1];
1748 warning "Status wrapper failed to build."
1751 set gdb_wrapper_initialized 1
1752 set gdb_wrapper_target [current_target_name]
1755 # Some targets need to always link a special object in. Save its path here.
1756 global gdb_saved_set_unbuffered_mode_obj
1757 set gdb_saved_set_unbuffered_mode_obj ""
1759 proc gdb_compile {source dest type options} {
1760 global GDB_TESTCASE_OPTIONS;
1761 global gdb_wrapper_file;
1762 global gdb_wrapper_flags;
1763 global gdb_wrapper_initialized;
1766 global gdb_saved_set_unbuffered_mode_obj
1768 set outdir [file dirname $dest]
1770 # Add platform-specific options if a shared library was specified using
1771 # "shlib=librarypath" in OPTIONS.
1775 foreach opt $options {
1776 if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] {
1777 if [test_compiler_info "xlc-*"] {
1778 # IBM xlc compiler doesn't accept shared library named other
1779 # than .so: use "-Wl," to bypass this
1780 lappend source "-Wl,$shlib_name"
1781 } elseif { ([istarget "*-*-mingw*"]
1782 || [istarget *-*-cygwin*]
1783 || [istarget *-*-pe*])} {
1784 lappend source "${shlib_name}.a"
1786 lappend source $shlib_name
1788 if { $shlib_found == 0 } {
1790 if { ([istarget "*-*-mingw*"]
1791 || [istarget *-*-cygwin*]) } {
1792 lappend new_options "additional_flags=-Wl,--enable-auto-import"
1795 } elseif { $opt == "shlib_load" } {
1798 lappend new_options $opt
1802 # We typically link to shared libraries using an absolute path, and
1803 # that's how they are found at runtime. If we are going to
1804 # dynamically load one by basename, we must specify rpath. If we
1805 # are using a remote host, DejaGNU will link to the shared library
1806 # using a relative path, so again we must specify an rpath.
1807 if { $shlib_load || ($shlib_found && [is_remote host]) } {
1808 if { ([istarget "*-*-mingw*"]
1809 || [istarget *-*-cygwin*]
1810 || [istarget *-*-pe*]
1811 || [istarget arm*-*-symbianelf*]
1812 || [istarget hppa*-*-hpux*])} {
1813 # Do not need anything.
1814 } elseif { [istarget *-*-openbsd*] } {
1815 lappend new_options "additional_flags=-Wl,-rpath,${outdir}"
1817 if { $shlib_load } {
1818 lappend new_options "libs=-ldl"
1820 lappend new_options "additional_flags=-Wl,-rpath,\\\$ORIGIN"
1823 set options $new_options
1825 if [target_info exists gdb_stub] {
1826 set options2 { "additional_flags=-Dusestubs" }
1827 lappend options "libs=[target_info gdb_stub]";
1828 set options [concat $options2 $options]
1830 if [target_info exists is_vxworks] {
1831 set options2 { "additional_flags=-Dvxworks" }
1832 lappend options "libs=[target_info gdb_stub]";
1833 set options [concat $options2 $options]
1835 if [info exists GDB_TESTCASE_OPTIONS] {
1836 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
1838 verbose "options are $options"
1839 verbose "source is $source $dest $type $options"
1841 if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init }
1843 if {[target_info exists needs_status_wrapper] && \
1844 [target_info needs_status_wrapper] != "0" && \
1845 [info exists gdb_wrapper_file]} {
1846 lappend options "libs=${gdb_wrapper_file}"
1847 lappend options "ldflags=${gdb_wrapper_flags}"
1850 # Replace the "nowarnings" option with the appropriate additional_flags
1851 # to disable compiler warnings.
1852 set nowarnings [lsearch -exact $options nowarnings]
1853 if {$nowarnings != -1} {
1854 if [target_info exists gdb,nowarnings_flag] {
1855 set flag "additional_flags=[target_info gdb,nowarnings_flag]"
1857 set flag "additional_flags=-w"
1859 set options [lreplace $options $nowarnings $nowarnings $flag]
1862 if { $type == "executable" } {
1863 if { ([istarget "*-*-mingw*"]
1864 || [istarget "*-*-*djgpp"]
1865 || [istarget "*-*-cygwin*"])} {
1866 # Force output to unbuffered mode, by linking in an object file
1867 # with a global contructor that calls setvbuf.
1869 # Compile the special object seperatelly for two reasons:
1870 # 1) Insulate it from $options.
1871 # 2) Avoid compiling it for every gdb_compile invocation,
1872 # which is time consuming, especially if we're remote
1875 if { $gdb_saved_set_unbuffered_mode_obj == "" } {
1876 verbose "compiling gdb_saved_set_unbuffered_obj"
1877 set unbuf_src ${srcdir}/lib/set_unbuffered_mode.c
1878 set unbuf_obj ${objdir}/set_unbuffered_mode.o
1880 set result [gdb_compile "${unbuf_src}" "${unbuf_obj}" object {nowarnings}]
1881 if { $result != "" } {
1885 set gdb_saved_set_unbuffered_mode_obj ${objdir}/set_unbuffered_mode_saved.o
1886 # Link a copy of the output object, because the
1887 # original may be automatically deleted.
1888 remote_exec host "cp -f $unbuf_obj $gdb_saved_set_unbuffered_mode_obj"
1890 verbose "gdb_saved_set_unbuffered_obj already compiled"
1893 # Rely on the internal knowledge that the global ctors are ran in
1894 # reverse link order. In that case, we can use ldflags to
1895 # avoid copying the object file to the host multiple
1897 # This object can only be added if standard libraries are
1898 # used. Thus, we need to disable it if -nostdlib option is used
1899 if {[lsearch -regexp $options "-nostdlib"] < 0 } {
1900 lappend options "ldflags=$gdb_saved_set_unbuffered_mode_obj"
1905 set result [target_compile $source $dest $type $options];
1907 # Prune uninteresting compiler (and linker) output.
1908 regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result
1910 regsub "\[\r\n\]*$" "$result" "" result;
1911 regsub "^\[\r\n\]*" "$result" "" result;
1913 if {[lsearch $options quiet] < 0} {
1914 # We shall update this on a per language basis, to avoid
1915 # changing the entire testsuite in one go.
1916 if {[lsearch $options f77] >= 0} {
1917 gdb_compile_test $source $result
1918 } elseif { $result != "" } {
1919 clone_output "gdb compile failed, $result"
1926 # This is just like gdb_compile, above, except that it tries compiling
1927 # against several different thread libraries, to see which one this
1929 proc gdb_compile_pthreads {source dest type options} {
1931 set why_msg "unrecognized error"
1932 foreach lib {-lpthreads -lpthread -lthread ""} {
1933 # This kind of wipes out whatever libs the caller may have
1934 # set. Or maybe theirs will override ours. How infelicitous.
1935 set options_with_lib [concat $options [list libs=$lib quiet]]
1936 set ccout [gdb_compile $source $dest $type $options_with_lib]
1937 switch -regexp -- $ccout {
1938 ".*no posix threads support.*" {
1939 set why_msg "missing threads include file"
1942 ".*cannot open -lpthread.*" {
1943 set why_msg "missing runtime threads library"
1945 ".*Can't find library for -lpthread.*" {
1946 set why_msg "missing runtime threads library"
1949 pass "successfully compiled posix threads test case"
1955 if {!$built_binfile} {
1956 unsupported "Couldn't compile $source: ${why_msg}"
1961 # Build a shared library from SOURCES. You must use get_compiler_info
1964 proc gdb_compile_shlib {sources dest options} {
1965 set obj_options $options
1967 switch -glob [test_compiler_info] {
1969 lappend obj_options "additional_flags=-qpic"
1972 if { !([istarget "powerpc*-*-aix*"]
1973 || [istarget "rs6000*-*-aix*"]
1974 || [istarget "*-*-cygwin*"]
1975 || [istarget "*-*-mingw*"]
1976 || [istarget "*-*-pe*"]) } {
1977 lappend obj_options "additional_flags=-fpic"
1981 switch -glob [istarget] {
1983 lappend obj_options "additional_flags=+z"
1986 # Disable SGI compiler's implicit -Dsgi
1987 lappend obj_options "additional_flags=-Usgi"
1990 # don't know what the compiler is...
1996 set outdir [file dirname $dest]
1998 foreach source $sources {
1999 set sourcebase [file tail $source]
2000 if {[gdb_compile $source "${outdir}/${sourcebase}.o" object $obj_options] != ""} {
2003 lappend objects ${outdir}/${sourcebase}.o
2006 if [istarget "hppa*-*-hpux*"] {
2007 remote_exec build "ld -b ${objects} -o ${dest}"
2009 set link_options $options
2010 if [test_compiler_info "xlc-*"] {
2011 lappend link_options "additional_flags=-qmkshrobj"
2013 lappend link_options "additional_flags=-shared"
2015 if { ([istarget "*-*-mingw*"]
2016 || [istarget *-*-cygwin*]
2017 || [istarget *-*-pe*])} {
2018 lappend link_options "additional_flags=-Wl,--out-implib,${dest}.a"
2021 if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
2027 # This is just like gdb_compile_pthreads, above, except that we always add the
2028 # objc library for compiling Objective-C programs
2029 proc gdb_compile_objc {source dest type options} {
2031 set why_msg "unrecognized error"
2032 foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} {
2033 # This kind of wipes out whatever libs the caller may have
2034 # set. Or maybe theirs will override ours. How infelicitous.
2035 if { $lib == "solaris" } {
2036 set lib "-lpthread -lposix4"
2038 if { $lib != "-lobjc" } {
2039 set lib "-lobjc $lib"
2041 set options_with_lib [concat $options [list libs=$lib quiet]]
2042 set ccout [gdb_compile $source $dest $type $options_with_lib]
2043 switch -regexp -- $ccout {
2044 ".*no posix threads support.*" {
2045 set why_msg "missing threads include file"
2048 ".*cannot open -lpthread.*" {
2049 set why_msg "missing runtime threads library"
2051 ".*Can't find library for -lpthread.*" {
2052 set why_msg "missing runtime threads library"
2055 pass "successfully compiled objc with posix threads test case"
2061 if {!$built_binfile} {
2062 unsupported "Couldn't compile $source: ${why_msg}"
2067 proc send_gdb { string } {
2068 global suppress_flag;
2069 if { $suppress_flag } {
2070 return "suppressed";
2072 return [remote_send host "$string"];
2078 proc gdb_expect { args } {
2079 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
2080 set atimeout [lindex $args 0];
2081 set expcode [list [lindex $args 1]];
2086 upvar timeout timeout;
2088 if [target_info exists gdb,timeout] {
2089 if [info exists timeout] {
2090 if { $timeout < [target_info gdb,timeout] } {
2091 set gtimeout [target_info gdb,timeout];
2093 set gtimeout $timeout;
2096 set gtimeout [target_info gdb,timeout];
2100 if ![info exists gtimeout] {
2102 if [info exists timeout] {
2103 set gtimeout $timeout;
2107 if [info exists atimeout] {
2108 if { ![info exists gtimeout] || $gtimeout < $atimeout } {
2109 set gtimeout $atimeout;
2112 if ![info exists gtimeout] {
2118 global suppress_flag;
2119 global remote_suppress_flag;
2120 if [info exists remote_suppress_flag] {
2121 set old_val $remote_suppress_flag;
2123 if [info exists suppress_flag] {
2124 if { $suppress_flag } {
2125 set remote_suppress_flag 1;
2129 {uplevel remote_expect host $gtimeout $expcode} string];
2130 if [info exists old_val] {
2131 set remote_suppress_flag $old_val;
2133 if [info exists remote_suppress_flag] {
2134 unset remote_suppress_flag;
2139 global errorInfo errorCode;
2141 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
2142 } elseif {$code == 2} {
2143 return -code return $string
2144 } elseif {$code == 3} {
2146 } elseif {$code > 4} {
2147 return -code $code $string
2151 # gdb_expect_list MESSAGE SENTINEL LIST -- expect a sequence of outputs
2153 # Check for long sequence of output by parts.
2154 # MESSAGE: is the test message to be printed with the test success/fail.
2155 # SENTINEL: Is the terminal pattern indicating that output has finished.
2156 # LIST: is the sequence of outputs to match.
2157 # If the sentinel is recognized early, it is considered an error.
2160 # 1 if the test failed,
2161 # 0 if the test passes,
2162 # -1 if there was an internal error.
2164 proc gdb_expect_list {test sentinel list} {
2166 global suppress_flag
2169 if { $suppress_flag } {
2171 unresolved "${test}"
2173 while { ${index} < [llength ${list}] } {
2174 set pattern [lindex ${list} ${index}]
2175 set index [expr ${index} + 1]
2176 if { ${index} == [llength ${list}] } {
2179 -re "${pattern}${sentinel}" {
2180 # pass "${test}, pattern ${index} + sentinel"
2183 fail "${test} (pattern ${index} + sentinel)"
2186 -re ".*A problem internal to GDB has been detected" {
2187 fail "${test} (GDB internal error)"
2189 gdb_internal_error_resync
2192 fail "${test} (pattern ${index} + sentinel) (timeout)"
2197 # unresolved "${test}, pattern ${index} + sentinel"
2203 # pass "${test}, pattern ${index}"
2206 fail "${test} (pattern ${index})"
2209 -re ".*A problem internal to GDB has been detected" {
2210 fail "${test} (GDB internal error)"
2212 gdb_internal_error_resync
2215 fail "${test} (pattern ${index}) (timeout)"
2220 # unresolved "${test}, pattern ${index}"
2234 proc gdb_suppress_entire_file { reason } {
2235 global suppress_flag;
2237 warning "$reason\n";
2238 set suppress_flag -1;
2242 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
2243 # gdb_expect to fail immediately (until the next call to
2244 # gdb_stop_suppressing_tests).
2246 proc gdb_suppress_tests { args } {
2247 global suppress_flag;
2249 return; # fnf - disable pending review of results where
2250 # testsuite ran better without this
2253 if { $suppress_flag == 1 } {
2254 if { [llength $args] > 0 } {
2255 warning "[lindex $args 0]\n";
2257 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
2263 # Clear suppress_flag.
2265 proc gdb_stop_suppressing_tests { } {
2266 global suppress_flag;
2268 if [info exists suppress_flag] {
2269 if { $suppress_flag > 0 } {
2270 set suppress_flag 0;
2271 clone_output "Tests restarted.\n";
2274 set suppress_flag 0;
2278 proc gdb_clear_suppressed { } {
2279 global suppress_flag;
2281 set suppress_flag 0;
2284 proc gdb_start { } {
2289 catch default_gdb_exit
2293 # gdb_load_cmd -- load a file into the debugger.
2294 # ARGS - additional args to load command.
2295 # return a -1 if anything goes wrong.
2297 proc gdb_load_cmd { args } {
2300 if [target_info exists gdb_load_timeout] {
2301 set loadtimeout [target_info gdb_load_timeout]
2303 set loadtimeout 1600
2305 send_gdb "load $args\n"
2306 verbose "Timeout is now $loadtimeout seconds" 2
2307 gdb_expect $loadtimeout {
2308 -re "Loading section\[^\r\]*\r\n" {
2311 -re "Start address\[\r\]*\r\n" {
2314 -re "Transfer rate\[\r\]*\r\n" {
2317 -re "Memory access error\[^\r\]*\r\n" {
2318 perror "Failed to load program"
2321 -re "$gdb_prompt $" {
2324 -re "(.*)\r\n$gdb_prompt " {
2325 perror "Unexpected reponse from 'load' -- $expect_out(1,string)"
2329 perror "Timed out trying to load $args."
2338 # Copy a file to the remote target and return its target filename.
2339 # Schedule the file to be deleted at the end of this test.
2341 proc gdb_download { filename } {
2344 set destname [remote_download target $filename]
2345 lappend cleanfiles $destname
2349 # gdb_load_shlibs LIB...
2351 # Copy the listed libraries to the target.
2353 proc gdb_load_shlibs { args } {
2354 if {![is_remote target]} {
2358 foreach file $args {
2362 # Even if the target supplies full paths for shared libraries,
2363 # they may not be paths for this system.
2364 gdb_test "set solib-search-path [file dirname [lindex $args 0]]" "" ""
2368 # gdb_load -- load a file into the debugger.
2369 # Many files in config/*.exp override this procedure.
2371 proc gdb_load { arg } {
2372 return [gdb_file_cmd $arg]
2375 # gdb_reload -- load a file into the target. Called before "running",
2376 # either the first time or after already starting the program once,
2377 # for remote targets. Most files that override gdb_load should now
2378 # override this instead.
2380 proc gdb_reload { } {
2381 # For the benefit of existing configurations, default to gdb_load.
2382 # Specifying no file defaults to the executable currently being
2384 return [gdb_load ""]
2387 proc gdb_continue { function } {
2390 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
2393 proc default_gdb_init { args } {
2394 global gdb_wrapper_initialized
2395 global gdb_wrapper_target
2400 gdb_clear_suppressed;
2402 # Make sure that the wrapper is rebuilt
2403 # with the appropriate multilib option.
2404 if { $gdb_wrapper_target != [current_target_name] } {
2405 set gdb_wrapper_initialized 0
2408 # Unlike most tests, we have a small number of tests that generate
2409 # a very large amount of output. We therefore increase the expect
2410 # buffer size to be able to contain the entire test output.
2412 # Also set this value for the currently running GDB.
2413 match_max [match_max -d]
2415 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
2416 if { [llength $args] > 0 } {
2419 set file [lindex $args 0];
2421 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
2424 if [target_info exists gdb_prompt] {
2425 set gdb_prompt [target_info gdb_prompt];
2427 set gdb_prompt "\\(gdb\\)"
2431 # The default timeout used when testing GDB commands. We want to use
2432 # the same timeout as the default dejagnu timeout, unless the user has
2433 # already provided a specific value (probably through a site.exp file).
2434 global gdb_test_timeout
2435 if ![info exists gdb_test_timeout] {
2436 set gdb_test_timeout $timeout
2439 proc gdb_init { args } {
2440 # Reset the timeout value to the default. This way, any testcase
2441 # that changes the timeout value without resetting it cannot affect
2442 # the timeout used in subsequent testcases.
2443 global gdb_test_timeout
2445 set timeout $gdb_test_timeout
2447 return [eval default_gdb_init $args];
2450 proc gdb_finish { } {
2453 # Exit first, so that the files are no longer in use.
2456 if { [llength $cleanfiles] > 0 } {
2457 eval remote_file target delete $cleanfiles
2463 set debug_format "unknown"
2465 # Run the gdb command "info source" and extract the debugging format
2466 # information from the output and save it in debug_format.
2468 proc get_debug_format { } {
2474 set debug_format "unknown"
2475 send_gdb "info source\n"
2477 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
2478 set debug_format $expect_out(1,string)
2479 verbose "debug format is $debug_format"
2482 -re "No current source file.\r\n$gdb_prompt $" {
2483 perror "get_debug_format used when no current source file"
2486 -re "$gdb_prompt $" {
2487 warning "couldn't check debug format (no valid response)."
2491 warning "couldn't check debug format (timed out)."
2497 # Return true if FORMAT matches the debug format the current test was
2498 # compiled with. FORMAT is a shell-style globbing pattern; it can use
2499 # `*', `[...]', and so on.
2501 # This function depends on variables set by `get_debug_format', above.
2503 proc test_debug_format {format} {
2506 return [expr [string match $format $debug_format] != 0]
2509 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
2510 # COFF, stabs, etc). If that format matches the format that the
2511 # current test was compiled with, then the next test is expected to
2512 # fail for any target. Returns 1 if the next test or set of tests is
2513 # expected to fail, 0 otherwise (or if it is unknown). Must have
2514 # previously called get_debug_format.
2515 proc setup_xfail_format { format } {
2516 set ret [test_debug_format $format];
2524 proc gdb_step_for_stub { } {
2527 if ![target_info exists gdb,use_breakpoint_for_stub] {
2528 if [target_info exists gdb_stub_step_command] {
2529 set command [target_info gdb_stub_step_command];
2533 send_gdb "${command}\n";
2536 -re "(main.* at |.*in .*start).*$gdb_prompt" {
2539 -re ".*$gdb_prompt" {
2541 if { $tries == 5 } {
2542 fail "stepping out of breakpoint function";
2545 send_gdb "${command}\n";
2549 fail "stepping out of breakpoint function";
2556 -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" {
2557 set file $expect_out(1,string);
2558 set linenum [expr $expect_out(2,string) + 1];
2559 set breakplace "${file}:${linenum}";
2563 send_gdb "break ${breakplace}\n";
2565 -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" {
2566 set breakpoint $expect_out(1,string);
2568 -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" {
2569 set breakpoint $expect_out(1,string);
2573 send_gdb "continue\n";
2575 -re "Breakpoint ${breakpoint},.*$gdb_prompt" {
2576 gdb_test "delete $breakpoint" ".*" "";
2583 # gdb_get_line_number TEXT [FILE]
2585 # Search the source file FILE, and return the line number of the
2586 # first line containing TEXT. If no match is found, return -1.
2588 # TEXT is a string literal, not a regular expression.
2590 # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is
2591 # specified, and does not start with "/", then it is assumed to be in
2592 # "$srcdir/$subdir". This is awkward, and can be fixed in the future,
2593 # by changing the callers and the interface at the same time.
2594 # In particular: gdb.base/break.exp, gdb.base/condbreak.exp,
2595 # gdb.base/ena-dis-br.exp.
2597 # Use this function to keep your test scripts independent of the
2598 # exact line numbering of the source file. Don't write:
2600 # send_gdb "break 20"
2602 # This means that if anyone ever edits your test's source file,
2603 # your test could break. Instead, put a comment like this on the
2604 # source file line you want to break at:
2606 # /* breakpoint spot: frotz.exp: test name */
2608 # and then write, in your test script (which we assume is named
2611 # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
2613 # (Yes, Tcl knows how to handle the nested quotes and brackets.
2616 # % puts "foo [lindex "bar baz" 1]"
2619 # Tcl is quite clever, for a little stringy language.)
2623 # The previous implementation of this procedure used the gdb search command.
2624 # This version is different:
2626 # . It works with MI, and it also works when gdb is not running.
2628 # . It operates on the build machine, not the host machine.
2630 # . For now, this implementation fakes a current directory of
2631 # $srcdir/$subdir to be compatible with the old implementation.
2632 # This will go away eventually and some callers will need to
2635 # . The TEXT argument is literal text and matches literally,
2636 # not a regular expression as it was before.
2638 # . State changes in gdb, such as changing the current file
2639 # and setting $_, no longer happen.
2641 # After a bit of time we can forget about the differences from the
2642 # old implementation.
2644 # --chastain 2004-08-05
2646 proc gdb_get_line_number { text { file "" } } {
2651 if { "$file" == "" } then {
2654 if { ! [regexp "^/" "$file"] } then {
2655 set file "$srcdir/$subdir/$file"
2658 if { [ catch { set fd [open "$file"] } message ] } then {
2664 for { set line 1 } { 1 } { incr line } {
2665 if { [ catch { set nchar [gets "$fd" body] } message ] } then {
2669 if { $nchar < 0 } then {
2672 if { [string first "$text" "$body"] >= 0 } then {
2678 if { [ catch { close "$fd" } message ] } then {
2686 # gdb_continue_to_end:
2687 # The case where the target uses stubs has to be handled specially. If a
2688 # stub is used, we set a breakpoint at exit because we cannot rely on
2689 # exit() behavior of a remote target.
2691 # mssg is the error message that gets printed.
2693 proc gdb_continue_to_end {mssg} {
2694 if [target_info exists use_gdb_stub] {
2695 if {![gdb_breakpoint "exit"]} {
2698 gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \
2699 "continue until exit at $mssg"
2701 # Continue until we exit. Should not stop again.
2702 # Don't bother to check the output of the program, that may be
2703 # extremely tough for some remote systems.
2704 gdb_test "continue"\
2705 "Continuing.\[\r\n0-9\]+(... EXIT code 0\[\r\n\]+|Program exited normally\\.).*"\
2706 "continue until exit at $mssg"
2710 proc rerun_to_main {} {
2713 if [target_info exists use_gdb_stub] {
2716 -re ".*Breakpoint .*main .*$gdb_prompt $"\
2717 {pass "rerun to main" ; return 0}
2718 -re "$gdb_prompt $"\
2719 {fail "rerun to main" ; return 0}
2720 timeout {fail "(timeout) rerun to main" ; return 0}
2725 -re "The program .* has been started already.*y or n. $" {
2729 -re "Starting program.*$gdb_prompt $"\
2730 {pass "rerun to main" ; return 0}
2731 -re "$gdb_prompt $"\
2732 {fail "rerun to main" ; return 0}
2733 timeout {fail "(timeout) rerun to main" ; return 0}
2738 # Print a message and return true if a test should be skipped
2739 # due to lack of floating point suport.
2741 proc gdb_skip_float_test { msg } {
2742 if [target_info exists gdb,skip_float_tests] {
2743 verbose "Skipping test '$msg': no float tests.";
2749 # Print a message and return true if a test should be skipped
2750 # due to lack of stdio support.
2752 proc gdb_skip_stdio_test { msg } {
2753 if [target_info exists gdb,noinferiorio] {
2754 verbose "Skipping test '$msg': no inferior i/o.";
2760 proc gdb_skip_bogus_test { msg } {
2764 # Return true if a test should be skipped due to lack of XML support
2766 # NOTE: This must be called while gdb is *not* running.
2768 proc gdb_skip_xml_test { } {
2771 global xml_missing_cached
2773 if {[info exists xml_missing_cached]} {
2774 return $xml_missing_cached
2778 set xml_missing_cached 0
2779 gdb_test_multiple "set tdesc filename ${srcdir}/gdb.xml/trivial.xml" "" {
2780 -re ".*XML support was disabled at compile time.*$gdb_prompt $" {
2781 set xml_missing_cached 1
2783 -re ".*$gdb_prompt $" { }
2786 return $xml_missing_cached
2789 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
2790 # ${binfile}.dbglnk, which is just like the executable ($binfile) but without
2791 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
2792 # the name of a debuginfo only file. This file will be stored in the
2793 # gdb.base/.debug subdirectory.
2795 # Functions for separate debug info testing
2797 # starting with an executable:
2798 # foo --> original executable
2800 # at the end of the process we have:
2801 # foo.stripped --> foo w/o debug info
2802 # .debug/foo.debug --> foo's debug info
2803 # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug.
2805 # Return the name of the file in which we should stor EXEC's separated
2806 # debug info. EXEC contains the full path.
2807 proc separate_debug_filename { exec } {
2809 # In a .debug subdirectory off the same directory where the testcase
2810 # executable is going to be. Something like:
2811 # <your-path>/gdb/testsuite/gdb.base/.debug/blah.debug.
2812 # This is the default location where gdb expects to findi
2813 # the debug info file.
2815 set exec_dir [file dirname $exec]
2816 set exec_file [file tail $exec]
2817 set debug_dir [file join $exec_dir ".debug"]
2818 set debug_file [file join $debug_dir "${exec_file}.debug"]
2823 # Return the build-id hex string (usually 160 bits as 40 hex characters)
2824 # converted to the form: .build-id/ab/cdef1234...89.debug
2825 # Return "" if no build-id found.
2826 proc build_id_debug_filename_get { exec } {
2827 set tmp "${exec}-tmp"
2828 set objcopy_program [transform objcopy]
2830 set result [catch "exec $objcopy_program -j .note.gnu.build-id -O binary $exec $tmp" output]
2831 verbose "result is $result"
2832 verbose "output is $output"
2837 fconfigure $fi -translation binary
2838 # Skip the NOTE header.
2843 if ![string compare $data ""] then {
2846 # Convert it to hex.
2847 binary scan $data H* data
2848 regsub {^..} $data {\0/} data
2849 return ".build-id/${data}.debug";
2852 # Create stripped files for DEST, replacing it. If ARGS is passed, it is a
2853 # list of optional flags. The only currently supported flag is no-main,
2854 # which removes the symbol entry for main from the separate debug file.
2856 proc gdb_gnu_strip_debug { dest args } {
2858 set debug_file [separate_debug_filename $dest]
2859 set strip_to_file_program [transform strip]
2860 set objcopy_program [transform objcopy]
2862 # Make sure the directory that will hold the separated debug
2863 # info actually exists.
2864 set debug_dir [file dirname $debug_file]
2865 if {! [file isdirectory $debug_dir]} {
2866 file mkdir $debug_dir
2869 set debug_link [file tail $debug_file]
2870 set stripped_file "${dest}.stripped"
2872 # Get rid of the debug info, and store result in stripped_file
2873 # something like gdb/testsuite/gdb.base/blah.stripped.
2874 set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
2875 verbose "result is $result"
2876 verbose "output is $output"
2881 # Workaround PR binutils/10802:
2882 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
2883 set perm [file attributes ${dest} -permissions]
2884 file attributes ${stripped_file} -permissions $perm
2886 # Get rid of everything but the debug info, and store result in debug_file
2887 # This will be in the .debug subdirectory, see above.
2888 set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
2889 verbose "result is $result"
2890 verbose "output is $output"
2895 # If no-main is passed, strip the symbol for main from the separate
2896 # file. This is to simulate the behavior of elfutils's eu-strip, which
2897 # leaves the symtab in the original file only. There's no way to get
2898 # objcopy or strip to remove the symbol table without also removing the
2899 # debugging sections, so this is as close as we can get.
2900 if { [llength $args] == 1 && [lindex $args 0] == "no-main" } {
2901 set result [catch "exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp" output]
2902 verbose "result is $result"
2903 verbose "output is $output"
2907 file delete "${debug_file}"
2908 file rename "${debug_file}-tmp" "${debug_file}"
2911 # Link the two previous output files together, adding the .gnu_debuglink
2912 # section to the stripped_file, containing a pointer to the debug_file,
2913 # save the new file in dest.
2914 # This will be the regular executable filename, in the usual location.
2915 set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
2916 verbose "result is $result"
2917 verbose "output is $output"
2922 # Workaround PR binutils/10802:
2923 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
2924 set perm [file attributes ${stripped_file} -permissions]
2925 file attributes ${dest} -permissions $perm
2930 # Test the output of GDB_COMMAND matches the pattern obtained
2931 # by concatenating all elements of EXPECTED_LINES. This makes
2932 # it possible to split otherwise very long string into pieces.
2933 # If third argument is not empty, it's used as the name of the
2934 # test to be printed on pass/fail.
2935 proc help_test_raw { gdb_command expected_lines args } {
2936 set message $gdb_command
2937 if [llength $args]>0 then {
2938 set message [lindex $args 0]
2940 set expected_output [join $expected_lines ""]
2941 gdb_test "${gdb_command}" "${expected_output}" $message
2944 # Test the output of "help COMMNAD_CLASS". EXPECTED_INITIAL_LINES
2945 # are regular expressions that should match the beginning of output,
2946 # before the list of commands in that class. The presence of
2947 # command list and standard epilogue will be tested automatically.
2948 proc test_class_help { command_class expected_initial_lines args } {
2950 "List of commands\:.*\[\r\n\]+"
2951 "Type \"help\" followed by command name for full documentation\.\[\r\n\]+"
2952 "Type \"apropos word\" to search for commands related to \"word\"\.[\r\n\]+"
2953 "Command name abbreviations are allowed if unambiguous\."
2955 set l_entire_body [concat $expected_initial_lines $l_stock_body]
2957 eval [list help_test_raw "help ${command_class}" $l_entire_body] $args
2960 # COMMAND_LIST should have either one element -- command to test, or
2961 # two elements -- abbreviated command to test, and full command the first
2962 # element is abbreviation of.
2963 # The command must be a prefix command. EXPECTED_INITIAL_LINES
2964 # are regular expressions that should match the beginning of output,
2965 # before the list of subcommands. The presence of
2966 # subcommand list and standard epilogue will be tested automatically.
2967 proc test_prefix_command_help { command_list expected_initial_lines args } {
2968 set command [lindex $command_list 0]
2969 if {[llength $command_list]>1} {
2970 set full_command [lindex $command_list 1]
2972 set full_command $command
2974 # Use 'list' and not just {} because we want variables to
2975 # be expanded in this list.
2976 set l_stock_body [list\
2977 "List of $full_command subcommands\:.*\[\r\n\]+"\
2978 "Type \"help $full_command\" followed by $full_command subcommand name for full documentation\.\[\r\n\]+"\
2979 "Type \"apropos word\" to search for commands related to \"word\"\.\[\r\n\]+"\
2980 "Command name abbreviations are allowed if unambiguous\."]
2981 set l_entire_body [concat $expected_initial_lines $l_stock_body]
2982 if {[llength $args]>0} {
2983 help_test_raw "help ${command}" $l_entire_body [lindex $args 0]
2985 help_test_raw "help ${command}" $l_entire_body
2989 # Build executable named EXECUTABLE, from SOURCES. If SOURCES are not
2990 # provided, uses $EXECUTABLE.c. The TESTNAME paramer is the name of test
2991 # to pass to untested, if something is wrong. OPTIONS are passed
2992 # to gdb_compile directly.
2993 proc build_executable { testname executable {sources ""} {options {debug}} } {
2998 if {[llength $sources]==0} {
2999 set sources ${executable}.c
3002 set binfile ${objdir}/${subdir}/${executable}
3005 for {set i 0} "\$i<[llength $sources]" {incr i} {
3006 set s [lindex $sources $i]
3007 if { [gdb_compile "${srcdir}/${subdir}/${s}" "${binfile}${i}.o" object $options] != "" } {
3011 lappend objects "${binfile}${i}.o"
3014 if { [gdb_compile $objects "${binfile}" executable $options] != "" } {
3019 if [get_compiler_info ${binfile}] {
3025 # Starts fresh GDB binary and loads EXECUTABLE into GDB. EXECUTABLE is
3026 # the name of binary in ${objdir}/${subdir}.
3027 proc clean_restart { executable } {
3031 set binfile ${objdir}/${subdir}/${executable}
3035 gdb_reinitialize_dir $srcdir/$subdir
3038 if [target_info exists gdb_stub] {
3043 # Prepares for testing, by calling build_executable, and then clean_restart.
3044 # Please refer to build_executable for parameter description.
3045 proc prepare_for_testing { testname executable {sources ""} {options {debug}}} {
3047 if {[build_executable $testname $executable $sources $options] == -1} {
3050 clean_restart $executable
3055 proc get_valueof { fmt exp default } {
3058 set test "get valueof \"${exp}\""
3060 gdb_test_multiple "print${fmt} ${exp}" "$test" {
3061 -re "\\$\[0-9\]* = (.*)\[\r\n\]*$gdb_prompt $" {
3062 set val $expect_out(1,string)
3066 fail "$test (timeout)"
3072 proc get_integer_valueof { exp default } {
3075 set test "get integer valueof \"${exp}\""
3077 gdb_test_multiple "print /d ${exp}" "$test" {
3078 -re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" {
3079 set val $expect_out(1,string)
3083 fail "$test (timeout)"
3089 proc get_hexadecimal_valueof { exp default } {
3091 send_gdb "print /x ${exp}\n"
3092 set test "get hexadecimal valueof \"${exp}\""
3094 -re "\\$\[0-9\]* = (0x\[0-9a-zA-Z\]+).*$gdb_prompt $" {
3095 set val $expect_out(1,string)
3100 fail "$test (timeout)"
3106 proc get_sizeof { type default } {
3107 return [get_integer_valueof "sizeof (${type})" $default]
3110 # Log gdb command line and script if requested.
3111 if {[info exists TRANSCRIPT]} {
3112 rename send_gdb real_send_gdb
3113 rename remote_spawn real_remote_spawn
3114 rename remote_close real_remote_close
3116 global gdb_transcript
3117 set gdb_transcript ""
3119 global gdb_trans_count
3120 set gdb_trans_count 1
3122 proc remote_spawn {args} {
3123 global gdb_transcript gdb_trans_count outdir
3125 if {$gdb_transcript != ""} {
3126 close $gdb_transcript
3128 set gdb_transcript [open [file join $outdir transcript.$gdb_trans_count] w]
3129 puts $gdb_transcript [lindex $args 1]
3130 incr gdb_trans_count
3132 return [uplevel real_remote_spawn $args]
3135 proc remote_close {args} {
3136 global gdb_transcript
3138 if {$gdb_transcript != ""} {
3139 close $gdb_transcript
3140 set gdb_transcript ""
3143 return [uplevel real_remote_close $args]
3146 proc send_gdb {args} {
3147 global gdb_transcript
3149 if {$gdb_transcript != ""} {
3150 puts -nonewline $gdb_transcript [lindex $args 0]
3153 return [uplevel real_send_gdb $args]
3157 proc core_find {binfile {deletefiles {}} {arg ""}} {
3158 global objdir subdir
3160 set destcore "$binfile.core"
3161 file delete $destcore
3163 # Create a core file named "$destcore" rather than just "core", to
3164 # avoid problems with sys admin types that like to regularly prune all
3165 # files named "core" from the system.
3167 # Arbitrarily try setting the core size limit to "unlimited" since
3168 # this does not hurt on systems where the command does not work and
3169 # allows us to generate a core on systems where it does.
3171 # Some systems append "core" to the name of the program; others append
3172 # the name of the program to "core"; still others (like Linux, as of
3173 # May 2003) create cores named "core.PID". In the latter case, we
3174 # could have many core files lying around, and it may be difficult to
3175 # tell which one is ours, so let's run the program in a subdirectory.
3177 set coredir "${objdir}/${subdir}/coredir.[getpid]"
3179 catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile} ${arg}; true) >/dev/null 2>&1\""
3180 # remote_exec host "${binfile}"
3181 foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
3182 if [remote_file build exists $i] {
3183 remote_exec build "mv $i $destcore"
3187 # Check for "core.PID".
3188 if { $found == 0 } {
3189 set names [glob -nocomplain -directory $coredir core.*]
3190 if {[llength $names] == 1} {
3191 set corefile [file join $coredir [lindex $names 0]]
3192 remote_exec build "mv $corefile $destcore"
3196 if { $found == 0 } {
3197 # The braindamaged HPUX shell quits after the ulimit -c above
3198 # without executing ${binfile}. So we try again without the
3199 # ulimit here if we didn't find a core file above.
3200 # Oh, I should mention that any "braindamaged" non-Unix system has
3201 # the same problem. I like the cd bit too, it's really neat'n stuff.
3202 catch "system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\""
3203 foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" {
3204 if [remote_file build exists $i] {
3205 remote_exec build "mv $i $destcore"
3211 # Try to clean up after ourselves.
3212 foreach deletefile $deletefiles {
3213 remote_file build delete [file join $coredir $deletefile]
3215 remote_exec build "rmdir $coredir"
3217 if { $found == 0 } {
3218 warning "can't generate a core file - core tests suppressed - check ulimit -c"