1 # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
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 # Please email any bugs, comments, and/or additions to this file to:
20 # bug-gdb@prep.ai.mit.edu
22 # This file was written by Fred Fish. (fnf@cygnus.com)
24 # Generic gdb subroutines that should work for any target. If these
25 # need to be modified for any target, it can be done with a variable
26 # or by passing arguments.
32 if [info exists TOOL_EXECUTABLE] {
33 set GDB $TOOL_EXECUTABLE;
35 if ![info exists GDB] {
36 if ![is_remote host] {
37 set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]]
39 set GDB [transform gdb];
42 verbose "using GDB = $GDB" 2
45 if ![info exists GDBFLAGS] {
48 verbose "using GDBFLAGS = $GDBFLAGS" 2
50 # The variable gdb_prompt is a regexp which matches the gdb prompt.
51 # Set it if it is not already set.
53 if ![info exists gdb_prompt] then {
54 set gdb_prompt "\[(\]gdb\[)\]"
57 # Needed for some tests under Cygwin.
61 if ![info exists env(EXEEXT)] {
64 set EXEEXT $env(EXEEXT)
67 ### Only procedures should come after this point.
70 # gdb_version -- extract and print the version number of GDB
72 proc default_gdb_version {} {
76 set fileid [open "gdb_cmd" w];
79 set cmdfile [remote_download host "gdb_cmd"];
80 set output [remote_exec host "$GDB -nw --command $cmdfile"]
81 remote_file build delete "gdb_cmd";
82 remote_file host delete "$cmdfile";
83 set tmp [lindex $output 1];
85 regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version
86 if ![is_remote host] {
87 clone_output "[which $GDB] version $version $GDBFLAGS\n"
89 clone_output "$GDB on remote host version $version $GDBFLAGS\n"
93 proc gdb_version { } {
94 return [default_gdb_version];
98 # gdb_unload -- unload a file if one is loaded
107 -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue }
108 -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue }
109 -re "A program is being debugged already..*Kill it.*y or n. $"\
111 verbose "\t\tKilling previous program being debugged"
114 -re "Discard symbol table from .*y or n.*$" {
118 -re "$gdb_prompt $" {}
120 perror "couldn't unload file in $GDB (timed out)."
126 # Many of the tests depend on setting breakpoints at various places and
127 # running until that breakpoint is reached. At times, we want to start
128 # with a clean-slate with respect to breakpoints, so this utility proc
129 # lets us do this without duplicating this code everywhere.
132 proc delete_breakpoints {} {
135 # we need a larger timeout value here or this thing just confuses
136 # itself. May need a better implementation if possible. - guo
138 send_gdb "delete breakpoints\n"
140 -re "Delete all breakpoints.*y or n.*$" {
144 -re "$gdb_prompt $" { # This happens if there were no breakpoints
146 timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return }
148 send_gdb "info breakpoints\n"
150 -re "No breakpoints or watchpoints..*$gdb_prompt $" {}
151 -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return }
152 -re "Delete all breakpoints.*or n.*$" {
156 timeout { perror "info breakpoints (timeout)" ; return }
162 # Generic run command.
164 # The second pattern below matches up to the first newline *only*.
165 # Using ``.*$'' could swallow up output that we attempt to match
168 proc gdb_run_cmd {args} {
171 if [target_info exists gdb_init_command] {
172 send_gdb "[target_info gdb_init_command]\n";
174 -re "$gdb_prompt $" { }
176 perror "gdb_init_command for target failed";
182 if [target_info exists use_gdb_stub] {
183 if [target_info exists gdb,do_reload_on_run] {
184 # Specifying no file, defaults to the executable
185 # currently being debugged.
186 if { [gdb_load ""] < 0 } {
189 send_gdb "continue\n";
191 -re "Continu\[^\r\n\]*\[\r\n\]" {}
197 if [target_info exists gdb,start_symbol] {
198 set start [target_info gdb,start_symbol];
202 send_gdb "jump *$start\n"
204 while { $start_attempt } {
205 # Cap (re)start attempts at three to ensure that this loop
206 # always eventually fails. Don't worry about trying to be
207 # clever and not send a command when it has failed.
208 if [expr $start_attempt > 3] {
209 perror "Jump to start() failed (retry count exceeded)";
212 set start_attempt [expr $start_attempt + 1];
214 -re "Continuing at \[^\r\n\]*\[\r\n\]" {
217 -re "No symbol \"_start\" in current.*$gdb_prompt $" {
218 perror "Can't find start symbol to run in gdb_run";
221 -re "No symbol \"start\" in current.*$gdb_prompt $" {
222 send_gdb "jump *_start\n";
224 -re "No symbol.*context.*$gdb_prompt $" {
227 -re "Line.* Jump anyway.*y or n. $" {
230 -re "The program is not being run.*$gdb_prompt $" {
231 if { [gdb_load ""] < 0 } {
234 send_gdb "jump *$start\n";
237 perror "Jump to start() failed (timeout)";
242 if [target_info exists gdb_stub] {
244 -re "$gdb_prompt $" {
245 send_gdb "continue\n"
252 if [target_info exists gdb,do_reload_on_run] {
253 if { [gdb_load ""] < 0 } {
257 send_gdb "run $args\n"
258 # This doesn't work quite right yet.
260 -re "The program .* has been started already.*y or n. $" {
264 -re "Starting program: \[^\r\n\]*" {}
268 # Set a breakpoint at FUNCTION. If there is an additional argument it is
269 # a list of options; the only currently supported option is allow-pending.
271 proc gdb_breakpoint { function args } {
275 set pending_response n
276 if {[lsearch -exact [lindex $args 0] allow-pending] != -1} {
277 set pending_response y
280 send_gdb "break $function\n"
281 # The first two regexps are what we get with -g, the third is without -g.
283 -re "Breakpoint \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {}
284 -re "Breakpoint \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {}
285 -re "Breakpoint \[0-9\]* at .*$gdb_prompt $" {}
286 -re "Breakpoint \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" {
287 if {$pending_response == "n"} {
288 fail "setting breakpoint at $function"
292 -re "Make breakpoint pending.*y or \\\[n\\\]. $" {
293 send_gdb "$pending_response\n"
296 -re "$gdb_prompt $" { fail "setting breakpoint at $function" ; return 0 }
297 timeout { fail "setting breakpoint at $function (timeout)" ; return 0 }
302 # Set breakpoint at function and run gdb until it breaks there.
303 # Since this is the only breakpoint that will be set, if it stops
304 # at a breakpoint, we will assume it is the one we want. We can't
305 # just compare to "function" because it might be a fully qualified,
306 # single quoted C++ function specifier. If there's an additional argument,
307 # pass it to gdb_breakpoint.
309 proc runto { function args } {
315 if ![gdb_breakpoint $function [lindex $args 0]] {
321 # the "at foo.c:36" output we get with -g.
322 # the "in func" output we get without -g.
324 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
327 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
330 -re "$gdb_prompt $" {
331 fail "running to $function in runto"
335 fail "running to $function in runto (timeout)"
343 # runto_main -- ask gdb to run until we hit a breakpoint at main.
344 # The case where the target uses stubs has to be handled
345 # specially--if it uses stubs, assuming we hit
346 # breakpoint() and just step out of the function.
348 proc runto_main { } {
352 if ![target_info exists gdb_stub] {
364 ### Continue, and expect to hit a breakpoint.
365 ### Report a pass or fail, depending on whether it seems to have
366 ### worked. Use NAME as part of the test name; each call to
367 ### continue_to_breakpoint should use a NAME which is unique within
369 proc gdb_continue_to_breakpoint {name} {
371 set full_name "continue to breakpoint: $name"
373 send_gdb "continue\n"
375 -re "Breakpoint .* at .*\r\n$gdb_prompt $" {
378 -re ".*$gdb_prompt $" {
382 fail "$full_name (timeout)"
388 # gdb_internal_error_resync:
390 # Answer the questions GDB asks after it reports an internal error
391 # until we get back to a GDB prompt. Decline to quit the debugging
392 # session, and decline to create a core file. Return non-zero if the
395 # This procedure just answers whatever questions come up until it sees
396 # a GDB prompt; it doesn't require you to have matched the input up to
397 # any specific point. However, it only answers questions it sees in
398 # the output itself, so if you've matched a question, you had better
399 # answer it yourself before calling this.
401 # You can use this function thus:
405 # -re ".*A problem internal to GDB has been detected" {
406 # gdb_internal_error_resync
411 proc gdb_internal_error_resync {} {
415 while {$count < 10} {
417 -re "Quit this debugging session\\? \\(y or n\\) $" {
421 -re "Create a core file of GDB\\? \\(y or n\\) $" {
425 -re "$gdb_prompt $" {
426 # We're resynchronized.
430 perror "Could not resync from internal error (timeout)"
435 perror "Could not resync from internal error (resync count exceeded)"
440 # gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS
441 # Send a command to gdb; test the result.
443 # COMMAND is the command to execute, send to GDB with send_gdb. If
444 # this is the null string no command is sent.
445 # MESSAGE is a message to be printed with the built-in failure patterns
446 # if one of them matches. If MESSAGE is empty COMMAND will be used.
447 # EXPECT_ARGUMENTS will be fed to expect in addition to the standard
448 # patterns. Pattern elements will be evaluated in the caller's
449 # context; action elements will be executed in the caller's context.
450 # Unlike patterns for gdb_test, these patterns should generally include
451 # the final newline and prompt.
454 # 1 if the test failed, according to a built-in failure pattern
455 # 0 if only user-supplied patterns matched
456 # -1 if there was an internal error.
458 # You can use this function thus:
460 # gdb_test_multiple "print foo" "test foo" {
461 # -re "expected output 1" {
464 # -re "expected output 2" {
469 # The standard patterns, such as "Program exited..." and "A problem
470 # ...", all being implicitly appended to that list.
472 proc gdb_test_multiple { command message user_code } {
476 upvar timeout timeout
477 upvar expect_out expect_out
479 if { $message == "" } {
483 # TCL/EXPECT WART ALERT
484 # Expect does something very strange when it receives a single braced
485 # argument. It splits it along word separators and performs substitutions.
486 # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is
487 # evaluated as "\[ab\]". But that's not how TCL normally works; inside a
488 # double-quoted list item, "\[ab\]" is just a long way of representing
489 # "[ab]", because the backslashes will be removed by lindex.
491 # Unfortunately, there appears to be no easy way to duplicate the splitting
492 # that expect will do from within TCL. And many places make use of the
493 # "\[0-9\]" construct, so we need to support that; and some places make use
494 # of the "[func]" construct, so we need to support that too. In order to
495 # get this right we have to substitute quoted list elements differently
496 # from braced list elements.
498 # We do this roughly the same way that Expect does it. We have to use two
499 # lists, because if we leave unquoted newlines in the argument to uplevel
500 # they'll be treated as command separators, and if we escape newlines
501 # we mangle newlines inside of command blocks. This assumes that the
502 # input doesn't contain a pattern which contains actual embedded newlines
505 regsub -all {\n} ${user_code} { } subst_code
506 set subst_code [uplevel list $subst_code]
508 set processed_code ""
510 set expecting_action 0
511 foreach item $user_code subst_item $subst_code {
512 if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } {
513 lappend processed_code $item
516 if {$item == "-indices" || $item == "-re" || $item == "-ex"} {
517 lappend processed_code $item
520 if { $expecting_action } {
521 lappend processed_code "uplevel [list $item]"
522 set expecting_action 0
523 # Cosmetic, no effect on the list.
524 append processed_code "\n"
527 set expecting_action 1
528 lappend processed_code $subst_item
529 if {$patterns != ""} {
532 append patterns "\"$subst_item\""
535 # Also purely cosmetic.
536 regsub -all {\r} $patterns {\\r} patterns
537 regsub -all {\n} $patterns {\\n} patterns
540 send_user "Sending \"$command\" to gdb\n"
541 send_user "Looking to match \"$patterns\"\n"
542 send_user "Message is \"$message\"\n"
546 set string "${command}\n";
547 if { $command != "" } {
548 while { "$string" != "" } {
549 set foo [string first "\n" "$string"];
550 set len [string length "$string"];
551 if { $foo < [expr $len - 1] } {
552 set str [string range "$string" 0 $foo];
553 if { [send_gdb "$str"] != "" } {
554 global suppress_flag;
556 if { ! $suppress_flag } {
557 perror "Couldn't send $command to GDB.";
562 # since we're checking if each line of the multi-line
563 # command are 'accepted' by GDB here,
564 # we need to set -notransfer expect option so that
565 # command output is not lost for pattern matching
568 -notransfer -re "\[\r\n\]" { verbose "partial: match" 3 }
569 timeout { verbose "partial: timeout" 3 }
571 set string [string range "$string" [expr $foo + 1] end];
576 if { "$string" != "" } {
577 if { [send_gdb "$string"] != "" } {
578 global suppress_flag;
580 if { ! $suppress_flag } {
581 perror "Couldn't send $command to GDB.";
589 if [target_info exists gdb,timeout] {
590 set tmt [target_info gdb,timeout];
592 if [info exists timeout] {
596 if [info exists timeout] {
605 -re ".*A problem internal to GDB has been detected" {
606 fail "$message (GDB internal error)"
607 gdb_internal_error_resync
609 -re "\\*\\*\\* DOSEXIT code.*" {
610 if { $message != "" } {
613 gdb_suppress_entire_file "GDB died";
616 -re "Ending remote debugging.*$gdb_prompt $" {
617 if ![isnative] then {
618 warning "Can`t communicate to remote target."
625 append code $processed_code
627 -re "Undefined\[a-z\]* command:.*$gdb_prompt $" {
628 perror "Undefined command \"$command\"."
632 -re "Ambiguous command.*$gdb_prompt $" {
633 perror "\"$command\" is not a unique command name."
637 -re "Program exited with code \[0-9\]+.*$gdb_prompt $" {
638 if ![string match "" $message] then {
639 set errmsg "$message (the program exited)"
641 set errmsg "$command (the program exited)"
646 -re "EXIT code \[0-9\r\n\]+Program exited normally.*$gdb_prompt $" {
647 if ![string match "" $message] then {
648 set errmsg "$message (the program exited)"
650 set errmsg "$command (the program exited)"
655 -re "The program is not being run.*$gdb_prompt $" {
656 if ![string match "" $message] then {
657 set errmsg "$message (the program is no longer running)"
659 set errmsg "$command (the program is no longer running)"
664 -re "\r\n$gdb_prompt $" {
665 if ![string match "" $message] then {
672 perror "Window too small."
676 -re "\\(y or n\\) " {
678 perror "Got interactive prompt."
683 perror "Process no longer exists"
684 if { $message != "" } {
690 perror "internal buffer is full."
695 if ![string match "" $message] then {
696 fail "$message (timeout)"
703 gdb_expect $tmt $code
707 # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE
708 # Send a command to gdb; test the result.
710 # COMMAND is the command to execute, send to GDB with send_gdb. If
711 # this is the null string no command is sent.
712 # PATTERN is the pattern to match for a PASS, and must NOT include
713 # the \r\n sequence immediately before the gdb prompt.
714 # MESSAGE is an optional message to be printed. If this is
715 # omitted, then the pass/fail messages use the command string as the
716 # message. (If this is the empty string, then sometimes we don't
717 # call pass or fail at all; I don't understand this at all.)
718 # QUESTION is a question GDB may ask in response to COMMAND, like
720 # RESPONSE is the response to send if QUESTION appears.
723 # 1 if the test failed,
724 # 0 if the test passes,
725 # -1 if there was an internal error.
727 proc gdb_test { args } {
731 upvar timeout timeout
733 if [llength $args]>2 then {
734 set message [lindex $args 2]
736 set message [lindex $args 0]
738 set command [lindex $args 0]
739 set pattern [lindex $args 1]
741 if [llength $args]==5 {
742 set question_string [lindex $args 3];
743 set response_string [lindex $args 4];
745 set question_string "^FOOBAR$"
748 return [gdb_test_multiple $command $message {
749 -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" {
750 if ![string match "" $message] then {
754 -re "(${question_string})$" {
755 send_gdb "$response_string\n";
761 # Test that a command gives an error. For pass or fail, return
762 # a 1 to indicate that more tests can proceed. However a timeout
763 # is a serious error, generates a special fail message, and causes
764 # a 0 to be returned to indicate that more tests are likely to fail
767 proc test_print_reject { args } {
771 if [llength $args]==2 then {
772 set expectthis [lindex $args 1]
774 set expectthis "should never match this bogus string"
776 set sendthis [lindex $args 0]
778 send_user "Sending \"$sendthis\" to gdb\n"
779 send_user "Looking to match \"$expectthis\"\n"
781 send_gdb "$sendthis\n"
782 #FIXME: Should add timeout as parameter.
784 -re "A .* in expression.*\\.*$gdb_prompt $" {
785 pass "reject $sendthis"
788 -re "Invalid syntax in expression.*$gdb_prompt $" {
789 pass "reject $sendthis"
792 -re "Junk after end of expression.*$gdb_prompt $" {
793 pass "reject $sendthis"
796 -re "Invalid number.*$gdb_prompt $" {
797 pass "reject $sendthis"
800 -re "Invalid character constant.*$gdb_prompt $" {
801 pass "reject $sendthis"
804 -re "No symbol table is loaded.*$gdb_prompt $" {
805 pass "reject $sendthis"
808 -re "No symbol .* in current context.*$gdb_prompt $" {
809 pass "reject $sendthis"
812 -re "Unmatched single quote.*$gdb_prompt $" {
813 pass "reject $sendthis"
816 -re "A character constant must contain at least one character.*$gdb_prompt $" {
817 pass "reject $sendthis"
820 -re "$expectthis.*$gdb_prompt $" {
821 pass "reject $sendthis"
824 -re ".*$gdb_prompt $" {
825 fail "reject $sendthis"
829 fail "reject $sendthis (eof or timeout)"
835 # Given an input string, adds backslashes as needed to create a
836 # regexp that will match the string.
838 proc string_to_regexp {str} {
840 regsub -all {[]*+.|()^$\[]} $str {\\&} result
844 # Same as gdb_test, but the second parameter is not a regexp,
845 # but a string that must match exactly.
847 proc gdb_test_exact { args } {
848 upvar timeout timeout
850 set command [lindex $args 0]
852 # This applies a special meaning to a null string pattern. Without
853 # this, "$pattern\r\n$gdb_prompt $" will match anything, including error
854 # messages from commands that should have no output except a new
855 # prompt. With this, only results of a null string will match a null
858 set pattern [lindex $args 1]
859 if [string match $pattern ""] {
860 set pattern [string_to_regexp [lindex $args 0]]
862 set pattern [string_to_regexp [lindex $args 1]]
865 # It is most natural to write the pattern argument with only
866 # embedded \n's, especially if you are trying to avoid Tcl quoting
867 # problems. But gdb_expect really wants to see \r\n in patterns. So
868 # transform the pattern here. First transform \r\n back to \n, in
869 # case some users of gdb_test_exact already do the right thing.
870 regsub -all "\r\n" $pattern "\n" pattern
871 regsub -all "\n" $pattern "\r\n" pattern
872 if [llength $args]==3 then {
873 set message [lindex $args 2]
878 return [gdb_test $command $pattern $message]
881 proc gdb_reinitialize_dir { subdir } {
884 if [is_remote host] {
889 -re "Reinitialize source path to empty.*y or n. " {
892 -re "Source directories searched.*$gdb_prompt $" {
893 send_gdb "dir $subdir\n"
895 -re "Source directories searched.*$gdb_prompt $" {
896 verbose "Dir set to $subdir"
898 -re "$gdb_prompt $" {
899 perror "Dir \"$subdir\" failed."
903 -re "$gdb_prompt $" {
904 perror "Dir \"$subdir\" failed."
908 -re "$gdb_prompt $" {
909 perror "Dir \"$subdir\" failed."
915 # gdb_exit -- exit the GDB, killing the target program if necessary
917 proc default_gdb_exit {} {
923 gdb_stop_suppressing_tests;
925 if ![info exists gdb_spawn_id] {
929 verbose "Quitting $GDB $GDBFLAGS"
931 if { [is_remote host] && [board_info host exists fileid] } {
938 -re "DOSEXIT code" { }
943 if ![is_remote host] {
950 # load a file into the debugger.
951 # return a -1 if anything goes wrong.
953 proc gdb_file_cmd { arg } {
959 upvar timeout timeout
961 if [is_remote host] {
962 set arg [remote_download host $arg];
964 error "download failed"
969 send_gdb "file $arg\n"
971 -re "Reading symbols from.*done.*$gdb_prompt $" {
972 verbose "\t\tLoaded $arg into the $GDB"
975 -re "has no symbol-table.*$gdb_prompt $" {
976 perror "$arg wasn't compiled with \"-g\""
979 -re "A program is being debugged already.*Kill it.*y or n. $" {
981 verbose "\t\tKilling previous program being debugged"
984 -re "Load new symbol table from \".*\".*y or n. $" {
987 -re "Reading symbols from.*done.*$gdb_prompt $" {
988 verbose "\t\tLoaded $arg with new symbol table into $GDB"
992 perror "(timeout) Couldn't load $arg, other program already loaded."
997 -re "No such file or directory.*$gdb_prompt $" {
998 perror "($arg) No such file or directory\n"
1001 -re "$gdb_prompt $" {
1002 perror "couldn't load $arg into $GDB."
1006 perror "couldn't load $arg into $GDB (timed out)."
1010 # This is an attempt to detect a core dump, but seems not to
1011 # work. Perhaps we need to match .* followed by eof, in which
1012 # gdb_expect does not seem to have a way to do that.
1013 perror "couldn't load $arg into $GDB (end of file)."
1020 # start gdb -- start gdb running, default procedure
1022 # When running over NFS, particularly if running many simultaneous
1023 # tests on different hosts all using the same server, things can
1024 # get really slow. Give gdb at least 3 minutes to start up.
1026 proc default_gdb_start { } {
1032 global gdb_spawn_id;
1034 gdb_stop_suppressing_tests;
1036 verbose "Spawning $GDB -nw $GDBFLAGS"
1038 if [info exists gdb_spawn_id] {
1042 if ![is_remote host] {
1043 if { [which $GDB] == 0 } then {
1044 perror "$GDB does not exist."
1048 set res [remote_spawn host "$GDB -nw $GDBFLAGS [host_info gdb_opts]"];
1049 if { $res < 0 || $res == "" } {
1050 perror "Spawning $GDB failed."
1054 -re "\[\r\n\]$gdb_prompt $" {
1055 verbose "GDB initialized."
1057 -re "$gdb_prompt $" {
1058 perror "GDB never initialized."
1062 perror "(timeout) GDB never initialized after 10 seconds."
1067 set gdb_spawn_id -1;
1068 # force the height to "unlimited", so no pagers get used
1070 send_gdb "set height 0\n"
1072 -re "$gdb_prompt $" {
1073 verbose "Setting height to 0." 2
1076 warning "Couldn't set the height to 0"
1079 # force the width to "unlimited", so no wraparound occurs
1080 send_gdb "set width 0\n"
1082 -re "$gdb_prompt $" {
1083 verbose "Setting width to 0." 2
1086 warning "Couldn't set the width to 0."
1092 # Return a 1 for configurations for which we don't even want to try to
1095 proc skip_cplus_tests {} {
1096 if { [istarget "d10v-*-*"] } {
1099 if { [istarget "h8300-*-*"] } {
1103 # The C++ IO streams are too large for HC11/HC12 and are thus not
1104 # available. The gdb C++ tests use them and don't compile.
1105 if { [istarget "m6811-*-*"] } {
1108 if { [istarget "m6812-*-*"] } {
1114 # Skip all the tests in the file if you are not on an hppa running
1117 proc skip_hp_tests {} {
1118 eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ]
1119 verbose "Skip hp tests is $skip_hp"
1123 set compiler_info "unknown"
1125 set hp_cc_compiler 0
1126 set hp_aCC_compiler 0
1127 set signed_keyword_not_used 0
1129 # Figure out what compiler I am using.
1131 # BINFILE is a "compiler information" output file. This implementation
1132 # does not use BINFILE.
1134 # ARGS can be empty or "C++". If empty, "C" is assumed.
1136 # There are several ways to do this, with various problems.
1138 # [ gdb_compile -E $ifile -o $binfile.ci ]
1139 # source $binfile.ci
1141 # Single Unix Spec v3 says that "-E -o ..." together are not
1142 # specified. And in fact, the native compiler on hp-ux 11 (among
1143 # others) does not work with "-E -o ...". Most targets used to do
1144 # this, and it mostly worked, because it works with gcc.
1146 # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ]
1147 # source $binfile.ci
1149 # This avoids the problem with -E and -o together. This almost works
1150 # if the build machine is the same as the host machine, which is
1151 # usually true of the targets which are not gcc. But this code does
1152 # not figure which compiler to call, and it always ends up using the C
1153 # compiler. Not good for setting hp_aCC_compiler. Targets
1154 # hppa*-*-hpux* and mips*-*-irix* used to do this.
1156 # [ gdb_compile -E $ifile > $binfile.ci ]
1157 # source $binfile.ci
1159 # dejagnu target_compile says that it supports output redirection,
1160 # but the code is completely different from the normal path and I
1161 # don't want to sweep the mines from that path. So I didn't even try
1164 # set cppout [ gdb_compile $ifile "" preprocess $args quiet ]
1167 # I actually do this for all targets now. gdb_compile runs the right
1168 # compiler, and TCL captures the output, and I eval the output.
1170 # Unfortunately, expect logs the output of the command as it goes by,
1171 # and dejagnu helpfully prints a second copy of it right afterwards.
1172 # So I turn off expect logging for a moment.
1174 # [ gdb_compile $ifile $ciexe_file executable $args ]
1175 # [ remote_exec $ciexe_file ]
1176 # [ source $ci_file.out ]
1178 # I could give up on -E and just do this.
1179 # I didn't get desperate enough to try this.
1181 # -- chastain 2004-01-06
1183 proc get_compiler_info {binfile args} {
1184 # For compiler.c and compiler.cc
1187 # I am going to play with the log to keep noise out.
1191 # These come from compiler.c or compiler.cc
1192 global compiler_info
1193 global signed_keyword_not_used
1195 # Legacy global data symbols.
1197 global hp_cc_compiler
1198 global hp_aCC_compiler
1200 # Choose which file to preprocess.
1201 set ifile "${srcdir}/lib/compiler.c"
1202 if { [llength $args] > 0 && [lindex $args 0] == "c++" } {
1203 set ifile "${srcdir}/lib/compiler.cc"
1206 # Run $ifile through the right preprocessor.
1207 # Toggle gdb.log to keep the compiler output out of the log.
1209 set cppout [ gdb_compile "${ifile}" "" preprocess [list "$args" quiet] ]
1210 log_file -a "$outdir/$tool.log"
1214 foreach cppline [ split "$cppout" "\n" ] {
1215 if { [ regexp "^#" "$cppline" ] } {
1217 } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } {
1219 } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } {
1221 verbose "get_compiler_info: $cppline" 2
1225 verbose -log "get_compiler_info: $cppline"
1230 # Reset to unknown compiler if any diagnostics happened.
1232 set compiler_info "unknown"
1233 set signed_keyword_not_used 0
1236 # Set the legacy symbols.
1238 set hp_cc_compiler 0
1239 set hp_aCC_compiler 0
1240 if { [regexp "^gcc-1-" "$compiler_info" ] } { set gcc_compiled 1 }
1241 if { [regexp "^gcc-2-" "$compiler_info" ] } { set gcc_compiled 2 }
1242 if { [regexp "^gcc-3-" "$compiler_info" ] } { set gcc_compiled 3 }
1243 if { [regexp "^gcc-4-" "$compiler_info" ] } { set gcc_compiled 4 }
1244 if { [regexp "^gcc-5-" "$compiler_info" ] } { set gcc_compiled 5 }
1245 if { [regexp "^hpcc-" "$compiler_info" ] } { set hp_cc_compiler 1 }
1246 if { [regexp "^hpacc-" "$compiler_info" ] } { set hp_aCC_compiler 1 }
1248 # Log what happened.
1249 verbose -log "get_compiler_info: $compiler_info"
1251 # Most compilers will evaluate comparisons and other boolean
1252 # operations to 0 or 1.
1253 uplevel \#0 { set true 1 }
1254 uplevel \#0 { set false 0 }
1256 # Use of aCC results in boolean results being displayed as
1258 if { $hp_aCC_compiler } {
1259 uplevel \#0 { set true true }
1260 uplevel \#0 { set false false }
1266 proc test_compiler_info { compiler } {
1267 global compiler_info
1268 return [string match $compiler $compiler_info]
1271 set gdb_wrapper_initialized 0
1273 proc gdb_wrapper_init { args } {
1274 global gdb_wrapper_initialized;
1275 global gdb_wrapper_file;
1276 global gdb_wrapper_flags;
1278 if { $gdb_wrapper_initialized == 1 } { return; }
1280 if {[target_info exists needs_status_wrapper] && \
1281 [target_info needs_status_wrapper] != "0"} {
1282 set result [build_wrapper "testglue.o"];
1283 if { $result != "" } {
1284 set gdb_wrapper_file [lindex $result 0];
1285 set gdb_wrapper_flags [lindex $result 1];
1287 warning "Status wrapper failed to build."
1290 set gdb_wrapper_initialized 1
1293 proc gdb_compile {source dest type options} {
1294 global GDB_TESTCASE_OPTIONS;
1295 global gdb_wrapper_file;
1296 global gdb_wrapper_flags;
1297 global gdb_wrapper_initialized;
1299 if [target_info exists gdb_stub] {
1300 set options2 { "additional_flags=-Dusestubs" }
1301 lappend options "libs=[target_info gdb_stub]";
1302 set options [concat $options2 $options]
1304 if [target_info exists is_vxworks] {
1305 set options2 { "additional_flags=-Dvxworks" }
1306 lappend options "libs=[target_info gdb_stub]";
1307 set options [concat $options2 $options]
1309 if [info exists GDB_TESTCASE_OPTIONS] {
1310 lappend options "additional_flags=$GDB_TESTCASE_OPTIONS";
1312 verbose "options are $options"
1313 verbose "source is $source $dest $type $options"
1315 if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init }
1317 if {[target_info exists needs_status_wrapper] && \
1318 [target_info needs_status_wrapper] != "0" && \
1319 [info exists gdb_wrapper_file]} {
1320 lappend options "libs=${gdb_wrapper_file}"
1321 lappend options "ldflags=${gdb_wrapper_flags}"
1324 set result [target_compile $source $dest $type $options];
1325 regsub "\[\r\n\]*$" "$result" "" result;
1326 regsub "^\[\r\n\]*" "$result" "" result;
1327 if { $result != "" && [lsearch $options quiet] == -1} {
1328 clone_output "gdb compile failed, $result"
1334 # This is just like gdb_compile, above, except that it tries compiling
1335 # against several different thread libraries, to see which one this
1337 proc gdb_compile_pthreads {source dest type options} {
1339 set why_msg "unrecognized error"
1340 foreach lib {-lpthreads -lpthread -lthread} {
1341 # This kind of wipes out whatever libs the caller may have
1342 # set. Or maybe theirs will override ours. How infelicitous.
1343 set options_with_lib [concat $options [list libs=$lib quiet]]
1344 set ccout [gdb_compile $source $dest $type $options_with_lib]
1345 switch -regexp -- $ccout {
1346 ".*no posix threads support.*" {
1347 set why_msg "missing threads include file"
1350 ".*cannot open -lpthread.*" {
1351 set why_msg "missing runtime threads library"
1353 ".*Can't find library for -lpthread.*" {
1354 set why_msg "missing runtime threads library"
1357 pass "successfully compiled posix threads test case"
1363 if {!$built_binfile} {
1364 unsupported "Couldn't compile $source: ${why_msg}"
1369 # This is just like gdb_compile_pthreads, above, except that we always add the
1370 # objc library for compiling Objective-C programs
1371 proc gdb_compile_objc {source dest type options} {
1373 set why_msg "unrecognized error"
1374 foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} {
1375 # This kind of wipes out whatever libs the caller may have
1376 # set. Or maybe theirs will override ours. How infelicitous.
1377 if { $lib == "solaris" } {
1378 set lib "-lpthread -lposix4"
1380 if { $lib != "-lobjc" } {
1381 set lib "-lobjc $lib"
1383 set options_with_lib [concat $options [list libs=$lib quiet]]
1384 set ccout [gdb_compile $source $dest $type $options_with_lib]
1385 switch -regexp -- $ccout {
1386 ".*no posix threads support.*" {
1387 set why_msg "missing threads include file"
1390 ".*cannot open -lpthread.*" {
1391 set why_msg "missing runtime threads library"
1393 ".*Can't find library for -lpthread.*" {
1394 set why_msg "missing runtime threads library"
1397 pass "successfully compiled objc with posix threads test case"
1403 if {!$built_binfile} {
1404 unsupported "Couldn't compile $source: ${why_msg}"
1409 proc send_gdb { string } {
1410 global suppress_flag;
1411 if { $suppress_flag } {
1412 return "suppressed";
1414 return [remote_send host "$string"];
1420 proc gdb_expect { args } {
1421 if { [llength $args] == 2 && [lindex $args 0] != "-re" } {
1422 set gtimeout [lindex $args 0];
1423 set expcode [list [lindex $args 1]];
1425 upvar timeout timeout;
1428 if [target_info exists gdb,timeout] {
1429 if [info exists timeout] {
1430 if { $timeout < [target_info gdb,timeout] } {
1431 set gtimeout [target_info gdb,timeout];
1433 set gtimeout $timeout;
1436 set gtimeout [target_info gdb,timeout];
1440 if ![info exists gtimeout] {
1442 if [info exists timeout] {
1443 set gtimeout $timeout;
1450 global suppress_flag;
1451 global remote_suppress_flag;
1452 if [info exists remote_suppress_flag] {
1453 set old_val $remote_suppress_flag;
1455 if [info exists suppress_flag] {
1456 if { $suppress_flag } {
1457 set remote_suppress_flag 1;
1461 {uplevel remote_expect host $gtimeout $expcode} string];
1462 if [info exists old_val] {
1463 set remote_suppress_flag $old_val;
1465 if [info exists remote_suppress_flag] {
1466 unset remote_suppress_flag;
1471 global errorInfo errorCode;
1473 return -code error -errorinfo $errorInfo -errorcode $errorCode $string
1474 } elseif {$code == 2} {
1475 return -code return $string
1476 } elseif {$code == 3} {
1478 } elseif {$code > 4} {
1479 return -code $code $string
1483 # gdb_expect_list MESSAGE SENTINEL LIST -- expect a sequence of outputs
1485 # Check for long sequence of output by parts.
1486 # MESSAGE: is the test message to be printed with the test success/fail.
1487 # SENTINEL: Is the terminal pattern indicating that output has finished.
1488 # LIST: is the sequence of outputs to match.
1489 # If the sentinel is recognized early, it is considered an error.
1492 # 1 if the test failed,
1493 # 0 if the test passes,
1494 # -1 if there was an internal error.
1496 proc gdb_expect_list {test sentinel list} {
1498 global suppress_flag
1501 if { $suppress_flag } {
1503 unresolved "${test}"
1505 while { ${index} < [llength ${list}] } {
1506 set pattern [lindex ${list} ${index}]
1507 set index [expr ${index} + 1]
1508 if { ${index} == [llength ${list}] } {
1511 -re "${pattern}${sentinel}" {
1512 # pass "${test}, pattern ${index} + sentinel"
1515 fail "${test} (pattern ${index} + sentinel)"
1518 -re ".*A problem internal to GDB has been detected" {
1519 fail "${test} (GDB internal error)"
1521 gdb_internal_error_resync
1524 fail "${test} (pattern ${index} + sentinel) (timeout)"
1529 # unresolved "${test}, pattern ${index} + sentinel"
1535 # pass "${test}, pattern ${index}"
1538 fail "${test} (pattern ${index})"
1541 -re ".*A problem internal to GDB has been detected" {
1542 fail "${test} (GDB internal error)"
1544 gdb_internal_error_resync
1547 fail "${test} (pattern ${index}) (timeout)"
1552 # unresolved "${test}, pattern ${index}"
1566 proc gdb_suppress_entire_file { reason } {
1567 global suppress_flag;
1569 warning "$reason\n";
1570 set suppress_flag -1;
1574 # Set suppress_flag, which will cause all subsequent calls to send_gdb and
1575 # gdb_expect to fail immediately (until the next call to
1576 # gdb_stop_suppressing_tests).
1578 proc gdb_suppress_tests { args } {
1579 global suppress_flag;
1581 return; # fnf - disable pending review of results where
1582 # testsuite ran better without this
1585 if { $suppress_flag == 1 } {
1586 if { [llength $args] > 0 } {
1587 warning "[lindex $args 0]\n";
1589 warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n";
1595 # Clear suppress_flag.
1597 proc gdb_stop_suppressing_tests { } {
1598 global suppress_flag;
1600 if [info exists suppress_flag] {
1601 if { $suppress_flag > 0 } {
1602 set suppress_flag 0;
1603 clone_output "Tests restarted.\n";
1606 set suppress_flag 0;
1610 proc gdb_clear_suppressed { } {
1611 global suppress_flag;
1613 set suppress_flag 0;
1616 proc gdb_start { } {
1621 catch default_gdb_exit
1625 # gdb_load -- load a file into the debugger.
1626 # return a -1 if anything goes wrong.
1628 proc gdb_load { arg } {
1629 return [gdb_file_cmd $arg]
1632 proc gdb_continue { function } {
1635 return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"];
1638 proc default_gdb_init { args } {
1639 global gdb_wrapper_initialized
1641 gdb_clear_suppressed;
1643 # Make sure that the wrapper is rebuilt
1644 # with the appropriate multilib option.
1645 set gdb_wrapper_initialized 0
1647 # Uh, this is lame. Really, really, really lame. But there's this *one*
1648 # testcase that will fail in random places if we don't increase this.
1651 # We want to add the name of the TCL testcase to the PASS/FAIL messages.
1652 if { [llength $args] > 0 } {
1655 set file [lindex $args 0];
1657 set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:";
1660 if [target_info exists gdb_prompt] {
1661 set gdb_prompt [target_info gdb_prompt];
1663 set gdb_prompt "\\(gdb\\)"
1667 proc gdb_init { args } {
1668 return [eval default_gdb_init $args];
1671 proc gdb_finish { } {
1676 set debug_format "unknown"
1678 # Run the gdb command "info source" and extract the debugging format
1679 # information from the output and save it in debug_format.
1681 proc get_debug_format { } {
1687 set debug_format "unknown"
1688 send_gdb "info source\n"
1690 -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" {
1691 set debug_format $expect_out(1,string)
1692 verbose "debug format is $debug_format"
1695 -re "No current source file.\r\n$gdb_prompt $" {
1696 perror "get_debug_format used when no current source file"
1699 -re "$gdb_prompt $" {
1700 warning "couldn't check debug format (no valid response)."
1704 warning "couldn't check debug format (timed out)."
1710 # Return true if FORMAT matches the debug format the current test was
1711 # compiled with. FORMAT is a shell-style globbing pattern; it can use
1712 # `*', `[...]', and so on.
1714 # This function depends on variables set by `get_debug_format', above.
1716 proc test_debug_format {format} {
1719 return [expr [string match $format $debug_format] != 0]
1722 # Like setup_xfail, but takes the name of a debug format (DWARF 1,
1723 # COFF, stabs, etc). If that format matches the format that the
1724 # current test was compiled with, then the next test is expected to
1725 # fail for any target. Returns 1 if the next test or set of tests is
1726 # expected to fail, 0 otherwise (or if it is unknown). Must have
1727 # previously called get_debug_format.
1728 proc setup_xfail_format { format } {
1729 set ret [test_debug_format $format];
1737 proc gdb_step_for_stub { } {
1740 if ![target_info exists gdb,use_breakpoint_for_stub] {
1741 if [target_info exists gdb_stub_step_command] {
1742 set command [target_info gdb_stub_step_command];
1746 send_gdb "${command}\n";
1749 -re "(main.* at |.*in .*start).*$gdb_prompt" {
1752 -re ".*$gdb_prompt" {
1754 if { $tries == 5 } {
1755 fail "stepping out of breakpoint function";
1758 send_gdb "${command}\n";
1762 fail "stepping out of breakpoint function";
1769 -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" {
1770 set file $expect_out(1,string);
1771 set linenum [expr $expect_out(2,string) + 1];
1772 set breakplace "${file}:${linenum}";
1776 send_gdb "break ${breakplace}\n";
1778 -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" {
1779 set breakpoint $expect_out(1,string);
1781 -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" {
1782 set breakpoint $expect_out(1,string);
1786 send_gdb "continue\n";
1788 -re "Breakpoint ${breakpoint},.*$gdb_prompt" {
1789 gdb_test "delete $breakpoint" ".*" "";
1796 # gdb_get_line_number TEXT [FILE]
1798 # Search the source file FILE, and return the line number of the
1799 # first line containing TEXT. If no match is found, return -1.
1801 # TEXT is a string literal, not a regular expression.
1803 # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is
1804 # specified, and does not start with "/", then it is assumed to be in
1805 # "$srcdir/$subdir". This is awkward, and can be fixed in the future,
1806 # by changing the callers and the interface at the same time.
1807 # In particular: gdb.base/break.exp, gdb.base/condbreak.exp,
1808 # gdb.base/ena-dis-br.exp.
1810 # Use this function to keep your test scripts independent of the
1811 # exact line numbering of the source file. Don't write:
1813 # send_gdb "break 20"
1815 # This means that if anyone ever edits your test's source file,
1816 # your test could break. Instead, put a comment like this on the
1817 # source file line you want to break at:
1819 # /* breakpoint spot: frotz.exp: test name */
1821 # and then write, in your test script (which we assume is named
1824 # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n"
1826 # (Yes, Tcl knows how to handle the nested quotes and brackets.
1829 # % puts "foo [lindex "bar baz" 1]"
1832 # Tcl is quite clever, for a little stringy language.)
1836 # The previous implementation of this procedure used the gdb search command.
1837 # This version is different:
1839 # . It works with MI, and it also works when gdb is not running.
1841 # . It operates on the build machine, not the host machine.
1843 # . For now, this implementation fakes a current directory of
1844 # $srcdir/$subdir to be compatible with the old implementation.
1845 # This will go away eventually and some callers will need to
1848 # . The TEXT argument is literal text and matches literally,
1849 # not a regular expression as it was before.
1851 # . State changes in gdb, such as changing the current file
1852 # and setting $_, no longer happen.
1854 # After a bit of time we can forget about the differences from the
1855 # old implementation.
1857 # --chastain 2004-08-05
1859 proc gdb_get_line_number { text { file "" } } {
1864 if { "$file" == "" } then {
1867 if { ! [regexp "^/" "$file"] } then {
1868 set file "$srcdir/$subdir/$file"
1871 if { [ catch { set fd [open "$file"] } message ] } then {
1877 for { set line 1 } { 1 } { incr line } {
1878 if { [ catch { set nchar [gets "$fd" body] } message ] } then {
1882 if { $nchar < 0 } then {
1885 if { [string first "$text" "$body"] >= 0 } then {
1891 if { [ catch { close "$fd" } message ] } then {
1899 # gdb_continue_to_end:
1900 # The case where the target uses stubs has to be handled specially. If a
1901 # stub is used, we set a breakpoint at exit because we cannot rely on
1902 # exit() behavior of a remote target.
1904 # mssg is the error message that gets printed.
1906 proc gdb_continue_to_end {mssg} {
1907 if [target_info exists use_gdb_stub] {
1908 if {![gdb_breakpoint "exit"]} {
1911 gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \
1912 "continue until exit at $mssg"
1914 # Continue until we exit. Should not stop again.
1915 # Don't bother to check the output of the program, that may be
1916 # extremely tough for some remote systems.
1917 gdb_test "continue"\
1918 "Continuing.\[\r\n0-9\]+(... EXIT code 0\[\r\n\]+|Program exited normally\\.).*"\
1919 "continue until exit at $mssg"
1923 proc rerun_to_main {} {
1926 if [target_info exists use_gdb_stub] {
1929 -re ".*Breakpoint .*main .*$gdb_prompt $"\
1930 {pass "rerun to main" ; return 0}
1931 -re "$gdb_prompt $"\
1932 {fail "rerun to main" ; return 0}
1933 timeout {fail "(timeout) rerun to main" ; return 0}
1938 -re "The program .* has been started already.*y or n. $" {
1942 -re "Starting program.*$gdb_prompt $"\
1943 {pass "rerun to main" ; return 0}
1944 -re "$gdb_prompt $"\
1945 {fail "rerun to main" ; return 0}
1946 timeout {fail "(timeout) rerun to main" ; return 0}
1951 # Print a message and return true if a test should be skipped
1952 # due to lack of floating point suport.
1954 proc gdb_skip_float_test { msg } {
1955 if [target_info exists gdb,skip_float_tests] {
1956 verbose "Skipping test '$msg': no float tests.";
1962 # Print a message and return true if a test should be skipped
1963 # due to lack of stdio support.
1965 proc gdb_skip_stdio_test { msg } {
1966 if [target_info exists gdb,noinferiorio] {
1967 verbose "Skipping test '$msg': no inferior i/o.";
1973 proc gdb_skip_bogus_test { msg } {
1978 # Note: the procedure gdb_gnu_strip_debug will produce an executable called
1979 # ${binfile}.dbglnk, which is just like the executable ($binfile) but without
1980 # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains
1981 # the name of a idebuginfo only file. This file will be stored in the
1982 # gdb.base/.debug subdirectory.
1984 # Functions for separate debug info testing
1986 # starting with an executable:
1987 # foo --> original executable
1989 # at the end of the process we have:
1990 # foo.stripped --> foo w/o debug info
1991 # .debug/foo.debug --> foo's debug info
1992 # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug.
1994 # Return the name of the file in which we should stor EXEC's separated
1995 # debug info. EXEC contains the full path.
1996 proc separate_debug_filename { exec } {
1998 # In a .debug subdirectory off the same directory where the testcase
1999 # executable is going to be. Something like:
2000 # <your-path>/gdb/testsuite/gdb.base/.debug/blah.debug.
2001 # This is the default location where gdb expects to findi
2002 # the debug info file.
2004 set exec_dir [file dirname $exec]
2005 set exec_file [file tail $exec]
2006 set debug_dir [file join $exec_dir ".debug"]
2007 set debug_file [file join $debug_dir "${exec_file}.debug"]
2013 proc gdb_gnu_strip_debug { dest } {
2015 set debug_file [separate_debug_filename $dest]
2016 set strip_to_file_program strip
2017 set objcopy_program objcopy
2019 # Make sure the directory that will hold the separated debug
2020 # info actually exists.
2021 set debug_dir [file dirname $debug_file]
2022 if {! [file isdirectory $debug_dir]} {
2023 file mkdir $debug_dir
2026 set debug_link [file tail $debug_file]
2027 set stripped_file "${dest}.stripped"
2029 # Get rid of the debug info, and store result in stripped_file
2030 # something like gdb/testsuite/gdb.base/blah.stripped.
2031 set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output]
2032 verbose "result is $result"
2033 verbose "output is $output"
2038 # Get rid of everything but the debug info, and store result in debug_file
2039 # This will be in the .debug subdirectory, see above.
2040 set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output]
2041 verbose "result is $result"
2042 verbose "output is $output"
2047 # Link the two previous output files together, adding the .gnu_debuglink
2048 # section to the stripped_file, containing a pointer to the debug_file,
2049 # save the new file in dest.
2050 # This will be the regular executable filename, in the usual location.
2051 set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output]
2052 verbose "result is $result"
2053 verbose "output is $output"