1 # Copyright
1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
2 #
2002, 2003, 2004, 2005
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
2 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
, write to the Free Software
17 # Foundation
, Inc.
, 59 Temple Place
- Suite
330, Boston
, MA
02111-1307, USA.
19 # This file was written by Fred Fish.
(fnf@cygnus.com
)
21 # Generic gdb subroutines that should work
for any target.
If these
22 # need to be modified
for any target
, it can be done with a
variable
23 # or by passing arguments.
29 if [info exists TOOL_EXECUTABLE
] {
30 set GDB $TOOL_EXECUTABLE
;
32 if ![info exists GDB
] {
33 if ![is_remote host
] {
34 set GDB
[findfile $base_dir
/..
/..
/gdb
/gdb
"$base_dir/../../gdb/gdb" [transform gdb]]
36 set GDB
[transform gdb
];
39 verbose
"using GDB = $GDB" 2
42 if ![info exists GDBFLAGS
] {
45 verbose
"using GDBFLAGS = $GDBFLAGS" 2
47 # The
variable gdb_prompt is a regexp which matches the gdb prompt.
48 #
Set it
if it is not already
set.
50 if ![info exists gdb_prompt
] then {
51 set gdb_prompt
"\[(\]gdb\[)\]"
54 # The
variable fullname_syntax_POSIX is a regexp which matches a POSIX
55 # absolute path ie.
/foo
/
56 set fullname_syntax_POSIX
"/.*/"
57 # The
variable fullname_syntax_UNC is a regexp which matches a Windows
58 # UNC path ie.
\\D
\foo\
59 set fullname_syntax_UNC
{\\\\[^
\\]+\\.
+\\}
60 # The
variable fullname_syntax_DOS_CASE is a regexp which matches a
61 # particular DOS case that GDB most likely will output
62 # ie.
\foo\
, but don
't match \\.*\
63 set fullname_syntax_DOS_CASE {\\[^\\].*\\}
64 # The variable fullname_syntax_DOS is a regexp which matches a DOS path
65 # ie. a:\foo\ && a:foo\
66 set fullname_syntax_DOS {[a-zA-Z]:.*\\}
67 # The variable fullname_syntax is a regexp which matches what GDB considers
68 # an absolute path. It is currently debatable if the Windows style paths
69 # d:foo and \abc should be considered valid as an absolute path.
70 # Also, the purpse of this regexp is not to recognize a well formed
71 # absolute path, but to say with certainty that a path is absolute.
72 set fullname_syntax "($fullname_syntax_POSIX|$fullname_syntax_UNC|$fullname_syntax_DOS_CASE|$fullname_syntax_DOS)"
74 # Needed for some tests under Cygwin.
78 if ![info exists env(EXEEXT)] {
81 set EXEEXT $env(EXEEXT)
84 ### Only procedures should come after this point.
87 # gdb_version -- extract and print the version number of GDB
89 proc default_gdb_version {} {
93 set fileid [open "gdb_cmd" w];
96 set cmdfile [remote_download host "gdb_cmd"];
97 set output [remote_exec host "$GDB -nw --command $cmdfile"]
98 remote_file build delete "gdb_cmd";
99 remote_file host delete "$cmdfile";
100 set tmp [lindex $output 1];
102 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
103 if ![is_remote host] {
104 clone_output "[which $GDB] version $version $GDBFLAGS\n"
106 clone_output "$GDB on remote host version $version $GDBFLAGS\n"
110 proc gdb_version { } {
111 return [default_gdb_version];
115 # gdb_unload -- unload a file if one is loaded
124 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
125 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
126 -re "A program is being debugged already..*Kill it.*y or n. $"\
128 verbose "\t\tKilling previous program being debugged"
131 -re "Discard symbol table from .*y or n.*$" {
135 -re "$gdb_prompt $" {}
137 perror "couldn't unload file in $GDB
(timed out
).
"
143 # Many of the tests depend
on setting breakpoints at various places and
144 # running until that breakpoint is reached. At times
, we want to start
145 # with a clean
-slate with respect to breakpoints
, so this utility proc
146 # lets us
do this without duplicating this code everywhere.
149 proc delete_breakpoints
{} {
152 # we need a larger timeout value here or this thing just confuses
153 # itself. May need a better implementation
if possible.
- guo
155 send_gdb
"delete breakpoints\n"
157 -re
"Delete all breakpoints.*y or n.*$" {
161 -re
"$gdb_prompt $" { # This happens if there were no breakpoints
163 timeout
{ perror
"Delete all breakpoints in delete_breakpoints (timeout)" ; return }
165 send_gdb
"info breakpoints\n"
167 -re
"No breakpoints or watchpoints..*$gdb_prompt $" {}
168 -re
"$gdb_prompt $" { perror "breakpoints not deleted" ; return }
169 -re
"Delete all breakpoints.*or n.*$" {
173 timeout
{ perror
"info breakpoints (timeout)" ; return }
179 # Generic run command.
181 # The second pattern below matches up to the first newline
*only
*.
182 # Using ``.
*$
'' could swallow up output that we attempt to match
185 proc gdb_run_cmd
{args} {
188 if [target_info
exists gdb_init_command
] {
189 send_gdb
"[target_info gdb_init_command]\n";
191 -re
"$gdb_prompt $" { }
193 perror
"gdb_init_command for target failed";
199 if [target_info
exists use_gdb_stub
] {
200 if [target_info
exists gdb
,do_reload_on_run
] {
201 # Specifying no file
, defaults to the executable
202 # currently being debugged.
203 if { [gdb_load
""] != 0 } {
206 send_gdb
"continue\n";
208 -re
"Continu\[^\r\n\]*\[\r\n\]" {}
214 if [target_info
exists gdb
,start_symbol
] {
215 set start
[target_info gdb
,start_symbol
];
219 send_gdb
"jump *$start\n"
221 while { $start_attempt
} {
222 # Cap
(re
)start attempts at three to ensure that this loop
223 # always eventually fails. Don
't worry about trying to be
224 # clever and not send a command when it has failed.
225 if [expr $start_attempt > 3] {
226 perror "Jump to start() failed (retry count exceeded)";
229 set start_attempt [expr $start_attempt + 1];
231 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
234 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
235 perror "Can't find start symbol to run in gdb_run
";
238 -re
"No symbol \"start\" in current.*$gdb_prompt $" {
239 send_gdb
"jump *_start\n";
241 -re
"No symbol.*context.*$gdb_prompt $" {
244 -re
"Line.* Jump anyway.*y or n. $" {
247 -re
"The program is not being run.*$gdb_prompt $" {
248 if { [gdb_load
""] != 0 } {
251 send_gdb
"jump *$start\n";
254 perror
"Jump to start() failed (timeout)";
259 if [target_info
exists gdb_stub
] {
261 -re
"$gdb_prompt $" {
262 send_gdb
"continue\n"
269 if [target_info
exists gdb
,do_reload_on_run
] {
270 if { [gdb_load
""] != 0 } {
274 send_gdb
"run $args\n"
275 # This doesn
't work quite right yet.
277 -re "The program .* has been started already.*y or n. $" {
281 -re "Starting program: \[^\r\n\]*" {}
285 # Set a breakpoint at FUNCTION. If there is an additional argument it is
286 # a list of options; the only currently supported option is allow-pending.
288 proc gdb_breakpoint { function args } {
292 set pending_response n
293 if {[lsearch -exact [lindex $args 0] allow-pending] != -1} {
294 set pending_response y
297 send_gdb "break $function\n"
298 # The first two regexps are what we get with -g, the third is without -g.
300 -re "Breakpoint \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
301 -re "Breakpoint \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
302 -re "Breakpoint \[0-9\]* at .*$gdb_prompt $" {}
303 -re "Breakpoint \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" {
304 if {$pending_response == "n"} {
305 fail "setting breakpoint at $function"
309 -re "Make breakpoint pending.*y or \\\[n\\\]. $" {
310 send_gdb "$pending_response\n"
313 -re "$gdb_prompt $" { fail "setting breakpoint at $function" ; return 0 }
314 timeout { fail "setting breakpoint at $function (timeout)" ; return 0 }
319 # Set breakpoint at function and run gdb until it breaks there.
320 # Since this is the only breakpoint that will be set, if it stops
321 # at a breakpoint, we will assume it is the one we want. We can't
322 # just compare to
"function" because it might be a fully qualified,
323 # single quoted C
++ function specifier.
If there
's an additional argument,
324 # pass it to gdb_breakpoint.
326 proc runto { function args } {
332 if ![gdb_breakpoint $function [lindex $args 0]] {
338 # the "at foo.c:36" output we get with -g.
339 # the "in func" output we get without -g.
341 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
344 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
347 -re "$gdb_prompt $" {
348 fail "running to $function in runto"
352 fail "running to $function in runto (timeout)"
360 # runto_main -- ask gdb to run until we hit a breakpoint at main.
361 # The case where the target uses stubs has to be handled
362 # specially--if it uses stubs, assuming we hit
363 # breakpoint() and just step out of the function.
365 proc runto_main { } {
369 if ![target_info exists gdb_stub] {
381 ### Continue, and expect to hit a breakpoint.
382 ### Report a pass or fail, depending on whether it seems to have
383 ### worked. Use NAME as part of the test name; each call to
384 ### continue_to_breakpoint should use a NAME which is unique within
386 proc gdb_continue_to_breakpoint {name} {
388 set full_name "continue to breakpoint: $name"
390 send_gdb "continue\n"
392 -re "Breakpoint .* at .*\r\n$gdb_prompt $" {
395 -re ".*$gdb_prompt $" {
399 fail "$full_name (timeout)"
405 # gdb_internal_error_resync:
407 # Answer the questions GDB asks after it reports an internal error
408 # until we get back to a GDB prompt. Decline to quit the debugging
409 # session, and decline to create a core file. Return non-zero if the
412 # This procedure just answers whatever questions come up until it sees
413 # a GDB prompt; it doesn't require you to have matched the input up to
414 #
any specific point. However
, it only answers questions it sees in
415 # the output itself
, so
if you
've matched a question, you had better
416 # answer it yourself before calling this.
418 # You can use this function thus:
422 # -re ".*A problem internal to GDB has been detected" {
423 # gdb_internal_error_resync
428 proc gdb_internal_error_resync {} {
432 while {$count < 10} {
434 -re "Quit this debugging session\\? \\(y or n\\) $" {
438 -re "Create a core file of GDB\\? \\(y or n\\) $" {
442 -re "$gdb_prompt $" {
443 # We're resynchronized.
447 perror
"Could not resync from internal error (timeout)"
452 perror
"Could not resync from internal error (resync count exceeded)"
457 # gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS
458 # Send a command to gdb
; test the result.
460 # COMMAND is the command to
execute, send to GDB with send_gdb.
If
461 # this is the null string no command is sent.
462 # MESSAGE is a message to be printed with the built
-in failure patterns
463 #
if one of them matches.
If MESSAGE is empty COMMAND will be used.
464 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
465 # patterns. Pattern elements will be evaluated in the caller
's
466 # context; action elements will be executed in the caller's
context.
467 # Unlike patterns
for gdb_test
, these patterns should generally
include
468 # the final newline and prompt.
471 #
1 if the test failed
, according to a built
-in failure pattern
472 #
0 if only user
-supplied patterns matched
473 #
-1 if there was an internal error.
475 # You can use this function thus
:
477 # gdb_test_multiple
"print foo" "test foo" {
478 #
-re
"expected output 1" {
481 #
-re
"expected output 2" {
486 # The standard patterns
, such as
"Program exited..." and "A problem
487 # ...
", all being implicitly appended to that list.
489 proc gdb_test_multiple
{ command message user_code
} {
493 upvar timeout timeout
494 upvar expect_out expect_out
496 if { $message
== "" } {
500 # TCL
/EXPECT WART ALERT
501 # Expect does something very strange when it receives a single braced
502 #
argument. It splits it along word separators and performs substitutions.
503 # This means that
{ "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
504 # evaluated as
"\[ab\]". But that's not how TCL normally works; inside a
505 # double
-quoted list item
, "\[ab\]" is just a long way of representing
506 #
"[ab]", because the backslashes will be removed by lindex.
508 # Unfortunately
, there appears to be no easy way to duplicate the splitting
509 # that expect will
do from within TCL. And many places make use of the
510 #
"\[0-9\]" construct, so we need to support that; and some places make use
511 # of the
"[func]" construct, so we need to support that too. In order to
512 #
get this right we have to substitute quoted list elements differently
513 # from braced list elements.
515 # We
do this roughly the same way that Expect does it. We have to use two
516 # lists
, because
if we leave unquoted newlines in the
argument to uplevel
517 # they
'll be treated as command separators, and if we escape newlines
518 # we mangle newlines inside of command blocks. This assumes that the
519 # input doesn't contain a pattern which contains actual embedded newlines
522 regsub
-all
{\n} $
{user_code
} { } subst_code
523 set subst_code
[uplevel list $subst_code
]
525 set processed_code
""
527 set expecting_action
0
528 foreach item $user_code subst_item $subst_code
{
529 if { $item
== "-n" || $item == "-notransfer" || $item == "-nocase" } {
530 lappend processed_code $item
533 if {$item
== "-indices" || $item == "-re" || $item == "-ex"} {
534 lappend processed_code $item
537 if { $expecting_action
} {
538 lappend processed_code
"uplevel [list $item]"
539 set expecting_action
0
540 # Cosmetic
, no effect
on the list.
541 append processed_code
"\n"
544 set expecting_action
1
545 lappend processed_code $subst_item
546 if {$patterns
!= ""} {
549 append patterns
"\"$subst_item\""
552 # Also purely cosmetic.
553 regsub
-all
{\r} $patterns
{\\r
} patterns
554 regsub
-all
{\n} $patterns
{\\n
} patterns
557 send_user
"Sending \"$command\" to gdb\n"
558 send_user
"Looking to match \"$patterns\"\n"
559 send_user
"Message is \"$message\"\n"
563 set string
"${command}\n";
564 if { $command
!= "" } {
565 while { "$string" != "" } {
566 set foo
[string first
"\n" "$string"];
567 set len
[string length
"$string"];
568 if { $foo
< [expr $len
- 1] } {
569 set str
[string range
"$string" 0 $foo];
570 if { [send_gdb
"$str"] != "" } {
571 global suppress_flag
;
573 if { ! $suppress_flag
} {
574 perror
"Couldn't send $command to GDB.";
579 # since we
're checking if each line of the multi-line
580 # command are 'accepted
' by GDB here,
581 # we need to set -notransfer expect option so that
582 # command output is not lost for pattern matching
585 -notransfer -re "\[\r\n\]" { verbose "partial: match" 3 }
586 timeout { verbose "partial: timeout" 3 }
588 set string [string range "$string" [expr $foo + 1] end];
593 if { "$string" != "" } {
594 if { [send_gdb "$string"] != "" } {
595 global suppress_flag;
597 if { ! $suppress_flag } {
598 perror "Couldn't send $command to GDB.
";
606 if [target_info
exists gdb
,timeout
] {
607 set tmt
[target_info gdb
,timeout
];
609 if [info exists timeout
] {
613 if [info exists timeout
] {
622 -re
".*A problem internal to GDB has been detected" {
623 fail
"$message (GDB internal error)"
624 gdb_internal_error_resync
626 -re
"\\*\\*\\* DOSEXIT code.*" {
627 if { $message
!= "" } {
630 gdb_suppress_entire_file
"GDB died";
633 -re
"Ending remote debugging.*$gdb_prompt $" {
634 if ![isnative
] then {
635 warning
"Can`t communicate to remote target."
642 append code $processed_code
644 -re
"Undefined\[a-z\]* command:.*$gdb_prompt $" {
645 perror
"Undefined command \"$command\"."
649 -re
"Ambiguous command.*$gdb_prompt $" {
650 perror
"\"$command\" is not a unique command name."
654 -re
"Program exited with code \[0-9\]+.*$gdb_prompt $" {
655 if ![string match
"" $message] then {
656 set errmsg
"$message (the program exited)"
658 set errmsg
"$command (the program exited)"
663 -re
"EXIT code \[0-9\r\n\]+Program exited normally.*$gdb_prompt $" {
664 if ![string match
"" $message] then {
665 set errmsg
"$message (the program exited)"
667 set errmsg
"$command (the program exited)"
672 -re
"The program is not being run.*$gdb_prompt $" {
673 if ![string match
"" $message] then {
674 set errmsg
"$message (the program is no longer running)"
676 set errmsg
"$command (the program is no longer running)"
681 -re
"\r\n$gdb_prompt $" {
682 if ![string match
"" $message] then {
689 perror
"Window too small."
693 -re
"\\(y or n\\) " {
695 perror
"Got interactive prompt."
700 perror
"Process no longer exists"
701 if { $message
!= "" } {
707 perror
"internal buffer is full."
712 if ![string match
"" $message] then {
713 fail
"$message (timeout)"
720 set code
[catch
{gdb_expect $tmt $code
} string
]
722 global errorInfo errorCode
;
723 return -code error
-errorinfo $errorInfo
-errorcode $errorCode $string
724 } elseif
{$code
== 2} {
725 return -code
return $string
726 } elseif
{$code
== 3} {
728 } elseif
{$code
> 4} {
729 return -code $code $string
734 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
735 # Send a command to gdb
; test the result.
737 # COMMAND is the command to
execute, send to GDB with send_gdb.
If
738 # this is the null string no command is sent.
739 # PATTERN is the pattern to match
for a PASS
, and must NOT
include
740 # the
\r\n sequence immediately before the gdb prompt.
741 # MESSAGE is an optional message to be printed.
If this is
742 # omitted
, then the pass
/fail messages use the command string as the
743 # message.
(If this is the empty string
, then sometimes we don
't
744 # call pass or fail at all; I don't understand this at all.
)
745 # QUESTION is a question GDB may ask in response to COMMAND
, like
747 # RESPONSE is the response to send
if QUESTION appears.
750 #
1 if the test failed
,
751 #
0 if the test passes
,
752 #
-1 if there was an internal error.
754 proc gdb_test
{ args } {
758 upvar timeout timeout
760 if [llength $
args]>2 then {
761 set message
[lindex $
args 2]
763 set message
[lindex $
args 0]
765 set command
[lindex $
args 0]
766 set pattern
[lindex $
args 1]
768 if [llength $
args]==5 {
769 set question_string
[lindex $
args 3];
770 set response_string
[lindex $
args 4];
772 set question_string
"^FOOBAR$"
775 return [gdb_test_multiple $command $message
{
776 -re
"\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
777 if ![string match
"" $message] then {
781 -re
"(${question_string})$" {
782 send_gdb
"$response_string\n";
788 # Test that a command gives an error.
For pass or fail
, return
789 # a
1 to indicate that more tests can proceed. However a timeout
790 # is a serious error
, generates a special fail message
, and causes
791 # a
0 to be returned to indicate that more tests are likely to fail
794 proc test_print_reject
{ args } {
798 if [llength $
args]==2 then {
799 set expectthis
[lindex $
args 1]
801 set expectthis
"should never match this bogus string"
803 set sendthis
[lindex $
args 0]
805 send_user
"Sending \"$sendthis\" to gdb\n"
806 send_user
"Looking to match \"$expectthis\"\n"
808 send_gdb
"$sendthis\n"
809 #FIXME
: Should add timeout as parameter.
811 -re
"A .* in expression.*\\.*$gdb_prompt $" {
812 pass
"reject $sendthis"
815 -re
"Invalid syntax in expression.*$gdb_prompt $" {
816 pass
"reject $sendthis"
819 -re
"Junk after end of expression.*$gdb_prompt $" {
820 pass
"reject $sendthis"
823 -re
"Invalid number.*$gdb_prompt $" {
824 pass
"reject $sendthis"
827 -re
"Invalid character constant.*$gdb_prompt $" {
828 pass
"reject $sendthis"
831 -re
"No symbol table is loaded.*$gdb_prompt $" {
832 pass
"reject $sendthis"
835 -re
"No symbol .* in current context.*$gdb_prompt $" {
836 pass
"reject $sendthis"
839 -re
"Unmatched single quote.*$gdb_prompt $" {
840 pass
"reject $sendthis"
843 -re
"A character constant must contain at least one character.*$gdb_prompt $" {
844 pass
"reject $sendthis"
847 -re
"$expectthis.*$gdb_prompt $" {
848 pass
"reject $sendthis"
851 -re
".*$gdb_prompt $" {
852 fail
"reject $sendthis"
856 fail
"reject $sendthis (eof or timeout)"
862 # Given an input string
, adds backslashes as needed to create a
863 # regexp that will match the string.
865 proc string_to_regexp
{str
} {
867 regsub
-all
{[]*+.|
()^$\
[\\]} $str
{\\&} result
871 # Same as gdb_test
, but the second parameter is not a regexp
,
872 # but a string that must match exactly.
874 proc gdb_test_exact
{ args } {
875 upvar timeout timeout
877 set command
[lindex $
args 0]
879 # This applies a special meaning to a null string pattern. Without
880 # this
, "$pattern\r\n$gdb_prompt $" will match anything, including error
881 # messages from commands that should have no output except a new
882 # prompt. With this
, only results of a null string will match a null
885 set pattern
[lindex $
args 1]
886 if [string match $pattern
""] {
887 set pattern
[string_to_regexp
[lindex $
args 0]]
889 set pattern
[string_to_regexp
[lindex $
args 1]]
892 # It is most natural to write the pattern
argument with only
893 # embedded
\n's, especially if you are trying to avoid Tcl quoting
894 # problems. But gdb_expect really wants to see \r\n in patterns. So
895 # transform the pattern here. First transform \r\n back to \n, in
896 # case some users of gdb_test_exact already do the right thing.
897 regsub -all "\r\n" $pattern "\n" pattern
898 regsub -all "\n" $pattern "\r\n" pattern
899 if [llength $args]==3 then {
900 set message [lindex $args 2]
905 return [gdb_test $command $pattern $message]
908 proc gdb_reinitialize_dir { subdir } {
911 if [is_remote host] {
916 -re "Reinitialize source path to empty.*y or n. " {
919 -re "Source directories searched.*$gdb_prompt $" {
920 send_gdb "dir $subdir\n"
922 -re "Source directories searched.*$gdb_prompt $" {
923 verbose "Dir set to $subdir"
925 -re "$gdb_prompt $" {
926 perror "Dir \"$subdir\" failed."
930 -re "$gdb_prompt $" {
931 perror "Dir \"$subdir\" failed."
935 -re "$gdb_prompt $" {
936 perror "Dir \"$subdir\" failed."
942 # gdb_exit -- exit the GDB, killing the target program if necessary
944 proc default_gdb_exit {} {
950 gdb_stop_suppressing_tests;
952 if ![info exists gdb_spawn_id] {
956 verbose "Quitting $GDB $GDBFLAGS"
958 if { [is_remote host] && [board_info host exists fileid] } {
965 -re "DOSEXIT code" { }
970 if ![is_remote host] {
976 # Load a file into the debugger.
977 # The return value is 0 for success, -1 for failure.
979 # This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO
980 # to one of these values:
982 # debug file was loaded successfully and has debug information
983 # nodebug file was loaded successfully and has no debug information
984 # fail file was not loaded
986 # I tried returning this information as part of the return value,
987 # but ran into a mess because of the many re-implementations of
988 # gdb_load in config/*.exp.
990 # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use
991 # this if they can get more information set.
993 proc gdb_file_cmd { arg } {
998 # Set whether debug info was found.
1000 global gdb_file_cmd_debug_info
1001 set gdb_file_cmd_debug_info "fail"
1003 if [is_remote host] {
1004 set arg [remote_download host $arg]
1006 perror "download failed"
1011 send_gdb "file $arg\n"
1013 -re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" {
1014 verbose "\t\tLoaded $arg into the $GDB with no debugging symbols"
1015 set gdb_file_cmd_debug_info "nodebug"
1018 -re "Reading symbols from.*done.*$gdb_prompt $" {
1019 verbose "\t\tLoaded $arg into the $GDB"
1020 set gdb_file_cmd_debug_info "debug"
1023 -re "A program is being debugged already.*Kill it.*y or n. $" {
1025 verbose "\t\tKilling previous program being debugged"
1028 -re "Load new symbol table from \".*\".*y or n. $" {
1031 -re "Reading symbols from.*done.*$gdb_prompt $" {
1032 verbose "\t\tLoaded $arg with new symbol table into $GDB"
1033 set gdb_file_cmd_debug_info "debug"
1037 perror "(timeout) Couldn't
load $
arg, other
program already loaded.
"
1042 -re
"No such file or directory.*$gdb_prompt $" {
1043 perror
"($arg) No such file or directory"
1046 -re
"$gdb_prompt $" {
1047 perror
"couldn't load $arg into $GDB."
1051 perror
"couldn't load $arg into $GDB (timed out)."
1055 # This is an attempt to detect a core dump
, but seems not to
1056 # work. Perhaps we need to match .
* followed by eof
, in which
1057 # gdb_expect does not seem to have a way to
do that.
1058 perror
"couldn't load $arg into $GDB (end of file)."
1065 # start gdb
-- start gdb running
, default procedure
1067 # When running over NFS
, particularly
if running many simultaneous
1068 # tests
on different hosts all using the same server
, things can
1069 #
get really slow. Give gdb at least
3 minutes to start up.
1071 proc default_gdb_start
{ } {
1077 global gdb_spawn_id
;
1079 gdb_stop_suppressing_tests
;
1081 verbose
"Spawning $GDB -nw $GDBFLAGS"
1083 if [info exists gdb_spawn_id
] {
1087 if ![is_remote host
] {
1088 if { [which $GDB
] == 0 } then {
1089 perror
"$GDB does not exist."
1093 set res
[remote_spawn host
"$GDB -nw $GDBFLAGS [host_info gdb_opts]"];
1094 if { $res
< 0 || $res
== "" } {
1095 perror
"Spawning $GDB failed."
1099 -re
"\[\r\n\]$gdb_prompt $" {
1100 verbose
"GDB initialized."
1102 -re
"$gdb_prompt $" {
1103 perror
"GDB never initialized."
1107 perror
"(timeout) GDB never initialized after 10 seconds."
1112 set gdb_spawn_id
-1;
1113 # force the height to
"unlimited", so no pagers get used
1115 send_gdb
"set height 0\n"
1117 -re
"$gdb_prompt $" {
1118 verbose
"Setting height to 0." 2
1121 warning
"Couldn't set the height to 0"
1124 # force the width to
"unlimited", so no wraparound occurs
1125 send_gdb
"set width 0\n"
1127 -re
"$gdb_prompt $" {
1128 verbose
"Setting width to 0." 2
1131 warning
"Couldn't set the width to 0."
1137 #
Return a
1 for configurations
for which we don
't even want to try to
1140 proc skip_cplus_tests {} {
1141 if { [istarget "d10v-*-*"] } {
1144 if { [istarget "h8300-*-*"] } {
1148 # The C++ IO streams are too large for HC11/HC12 and are thus not
1149 # available. The gdb C++ tests use them and don't
compile.
1150 if { [istarget
"m6811-*-*"] } {
1153 if { [istarget
"m6812-*-*"] } {
1159 #
Return a
1 if I don
't even want to try to test FORTRAN.
1161 proc skip_fortran_tests {} {
1165 # Run a test on the target to see if it supports vmx hardware. Return 0 if so,
1166 # 1 if it does not. Based on 'check_vmx_hw_available
' from the GCC testsuite.
1168 proc skip_altivec_tests {} {
1169 global skip_vmx_tests_saved
1170 global srcdir subdir gdb_prompt
1172 # Use the cached value, if it exists.
1173 set me "skip_altivec_tests"
1174 if [info exists skip_vmx_tests_saved] {
1175 verbose "$me: returning saved $skip_vmx_tests_saved" 2
1176 return $skip_vmx_tests_saved
1179 # Some simulators are known to not support VMX instructions.
1180 if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } {
1181 verbose "$me: target known to not support VMX, returning 1" 2
1182 return [set $skip_vmx_tests_saved 1]
1185 # Make sure we have a compiler that understands altivec.
1186 set compile_flags {debug nowarnings}
1187 if [get_compiler_info not-used] {
1188 warning "Could not get compiler info"
1191 if [test_compiler_info gcc*] {
1192 set compile_flags "$compile_flags additional_flags=-maltivec"
1193 } elseif [test_compiler_info xlc*] {
1194 set compile_flags "$compile_flags additional_flags=-qaltivec"
1196 verbose "Could not compile with altivec support, returning 1" 2
1200 # Set up, compile, and execute a test program containing VMX instructions.
1201 # Include the current process ID in the file names to prevent conflicts
1202 # with invocations for multiple testsuites.
1206 set f [open $src "w"]
1207 puts $f "int main() {"
1208 puts $f "#ifdef __MACH__"
1209 puts $f " asm volatile (\"vor v0,v0,v0\");"
1211 puts $f " asm volatile (\"vor 0,0,0\");"
1213 puts $f " return 0; }"
1216 verbose "$me: compiling testfile $src" 2
1217 set lines [gdb_compile $src $exe executable $compile_flags]
1220 if ![string match "" $lines] then {
1221 verbose "$me: testfile compilation failed, returning 1" 2
1222 return [set skip_vmx_tests_saved 1]
1225 # No error message, compilation succeeded so now run it via gdb.
1229 gdb_reinitialize_dir $srcdir/$subdir
1233 -re ".*Illegal instruction.*${gdb_prompt} $" {
1234 verbose -log "\n$me altivec hardware not detected"
1235 set skip_vmx_tests_saved 1
1237 -re ".*Program exited normally.*${gdb_prompt} $" {
1238 verbose -log "\n$me: altivec hardware detected"
1239 set skip_vmx_tests_saved 0
1242 warning "\n$me: default case taken"
1243 set skip_vmx_tests_saved 1
1247 remote_file build delete $exe
1249 verbose "$me: returning $skip_vmx_tests_saved" 2
1250 return $skip_vmx_tests_saved
1253 # Skip all the tests in the file if you are not on an hppa running
1256 proc skip_hp_tests {} {
1257 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
1258 verbose "Skip hp tests is $skip_hp"
1262 set compiler_info "unknown"
1264 set hp_cc_compiler 0
1265 set hp_aCC_compiler 0
1267 # Figure out what compiler I am using.
1269 # BINFILE is a "compiler information" output file. This implementation
1270 # does not use BINFILE.
1272 # ARGS can be empty or "C++". If empty, "C" is assumed.
1274 # There are several ways to do this, with various problems.
1276 # [ gdb_compile -E $ifile -o $binfile.ci ]
1277 # source $binfile.ci
1279 # Single Unix Spec v3 says that "-E -o ..." together are not
1280 # specified. And in fact, the native compiler on hp-ux 11 (among
1281 # others) does not work with "-E -o ...". Most targets used to do
1282 # this, and it mostly worked, because it works with gcc.
1284 # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ]
1285 # source $binfile.ci
1287 # This avoids the problem with -E and -o together. This almost works
1288 # if the build machine is the same as the host machine, which is
1289 # usually true of the targets which are not gcc. But this code does
1290 # not figure which compiler to call, and it always ends up using the C
1291 # compiler. Not good for setting hp_aCC_compiler. Targets
1292 # hppa*-*-hpux* and mips*-*-irix* used to do this.
1294 # [ gdb_compile -E $ifile > $binfile.ci ]
1295 # source $binfile.ci
1297 # dejagnu target_compile says that it supports output redirection,
1298 # but the code is completely different from the normal path and I
1299 # don't want to sweep the mines from that path. So I didn
't even try
1302 # set cppout [ gdb_compile $ifile "" preprocess $args quiet ]
1305 # I actually do this for all targets now. gdb_compile runs the right
1306 # compiler, and TCL captures the output, and I eval the output.
1308 # Unfortunately, expect logs the output of the command as it goes by,
1309 # and dejagnu helpfully prints a second copy of it right afterwards.
1310 # So I turn off expect logging for a moment.
1312 # [ gdb_compile $ifile $ciexe_file executable $args ]
1313 # [ remote_exec $ciexe_file ]
1314 # [ source $ci_file.out ]
1316 # I could give up on -E and just do this.
1317 # I didn't
get desperate enough to try this.
1319 #
-- chastain
2004-01-06
1321 proc get_compiler_info
{binfile
args} {
1322 #
For compiler.c and compiler.cc
1325 # I am going to play with the
log to keep noise out.
1329 # These come from compiler.c or compiler.cc
1330 global compiler_info
1332 # Legacy global data symbols.
1334 global hp_cc_compiler
1335 global hp_aCC_compiler
1337 # Choose which file to preprocess.
1338 set ifile
"${srcdir}/lib/compiler.c"
1339 if { [llength $
args] > 0 && [lindex $
args 0] == "c++" } {
1340 set ifile
"${srcdir}/lib/compiler.cc"
1343 # Run $ifile through the right preprocessor.
1344 # Toggle gdb.
log to keep the compiler output out of the
log.
1346 set cppout
[ gdb_compile
"${ifile}" "" preprocess [list "$args" quiet] ]
1347 log_file
-a
"$outdir/$tool.log"
1351 foreach cppline
[ split
"$cppout" "\n" ] {
1352 if { [ regexp
"^#" "$cppline" ] } {
1354 } elseif
{ [ regexp
"^\[\n\r\t \]*$" "$cppline" ] } {
1356 } elseif
{ [ regexp
"^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } {
1358 verbose
"get_compiler_info: $cppline" 2
1362 verbose
-log "get_compiler_info: $cppline"
1367 # Reset to unknown compiler
if any diagnostics happened.
1369 set compiler_info
"unknown"
1372 #
Set the legacy symbols.
1374 set hp_cc_compiler
0
1375 set hp_aCC_compiler
0
1376 if { [regexp
"^gcc-1-" "$compiler_info" ] } { set gcc_compiled 1 }
1377 if { [regexp
"^gcc-2-" "$compiler_info" ] } { set gcc_compiled 2 }
1378 if { [regexp
"^gcc-3-" "$compiler_info" ] } { set gcc_compiled 3 }
1379 if { [regexp
"^gcc-4-" "$compiler_info" ] } { set gcc_compiled 4 }
1380 if { [regexp
"^gcc-5-" "$compiler_info" ] } { set gcc_compiled 5 }
1381 if { [regexp
"^hpcc-" "$compiler_info" ] } { set hp_cc_compiler 1 }
1382 if { [regexp
"^hpacc-" "$compiler_info" ] } { set hp_aCC_compiler 1 }
1384 #
Log what happened.
1385 verbose
-log "get_compiler_info: $compiler_info"
1387 # Most compilers will evaluate comparisons and other
boolean
1388 # operations to
0 or
1.
1389 uplevel \#
0 { set true
1 }
1390 uplevel \#
0 { set false
0 }
1392 # Use of aCC results in
boolean results being displayed as
1394 if { $hp_aCC_compiler
} {
1395 uplevel \#
0 { set true true
}
1396 uplevel \#
0 { set false false
}
1402 proc test_compiler_info
{ {compiler
""} } {
1403 global compiler_info
1405 #
if no
arg, return the compiler_info string
1407 if [string match
"" $compiler] {
1408 if [info exists compiler_info
] {
1409 return $compiler_info
1411 perror
"No compiler info found."
1415 return [string match $compiler $compiler_info
]
1418 set gdb_wrapper_initialized
0
1420 proc gdb_wrapper_init
{ args } {
1421 global gdb_wrapper_initialized
;
1422 global gdb_wrapper_file
;
1423 global gdb_wrapper_flags
;
1425 if { $gdb_wrapper_initialized
== 1 } { return; }
1427 if {[target_info
exists needs_status_wrapper
] && \
1428 [target_info needs_status_wrapper
] != "0"} {
1429 set result
[build_wrapper
"testglue.o"];
1430 if { $result
!= "" } {
1431 set gdb_wrapper_file
[lindex $result
0];
1432 set gdb_wrapper_flags
[lindex $result
1];
1434 warning
"Status wrapper failed to build."
1437 set gdb_wrapper_initialized
1
1440 proc gdb_compile
{source dest type options
} {
1441 global GDB_TESTCASE_OPTIONS
;
1442 global gdb_wrapper_file
;
1443 global gdb_wrapper_flags
;
1444 global gdb_wrapper_initialized
;
1446 # Add platform
-specific options
if a shared library was specified using
1447 #
"shlib=librarypath" in OPTIONS.
1450 foreach opt $options
{
1451 if [regexp
{^shlib
=(.
*)} $opt dummy_var shlib_name
] {
1452 if [test_compiler_info
"xlc-*"] {
1453 # IBM xlc compiler doesn
't accept shared library named other
1454 # than .so: use "-Wl," to bypass this
1455 lappend source "-Wl,$shlib_name"
1457 lappend source $shlib_name
1459 if {$shlib_found == 0} {
1461 if { ([test_compiler_info "gcc-*"]
1462 && ([istarget "powerpc*-*-aix*"]
1463 || [istarget "rs6000*-*-aix*"] )) } {
1464 lappend options "additional_flags=-L${objdir}/${subdir}"
1465 } elseif { [istarget "mips-sgi-irix*"] } {
1466 lappend options "additional_flags=-rpath ${objdir}/${subdir}"
1470 lappend new_options $opt
1473 set options $new_options
1475 if [target_info exists gdb_stub] {
1476 set options2 { "additional_flags=-Dusestubs" }
1477 lappend options "libs=[target_info gdb_stub]";
1478 set options [concat $options2 $options]
1480 if [target_info exists is_vxworks] {
1481 set options2 { "additional_flags=-Dvxworks" }
1482 lappend options "libs=[target_info gdb_stub]";
1483 set options [concat $options2 $options]
1485 if [info exists GDB_TESTCASE_OPTIONS] {
1486 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
1488 verbose "options are $options"
1489 verbose "source is $source $dest $type $options"
1491 if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init }
1493 if {[target_info exists needs_status_wrapper] && \
1494 [target_info needs_status_wrapper] != "0" && \
1495 [info exists gdb_wrapper_file]} {
1496 lappend options "libs=${gdb_wrapper_file}"
1497 lappend options "ldflags=${gdb_wrapper_flags}"
1500 # Replace the "nowarnings" option with the appropriate additional_flags
1501 # to disable compiler warnings.
1502 set nowarnings [lsearch -exact $options nowarnings]
1503 if {$nowarnings != -1} {
1504 if [target_info exists gdb,nowarnings_flag] {
1505 set flag "additional_flags=[target_info gdb,nowarnings_flag]"
1507 set flag "additional_flags=-w"
1509 set options [lreplace $options $nowarnings $nowarnings $flag]
1512 set result [target_compile $source $dest $type $options];
1513 regsub "\[\r\n\]*$" "$result" "" result;
1514 regsub "^\[\r\n\]*" "$result" "" result;
1515 if { $result != "" && [lsearch $options quiet] == -1} {
1516 clone_output "gdb compile failed, $result"
1522 # This is just like gdb_compile, above, except that it tries compiling
1523 # against several different thread libraries, to see which one this
1525 proc gdb_compile_pthreads {source dest type options} {
1527 set why_msg "unrecognized error"
1528 foreach lib {-lpthreads -lpthread -lthread} {
1529 # This kind of wipes out whatever libs the caller may have
1530 # set. Or maybe theirs will override ours. How infelicitous.
1531 set options_with_lib [concat $options [list libs=$lib quiet]]
1532 set ccout [gdb_compile $source $dest $type $options_with_lib]
1533 switch -regexp -- $ccout {
1534 ".*no posix threads support.*" {
1535 set why_msg "missing threads include file"
1538 ".*cannot open -lpthread.*" {
1539 set why_msg "missing runtime threads library"
1541 ".*Can't find library
for -lpthread.
*" {
1542 set why_msg
"missing runtime threads library"
1545 pass
"successfully compiled posix threads test case"
1551 if {!$built_binfile
} {
1552 unsupported
"Couldn't compile $source: ${why_msg}"
1557 # Build a shared library from SOURCES. You must use get_compiler_info
1560 proc gdb_compile_shlib
{sources dest options
} {
1561 set obj_options $options
1563 switch -glob
[test_compiler_info
] {
1565 lappend obj_options
"additional_flags=-qpic"
1568 if { !([istarget
"powerpc*-*-aix*"]
1569 ||
[istarget
"rs6000*-*-aix*"]) } {
1570 lappend obj_options
"additional_flags=-fpic"
1574 switch -glob
[istarget
] {
1576 lappend obj_options
"additional_flags=+z"
1579 # Disable SGI compiler
's implicit -Dsgi
1580 lappend obj_options "additional_flags=-Usgi"
1583 # don't know what the compiler is...
1589 set outdir
[file dirname $dest
]
1591 foreach source $sources
{
1592 set sourcebase
[file tail $source
]
1593 if {[gdb_compile $source
"${outdir}/${sourcebase}.o" object $obj_options] != ""} {
1596 lappend objects $
{outdir
}/$
{sourcebase
}.o
1599 if [istarget
"hppa*-*-hpux*"] {
1600 remote_exec build
"ld -b ${objects} -o ${dest}"
1602 set link_options $options
1603 if [test_compiler_info
"xlc-*"] {
1604 lappend link_options
"additional_flags=-qmkshrobj"
1606 lappend link_options
"additional_flags=-shared"
1608 if {[gdb_compile
"${objects}" "${dest}" executable $link_options] != ""} {
1614 # This is just like gdb_compile_pthreads
, above
, except that we always add the
1615 # objc library
for compiling Objective
-C programs
1616 proc gdb_compile_objc
{source dest type options
} {
1618 set why_msg
"unrecognized error"
1619 foreach lib
{-lobjc
-lpthreads
-lpthread
-lthread solaris
} {
1620 # This kind of wipes out whatever libs the caller may have
1621 #
set. Or maybe theirs will override ours. How infelicitous.
1622 if { $lib
== "solaris" } {
1623 set lib
"-lpthread -lposix4"
1625 if { $lib
!= "-lobjc" } {
1626 set lib
"-lobjc $lib"
1628 set options_with_lib
[concat $options
[list libs
=$lib quiet
]]
1629 set ccout
[gdb_compile $source $dest $type $options_with_lib
]
1630 switch -regexp
-- $ccout
{
1631 ".*no posix threads support.*" {
1632 set why_msg
"missing threads include file"
1635 ".*cannot open -lpthread.*" {
1636 set why_msg
"missing runtime threads library"
1638 ".*Can't find library for -lpthread.*" {
1639 set why_msg
"missing runtime threads library"
1642 pass
"successfully compiled objc with posix threads test case"
1648 if {!$built_binfile
} {
1649 unsupported
"Couldn't compile $source: ${why_msg}"
1654 proc send_gdb
{ string
} {
1655 global suppress_flag
;
1656 if { $suppress_flag
} {
1657 return "suppressed";
1659 return [remote_send host
"$string"];
1665 proc gdb_expect
{ args } {
1666 if { [llength $
args] == 2 && [lindex $
args 0] != "-re" } {
1667 set gtimeout
[lindex $
args 0];
1668 set expcode
[list
[lindex $
args 1]];
1670 upvar timeout timeout
;
1673 if [target_info
exists gdb
,timeout
] {
1674 if [info exists timeout
] {
1675 if { $timeout
< [target_info gdb
,timeout
] } {
1676 set gtimeout
[target_info gdb
,timeout
];
1678 set gtimeout $timeout
;
1681 set gtimeout
[target_info gdb
,timeout
];
1685 if ![info exists gtimeout
] {
1687 if [info exists timeout
] {
1688 set gtimeout $timeout
;
1695 global suppress_flag
;
1696 global remote_suppress_flag
;
1697 if [info exists remote_suppress_flag
] {
1698 set old_val $remote_suppress_flag
;
1700 if [info exists suppress_flag
] {
1701 if { $suppress_flag
} {
1702 set remote_suppress_flag
1;
1706 {uplevel remote_expect host $gtimeout $expcode
} string
];
1707 if [info exists old_val
] {
1708 set remote_suppress_flag $old_val
;
1710 if [info exists remote_suppress_flag
] {
1711 unset remote_suppress_flag
;
1716 global errorInfo errorCode
;
1718 return -code error
-errorinfo $errorInfo
-errorcode $errorCode $string
1719 } elseif
{$code
== 2} {
1720 return -code
return $string
1721 } elseif
{$code
== 3} {
1723 } elseif
{$code
> 4} {
1724 return -code $code $string
1728 # gdb_expect_list MESSAGE SENTINEL LIST
-- expect a sequence of outputs
1730 # Check
for long sequence of output by parts.
1731 # MESSAGE
: is the test message to be printed with the test success
/fail.
1732 # SENTINEL
: Is the terminal pattern indicating that output has finished.
1733 # LIST
: is the sequence of outputs to match.
1734 #
If the sentinel is recognized early
, it is considered an error.
1737 #
1 if the test failed
,
1738 #
0 if the test passes
,
1739 #
-1 if there was an internal error.
1741 proc gdb_expect_list
{test sentinel list
} {
1743 global suppress_flag
1746 if { $suppress_flag
} {
1748 unresolved
"${test}"
1750 while { $
{index
} < [llength $
{list
}] } {
1751 set pattern
[lindex $
{list
} $
{index
}]
1752 set index
[expr $
{index
} + 1]
1753 if { $
{index
} == [llength $
{list
}] } {
1756 -re
"${pattern}${sentinel}" {
1757 # pass
"${test}, pattern ${index} + sentinel"
1760 fail
"${test} (pattern ${index} + sentinel)"
1763 -re
".*A problem internal to GDB has been detected" {
1764 fail
"${test} (GDB internal error)"
1766 gdb_internal_error_resync
1769 fail
"${test} (pattern ${index} + sentinel) (timeout)"
1774 # unresolved
"${test}, pattern ${index} + sentinel"
1780 # pass
"${test}, pattern ${index}"
1783 fail
"${test} (pattern ${index})"
1786 -re
".*A problem internal to GDB has been detected" {
1787 fail
"${test} (GDB internal error)"
1789 gdb_internal_error_resync
1792 fail
"${test} (pattern ${index}) (timeout)"
1797 # unresolved
"${test}, pattern ${index}"
1811 proc gdb_suppress_entire_file
{ reason
} {
1812 global suppress_flag
;
1814 warning
"$reason\n";
1815 set suppress_flag
-1;
1819 #
Set suppress_flag
, which will cause all subsequent calls to send_gdb and
1820 # gdb_expect to fail immediately
(until the next
call to
1821 # gdb_stop_suppressing_tests
).
1823 proc gdb_suppress_tests
{ args } {
1824 global suppress_flag
;
1826 return; # fnf
- disable pending review of results where
1827 # testsuite ran better without this
1830 if { $suppress_flag
== 1 } {
1831 if { [llength $
args] > 0 } {
1832 warning
"[lindex $args 0]\n";
1834 warning
"Because of previous failure, all subsequent tests in this group will automatically fail.\n";
1840 # Clear suppress_flag.
1842 proc gdb_stop_suppressing_tests
{ } {
1843 global suppress_flag
;
1845 if [info exists suppress_flag
] {
1846 if { $suppress_flag
> 0 } {
1847 set suppress_flag
0;
1848 clone_output
"Tests restarted.\n";
1851 set suppress_flag
0;
1855 proc gdb_clear_suppressed
{ } {
1856 global suppress_flag
;
1858 set suppress_flag
0;
1861 proc gdb_start
{ } {
1866 catch default_gdb_exit
1870 # gdb_load
-- load a file into the debugger.
1871 # Many files in config
/*.exp override this procedure.
1873 proc gdb_load
{ arg } {
1874 return [gdb_file_cmd $
arg]
1877 proc gdb_continue
{ function
} {
1880 return [gdb_test
"continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
1883 proc default_gdb_init
{ args } {
1884 global gdb_wrapper_initialized
1886 gdb_clear_suppressed
;
1888 # Make sure that the wrapper is rebuilt
1889 # with the appropriate multilib option.
1890 set gdb_wrapper_initialized
0
1892 # Uh
, this is lame. Really
, really
, really lame. But there
's this *one*
1893 # testcase that will fail in random places if we don't increase this.
1896 # We want to add the
name of the TCL testcase to the PASS
/FAIL messages.
1897 if { [llength $
args] > 0 } {
1900 set file
[lindex $
args 0];
1902 set pf_prefix
"[file tail [file dirname $file]]/[file tail $file]:";
1905 if [target_info
exists gdb_prompt
] {
1906 set gdb_prompt
[target_info gdb_prompt
];
1908 set gdb_prompt
"\\(gdb\\)"
1912 proc gdb_init
{ args } {
1913 return [eval default_gdb_init $
args];
1916 proc gdb_finish
{ } {
1921 set debug_format
"unknown"
1923 # Run the gdb command
"info source" and extract the debugging format
1924 # information from the output and save it in debug_format.
1926 proc get_debug_format
{ } {
1932 set debug_format
"unknown"
1933 send_gdb
"info source\n"
1935 -re
"Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
1936 set debug_format $expect_out
(1,string
)
1937 verbose
"debug format is $debug_format"
1940 -re
"No current source file.\r\n$gdb_prompt $" {
1941 perror
"get_debug_format used when no current source file"
1944 -re
"$gdb_prompt $" {
1945 warning
"couldn't check debug format (no valid response)."
1949 warning
"couldn't check debug format (timed out)."
1955 #
Return true
if FORMAT matches the debug format the current test was
1956 # compiled with. FORMAT is a
shell-style globbing pattern
; it can use
1957 # `
*', `[...]', and so
on.
1959 # This function depends
on variables
set by `get_debug_format
', above.
1961 proc test_debug_format {format} {
1964 return [expr [string match $format $debug_format] != 0]
1967 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
1968 # COFF, stabs, etc). If that format matches the format that the
1969 # current test was compiled with, then the next test is expected to
1970 # fail for any target. Returns 1 if the next test or set of tests is
1971 # expected to fail, 0 otherwise (or if it is unknown). Must have
1972 # previously called get_debug_format.
1973 proc setup_xfail_format { format } {
1974 set ret [test_debug_format $format];
1982 proc gdb_step_for_stub { } {
1985 if ![target_info exists gdb,use_breakpoint_for_stub] {
1986 if [target_info exists gdb_stub_step_command] {
1987 set command [target_info gdb_stub_step_command];
1991 send_gdb "${command}\n";
1994 -re "(main.* at |.*in .*start).*$gdb_prompt" {
1997 -re ".*$gdb_prompt" {
1999 if { $tries == 5 } {
2000 fail "stepping out of breakpoint function";
2003 send_gdb "${command}\n";
2007 fail "stepping out of breakpoint function";
2014 -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" {
2015 set file $expect_out(1,string);
2016 set linenum [expr $expect_out(2,string) + 1];
2017 set breakplace "${file}:${linenum}";
2021 send_gdb "break ${breakplace}\n";
2023 -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" {
2024 set breakpoint $expect_out(1,string);
2026 -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" {
2027 set breakpoint $expect_out(1,string);
2031 send_gdb "continue\n";
2033 -re "Breakpoint ${breakpoint},.*$gdb_prompt" {
2034 gdb_test "delete $breakpoint" ".*" "";
2041 # gdb_get_line_number TEXT [FILE]
2043 # Search the source file FILE, and return the line number of the
2044 # first line containing TEXT. If no match is found, return -1.
2046 # TEXT is a string literal, not a regular expression.
2048 # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is
2049 # specified, and does not start with "/", then it is assumed to be in
2050 # "$srcdir/$subdir". This is awkward, and can be fixed in the future,
2051 # by changing the callers and the interface at the same time.
2052 # In particular: gdb.base/break.exp, gdb.base/condbreak.exp,
2053 # gdb.base/ena-dis-br.exp.
2055 # Use this function to keep your test scripts independent of the
2056 # exact line numbering of the source file. Don't write
:
2058 # send_gdb
"break 20"
2060 # This means that
if anyone ever edits your test
's source file,
2061 # your test could break. Instead, put a comment like this on the
2062 # source file line you want to break at:
2064 # /* breakpoint spot: frotz.exp: test name */
2066 # and then write, in your test script (which we assume is named
2069 # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
2071 # (Yes, Tcl knows how to handle the nested quotes and brackets.
2074 # % puts "foo [lindex "bar baz" 1]"
2077 # Tcl is quite clever, for a little stringy language.)
2081 # The previous implementation of this procedure used the gdb search command.
2082 # This version is different:
2084 # . It works with MI, and it also works when gdb is not running.
2086 # . It operates on the build machine, not the host machine.
2088 # . For now, this implementation fakes a current directory of
2089 # $srcdir/$subdir to be compatible with the old implementation.
2090 # This will go away eventually and some callers will need to
2093 # . The TEXT argument is literal text and matches literally,
2094 # not a regular expression as it was before.
2096 # . State changes in gdb, such as changing the current file
2097 # and setting $_, no longer happen.
2099 # After a bit of time we can forget about the differences from the
2100 # old implementation.
2102 # --chastain 2004-08-05
2104 proc gdb_get_line_number { text { file "" } } {
2109 if { "$file" == "" } then {
2112 if { ! [regexp "^/" "$file"] } then {
2113 set file "$srcdir/$subdir/$file"
2116 if { [ catch { set fd [open "$file"] } message ] } then {
2122 for { set line 1 } { 1 } { incr line } {
2123 if { [ catch { set nchar [gets "$fd" body] } message ] } then {
2127 if { $nchar < 0 } then {
2130 if { [string first "$text" "$body"] >= 0 } then {
2136 if { [ catch { close "$fd" } message ] } then {
2144 # gdb_continue_to_end:
2145 # The case where the target uses stubs has to be handled specially. If a
2146 # stub is used, we set a breakpoint at exit because we cannot rely on
2147 # exit() behavior of a remote target.
2149 # mssg is the error message that gets printed.
2151 proc gdb_continue_to_end {mssg} {
2152 if [target_info exists use_gdb_stub] {
2153 if {![gdb_breakpoint "exit"]} {
2156 gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \
2157 "continue until exit at $mssg"
2159 # Continue until we exit. Should not stop again.
2160 # Don't bother to check the output of the
program, that may be
2161 # extremely tough
for some remote systems.
2162 gdb_test
"continue"\
2163 "Continuing.\[\r\n0-9\]+(... EXIT code 0\[\r\n\]+|Program exited normally\\.).*"\
2164 "continue until exit at $mssg"
2168 proc rerun_to_main
{} {
2171 if [target_info
exists use_gdb_stub
] {
2174 -re
".*Breakpoint .*main .*$gdb_prompt $"\
2175 {pass
"rerun to main" ; return 0}
2176 -re
"$gdb_prompt $"\
2177 {fail
"rerun to main" ; return 0}
2178 timeout
{fail
"(timeout) rerun to main" ; return 0}
2183 -re
"The program .* has been started already.*y or n. $" {
2187 -re
"Starting program.*$gdb_prompt $"\
2188 {pass
"rerun to main" ; return 0}
2189 -re
"$gdb_prompt $"\
2190 {fail
"rerun to main" ; return 0}
2191 timeout
{fail
"(timeout) rerun to main" ; return 0}
2196 # Print a message and
return true
if a test should be skipped
2197 # due to lack of floating point suport.
2199 proc gdb_skip_float_test
{ msg
} {
2200 if [target_info
exists gdb
,skip_float_tests
] {
2201 verbose
"Skipping test '$msg': no float tests.";
2207 # Print a message and
return true
if a test should be skipped
2208 # due to lack of stdio support.
2210 proc gdb_skip_stdio_test
{ msg
} {
2211 if [target_info
exists gdb
,noinferiorio
] {
2212 verbose
"Skipping test '$msg': no inferior i/o.";
2218 proc gdb_skip_bogus_test
{ msg
} {
2223 # Note
: the procedure gdb_gnu_strip_debug will produce an executable called
2224 # $
{binfile
}.dbglnk
, which is just like the executable
($binfile
) but without
2225 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
2226 # the
name of a idebuginfo only file. This file will be stored in the
2227 # gdb.base
/.debug subdirectory.
2229 # Functions
for separate debug
info testing
2231 # starting with an executable
:
2232 # foo
--> original executable
2234 # at the end of the process we have
:
2235 # foo.stripped
--> foo w
/o debug
info
2236 # .debug
/foo.debug
--> foo
's debug info
2237 # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug.
2239 # Return the name of the file in which we should stor EXEC's separated
2240 # debug
info. EXEC contains the full path.
2241 proc separate_debug_filename
{ exec
} {
2243 # In a .debug subdirectory
off the same directory where the testcase
2244 # executable is going to be. Something like
:
2245 #
<your
-path
>/gdb
/testsuite
/gdb.base
/.debug
/blah.debug.
2246 # This is the default location where gdb expects to findi
2247 # the debug
info file.
2249 set exec_dir
[file dirname $exec
]
2250 set exec_file
[file tail $exec
]
2251 set debug_dir
[file join $exec_dir
".debug"]
2252 set debug_file
[file join $debug_dir
"${exec_file}.debug"]
2258 proc gdb_gnu_strip_debug
{ dest
} {
2260 set debug_file
[separate_debug_filename $dest
]
2261 set strip_to_file_program
strip
2262 set objcopy_program objcopy
2264 # Make sure the directory that will hold the separated debug
2265 #
info actually
exists.
2266 set debug_dir
[file dirname $debug_file
]
2267 if {! [file isdirectory $debug_dir
]} {
2268 file
mkdir $debug_dir
2271 set debug_link
[file tail $debug_file
]
2272 set stripped_file
"${dest}.stripped"
2274 #
Get rid of the debug
info, and store result in stripped_file
2275 # something like gdb
/testsuite
/gdb.base
/blah.stripped.
2276 set result
[catch
"exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
2277 verbose
"result is $result"
2278 verbose
"output is $output"
2283 #
Get rid of everything but the debug
info, and store result in debug_file
2284 # This will be in the .debug subdirectory
, see above.
2285 set result
[catch
"exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
2286 verbose
"result is $result"
2287 verbose
"output is $output"
2292 # Link the two previous output files together
, adding the .gnu_debuglink
2293 # section to the stripped_file
, containing a pointer to the debug_file
,
2294 # save the new file in dest.
2295 # This will be the regular executable filename
, in the usual location.
2296 set result
[catch
"exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
2297 verbose
"result is $result"
2298 verbose
"output is $output"