1 # Copyright 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}/stub-loader.c" $loader executable "libs=-Wl,-Ttext,[target_info gdb_stub_offset]"];
42 set result [target_compile "${libdir}/stub-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 } {
91 set is_running_stub 0;
93 if [target_info exists serial] {
94 set serial [target_info serial];
96 set serial [target_info netport];
98 set protocol [target_info gdb_protocol];
101 send_gdb "target $protocol $serial\n";
102 # 10 seconds may be a bit short.
104 -re "already.*y or n." {
108 -re "Remote target.*connected to.*$gdb_prompt" { set check_stub 0; }
109 -re "$gdb_prompt" { }
113 verbose "timed out, checking if stub is already running"
118 -re "$gdb_prompt" { }
126 if [target_info exists gdb_serial] {
127 set gdb_serial [target_info gdb_serial];
129 set gdb_serial $serial;
132 send_gdb "target remote $gdb_serial\n";
134 -re "Remote debugging.*$gdb_prompt" {
135 verbose "stub is already running"
136 set is_running_stub 1;
139 warning "board isn't responding";
141 remote_reboot target;
147 if { $is_running_stub == 0 } {
150 if [is_remote host] {
151 set loader [remote_download host "loader"];
155 send_gdb "file $loader\n";
157 -re "A program is being debug.*Kill it.*y or n. $" {
161 -re "Load new symbol table.*y or n. $" {
165 -re "Reading symbols from.*done..*$gdb_prompt $" {}
166 -re "$gdb_prompt $" { perror "GDB couldn't find loader" }
168 perror "(timeout) read symbol file" ;
173 send_gdb "target $protocol $serial\n";
175 -re "Remote target.*connected to.*$gdb_prompt" { }
177 perror "Error reconnecting to board.";
182 send_gdb "load $loader [target_info gdb_stub_offset]\n"
183 verbose "Loading $loader into $GDB" 2
184 set no_run_command 0;
186 -re "Loading.*$gdb_prompt $" {
187 verbose "Loaded $loader into $GDB" 1
189 -re "Transfer rate:.*Switching to remote protocol.*Remote debugging" {
190 set no_run_command 1;
192 -re "$gdb_prompt $" {
194 perror "GDB couldn't load."
199 perror "Timed out trying to load $arg."
204 if !$no_run_command {
207 -re "A program is being debug.*Kill it.*y or n. $" {
211 -re "The program being debugged .*y or n. $" {
215 -re "Starting program:.*loader.*$" {
216 verbose "Starting loader succeeded"
219 perror "(timeout) starting the loader" ;
223 perror "error starting the loader";
233 -re "Give up .and stop debugging it.*$" {
237 -re "$gdb_prompt $" {
238 verbose "Running loader succeeded"
241 warning "(timeout) interrupting the loader" ;
245 warning "error interrupting the loader";
255 proc gdb_run_cmd { args } {
259 send_gdb "set \$fp=0\n";
261 -re "$gdb_prompt" { }
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";
267 set start_comm "jump *start\n";
269 send_gdb "break copyloop\n";
271 -re "Breakpoint.*$gdb_prompt $" {
272 set start_comm "continue\n";
274 -re "$gdb_prompt $" { }
275 timeout { warning "break copyloop failed badly"; }
277 send_gdb $start_comm;
280 remote_send host "y\n"
283 -re "Breakpoint.*in copyloop.*$gdb_prompt $" {
284 remote_send host "jump relocd\n";
287 -re "Continuing at.*\[\r\n\]" { }
298 # gdb_load -- load a file into the GDB.
299 # Returns a 0 if there was an error,
300 # 1 if it load successfully.
302 proc gdb_load { arg } {
310 set loadfile [file tail $arg]
311 set loadpath [file dirname $arg]
313 set protocol [target_info gdb_protocol];
315 if [is_remote host] {
316 set arg [remote_download host $arg];
318 send_gdb "file $arg\n"
320 -re "A program is being debug.*Kill it.*y or n. $" {
324 -re "Load new symbol table.*y or n. $" {
328 -re "Reading symbols from.*done..*$gdb_prompt $" {}
329 -re "$gdb_prompt $" { perror "GDB couldn't read file" }
331 perror "(timeout) read symbol file" ;
336 if [target_info exists gdb_serial] {
337 set gdb_serial [target_info gdb_serial];
339 if [target_info exists serial] {
340 set gdb_serial [target_info serial];
342 set gdb_serial [target_info netport];
345 send_gdb "target remote $gdb_serial\n"
347 -re "Kill it?.*y or n.*" {
351 -re "$gdb_prompt $" {
352 verbose "Set remote target to $gdb_serial" 2
355 perror "Couldn't set remote target."
359 if [target_info exists gdb_load_offset] {
360 set offset "[target_info gdb_load_offset]";
364 send_gdb "load $arg $offset\n"
365 verbose "Loading $arg into $GDB" 2
367 -re "Loading.*$gdb_prompt $" {
368 verbose "Loaded $arg into $GDB" 1
370 -re "$gdb_prompt $" {
372 perror "GDB couldn't load."
377 perror "Timed out trying to load $arg."
381 send_gdb "list main\n";
383 -re "$gdb_prompt" { }
385 perror "command for list main never completed";