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,
103 resume at same address.
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
139 program is running and the debugger
140 should continue to wait for
143 thread alive TXX Find out if the thread XX is alive.
144 reply OK thread is still alive
147 remote restart RXX Restart the remote server
149 extended ops ! Use the extended remote protocol.
150 Sticky -- only needs to be set once.
154 toggle debug d toggle debug flag (see 386 & 68k stubs)
155 reset r reset -- see sparc stub.
156 reserved <other> On other requests, the stub should
157 ignore the request and send an empty
158 response ($#<checksum>). This way
159 we can extend the protocol and GDB
160 can tell whether the stub it is
161 talking to uses the old or the new.
162 search tAA:PP,MM Search backwards starting at address
163 AA for a match with pattern PP and
164 mask MM. PP and MM are 4 bytes.
165 Not supported by all stubs.
167 general query qXXXX Request info about XXXX.
168 general set QXXXX=yyyy Set value of XXXX to yyyy.
169 query sect offs qOffsets Get section offsets. Reply is
170 Text=xxx;Data=yyy;Bss=zzz
172 Responses can be run-length encoded to save space. A '*' means that
173 the next character is an ASCII encoding giving a repeat count which
174 stands for that many repititions of the character preceding the '*'.
175 The encoding is n+29, yielding a printable character where n >=3
176 (which is where rle starts to win). Don't use an n > 126.
179 "0* " means the same as "0000". */
182 #include "gdb_string.h"
185 #include "inferior.h"
190 /*#include "terminal.h"*/
192 #include "objfiles.h"
193 #include "gdb-stabs.h"
194 #include "gdbthread.h"
199 #include <sys/types.h>
205 /* Prototypes for local functions */
207 static int remote_write_bytes
PARAMS ((CORE_ADDR memaddr
,
208 char *myaddr
, int len
));
210 static int remote_read_bytes
PARAMS ((CORE_ADDR memaddr
,
211 char *myaddr
, int len
));
213 static void remote_files_info
PARAMS ((struct target_ops
* ignore
));
215 static int remote_xfer_memory
PARAMS ((CORE_ADDR memaddr
, char * myaddr
,
216 int len
, int should_write
,
217 struct target_ops
* target
));
219 static void remote_prepare_to_store
PARAMS ((void));
221 static void remote_fetch_registers
PARAMS ((int regno
));
223 static void remote_resume
PARAMS ((int pid
, int step
,
224 enum target_signal siggnal
));
226 static int remote_start_remote
PARAMS ((char *dummy
));
228 static void remote_open
PARAMS ((char *name
, int from_tty
));
230 static void extended_remote_open
PARAMS ((char *name
, int from_tty
));
232 static void remote_open_1
PARAMS ((char *, int, struct target_ops
*,
235 static void remote_close
PARAMS ((int quitting
));
237 static void remote_store_registers
PARAMS ((int regno
));
239 static void remote_mourn
PARAMS ((void));
241 static void extended_remote_restart
PARAMS ((void));
243 static void extended_remote_mourn
PARAMS ((void));
245 static void extended_remote_create_inferior
PARAMS ((char *, char *, char **));
247 static void remote_mourn_1
PARAMS ((struct target_ops
*));
249 static void remote_send
PARAMS ((char *buf
));
251 static int readchar
PARAMS ((int timeout
));
253 static int remote_wait
PARAMS ((int pid
, struct target_waitstatus
* status
));
255 static void remote_kill
PARAMS ((void));
257 static int tohex
PARAMS ((int nib
));
259 static void remote_detach
PARAMS ((char *args
, int from_tty
));
261 static void remote_interrupt
PARAMS ((int signo
));
263 static void interrupt_query
PARAMS ((void));
265 static void set_thread
PARAMS ((int, int));
267 static int remote_thread_alive
PARAMS ((int));
269 static void get_offsets
PARAMS ((void));
271 static int read_frame
PARAMS ((char *));
273 static int remote_insert_breakpoint
PARAMS ((CORE_ADDR
, char *));
275 static int remote_remove_breakpoint
PARAMS ((CORE_ADDR
, char *));
277 static int hexnumlen
PARAMS ((ULONGEST num
));
279 static void init_remote_ops
PARAMS ((void));
281 static void init_extended_remote_ops
PARAMS ((void));
283 static void remote_stop
PARAMS ((void));
285 static int hexnumstr
PARAMS ((char *, ULONGEST
));
287 static CORE_ADDR remote_address_masked
PARAMS ((CORE_ADDR
));
289 static void print_packet
PARAMS ((char *));
291 static unsigned long crc32
PARAMS ((unsigned char *, int, unsigned int));
293 static void compare_sections_command
PARAMS ((char *, int));
295 static void packet_command
PARAMS ((char *, int));
297 /* exported functions */
299 extern int fromhex
PARAMS ((int a
));
301 extern void getpkt
PARAMS ((char *buf
, int forever
));
303 extern int putpkt
PARAMS ((char *buf
));
305 void remote_console_output
PARAMS ((char *));
307 /* Define the target subroutine names */
309 void open_remote_target
PARAMS ((char *, int, struct target_ops
*, int));
311 void _initialize_remote
PARAMS ((void));
315 static struct target_ops remote_ops
;
317 static struct target_ops extended_remote_ops
;
319 /* This was 5 seconds, which is a long time to sit and wait.
320 Unless this is going though some terminal server or multiplexer or
321 other form of hairy serial connection, I would think 2 seconds would
324 /* Changed to allow option to set timeout value.
325 was static int remote_timeout = 2; */
326 extern int remote_timeout
;
328 /* This variable chooses whether to send a ^C or a break when the user
329 requests program interruption. Although ^C is usually what remote
330 systems expect, and that is the default here, sometimes a break is
331 preferable instead. */
333 static int remote_break
;
335 /* Has the user attempted to interrupt the target? If so, then offer
336 the user the opportunity to bail out completely if he interrupts
338 static int interrupted_already
= 0;
340 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
341 remote_open knows that we don't have a file open when the program
343 static serial_t remote_desc
= NULL
;
345 /* Having this larger than 400 causes us to be incompatible with m68k-stub.c
346 and i386-stub.c. Normally, no one would notice because it only matters
347 for writing large chunks of memory (e.g. in downloads). Also, this needs
348 to be more than 400 if required to hold the registers (see below, where
349 we round it up based on REGISTER_BYTES). */
352 /* Maximum number of bytes to read/write at once. The value here
353 is chosen to fill up a packet (the headers account for the 32). */
354 #define MAXBUFBYTES ((PBUFSIZ-32)/2)
356 /* Round up PBUFSIZ to hold all the registers, at least. */
357 /* The blank line after the #if seems to be required to work around a
358 bug in HP's PA compiler. */
359 #if REGISTER_BYTES > MAXBUFBYTES
362 #define PBUFSIZ (REGISTER_BYTES * 2 + 32)
366 /* This variable sets the number of bytes to be written to the target
367 in a single packet. Normally PBUFSIZ is satisfactory, but some
368 targets need smaller values (perhaps because the receiving end
371 static int remote_write_size
= PBUFSIZ
;
373 /* This variable sets the number of bits in an address that are to be
374 sent in a memory ("M" or "m") packet. Normally, after stripping
375 leading zeros, the entire address would be sent. This variable
376 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
377 initial implementation of remote.c restricted the address sent in
378 memory packets to ``host::sizeof long'' bytes - (typically 32
379 bits). Consequently, for 64 bit targets, the upper 32 bits of an
380 address was never sent. Since fixing this bug may cause a break in
381 some remote targets this variable is principly provided to
382 facilitate backward compatibility. */
384 static int remote_address_size
;
386 /* This is the size (in chars) of the first response to the `g' command. This
387 is used to limit the size of the memory read and write commands to prevent
388 stub buffers from overflowing. The size does not include headers and
389 trailers, it is only the payload size. */
391 static int remote_register_buf_size
= 0;
393 /* Should we try the 'P' request? If this is set to one when the stub
394 doesn't support 'P', the only consequence is some unnecessary traffic. */
395 static int stub_supports_P
= 1;
397 /* These are pointers to hook functions that may be set in order to
398 modify resume/wait behavior for a particular architecture. */
400 void (*target_resume_hook
) PARAMS ((void));
401 void (*target_wait_loop_hook
) PARAMS ((void));
404 /* ------- REMOTE Thread (or) Process support ----------------------- */
409 stub_unpack_int
PARAMS ((char *buff
, int fieldlength
));
412 unpack_varlen_hex
PARAMS ((char *buff
, int *result
));
416 unpack_nibble
PARAMS ((char *buf
, int *val
));
419 unpack_nibble
PARAMS ((char *buf
, int *val
));
422 pack_hex_byte
PARAMS ((char *pkt
, unsigned char byte
));
425 unpack_byte
PARAMS ((char *buf
, int *value
));
428 pack_int
PARAMS ((char *buf
, int value
));
431 unpack_int
PARAMS ((char *buf
, int *value
));
434 pack_string
PARAMS ((char *pkt
, char *string
));
437 unpack_string
PARAMS ((char *src
, char *dest
, int length
));
440 pack_threadid
PARAMS ((char *pkt
, threadref
* id
));
443 unpack_threadid
PARAMS ((char *inbuf
, threadref
* id
));
446 int_to_threadref
PARAMS ((threadref
* id
, int value
));
450 threadref_to_int
PARAMS ((threadref
* ref
));
453 copy_threadref
PARAMS ((threadref
* dest
, threadref
* src
));
456 threadmatch
PARAMS ((threadref
* dest
, threadref
* src
));
460 pack_threadinfo_request
PARAMS ((char *pkt
,
465 remote_unpack_thread_info_response
PARAMS ((char *pkt
,
466 threadref
* expectedref
,
467 struct gdb_ext_thread_info
* info
471 remote_get_threadinfo
PARAMS ((threadref
* threadid
,
472 int fieldset
, /* TAG mask */
473 struct gdb_ext_thread_info
* info
));
476 adapt_remote_get_threadinfo
PARAMS ((gdb_threadref
* ref
,
478 struct gdb_ext_thread_info
* info
));
480 pack_threadlist_request
PARAMS ((char *pkt
,
483 threadref
* nextthread
));
486 parse_threadlist_response
PARAMS ((char *pkt
,
488 threadref
* original_echo
,
489 threadref
* resultlist
,
492 remote_get_threadlist
PARAMS ((int startflag
,
493 threadref
* nextthread
,
497 threadref
* threadlist
));
500 remote_newthread_step
PARAMS ((threadref
* ref
,
504 remote_find_new_threads
PARAMS ((void));
507 threadalive_test
PARAMS ((char *cmd
, int tty
));
511 threadset_test_cmd
PARAMS ((char *cmd
, int tty
));
514 threadlist_test_cmd
PARAMS ((char *cmd
,
518 display_thread_info
PARAMS ((struct gdb_ext_thread_info
* info
));
522 get_and_display_threadinfo
PARAMS ((threadref
* ref
));
526 threadinfo_test_cmd
PARAMS ((char *cmd
,
530 thread_display_step
PARAMS ((
536 threadlist_update_test_cmd
PARAMS ((char *cmd
,
541 init_remote_threadtests
PARAMS ((void));
543 /* These are the threads which we last sent to the remote system.
544 -1 for all or -2 for not sent yet. */
548 /* Call this function as a result of
549 1) A halt indication (T packet) containing a thread id
550 2) A direct query of currthread
551 3) Successful execution of set thread
555 record_currthread (currthread
)
558 inferior_pid
= currthread
;
559 general_thread
= currthread
;
560 cont_thread
= currthread
;
569 int state
= gen
? general_thread
: cont_thread
;
575 buf
[1] = gen
? 'g' : 'c';
582 sprintf (&buf
[2], "-%x", -th
);
584 sprintf (&buf
[2], "%x", th
);
593 /* Return nonzero if the thread TH is still alive on the remote system. */
596 remote_thread_alive (th
)
603 sprintf (&buf
[1], "-%08x", -th
);
605 sprintf (&buf
[1], "%08x", th
);
608 return (buf
[0] == 'O' && buf
[1] == 'K');
612 About these extended threadlist and threadinfo packets.
613 They are variable length packets but, the fields within them
614 are often fixed length.
615 They are redundent enough to send over UDP as is the remote protocol
617 There is a matching unit test module in libstub.
621 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
622 /* encode 64 bits in 16 chars of hex */
625 static const char hexchars
[] = "0123456789abcdef";
632 if ((ch
>= 'a') && (ch
<= 'f'))
634 *val
= ch
- 'a' + 10;
637 if ((ch
>= 'A') && (ch
<= 'F'))
639 *val
= ch
- 'A' + 10;
642 if ((ch
>= '0') && (ch
<= '9'))
654 if (ch
>= 'a' && ch
<= 'f')
655 return ch
- 'a' + 10;
656 if (ch
>= '0' && ch
<= '9')
658 if (ch
>= 'A' && ch
<= 'F')
659 return ch
- 'A' + 10;
664 stub_unpack_int (buff
, fieldlength
)
672 nibble
= stubhex (*buff
++);
676 retval
= retval
<< 4;
682 unpack_varlen_hex (buff
, result
)
683 char *buff
; /* packet to parse */
690 while (ishex (*buff
, &nibble
))
693 retval
= retval
<< 4;
694 retval
|= nibble
& 0x0f;
701 unpack_nibble (buf
, val
)
711 pack_nibble (buf
, nibble
)
716 *buf
++ = hexchars
[(nibble
& 0x0f)];
721 pack_hex_byte (pkt
, byte
)
725 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
726 *pkt
++ = hexchars
[(byte
& 0xf)];
731 unpack_byte (buf
, value
)
735 *value
= stub_unpack_int (buf
, 2);
741 pack_int (buf
, value
)
745 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
746 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
747 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
748 buf
= pack_hex_byte (buf
, (value
& 0xff));
754 unpack_int (buf
, value
)
758 *value
= stub_unpack_int (buf
, 8);
764 pack_string (pkt
, string
)
770 len
= strlen (string
);
772 len
= 200; /* Bigger than most GDB packets, junk??? */
773 pkt
= pack_hex_byte (pkt
, len
);
777 if ((ch
== '\0') || (ch
== '#'))
778 ch
= '*'; /* Protect encapsulation */
785 unpack_string (src
, dest
, length
)
797 pack_threadid (pkt
, id
)
802 unsigned char *altid
;
803 altid
= (unsigned char *) id
;
804 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
806 pkt
= pack_hex_byte (pkt
, *altid
++);
812 unpack_threadid (inbuf
, id
)
817 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
819 altref
= (char *) id
;
821 while (inbuf
< limit
)
823 x
= stubhex (*inbuf
++);
824 y
= stubhex (*inbuf
++);
825 *altref
++ = (x
<< 4) | y
;
830 /* Externally, threadrefs are 64 bits but internally, they are still
831 ints. This is due to a mismatch of specifications.
832 We would like to use 64bit thread references internally.
833 This is an adapter function.
837 int_to_threadref (id
, value
)
842 scan
= (unsigned char *) id
;
848 *scan
++ = (value
>> 24) & 0xff;
849 *scan
++ = (value
>> 16) & 0xff;
850 *scan
++ = (value
>> 8) & 0xff;
851 *scan
++ = (value
& 0xff);
855 threadref_to_int (ref
)
866 value
= (value
<< 8) | ((*scan
++) & 0xff);
871 copy_threadref (dest
, src
)
876 unsigned char *csrc
, *cdest
;
877 csrc
= (unsigned char *) src
;
878 cdest
= (unsigned char *) dest
;
887 threadmatch (dest
, src
)
891 /* things are broken right now, so just assume we got a match */
893 unsigned char *srcp
, *destp
;
896 destp
= (char *) dest
;
900 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
907 #define PKT_TRACE(title,packet) { printf_filtered("%s %s\n", title, packet);}
909 #define PKT_TRACE(a,b) {}
913 /* ----- PACK_THREAD_INFO_REQUEST -------------------------------- */
916 threadid:1, # always request threadid
923 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
926 pack_threadinfo_request
PARAMS ((char *pkt
,
931 pack_threadinfo_request (pkt
, mode
, id
)
937 *pkt
++ = 'q'; /* Info Query */
938 *pkt
++ = 'P'; /* process or thread info */
939 pkt
= pack_int (pkt
, mode
); /* mode */
940 pkt
= pack_threadid (pkt
, id
); /* threadid */
941 *pkt
= '\0'; /* terminate */
942 PKT_TRACE ("threadinfo-req ", base
);
947 /* These values tag the fields in a thread info response packet */
948 /* Tagging the fields allows us to request specific fields and to
949 add more fields as time goes by */
950 #define TAG_THREADID 1 /* Echo the thread identifier */
951 #define TAG_EXISTS 2 /* It this process defined enough to
952 fetch registers and its stack */
953 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
954 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
955 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
960 remote_unpack_thread_info_response (pkt
, expectedref
, info
)
962 threadref
*expectedref
;
963 struct gdb_ext_thread_info
*info
;
968 char *limit
= pkt
+ PBUFSIZ
; /* plausable parsing limit */
971 PKT_TRACE ("unpack-threadinfo ", pkt
);
973 /* info->threadid = 0; FIXME: implement zero_threadref */
975 info
->display
[0] = '\0';
976 info
->shortname
[0] = '\0';
977 info
->more_display
[0] = '\0';
979 /* Assume the characters indicating the packet type have been stripped */
980 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
981 pkt
= unpack_threadid (pkt
, &ref
);
984 warning("Incomplete response to threadinfo request\n");
985 if (!threadmatch (&ref
, expectedref
))
986 { /* This is an answer to a different request */
987 warning("ERROR RMT Thread info mismatch\n");
990 copy_threadref (&info
->threadid
, &ref
);
992 /* Loop on tagged fields , try to bail if somthing goes wrong */
994 while ((pkt
< limit
) && mask
&& *pkt
) /* packets are terminated with nulls */
996 pkt
= unpack_int (pkt
, &tag
); /* tag */
997 pkt
= unpack_byte (pkt
, &length
); /* length */
998 if (!(tag
& mask
)) /* tags out of synch with mask */
1000 warning ("ERROR RMT: threadinfo tag mismatch\n");
1004 if (tag
== TAG_THREADID
)
1008 warning ("ERROR RMT: length of threadid is not 16\n");
1012 pkt
= unpack_threadid (pkt
, &ref
);
1013 mask
= mask
& ~TAG_THREADID
;
1016 if (tag
== TAG_EXISTS
)
1018 info
->active
= stub_unpack_int (pkt
, length
);
1020 mask
= mask
& ~(TAG_EXISTS
);
1023 warning ("ERROR RMT: 'exists' length too long\n");
1029 if (tag
== TAG_THREADNAME
)
1031 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1032 mask
= mask
& ~TAG_THREADNAME
;
1035 if (tag
== TAG_DISPLAY
)
1037 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1038 mask
= mask
& ~TAG_DISPLAY
;
1041 if (tag
== TAG_MOREDISPLAY
)
1043 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1044 mask
= mask
& ~TAG_MOREDISPLAY
;
1047 warning ("ERROR RMT: unknown thread info tag\n");
1048 break; /* Not a tag we know about */
1054 /* ------ REMOTE_GET_THREADINFO -------------------------------------- */
1057 remote_get_threadinfo (threadid
, fieldset
, info
)
1058 threadref
*threadid
;
1059 int fieldset
; /* TAG mask */
1060 struct gdb_ext_thread_info
*info
;
1063 char threadinfo_pkt
[PBUFSIZ
];
1064 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
1065 putpkt (threadinfo_pkt
);
1066 getpkt (threadinfo_pkt
, 0);
1067 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2,
1072 /* ------- ADAPT_remote_GET_THREADINFO - */
1073 /* Unfortunatly, 61 but thread-ids are bugger than the internal
1074 representation of a threadid. */
1078 adapt_remote_get_threadinfo (ref
, selection
, info
)
1081 struct gdb_ext_thread_info
*info
;
1084 int_to_threadref (&lclref
, *ref
);
1085 return remote_get_threadinfo (&lclref
, selection
, info
);
1089 /* -------- PACK_THREADLIST-REQUEST --------------------------------- */
1090 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1093 pack_threadlist_request (pkt
, startflag
, threadcount
, nextthread
)
1097 threadref
*nextthread
;
1099 *pkt
++ = 'q'; /* info query packet */
1100 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1101 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1102 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1103 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1109 /* ---------- PARSE_THREADLIST_RESPONSE -------------------------------- */
1110 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1114 parse_threadlist_response (pkt
, result_limit
, original_echo
,
1115 resultlist
, doneflag
)
1118 threadref
*original_echo
;
1119 threadref
*resultlist
;
1123 int count
, resultcount
, done
;
1126 /* assume the 'q' and 'M chars have been stripped */
1127 PKT_TRACE ("parse-threadlist-response ", pkt
);
1128 limit
= pkt
+ (PBUFSIZ
- BUF_THREAD_ID_SIZE
); /* done parse past here */
1129 pkt
= unpack_byte (pkt
, &count
); /* count field */
1130 pkt
= unpack_nibble (pkt
, &done
);
1131 /* The first threadid is the argument threadid */
1132 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1133 while ((count
-- > 0) && (pkt
< limit
))
1135 pkt
= unpack_threadid (pkt
, resultlist
++);
1136 if (resultcount
++ >= result_limit
)
1141 return resultcount
; /* successvalue */
1147 remote_get_threadlist (startflag
, nextthread
, result_limit
,
1148 done
, result_count
, threadlist
)
1150 threadref
*nextthread
;
1154 threadref
*threadlist
;
1157 static threadref echo_nextthread
;
1158 char threadlist_packet
[PBUFSIZ
];
1159 char t_response
[PBUFSIZ
];
1162 /* Trancate result limit to be smaller than the packet size */
1163 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= PBUFSIZ
)
1164 result_limit
= (PBUFSIZ
/ BUF_THREAD_ID_SIZE
) - 2;
1166 pack_threadlist_request (threadlist_packet
,
1167 startflag
, result_limit
, nextthread
);
1168 putpkt (threadlist_packet
);
1169 getpkt (t_response
, 0);
1170 *result_count
= parse_threadlist_response (t_response
+ 2, /* strip header */
1175 if (!threadmatch (&echo_nextthread
, nextthread
))
1177 /* FIXME: This is a good reason to drop the packet */
1178 /* Possably, there is a duplicate response */
1180 retransmit immediatly - race conditions
1181 retransmit after timeout - yes
1183 wait for packet, then exit
1185 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1186 return 0; /* I choose simply exiting */
1188 if (*result_count
<= 0)
1192 warning ("RMT ERROR : failed to get remote thread list\n");
1195 return result
; /* break; */
1197 if (*result_count
> result_limit
)
1200 warning ("RMT ERROR: threadlist response longer than requested\n");
1208 /* This is the interface between remote and threads, remotes upper interface */
1209 /* remote_find_new_threads retreives the thread list and for each
1210 thread in the list, looks up the thread in GDB's internal list,
1211 ading the thread if it does not already exist.
1212 This involves getting partial thread lists from the remote target so,
1213 polling the quit_flag is required.
1216 typedef int (*rmt_thread_action
) (
1221 /* About this many threadisds fit in a packet */
1222 #define MAXTHREADLISTRESULTS 32
1225 remote_threadlist_iterator
PARAMS ((
1226 rmt_thread_action stepfunction
,
1231 remote_threadlist_iterator (stepfunction
, context
, looplimit
)
1232 rmt_thread_action stepfunction
;
1236 int done
, i
, result_count
;
1240 static threadref nextthread
;
1241 static threadref echo_nextthread
;
1242 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1247 if (loopcount
++ > looplimit
)
1250 warning ("Remote fetch threadlist -infinite loop-\n");
1253 if (!remote_get_threadlist (startflag
,
1255 MAXTHREADLISTRESULTS
,
1263 startflag
= 0; /* clear for later iterations */
1264 /* Setup to resume next batch of thread references , set nestthread */
1265 if (result_count
>= 1)
1266 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1267 /* output_threadid("last-of-batch",&nextthread); */
1269 while (result_count
--)
1270 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1278 remote_newthread_step (ref
, context
)
1283 pid
= threadref_to_int (ref
);
1284 if (!in_thread_list (pid
))
1286 return 1; /* continue iterator */
1289 #define CRAZY_MAX_THREADS 1000
1292 remote_find_new_threads (void)
1296 ret
= remote_threadlist_iterator (remote_newthread_step
, 0,
1299 } /* remote_find_new_threads */
1302 remote_update_threads ()
1304 /* Right now, this is empty. But it is one of the functions
1305 defined for the thread target vector so it gets called.
1306 If we were to allow the modification of the registers of
1307 a suspended process, this would be implemented. */
1311 static struct target_thread_vector remote_thread_vec
;
1313 /* Initialize the thread vector which is used by threads.c */
1314 /* The thread stubb is a package, it has an initializer */
1315 void init_remote_threads ()
1317 remote_thread_vec
.find_new_threads
= remote_find_new_threads
;
1318 remote_thread_vec
.get_thread_info
= adapt_remote_get_threadinfo
;
1321 /* --------- UNIT_TEST for THREAD oriented PACKETS -------------------- */
1323 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
1327 threadset_test_cmd (cmd
, tty
)
1331 int sample_thread
= SAMPLE_THREAD
;
1332 printf_filtered ("Remote threadset test\n");
1333 set_thread (sample_thread
, 1);
1338 threadalive_test (cmd
, tty
)
1342 int sample_thread
= SAMPLE_THREAD
;
1343 if (remote_thread_alive (sample_thread
))
1344 printf_filtered ("PASS: Thread alive test\n");
1346 printf_filtered ("FAIL: Thread alive test\n");
1350 output_threadid
PARAMS ((char *title
, threadref
* ref
));
1353 output_threadid (title
, ref
)
1358 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex */
1360 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
1365 threadlist_test_cmd (cmd
, tty
)
1370 threadref nextthread
;
1371 int done
, result_count
;
1372 threadref threadlist
[3];
1374 printf_filtered ("Remote Threadlist test\n");
1375 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
1376 &result_count
, &threadlist
[0]))
1377 printf_filtered ("FAIL: threadlist test\n");
1380 threadref
*scan
= threadlist
;
1381 threadref
*limit
= scan
+ result_count
;
1382 while (scan
< limit
)
1383 output_threadid (" thread ", scan
++);
1388 display_thread_info (info
)
1389 struct gdb_ext_thread_info
*info
;
1392 output_threadid ("Threadid: ", &info
->threadid
);
1394 printf_filtered ("Name: %s\n ", info
->shortname
);
1395 /* format display state */
1396 printf_filtered ("State: %s\n", info
->display
);
1397 /* additional data */
1398 printf_filtered ("other: %s\n\n", info
->more_display
);
1402 get_and_display_threadinfo (ref
)
1407 struct gdb_ext_thread_info threadinfo
;
1409 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
1410 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
1411 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
1412 display_thread_info (&threadinfo
);
1417 threadinfo_test_cmd (cmd
, tty
)
1421 int athread
= SAMPLE_THREAD
;
1425 int_to_threadref (&thread
, athread
);
1426 printf_filtered ("Remote Threadinfo test\n");
1427 if (!get_and_display_threadinfo (&thread
))
1428 printf_filtered ("FAIL cannot get thread info\n");
1433 thread_display_step (ref
, context
)
1437 /* output_threadid(" threadstep ",ref); *//* simple test */
1438 return get_and_display_threadinfo (ref
);
1443 threadlist_update_test_cmd (cmd
, tty
)
1447 printf_filtered ("Remote Threadlist update test\n");
1448 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
1452 init_remote_threadtests (void)
1454 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
1455 "Fetch and print the remote list of thread identifiers, one pkt only");
1456 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
1457 "Fetch and display info about one thread");
1458 add_com ("tset", class_obscure
, threadset_test_cmd
,
1459 "Test setting to a different thread");
1460 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
1461 "Iterate through updating all remote thread info");
1462 add_com ("talive", class_obscure
, threadalive_test
,
1463 " Remote thread alive test ");
1466 #define INIT_REMOTE_THREADTESTS { init_remote_threadtests();}
1467 /* END OF REMOTE THREAD UNIT TESTS */
1470 /* Restart the remote side; this is an extended protocol operation. */
1473 extended_remote_restart ()
1477 /* Send the restart command; for reasons I don't understand the
1478 remote side really expects a number after the "R". */
1480 sprintf (&buf
[1], "%x", 0);
1483 /* Now query for status so this looks just like we restarted
1484 gdbserver from scratch. */
1489 /* Clean up connection to a remote debugger. */
1493 remote_close (quitting
)
1497 SERIAL_CLOSE (remote_desc
);
1501 /* Query the remote side for the text, data and bss offsets. */
1506 char buf
[PBUFSIZ
], *ptr
;
1508 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1509 struct section_offsets
*offs
;
1511 putpkt ("qOffsets");
1515 if (buf
[0] == '\000')
1516 return; /* Return silently. Stub doesn't support
1520 warning ("Remote failure reply: %s", buf
);
1524 /* Pick up each field in turn. This used to be done with scanf, but
1525 scanf will make trouble if CORE_ADDR size doesn't match
1526 conversion directives correctly. The following code will work
1527 with any size of CORE_ADDR. */
1528 text_addr
= data_addr
= bss_addr
= 0;
1532 if (strncmp (ptr
, "Text=", 5) == 0)
1535 /* Don't use strtol, could lose on big values. */
1536 while (*ptr
&& *ptr
!= ';')
1537 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1542 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1545 while (*ptr
&& *ptr
!= ';')
1546 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1551 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
1554 while (*ptr
&& *ptr
!= ';')
1555 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
1561 error ("Malformed response to offset query, %s", buf
);
1563 if (symfile_objfile
== NULL
)
1566 offs
= (struct section_offsets
*) alloca (sizeof (struct section_offsets
)
1567 + symfile_objfile
->num_sections
1568 * sizeof (offs
->offsets
));
1569 memcpy (offs
, symfile_objfile
->section_offsets
,
1570 sizeof (struct section_offsets
)
1571 + symfile_objfile
->num_sections
1572 * sizeof (offs
->offsets
));
1574 ANOFFSET (offs
, SECT_OFF_TEXT
) = text_addr
;
1576 /* This is a temporary kludge to force data and bss to use the same offsets
1577 because that's what nlmconv does now. The real solution requires changes
1578 to the stub and remote.c that I don't have time to do right now. */
1580 ANOFFSET (offs
, SECT_OFF_DATA
) = data_addr
;
1581 ANOFFSET (offs
, SECT_OFF_BSS
) = data_addr
;
1583 objfile_relocate (symfile_objfile
, offs
);
1586 /* Stub for catch_errors. */
1589 remote_start_remote (dummy
)
1592 immediate_quit
= 1; /* Allow user to interrupt it */
1594 /* Ack any packet which the remote side has already sent. */
1595 SERIAL_WRITE (remote_desc
, "+", 1);
1597 /* Let the stub know that we want it to return the thread. */
1600 get_offsets (); /* Get text, data & bss offsets */
1602 putpkt ("?"); /* initiate a query from remote machine */
1605 start_remote (); /* Initialize gdb process mechanisms */
1609 /* Open a connection to a remote debugger.
1610 NAME is the filename used for communication. */
1613 remote_open (name
, from_tty
)
1617 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
1620 /* Open a connection to a remote debugger using the extended
1621 remote gdb protocol. NAME is the filename used for communication. */
1624 extended_remote_open (name
, from_tty
)
1628 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1/*extended_p*/);
1631 /* Generic code for opening a connection to a remote target. */
1632 static DCACHE
*remote_dcache
;
1635 remote_open_1 (name
, from_tty
, target
, extended_p
)
1638 struct target_ops
*target
;
1642 error ("To open a remote debug connection, you need to specify what\n\
1643 serial device is attached to the remote system (e.g. /dev/ttya).");
1645 target_preopen (from_tty
);
1647 unpush_target (target
);
1649 remote_dcache
= dcache_init (remote_read_bytes
, remote_write_bytes
);
1651 remote_desc
= SERIAL_OPEN (name
);
1653 perror_with_name (name
);
1655 if (baud_rate
!= -1)
1657 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
1659 SERIAL_CLOSE (remote_desc
);
1660 perror_with_name (name
);
1665 SERIAL_RAW (remote_desc
);
1667 /* If there is something sitting in the buffer we might take it as a
1668 response to a command, which would be bad. */
1669 SERIAL_FLUSH_INPUT (remote_desc
);
1673 puts_filtered ("Remote debugging using ");
1674 puts_filtered (name
);
1675 puts_filtered ("\n");
1677 push_target (target
); /* Switch to using remote target now */
1678 /* The target vector does not have the thread functions in it yet,
1679 so we use this function to call back into the thread module and
1680 register the thread vector and its contained functions. */
1681 bind_target_thread_vector(&remote_thread_vec
);
1682 /* Start out by trying the 'P' request to set registers. We set this each
1683 time that we open a new target so that if the user switches from one
1684 stub to another, we can (if the target is closed and reopened) cope. */
1685 stub_supports_P
= 1;
1687 general_thread
= -2;
1690 /* Without this, some commands which require an active target (such as kill)
1691 won't work. This variable serves (at least) double duty as both the pid
1692 of the target process (if it has such), and as a flag indicating that a
1693 target is active. These functions should be split out into seperate
1694 variables, especially since GDB will someday have a notion of debugging
1695 several processes. */
1697 inferior_pid
= 42000;
1698 /* Start the remote connection; if error (0), discard this target.
1699 In particular, if the user quits, be sure to discard it
1700 (we'd be in an inconsistent state otherwise). */
1701 if (!catch_errors (remote_start_remote
, (char *)0,
1702 "Couldn't establish connection to remote target\n",
1711 /* tell the remote that we're using the extended protocol. */
1718 /* This takes a program previously attached to and detaches it. After
1719 this is done, GDB can be used to debug some other program. We
1720 better not have left any breakpoints in the target program or it'll
1721 die when it hits one. */
1724 remote_detach (args
, from_tty
)
1731 error ("Argument given to \"detach\" when remotely debugging.");
1733 /* Tell the remote target to detach. */
1739 puts_filtered ("Ending remote debugging.\n");
1742 /* Convert hex digit A to a number. */
1748 if (a
>= '0' && a
<= '9')
1750 else if (a
>= 'a' && a
<= 'f')
1751 return a
- 'a' + 10;
1752 else if (a
>= 'A' && a
<= 'F')
1753 return a
- 'A' + 10;
1755 error ("Reply contains invalid hex digit %d", a
);
1758 /* Convert number NIB to a hex digit. */
1770 /* Tell the remote machine to resume. */
1772 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
1776 remote_resume (pid
, step
, siggnal
)
1778 enum target_signal siggnal
;
1783 set_thread (inferior_pid
, 0);
1785 set_thread (pid
, 0);
1787 dcache_flush (remote_dcache
);
1789 last_sent_signal
= siggnal
;
1790 last_sent_step
= step
;
1792 /* A hook for when we need to do something at the last moment before
1794 if (target_resume_hook
)
1795 (*target_resume_hook
) ();
1797 if (siggnal
!= TARGET_SIGNAL_0
)
1799 buf
[0] = step
? 'S' : 'C';
1800 buf
[1] = tohex (((int)siggnal
>> 4) & 0xf);
1801 buf
[2] = tohex ((int)siggnal
& 0xf);
1805 strcpy (buf
, step
? "s": "c");
1810 /* Send ^C to target to halt it. Target will respond, and send us a
1812 static void (*ofunc
) PARAMS ((int));
1815 remote_interrupt (signo
)
1819 signal (signo
, remote_interrupt
);
1825 if (!interrupted_already
)
1827 /* Send a break or a ^C, depending on user preference. */
1828 interrupted_already
= 1;
1831 printf_unfiltered ("remote_stop called\n");
1834 SERIAL_SEND_BREAK (remote_desc
);
1836 SERIAL_WRITE (remote_desc
, "\003", 1);
1840 signal (SIGINT
, ofunc
);
1842 signal (SIGINT
, remote_interrupt
);
1843 interrupted_already
= 0;
1847 /* Ask the user what to do when an interrupt is received. */
1852 target_terminal_ours ();
1854 if (query ("Interrupted while waiting for the program.\n\
1855 Give up (and stop debugging it)? "))
1857 target_mourn_inferior ();
1858 return_to_top_level (RETURN_QUIT
);
1861 target_terminal_inferior ();
1864 /* If nonzero, ignore the next kill. */
1868 remote_console_output (msg
)
1873 for (p
= msg
; *p
; p
+=2)
1876 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
1879 if (target_output_hook
)
1880 target_output_hook (tb
);
1882 fputs_filtered (tb
, gdb_stdout
);
1886 /* Wait until the remote machine stops, then return,
1887 storing status in STATUS just as `wait' would.
1888 Returns "pid" (though it's not clear what, if anything, that
1889 means in the case of this target). */
1892 remote_wait (pid
, status
)
1894 struct target_waitstatus
*status
;
1896 unsigned char buf
[PBUFSIZ
];
1897 int thread_num
= -1;
1899 status
->kind
= TARGET_WAITKIND_EXITED
;
1900 status
->value
.integer
= 0;
1906 interrupted_already
= 0;
1907 ofunc
= signal (SIGINT
, remote_interrupt
);
1908 getpkt ((char *) buf
, 1);
1909 signal (SIGINT
, ofunc
);
1911 /* This is a hook for when we need to do something (perhaps the
1912 collection of trace data) every time the target stops. */
1913 if (target_wait_loop_hook
)
1914 (*target_wait_loop_hook
) ();
1918 case 'E': /* Error of some sort */
1919 warning ("Remote failure reply: %s", buf
);
1921 case 'T': /* Status with PC, SP, FP, ... */
1925 char regs
[MAX_REGISTER_RAW_SIZE
];
1927 /* Expedited reply, containing Signal, {regno, reg} repeat */
1928 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
1930 n... = register number
1931 r... = register contents
1933 p
= &buf
[3]; /* after Txx */
1940 /* Read the register number */
1941 regno
= strtol ((const char *) p
, &p_temp
, 16);
1942 p1
= (unsigned char *)p_temp
;
1944 if (p1
== p
) /* No register number present here */
1946 p1
= (unsigned char *) strchr ((const char *) p
, ':');
1948 warning ("Malformed packet(a) (missing colon): %s\n\
1951 if (strncmp ((const char *) p
, "thread", p1
- p
) == 0)
1953 p_temp
= unpack_varlen_hex(++p1
,&thread_num
);
1954 record_currthread(thread_num
);
1955 p
= (unsigned char *)p_temp
;
1963 warning ("Malformed packet(b) (missing colon): %s\n\
1967 if (regno
>= NUM_REGS
)
1968 warning ("Remote sent bad register number %ld: %s\n\
1972 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
++)
1974 if (p
[0] == 0 || p
[1] == 0)
1975 warning ("Remote reply is too short: %s", buf
);
1976 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
1979 supply_register (regno
, regs
);
1984 warning ("Remote register badly formatted: %s", buf
);
1985 warning (" here: %s",p
);
1990 case 'S': /* Old style status, just signal only */
1991 status
->kind
= TARGET_WAITKIND_STOPPED
;
1992 status
->value
.sig
= (enum target_signal
)
1993 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
1996 case 'W': /* Target exited */
1998 /* The remote process exited. */
1999 status
->kind
= TARGET_WAITKIND_EXITED
;
2000 status
->value
.integer
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
2004 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
2005 status
->value
.sig
= (enum target_signal
)
2006 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
2010 case 'O': /* Console output */
2011 remote_console_output (buf
+ 1);
2014 if (last_sent_signal
!= TARGET_SIGNAL_0
)
2016 /* Zero length reply means that we tried 'S' or 'C' and
2017 the remote system doesn't support it. */
2018 target_terminal_ours_for_output ();
2020 ("Can't send signals to this remote system. %s not sent.\n",
2021 target_signal_to_name (last_sent_signal
));
2022 last_sent_signal
= TARGET_SIGNAL_0
;
2023 target_terminal_inferior ();
2025 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
2026 putpkt ((char *) buf
);
2029 /* else fallthrough */
2031 warning ("Invalid remote reply: %s", buf
);
2036 if (thread_num
!= -1)
2038 /* Initial thread value can only be acquired via wait, so deal with
2039 this marker which is used before the first thread value is
2041 if (inferior_pid
== 42000)
2043 inferior_pid
= thread_num
;
2044 add_thread (inferior_pid
);
2048 return inferior_pid
;
2051 /* Number of bytes of registers this stub implements. */
2052 static int register_bytes_found
;
2054 /* Read the remote registers into the block REGS. */
2055 /* Currently we just read all the registers, so we don't use regno. */
2058 remote_fetch_registers (regno
)
2064 char regs
[REGISTER_BYTES
];
2066 set_thread (inferior_pid
, 1);
2071 if (remote_register_buf_size
== 0)
2072 remote_register_buf_size
= strlen (buf
);
2074 /* Unimplemented registers read as all bits zero. */
2075 memset (regs
, 0, REGISTER_BYTES
);
2077 /* We can get out of synch in various cases. If the first character
2078 in the buffer is not a hex character, assume that has happened
2079 and try to fetch another packet to read. */
2080 while ((buf
[0] < '0' || buf
[0] > '9')
2081 && (buf
[0] < 'a' || buf
[0] > 'f')
2082 && buf
[0] != 'x') /* New: unavailable register value */
2085 printf_unfiltered ("Bad register packet; fetching a new packet\n");
2089 /* Reply describes registers byte by byte, each byte encoded as two
2090 hex characters. Suck them all up, then supply them to the
2091 register cacheing/storage mechanism. */
2094 for (i
= 0; i
< REGISTER_BYTES
; i
++)
2100 warning ("Remote reply is of odd length: %s", buf
);
2101 /* Don't change register_bytes_found in this case, and don't
2102 print a second warning. */
2105 if (p
[0] == 'x' && p
[1] == 'x')
2106 regs
[i
] = 0; /* 'x' */
2108 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
2112 if (i
!= register_bytes_found
)
2114 register_bytes_found
= i
;
2115 #ifdef REGISTER_BYTES_OK
2116 if (!REGISTER_BYTES_OK (i
))
2117 warning ("Remote reply is too short: %s", buf
);
2122 for (i
= 0; i
< NUM_REGS
; i
++)
2124 supply_register (i
, ®s
[REGISTER_BYTE(i
)]);
2125 if (buf
[REGISTER_BYTE(i
) * 2] == 'x')
2126 register_valid
[i
] = -1; /* register value not available */
2130 /* Prepare to store registers. Since we may send them all (using a
2131 'G' request), we have to read out the ones we don't want to change
2135 remote_prepare_to_store ()
2137 /* Make sure the entire registers array is valid. */
2138 read_register_bytes (0, (char *)NULL
, REGISTER_BYTES
);
2141 /* Store register REGNO, or all registers if REGNO == -1, from the contents
2142 of REGISTERS. FIXME: ignores errors. */
2145 remote_store_registers (regno
)
2152 set_thread (inferior_pid
, 1);
2154 if (regno
>= 0 && stub_supports_P
)
2156 /* Try storing a single register. */
2159 sprintf (buf
, "P%x=", regno
);
2160 p
= buf
+ strlen (buf
);
2161 regp
= ®isters
[REGISTER_BYTE (regno
)];
2162 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); ++i
)
2164 *p
++ = tohex ((regp
[i
] >> 4) & 0xf);
2165 *p
++ = tohex (regp
[i
] & 0xf);
2171 /* The stub understands the 'P' request. We are done. */
2175 /* The stub does not support the 'P' request. Use 'G' instead,
2176 and don't try using 'P' in the future (it will just waste our
2178 stub_supports_P
= 0;
2183 /* Command describes registers byte by byte,
2184 each byte encoded as two hex characters. */
2187 /* remote_prepare_to_store insures that register_bytes_found gets set. */
2188 for (i
= 0; i
< register_bytes_found
; i
++)
2190 *p
++ = tohex ((registers
[i
] >> 4) & 0xf);
2191 *p
++ = tohex (registers
[i
] & 0xf);
2199 Use of the data cache *used* to be disabled because it loses for looking
2200 at and changing hardware I/O ports and the like. Accepting `volatile'
2201 would perhaps be one way to fix it. Another idea would be to use the
2202 executable file for the text segment (for all SEC_CODE sections?
2203 For all SEC_READONLY sections?). This has problems if you want to
2204 actually see what the memory contains (e.g. self-modifying code,
2205 clobbered memory, user downloaded the wrong thing).
2207 Because it speeds so much up, it's now enabled, if you're playing
2208 with registers you turn it of (set remotecache 0)
2211 /* Read a word from remote address ADDR and return it.
2212 This goes through the data cache. */
2216 remote_fetch_word (addr
)
2219 return dcache_fetch (remote_dcache
, addr
);
2222 /* Write a word WORD into remote address ADDR.
2223 This goes through the data cache. */
2226 remote_store_word (addr
, word
)
2230 dcache_poke (remote_dcache
, addr
, word
);
2232 #endif /* 0 (unused?) */
2236 /* Return the number of hex digits in num. */
2244 for (i
= 0; num
!= 0; i
++)
2250 /* Set BUF to the hex digits representing NUM */
2253 hexnumstr (buf
, num
)
2258 int len
= hexnumlen (num
);
2262 for (i
= len
- 1; i
>= 0; i
--)
2264 buf
[i
] = "0123456789abcdef" [(num
& 0xf)];
2271 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits */
2274 remote_address_masked (addr
)
2277 if (remote_address_size
> 0
2278 && remote_address_size
< (sizeof (ULONGEST
) * 8))
2280 /* Only create a mask when that mask can safely be constructed
2281 in a ULONGEST variable. */
2283 mask
= (mask
<< remote_address_size
) - 1;
2289 /* Write memory data directly to the remote machine.
2290 This does not inform the data cache; the data cache uses this.
2291 MEMADDR is the address in the remote memory space.
2292 MYADDR is the address of the buffer in our space.
2293 LEN is the number of bytes.
2295 Returns number of bytes transferred, or 0 for error. */
2298 remote_write_bytes (memaddr
, myaddr
, len
)
2303 int max_buf_size
; /* Max size of packet output buffer */
2306 /* Chop the transfer down if necessary */
2308 max_buf_size
= min (remote_write_size
, PBUFSIZ
);
2309 if (remote_register_buf_size
!= 0)
2310 max_buf_size
= min (max_buf_size
, remote_register_buf_size
);
2312 /* Subtract header overhead from max payload size - $M<memaddr>,<len>:#nn */
2313 max_buf_size
-= 2 + hexnumlen (memaddr
+ len
- 1) + 1 + hexnumlen (len
) + 4;
2323 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
2325 /* construct "M"<memaddr>","<len>":" */
2326 /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
2327 memaddr
= remote_address_masked (memaddr
);
2330 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
2332 p
+= hexnumstr (p
, (ULONGEST
) todo
);
2336 /* We send target system values byte by byte, in increasing byte
2337 addresses, each byte encoded as two hex characters. */
2339 for (i
= 0; i
< todo
; i
++)
2341 *p
++ = tohex ((myaddr
[i
] >> 4) & 0xf);
2342 *p
++ = tohex (myaddr
[i
] & 0xf);
2351 /* There is no correspondance between what the remote protocol uses
2352 for errors and errno codes. We would like a cleaner way of
2353 representing errors (big enough to include errno codes, bfd_error
2354 codes, and others). But for now just return EIO. */
2365 /* Read memory data directly from the remote machine.
2366 This does not use the data cache; the data cache uses this.
2367 MEMADDR is the address in the remote memory space.
2368 MYADDR is the address of the buffer in our space.
2369 LEN is the number of bytes.
2371 Returns number of bytes transferred, or 0 for error. */
2374 remote_read_bytes (memaddr
, myaddr
, len
)
2379 int max_buf_size
; /* Max size of packet output buffer */
2382 /* Chop the transfer down if necessary */
2384 max_buf_size
= min (remote_write_size
, PBUFSIZ
);
2385 if (remote_register_buf_size
!= 0)
2386 max_buf_size
= min (max_buf_size
, remote_register_buf_size
);
2396 todo
= min (len
, max_buf_size
/ 2); /* num bytes that will fit */
2398 /* construct "m"<memaddr>","<len>" */
2399 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
2400 memaddr
= remote_address_masked (memaddr
);
2403 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
2405 p
+= hexnumstr (p
, (ULONGEST
) todo
);
2413 /* There is no correspondance between what the remote protocol uses
2414 for errors and errno codes. We would like a cleaner way of
2415 representing errors (big enough to include errno codes, bfd_error
2416 codes, and others). But for now just return EIO. */
2421 /* Reply describes memory byte by byte,
2422 each byte encoded as two hex characters. */
2425 for (i
= 0; i
< todo
; i
++)
2427 if (p
[0] == 0 || p
[1] == 0)
2428 /* Reply is short. This means that we were able to read
2429 only part of what we wanted to. */
2430 return i
+ (origlen
- len
);
2431 myaddr
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
2441 /* Read or write LEN bytes from inferior memory at MEMADDR, transferring
2442 to or from debugger address MYADDR. Write to inferior if SHOULD_WRITE is
2443 nonzero. Returns length of data written or read; 0 for error. */
2447 remote_xfer_memory(memaddr
, myaddr
, len
, should_write
, target
)
2452 struct target_ops
*target
; /* ignored */
2454 #ifdef REMOTE_TRANSLATE_XFER_ADDRESS
2457 REMOTE_TRANSLATE_XFER_ADDRESS (memaddr
, len
, targaddr
, targlen
);
2464 return dcache_xfer_memory (remote_dcache
, memaddr
, myaddr
,
2470 /* Enable after 4.12. */
2473 remote_search (len
, data
, mask
, startaddr
, increment
, lorange
, hirange
2474 addr_found
, data_found
)
2478 CORE_ADDR startaddr
;
2482 CORE_ADDR
*addr_found
;
2485 if (increment
== -4 && len
== 4)
2487 long mask_long
, data_long
;
2488 long data_found_long
;
2489 CORE_ADDR addr_we_found
;
2491 long returned_long
[2];
2494 mask_long
= extract_unsigned_integer (mask
, len
);
2495 data_long
= extract_unsigned_integer (data
, len
);
2496 sprintf (buf
, "t%x:%x,%x", startaddr
, data_long
, mask_long
);
2501 /* The stub doesn't support the 't' request. We might want to
2502 remember this fact, but on the other hand the stub could be
2503 switched on us. Maybe we should remember it only until
2504 the next "target remote". */
2505 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
2506 hirange
, addr_found
, data_found
);
2511 /* There is no correspondance between what the remote protocol uses
2512 for errors and errno codes. We would like a cleaner way of
2513 representing errors (big enough to include errno codes, bfd_error
2514 codes, and others). But for now just use EIO. */
2515 memory_error (EIO
, startaddr
);
2518 while (*p
!= '\0' && *p
!= ',')
2519 addr_we_found
= (addr_we_found
<< 4) + fromhex (*p
++);
2521 error ("Protocol error: short return for search");
2523 data_found_long
= 0;
2524 while (*p
!= '\0' && *p
!= ',')
2525 data_found_long
= (data_found_long
<< 4) + fromhex (*p
++);
2526 /* Ignore anything after this comma, for future extensions. */
2528 if (addr_we_found
< lorange
|| addr_we_found
>= hirange
)
2534 *addr_found
= addr_we_found
;
2535 *data_found
= store_unsigned_integer (data_we_found
, len
);
2538 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
2539 hirange
, addr_found
, data_found
);
2544 remote_files_info (ignore
)
2545 struct target_ops
*ignore
;
2547 puts_filtered ("Debugging a target over a serial line.\n");
2550 /* Stuff for dealing with the packets which are part of this protocol.
2551 See comment at top of file for details. */
2553 /* Read a single character from the remote end, masking it down to 7 bits. */
2561 ch
= SERIAL_READCHAR (remote_desc
, timeout
);
2566 error ("Remote connection closed");
2568 perror_with_name ("Remote communication error");
2569 case SERIAL_TIMEOUT
:
2576 /* Send the command in BUF to the remote machine,
2577 and read the reply into BUF.
2578 Report an error if we get an error reply. */
2588 error ("Remote failure reply: %s", buf
);
2591 /* Display a null-terminated packet on stdout, for debugging, using C
2598 puts_filtered ("\"");
2600 gdb_printchar (*buf
++, gdb_stdout
, '"');
2601 puts_filtered ("\"");
2605 /* Send a packet to the remote machine, with error checking.
2606 The data of the packet is in BUF. */
2613 unsigned char csum
= 0;
2615 int cnt
= strlen (buf
);
2620 /* Copy the packet into buffer BUF2, encapsulating it
2621 and giving it a checksum. */
2623 if (cnt
> (int) sizeof (buf2
) - 5) /* Prosanity check */
2629 for (i
= 0; i
< cnt
; i
++)
2635 *p
++ = tohex ((csum
>> 4) & 0xf);
2636 *p
++ = tohex (csum
& 0xf);
2638 /* Send it over and over until we get a positive ack. */
2642 int started_error_output
= 0;
2647 printf_unfiltered ("Sending packet: %s...", buf2
);
2648 gdb_flush(gdb_stdout
);
2650 if (SERIAL_WRITE (remote_desc
, buf2
, p
- buf2
))
2651 perror_with_name ("putpkt: write failed");
2653 /* read until either a timeout occurs (-2) or '+' is read */
2656 ch
= readchar (remote_timeout
);
2663 case SERIAL_TIMEOUT
:
2665 if (started_error_output
)
2667 putchar_unfiltered ('\n');
2668 started_error_output
= 0;
2677 printf_unfiltered("Ack\n");
2679 case SERIAL_TIMEOUT
:
2683 break; /* Retransmit buffer */
2686 char junkbuf
[PBUFSIZ
];
2688 /* It's probably an old response, and we're out of sync.
2689 Just gobble up the packet and ignore it. */
2690 getpkt (junkbuf
, 0);
2691 continue; /* Now, go look for + */
2696 if (!started_error_output
)
2698 started_error_output
= 1;
2699 printf_unfiltered ("putpkt: Junk: ");
2701 putchar_unfiltered (ch
& 0177);
2705 break; /* Here to retransmit */
2709 /* This is wrong. If doing a long backtrace, the user should be
2710 able to get out next time we call QUIT, without anything as
2711 violent as interrupt_query. If we want to provide a way out of
2712 here without getting to the next QUIT, it should be based on
2713 hitting ^C twice as in remote_wait. */
2723 /* Come here after finding the start of the frame. Collect the rest into BUF,
2724 verifying the checksum, length, and handling run-length compression.
2725 Returns 0 on any error, 1 on success. */
2740 c
= readchar (remote_timeout
);
2744 case SERIAL_TIMEOUT
:
2746 puts_filtered ("Timeout in mid-packet, retrying\n");
2750 puts_filtered ("Saw new packet start in middle of old one\n");
2751 return 0; /* Start a new packet, count retries */
2754 unsigned char pktcsum
;
2758 pktcsum
= fromhex (readchar (remote_timeout
)) << 4;
2759 pktcsum
|= fromhex (readchar (remote_timeout
));
2761 if (csum
== pktcsum
)
2766 printf_filtered ("Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
2768 puts_filtered (buf
);
2769 puts_filtered ("\n");
2773 case '*': /* Run length encoding */
2775 c
= readchar (remote_timeout
);
2777 c
= c
- ' ' + 3; /* Compute repeat count */
2780 if (c
> 0 && c
< 255 && bp
+ c
- 1 < buf
+ PBUFSIZ
- 1)
2782 memset (bp
, *(bp
- 1), c
);
2788 printf_filtered ("Repeat count %d too large for buffer: ", c
);
2789 puts_filtered (buf
);
2790 puts_filtered ("\n");
2794 if (bp
< buf
+ PBUFSIZ
- 1)
2802 puts_filtered ("Remote packet too long: ");
2803 puts_filtered (buf
);
2804 puts_filtered ("\n");
2813 /* Read a packet from the remote machine, with error checking,
2814 and store it in BUF. BUF is expected to be of size PBUFSIZ.
2815 If FOREVER, wait forever rather than timing out; this is used
2816 while the target is executing user code. */
2819 getpkt (buf
, forever
)
2828 strcpy (buf
,"timeout");
2832 #ifdef MAINTENANCE_CMDS
2833 timeout
= watchdog
> 0 ? watchdog
: -1;
2840 timeout
= remote_timeout
;
2844 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
2846 /* This can loop forever if the remote side sends us characters
2847 continuously, but if it pauses, we'll get a zero from readchar
2848 because of timeout. Then we'll count that as a retry. */
2850 /* Note that we will only wait forever prior to the start of a packet.
2851 After that, we expect characters to arrive at a brisk pace. They
2852 should show up within remote_timeout intervals. */
2856 c
= readchar (timeout
);
2858 if (c
== SERIAL_TIMEOUT
)
2860 #ifdef MAINTENANCE_CMDS
2861 if (forever
) /* Watchdog went off. Kill the target. */
2863 target_mourn_inferior ();
2864 error ("Watchdog has expired. Target detached.\n");
2868 puts_filtered ("Timed out.\n");
2874 /* We've found the start of a packet, now collect the data. */
2876 val
= read_frame (buf
);
2881 fprintf_unfiltered (gdb_stdout
, "Packet received: %s\n", buf
);
2882 SERIAL_WRITE (remote_desc
, "+", 1);
2886 /* Try the whole thing again. */
2888 SERIAL_WRITE (remote_desc
, "-", 1);
2891 /* We have tried hard enough, and just can't receive the packet. Give up. */
2893 printf_unfiltered ("Ignoring packet error, continuing...\n");
2894 SERIAL_WRITE (remote_desc
, "+", 1);
2900 /* For some mysterious reason, wait_for_inferior calls kill instead of
2901 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
2905 target_mourn_inferior ();
2909 /* Use catch_errors so the user can quit from gdb even when we aren't on
2910 speaking terms with the remote system. */
2911 catch_errors (putpkt
, "k", "", RETURN_MASK_ERROR
);
2913 /* Don't wait for it to die. I'm not really sure it matters whether
2914 we do or not. For the existing stubs, kill is a noop. */
2915 target_mourn_inferior ();
2921 remote_mourn_1 (&remote_ops
);
2925 extended_remote_mourn ()
2927 /* We do _not_ want to mourn the target like this; this will
2928 remove the extended remote target from the target stack,
2929 and the next time the user says "run" it'll fail.
2931 FIXME: What is the right thing to do here? */
2933 remote_mourn_1 (&extended_remote_ops
);
2937 /* Worker function for remote_mourn. */
2939 remote_mourn_1 (target
)
2940 struct target_ops
*target
;
2942 unpush_target (target
);
2943 generic_mourn_inferior ();
2946 /* In the extended protocol we want to be able to do things like
2947 "run" and have them basically work as expected. So we need
2948 a special create_inferior function.
2950 FIXME: One day add support for changing the exec file
2951 we're debugging, arguments and an environment. */
2954 extended_remote_create_inferior (exec_file
, args
, env
)
2959 /* Rip out the breakpoints; we'll reinsert them after restarting
2960 the remote server. */
2961 remove_breakpoints ();
2963 /* Now restart the remote server. */
2964 extended_remote_restart ();
2966 /* Now put the breakpoints back in. This way we're safe if the
2967 restart function works via a unix fork on the remote side. */
2968 insert_breakpoints ();
2970 /* Clean up from the last time we were running. */
2971 clear_proceed_status ();
2973 /* Let the remote process run. */
2974 proceed (-1, TARGET_SIGNAL_0
, 0);
2978 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
2979 than other targets; in those use REMOTE_BREAKPOINT instead of just
2980 BREAKPOINT. Also, bi-endian targets may define LITTLE_REMOTE_BREAKPOINT
2981 and BIG_REMOTE_BREAKPOINT. If none of these are defined, we just call
2982 the standard routines that are in mem-break.c. */
2984 /* FIXME, these ought to be done in a more dynamic fashion. For instance,
2985 the choice of breakpoint instruction affects target program design and
2986 vice versa, and by making it user-tweakable, the special code here
2987 goes away and we need fewer special GDB configurations. */
2989 #if defined (LITTLE_REMOTE_BREAKPOINT) && defined (BIG_REMOTE_BREAKPOINT) && !defined(REMOTE_BREAKPOINT)
2990 #define REMOTE_BREAKPOINT
2993 #ifdef REMOTE_BREAKPOINT
2995 /* If the target isn't bi-endian, just pretend it is. */
2996 #if !defined (LITTLE_REMOTE_BREAKPOINT) && !defined (BIG_REMOTE_BREAKPOINT)
2997 #define LITTLE_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
2998 #define BIG_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
3001 static unsigned char big_break_insn
[] = BIG_REMOTE_BREAKPOINT
;
3002 static unsigned char little_break_insn
[] = LITTLE_REMOTE_BREAKPOINT
;
3004 #endif /* REMOTE_BREAKPOINT */
3006 /* Insert a breakpoint on targets that don't have any better breakpoint
3007 support. We read the contents of the target location and stash it,
3008 then overwrite it with a breakpoint instruction. ADDR is the target
3009 location in the target machine. CONTENTS_CACHE is a pointer to
3010 memory allocated for saving the target contents. It is guaranteed
3011 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
3012 is accomplished via BREAKPOINT_MAX). */
3015 remote_insert_breakpoint (addr
, contents_cache
)
3017 char *contents_cache
;
3019 #ifdef REMOTE_BREAKPOINT
3022 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
3026 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
3027 val
= target_write_memory (addr
, (char *) big_break_insn
,
3028 sizeof big_break_insn
);
3030 val
= target_write_memory (addr
, (char *) little_break_insn
,
3031 sizeof little_break_insn
);
3036 return memory_insert_breakpoint (addr
, contents_cache
);
3037 #endif /* REMOTE_BREAKPOINT */
3041 remote_remove_breakpoint (addr
, contents_cache
)
3043 char *contents_cache
;
3045 #ifdef REMOTE_BREAKPOINT
3046 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
3048 return memory_remove_breakpoint (addr
, contents_cache
);
3049 #endif /* REMOTE_BREAKPOINT */
3052 /* Some targets are only capable of doing downloads, and afterwards they switch
3053 to the remote serial protocol. This function provides a clean way to get
3054 from the download target to the remote target. It's basically just a
3055 wrapper so that we don't have to expose any of the internal workings of
3058 Prior to calling this routine, you should shutdown the current target code,
3059 else you will get the "A program is being debugged already..." message.
3060 Usually a call to pop_target() suffices.
3064 push_remote_target (name
, from_tty
)
3068 printf_filtered ("Switching to remote protocol\n");
3069 remote_open (name
, from_tty
);
3072 /* Other targets want to use the entire remote serial module but with
3073 certain remote_ops overridden. */
3076 open_remote_target (name
, from_tty
, target
, extended_p
)
3079 struct target_ops
*target
;
3082 printf_filtered ("Selecting the %sremote protocol\n",
3083 (extended_p
? "extended-" : ""));
3084 remote_open_1 (name
, from_tty
, target
, extended_p
);
3087 /* Table used by the crc32 function to calcuate the checksum. */
3088 static unsigned long crc32_table
[256] = {0, 0};
3090 static unsigned long
3091 crc32 (buf
, len
, crc
)
3096 if (! crc32_table
[1])
3098 /* Initialize the CRC table and the decoding table. */
3102 for (i
= 0; i
< 256; i
++)
3104 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
3105 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
3112 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
3118 /* compare-sections command
3120 With no arguments, compares each loadable section in the exec bfd
3121 with the same memory range on the target, and reports mismatches.
3122 Useful for verifying the image on the target against the exec file.
3123 Depends on the target understanding the new "qCRC:" request. */
3126 compare_sections_command (args
, from_tty
)
3131 unsigned long host_crc
, target_crc
;
3132 extern bfd
*exec_bfd
;
3133 struct cleanup
*old_chain
;
3134 char *tmp
, *sectdata
, *sectname
, buf
[PBUFSIZ
];
3141 error ("command cannot be used without an exec file");
3142 if (!current_target
.to_shortname
||
3143 strcmp (current_target
.to_shortname
, "remote") != 0)
3144 error ("command can only be used with remote target");
3146 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
3148 if (!(s
->flags
& SEC_LOAD
))
3149 continue; /* skip non-loadable section */
3151 size
= bfd_get_section_size_before_reloc (s
);
3153 continue; /* skip zero-length section */
3155 sectname
= (char *) bfd_get_section_name (exec_bfd
, s
);
3156 if (args
&& strcmp (args
, sectname
) != 0)
3157 continue; /* not the section selected by user */
3159 matched
= 1; /* do this section */
3161 /* FIXME: assumes lma can fit into long */
3162 sprintf (buf
, "qCRC:%lx,%lx", (long) lma
, (long) size
);
3165 /* be clever; compute the host_crc before waiting for target reply */
3166 sectdata
= xmalloc (size
);
3167 old_chain
= make_cleanup (free
, sectdata
);
3168 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
3169 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
3173 error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
3174 sectname
, lma
, lma
+ size
);
3176 error ("remote target does not support this operation");
3178 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
3179 target_crc
= target_crc
* 16 + fromhex (*tmp
);
3181 printf_filtered ("Section %s, range 0x%08x -- 0x%08x: ",
3182 sectname
, lma
, lma
+ size
);
3183 if (host_crc
== target_crc
)
3184 printf_filtered ("matched.\n");
3187 printf_filtered ("MIS-MATCHED!\n");
3191 do_cleanups (old_chain
);
3194 warning ("One or more sections of the remote executable does not match\n\
3195 the loaded file\n");
3196 if (args
&& !matched
)
3197 printf_filtered ("No loaded section named '%s'.\n", args
);
3201 packet_command (args
, from_tty
)
3208 error ("command can only be used with remote target");
3211 error ("remote-packet command requires packet text as argument");
3213 puts_filtered ("sending: ");
3214 print_packet (args
);
3215 puts_filtered ("\n");
3219 puts_filtered ("received: ");
3221 puts_filtered ("\n");
3227 remote_ops
.to_shortname
= "remote";
3228 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
3230 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
3231 Specify the serial device it is connected to (e.g. /dev/ttya).";
3232 remote_ops
.to_open
= remote_open
;
3233 remote_ops
.to_close
= remote_close
;
3234 remote_ops
.to_detach
= remote_detach
;
3235 remote_ops
.to_resume
= remote_resume
;
3236 remote_ops
.to_wait
= remote_wait
;
3237 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
3238 remote_ops
.to_store_registers
= remote_store_registers
;
3239 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
3240 remote_ops
.to_xfer_memory
= remote_xfer_memory
;
3241 remote_ops
.to_files_info
= remote_files_info
;
3242 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
3243 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
3244 remote_ops
.to_kill
= remote_kill
;
3245 remote_ops
.to_load
= generic_load
;
3246 remote_ops
.to_mourn_inferior
= remote_mourn
;
3247 remote_ops
.to_thread_alive
= remote_thread_alive
;
3248 remote_ops
.to_stop
= remote_stop
;
3249 remote_ops
.to_stratum
= process_stratum
;
3250 remote_ops
.to_has_all_memory
= 1;
3251 remote_ops
.to_has_memory
= 1;
3252 remote_ops
.to_has_stack
= 1;
3253 remote_ops
.to_has_registers
= 1;
3254 remote_ops
.to_has_execution
= 1;
3255 remote_ops
.to_magic
= OPS_MAGIC
;
3259 init_extended_remote_ops ()
3261 extended_remote_ops
= remote_ops
;
3263 extended_remote_ops
.to_shortname
= "extended-remote";
3264 extended_remote_ops
.to_longname
=
3265 "Extended remote serial target in gdb-specific protocol";
3266 extended_remote_ops
.to_doc
=
3267 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
3268 Specify the serial device it is connected to (e.g. /dev/ttya).",
3269 extended_remote_ops
.to_open
= extended_remote_open
;
3270 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
3271 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
3275 _initialize_remote ()
3278 add_target (&remote_ops
);
3280 init_extended_remote_ops ();
3281 add_target (&extended_remote_ops
);
3282 init_remote_threads();
3283 INIT_REMOTE_THREADTESTS
/* conditional thread packet unit test */
3285 add_cmd ("compare-sections", class_obscure
, compare_sections_command
,
3286 "Compare section data on target to the exec file.\n\
3287 Argument is a single section name (default: all loaded sections).",
3290 add_cmd ("packet", class_maintenance
, packet_command
,
3291 "Send an arbitrary packet to a remote target.\n\
3292 maintenance packet TEXT\n\
3293 If GDB is talking to an inferior via the GDB serial protocol, then\n\
3294 this command sends the string TEXT to the inferior, and displays the\n\
3295 response packet. GDB supplies the initial `$' character, and the\n\
3296 terminating `#' character and checksum.",
3300 (add_set_cmd ("remotetimeout", no_class
,
3301 var_integer
, (char *)&remote_timeout
,
3302 "Set timeout value for remote read.\n",
3307 (add_set_cmd ("remotebreak", no_class
,
3308 var_integer
, (char *)&remote_break
,
3309 "Set whether to send break if interrupted.\n",
3314 (add_set_cmd ("remotewritesize", no_class
,
3315 var_integer
, (char *)&remote_write_size
,
3316 "Set the maximum number of bytes per memory write packet.\n",
3322 remote_address_size
= TARGET_PTR_BIT
;
3324 (add_set_cmd ("remoteaddresssize", class_obscure
,
3325 var_integer
, (char *)&remote_address_size
,
3326 "Set the maximum size of the address (in bits) \
3327 in a memory packet.\n",