* coffread.c: Replace all occurrences of bfd_read with bfd_bread.
[binutils-gdb.git] / gdb / testsuite / config / sparclet.exp
1 # Copyright 1996, 1997 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # DejaGnu@cygnus.com
19
20 # This file was written by Michael Snyder <msnyder@cygnus.com>.
21
22 # GDB support routines for a board using the sparclet remote debugging
23 # protocol.
24
25 load_lib remote.exp
26 load_lib gdb.exp
27
28 #
29 # Sparclet remote run command.
30 #
31
32 proc gdb_start { } {
33 global gdb_prompt
34
35 if ![file exists loader] {
36 global libdir
37 set loader loader;
38
39 if [target_info exists gdb_stub_offset] {
40 set result [target_compile "${libdir}/stub-loader.c" $loader executable "libs=-Wl,-Ttext,[target_info gdb_stub_offset]"];
41 } else {
42 set result [target_compile "${libdir}/stub-loader.c" $loader executable "ldscript=[target_info gdb_stub_ldscript]"];
43 }
44 }
45
46 verbose -log "$gdb_prompt is gdb prompt"
47
48 set result 0;
49 for { set y 0; } { $y < 4 } { incr y } {
50 if { [default_gdb_start] != 0 } {
51 return -1;
52 }
53
54 if [target_info exists baud] {
55 send_gdb "set remotebaud [target_info baud]\n"
56 gdb_expect {
57 -re "$gdb_prompt" { }
58 default {
59 perror "Error setting baud rate."
60 return -1;
61 }
62 }
63 }
64
65 for {set x 1;} { $x < 4 } {incr x} {
66 set result [gdb_sparclet_startup $result];
67 if { $result > 0 } {
68 return 1;
69 }
70 # mmmmm, magic numbers.
71 if { $result == -42 || $result == -43 } {
72 break;
73 } else {
74 reboot_target;
75 }
76 }
77 if { $x == 4 } {
78 return -1;
79 }
80 gdb_exit;
81 sleep 5;
82 }
83 return -1;
84 }
85
86 proc gdb_sparclet_startup { arg } {
87 global gdb_prompt
88 global GDB
89 global verbose
90
91 set is_running_stub 0;
92
93 if [target_info exists serial] {
94 set serial [target_info serial];
95 } else {
96 set serial [target_info netport];
97 }
98 set protocol [target_info gdb_protocol];
99 set check_stub 1;
100 if { $arg != -42 } {
101 send_gdb "target $protocol $serial\n";
102 # 10 seconds may be a bit short.
103 gdb_expect 10 {
104 -re "already.*y or n." {
105 gdb_send "y\n";
106 exp_continue;
107 }
108 -re "Remote target.*connected to.*$gdb_prompt" { set check_stub 0; }
109 -re "$gdb_prompt" { }
110 timeout { }
111 }
112 if { $check_stub } {
113 verbose "timed out, checking if stub is already running"
114 send_gdb "\003";
115 sleep 1;
116 send_gdb "\003";
117 gdb_expect 10 {
118 -re "$gdb_prompt" { }
119 default {
120 remote_close host;
121 return -42;
122 }
123 }
124 }
125 }
126 if [target_info exists gdb_serial] {
127 set gdb_serial [target_info gdb_serial];
128 } else {
129 set gdb_serial $serial;
130 }
131 if { $check_stub } {
132 send_gdb "target remote $gdb_serial\n";
133 gdb_expect 15 {
134 -re "Remote debugging.*$gdb_prompt" {
135 verbose "stub is already running"
136 set is_running_stub 1;
137 }
138 default {
139 warning "board isn't responding";
140 remote_close host;
141 remote_reboot target;
142 return -43;
143 }
144 }
145 }
146
147 if { $is_running_stub == 0 } {
148 global srcdir
149
150 if [is_remote host] {
151 set loader [remote_download host "loader"];
152 } else {
153 set loader "loader";
154 }
155 send_gdb "file $loader\n";
156 gdb_expect {
157 -re "A program is being debug.*Kill it.*y or n. $" {
158 send_gdb "y\n"
159 exp_continue
160 }
161 -re "Load new symbol table.*y or n. $" {
162 send_gdb "y\n"
163 exp_continue
164 }
165 -re "Reading symbols from.*done..*$gdb_prompt $" {}
166 -re "$gdb_prompt $" { perror "GDB couldn't find loader" }
167 timeout {
168 perror "(timeout) read symbol file" ;
169 return -1
170 }
171 }
172
173 send_gdb "target $protocol $serial\n";
174 gdb_expect {
175 -re "Remote target.*connected to.*$gdb_prompt" { }
176 default {
177 perror "Error reconnecting to board.";
178 return -1;
179 }
180 }
181
182 send_gdb "load $loader [target_info gdb_stub_offset]\n"
183 verbose "Loading $loader into $GDB" 2
184 set no_run_command 0;
185 gdb_expect 1200 {
186 -re "Loading.*$gdb_prompt $" {
187 verbose "Loaded $loader into $GDB" 1
188 }
189 -re "Transfer rate:.*Switching to remote protocol.*Remote debugging" {
190 set no_run_command 1;
191 }
192 -re "$gdb_prompt $" {
193 if $verbose>1 then {
194 perror "GDB couldn't load."
195 }
196 }
197 timeout {
198 if $verbose>1 then {
199 perror "Timed out trying to load $arg."
200 }
201 }
202 }
203
204 if !$no_run_command {
205 send_gdb "run\n";
206 gdb_expect 60 {
207 -re "A program is being debug.*Kill it.*y or n. $" {
208 send_gdb "y\n"
209 exp_continue
210 }
211 -re "The program being debugged .*y or n. $" {
212 send_gdb "y\n"
213 exp_continue
214 }
215 -re "Starting program:.*loader.*$" {
216 verbose "Starting loader succeeded"
217 }
218 timeout {
219 perror "(timeout) starting the loader" ;
220 return -1
221 }
222 default {
223 perror "error starting the loader";
224 }
225 }
226 }
227 sleep 2;
228 send_gdb "\ 3"
229 sleep 1;
230 send_gdb "\ 3"
231 verbose "Sent ^C^C"
232 gdb_expect 10 {
233 -re "Give up .and stop debugging it.*$" {
234 send_gdb "y\n"
235 exp_continue
236 }
237 -re "$gdb_prompt $" {
238 verbose "Running loader succeeded"
239 }
240 timeout {
241 warning "(timeout) interrupting the loader" ;
242 remote_close host;
243 }
244 default {
245 warning "error interrupting the loader";
246 }
247 }
248
249 gdb_exit;
250 return [gdb_start];
251 }
252 return 1;
253 }
254
255 proc gdb_run_cmd { args } {
256 global gdb_prompt
257
258 gdb_breakpoint exit;
259 send_gdb "set \$fp=0\n";
260 gdb_expect {
261 -re "$gdb_prompt" { }
262 }
263 # This is needed for the SparcLite. Whee.
264 if [target_info exists gdb,start_symbol] {
265 set start_comm "jump *[target_info gdb,start_symbol]\n";
266 } else {
267 set start_comm "jump *start\n";
268 }
269 send_gdb "break copyloop\n";
270 gdb_expect 10 {
271 -re "Breakpoint.*$gdb_prompt $" {
272 set start_comm "continue\n";
273 }
274 -re "$gdb_prompt $" { }
275 timeout { warning "break copyloop failed badly"; }
276 }
277 send_gdb $start_comm;
278 gdb_expect 10 {
279 -re "y or n. $" {
280 remote_send host "y\n"
281 exp_continue;
282 }
283 -re "Breakpoint.*in copyloop.*$gdb_prompt $" {
284 remote_send host "jump relocd\n";
285 exp_continue;
286 }
287 -re "Continuing at.*\[\r\n\]" { }
288 default {
289 return -1;
290 }
291 }
292
293 return "";
294 }
295
296
297 #
298 # gdb_load -- load a file into the GDB.
299 # Returns a 0 if there was an error,
300 # 1 if it load successfully.
301 #
302 proc gdb_load { arg } {
303 global verbose
304 global loadpath
305 global loadfile
306 global gdb_prompt
307 global GDB
308 global expect_out
309
310 set loadfile [file tail $arg]
311 set loadpath [file dirname $arg]
312
313 set protocol [target_info gdb_protocol];
314
315 if [is_remote host] {
316 set arg [remote_download host $arg];
317 }
318 send_gdb "file $arg\n"
319 gdb_expect 30 {
320 -re "A program is being debug.*Kill it.*y or n. $" {
321 send_gdb "y\n"
322 exp_continue
323 }
324 -re "Load new symbol table.*y or n. $" {
325 send_gdb "y\n"
326 exp_continue
327 }
328 -re "Reading symbols from.*done..*$gdb_prompt $" {}
329 -re "$gdb_prompt $" { perror "GDB couldn't read file" }
330 timeout {
331 perror "(timeout) read symbol file" ;
332 return -1
333 }
334 }
335
336 if [target_info exists gdb_serial] {
337 set gdb_serial [target_info gdb_serial];
338 } else {
339 if [target_info exists serial] {
340 set gdb_serial [target_info serial];
341 } else {
342 set gdb_serial [target_info netport];
343 }
344 }
345 send_gdb "target remote $gdb_serial\n"
346 gdb_expect 30 {
347 -re "Kill it?.*y or n.*" {
348 send_gdb "y\n";
349 exp_continue
350 }
351 -re "$gdb_prompt $" {
352 verbose "Set remote target to $gdb_serial" 2
353 }
354 timeout {
355 perror "Couldn't set remote target."
356 return -1
357 }
358 }
359 if [target_info exists gdb_load_offset] {
360 set offset "[target_info gdb_load_offset]";
361 } else {
362 set offset "";
363 }
364 send_gdb "load $arg $offset\n"
365 verbose "Loading $arg into $GDB" 2
366 gdb_expect 1200 {
367 -re "Loading.*$gdb_prompt $" {
368 verbose "Loaded $arg into $GDB" 1
369 }
370 -re "$gdb_prompt $" {
371 if $verbose>1 then {
372 perror "GDB couldn't load."
373 }
374 }
375 timeout {
376 if $verbose>1 then {
377 perror "Timed out trying to load $arg."
378 }
379 }
380 }
381 send_gdb "list main\n";
382 gdb_expect 60 {
383 -re "$gdb_prompt" { }
384 default {
385 perror "command for list main never completed";
386 return -1;
387 }
388 }
389
390 return 0
391 }