1 # Test Framework Driver for GDB driving an external simulator
2 # Copyright 1999 Free Software Foundation, Inc. ?
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 set port [lindex [split [target_info netport] ":"] 1]
26 # Set a default endianness
27 case [target_info multilib_flags] in {
28 { *big-endian* *-EB* *-meb* } { set sidendian "-EB" }
29 { *little-endian* *-EL* *-mel* } { set sidendian "-EL" }
31 if {[target_info exists sim,defaultendian]} then {
32 set sidendian [target_info sim,defaultendian]
34 warning "Unknown target endianness - assuming -EB"
39 # set verbosity conditionally
40 if {$verbose > 0} then { set sidverbose "--verbose" } else { set sidverbose "" }
42 # test to see whether to use use sid in build or install tree
43 set use_build_tree [file exists ../../sid]
45 if {$use_build_tree} then {
48 set env(SID_LIBRARY_PATH) [join [glob "../../sid/component/*"] ":"]
49 set env(SID) "../../sid/main/dynamic/sid"
50 set env(MKSID) "../../sid/main/static/mksid"
51 if {! [file exists $env(SID)]} then { error "Cannot find sid in build tree" }
53 set spawncmd "../../sid/bsp/[target_info sim] $sidverbose $sidendian --persistent --gdb=$port [target_info sim,options]"
56 unset env(SID_LIBRARY_PATH)
62 set spawncmd "[target_info sim] $sidverbose $sidendian --persistent --gdb=$port [target_info sim,options]"
67 if {[catch "spawn $spawncmd" msg]} {
75 regsub "\n" $expect_out(buffer) {} msg
80 # There should be no need to sleep to give SID time to start;
81 # GDB would wait for a fair while for the stub to respond.
84 set sid_spawn_id $spawn_id
88 # Handle GDB talking to SID
93 return [default_gdb_start]
98 if {[info exists sid_spawn_id]} {
99 catch {exec kill [exp_pid -i $sid_spawn_id]}
100 catch {wait -i $sid_spawn_id}
107 set result [default_gdb_exit]
114 # Set gdb to target the simulator
116 proc send_target_sid { } {
117 # wait a little while, giving sid time to shut down & restart its
120 send_gdb "target [target_info gdb_protocol] [target_info netport]\n"
123 proc gdb_target_sid { } {
130 set prev_timeout $timeout
132 verbose "Timeout is now $timeout seconds" 2
134 -re "Remote debugging using.*$gdb_prompt" {
135 verbose "Set target to sid"
138 perror "Couldn't set target for remote simulator."
143 set timeout $prev_timeout
144 verbose "Timeout is now $timeout seconds" 2
148 # gdb_load -- load a file into the debugger.
149 # return a -1 if anything goes wrong.
151 proc gdb_load { arg } {
159 if [gdb_file_cmd $arg] then { return -1 }
164 set prev_timeout $timeout
166 verbose "Timeout is now $timeout seconds" 2
168 -re ".*$gdb_prompt $" {
170 send_user "Loaded $arg into $GDB\n"
173 verbose "Timeout is now $timeout seconds" 2
176 -re "$gdb_prompt $" {
178 perror "GDB couldn't load."
183 perror "Timed out trying to load $arg."
187 set timeout $prev_timeout