]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/config/sparclet.exp
* config/sh/tm-sh.h (BELIEVE_PCC_PROMOTION): Define, so that
[thirdparty/binutils-gdb.git] / gdb / testsuite / config / sparclet.exp
CommitLineData
fa5864d5 1# Copyright (C) 1996, 1997 Free Software Foundation, Inc.
787f6220
BM
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
25load_lib remote.exp
26load_lib gdb.exp
787f6220
BM
27
28#
29# Sparclet remote run command.
30#
787f6220
BM
31
32proc gdb_start { } {
85fbaa74 33 global gdb_prompt
787f6220 34
5e7be531
BM
35 if ![file exists loader] {
36 global libdir
37 set loader loader;
38
39 if [target_info exists gdb_stub_offset] {
6d2f93f8 40 set result [target_compile "${libdir}/stub-loader.c" $loader executable "libs=-Wl,-Ttext,[target_info gdb_stub_offset]"];
5e7be531 41 } else {
6d2f93f8 42 set result [target_compile "${libdir}/stub-loader.c" $loader executable "ldscript=[target_info gdb_stub_ldscript]"];
5e7be531 43 }
787f6220
BM
44 }
45
5e7be531
BM
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 }
787f6220
BM
62 }
63 }
787f6220 64
5e7be531
BM
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 }
787f6220 76 }
5e7be531
BM
77 if { $x == 4 } {
78 return -1;
79 }
80 gdb_exit;
81 sleep 5;
787f6220 82 }
5e7be531 83 return -1;
787f6220
BM
84}
85
5e7be531 86proc gdb_sparclet_startup { arg } {
85fbaa74 87 global gdb_prompt
787f6220 88 global GDB
dbd850bb 89 global verbose
787f6220 90
787f6220
BM
91 set is_running_stub 0;
92
5e7be531
BM
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 { }
787f6220 111 }
5e7be531 112 if { $check_stub } {
787f6220 113 verbose "timed out, checking if stub is already running"
787f6220 114 send_gdb "\003";
5e7be531
BM
115 sleep 1;
116 send_gdb "\003";
117 gdb_expect 10 {
118 -re "$gdb_prompt" { }
119 default {
120 remote_close host;
121 return -42;
787f6220
BM
122 }
123 }
5e7be531
BM
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;
787f6220
BM
143 }
144 }
145 }
146
147 if { $is_running_stub == 0 } {
148 global srcdir
149
5e7be531
BM
150 if [is_remote host] {
151 set loader [remote_download host "loader"];
152 } else {
153 set loader "loader";
787f6220 154 }
787f6220 155 send_gdb "file $loader\n";
40ac1624
BM
156 gdb_expect {
157 -re "A program is being debug.*Kill it.*y or n. $" {
787f6220
BM
158 send_gdb "y\n"
159 exp_continue
160 }
40ac1624 161 -re "Load new symbol table.*y or n. $" {
787f6220
BM
162 send_gdb "y\n"
163 exp_continue
164 }
40ac1624
BM
165 -re "Reading symbols from.*done..*$gdb_prompt $" {}
166 -re "$gdb_prompt $" { perror "GDB couldn't find loader" }
167 timeout {
787f6220
BM
168 perror "(timeout) read symbol file" ;
169 return -1
170 }
171 }
172
5e7be531 173 send_gdb "target $protocol $serial\n";
40ac1624
BM
174 gdb_expect {
175 -re "Remote target.*connected to.*$gdb_prompt" { }
176 default {
5e7be531 177 perror "Error reconnecting to board.";
787f6220
BM
178 return -1;
179 }
180 }
181
182 send_gdb "load $loader [target_info gdb_stub_offset]\n"
183 verbose "Loading $loader into $GDB" 2
eaac098b 184 set no_run_command 0;
5e7be531 185 gdb_expect 1200 {
40ac1624 186 -re "Loading.*$gdb_prompt $" {
787f6220 187 verbose "Loaded $loader into $GDB" 1
eaac098b
BM
188 }
189 -re "Transfer rate:.*Switching to remote protocol.*Remote debugging" {
190 set no_run_command 1;
787f6220 191 }
40ac1624 192 -re "$gdb_prompt $" {
787f6220
BM
193 if $verbose>1 then {
194 perror "GDB couldn't load."
195 }
196 }
40ac1624 197 timeout {
787f6220
BM
198 if $verbose>1 then {
199 perror "Timed out trying to load $arg."
200 }
201 }
202 }
203
eaac098b
BM
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 }
787f6220
BM
225 }
226 }
227 sleep 2;
228 send_gdb "\ 3"
229 sleep 1;
230 send_gdb "\ 3"
231 verbose "Sent ^C^C"
5e7be531
BM
232 gdb_expect 10 {
233 -re "Give up .and stop debugging it.*$" {
787f6220
BM
234 send_gdb "y\n"
235 exp_continue
236 }
5e7be531 237 -re "$gdb_prompt $" {
787f6220
BM
238 verbose "Running loader succeeded"
239 }
5e7be531
BM
240 timeout {
241 warning "(timeout) interrupting the loader" ;
242 remote_close host;
787f6220 243 }
5e7be531
BM
244 default {
245 warning "error interrupting the loader";
787f6220
BM
246 }
247 }
248
249 gdb_exit;
250 return [gdb_start];
251 }
252 return 1;
253}
254
255proc gdb_run_cmd { args } {
85fbaa74 256 global gdb_prompt
787f6220
BM
257
258 gdb_breakpoint exit;
259 send_gdb "set \$fp=0\n";
40ac1624 260 gdb_expect {
5e7be531 261 -re "$gdb_prompt" { }
787f6220 262 }
5e7be531
BM
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";
787f6220 273 }
5e7be531
BM
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;
787f6220
BM
290 }
291 }
5e7be531 292
787f6220
BM
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#
302proc gdb_load { arg } {
303 global verbose
304 global loadpath
305 global loadfile
85fbaa74 306 global gdb_prompt
787f6220
BM
307 global GDB
308 global expect_out
787f6220
BM
309
310 set loadfile [file tail $arg]
311 set loadpath [file dirname $arg]
312
5e7be531 313 set protocol [target_info gdb_protocol];
787f6220 314
5e7be531
BM
315 if [is_remote host] {
316 set arg [remote_download host $arg];
317 }
787f6220 318 send_gdb "file $arg\n"
5e7be531 319 gdb_expect 30 {
40ac1624 320 -re "A program is being debug.*Kill it.*y or n. $" {
787f6220
BM
321 send_gdb "y\n"
322 exp_continue
323 }
40ac1624 324 -re "Load new symbol table.*y or n. $" {
787f6220
BM
325 send_gdb "y\n"
326 exp_continue
327 }
40ac1624
BM
328 -re "Reading symbols from.*done..*$gdb_prompt $" {}
329 -re "$gdb_prompt $" { perror "GDB couldn't read file" }
330 timeout {
787f6220
BM
331 perror "(timeout) read symbol file" ;
332 return -1
333 }
334 }
335
336 if [target_info exists gdb_serial] {
5e7be531
BM
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
787f6220
BM
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
5e7be531 366 gdb_expect 1200 {
40ac1624 367 -re "Loading.*$gdb_prompt $" {
787f6220 368 verbose "Loaded $arg into $GDB" 1
787f6220 369 }
40ac1624 370 -re "$gdb_prompt $" {
787f6220
BM
371 if $verbose>1 then {
372 perror "GDB couldn't load."
373 }
374 }
40ac1624 375 timeout {
787f6220
BM
376 if $verbose>1 then {
377 perror "Timed out trying to load $arg."
378 }
379 }
380 }
381 send_gdb "list main\n";
5e7be531
BM
382 gdb_expect 60 {
383 -re "$gdb_prompt" { }
40ac1624 384 default {
787f6220
BM
385 perror "command for list main never completed";
386 return -1;
387 }
388 }
389
390 return 0
391}