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