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