1 /* Remote target communications for serial-line targets in custom GDB protocol
2 Copyright 1988, 91, 92, 93, 94, 95, 96, 97, 1998
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* Remote communication protocol.
23 A debug packet whose contents are <data>
24 is encapsulated for transmission in the form:
26 $ <data> # CSUM1 CSUM2
28 <data> must be ASCII alphanumeric and cannot include characters
29 '$' or '#'. If <data> starts with two characters followed by
30 ':', then the existing stubs interpret this as a sequence number.
32 CSUM1 and CSUM2 are ascii hex representation of an 8-bit
33 checksum of <data>, the most significant nibble is sent first.
34 the hex digits 0-9,a-f are used.
36 Receiver responds with:
38 + - if CSUM is correct and ready for next packet
39 - - if CSUM is incorrect
42 Most values are encoded in ascii hex digits. Signal numbers are according
43 to the numbering in target.h.
47 set thread Hct... Set thread for subsequent operations.
48 c = 'c' for thread used in step and
49 continue; t... can be -1 for all
51 c = 'g' for thread used in other
52 operations. If zero, pick a thread,
58 reply XX....X Each byte of register data
59 is described by two hex digits.
60 Registers are in the internal order
61 for GDB, and the bytes in a register
62 are in the same order the machine uses.
65 write regs GXX..XX Each byte of register data
66 is described by two hex digits.
70 write reg Pn...=r... Write register n... with value r...,
71 which contains two hex digits for each
72 byte in the register (target byte
76 (not supported by all stubs).
78 read mem mAA..AA,LLLL AA..AA is address, LLLL is length.
79 reply XX..XX XX..XX is mem contents
80 Can be fewer bytes than requested
81 if able to read only part of the data.
84 write mem MAA..AA,LLLL:XX..XX
86 LLLL is number of bytes,
89 ENN for an error (this includes the case
90 where only part of the data was
93 continue cAA..AA AA..AA is address to resume
95 resume at same address.
97 step sAA..AA AA..AA is address to resume
99 resume at same address.
101 continue with Csig;AA..AA Continue with signal sig (hex signal
102 signal number). If ;AA..AA is omitted, resume
105 step with Ssig;AA..AA Like 'C' but step not continue.
108 last signal ? Reply the current reason for stopping.
109 This is the same reply as is generated
110 for step or cont : SAA where AA is the
115 There is no immediate reply to step or cont.
116 The reply comes when the machine stops.
117 It is SAA AA is the signal number.
119 or... TAAn...:r...;n...:r...;n...:r...;
121 n... = register number (hex)
122 r... = register contents
124 r... = thread process ID. This is
126 n... = other string not starting
127 with valid hex digit.
128 gdb should ignore this n,r pair
129 and go on to the next. This way
130 we can extend the protocol.
131 or... WAA The process exited, and AA is
132 the exit status. This is only
133 applicable for certains sorts of
135 or... XAA The process terminated with signal
137 or... OXX..XX XX..XX is hex encoding of ASCII data. This
138 can happen at any time while the program is
139 running and the debugger should
140 continue to wait for 'W', 'T', etc.
142 thread alive TXX Find out if the thread XX is alive.
143 reply OK thread is still alive
146 remote restart RXX Restart the remote server
148 extended ops ! Use the extended remote protocol.
149 Sticky -- only needs to be set once.
153 toggle debug d toggle debug flag (see 386 & 68k stubs)
154 reset r reset -- see sparc stub.
155 reserved <other> On other requests, the stub should
156 ignore the request and send an empty
157 response ($#<checksum>). This way
158 we can extend the protocol and GDB
159 can tell whether the stub it is
160 talking to uses the old or the new.
161 search tAA:PP,MM Search backwards starting at address
162 AA for a match with pattern PP and
163 mask MM. PP and MM are 4 bytes.
164 Not supported by all stubs.
166 general query qXXXX Request info about XXXX.
167 general set QXXXX=yyyy Set value of XXXX to yyyy.
168 query sect offs qOffsets Get section offsets. Reply is
169 Text=xxx;Data=yyy;Bss=zzz
171 Responses can be run-length encoded to save space. A '*' means that
172 the next character is an ASCII encoding giving a repeat count which
173 stands for that many repititions of the character preceding the '*'.
174 The encoding is n+29, yielding a printable character where n >=3
175 (which is where rle starts to win). Don't use an n > 126.
178 "0* " means the same as "0000". */
181 #include "gdb_string.h"
184 #include "inferior.h"
189 /*#include "terminal.h"*/
191 #include "objfiles.h"
192 #include "gdb-stabs.h"
193 #include "gdbthread.h"
198 #include <sys/types.h>
204 /* Prototypes for local functions */
206 static int remote_write_bytes
PARAMS ((CORE_ADDR memaddr
,
207 char *myaddr
, int len
));
209 static int remote_read_bytes
PARAMS ((CORE_ADDR memaddr
,
210 char *myaddr
, int len
));
212 static void remote_files_info
PARAMS ((struct target_ops
*ignore
));
214 static int remote_xfer_memory
PARAMS ((CORE_ADDR memaddr
, char *myaddr
,
215 int len
, int should_write
,
216 struct target_ops
*target
));
218 static void remote_prepare_to_store
PARAMS ((void));
220 static void remote_fetch_registers
PARAMS ((int regno
));
222 static void remote_resume
PARAMS ((int pid
, int step
,
223 enum target_signal siggnal
));
225 static int remote_start_remote
PARAMS ((char *dummy
));
227 static void remote_open
PARAMS ((char *name
, int from_tty
));
229 static void extended_remote_open
PARAMS ((char *name
, int from_tty
));
231 static void remote_open_1
PARAMS ((char *, int, struct target_ops
*, int extended_p
));
233 static void remote_close
PARAMS ((int quitting
));
235 static void remote_store_registers
PARAMS ((int regno
));
237 static void remote_mourn
PARAMS ((void));
239 static void extended_remote_restart
PARAMS ((void));
241 static void extended_remote_mourn
PARAMS ((void));
243 static void extended_remote_create_inferior
PARAMS ((char *, char *, char **));
245 static void remote_mourn_1
PARAMS ((struct target_ops
*));
247 static void remote_send
PARAMS ((char *buf
));
249 static int readchar
PARAMS ((int timeout
));
251 static int remote_wait
PARAMS ((int pid
, struct target_waitstatus
*status
));
253 static void remote_kill
PARAMS ((void));
255 static int tohex
PARAMS ((int nib
));
257 static void remote_detach
PARAMS ((char *args
, int from_tty
));
259 static void remote_interrupt
PARAMS ((int signo
));
261 static void interrupt_query
PARAMS ((void));
263 static void set_thread
PARAMS ((int, int));
265 static int remote_thread_alive
PARAMS ((int));
267 static void get_offsets
PARAMS ((void));
269 static int read_frame
PARAMS ((char *));
271 static int remote_insert_breakpoint
PARAMS ((CORE_ADDR
, char *));
273 static int remote_remove_breakpoint
PARAMS ((CORE_ADDR
, char *));
275 static int hexnumlen
PARAMS ((ULONGEST num
));
277 static void init_remote_ops
PARAMS ((void));
279 static void init_extended_remote_ops
PARAMS ((void));
281 static void remote_stop
PARAMS ((void));
283 static int hexnumstr
PARAMS ((char *, ULONGEST
));
285 static CORE_ADDR remote_address_masked
PARAMS ((CORE_ADDR
));
287 static void print_packet
PARAMS ((char *));
289 static unsigned long crc32
PARAMS ((unsigned char *, int, unsigned int));
291 static void compare_sections_command
PARAMS ((char *, int));
293 static void packet_command
PARAMS ((char *, int));
295 /* exported functions */
297 extern int fromhex
PARAMS ((int a
));
299 extern void getpkt
PARAMS ((char *buf
, int forever
));
301 extern int putpkt
PARAMS ((char *buf
));
303 void remote_console_output
PARAMS ((char *));
305 void open_remote_target
PARAMS ((char *, int, struct target_ops
*, int));
307 void _initialize_remote
PARAMS ((void));
311 static struct target_ops remote_ops
;
313 static struct target_ops extended_remote_ops
;
315 /* This was 5 seconds, which is a long time to sit and wait.
316 Unless this is going though some terminal server or multiplexer or
317 other form of hairy serial connection, I would think 2 seconds would
320 /* Changed to allow option to set timeout value.
321 was static int remote_timeout = 2; */
322 extern int remote_timeout
;
324 /* This variable chooses whether to send a ^C or a break when the user
325 requests program interruption. Although ^C is usually what remote
326 systems expect, and that is the default here, sometimes a break is
327 preferable instead. */
329 static int remote_break
;
331 /* Has the user attempted to interrupt the target? If so, then offer
332 the user the opportunity to bail out completely if he interrupts
334 static int interrupted_already
= 0;
336 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
337 remote_open knows that we don't have a file open when the program
339 static serial_t remote_desc
= NULL
;
341 /* Having this larger than 400 causes us to be incompatible with m68k-stub.c
342 and i386-stub.c. Normally, no one would notice because it only matters
343 for writing large chunks of memory (e.g. in downloads). Also, this needs
344 to be more than 400 if required to hold the registers (see below, where
345 we round it up based on REGISTER_BYTES). */
348 /* Maximum number of bytes to read/write at once. The value here
349 is chosen to fill up a packet (the headers account for the 32). */
350 #define MAXBUFBYTES ((PBUFSIZ-32)/2)
352 /* Round up PBUFSIZ to hold all the registers, at least. */
353 /* The blank line after the #if seems to be required to work around a
354 bug in HP's PA compiler. */
355 #if REGISTER_BYTES > MAXBUFBYTES
358 #define PBUFSIZ (REGISTER_BYTES * 2 + 32)
361 /* This variable sets the number of bytes to be written to the target
362 in a single packet. Normally PBUFSIZ is satisfactory, but some
363 targets need smaller values (perhaps because the receiving end
366 static int remote_write_size
= PBUFSIZ
;
368 /* This variable sets the number of bits in an address that are to be
369 sent in a memory ("M" or "m") packet. Normally, after stripping
370 leading zeros, the entire address would be sent. This variable
371 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
372 initial implementation of remote.c restricted the address sent in
373 memory packets to ``host::sizeof long'' bytes - (typically 32
374 bits). Consequently, for 64 bit targets, the upper 32 bits of an
375 address was never sent. Since fixing this bug may cause a break in
376 some remote targets this variable is principly provided to
377 facilitate backward compatibility. */
379 static int remote_address_size
;
381 /* This is the size (in chars) of the first response to the `g' command. This
382 is used to limit the size of the memory read and write commands to prevent
383 stub buffers from overflowing. The size does not include headers and
384 trailers, it is only the payload size. */
386 static int remote_register_buf_size
= 0;
388 /* Should we try the 'P' request? If this is set to one when the stub
389 doesn't support 'P', the only consequence is some unnecessary traffic. */
390 static int stub_supports_P
= 1;
392 /* These are pointers to hook functions that may be set in order to
393 modify resume/wait behavior for a particular architecture. */
395 void (*target_resume_hook
) PARAMS ((void));
396 void (*target_wait_loop_hook
) PARAMS ((void));
399 /* These are the threads which we last sent to the remote system. -1 for all
400 or -2 for not sent yet. */
410 int state
= gen
? general_thread
: cont_thread
;
414 buf
[1] = gen
? 'g' : 'c';
421 sprintf (&buf
[2], "-%x", -th
);
423 sprintf (&buf
[2], "%x", th
);
432 /* Return nonzero if the thread TH is still alive on the remote system. */
435 remote_thread_alive (th
)
442 sprintf (&buf
[1], "-%x", -th
);
444 sprintf (&buf
[1], "%x", th
);
447 return (buf
[0] == 'O' && buf
[1] == 'K');
450 /* Restart the remote side; this is an extended protocol operation. */
453 extended_remote_restart ()
457 /* Send the restart command; for reasons I don't understand the
458 remote side really expects a number after the "R". */
460 sprintf (&buf
[1], "%x", 0);
463 /* Now query for status so this looks just like we restarted
464 gdbserver from scratch. */
469 /* Clean up connection to a remote debugger. */
473 remote_close (quitting
)
477 SERIAL_CLOSE (remote_desc
);
481 /* Query the remote side for the text, data and bss offsets. */
486 char buf
[PBUFSIZ
], *ptr
;
488 CORE_ADDR text_addr
, data_addr
, bss_addr
;
489 struct section_offsets
*offs
;
495 if (buf
[0] == '\000')
496 return; /* Return silently. Stub doesn't support this
500 warning ("Remote failure reply: %s", buf
);
504 /* Pick up each field in turn. This used to be done with scanf, but
505 scanf will make trouble if CORE_ADDR size doesn't match
506 conversion directives correctly. The following code will work
507 with any size of CORE_ADDR. */
508 text_addr
= data_addr
= bss_addr
= 0;
512 if (strncmp (ptr
, "Text=", 5) == 0)
515 /* Don't use strtol, could lose on big values. */
516 while (*ptr
&& *ptr
!= ';')
517 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
522 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
525 while (*ptr
&& *ptr
!= ';')
526 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
531 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
534 while (*ptr
&& *ptr
!= ';')
535 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
541 error ("Malformed response to offset query, %s", buf
);
543 if (symfile_objfile
== NULL
)
546 offs
= (struct section_offsets
*) alloca (sizeof (struct section_offsets
)
547 + symfile_objfile
->num_sections
548 * sizeof (offs
->offsets
));
549 memcpy (offs
, symfile_objfile
->section_offsets
,
550 sizeof (struct section_offsets
)
551 + symfile_objfile
->num_sections
552 * sizeof (offs
->offsets
));
554 ANOFFSET (offs
, SECT_OFF_TEXT
) = text_addr
;
556 /* This is a temporary kludge to force data and bss to use the same offsets
557 because that's what nlmconv does now. The real solution requires changes
558 to the stub and remote.c that I don't have time to do right now. */
560 ANOFFSET (offs
, SECT_OFF_DATA
) = data_addr
;
561 ANOFFSET (offs
, SECT_OFF_BSS
) = data_addr
;
563 objfile_relocate (symfile_objfile
, offs
);
566 /* Stub for catch_errors. */
569 remote_start_remote (dummy
)
572 immediate_quit
= 1; /* Allow user to interrupt it */
574 /* Ack any packet which the remote side has already sent. */
575 SERIAL_WRITE (remote_desc
, "+", 1);
577 /* Let the stub know that we want it to return the thread. */
580 get_offsets (); /* Get text, data & bss offsets */
582 putpkt ("?"); /* initiate a query from remote machine */
585 start_remote (); /* Initialize gdb process mechanisms */
589 /* Open a connection to a remote debugger.
590 NAME is the filename used for communication. */
593 remote_open (name
, from_tty
)
597 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
600 /* Open a connection to a remote debugger using the extended
601 remote gdb protocol. NAME is the filename used for communication. */
604 extended_remote_open (name
, from_tty
)
608 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1/*extended_p*/);
611 /* Generic code for opening a connection to a remote target. */
612 static DCACHE
*remote_dcache
;
615 remote_open_1 (name
, from_tty
, target
, extended_p
)
618 struct target_ops
*target
;
622 error ("To open a remote debug connection, you need to specify what serial\n\
623 device is attached to the remote system (e.g. /dev/ttya).");
625 target_preopen (from_tty
);
627 unpush_target (target
);
629 remote_dcache
= dcache_init (remote_read_bytes
, remote_write_bytes
);
631 remote_desc
= SERIAL_OPEN (name
);
633 perror_with_name (name
);
637 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
639 SERIAL_CLOSE (remote_desc
);
640 perror_with_name (name
);
645 SERIAL_RAW (remote_desc
);
647 /* If there is something sitting in the buffer we might take it as a
648 response to a command, which would be bad. */
649 SERIAL_FLUSH_INPUT (remote_desc
);
653 puts_filtered ("Remote debugging using ");
654 puts_filtered (name
);
655 puts_filtered ("\n");
657 push_target (target
); /* Switch to using remote target now */
659 /* Start out by trying the 'P' request to set registers. We set this each
660 time that we open a new target so that if the user switches from one
661 stub to another, we can (if the target is closed and reopened) cope. */
667 /* Without this, some commands which require an active target (such as kill)
668 won't work. This variable serves (at least) double duty as both the pid
669 of the target process (if it has such), and as a flag indicating that a
670 target is active. These functions should be split out into seperate
671 variables, especially since GDB will someday have a notion of debugging
672 several processes. */
674 inferior_pid
= 42000;
675 /* Start the remote connection; if error (0), discard this target.
676 In particular, if the user quits, be sure to discard it
677 (we'd be in an inconsistent state otherwise). */
678 if (!catch_errors (remote_start_remote
, (char *)0,
679 "Couldn't establish connection to remote target\n", RETURN_MASK_ALL
))
687 /* tell the remote that we're using the extended protocol. */
694 /* This takes a program previously attached to and detaches it. After
695 this is done, GDB can be used to debug some other program. We
696 better not have left any breakpoints in the target program or it'll
697 die when it hits one. */
700 remote_detach (args
, from_tty
)
707 error ("Argument given to \"detach\" when remotely debugging.");
709 /* Tell the remote target to detach. */
715 puts_filtered ("Ending remote debugging.\n");
718 /* Convert hex digit A to a number. */
724 if (a
>= '0' && a
<= '9')
726 else if (a
>= 'a' && a
<= 'f')
728 else if (a
>= 'A' && a
<= 'F')
731 error ("Reply contains invalid hex digit %d", a
);
734 /* Convert number NIB to a hex digit. */
746 /* Tell the remote machine to resume. */
748 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
752 remote_resume (pid
, step
, siggnal
)
754 enum target_signal siggnal
;
759 set_thread (inferior_pid
, 0);
763 dcache_flush (remote_dcache
);
765 last_sent_signal
= siggnal
;
766 last_sent_step
= step
;
768 /* A hook for when we need to do something at the last moment before
770 if (target_resume_hook
)
771 (*target_resume_hook
) ();
773 if (siggnal
!= TARGET_SIGNAL_0
)
775 buf
[0] = step
? 'S' : 'C';
776 buf
[1] = tohex (((int)siggnal
>> 4) & 0xf);
777 buf
[2] = tohex ((int)siggnal
& 0xf);
781 strcpy (buf
, step
? "s": "c");
786 /* Send ^C to target to halt it. Target will respond, and send us a
788 static void (*ofunc
) PARAMS ((int));
791 remote_interrupt (signo
)
795 signal (signo
, remote_interrupt
);
801 if (!interrupted_already
)
803 /* Send a break or a ^C, depending on user preference. */
804 interrupted_already
= 1;
807 printf_unfiltered ("remote_stop called\n");
810 SERIAL_SEND_BREAK (remote_desc
);
812 SERIAL_WRITE (remote_desc
, "\003", 1);
816 signal (SIGINT
, ofunc
);
818 signal (SIGINT
, remote_interrupt
);
819 interrupted_already
= 0;
823 /* Ask the user what to do when an interrupt is received. */
828 target_terminal_ours ();
830 if (query ("Interrupted while waiting for the program.\n\
831 Give up (and stop debugging it)? "))
833 target_mourn_inferior ();
834 return_to_top_level (RETURN_QUIT
);
837 target_terminal_inferior ();
840 /* If nonzero, ignore the next kill. */
844 remote_console_output (msg
)
849 for (p
= msg
; *p
; p
+=2)
852 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
855 if (target_output_hook
)
856 target_output_hook (tb
);
858 fputs_filtered (tb
, gdb_stdout
);
862 /* Wait until the remote machine stops, then return,
863 storing status in STATUS just as `wait' would.
864 Returns "pid" (though it's not clear what, if anything, that
865 means in the case of this target). */
868 remote_wait (pid
, status
)
870 struct target_waitstatus
*status
;
872 unsigned char buf
[PBUFSIZ
];
875 status
->kind
= TARGET_WAITKIND_EXITED
;
876 status
->value
.integer
= 0;
882 interrupted_already
= 0;
883 ofunc
= signal (SIGINT
, remote_interrupt
);
884 getpkt ((char *) buf
, 1);
885 signal (SIGINT
, ofunc
);
887 /* This is a hook for when we need to do something (perhaps the
888 collection of trace data) every time the target stops. */
889 if (target_wait_loop_hook
)
890 (*target_wait_loop_hook
) ();
894 case 'E': /* Error of some sort */
895 warning ("Remote failure reply: %s", buf
);
897 case 'T': /* Status with PC, SP, FP, ... */
901 char regs
[MAX_REGISTER_RAW_SIZE
];
903 /* Expedited reply, containing Signal, {regno, reg} repeat */
904 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
906 n... = register number
907 r... = register contents
909 p
= &buf
[3]; /* after Txx */
916 regno
= strtol ((const char *) p
, &p_temp
, 16); /* Read the register number */
917 p1
= (unsigned char *)p_temp
;
921 p1
= (unsigned char *) strchr ((const char *) p
, ':');
923 warning ("Malformed packet (missing colon): %s\n\
926 if (strncmp ((const char *) p
, "thread", p1
- p
) == 0)
928 thread_num
= strtol ((const char *) ++p1
, &p_temp
, 16);
929 p
= (unsigned char *)p_temp
;
937 warning ("Malformed packet (missing colon): %s\n\
941 if (regno
>= NUM_REGS
)
942 warning ("Remote sent bad register number %ld: %s\n\
946 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
++)
948 if (p
[0] == 0 || p
[1] == 0)
949 warning ("Remote reply is too short: %s", buf
);
950 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
953 supply_register (regno
, regs
);
957 warning ("Remote register badly formatted: %s", buf
);
961 case 'S': /* Old style status, just signal only */
962 status
->kind
= TARGET_WAITKIND_STOPPED
;
963 status
->value
.sig
= (enum target_signal
)
964 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
967 case 'W': /* Target exited */
969 /* The remote process exited. */
970 status
->kind
= TARGET_WAITKIND_EXITED
;
971 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
975 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
976 status
->value
.sig
= (enum target_signal
)
977 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
981 case 'O': /* Console output */
982 remote_console_output (buf
+ 1);
985 if (last_sent_signal
!= TARGET_SIGNAL_0
)
987 /* Zero length reply means that we tried 'S' or 'C' and
988 the remote system doesn't support it. */
989 target_terminal_ours_for_output ();
991 ("Can't send signals to this remote system. %s not sent.\n",
992 target_signal_to_name (last_sent_signal
));
993 last_sent_signal
= TARGET_SIGNAL_0
;
994 target_terminal_inferior ();
996 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
997 putpkt ((char *) buf
);
1000 /* else fallthrough */
1002 warning ("Invalid remote reply: %s", buf
);
1007 if (thread_num
!= -1)
1009 /* Initial thread value can only be acquired via wait, so deal with
1010 this marker which is used before the first thread value is
1012 if (inferior_pid
== 42000)
1014 inferior_pid
= thread_num
;
1015 add_thread (inferior_pid
);
1019 return inferior_pid
;
1022 /* Number of bytes of registers this stub implements. */
1023 static int register_bytes_found
;
1025 /* Read the remote registers into the block REGS. */
1026 /* Currently we just read all the registers, so we don't use regno. */
1029 remote_fetch_registers (regno
)
1035 char regs
[REGISTER_BYTES
];
1037 set_thread (inferior_pid
, 1);
1042 if (remote_register_buf_size
== 0)
1043 remote_register_buf_size
= strlen (buf
);
1045 /* Unimplemented registers read as all bits zero. */
1046 memset (regs
, 0, REGISTER_BYTES
);
1048 /* We can get out of synch in various cases. If the first character
1049 in the buffer is not a hex character, assume that has happened
1050 and try to fetch another packet to read. */
1051 while ((buf
[0] < '0' || buf
[0] > '9')
1052 && (buf
[0] < 'a' || buf
[0] > 'f')
1053 && buf
[0] != 'x') /* New: unavailable register value */
1056 printf_unfiltered ("Bad register packet; fetching a new packet\n");
1060 /* Reply describes registers byte by byte, each byte encoded as two
1061 hex characters. Suck them all up, then supply them to the
1062 register cacheing/storage mechanism. */
1065 for (i
= 0; i
< REGISTER_BYTES
; i
++)
1071 warning ("Remote reply is of odd length: %s", buf
);
1072 /* Don't change register_bytes_found in this case, and don't
1073 print a second warning. */
1076 if (p
[0] == 'x' && p
[1] == 'x')
1077 regs
[i
] = 0; /* 'x' */
1079 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
1083 if (i
!= register_bytes_found
)
1085 register_bytes_found
= i
;
1086 #ifdef REGISTER_BYTES_OK
1087 if (!REGISTER_BYTES_OK (i
))
1088 warning ("Remote reply is too short: %s", buf
);
1093 for (i
= 0; i
< NUM_REGS
; i
++)
1095 supply_register (i
, ®s
[REGISTER_BYTE(i
)]);
1096 if (buf
[REGISTER_BYTE(i
) * 2] == 'x')
1097 register_valid
[i
] = -1; /* register value not available */
1101 /* Prepare to store registers. Since we may send them all (using a
1102 'G' request), we have to read out the ones we don't want to change
1106 remote_prepare_to_store ()
1108 /* Make sure the entire registers array is valid. */
1109 read_register_bytes (0, (char *)NULL
, REGISTER_BYTES
);
1112 /* Store register REGNO, or all registers if REGNO == -1, from the contents
1113 of REGISTERS. FIXME: ignores errors. */
1116 remote_store_registers (regno
)
1123 set_thread (inferior_pid
, 1);
1125 if (regno
>= 0 && stub_supports_P
)
1127 /* Try storing a single register. */
1130 sprintf (buf
, "P%x=", regno
);
1131 p
= buf
+ strlen (buf
);
1132 regp
= ®isters
[REGISTER_BYTE (regno
)];
1133 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); ++i
)
1135 *p
++ = tohex ((regp
[i
] >> 4) & 0xf);
1136 *p
++ = tohex (regp
[i
] & 0xf);
1142 /* The stub understands the 'P' request. We are done. */
1146 /* The stub does not support the 'P' request. Use 'G' instead,
1147 and don't try using 'P' in the future (it will just waste our
1149 stub_supports_P
= 0;
1154 /* Command describes registers byte by byte,
1155 each byte encoded as two hex characters. */
1158 /* remote_prepare_to_store insures that register_bytes_found gets set. */
1159 for (i
= 0; i
< register_bytes_found
; i
++)
1161 *p
++ = tohex ((registers
[i
] >> 4) & 0xf);
1162 *p
++ = tohex (registers
[i
] & 0xf);
1170 Use of the data cache *used* to be disabled because it loses for looking at
1171 and changing hardware I/O ports and the like. Accepting `volatile'
1172 would perhaps be one way to fix it. Another idea would be to use the
1173 executable file for the text segment (for all SEC_CODE sections?
1174 For all SEC_READONLY sections?). This has problems if you want to
1175 actually see what the memory contains (e.g. self-modifying code,
1176 clobbered memory, user downloaded the wrong thing).
1178 Because it speeds so much up, it's now enabled, if you're playing
1179 with registers you turn it of (set remotecache 0)
1182 /* Read a word from remote address ADDR and return it.
1183 This goes through the data cache. */
1187 remote_fetch_word (addr
)
1190 return dcache_fetch (remote_dcache
, addr
);
1193 /* Write a word WORD into remote address ADDR.
1194 This goes through the data cache. */
1197 remote_store_word (addr
, word
)
1201 dcache_poke (remote_dcache
, addr
, word
);
1203 #endif /* 0 (unused?) */
1207 /* Return the number of hex digits in num. */
1215 for (i
= 0; num
!= 0; i
++)
1221 /* Set BUF to the hex digits representing NUM */
1224 hexnumstr (buf
, num
)
1229 int len
= hexnumlen (num
);
1233 for (i
= len
- 1; i
>= 0; i
--)
1235 buf
[i
] = "0123456789abcdef" [(num
& 0xf)];
1242 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits */
1245 remote_address_masked (addr
)
1248 if (remote_address_size
> 0
1249 && remote_address_size
< (sizeof (ULONGEST
) * 8))
1251 /* Only create a mask when that mask can safely be constructed
1252 in a ULONGEST variable. */
1254 mask
= (mask
<< remote_address_size
) - 1;
1260 /* Write memory data directly to the remote machine.
1261 This does not inform the data cache; the data cache uses this.
1262 MEMADDR is the address in the remote memory space.
1263 MYADDR is the address of the buffer in our space.
1264 LEN is the number of bytes.
1266 Returns number of bytes transferred, or 0 for error. */
1269 remote_write_bytes (memaddr
, myaddr
, len
)
1274 int max_buf_size
; /* Max size of packet output buffer */
1277 /* Chop the transfer down if necessary */
1279 max_buf_size
= min (remote_write_size
, PBUFSIZ
);
1280 if (remote_register_buf_size
!= 0)
1281 max_buf_size
= min (max_buf_size
, remote_register_buf_size
);
1283 /* Subtract header overhead from max payload size - $M<memaddr>,<len>:#nn */
1284 max_buf_size
-= 2 + hexnumlen (memaddr
+ len
- 1) + 1 + hexnumlen (len
) + 4;
1294 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
1296 /* construct "M"<memaddr>","<len>":" */
1297 /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
1298 memaddr
= remote_address_masked (memaddr
);
1301 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
1303 p
+= hexnumstr (p
, (ULONGEST
) todo
);
1307 /* We send target system values byte by byte, in increasing byte addresses,
1308 each byte encoded as two hex characters. */
1310 for (i
= 0; i
< todo
; i
++)
1312 *p
++ = tohex ((myaddr
[i
] >> 4) & 0xf);
1313 *p
++ = tohex (myaddr
[i
] & 0xf);
1322 /* There is no correspondance between what the remote protocol uses
1323 for errors and errno codes. We would like a cleaner way of
1324 representing errors (big enough to include errno codes, bfd_error
1325 codes, and others). But for now just return EIO. */
1336 /* Read memory data directly from the remote machine.
1337 This does not use the data cache; the data cache uses this.
1338 MEMADDR is the address in the remote memory space.
1339 MYADDR is the address of the buffer in our space.
1340 LEN is the number of bytes.
1342 Returns number of bytes transferred, or 0 for error. */
1345 remote_read_bytes (memaddr
, myaddr
, len
)
1350 int max_buf_size
; /* Max size of packet output buffer */
1353 /* Chop the transfer down if necessary */
1355 max_buf_size
= min (remote_write_size
, PBUFSIZ
);
1356 if (remote_register_buf_size
!= 0)
1357 max_buf_size
= min (max_buf_size
, remote_register_buf_size
);
1367 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
1369 /* construct "m"<memaddr>","<len>" */
1370 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
1371 memaddr
= remote_address_masked (memaddr
);
1374 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
1376 p
+= hexnumstr (p
, (ULONGEST
) todo
);
1384 /* There is no correspondance between what the remote protocol uses
1385 for errors and errno codes. We would like a cleaner way of
1386 representing errors (big enough to include errno codes, bfd_error
1387 codes, and others). But for now just return EIO. */
1392 /* Reply describes memory byte by byte,
1393 each byte encoded as two hex characters. */
1396 for (i
= 0; i
< todo
; i
++)
1398 if (p
[0] == 0 || p
[1] == 0)
1399 /* Reply is short. This means that we were able to read only part
1400 of what we wanted to. */
1401 return i
+ (origlen
- len
);
1402 myaddr
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
1412 /* Read or write LEN bytes from inferior memory at MEMADDR, transferring
1413 to or from debugger address MYADDR. Write to inferior if SHOULD_WRITE is
1414 nonzero. Returns length of data written or read; 0 for error. */
1418 remote_xfer_memory(memaddr
, myaddr
, len
, should_write
, target
)
1423 struct target_ops
*target
; /* ignored */
1425 #ifdef REMOTE_TRANSLATE_XFER_ADDRESS
1428 REMOTE_TRANSLATE_XFER_ADDRESS (memaddr
, len
, targaddr
, targlen
);
1435 return dcache_xfer_memory (remote_dcache
, memaddr
, myaddr
, len
, should_write
);
1440 /* Enable after 4.12. */
1443 remote_search (len
, data
, mask
, startaddr
, increment
, lorange
, hirange
1444 addr_found
, data_found
)
1448 CORE_ADDR startaddr
;
1452 CORE_ADDR
*addr_found
;
1455 if (increment
== -4 && len
== 4)
1457 long mask_long
, data_long
;
1458 long data_found_long
;
1459 CORE_ADDR addr_we_found
;
1461 long returned_long
[2];
1464 mask_long
= extract_unsigned_integer (mask
, len
);
1465 data_long
= extract_unsigned_integer (data
, len
);
1466 sprintf (buf
, "t%x:%x,%x", startaddr
, data_long
, mask_long
);
1471 /* The stub doesn't support the 't' request. We might want to
1472 remember this fact, but on the other hand the stub could be
1473 switched on us. Maybe we should remember it only until
1474 the next "target remote". */
1475 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
1476 hirange
, addr_found
, data_found
);
1481 /* There is no correspondance between what the remote protocol uses
1482 for errors and errno codes. We would like a cleaner way of
1483 representing errors (big enough to include errno codes, bfd_error
1484 codes, and others). But for now just use EIO. */
1485 memory_error (EIO
, startaddr
);
1488 while (*p
!= '\0' && *p
!= ',')
1489 addr_we_found
= (addr_we_found
<< 4) + fromhex (*p
++);
1491 error ("Protocol error: short return for search");
1493 data_found_long
= 0;
1494 while (*p
!= '\0' && *p
!= ',')
1495 data_found_long
= (data_found_long
<< 4) + fromhex (*p
++);
1496 /* Ignore anything after this comma, for future extensions. */
1498 if (addr_we_found
< lorange
|| addr_we_found
>= hirange
)
1504 *addr_found
= addr_we_found
;
1505 *data_found
= store_unsigned_integer (data_we_found
, len
);
1508 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
1509 hirange
, addr_found
, data_found
);
1514 remote_files_info (ignore
)
1515 struct target_ops
*ignore
;
1517 puts_filtered ("Debugging a target over a serial line.\n");
1520 /* Stuff for dealing with the packets which are part of this protocol.
1521 See comment at top of file for details. */
1523 /* Read a single character from the remote end, masking it down to 7 bits. */
1531 ch
= SERIAL_READCHAR (remote_desc
, timeout
);
1536 error ("Remote connection closed");
1538 perror_with_name ("Remote communication error");
1539 case SERIAL_TIMEOUT
:
1546 /* Send the command in BUF to the remote machine,
1547 and read the reply into BUF.
1548 Report an error if we get an error reply. */
1558 error ("Remote failure reply: %s", buf
);
1561 /* Display a null-terminated packet on stdout, for debugging, using C
1568 puts_filtered ("\"");
1570 gdb_printchar (*buf
++, gdb_stdout
, '"');
1571 puts_filtered ("\"");
1575 /* Send a packet to the remote machine, with error checking.
1576 The data of the packet is in BUF. */
1583 unsigned char csum
= 0;
1585 int cnt
= strlen (buf
);
1590 /* Copy the packet into buffer BUF2, encapsulating it
1591 and giving it a checksum. */
1593 if (cnt
> (int) sizeof (buf2
) - 5) /* Prosanity check */
1599 for (i
= 0; i
< cnt
; i
++)
1605 *p
++ = tohex ((csum
>> 4) & 0xf);
1606 *p
++ = tohex (csum
& 0xf);
1608 /* Send it over and over until we get a positive ack. */
1612 int started_error_output
= 0;
1617 printf_unfiltered ("Sending packet: %s...", buf2
);
1618 gdb_flush(gdb_stdout
);
1620 if (SERIAL_WRITE (remote_desc
, buf2
, p
- buf2
))
1621 perror_with_name ("putpkt: write failed");
1623 /* read until either a timeout occurs (-2) or '+' is read */
1626 ch
= readchar (remote_timeout
);
1633 case SERIAL_TIMEOUT
:
1635 if (started_error_output
)
1637 putchar_unfiltered ('\n');
1638 started_error_output
= 0;
1647 printf_unfiltered("Ack\n");
1649 case SERIAL_TIMEOUT
:
1653 break; /* Retransmit buffer */
1656 char junkbuf
[PBUFSIZ
];
1658 /* It's probably an old response, and we're out of sync. Just
1659 gobble up the packet and ignore it. */
1660 getpkt (junkbuf
, 0);
1661 continue; /* Now, go look for + */
1666 if (!started_error_output
)
1668 started_error_output
= 1;
1669 printf_unfiltered ("putpkt: Junk: ");
1671 putchar_unfiltered (ch
& 0177);
1675 break; /* Here to retransmit */
1679 /* This is wrong. If doing a long backtrace, the user should be
1680 able to get out next time we call QUIT, without anything as violent
1681 as interrupt_query. If we want to provide a way out of here
1682 without getting to the next QUIT, it should be based on hitting
1683 ^C twice as in remote_wait. */
1693 /* Come here after finding the start of the frame. Collect the rest into BUF,
1694 verifying the checksum, length, and handling run-length compression.
1695 Returns 0 on any error, 1 on success. */
1710 c
= readchar (remote_timeout
);
1714 case SERIAL_TIMEOUT
:
1716 puts_filtered ("Timeout in mid-packet, retrying\n");
1720 puts_filtered ("Saw new packet start in middle of old one\n");
1721 return 0; /* Start a new packet, count retries */
1724 unsigned char pktcsum
;
1728 pktcsum
= fromhex (readchar (remote_timeout
)) << 4;
1729 pktcsum
|= fromhex (readchar (remote_timeout
));
1731 if (csum
== pktcsum
)
1736 printf_filtered ("Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
1738 puts_filtered (buf
);
1739 puts_filtered ("\n");
1743 case '*': /* Run length encoding */
1745 c
= readchar (remote_timeout
);
1747 c
= c
- ' ' + 3; /* Compute repeat count */
1750 if (c
> 0 && c
< 255 && bp
+ c
- 1 < buf
+ PBUFSIZ
- 1)
1752 memset (bp
, *(bp
- 1), c
);
1758 printf_filtered ("Repeat count %d too large for buffer: ", c
);
1759 puts_filtered (buf
);
1760 puts_filtered ("\n");
1764 if (bp
< buf
+ PBUFSIZ
- 1)
1772 puts_filtered ("Remote packet too long: ");
1773 puts_filtered (buf
);
1774 puts_filtered ("\n");
1781 /* Read a packet from the remote machine, with error checking,
1782 and store it in BUF. BUF is expected to be of size PBUFSIZ.
1783 If FOREVER, wait forever rather than timing out; this is used
1784 while the target is executing user code. */
1787 getpkt (buf
, forever
)
1796 strcpy (buf
,"timeout");
1800 #ifdef MAINTENANCE_CMDS
1801 timeout
= watchdog
> 0 ? watchdog
: -1;
1808 timeout
= remote_timeout
;
1812 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
1814 /* This can loop forever if the remote side sends us characters
1815 continuously, but if it pauses, we'll get a zero from readchar
1816 because of timeout. Then we'll count that as a retry. */
1818 /* Note that we will only wait forever prior to the start of a packet.
1819 After that, we expect characters to arrive at a brisk pace. They
1820 should show up within remote_timeout intervals. */
1824 c
= readchar (timeout
);
1826 if (c
== SERIAL_TIMEOUT
)
1828 #ifdef MAINTENANCE_CMDS
1829 if (forever
) /* Watchdog went off. Kill the target. */
1831 target_mourn_inferior ();
1832 error ("Watchdog has expired. Target detached.\n");
1836 puts_filtered ("Timed out.\n");
1842 /* We've found the start of a packet, now collect the data. */
1844 val
= read_frame (buf
);
1849 fprintf_unfiltered (gdb_stdout
, "Packet received: %s\n", buf
);
1850 SERIAL_WRITE (remote_desc
, "+", 1);
1854 /* Try the whole thing again. */
1856 SERIAL_WRITE (remote_desc
, "-", 1);
1859 /* We have tried hard enough, and just can't receive the packet. Give up. */
1861 printf_unfiltered ("Ignoring packet error, continuing...\n");
1862 SERIAL_WRITE (remote_desc
, "+", 1);
1868 /* For some mysterious reason, wait_for_inferior calls kill instead of
1869 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
1873 target_mourn_inferior ();
1877 /* Use catch_errors so the user can quit from gdb even when we aren't on
1878 speaking terms with the remote system. */
1879 catch_errors (putpkt
, "k", "", RETURN_MASK_ERROR
);
1881 /* Don't wait for it to die. I'm not really sure it matters whether
1882 we do or not. For the existing stubs, kill is a noop. */
1883 target_mourn_inferior ();
1889 remote_mourn_1 (&remote_ops
);
1893 extended_remote_mourn ()
1895 /* We do _not_ want to mourn the target like this; this will
1896 remove the extended remote target from the target stack,
1897 and the next time the user says "run" it'll fail.
1899 FIXME: What is the right thing to do here? */
1901 remote_mourn_1 (&extended_remote_ops
);
1905 /* Worker function for remote_mourn. */
1907 remote_mourn_1 (target
)
1908 struct target_ops
*target
;
1910 unpush_target (target
);
1911 generic_mourn_inferior ();
1914 /* In the extended protocol we want to be able to do things like
1915 "run" and have them basically work as expected. So we need
1916 a special create_inferior function.
1918 FIXME: One day add support for changing the exec file
1919 we're debugging, arguments and an environment. */
1922 extended_remote_create_inferior (exec_file
, args
, env
)
1927 /* Rip out the breakpoints; we'll reinsert them after restarting
1928 the remote server. */
1929 remove_breakpoints ();
1931 /* Now restart the remote server. */
1932 extended_remote_restart ();
1934 /* Now put the breakpoints back in. This way we're safe if the
1935 restart function works via a unix fork on the remote side. */
1936 insert_breakpoints ();
1938 /* Clean up from the last time we were running. */
1939 clear_proceed_status ();
1941 /* Let the remote process run. */
1942 proceed (-1, TARGET_SIGNAL_0
, 0);
1946 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
1947 than other targets; in those use REMOTE_BREAKPOINT instead of just
1948 BREAKPOINT. Also, bi-endian targets may define LITTLE_REMOTE_BREAKPOINT
1949 and BIG_REMOTE_BREAKPOINT. If none of these are defined, we just call
1950 the standard routines that are in mem-break.c. */
1952 /* FIXME, these ought to be done in a more dynamic fashion. For instance,
1953 the choice of breakpoint instruction affects target program design and
1954 vice versa, and by making it user-tweakable, the special code here
1955 goes away and we need fewer special GDB configurations. */
1957 #if defined (LITTLE_REMOTE_BREAKPOINT) && defined (BIG_REMOTE_BREAKPOINT) && !defined(REMOTE_BREAKPOINT)
1958 #define REMOTE_BREAKPOINT
1961 #ifdef REMOTE_BREAKPOINT
1963 /* If the target isn't bi-endian, just pretend it is. */
1964 #if !defined (LITTLE_REMOTE_BREAKPOINT) && !defined (BIG_REMOTE_BREAKPOINT)
1965 #define LITTLE_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
1966 #define BIG_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
1969 static unsigned char big_break_insn
[] = BIG_REMOTE_BREAKPOINT
;
1970 static unsigned char little_break_insn
[] = LITTLE_REMOTE_BREAKPOINT
;
1972 #endif /* REMOTE_BREAKPOINT */
1974 /* Insert a breakpoint on targets that don't have any better breakpoint
1975 support. We read the contents of the target location and stash it,
1976 then overwrite it with a breakpoint instruction. ADDR is the target
1977 location in the target machine. CONTENTS_CACHE is a pointer to
1978 memory allocated for saving the target contents. It is guaranteed
1979 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
1980 is accomplished via BREAKPOINT_MAX). */
1983 remote_insert_breakpoint (addr
, contents_cache
)
1985 char *contents_cache
;
1987 #ifdef REMOTE_BREAKPOINT
1990 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
1994 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
1995 val
= target_write_memory (addr
, (char *) big_break_insn
,
1996 sizeof big_break_insn
);
1998 val
= target_write_memory (addr
, (char *) little_break_insn
,
1999 sizeof little_break_insn
);
2004 return memory_insert_breakpoint (addr
, contents_cache
);
2005 #endif /* REMOTE_BREAKPOINT */
2009 remote_remove_breakpoint (addr
, contents_cache
)
2011 char *contents_cache
;
2013 #ifdef REMOTE_BREAKPOINT
2014 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
2016 return memory_remove_breakpoint (addr
, contents_cache
);
2017 #endif /* REMOTE_BREAKPOINT */
2020 /* Some targets are only capable of doing downloads, and afterwards they switch
2021 to the remote serial protocol. This function provides a clean way to get
2022 from the download target to the remote target. It's basically just a
2023 wrapper so that we don't have to expose any of the internal workings of
2026 Prior to calling this routine, you should shutdown the current target code,
2027 else you will get the "A program is being debugged already..." message.
2028 Usually a call to pop_target() suffices.
2032 push_remote_target (name
, from_tty
)
2036 printf_filtered ("Switching to remote protocol\n");
2037 remote_open (name
, from_tty
);
2040 /* Other targets want to use the entire remote serial module but with
2041 certain remote_ops overridden. */
2044 open_remote_target (name
, from_tty
, target
, extended_p
)
2047 struct target_ops
*target
;
2050 printf_filtered ("Selecting the %sremote protocol\n",
2051 (extended_p
? "extended-" : ""));
2052 remote_open_1 (name
, from_tty
, target
, extended_p
);
2055 /* Table used by the crc32 function to calcuate the checksum. */
2056 static unsigned long crc32_table
[256] = {0, 0};
2058 static unsigned long
2059 crc32 (buf
, len
, crc
)
2064 if (! crc32_table
[1])
2066 /* Initialize the CRC table and the decoding table. */
2070 for (i
= 0; i
< 256; i
++)
2072 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
2073 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
2080 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
2086 /* compare-sections command
2088 With no arguments, compares each loadable section in the exec bfd
2089 with the same memory range on the target, and reports mismatches.
2090 Useful for verifying the image on the target against the exec file.
2091 Depends on the target understanding the new "qCRC:" request. */
2094 compare_sections_command (args
, from_tty
)
2099 unsigned long host_crc
, target_crc
;
2100 extern bfd
*exec_bfd
;
2101 struct cleanup
*old_chain
;
2102 char *tmp
, *sectdata
, *sectname
, buf
[PBUFSIZ
];
2109 error ("command cannot be used without an exec file");
2110 if (!current_target
.to_shortname
||
2111 strcmp (current_target
.to_shortname
, "remote") != 0)
2112 error ("command can only be used with remote target");
2114 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
2116 if (!(s
->flags
& SEC_LOAD
))
2117 continue; /* skip non-loadable section */
2119 size
= bfd_get_section_size_before_reloc (s
);
2121 continue; /* skip zero-length section */
2123 sectname
= (char *) bfd_get_section_name (exec_bfd
, s
);
2124 if (args
&& strcmp (args
, sectname
) != 0)
2125 continue; /* not the section selected by user */
2127 matched
= 1; /* do this section */
2129 /* FIXME: assumes lma can fit into long */
2130 sprintf (buf
, "qCRC:%lx,%lx", (long) lma
, (long) size
);
2133 /* be clever; compute the host_crc before waiting for target reply */
2134 sectdata
= xmalloc (size
);
2135 old_chain
= make_cleanup (free
, sectdata
);
2136 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
2137 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
2141 error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
2142 sectname
, lma
, lma
+ size
);
2144 error ("remote target does not support this operation");
2146 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
2147 target_crc
= target_crc
* 16 + fromhex (*tmp
);
2149 printf_filtered ("Section %s, range 0x%08x -- 0x%08x: ",
2150 sectname
, lma
, lma
+ size
);
2151 if (host_crc
== target_crc
)
2152 printf_filtered ("matched.\n");
2155 printf_filtered ("MIS-MATCHED!\n");
2159 do_cleanups (old_chain
);
2162 warning ("One or more sections of the remote executable does not match\nthe loaded file\n");
2163 if (args
&& !matched
)
2164 printf_filtered ("No loaded section named '%s'.\n", args
);
2168 packet_command (args
, from_tty
)
2175 error ("command can only be used with remote target");
2178 error ("remote-packet command requires packet text as argument");
2180 puts_filtered ("sending: ");
2181 print_packet (args
);
2182 puts_filtered ("\n");
2186 puts_filtered ("received: ");
2188 puts_filtered ("\n");
2194 remote_ops
.to_shortname
= "remote";
2195 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
2196 remote_ops
.to_doc
= "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
2197 Specify the serial device it is connected to (e.g. /dev/ttya).";
2198 remote_ops
.to_open
= remote_open
;
2199 remote_ops
.to_close
= remote_close
;
2200 remote_ops
.to_detach
= remote_detach
;
2201 remote_ops
.to_resume
= remote_resume
;
2202 remote_ops
.to_wait
= remote_wait
;
2203 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
2204 remote_ops
.to_store_registers
= remote_store_registers
;
2205 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
2206 remote_ops
.to_xfer_memory
= remote_xfer_memory
;
2207 remote_ops
.to_files_info
= remote_files_info
;
2208 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
2209 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
2210 remote_ops
.to_kill
= remote_kill
;
2211 remote_ops
.to_load
= generic_load
;
2212 remote_ops
.to_mourn_inferior
= remote_mourn
;
2213 remote_ops
.to_thread_alive
= remote_thread_alive
;
2214 remote_ops
.to_stop
= remote_stop
;
2215 remote_ops
.to_stratum
= process_stratum
;
2216 remote_ops
.to_has_all_memory
= 1;
2217 remote_ops
.to_has_memory
= 1;
2218 remote_ops
.to_has_stack
= 1;
2219 remote_ops
.to_has_registers
= 1;
2220 remote_ops
.to_has_execution
= 1;
2221 remote_ops
.to_magic
= OPS_MAGIC
;
2225 init_extended_remote_ops ()
2227 extended_remote_ops
= remote_ops
;
2229 extended_remote_ops
.to_shortname
= "extended-remote";
2230 extended_remote_ops
.to_longname
= "Extended remote serial target in gdb-specific protocol";
2231 extended_remote_ops
.to_doc
= "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
2232 Specify the serial device it is connected to (e.g. /dev/ttya).",
2233 extended_remote_ops
.to_open
= extended_remote_open
;
2234 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
2235 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
2239 _initialize_remote ()
2242 add_target (&remote_ops
);
2244 init_extended_remote_ops ();
2245 add_target (&extended_remote_ops
);
2247 add_cmd ("compare-sections", class_obscure
, compare_sections_command
,
2248 "Compare section data on target to the exec file.\n\
2249 Argument is a single section name (default: all loaded sections).",
2252 add_cmd ("packet", class_maintenance
, packet_command
,
2253 "Send an arbitrary packet to a remote target.\n\
2254 maintenance packet TEXT\n\
2255 If GDB is talking to an inferior via the GDB serial protocol, then\n\
2256 this command sends the string TEXT to the inferior, and displays the\n\
2257 response packet. GDB supplies the initial `$' character, and the\n\
2258 terminating `#' character and checksum.",
2261 add_show_from_set (add_set_cmd ("remotetimeout", no_class
,
2262 var_integer
, (char *)&remote_timeout
,
2263 "Set timeout value for remote read.\n", &setlist
),
2266 add_show_from_set (add_set_cmd ("remotebreak", no_class
,
2267 var_integer
, (char *)&remote_break
,
2268 "Set whether to send break if interrupted.\n", &setlist
),
2271 add_show_from_set (add_set_cmd ("remotewritesize", no_class
,
2272 var_integer
, (char *)&remote_write_size
,
2273 "Set the maximum number of bytes in each memory write packet.\n", &setlist
),
2276 remote_address_size
= TARGET_PTR_BIT
;
2277 add_show_from_set (add_set_cmd ("remoteaddresssize", class_obscure
,
2278 var_integer
, (char *)&remote_address_size
,
2279 "Set the maximum size of the address (in bits) in a memory packet.\n", &setlist
),