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 /* Define the target subroutine names */
307 void open_remote_target
PARAMS ((char *, int, struct target_ops
*, int));
309 void _initialize_remote
PARAMS ((void));
313 static struct target_ops remote_ops
;
315 static struct target_ops extended_remote_ops
;
317 /* This was 5 seconds, which is a long time to sit and wait.
318 Unless this is going though some terminal server or multiplexer or
319 other form of hairy serial connection, I would think 2 seconds would
322 /* Changed to allow option to set timeout value.
323 was static int remote_timeout = 2; */
324 extern int remote_timeout
;
326 /* This variable chooses whether to send a ^C or a break when the user
327 requests program interruption. Although ^C is usually what remote
328 systems expect, and that is the default here, sometimes a break is
329 preferable instead. */
331 static int remote_break
;
333 /* Has the user attempted to interrupt the target? If so, then offer
334 the user the opportunity to bail out completely if he interrupts
336 static int interrupted_already
= 0;
338 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
339 remote_open knows that we don't have a file open when the program
341 static serial_t remote_desc
= NULL
;
343 /* Having this larger than 400 causes us to be incompatible with m68k-stub.c
344 and i386-stub.c. Normally, no one would notice because it only matters
345 for writing large chunks of memory (e.g. in downloads). Also, this needs
346 to be more than 400 if required to hold the registers (see below, where
347 we round it up based on REGISTER_BYTES). */
350 /* Maximum number of bytes to read/write at once. The value here
351 is chosen to fill up a packet (the headers account for the 32). */
352 #define MAXBUFBYTES ((PBUFSIZ-32)/2)
354 /* Round up PBUFSIZ to hold all the registers, at least. */
355 /* The blank line after the #if seems to be required to work around a
356 bug in HP's PA compiler. */
357 #if REGISTER_BYTES > MAXBUFBYTES
360 #define PBUFSIZ (REGISTER_BYTES * 2 + 32)
364 /* This variable sets the number of bytes to be written to the target
365 in a single packet. Normally PBUFSIZ is satisfactory, but some
366 targets need smaller values (perhaps because the receiving end
369 static int remote_write_size
= PBUFSIZ
;
371 /* This variable sets the number of bits in an address that are to be
372 sent in a memory ("M" or "m") packet. Normally, after stripping
373 leading zeros, the entire address would be sent. This variable
374 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
375 initial implementation of remote.c restricted the address sent in
376 memory packets to ``host::sizeof long'' bytes - (typically 32
377 bits). Consequently, for 64 bit targets, the upper 32 bits of an
378 address was never sent. Since fixing this bug may cause a break in
379 some remote targets this variable is principly provided to
380 facilitate backward compatibility. */
382 static int remote_address_size
;
384 /* This is the size (in chars) of the first response to the `g' command. This
385 is used to limit the size of the memory read and write commands to prevent
386 stub buffers from overflowing. The size does not include headers and
387 trailers, it is only the payload size. */
389 static int remote_register_buf_size
= 0;
391 /* Should we try the 'P' request? If this is set to one when the stub
392 doesn't support 'P', the only consequence is some unnecessary traffic. */
393 static int stub_supports_P
= 1;
395 /* These are pointers to hook functions that may be set in order to
396 modify resume/wait behavior for a particular architecture. */
398 void (*target_resume_hook
) PARAMS ((void));
399 void (*target_wait_loop_hook
) PARAMS ((void));
402 /* ------- REMOTE Thread (or) Process support ----------------------- */
407 stub_unpack_int
PARAMS ((char *buff
, int fieldlength
));
410 unpack_varlen_hex
PARAMS ((char *buff
, int *result
));
414 unpack_nibble
PARAMS ((char *buf
, int *val
));
417 unpack_nibble
PARAMS ((char *buf
, int *val
));
420 pack_hex_byte
PARAMS ((char *pkt
, unsigned char byte
));
423 unpack_byte
PARAMS ((char *buf
, int *value
));
426 pack_int
PARAMS ((char *buf
, int value
));
429 unpack_int
PARAMS ((char *buf
, int *value
));
432 pack_string
PARAMS ((char *pkt
, char *string
));
435 unpack_string
PARAMS ((char *src
, char *dest
, int length
));
438 pack_threadid
PARAMS ((char *pkt
, threadref
* id
));
441 unpack_threadid
PARAMS ((char *inbuf
, threadref
* id
));
444 int_to_threadref
PARAMS ((threadref
* id
, int value
));
448 threadref_to_int
PARAMS ((threadref
* ref
));
451 copy_threadref
PARAMS ((threadref
* dest
, threadref
* src
));
454 threadmatch
PARAMS ((threadref
* dest
, threadref
* src
));
458 pack_threadinfo_request
PARAMS ((char *pkt
,
463 remote_unpack_thread_info_response
PARAMS ((
465 threadref
* expectedref
,
466 struct gdb_ext_thread_info
* info
));
470 remote_get_threadinfo
PARAMS ((
471 threadref
* threadid
,
472 int fieldset
, /* TAG mask */
473 struct gdb_ext_thread_info
* info
));
476 adapt_remote_get_threadinfo
PARAMS ((
479 struct gdb_ext_thread_info
* info
));
481 pack_threadlist_request
PARAMS ((
485 threadref
* nextthread
));
488 parse_threadlist_response
PARAMS ((
491 threadref
* original_echo
,
492 threadref
* resultlist
,
495 remote_get_threadlist
PARAMS ((
497 threadref
* nextthread
,
501 threadref
* threadlist
));
506 remote_newthread_step
PARAMS ((
511 remote_find_new_threads
PARAMS ((void)) ;
514 threadalive_test
PARAMS ((char *cmd
, int tty
));
518 threadset_test_cmd
PARAMS ((char *cmd
, int tty
));
521 threadlist_test_cmd
PARAMS ((char *cmd
,
525 display_thread_info
PARAMS ((struct gdb_ext_thread_info
* info
));
529 get_and_display_threadinfo
PARAMS ((threadref
* ref
));
533 threadinfo_test_cmd
PARAMS ((char *cmd
,
537 thread_display_step
PARAMS ((
543 threadlist_update_test_cmd
PARAMS ((char *cmd
,
548 init_remote_threadtests
PARAMS ((void));
550 /* These are the threads which we last sent to the remote system. -1 for all
551 or -2 for not sent yet. */
555 /* Call this function as a result of
556 1) A halt indication (T packet) containing a thread id
557 2) A direct query of currthread
558 3) Successful execution of set thread
562 record_currthread (currthread
)
565 inferior_pid
= currthread
;
566 general_thread
= currthread
;
567 cont_thread
= currthread
;
576 int state
= gen
? general_thread
: cont_thread
;
580 buf
[1] = gen
? 'g' : 'c';
587 sprintf (&buf
[2], "-%x", -th
);
589 sprintf (&buf
[2], "%x", th
);
598 /* Return nonzero if the thread TH is still alive on the remote system. */
601 remote_thread_alive (th
)
608 sprintf (&buf
[1], "-%08x", -th
);
610 sprintf (&buf
[1], "%08x", th
);
613 return (buf
[0] == 'O' && buf
[1] == 'K');
617 About these extended threadlist and threadinfo packets.
618 They are variable length packets but, the fields within them
619 are often fixed length.
620 They are redundent enough to send over UDP as is the remote protocol
622 There is a matching unit test module in libstub.
626 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
627 /* encode 64 bits in 16 chars of hex */
630 static const char hexchars
[] = "0123456789abcdef";
637 if ((ch
>= 'a') && (ch
<= 'f'))
639 *val
= ch
- 'a' + 10;
642 if ((ch
>= 'A') && (ch
<= 'F'))
644 *val
= ch
- 'A' + 10;
647 if ((ch
>= '0') && (ch
<= '9'))
659 if (ch
>= 'a' && ch
<= 'f')
660 return ch
- 'a' + 10;
661 if (ch
>= '0' && ch
<= '9')
663 if (ch
>= 'A' && ch
<= 'F')
664 return ch
- 'A' + 10;
669 stub_unpack_int (buff
, fieldlength
)
677 nibble
= stubhex (*buff
++);
681 retval
= retval
<< 4;
687 unpack_varlen_hex (buff
, result
)
688 char *buff
; /* packet to parse */
695 while (ishex (*buff
, &nibble
))
698 retval
= retval
<< 4;
699 retval
|= nibble
& 0x0f;
706 unpack_nibble (buf
, val
)
716 pack_nibble (buf
, nibble
)
721 *buf
++ = hexchars
[(nibble
& 0x0f)];
726 pack_hex_byte (pkt
, byte
)
730 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
731 *pkt
++ = hexchars
[(byte
& 0xf)];
736 unpack_byte (buf
, value
)
740 *value
= stub_unpack_int (buf
, 2);
746 pack_int (buf
, value
)
750 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
751 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
752 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
753 buf
= pack_hex_byte (buf
, (value
& 0xff));
759 unpack_int (buf
, value
)
763 *value
= stub_unpack_int (buf
, 8);
769 pack_string (pkt
, string
)
775 len
= strlen (string
);
777 len
= 200; /* Bigger than most GDB packets, junk??? */
778 pkt
= pack_hex_byte (pkt
, len
);
782 if ((ch
== '\0') || (ch
== '#'))
783 ch
= '*'; /* Protect encapsulation */
790 unpack_string (src
, dest
, length
)
802 pack_threadid (pkt
, id
)
807 unsigned char *altid
;
808 altid
= (unsigned char *) id
;
809 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
811 pkt
= pack_hex_byte (pkt
, *altid
++);
817 unpack_threadid (inbuf
, id
)
822 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
824 altref
= (char *) id
;
826 while (inbuf
< limit
)
828 x
= stubhex (*inbuf
++);
829 y
= stubhex (*inbuf
++);
830 *altref
++ = (x
<< 4) | y
;
835 /* Externally, threadrefs are 64 bits but internally, they are still
836 ints. This is due to a mismatch of specifications.
837 We would like to use 64bit thread references internally.
838 This is an adapter function.
842 int_to_threadref (id
, value
)
847 scan
= (unsigned char *) id
;
853 *scan
++ = (value
>> 24) & 0xff;
854 *scan
++ = (value
>> 16) & 0xff;
855 *scan
++ = (value
>> 8) & 0xff;
856 *scan
++ = (value
& 0xff);
860 threadref_to_int (ref
)
871 value
= (value
<< 8) | ((*scan
++) & 0xff);
876 copy_threadref (dest
, src
)
881 unsigned char *csrc
, *cdest
;
882 csrc
= (unsigned char *) src
;
883 cdest
= (unsigned char *) dest
;
892 threadmatch (dest
, src
)
896 /* things are broken right now, so just assume we got a match */
898 unsigned char *srcp
, *destp
;
901 destp
= (char *) dest
;
905 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
912 #define PKT_TRACE(title,packet) { printf_filtered("%s %s\n", title, packet);}
914 #define PKT_TRACE(a,b) {}
918 /* ----- PACK_THREAD_INFO_REQUEST -------------------------------- */
921 threadid:1, # always request threadid
928 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
931 pack_threadinfo_request
PARAMS ((char *pkt
,
936 pack_threadinfo_request (pkt
, mode
, id
)
942 *pkt
++ = 'q'; /* Info Query */
943 *pkt
++ = 'P'; /* process or thread info */
944 pkt
= pack_int (pkt
, mode
); /* mode */
945 pkt
= pack_threadid (pkt
, id
); /* threadid */
946 *pkt
= '\0'; /* terminate */
947 PKT_TRACE ("threadinfo-req ", base
);
952 /* These values tag the fields in a thread info response packet */
953 /* Tagging the fields allows us to request specific fields and to
954 add more fields as time goes by */
955 #define TAG_THREADID 1 /* Echo the thread identifier */
956 #define TAG_EXISTS 2 /* It this process defined enough to
957 fetch registers and its stack */
958 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
959 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
960 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about the process*/
964 remote_unpack_thread_info_response (pkt
, expectedref
, info
)
966 threadref
*expectedref
;
967 struct gdb_ext_thread_info
*info
;
972 char *limit
= pkt
+ PBUFSIZ
; /* plausable parsing limit */
975 PKT_TRACE ("unpack-threadinfo ", pkt
);
977 /* info->threadid = 0; FIXME: implement zero_threadref */
979 info
->display
[0] = '\0';
980 info
->shortname
[0] = '\0';
981 info
->more_display
[0] = '\0';
983 /* Assume the characters indicating the packet type have been stripped */
984 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
985 pkt
= unpack_threadid (pkt
, &ref
);
988 warning("Incomplete response to threadinfo request\n");
989 if (!threadmatch (&ref
, expectedref
))
990 { /* This is an answer to a different request */
991 warning("ERROR RMT Thread info mismatch\n");
994 copy_threadref (&info
->threadid
, &ref
);
996 /* Loop on tagged fields , try to bail if somthing goes wrong */
998 while ((pkt
< limit
) && mask
&& *pkt
) /* packets are terminated with nulls */
1000 pkt
= unpack_int (pkt
, &tag
); /* tag */
1001 pkt
= unpack_byte (pkt
, &length
); /* length */
1002 if (!(tag
& mask
)) /* tags out of synch with mask */
1004 warning ("ERROR RMT: threadinfo tag mismatch\n");
1008 if (tag
== TAG_THREADID
)
1012 warning ("ERROR RMT: length of threadid is not 16\n");
1016 pkt
= unpack_threadid (pkt
, &ref
);
1017 mask
= mask
& ~TAG_THREADID
;
1020 if (tag
== TAG_EXISTS
)
1022 info
->active
= stub_unpack_int (pkt
, length
);
1024 mask
= mask
& ~(TAG_EXISTS
);
1027 warning ("ERROR RMT: 'exists' length too long\n");
1033 if (tag
== TAG_THREADNAME
)
1035 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
1036 mask
= mask
& ~TAG_THREADNAME
;
1039 if (tag
== TAG_DISPLAY
)
1041 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
1042 mask
= mask
& ~TAG_DISPLAY
;
1045 if (tag
== TAG_MOREDISPLAY
)
1047 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
1048 mask
= mask
& ~TAG_MOREDISPLAY
;
1051 warning ("ERROR RMT: unknown thread info tag\n");
1052 break; /* Not a tag we know about */
1058 /* ------ REMOTE_GET_THREADINFO -------------------------------------- */
1061 remote_get_threadinfo (threadid
, fieldset
, info
)
1062 threadref
*threadid
;
1063 int fieldset
; /* TAG mask */
1064 struct gdb_ext_thread_info
*info
;
1067 char threadinfo_pkt
[PBUFSIZ
];
1068 pack_threadinfo_request (threadinfo_pkt
, fieldset
, threadid
);
1069 putpkt (threadinfo_pkt
);
1070 getpkt (threadinfo_pkt
, 0);
1071 result
= remote_unpack_thread_info_response (threadinfo_pkt
+ 2, threadid
, info
);
1075 /* ------- ADAPT_remote_GET_THREADINFO - */
1076 /* Unfortunatly, 61 but thread-ids are bugger than the internal
1077 representation of a threadid. */
1081 adapt_remote_get_threadinfo (ref
, selection
, info
)
1084 struct gdb_ext_thread_info
*info
;
1087 int_to_threadref (&lclref
, *ref
);
1088 return remote_get_threadinfo (&lclref
, selection
, info
);
1092 /* -------- PACK_THREADLIST-REQUEST --------------------------------- */
1093 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1096 pack_threadlist_request (pkt
, startflag
, threadcount
, nextthread
)
1100 threadref
*nextthread
;
1102 *pkt
++ = 'q'; /* info query packet */
1103 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
1104 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
1105 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
1106 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
1112 /* ---------- PARSE_THREADLIST_RESPONSE ------------------------------------ */
1113 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1117 parse_threadlist_response (pkt
, result_limit
, original_echo
,
1118 resultlist
, doneflag
)
1121 threadref
*original_echo
;
1122 threadref
*resultlist
;
1126 int count
, resultcount
, done
;
1129 /* assume the 'q' and 'M chars have been stripped */
1130 PKT_TRACE ("parse-threadlist-response ", pkt
);
1131 limit
= pkt
+ (PBUFSIZ
- BUF_THREAD_ID_SIZE
); /* done parse past here */
1132 pkt
= unpack_byte (pkt
, &count
); /* count field */
1133 pkt
= unpack_nibble (pkt
, &done
);
1134 /* The first threadid is the argument threadid */
1135 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
1136 while ((count
-- > 0) && (pkt
< limit
))
1138 pkt
= unpack_threadid (pkt
, resultlist
++);
1139 if (resultcount
++ >= result_limit
)
1144 return resultcount
; /* successvalue */
1150 remote_get_threadlist (startflag
, nextthread
, result_limit
,
1151 done
, result_count
, threadlist
)
1153 threadref
*nextthread
;
1157 threadref
*threadlist
;
1160 static threadref echo_nextthread
;
1161 char threadlist_packet
[PBUFSIZ
];
1162 char t_response
[PBUFSIZ
];
1165 /* Trancate result limit to be smaller than the packet size */
1166 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10) >= PBUFSIZ
)
1167 result_limit
= (PBUFSIZ
/ BUF_THREAD_ID_SIZE
) - 2;
1169 pack_threadlist_request (threadlist_packet
,
1170 startflag
, result_limit
, nextthread
);
1171 putpkt (threadlist_packet
);
1172 getpkt (t_response
, 0);
1173 *result_count
= parse_threadlist_response (
1174 t_response
+ 2, /* strip header */
1179 if (!threadmatch (&echo_nextthread
, nextthread
))
1181 /* FIXME: This is a good reason to drop the packet */
1182 /* Possably, there is a duplicate response */
1184 retransmit immediatly - race conditions
1185 retransmit after timeout - yes
1187 wait for packet, then exit
1189 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1190 return 0; /* I choose simply exiting */
1192 if (*result_count
<= 0)
1196 warning ("RMT ERROR : failed to get remote thread list\n");
1199 return result
; /* break; */
1201 if (*result_count
> result_limit
)
1204 warning ("RMT ERROR: threadlist response longer than requested\n");
1212 /* This is the interface between remote and threads, remotes upper interface */
1213 /* remote_find_new_threads retreives the thread list and for each
1214 thread in the list, looks up the thread in GDB's internal list,
1215 ading the thread if it does not already exist.
1216 This involves getting partial thread lists from the remote target so,
1217 polling the quit_flag is required.
1220 typedef int (*rmt_thread_action
) (
1225 #define MAXTHREADLISTRESULTS 32 /* About this many threadisds fit in a packet */
1228 remote_threadlist_iterator
PARAMS ((
1229 rmt_thread_action stepfunction
,
1234 remote_threadlist_iterator (stepfunction
, context
, looplimit
)
1235 rmt_thread_action stepfunction
;
1239 int done
, i
, result_count
;
1243 static threadref nextthread
;
1244 static threadref echo_nextthread
;
1245 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
1250 if (loopcount
++ > looplimit
)
1253 warning ("Remote fetch threadlist -infinite loop-\n");
1256 if (!remote_get_threadlist (startflag
,
1258 MAXTHREADLISTRESULTS
,
1266 startflag
= 0; /* clear for later iterations */
1267 /* Setup to resume next batch of thread references , set nestthread */
1268 if (result_count
>= 1)
1269 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
1270 /* output_threadid("last-of-batch",&nextthread); */
1272 while (result_count
--)
1273 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
1281 remote_newthread_step (ref
, context
)
1288 pid
= threadref_to_int (ref
);
1289 if (!in_thread_list (pid
))
1291 return 1; /* continue iterator */
1294 #define CRAZY_MAX_THREADS 1000
1298 remote_find_new_threads (void)
1300 return remote_threadlist_iterator (remote_newthread_step
, 0, CRAZY_MAX_THREADS
);
1301 } /* remote_find_new_threads */
1304 remote_update_threads ()
1306 /* Right now, this is empty. But it is one of the functions
1307 defined for the thread target vector so it gets called.
1308 If we were to allow the modification of the registers of
1309 a suspended process, this would be implemented. */
1313 static struct target_thread_vector remote_thread_vec
;
1315 /* Initialize the thread vector which is used by threads.c */
1316 /* The thread stubb is a package, it has an initializer */
1317 void init_remote_threads ()
1319 remote_thread_vec
.find_new_threads
= remote_find_new_threads
;
1320 remote_thread_vec
.get_thread_info
= adapt_remote_get_threadinfo
;
1323 /* --------- UNIT_TEST for THREAD oriented PACKETS -------------------------- */
1325 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
1329 threadset_test_cmd (cmd
, tty
)
1333 int sample_thread
= SAMPLE_THREAD
;
1334 printf_filtered ("Remote threadset test\n");
1335 set_thread (sample_thread
, 1);
1340 threadalive_test (cmd
, tty
)
1344 int sample_thread
= SAMPLE_THREAD
;
1345 if (remote_thread_alive (sample_thread
))
1346 printf_filtered ("PASS: Thread alive test\n");
1348 printf_filtered ("FAIL: Thread alive test\n");
1352 output_threadid
PARAMS ((char *title
, threadref
* ref
));
1355 output_threadid (title
, ref
)
1360 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex */
1362 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
1367 threadlist_test_cmd (cmd
, tty
)
1372 threadref nextthread
;
1373 int done
, result_count
;
1374 threadref threadlist
[3];
1376 printf_filtered ("Remote Threadlist test\n");
1377 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
1378 &result_count
, &threadlist
[0]))
1379 printf_filtered ("FAIL: threadlist test\n");
1382 threadref
*scan
= threadlist
;
1383 threadref
*limit
= scan
+ result_count
;
1384 while (scan
< limit
)
1385 output_threadid (" thread ", scan
++);
1390 display_thread_info (info
)
1391 struct gdb_ext_thread_info
*info
;
1394 output_threadid ("Threadid: ", &info
->threadid
);
1396 printf_filtered ("Name: %s\n ", info
->shortname
);
1397 /* format display state */
1398 printf_filtered ("State: %s\n", info
->display
);
1399 /* additional data */
1400 printf_filtered ("other: %s\n\n", info
->more_display
);
1404 get_and_display_threadinfo (ref
)
1409 struct gdb_ext_thread_info threadinfo
;
1411 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
1412 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
1413 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
1414 display_thread_info (&threadinfo
);
1419 threadinfo_test_cmd (cmd
, tty
)
1423 int athread
= SAMPLE_THREAD
;
1427 int_to_threadref (&thread
, athread
);
1428 printf_filtered ("Remote Threadinfo test\n");
1429 if (!get_and_display_threadinfo (&thread
))
1430 printf_filtered ("FAIL cannot get thread info\n");
1435 thread_display_step (ref
, context
)
1439 /* output_threadid(" threadstep ",ref); *//* simple test */
1440 return get_and_display_threadinfo (ref
);
1445 threadlist_update_test_cmd (cmd
, tty
)
1449 printf_filtered ("Remote Threadlist update test\n");
1450 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
1454 init_remote_threadtests (void)
1456 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
1457 "Fetch and print the remote list of thread identifiers, one pkt only");
1458 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
1459 "Fetch and display info about one thread");
1460 add_com ("tset", class_obscure
, threadset_test_cmd
,
1461 "Test setting to a different thread");
1462 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
1463 "Iterate through updating all remote thread info");
1464 add_com ("talive", class_obscure
, threadalive_test
,
1465 " Remote thread alive test ");
1468 #define INIT_REMOTE_THREADTESTS { init_remote_threadtests();}
1469 /* END OF REMOTE THREAD UNIT TESTS */
1472 /* Restart the remote side; this is an extended protocol operation. */
1475 extended_remote_restart ()
1479 /* Send the restart command; for reasons I don't understand the
1480 remote side really expects a number after the "R". */
1482 sprintf (&buf
[1], "%x", 0);
1485 /* Now query for status so this looks just like we restarted
1486 gdbserver from scratch. */
1491 /* Clean up connection to a remote debugger. */
1495 remote_close (quitting
)
1499 SERIAL_CLOSE (remote_desc
);
1503 /* Query the remote side for the text, data and bss offsets. */
1508 char buf
[PBUFSIZ
], *ptr
;
1510 CORE_ADDR text_addr
, data_addr
, bss_addr
;
1511 struct section_offsets
*offs
;
1513 putpkt ("qOffsets");
1517 if (buf
[0] == '\000')
1518 return; /* Return silently. Stub doesn't support this
1522 warning ("Remote failure reply: %s", buf
);
1526 /* Pick up each field in turn. This used to be done with scanf, but
1527 scanf will make trouble if CORE_ADDR size doesn't match
1528 conversion directives correctly. The following code will work
1529 with any size of CORE_ADDR. */
1530 text_addr
= data_addr
= bss_addr
= 0;
1534 if (strncmp (ptr
, "Text=", 5) == 0)
1537 /* Don't use strtol, could lose on big values. */
1538 while (*ptr
&& *ptr
!= ';')
1539 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
1544 if (!lose
&& strncmp (ptr
, ";Data=", 6) == 0)
1547 while (*ptr
&& *ptr
!= ';')
1548 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
1553 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
1556 while (*ptr
&& *ptr
!= ';')
1557 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
1563 error ("Malformed response to offset query, %s", buf
);
1565 if (symfile_objfile
== NULL
)
1568 offs
= (struct section_offsets
*) alloca (sizeof (struct section_offsets
)
1569 + symfile_objfile
->num_sections
1570 * sizeof (offs
->offsets
));
1571 memcpy (offs
, symfile_objfile
->section_offsets
,
1572 sizeof (struct section_offsets
)
1573 + symfile_objfile
->num_sections
1574 * sizeof (offs
->offsets
));
1576 ANOFFSET (offs
, SECT_OFF_TEXT
) = text_addr
;
1578 /* This is a temporary kludge to force data and bss to use the same offsets
1579 because that's what nlmconv does now. The real solution requires changes
1580 to the stub and remote.c that I don't have time to do right now. */
1582 ANOFFSET (offs
, SECT_OFF_DATA
) = data_addr
;
1583 ANOFFSET (offs
, SECT_OFF_BSS
) = data_addr
;
1585 objfile_relocate (symfile_objfile
, offs
);
1588 /* Stub for catch_errors. */
1591 remote_start_remote (dummy
)
1594 immediate_quit
= 1; /* Allow user to interrupt it */
1596 /* Ack any packet which the remote side has already sent. */
1597 SERIAL_WRITE (remote_desc
, "+", 1);
1599 /* Let the stub know that we want it to return the thread. */
1602 get_offsets (); /* Get text, data & bss offsets */
1604 putpkt ("?"); /* initiate a query from remote machine */
1607 start_remote (); /* Initialize gdb process mechanisms */
1611 /* Open a connection to a remote debugger.
1612 NAME is the filename used for communication. */
1615 remote_open (name
, from_tty
)
1619 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
1622 /* Open a connection to a remote debugger using the extended
1623 remote gdb protocol. NAME is the filename used for communication. */
1626 extended_remote_open (name
, from_tty
)
1630 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1/*extended_p*/);
1633 /* Generic code for opening a connection to a remote target. */
1634 static DCACHE
*remote_dcache
;
1637 remote_open_1 (name
, from_tty
, target
, extended_p
)
1640 struct target_ops
*target
;
1644 error ("To open a remote debug connection, you need to specify what serial\n\
1645 device is attached to the remote system (e.g. /dev/ttya).");
1647 target_preopen (from_tty
);
1649 unpush_target (target
);
1651 remote_dcache
= dcache_init (remote_read_bytes
, remote_write_bytes
);
1653 remote_desc
= SERIAL_OPEN (name
);
1655 perror_with_name (name
);
1657 if (baud_rate
!= -1)
1659 if (SERIAL_SETBAUDRATE (remote_desc
, baud_rate
))
1661 SERIAL_CLOSE (remote_desc
);
1662 perror_with_name (name
);
1667 SERIAL_RAW (remote_desc
);
1669 /* If there is something sitting in the buffer we might take it as a
1670 response to a command, which would be bad. */
1671 SERIAL_FLUSH_INPUT (remote_desc
);
1675 puts_filtered ("Remote debugging using ");
1676 puts_filtered (name
);
1677 puts_filtered ("\n");
1679 push_target (target
); /* Switch to using remote target now */
1680 /* The target vector does not have the thread functions in it yet,
1681 so we use this function to call back into the thread module and
1682 register the thread vector and its contained functions. */
1683 bind_target_thread_vector(&remote_thread_vec
);
1684 /* Start out by trying the 'P' request to set registers. We set this each
1685 time that we open a new target so that if the user switches from one
1686 stub to another, we can (if the target is closed and reopened) cope. */
1687 stub_supports_P
= 1;
1689 general_thread
= -2;
1692 /* Without this, some commands which require an active target (such as kill)
1693 won't work. This variable serves (at least) double duty as both the pid
1694 of the target process (if it has such), and as a flag indicating that a
1695 target is active. These functions should be split out into seperate
1696 variables, especially since GDB will someday have a notion of debugging
1697 several processes. */
1699 inferior_pid
= 42000;
1700 /* Start the remote connection; if error (0), discard this target.
1701 In particular, if the user quits, be sure to discard it
1702 (we'd be in an inconsistent state otherwise). */
1703 if (!catch_errors (remote_start_remote
, (char *)0,
1704 "Couldn't establish connection to remote target\n", RETURN_MASK_ALL
))
1712 /* tell the remote that we're using the extended protocol. */
1719 /* This takes a program previously attached to and detaches it. After
1720 this is done, GDB can be used to debug some other program. We
1721 better not have left any breakpoints in the target program or it'll
1722 die when it hits one. */
1725 remote_detach (args
, from_tty
)
1732 error ("Argument given to \"detach\" when remotely debugging.");
1734 /* Tell the remote target to detach. */
1740 puts_filtered ("Ending remote debugging.\n");
1743 /* Convert hex digit A to a number. */
1749 if (a
>= '0' && a
<= '9')
1751 else if (a
>= 'a' && a
<= 'f')
1752 return a
- 'a' + 10;
1753 else if (a
>= 'A' && a
<= 'F')
1754 return a
- 'A' + 10;
1756 error ("Reply contains invalid hex digit %d", a
);
1759 /* Convert number NIB to a hex digit. */
1771 /* Tell the remote machine to resume. */
1773 static enum target_signal last_sent_signal
= TARGET_SIGNAL_0
;
1777 remote_resume (pid
, step
, siggnal
)
1779 enum target_signal siggnal
;
1784 set_thread (inferior_pid
, 0);
1786 set_thread (pid
, 0);
1788 dcache_flush (remote_dcache
);
1790 last_sent_signal
= siggnal
;
1791 last_sent_step
= step
;
1793 /* A hook for when we need to do something at the last moment before
1795 if (target_resume_hook
)
1796 (*target_resume_hook
) ();
1798 if (siggnal
!= TARGET_SIGNAL_0
)
1800 buf
[0] = step
? 'S' : 'C';
1801 buf
[1] = tohex (((int)siggnal
>> 4) & 0xf);
1802 buf
[2] = tohex ((int)siggnal
& 0xf);
1806 strcpy (buf
, step
? "s": "c");
1811 /* Send ^C to target to halt it. Target will respond, and send us a
1813 static void (*ofunc
) PARAMS ((int));
1816 remote_interrupt (signo
)
1820 signal (signo
, remote_interrupt
);
1826 if (!interrupted_already
)
1828 /* Send a break or a ^C, depending on user preference. */
1829 interrupted_already
= 1;
1832 printf_unfiltered ("remote_stop called\n");
1835 SERIAL_SEND_BREAK (remote_desc
);
1837 SERIAL_WRITE (remote_desc
, "\003", 1);
1841 signal (SIGINT
, ofunc
);
1843 signal (SIGINT
, remote_interrupt
);
1844 interrupted_already
= 0;
1848 /* Ask the user what to do when an interrupt is received. */
1853 target_terminal_ours ();
1855 if (query ("Interrupted while waiting for the program.\n\
1856 Give up (and stop debugging it)? "))
1858 target_mourn_inferior ();
1859 return_to_top_level (RETURN_QUIT
);
1862 target_terminal_inferior ();
1865 /* If nonzero, ignore the next kill. */
1869 remote_console_output (msg
)
1874 for (p
= msg
; *p
; p
+=2)
1877 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
1880 if (target_output_hook
)
1881 target_output_hook (tb
);
1883 fputs_filtered (tb
, gdb_stdout
);
1887 /* Wait until the remote machine stops, then return,
1888 storing status in STATUS just as `wait' would.
1889 Returns "pid" (though it's not clear what, if anything, that
1890 means in the case of this target). */
1893 remote_wait (pid
, status
)
1895 struct target_waitstatus
*status
;
1897 unsigned char buf
[PBUFSIZ
];
1898 int thread_num
= -1;
1900 status
->kind
= TARGET_WAITKIND_EXITED
;
1901 status
->value
.integer
= 0;
1907 interrupted_already
= 0;
1908 ofunc
= signal (SIGINT
, remote_interrupt
);
1909 getpkt ((char *) buf
, 1);
1910 signal (SIGINT
, ofunc
);
1912 /* This is a hook for when we need to do something (perhaps the
1913 collection of trace data) every time the target stops. */
1914 if (target_wait_loop_hook
)
1915 (*target_wait_loop_hook
) ();
1919 case 'E': /* Error of some sort */
1920 warning ("Remote failure reply: %s", buf
);
1922 case 'T': /* Status with PC, SP, FP, ... */
1926 char regs
[MAX_REGISTER_RAW_SIZE
];
1928 /* Expedited reply, containing Signal, {regno, reg} repeat */
1929 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
1931 n... = register number
1932 r... = register contents
1934 p
= &buf
[3]; /* after Txx */
1941 regno
= strtol ((const char *) p
, &p_temp
, 16); /* Read the register number */
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 at
2200 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 addresses,
2337 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 only part
2429 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
, len
, should_write
);
2469 /* Enable after 4.12. */
2472 remote_search (len
, data
, mask
, startaddr
, increment
, lorange
, hirange
2473 addr_found
, data_found
)
2477 CORE_ADDR startaddr
;
2481 CORE_ADDR
*addr_found
;
2484 if (increment
== -4 && len
== 4)
2486 long mask_long
, data_long
;
2487 long data_found_long
;
2488 CORE_ADDR addr_we_found
;
2490 long returned_long
[2];
2493 mask_long
= extract_unsigned_integer (mask
, len
);
2494 data_long
= extract_unsigned_integer (data
, len
);
2495 sprintf (buf
, "t%x:%x,%x", startaddr
, data_long
, mask_long
);
2500 /* The stub doesn't support the 't' request. We might want to
2501 remember this fact, but on the other hand the stub could be
2502 switched on us. Maybe we should remember it only until
2503 the next "target remote". */
2504 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
2505 hirange
, addr_found
, data_found
);
2510 /* There is no correspondance between what the remote protocol uses
2511 for errors and errno codes. We would like a cleaner way of
2512 representing errors (big enough to include errno codes, bfd_error
2513 codes, and others). But for now just use EIO. */
2514 memory_error (EIO
, startaddr
);
2517 while (*p
!= '\0' && *p
!= ',')
2518 addr_we_found
= (addr_we_found
<< 4) + fromhex (*p
++);
2520 error ("Protocol error: short return for search");
2522 data_found_long
= 0;
2523 while (*p
!= '\0' && *p
!= ',')
2524 data_found_long
= (data_found_long
<< 4) + fromhex (*p
++);
2525 /* Ignore anything after this comma, for future extensions. */
2527 if (addr_we_found
< lorange
|| addr_we_found
>= hirange
)
2533 *addr_found
= addr_we_found
;
2534 *data_found
= store_unsigned_integer (data_we_found
, len
);
2537 generic_search (len
, data
, mask
, startaddr
, increment
, lorange
,
2538 hirange
, addr_found
, data_found
);
2543 remote_files_info (ignore
)
2544 struct target_ops
*ignore
;
2546 puts_filtered ("Debugging a target over a serial line.\n");
2549 /* Stuff for dealing with the packets which are part of this protocol.
2550 See comment at top of file for details. */
2552 /* Read a single character from the remote end, masking it down to 7 bits. */
2560 ch
= SERIAL_READCHAR (remote_desc
, timeout
);
2565 error ("Remote connection closed");
2567 perror_with_name ("Remote communication error");
2568 case SERIAL_TIMEOUT
:
2575 /* Send the command in BUF to the remote machine,
2576 and read the reply into BUF.
2577 Report an error if we get an error reply. */
2587 error ("Remote failure reply: %s", buf
);
2590 /* Display a null-terminated packet on stdout, for debugging, using C
2597 puts_filtered ("\"");
2599 gdb_printchar (*buf
++, gdb_stdout
, '"');
2600 puts_filtered ("\"");
2604 /* Send a packet to the remote machine, with error checking.
2605 The data of the packet is in BUF. */
2612 unsigned char csum
= 0;
2614 int cnt
= strlen (buf
);
2619 /* Copy the packet into buffer BUF2, encapsulating it
2620 and giving it a checksum. */
2622 if (cnt
> (int) sizeof (buf2
) - 5) /* Prosanity check */
2628 for (i
= 0; i
< cnt
; i
++)
2634 *p
++ = tohex ((csum
>> 4) & 0xf);
2635 *p
++ = tohex (csum
& 0xf);
2637 /* Send it over and over until we get a positive ack. */
2641 int started_error_output
= 0;
2646 printf_unfiltered ("Sending packet: %s...", buf2
);
2647 gdb_flush(gdb_stdout
);
2649 if (SERIAL_WRITE (remote_desc
, buf2
, p
- buf2
))
2650 perror_with_name ("putpkt: write failed");
2652 /* read until either a timeout occurs (-2) or '+' is read */
2655 ch
= readchar (remote_timeout
);
2662 case SERIAL_TIMEOUT
:
2664 if (started_error_output
)
2666 putchar_unfiltered ('\n');
2667 started_error_output
= 0;
2676 printf_unfiltered("Ack\n");
2678 case SERIAL_TIMEOUT
:
2682 break; /* Retransmit buffer */
2685 char junkbuf
[PBUFSIZ
];
2687 /* It's probably an old response, and we're out of sync. Just
2688 gobble up the packet and ignore it. */
2689 getpkt (junkbuf
, 0);
2690 continue; /* Now, go look for + */
2695 if (!started_error_output
)
2697 started_error_output
= 1;
2698 printf_unfiltered ("putpkt: Junk: ");
2700 putchar_unfiltered (ch
& 0177);
2704 break; /* Here to retransmit */
2708 /* This is wrong. If doing a long backtrace, the user should be
2709 able to get out next time we call QUIT, without anything as violent
2710 as interrupt_query. If we want to provide a way out of here
2711 without getting to the next QUIT, it should be based on hitting
2712 ^C twice as in remote_wait. */
2722 /* Come here after finding the start of the frame. Collect the rest into BUF,
2723 verifying the checksum, length, and handling run-length compression.
2724 Returns 0 on any error, 1 on success. */
2739 c
= readchar (remote_timeout
);
2743 case SERIAL_TIMEOUT
:
2745 puts_filtered ("Timeout in mid-packet, retrying\n");
2749 puts_filtered ("Saw new packet start in middle of old one\n");
2750 return 0; /* Start a new packet, count retries */
2753 unsigned char pktcsum
;
2757 pktcsum
= fromhex (readchar (remote_timeout
)) << 4;
2758 pktcsum
|= fromhex (readchar (remote_timeout
));
2760 if (csum
== pktcsum
)
2765 printf_filtered ("Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
2767 puts_filtered (buf
);
2768 puts_filtered ("\n");
2772 case '*': /* Run length encoding */
2774 c
= readchar (remote_timeout
);
2776 c
= c
- ' ' + 3; /* Compute repeat count */
2779 if (c
> 0 && c
< 255 && bp
+ c
- 1 < buf
+ PBUFSIZ
- 1)
2781 memset (bp
, *(bp
- 1), c
);
2787 printf_filtered ("Repeat count %d too large for buffer: ", c
);
2788 puts_filtered (buf
);
2789 puts_filtered ("\n");
2793 if (bp
< buf
+ PBUFSIZ
- 1)
2801 puts_filtered ("Remote packet too long: ");
2802 puts_filtered (buf
);
2803 puts_filtered ("\n");
2812 /* Read a packet from the remote machine, with error checking,
2813 and store it in BUF. BUF is expected to be of size PBUFSIZ.
2814 If FOREVER, wait forever rather than timing out; this is used
2815 while the target is executing user code. */
2818 getpkt (buf
, forever
)
2827 strcpy (buf
,"timeout");
2831 #ifdef MAINTENANCE_CMDS
2832 timeout
= watchdog
> 0 ? watchdog
: -1;
2839 timeout
= remote_timeout
;
2843 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
2845 /* This can loop forever if the remote side sends us characters
2846 continuously, but if it pauses, we'll get a zero from readchar
2847 because of timeout. Then we'll count that as a retry. */
2849 /* Note that we will only wait forever prior to the start of a packet.
2850 After that, we expect characters to arrive at a brisk pace. They
2851 should show up within remote_timeout intervals. */
2855 c
= readchar (timeout
);
2857 if (c
== SERIAL_TIMEOUT
)
2859 #ifdef MAINTENANCE_CMDS
2860 if (forever
) /* Watchdog went off. Kill the target. */
2862 target_mourn_inferior ();
2863 error ("Watchdog has expired. Target detached.\n");
2867 puts_filtered ("Timed out.\n");
2873 /* We've found the start of a packet, now collect the data. */
2875 val
= read_frame (buf
);
2880 fprintf_unfiltered (gdb_stdout
, "Packet received: %s\n", buf
);
2881 SERIAL_WRITE (remote_desc
, "+", 1);
2885 /* Try the whole thing again. */
2887 SERIAL_WRITE (remote_desc
, "-", 1);
2890 /* We have tried hard enough, and just can't receive the packet. Give up. */
2892 printf_unfiltered ("Ignoring packet error, continuing...\n");
2893 SERIAL_WRITE (remote_desc
, "+", 1);
2899 /* For some mysterious reason, wait_for_inferior calls kill instead of
2900 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
2904 target_mourn_inferior ();
2908 /* Use catch_errors so the user can quit from gdb even when we aren't on
2909 speaking terms with the remote system. */
2910 catch_errors (putpkt
, "k", "", RETURN_MASK_ERROR
);
2912 /* Don't wait for it to die. I'm not really sure it matters whether
2913 we do or not. For the existing stubs, kill is a noop. */
2914 target_mourn_inferior ();
2920 remote_mourn_1 (&remote_ops
);
2924 extended_remote_mourn ()
2926 /* We do _not_ want to mourn the target like this; this will
2927 remove the extended remote target from the target stack,
2928 and the next time the user says "run" it'll fail.
2930 FIXME: What is the right thing to do here? */
2932 remote_mourn_1 (&extended_remote_ops
);
2936 /* Worker function for remote_mourn. */
2938 remote_mourn_1 (target
)
2939 struct target_ops
*target
;
2941 unpush_target (target
);
2942 generic_mourn_inferior ();
2945 /* In the extended protocol we want to be able to do things like
2946 "run" and have them basically work as expected. So we need
2947 a special create_inferior function.
2949 FIXME: One day add support for changing the exec file
2950 we're debugging, arguments and an environment. */
2953 extended_remote_create_inferior (exec_file
, args
, env
)
2958 /* Rip out the breakpoints; we'll reinsert them after restarting
2959 the remote server. */
2960 remove_breakpoints ();
2962 /* Now restart the remote server. */
2963 extended_remote_restart ();
2965 /* Now put the breakpoints back in. This way we're safe if the
2966 restart function works via a unix fork on the remote side. */
2967 insert_breakpoints ();
2969 /* Clean up from the last time we were running. */
2970 clear_proceed_status ();
2972 /* Let the remote process run. */
2973 proceed (-1, TARGET_SIGNAL_0
, 0);
2977 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
2978 than other targets; in those use REMOTE_BREAKPOINT instead of just
2979 BREAKPOINT. Also, bi-endian targets may define LITTLE_REMOTE_BREAKPOINT
2980 and BIG_REMOTE_BREAKPOINT. If none of these are defined, we just call
2981 the standard routines that are in mem-break.c. */
2983 /* FIXME, these ought to be done in a more dynamic fashion. For instance,
2984 the choice of breakpoint instruction affects target program design and
2985 vice versa, and by making it user-tweakable, the special code here
2986 goes away and we need fewer special GDB configurations. */
2988 #if defined (LITTLE_REMOTE_BREAKPOINT) && defined (BIG_REMOTE_BREAKPOINT) && !defined(REMOTE_BREAKPOINT)
2989 #define REMOTE_BREAKPOINT
2992 #ifdef REMOTE_BREAKPOINT
2994 /* If the target isn't bi-endian, just pretend it is. */
2995 #if !defined (LITTLE_REMOTE_BREAKPOINT) && !defined (BIG_REMOTE_BREAKPOINT)
2996 #define LITTLE_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
2997 #define BIG_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
3000 static unsigned char big_break_insn
[] = BIG_REMOTE_BREAKPOINT
;
3001 static unsigned char little_break_insn
[] = LITTLE_REMOTE_BREAKPOINT
;
3003 #endif /* REMOTE_BREAKPOINT */
3005 /* Insert a breakpoint on targets that don't have any better breakpoint
3006 support. We read the contents of the target location and stash it,
3007 then overwrite it with a breakpoint instruction. ADDR is the target
3008 location in the target machine. CONTENTS_CACHE is a pointer to
3009 memory allocated for saving the target contents. It is guaranteed
3010 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
3011 is accomplished via BREAKPOINT_MAX). */
3014 remote_insert_breakpoint (addr
, contents_cache
)
3016 char *contents_cache
;
3018 #ifdef REMOTE_BREAKPOINT
3021 val
= target_read_memory (addr
, contents_cache
, sizeof big_break_insn
);
3025 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
3026 val
= target_write_memory (addr
, (char *) big_break_insn
,
3027 sizeof big_break_insn
);
3029 val
= target_write_memory (addr
, (char *) little_break_insn
,
3030 sizeof little_break_insn
);
3035 return memory_insert_breakpoint (addr
, contents_cache
);
3036 #endif /* REMOTE_BREAKPOINT */
3040 remote_remove_breakpoint (addr
, contents_cache
)
3042 char *contents_cache
;
3044 #ifdef REMOTE_BREAKPOINT
3045 return target_write_memory (addr
, contents_cache
, sizeof big_break_insn
);
3047 return memory_remove_breakpoint (addr
, contents_cache
);
3048 #endif /* REMOTE_BREAKPOINT */
3051 /* Some targets are only capable of doing downloads, and afterwards they switch
3052 to the remote serial protocol. This function provides a clean way to get
3053 from the download target to the remote target. It's basically just a
3054 wrapper so that we don't have to expose any of the internal workings of
3057 Prior to calling this routine, you should shutdown the current target code,
3058 else you will get the "A program is being debugged already..." message.
3059 Usually a call to pop_target() suffices.
3063 push_remote_target (name
, from_tty
)
3067 printf_filtered ("Switching to remote protocol\n");
3068 remote_open (name
, from_tty
);
3071 /* Other targets want to use the entire remote serial module but with
3072 certain remote_ops overridden. */
3075 open_remote_target (name
, from_tty
, target
, extended_p
)
3078 struct target_ops
*target
;
3081 printf_filtered ("Selecting the %sremote protocol\n",
3082 (extended_p
? "extended-" : ""));
3083 remote_open_1 (name
, from_tty
, target
, extended_p
);
3086 /* Table used by the crc32 function to calcuate the checksum. */
3087 static unsigned long crc32_table
[256] = {0, 0};
3089 static unsigned long
3090 crc32 (buf
, len
, crc
)
3095 if (! crc32_table
[1])
3097 /* Initialize the CRC table and the decoding table. */
3101 for (i
= 0; i
< 256; i
++)
3103 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
3104 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
3111 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
3117 /* compare-sections command
3119 With no arguments, compares each loadable section in the exec bfd
3120 with the same memory range on the target, and reports mismatches.
3121 Useful for verifying the image on the target against the exec file.
3122 Depends on the target understanding the new "qCRC:" request. */
3125 compare_sections_command (args
, from_tty
)
3130 unsigned long host_crc
, target_crc
;
3131 extern bfd
*exec_bfd
;
3132 struct cleanup
*old_chain
;
3133 char *tmp
, *sectdata
, *sectname
, buf
[PBUFSIZ
];
3140 error ("command cannot be used without an exec file");
3141 if (!current_target
.to_shortname
||
3142 strcmp (current_target
.to_shortname
, "remote") != 0)
3143 error ("command can only be used with remote target");
3145 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
3147 if (!(s
->flags
& SEC_LOAD
))
3148 continue; /* skip non-loadable section */
3150 size
= bfd_get_section_size_before_reloc (s
);
3152 continue; /* skip zero-length section */
3154 sectname
= (char *) bfd_get_section_name (exec_bfd
, s
);
3155 if (args
&& strcmp (args
, sectname
) != 0)
3156 continue; /* not the section selected by user */
3158 matched
= 1; /* do this section */
3160 /* FIXME: assumes lma can fit into long */
3161 sprintf (buf
, "qCRC:%lx,%lx", (long) lma
, (long) size
);
3164 /* be clever; compute the host_crc before waiting for target reply */
3165 sectdata
= xmalloc (size
);
3166 old_chain
= make_cleanup (free
, sectdata
);
3167 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
3168 host_crc
= crc32 ((unsigned char *) sectdata
, size
, 0xffffffff);
3172 error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
3173 sectname
, lma
, lma
+ size
);
3175 error ("remote target does not support this operation");
3177 for (target_crc
= 0, tmp
= &buf
[1]; *tmp
; tmp
++)
3178 target_crc
= target_crc
* 16 + fromhex (*tmp
);
3180 printf_filtered ("Section %s, range 0x%08x -- 0x%08x: ",
3181 sectname
, lma
, lma
+ size
);
3182 if (host_crc
== target_crc
)
3183 printf_filtered ("matched.\n");
3186 printf_filtered ("MIS-MATCHED!\n");
3190 do_cleanups (old_chain
);
3193 warning ("One or more sections of the remote executable does not match\nthe loaded file\n");
3194 if (args
&& !matched
)
3195 printf_filtered ("No loaded section named '%s'.\n", args
);
3199 packet_command (args
, from_tty
)
3206 error ("command can only be used with remote target");
3209 error ("remote-packet command requires packet text as argument");
3211 puts_filtered ("sending: ");
3212 print_packet (args
);
3213 puts_filtered ("\n");
3217 puts_filtered ("received: ");
3219 puts_filtered ("\n");
3225 remote_ops
.to_shortname
= "remote";
3226 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
3227 remote_ops
.to_doc
= "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
3228 Specify the serial device it is connected to (e.g. /dev/ttya).";
3229 remote_ops
.to_open
= remote_open
;
3230 remote_ops
.to_close
= remote_close
;
3231 remote_ops
.to_detach
= remote_detach
;
3232 remote_ops
.to_resume
= remote_resume
;
3233 remote_ops
.to_wait
= remote_wait
;
3234 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
3235 remote_ops
.to_store_registers
= remote_store_registers
;
3236 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
3237 remote_ops
.to_xfer_memory
= remote_xfer_memory
;
3238 remote_ops
.to_files_info
= remote_files_info
;
3239 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
3240 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
3241 remote_ops
.to_kill
= remote_kill
;
3242 remote_ops
.to_load
= generic_load
;
3243 remote_ops
.to_mourn_inferior
= remote_mourn
;
3244 remote_ops
.to_thread_alive
= remote_thread_alive
;
3245 remote_ops
.to_stop
= remote_stop
;
3246 remote_ops
.to_stratum
= process_stratum
;
3247 remote_ops
.to_has_all_memory
= 1;
3248 remote_ops
.to_has_memory
= 1;
3249 remote_ops
.to_has_stack
= 1;
3250 remote_ops
.to_has_registers
= 1;
3251 remote_ops
.to_has_execution
= 1;
3252 remote_ops
.to_magic
= OPS_MAGIC
;
3256 init_extended_remote_ops ()
3258 extended_remote_ops
= remote_ops
;
3260 extended_remote_ops
.to_shortname
= "extended-remote";
3261 extended_remote_ops
.to_longname
= "Extended remote serial target in gdb-specific protocol";
3262 extended_remote_ops
.to_doc
= "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
3263 Specify the serial device it is connected to (e.g. /dev/ttya).",
3264 extended_remote_ops
.to_open
= extended_remote_open
;
3265 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
3266 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
3270 _initialize_remote ()
3273 add_target (&remote_ops
);
3275 init_extended_remote_ops ();
3276 add_target (&extended_remote_ops
);
3277 init_remote_threads();
3278 INIT_REMOTE_THREADTESTS
/* conditional thread packet unit test */
3280 add_cmd ("compare-sections", class_obscure
, compare_sections_command
,
3281 "Compare section data on target to the exec file.\n\
3282 Argument is a single section name (default: all loaded sections).",
3285 add_cmd ("packet", class_maintenance
, packet_command
,
3286 "Send an arbitrary packet to a remote target.\n\
3287 maintenance packet TEXT\n\
3288 If GDB is talking to an inferior via the GDB serial protocol, then\n\
3289 this command sends the string TEXT to the inferior, and displays the\n\
3290 response packet. GDB supplies the initial `$' character, and the\n\
3291 terminating `#' character and checksum.",
3294 add_show_from_set (add_set_cmd ("remotetimeout", no_class
,
3295 var_integer
, (char *)&remote_timeout
,
3296 "Set timeout value for remote read.\n",
3300 add_show_from_set (add_set_cmd ("remotebreak", no_class
,
3301 var_integer
, (char *)&remote_break
,
3302 "Set whether to send break if interrupted.\n",
3306 add_show_from_set (add_set_cmd ("remotewritesize", no_class
,
3307 var_integer
, (char *)&remote_write_size
,
3308 "Set the maximum number of bytes in each memory write packet.\n",
3314 remote_address_size
= TARGET_PTR_BIT
;
3315 add_show_from_set (add_set_cmd ("remoteaddresssize", class_obscure
,
3316 var_integer
, (char *)&remote_address_size
,
3317 "Set the maximum size of the address (in bits) in a memory packet.\n",