1 # Copyright (C) 1996, 1997 Free Software Foundation, Inc.
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.
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.
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.
17 # Please email any bugs, comments, and/or additions to this file to:
20 # This file was written by Michael Snyder <msnyder@cygnus.com>.
22 # GDB support routines for a board using the sparclet remote debugging
29 # Sparclet remote run command.
35 if ![file exists loader] {
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]"];
42 set result [target_compile "${libdir}/sparclet-loader.c" $loader executable "ldscript=[target_info gdb_stub_ldscript]"];
46 verbose -log "$gdb_prompt is gdb prompt"
49 for { set y 0; } { $y < 4 } { incr y } {
50 if { [default_gdb_start] != 0 } {
54 if [target_info exists baud] {
55 send_gdb "set remotebaud [target_info baud]\n"
59 perror "Error setting baud rate."
65 for {set x 1;} { $x < 4 } {incr x} {
66 set result [gdb_sparclet_startup $result];
70 # mmmmm, magic numbers.
71 if { $result == -42 || $result == -43 } {
86 proc gdb_sparclet_startup { arg } {
90 set is_running_stub 0;
92 if [target_info exists serial] {
93 set serial [target_info serial];
95 set serial [target_info netport];
97 set protocol [target_info gdb_protocol];
100 send_gdb "target $protocol $serial\n";
101 # 10 seconds may be a bit short.
103 -re "already.*y or n." {
107 -re "Remote target.*connected to.*$gdb_prompt" { set check_stub 0; }
108 -re "$gdb_prompt" { }
112 verbose "timed out, checking if stub is already running"
117 -re "$gdb_prompt" { }
125 if [target_info exists gdb_serial] {
126 set gdb_serial [target_info gdb_serial];
128 set gdb_serial $serial;
131 send_gdb "target remote $gdb_serial\n";
133 -re "Remote debugging.*$gdb_prompt" {
134 verbose "stub is already running"
135 set is_running_stub 1;
138 warning "board isn't responding";
140 remote_reboot target;
146 if { $is_running_stub == 0 } {
149 if [is_remote host] {
150 set loader [remote_download host "loader"];
154 send_gdb "file $loader\n";
156 -re "A program is being debug.*Kill it.*y or n. $" {
160 -re "Load new symbol table.*y or n. $" {
164 -re "Reading symbols from.*done..*$gdb_prompt $" {}
165 -re "$gdb_prompt $" { perror "GDB couldn't find loader" }
167 perror "(timeout) read symbol file" ;
172 send_gdb "target $protocol $serial\n";
174 -re "Remote target.*connected to.*$gdb_prompt" { }
176 perror "Error reconnecting to board.";
181 send_gdb "load $loader [target_info gdb_stub_offset]\n"
182 verbose "Loading $loader into $GDB" 2
184 -re "Loading.*$gdb_prompt $" {
185 verbose "Loaded $loader into $GDB" 1
187 -re "$gdb_prompt $" {
189 perror "GDB couldn't load."
194 perror "Timed out trying to load $arg."
201 -re "A program is being debug.*Kill it.*y or n. $" {
205 -re "The program being debugged .*y or n. $" {
209 -re "Starting program:.*loader.*$" {
210 verbose "Starting loader succeeded"
213 perror "(timeout) starting the loader" ;
217 perror "error starting the loader";
226 -re "Give up .and stop debugging it.*$" {
230 -re "$gdb_prompt $" {
231 verbose "Running loader succeeded"
234 warning "(timeout) interrupting the loader" ;
238 warning "error interrupting the loader";
248 proc gdb_run_cmd { args } {
252 send_gdb "set \$fp=0\n";
254 -re "$gdb_prompt" { }
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";
260 set start_comm "jump *start\n";
262 send_gdb "break copyloop\n";
264 -re "Breakpoint.*$gdb_prompt $" {
265 set start_comm "continue\n";
267 -re "$gdb_prompt $" { }
268 timeout { warning "break copyloop failed badly"; }
270 send_gdb $start_comm;
273 remote_send host "y\n"
276 -re "Breakpoint.*in copyloop.*$gdb_prompt $" {
277 remote_send host "jump relocd\n";
280 -re "Continuing at.*\[\r\n\]" { }
291 # gdb_load -- load a file into the GDB.
292 # Returns a 0 if there was an error,
293 # 1 if it load successfully.
295 proc gdb_load { arg } {
303 set loadfile [file tail $arg]
304 set loadpath [file dirname $arg]
306 set protocol [target_info gdb_protocol];
308 if [is_remote host] {
309 set arg [remote_download host $arg];
311 send_gdb "file $arg\n"
313 -re "A program is being debug.*Kill it.*y or n. $" {
317 -re "Load new symbol table.*y or n. $" {
321 -re "Reading symbols from.*done..*$gdb_prompt $" {}
322 -re "$gdb_prompt $" { perror "GDB couldn't read file" }
324 perror "(timeout) read symbol file" ;
329 if [target_info exists gdb_serial] {
330 set gdb_serial [target_info gdb_serial];
332 if [target_info exists serial] {
333 set gdb_serial [target_info serial];
335 set gdb_serial [target_info netport];
338 send_gdb "target remote $gdb_serial\n"
340 -re "Kill it?.*y or n.*" {
344 -re "$gdb_prompt $" {
345 verbose "Set remote target to $gdb_serial" 2
348 perror "Couldn't set remote target."
352 if [target_info exists gdb_load_offset] {
353 set offset "[target_info gdb_load_offset]";
357 send_gdb "load $arg $offset\n"
358 verbose "Loading $arg into $GDB" 2
360 -re "Loading.*$gdb_prompt $" {
361 verbose "Loaded $arg into $GDB" 1
363 -re "$gdb_prompt $" {
365 perror "GDB couldn't load."
370 perror "Timed out trying to load $arg."
374 send_gdb "list main\n";
376 -re "$gdb_prompt" { }
378 perror "command for list main never completed";