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