]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/config/sid.exp
gdb/testsuite: Prepare for DejaGnu 1.6.2
[thirdparty/binutils-gdb.git] / gdb / testsuite / config / sid.exp
CommitLineData
9c646a6e 1# Test Framework Driver for GDB driving an external simulator
42a4f53d 2# Copyright 1999-2019 Free Software Foundation, Inc.
9c646a6e
BE
3#
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
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
9c646a6e 7# (at your option) any later version.
e22f8b7c 8#
9c646a6e
BE
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.
e22f8b7c 13#
9c646a6e 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
9c646a6e 16
9c646a6e 17proc sid_start {} {
9c646a6e
BE
18 global verbose
19
20 set port [lindex [split [target_info netport] ":"] 1]
21
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" }
26 default {
27 if {[target_info exists sim,defaultendian]} then {
28 set sidendian [target_info sim,defaultendian]
29 } else {
61d11d80
FCE
30 # rely on endianness settings in sid configuration defaults
31 set sidendian ""
9c646a6e
BE
32 }
33 }
34 }
8d6e6f81
FCE
35 case $sidendian in {
36 { -EB } { set sidendian2 {-e "set cpu endian big"} }
37 { -EL } { set sidendian2 {-e "set cpu endian little"} }
38 default { set sidendian2 {} }
39 }
9c646a6e
BE
40
41 # test to see whether to use use sid in build or install tree
42 set use_build_tree [file exists ../../sid]
43
44 if {$use_build_tree} then {
45 set pre_spawn {
46 global env
47 set env(SID_LIBRARY_PATH) [join [glob "../../sid/component/*"] ":"]
48 set env(SID) "../../sid/main/dynamic/sid"
9c646a6e
BE
49 if {! [file exists $env(SID)]} then { error "Cannot find sid in build tree" }
50 }
ca3f91ed 51 if { [board_info target sim,protocol] == "sid" } {
8d6e6f81 52 set spawncmd "[target_info sim] [target_info sim,options] $sidendian2 -e \"set cpu-gdb-socket sockaddr-local 0.0.0.0:$port\""
6079c749
BE
53 } elseif { [board_info target sim,protocol] == "rawsid" } {
54 set spawncmd "[target_info sim] [target_info sim,options] -$sidendian --gdb=$port"
ca3f91ed 55 } else {
8d6e6f81 56 set spawncmd "../../sid/bsp/[target_info sim] $sidendian --gdb=$port [target_info sim,options]"
ca3f91ed 57 }
9c646a6e
BE
58 set post_spawn {
59 global env
60 unset env(SID_LIBRARY_PATH)
9c646a6e
BE
61 unset env(SID)
62 }
63 } else {
64 set pre_spawn {}
ca3f91ed
MS
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.
8d6e6f81 68 set spawncmd "sid [target_info sim,options] $sidendian2 -e \"set cpu-gdb-socket sockaddr-local 0.0.0.0:$port\""
6079c749
BE
69 } elseif { [board_info target sim,protocol] == "rawsid" } {
70 set spawncmd "[target_info sim] [target_info sim,options] -$sidendian --gdb=$port"
ca3f91ed 71 } else {
8d6e6f81 72 set spawncmd "[target_info sim] $sidendian --gdb=$port [target_info sim,options]"
ca3f91ed 73 }
9c646a6e
BE
74 set post_spawn {}
75 }
76
77 eval $pre_spawn
ca3f91ed 78 if {[catch [list remote_spawn host $spawncmd] msg]} {
9c646a6e
BE
79 perror $msg
80 exit 1
81 }
82 eval $post_spawn
83
8d6e6f81
FCE
84 # Don't do the following any more; it breaks with "runtest ... < /dev/null"
85# expect_background {
86# -re \[^\n\]*\n {
87# regsub "\n" $expect_out(buffer) {} msg
88# verbose "SID: $msg" 2
89# }
90# }
9c646a6e
BE
91
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.
94 sleep 4
95
ca3f91ed 96 if ![target_info exists gdb,no_push_conn] {
4ec70201 97 remote_push_conn host
ca3f91ed 98 }
9c646a6e
BE
99}
100
101#
102# Handle GDB talking to SID
103#
104
105proc gdb_start {} {
106 sid_start
107 return [default_gdb_start]
108}
109
110proc sid_exit {} {
ca3f91ed 111 if ![target_info exists gdb,no_push_conn] {
4ec70201
PA
112 remote_close host
113 remote_pop_conn host
9c646a6e
BE
114 }
115}
116
117proc gdb_exit {} {
118 set result [default_gdb_exit]
119 sid_exit
120 return $result
121}
122
123#
124# gdb_target_sid
125# Set gdb to target the simulator
126#
127proc send_target_sid { } {
128 # wait a little while, giving sid time to shut down & restart its
129 # gdb socket
130 sleep 4
131 send_gdb "target [target_info gdb_protocol] [target_info netport]\n"
132}
133
134proc gdb_target_sid { } {
135 global gdb_prompt
136 global exit_status
137
138 send_target_sid
139
140 global timeout
141 set prev_timeout $timeout
142 set timeout 60
143 verbose "Timeout is now $timeout seconds" 2
144 gdb_expect {
66c756c6
MS
145 -re ".*\[Ee\]rror.*$gdb_prompt $" {
146 perror "Couldn't set target for remote simulator."
66c756c6
MS
147 gdb_exit
148 }
9c646a6e
BE
149 -re "Remote debugging using.*$gdb_prompt" {
150 verbose "Set target to sid"
151 }
152 timeout {
153 perror "Couldn't set target for remote simulator."
66c756c6 154 gdb_exit
9c646a6e
BE
155 }
156 }
157 set timeout $prev_timeout
158 verbose "Timeout is now $timeout seconds" 2
159}
160
161#
162# gdb_load -- load a file into the debugger.
163# return a -1 if anything goes wrong.
164#
165proc gdb_load { arg } {
166 global verbose
167 global loadpath
168 global loadfile
169 global GDB
170 global gdb_prompt
66c756c6 171 global retval
9c646a6e 172
7b5ebade
KB
173 if { $arg != "" } {
174 if [gdb_file_cmd $arg] then { return -1 }
175 }
176
9c646a6e
BE
177 gdb_target_sid
178
179 send_gdb "load\n"
180 global timeout
181 set prev_timeout $timeout
182 set timeout 2400
183 verbose "Timeout is now $timeout seconds" 2
184 gdb_expect {
66c756c6
MS
185 -re ".*\[Ee\]rror.*$gdb_prompt $" {
186 if $verbose>1 then {
187 perror "Error during download."
188 }
4ec70201 189 set retval -1
66c756c6 190 }
9c646a6e
BE
191 -re ".*$gdb_prompt $" {
192 if $verbose>1 then {
193 send_user "Loaded $arg into $GDB\n"
194 }
4ec70201 195 set retval 0
9c646a6e
BE
196 }
197 -re "$gdb_prompt $" {
198 if $verbose>1 then {
199 perror "GDB couldn't load."
200 }
4ec70201 201 set retval -1
9c646a6e
BE
202 }
203 timeout {
204 if $verbose>1 then {
205 perror "Timed out trying to load $arg."
206 }
4ec70201 207 set retval -1
9c646a6e
BE
208 }
209 }
210 set timeout $prev_timeout
66c756c6 211 verbose "Timeout is now $timeout seconds" 2
ae59b1da 212 return $retval
9c646a6e 213}