1 # Test Framework Driver for GDB driving an external simulator
2 # Copyright 1999, 2001, 2007, 2008, 2009 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 set port [lindex [split [target_info netport] ":"] 1]
24 # Set a default endianness
25 case [target_info multilib_flags] in {
26 { *big-endian* *-EB* *-meb* } { set sidendian "-EB" }
27 { *little-endian* *-EL* *-mel* } { set sidendian "-EL" }
29 if {[target_info exists sim,defaultendian]} then {
30 set sidendian [target_info sim,defaultendian]
32 # rely on endianness settings in sid configuration defaults
38 { -EB } { set sidendian2 {-e "set cpu endian big"} }
39 { -EL } { set sidendian2 {-e "set cpu endian little"} }
40 default { set sidendian2 {} }
43 # test to see whether to use use sid in build or install tree
44 set use_build_tree [file exists ../../sid]
46 if {$use_build_tree} then {
49 set env(SID_LIBRARY_PATH) [join [glob "../../sid/component/*"] ":"]
50 set env(SID) "../../sid/main/dynamic/sid"
51 if {! [file exists $env(SID)]} then { error "Cannot find sid in build tree" }
53 if { [board_info target sim,protocol] == "sid" } {
54 set spawncmd "[target_info sim] [target_info sim,options] $sidendian2 -e \"set cpu-gdb-socket sockaddr-local 0.0.0.0:$port\""
55 } elseif { [board_info target sim,protocol] == "rawsid" } {
56 set spawncmd "[target_info sim] [target_info sim,options] -$sidendian --gdb=$port"
58 set spawncmd "../../sid/bsp/[target_info sim] $sidendian --gdb=$port [target_info sim,options]"
62 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] $sidendian2 -e \"set cpu-gdb-socket sockaddr-local 0.0.0.0:$port\""
71 } elseif { [board_info target sim,protocol] == "rawsid" } {
72 set spawncmd "[target_info sim] [target_info sim,options] -$sidendian --gdb=$port"
74 set spawncmd "[target_info sim] $sidendian --gdb=$port [target_info sim,options]"
80 if {[catch [list remote_spawn host $spawncmd] msg]} {
86 # Don't do the following any more; it breaks with "runtest ... < /dev/null"
89 # regsub "\n" $expect_out(buffer) {} msg
90 # verbose "SID: $msg" 2
94 # There should be no need to sleep to give SID time to start;
95 # GDB would wait for a fair while for the stub to respond.
98 if ![target_info exists gdb,no_push_conn] {
99 remote_push_conn host;
104 # Handle GDB talking to SID
109 return [default_gdb_start]
113 if ![target_info exists gdb,no_push_conn] {
115 remote_pop_conn host;
120 set result [default_gdb_exit]
127 # Set gdb to target the simulator
129 proc send_target_sid { } {
130 # wait a little while, giving sid time to shut down & restart its
133 send_gdb "target [target_info gdb_protocol] [target_info netport]\n"
136 proc gdb_target_sid { } {
143 set prev_timeout $timeout
145 verbose "Timeout is now $timeout seconds" 2
147 -re ".*\[Ee\]rror.*$gdb_prompt $" {
148 perror "Couldn't set target for remote simulator."
152 -re "Remote debugging using.*$gdb_prompt" {
153 verbose "Set target to sid"
156 perror "Couldn't set target for remote simulator."
161 set timeout $prev_timeout
162 verbose "Timeout is now $timeout seconds" 2
166 # gdb_load -- load a file into the debugger.
167 # return a -1 if anything goes wrong.
169 proc gdb_load { arg } {
178 if [gdb_file_cmd $arg] then { return -1 }
185 set prev_timeout $timeout
187 verbose "Timeout is now $timeout seconds" 2
189 -re ".*\[Ee\]rror.*$gdb_prompt $" {
191 perror "Error during download."
195 -re ".*$gdb_prompt $" {
197 send_user "Loaded $arg into $GDB\n"
201 -re "$gdb_prompt $" {
203 perror "GDB couldn't load."
209 perror "Timed out trying to load $arg."
214 set timeout $prev_timeout
215 verbose "Timeout is now $timeout seconds" 2