1 # Test Framework Driver for GDB driving an external simulator
2 # Copyright 1999-2023 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/>.
18 set port [lindex [split [target_info netport] ":"] 1]
20 # Set a default endianness
21 case [target_info multilib_flags] in {
22 { *big-endian* *-EB* *-meb* } { set sidendian "-EB" }
23 { *little-endian* *-EL* *-mel* } { set sidendian "-EL" }
25 if {[target_info exists sim,defaultendian]} {
26 set sidendian [target_info sim,defaultendian]
28 # rely on endianness settings in sid configuration defaults
34 { -EB } { set sidendian2 {-e "set cpu endian big"} }
35 { -EL } { set sidendian2 {-e "set cpu endian little"} }
36 default { set sidendian2 {} }
39 # test to see whether to use use sid in build or install tree
40 set use_build_tree [file exists ../../sid]
42 if {$use_build_tree} {
45 set env(SID_LIBRARY_PATH) [join [glob "../../sid/component/*"] ":"]
46 set env(SID) "../../sid/main/dynamic/sid"
47 if {![file exists $env(SID)]} { error "Cannot find sid in build tree" }
49 if { [board_info target sim,protocol] == "sid" } {
50 set spawncmd "[target_info sim] [target_info sim,options] $sidendian2 -e \"set cpu-gdb-socket sockaddr-local 0.0.0.0:$port\""
51 } elseif { [board_info target sim,protocol] == "rawsid" } {
52 set spawncmd "[target_info sim] [target_info sim,options] -$sidendian --gdb=$port"
54 set spawncmd "../../sid/bsp/[target_info sim] $sidendian --gdb=$port [target_info sim,options]"
58 unset env(SID_LIBRARY_PATH)
63 if { [board_info target sim,protocol] == "sid" } {
64 # FIXME: sim,options may be from the build tree, should find
65 # it in the install tree.
66 set spawncmd "sid [target_info sim,options] $sidendian2 -e \"set cpu-gdb-socket sockaddr-local 0.0.0.0:$port\""
67 } elseif { [board_info target sim,protocol] == "rawsid" } {
68 set spawncmd "[target_info sim] [target_info sim,options] -$sidendian --gdb=$port"
70 set spawncmd "[target_info sim] $sidendian --gdb=$port [target_info sim,options]"
76 if {[catch [list remote_spawn host $spawncmd] msg]} {
82 # Don't do the following any more; it breaks with "runtest ... < /dev/null"
85 # regsub "\n" $expect_out(buffer) {} msg
86 # verbose "SID: $msg" 2
90 # There should be no need to sleep to give SID time to start;
91 # GDB would wait for a fair while for the stub to respond.
94 if ![target_info exists gdb,no_push_conn] {
100 # Handle GDB talking to SID
105 return [default_gdb_start]
109 if ![target_info exists gdb,no_push_conn] {
116 set result [default_gdb_exit]
123 # Set gdb to target the simulator
125 proc send_target_sid { } {
126 # wait a little while, giving sid time to shut down & restart its
129 send_gdb "target [target_info gdb_protocol] [target_info netport]\n"
132 proc gdb_target_sid { } {
139 set prev_timeout $timeout
141 verbose "Timeout is now $timeout seconds" 2
143 -re ".*\[Ee\]rror.*$gdb_prompt $" {
144 perror "Couldn't set target for remote simulator."
147 -re "Remote debugging using.*$gdb_prompt" {
148 verbose "Set target to sid"
151 perror "Couldn't set target for remote simulator."
155 set timeout $prev_timeout
156 verbose "Timeout is now $timeout seconds" 2
160 # gdb_load -- load a file into the debugger.
161 # return a -1 if anything goes wrong.
163 proc gdb_load { arg } {
172 if {[gdb_file_cmd $arg]} { return -1 }
179 set prev_timeout $timeout
181 verbose "Timeout is now $timeout seconds" 2
183 -re ".*\[Ee\]rror.*$gdb_prompt $" {
185 perror "Error during download."
189 -re ".*$gdb_prompt $" {
191 send_user "Loaded $arg into $GDB\n"
195 -re "$gdb_prompt $" {
197 perror "GDB couldn't load."
203 perror "Timed out trying to load $arg."
208 set timeout $prev_timeout
209 verbose "Timeout is now $timeout seconds" 2