Commit | Line | Data |
---|---|---|
787f6220 BM |
1 | # Copyright (C) 1996 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 Mitsubishi M32R remote debugging | |
23 | # protocol. | |
24 | ||
25 | load_lib remote.exp | |
26 | load_lib gdb.exp | |
27 | ||
28 | ||
29 | # | |
30 | # M32R remote run command. | |
31 | # | |
32 | # This requires that we beep the user and ask him to push the board reset! | |
33 | # Then we will switch to the monitor target, run the program, use 2 ^C's | |
34 | # to interrupt the monitor target, and switch back to the remote target. | |
35 | # Then we have to do a continue to get past the stub breakpoint. | |
36 | # | |
37 | ||
38 | proc gdb_run_cmd {} { | |
39 | global prompt | |
40 | global gdb_spawn_id | |
41 | ||
42 | set timeout 60 | |
43 | verbose "Timeout is now $timeout seconds, starting remote stub" 2 | |
44 | send_user "\aPlease reset the board now...\a\n" | |
45 | sleep 1 | |
46 | send_user "\a\n" | |
47 | sleep 1 | |
48 | send_user "\a\n" | |
49 | sleep 1 | |
50 | send_user "\a\n" | |
51 | ||
52 | # go back to monitor, run the program, interrupt it, and start remote. | |
53 | ||
54 | if [target_info exists gdb_protocol] { | |
55 | set protocol [target_info gdb_protocol]; | |
56 | } else { | |
57 | set protocol "sparclet" | |
58 | } | |
59 | if [target_info exists serial] { | |
60 | set targetname [target_info serial]; | |
61 | send_gdb "target $protocol [target_info serial]\n"; | |
62 | } else { | |
63 | if ![target_info exists netport] { | |
64 | perror "Need either netport or gdb_serial entry for [target_info name]."; | |
65 | return -1; | |
66 | } | |
67 | set targetname [target_info netport]; | |
68 | send_gdb "target $protocol udp [target_info netport]\n"; | |
69 | } | |
70 | ||
71 | expect { | |
72 | -i $gdb_spawn_id -re "A program is being debug.*Kill it.*y or n. $" { | |
73 | send_gdb "y\n" | |
74 | exp_continue | |
75 | } | |
76 | -i $gdb_spawn_id -re "Remote target.*$prompt $" { } | |
77 | -i $gdb_spawn_id -re ".*SPARCLET appears to be alive.*$prompt $" { | |
78 | if $verbose>1 then { | |
79 | send_user "Set target to $targetname\n" | |
80 | } | |
81 | } | |
82 | -i $gdb_spawn_id timeout { | |
83 | set timeout 10 | |
84 | verbose "Timeout is now $timeout seconds" 2 | |
85 | perror "Couldn't set M32R target." | |
86 | return -1 | |
87 | } | |
88 | } | |
89 | ||
90 | send_gdb "disable\n"; | |
91 | expect { | |
92 | -i $gdb_spawn_id -re ".*$prompt $" { | |
93 | verbose "Breakpoints disabled" 2 | |
94 | } | |
95 | -i $gdb_spawn_id timeout { | |
96 | perror "(timeout) disabling breakpoints"; | |
97 | return -1 | |
98 | } | |
99 | -i $gdb_spawn_id default { | |
100 | perror "error disabling breakpoints"; | |
101 | } | |
102 | } | |
103 | send_gdb "run\n"; | |
104 | expect { | |
105 | -i $gdb_spawn_id -re "A program is being debug.*Kill it.*y or n. $" { | |
106 | send_gdb "y\n" | |
107 | exp_continue | |
108 | } | |
109 | -i $gdb_spawn_id -re "The program being debugged .*y or n. $" { | |
110 | send_gdb "y\n" | |
111 | exp_continue | |
112 | } | |
113 | -i $gdb_spawn_id -re ".*Starting program:.*$" { | |
114 | verbose "Starting remote stub succeeded" | |
115 | } | |
116 | -i $gdb_spawn_id timeout { | |
117 | perror "(timeout) starting the remote stub" ; | |
118 | return -1 | |
119 | } | |
120 | -i $gdb_spawn_id default { | |
121 | perror "error starting the remote stub"; | |
122 | } | |
123 | } | |
124 | sleep 2; | |
125 | send_gdb "\ 3" | |
126 | sleep 1; | |
127 | send_gdb "\ 3" | |
128 | verbose "Sent ^C^C" | |
129 | expect { | |
130 | -i $gdb_spawn_id -re ".*Give up .and stop debugging it.*$" { | |
131 | send_gdb "y\n" | |
132 | exp_continue | |
133 | } | |
134 | -i $gdb_spawn_id -re ".*$prompt $" { | |
135 | verbose "interrupting remote stub succeeded" | |
136 | } | |
137 | -i $gdb_spawn_id timeout { | |
138 | perror "(timeout) interrupting the remote stub"; | |
139 | return -1 | |
140 | } | |
141 | -i $gdb_spawn_id default { | |
142 | perror "error interrupting the remote stub"; | |
143 | } | |
144 | } | |
145 | ||
146 | if [target_info exists gdb_serial] { | |
147 | send_gdb "target remote [target_info gdb_serial]\n" | |
148 | expect { | |
149 | -i $gdb_spawn_id -re ".*Kill it?.*y or n.*" { | |
150 | send_gdb "y\n"; | |
151 | exp_continue | |
152 | } | |
153 | -i $gdb_spawn_id -re ".*$prompt $" { | |
154 | verbose "connected to stub at [target_info gdb_serial]" 2 | |
155 | } | |
156 | -i $gdb_spawn_id timeout { | |
157 | set timeout 10 | |
158 | verbose "Timeout is now $timeout seconds" 2 | |
159 | perror "Couldn't set remote target." | |
160 | return -1 | |
161 | } | |
162 | } | |
163 | } | |
164 | ||
165 | send_gdb "enable\n"; | |
166 | expect { | |
167 | -i $gdb_spawn_id -re ".*$prompt $" { | |
168 | verbose "Breakpoints enabled" 2 | |
169 | } | |
170 | -i $gdb_spawn_id timeout { | |
171 | perror "(timeout) enabling breakpoints"; | |
172 | return -1 | |
173 | } | |
174 | -i $gdb_spawn_id default { | |
175 | perror "error enabling breakpoints"; | |
176 | } | |
177 | } | |
178 | send_gdb "continue\n"; | |
179 | return | |
180 | } | |
181 | ||
182 | ||
183 | # | |
184 | # gdb_load -- load a file into the GDB. | |
185 | # Returns a 0 if there was an error, | |
186 | # 1 if it load successfully. | |
187 | # | |
188 | proc gdb_load { arg } { | |
189 | global verbose | |
190 | global loadpath | |
191 | global loadfile | |
192 | global prompt | |
193 | global GDB | |
194 | global expect_out | |
195 | global gdb_spawn_id | |
196 | ||
197 | set loadfile [file tail $arg] | |
198 | set loadpath [file dirname $arg] | |
199 | ||
200 | if [target_info exists gdb_protocol] { | |
201 | set protocol [target_info gdb_protocol]; | |
202 | } else { | |
203 | set protocol "m32r" | |
204 | } | |
205 | ||
206 | # get the stub-based loader for faster loading | |
207 | send_gdb "file [target_info gdb_loader]\n" | |
208 | expect { | |
209 | -i $gdb_spawn_id -re "A program is being debug.*Kill it.*y or n. $" { | |
210 | send_gdb "y\n" | |
211 | exp_continue | |
212 | } | |
213 | -i $gdb_spawn_id -re "Load new symbol table.*y or n. $" { | |
214 | send_gdb "y\n" | |
215 | exp_continue | |
216 | } | |
217 | -i $gdb_spawn_id -re "Reading symbols from.*done..*$prompt $" {} | |
218 | -i $gdb_spawn_id -re "$prompt $" { perror "GDB couldn't find loader" } | |
219 | -i $gdb_spawn_id timeout { | |
220 | perror "(timeout) read symbol file" ; | |
221 | return -1 | |
222 | } | |
223 | } | |
224 | ||
225 | if [target_info exists serial] { | |
226 | set targetname [target_info serial]; | |
227 | send_gdb "target $protocol [target_info serial]\n"; | |
228 | } else { | |
229 | if ![target_info exists netport] { | |
230 | perror "Need either netport or gdb_serial entry for [target_info name]."; | |
231 | return -1; | |
232 | } | |
233 | set targetname [target_info netport]; | |
234 | send_gdb "target $protocol udp [target_info netport]\n"; | |
235 | } | |
236 | expect { | |
237 | -i $gdb_spawn_id -re "Remote target.*$prompt $" { } | |
238 | -i $gdb_spawn_id -re ".*SPARCLET appears to be alive.*$prompt $" { | |
239 | if $verbose>1 then { | |
240 | send_user "Set target to $targetname\n" | |
241 | } | |
242 | } | |
243 | -i $gdb_spawn_id timeout { | |
244 | set timeout 10 | |
245 | verbose "Timeout is now $timeout seconds" 2 | |
246 | perror "Couldn't set M32R target." | |
247 | return -1 | |
248 | } | |
249 | } | |
250 | ||
251 | send_gdb "run\n"; | |
252 | expect { | |
253 | -i $gdb_spawn_id -re "A program is being debug.*Kill it.*y or n. $" { | |
254 | send_gdb "y\n" | |
255 | exp_continue | |
256 | } | |
257 | -i $gdb_spawn_id -re "The program being debugged .*y or n. $" { | |
258 | send_gdb "y\n" | |
259 | exp_continue | |
260 | } | |
261 | -i $gdb_spawn_id -re ".*Starting program:.*loader.*$" { | |
262 | verbose "Starting loader succeeded" | |
263 | } | |
264 | -i $gdb_spawn_id timeout { | |
265 | perror "(timeout) starting the loader" ; | |
266 | return -1 | |
267 | } | |
268 | -i $gdb_spawn_id default { | |
269 | perror "error starting the loader"; | |
270 | } | |
271 | } | |
272 | sleep 2; | |
273 | send_gdb "\ 3" | |
274 | sleep 1; | |
275 | send_gdb "\ 3" | |
276 | verbose "Sent ^C^C" | |
277 | expect { | |
278 | -i $gdb_spawn_id -re ".*Give up .and stop debugging it.*$" { | |
279 | send_gdb "y\n" | |
280 | exp_continue | |
281 | } | |
282 | -i $gdb_spawn_id -re ".*$prompt $" { | |
283 | verbose "Running loader succeeded" | |
284 | } | |
285 | -i $gdb_spawn_id timeout { | |
286 | perror "(timeout) interrupting the loader" ; | |
287 | return -1 | |
288 | } | |
289 | -i $gdb_spawn_id default { | |
290 | perror "error interrupting the loader"; | |
291 | } | |
292 | } | |
293 | ||
294 | # Now ready to actually load the file: | |
295 | ||
296 | send_gdb "file $arg\n" | |
297 | expect { | |
298 | -i $gdb_spawn_id -re "A program is being debug.*Kill it.*y or n. $" { | |
299 | send_gdb "y\n" | |
300 | exp_continue | |
301 | } | |
302 | -i $gdb_spawn_id -re "Load new symbol table.*y or n. $" { | |
303 | send_gdb "y\n" | |
304 | exp_continue | |
305 | } | |
306 | -i $gdb_spawn_id -re "Reading symbols from.*done..*$prompt $" {} | |
307 | -i $gdb_spawn_id -re "$prompt $" { perror "GDB couldn't read file" } | |
308 | -i $gdb_spawn_id timeout { | |
309 | perror "(timeout) read symbol file" ; | |
310 | return -1 | |
311 | } | |
312 | } | |
313 | ||
314 | if [target_info exists gdb_serial] { | |
315 | send_gdb "target remote [target_info gdb_serial]\n" | |
316 | expect { | |
317 | -i $gdb_spawn_id -re ".*Kill it?.*y or n.*" { | |
318 | send_gdb "y\n"; | |
319 | exp_continue | |
320 | } | |
321 | -i $gdb_spawn_id -re ".*$prompt $" { | |
322 | verbose "Set remote target to [target_info serial]" 2 | |
323 | } | |
324 | -i $gdb_spawn_id timeout { | |
325 | set timeout 10 | |
326 | verbose "Timeout is now $timeout seconds" 2 | |
327 | perror "Couldn't set remote target." | |
328 | return -1 | |
329 | } | |
330 | } | |
331 | } | |
332 | if [target_info exists gdb_load_offset] { | |
333 | set offset "[target_info gdb_load_offset]"; | |
334 | } else { | |
335 | set offset ""; | |
336 | } | |
337 | send_gdb "load $arg $offset\n" | |
338 | verbose "Loading $arg into $GDB" 2 | |
339 | set timeout 1200 | |
340 | verbose "Timeout is now $timeout seconds" 2 | |
341 | expect { | |
342 | -i $gdb_spawn_id -re "Loading.*$prompt $" { | |
343 | verbose "Loaded $arg into $GDB" 1 | |
344 | set timeout 60 | |
345 | verbose "Timeout is now $timeout seconds" 2 | |
346 | } | |
347 | -i $gdb_spawn_id -re "$prompt $" { | |
348 | if $verbose>1 then { | |
349 | perror "GDB couldn't load." | |
350 | } | |
351 | } | |
352 | -i $gdb_spawn_id timeout { | |
353 | if $verbose>1 then { | |
354 | perror "Timed out trying to load $arg." | |
355 | } | |
356 | } | |
357 | } | |
358 | ||
359 | send_user "\aPlease reset the board now...\a\n" | |
360 | sleep 1 | |
361 | send_user "\a\n" | |
362 | sleep 1 | |
363 | send_user "\a\n" | |
364 | sleep 1 | |
365 | send_user "\a\n" | |
366 | ||
367 | # go back to monitor, run the program, interrupt it, and start remote. | |
368 | ||
369 | if [target_info exists serial] { | |
370 | set targetname [target_info serial]; | |
371 | send_gdb "target $protocol [target_info serial]\n"; | |
372 | } else { | |
373 | if ![target_info exists netport] { | |
374 | perror "Need either netport or gdb_serial entry for [target_info name]."; | |
375 | return -1; | |
376 | } | |
377 | set targetname [target_info netport]; | |
378 | send_gdb "target $protocol udp [target_info netport]\n"; | |
379 | } | |
380 | ||
381 | expect { | |
382 | -i $gdb_spawn_id -re "A program is being debug.*Kill it.*y or n. $" { | |
383 | send_gdb "y\n" | |
384 | exp_continue | |
385 | } | |
386 | -i $gdb_spawn_id -re "Remote target.*$prompt $" { } | |
387 | -i $gdb_spawn_id -re ".*SPARCLET appears to be alive.*$prompt $" { | |
388 | if $verbose>1 then { | |
389 | send_user "Set target to $targetname\n" | |
390 | } | |
391 | } | |
392 | -i $gdb_spawn_id timeout { | |
393 | set timeout 10 | |
394 | verbose "Timeout is now $timeout seconds" 2 | |
395 | perror "Couldn't set M32R target." | |
396 | return -1 | |
397 | } | |
398 | } | |
399 | ||
400 | send_gdb "run\n"; | |
401 | expect { | |
402 | -i $gdb_spawn_id -re "A program is being debug.*Kill it.*y or n. $" { | |
403 | send_gdb "y\n" | |
404 | exp_continue | |
405 | } | |
406 | -i $gdb_spawn_id -re "The program being debugged .*y or n. $" { | |
407 | send_gdb "y\n" | |
408 | exp_continue | |
409 | } | |
410 | -i $gdb_spawn_id -re ".*Starting program:.*$" { | |
411 | verbose "Starting remote stub succeeded" | |
412 | } | |
413 | -i $gdb_spawn_id timeout { | |
414 | perror "(timeout) starting the remote stub" ; | |
415 | return -1 | |
416 | } | |
417 | -i $gdb_spawn_id default { | |
418 | perror "error starting the remote stub"; | |
419 | } | |
420 | } | |
421 | sleep 2; | |
422 | send_gdb "\ 3" | |
423 | sleep 1; | |
424 | send_gdb "\ 3" | |
425 | verbose "Sent ^C^C" | |
426 | expect { | |
427 | -i $gdb_spawn_id -re ".*Give up .and stop debugging it.*$" { | |
428 | send_gdb "y\n" | |
429 | exp_continue | |
430 | } | |
431 | -i $gdb_spawn_id -re ".*$prompt $" { | |
432 | verbose "interrupting remote stub succeeded" | |
433 | } | |
434 | -i $gdb_spawn_id timeout { | |
435 | perror "(timeout) interrupting the remote stub"; | |
436 | return -1 | |
437 | } | |
438 | -i $gdb_spawn_id default { | |
439 | perror "error interrupting the remote stub"; | |
440 | } | |
441 | } | |
442 | ||
443 | if [target_info exists gdb_serial] { | |
444 | send_gdb "target remote [target_info gdb_serial]\n" | |
445 | expect { | |
446 | -i $gdb_spawn_id -re ".*Kill it?.*y or n.*" { | |
447 | send_gdb "y\n"; | |
448 | exp_continue | |
449 | } | |
450 | -i $gdb_spawn_id -re ".*$prompt $" { | |
451 | verbose "connected to stub at [target_info gdb_serial]" 2 | |
452 | } | |
453 | -i $gdb_spawn_id timeout { | |
454 | set timeout 10 | |
455 | verbose "Timeout is now $timeout seconds" 2 | |
456 | perror "Couldn't set remote target." | |
457 | return -1 | |
458 | } | |
459 | } | |
460 | } | |
461 | return 0 | |
462 | } | |
463 |