1 # Test Framework Driver for GDB driving an external simulator
2 # Copyright 1999, 2001 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.
23 set port [lindex [split [target_info netport] ":"] 1]
25 # Set a default endianness
26 case [target_info multilib_flags] in {
27 { *big-endian* *-EB* *-meb* } { set sidendian "-EB" }
28 { *little-endian* *-EL* *-mel* } { set sidendian "-EL" }
30 if {[target_info exists sim,defaultendian]} then {
31 set sidendian [target_info sim,defaultendian]
33 warning "Unknown target endianness - assuming -EB"
38 # set verbosity conditionally
39 if {$verbose > 0} then { set sidverbose "--verbose" } else { set sidverbose "" }
41 # test to see whether to use use sid in build or install tree
42 set use_build_tree [file exists ../../sid]
44 if {$use_build_tree} then {
47 set env(SID_LIBRARY_PATH) [join [glob "../../sid/component/*"] ":"]
48 set env(SID) "../../sid/main/dynamic/sid"
49 set env(MKSID) "../../sid/main/static/mksid"
50 if {! [file exists $env(SID)]} then { error "Cannot find sid in build tree" }
52 if { [board_info target sim,protocol] == "sid" } {
53 set spawncmd "[target_info sim] [target_info sim,options] -e \"set cpu-gdb-socket sockaddr-local 0.0.0.0:$port\""
55 set spawncmd "../../sid/bsp/[target_info sim] $sidverbose $sidendian --gdb=$port [target_info sim,options]"
59 unset env(SID_LIBRARY_PATH)
67 if { [board_info target sim,protocol] == "sid" } {
68 # FIXME: sim,options may be from the build tree, should find
69 # it in the install tree.
70 set spawncmd "sid [target_info sim,options] -e \"set cpu-gdb-socket sockaddr-local 0.0.0.0:$port\""
72 set spawncmd "[target_info sim] $sidverbose $sidendian --gdb=$port [target_info sim,options]"
78 if {[catch [list remote_spawn host $spawncmd] msg]} {
86 regsub "\n" $expect_out(buffer) {} msg
91 # There should be no need to sleep to give SID time to start;
92 # GDB would wait for a fair while for the stub to respond.
95 if ![target_info exists gdb,no_push_conn] {
96 remote_push_conn host;
101 # Handle GDB talking to SID
106 return [default_gdb_start]
110 if ![target_info exists gdb,no_push_conn] {
112 remote_pop_conn host;
117 set result [default_gdb_exit]
124 # Set gdb to target the simulator
126 proc send_target_sid { } {
127 # wait a little while, giving sid time to shut down & restart its
130 send_gdb "target [target_info gdb_protocol] [target_info netport]\n"
133 proc gdb_target_sid { } {
140 set prev_timeout $timeout
142 verbose "Timeout is now $timeout seconds" 2
144 -re ".*\[Ee\]rror.*$gdb_prompt $" {
145 perror "Couldn't set target for remote simulator."
149 -re "Remote debugging using.*$gdb_prompt" {
150 verbose "Set target to sid"
153 perror "Couldn't set target for remote simulator."
158 set timeout $prev_timeout
159 verbose "Timeout is now $timeout seconds" 2
163 # gdb_load -- load a file into the debugger.
164 # return a -1 if anything goes wrong.
166 proc gdb_load { arg } {
175 if [gdb_file_cmd $arg] then { return -1 }
180 set prev_timeout $timeout
182 verbose "Timeout is now $timeout seconds" 2
184 -re ".*\[Ee\]rror.*$gdb_prompt $" {
186 perror "Error during download."
190 -re ".*$gdb_prompt $" {
192 send_user "Loaded $arg into $GDB\n"
196 -re "$gdb_prompt $" {
198 perror "GDB couldn't load."
204 perror "Timed out trying to load $arg."
209 set timeout $prev_timeout
210 verbose "Timeout is now $timeout seconds" 2