1 # Test Framework Driver for GDB driving an external simulator
2 # Copyright 1999-2019 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/>.
20 set port [lindex [split [target_info netport] ":"] 1]
22 # Set a default endianness
23 case [target_info multilib_flags] in {
24 { *big-endian* *-EB* *-meb* } { set sidendian "-EB" }
25 { *little-endian* *-EL* *-mel* } { set sidendian "-EL" }
27 if {[target_info exists sim,defaultendian]} then {
28 set sidendian [target_info sim,defaultendian]
30 # rely on endianness settings in sid configuration defaults
36 { -EB } { set sidendian2 {-e "set cpu endian big"} }
37 { -EL } { set sidendian2 {-e "set cpu endian little"} }
38 default { set sidendian2 {} }
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 if {! [file exists $env(SID)]} then { error "Cannot find sid in build tree" }
51 if { [board_info target sim,protocol] == "sid" } {
52 set spawncmd "[target_info sim] [target_info sim,options] $sidendian2 -e \"set cpu-gdb-socket sockaddr-local 0.0.0.0:$port\""
53 } elseif { [board_info target sim,protocol] == "rawsid" } {
54 set spawncmd "[target_info sim] [target_info sim,options] -$sidendian --gdb=$port"
56 set spawncmd "../../sid/bsp/[target_info sim] $sidendian --gdb=$port [target_info sim,options]"
60 unset env(SID_LIBRARY_PATH)
65 if { [board_info target sim,protocol] == "sid" } {
66 # FIXME: sim,options may be from the build tree, should find
67 # it in the install tree.
68 set spawncmd "sid [target_info sim,options] $sidendian2 -e \"set cpu-gdb-socket sockaddr-local 0.0.0.0:$port\""
69 } elseif { [board_info target sim,protocol] == "rawsid" } {
70 set spawncmd "[target_info sim] [target_info sim,options] -$sidendian --gdb=$port"
72 set spawncmd "[target_info sim] $sidendian --gdb=$port [target_info sim,options]"
78 if {[catch [list remote_spawn host $spawncmd] msg]} {
84 # Don't do the following any more; it breaks with "runtest ... < /dev/null"
87 # regsub "\n" $expect_out(buffer) {} msg
88 # verbose "SID: $msg" 2
92 # There should be no need to sleep to give SID time to start;
93 # GDB would wait for a fair while for the stub to respond.
96 if ![target_info exists gdb,no_push_conn] {
102 # Handle GDB talking to SID
107 return [default_gdb_start]
111 if ![target_info exists gdb,no_push_conn] {
118 set result [default_gdb_exit]
125 # Set gdb to target the simulator
127 proc send_target_sid { } {
128 # wait a little while, giving sid time to shut down & restart its
131 send_gdb "target [target_info gdb_protocol] [target_info netport]\n"
134 proc gdb_target_sid { } {
141 set prev_timeout $timeout
143 verbose "Timeout is now $timeout seconds" 2
145 -re ".*\[Ee\]rror.*$gdb_prompt $" {
146 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."
157 set timeout $prev_timeout
158 verbose "Timeout is now $timeout seconds" 2
162 # gdb_load -- load a file into the debugger.
163 # return a -1 if anything goes wrong.
165 proc gdb_load { arg } {
174 if [gdb_file_cmd $arg] then { return -1 }
181 set prev_timeout $timeout
183 verbose "Timeout is now $timeout seconds" 2
185 -re ".*\[Ee\]rror.*$gdb_prompt $" {
187 perror "Error during download."
191 -re ".*$gdb_prompt $" {
193 send_user "Loaded $arg into $GDB\n"
197 -re "$gdb_prompt $" {
199 perror "GDB couldn't load."
205 perror "Timed out trying to load $arg."
210 set timeout $prev_timeout
211 verbose "Timeout is now $timeout seconds" 2