1 /* Remote target communications for serial-line targets in custom GDB protocol
2 Copyright 1988, 91, 92, 93, 94, 95, 96, 97, 98, 1999
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,
20 Boston, MA 02111-1307, USA. */
22 /* Remote communication protocol.
24 A debug packet whose contents are <data>
25 is encapsulated for transmission in the form:
27 $ <data> # CSUM1 CSUM2
29 <data> must be ASCII alphanumeric and cannot include characters
30 '$' or '#'. If <data> starts with two characters followed by
31 ':', then the existing stubs interpret this as a sequence number.
33 CSUM1 and CSUM2 are ascii hex representation of an 8-bit
34 checksum of <data>, the most significant nibble is sent first.
35 the hex digits 0-9,a-f are used.
37 Receiver responds with:
39 + - if CSUM is correct and ready for next packet
40 - - if CSUM is incorrect
43 Most values are encoded in ascii hex digits. Signal numbers are according
44 to the numbering in target.h.
48 set thread Hct... Set thread for subsequent operations.
49 c = 'c' for thread used in step and
50 continue; t... can be -1 for all
52 c = 'g' for thread used in other
53 operations. If zero, pick a thread,
59 reply XX....X Each byte of register data
60 is described by two hex digits.
61 Registers are in the internal order
62 for GDB, and the bytes in a register
63 are in the same order the machine uses.
66 write regs GXX..XX Each byte of register data
67 is described by two hex digits.
71 write reg Pn...=r... Write register n... with value r...,
72 which contains two hex digits for each
73 byte in the register (target byte
77 (not supported by all stubs).
79 read mem mAA..AA,LLLL AA..AA is address, LLLL is length.
80 reply XX..XX XX..XX is mem contents
81 Can be fewer bytes than requested
82 if able to read only part of the data.
85 write mem MAA..AA,LLLL:XX..XX
87 LLLL is number of bytes,
90 ENN for an error (this includes the case
91 where only part of the data was
94 write mem XAA..AA,LLLL:XX..XX
95 (binary) AA..AA is address,
96 LLLL is number of bytes,
101 continue cAA..AA AA..AA is address to resume
102 If AA..AA is omitted,
103 resume at same address.
105 step sAA..AA AA..AA is address to resume
106 If AA..AA is omitted,
107 resume at same address.
109 continue with Csig;AA..AA Continue with signal sig (hex signal
110 signal number). If ;AA..AA is omitted,
111 resume at same address.
113 step with Ssig;AA..AA Like 'C' but step not continue.
116 last signal ? Reply the current reason for stopping.
117 This is the same reply as is generated
118 for step or cont : SAA where AA is the
123 There is no immediate reply to step or cont.
124 The reply comes when the machine stops.
125 It is SAA AA is the signal number.
127 or... TAAn...:r...;n...:r...;n...:r...;
129 n... = register number (hex)
130 r... = register contents
132 r... = thread process ID. This is
134 n... = other string not starting
135 with valid hex digit.
136 gdb should ignore this n,r pair
137 and go on to the next. This way
138 we can extend the protocol.
139 or... WAA The process exited, and AA is
140 the exit status. This is only
141 applicable for certains sorts of
143 or... XAA The process terminated with signal
145 or (obsolete) NAA;tttttttt;dddddddd;bbbbbbbb
147 tttttttt = address of symbol "_start"
148 dddddddd = base of data section
149 bbbbbbbb = base of bss section.
150 Note: only used by Cisco Systems
151 targets. The difference between this
152 reply and the "qOffsets" query is that
153 the 'N' packet may arrive spontaneously
154 whereas the 'qOffsets' is a query
155 initiated by the host debugger.
156 or... OXX..XX XX..XX is hex encoding of ASCII data. This
157 can happen at any time while the
158 program is running and the debugger
159 should continue to wait for
162 thread alive TXX Find out if the thread XX is alive.
163 reply OK thread is still alive
166 remote restart RXX Restart the remote server
168 extended ops ! Use the extended remote protocol.
169 Sticky -- only needs to be set once.
173 toggle debug d toggle debug flag (see 386 & 68k stubs)
174 reset r reset -- see sparc stub.
175 reserved <other> On other requests, the stub should
176 ignore the request and send an empty
177 response ($#<checksum>). This way
178 we can extend the protocol and GDB
179 can tell whether the stub it is
180 talking to uses the old or the new.
181 search tAA:PP,MM Search backwards starting at address
182 AA for a match with pattern PP and
183 mask MM. PP and MM are 4 bytes.
184 Not supported by all stubs.
186 general query qXXXX Request info about XXXX.
187 general set QXXXX=yyyy Set value of XXXX to yyyy.
188 query sect offs qOffsets Get section offsets. Reply is
189 Text=xxx;Data=yyy;Bss=zzz
191 Responses can be run-length encoded to save space. A '*' means that
192 the next character is an ASCII encoding giving a repeat count which
193 stands for that many repititions of the character preceding the '*'.
194 The encoding is n+29, yielding a printable character where n >=3
195 (which is where rle starts to win). Don't use an n > 126.
198 "0* " means the same as "0000". */
205 #include "gdb_string.h"
209 #include "inferior.h"
214 /*#include "terminal.h" */
216 #include "objfiles.h"
217 #include "gdb-stabs.h"
218 #include "gdbthread.h"
223 #include <sys/time.h>
225 #include <sys/types.h>
228 #include "event-loop.h"
233 /* Prototypes for local functions */
234 static void initialize_sigint_signal_handler PARAMS ((void));
235 static void handle_remote_sigint PARAMS ((int));
236 static void handle_remote_sigint_twice PARAMS ((int));
237 static void async_remote_interrupt PARAMS ((gdb_client_data));
238 static void async_remote_interrupt_twice PARAMS ((gdb_client_data));
240 static void set_extended_protocol PARAMS ((struct continuation_arg *));
242 static void build_remote_gdbarch_data PARAMS ((void));
244 static int remote_write_bytes PARAMS ((CORE_ADDR memaddr,
245 char *myaddr, int len));
247 static int remote_read_bytes PARAMS ((CORE_ADDR memaddr,
248 char *myaddr, int len));
250 static void remote_files_info PARAMS ((struct target_ops * ignore));
252 static int remote_xfer_memory PARAMS ((CORE_ADDR memaddr, char *myaddr,
253 int len, int should_write,
254 struct target_ops * target));
256 static void remote_prepare_to_store PARAMS ((void));
258 static void remote_fetch_registers PARAMS ((int regno));
260 static void remote_resume PARAMS ((int pid, int step,
261 enum target_signal siggnal));
262 static void remote_async_resume PARAMS ((int pid, int step,
263 enum target_signal siggnal));
265 static int remote_start_remote PARAMS ((PTR));
267 static void remote_open PARAMS ((char *name, int from_tty));
268 static void remote_async_open PARAMS ((char *name, int from_tty));
270 static void extended_remote_open PARAMS ((char *name, int from_tty));
271 static void extended_remote_async_open PARAMS ((char *name, int from_tty));
273 static void remote_open_1 PARAMS ((char *, int, struct target_ops *,
275 static void remote_async_open_1 PARAMS ((char *, int, struct target_ops *,
278 static void remote_close PARAMS ((int quitting));
280 static void remote_store_registers PARAMS ((int regno));
282 static void remote_mourn PARAMS ((void));
284 static void extended_remote_restart PARAMS ((void));
286 static void extended_remote_mourn PARAMS ((void));
288 static void extended_remote_create_inferior PARAMS ((char *, char *, char **));
289 static void extended_remote_async_create_inferior PARAMS ((char *, char *, char **));
291 static void remote_mourn_1 PARAMS ((struct target_ops *));
293 static void remote_send PARAMS ((char *buf));
295 static int readchar PARAMS ((int timeout));
297 static int remote_wait PARAMS ((int pid, struct target_waitstatus * status));
298 static int remote_async_wait PARAMS ((int pid, struct target_waitstatus * status));
300 static void remote_kill PARAMS ((void));
301 static void remote_async_kill PARAMS ((void));
303 static int tohex PARAMS ((int nib));
305 static void remote_detach PARAMS ((char *args, int from_tty));
306 static void remote_async_detach PARAMS ((char *args, int from_tty));
308 static void remote_interrupt PARAMS ((int signo));
310 static void remote_interrupt_twice PARAMS ((int signo));
312 static void interrupt_query PARAMS ((void));
314 static void set_thread PARAMS ((int, int));
316 static int remote_thread_alive PARAMS ((int));
318 static void get_offsets PARAMS ((void));
320 static int read_frame PARAMS ((char *));
322 static int remote_insert_breakpoint PARAMS ((CORE_ADDR, char *));
324 static int remote_remove_breakpoint PARAMS ((CORE_ADDR, char *));
326 static int hexnumlen PARAMS ((ULONGEST num));
328 static void init_remote_ops PARAMS ((void));
330 static void init_extended_remote_ops PARAMS ((void));
332 static void init_remote_cisco_ops PARAMS ((void));
334 static struct target_ops remote_cisco_ops;
336 static void remote_stop PARAMS ((void));
338 static int ishex PARAMS ((int ch, int *val));
340 static int stubhex PARAMS ((int ch));
342 static int remote_query PARAMS ((int /*char */ , char *, char *, int *));
344 static int hexnumstr PARAMS ((char *, ULONGEST));
346 static CORE_ADDR remote_address_masked PARAMS ((CORE_ADDR));
348 static void print_packet PARAMS ((char *));
350 static unsigned long crc32 PARAMS ((unsigned char *, int, unsigned int));
352 static void compare_sections_command PARAMS ((char *, int));
354 static void packet_command PARAMS ((char *, int));
356 static int stub_unpack_int PARAMS ((char *buff, int fieldlength));
358 static int remote_current_thread PARAMS ((int oldpid));
360 static void remote_find_new_threads PARAMS ((void));
362 static void record_currthread PARAMS ((int currthread));
364 /* exported functions */
366 extern int fromhex PARAMS ((int a));
368 extern void getpkt PARAMS ((char *buf, int forever));
370 extern int putpkt PARAMS ((char *buf));
372 static int putpkt_binary PARAMS ((char *buf, int cnt));
374 void remote_console_output PARAMS ((char *));
376 static void check_binary_download PARAMS ((CORE_ADDR addr));
379 struct packet_config;
382 static void show_packet_config_cmd PARAMS ((struct packet_config * config));
384 static void set_packet_config_cmd PARAMS ((struct packet_config * config,
385 struct cmd_list_element * c));
387 static void add_packet_config_cmd PARAMS ((struct packet_config * config,
390 void (*set_func) (char *args, int from_tty, struct cmd_list_element * c),
391 void (*show_func) (char *name, int from_tty),
392 struct cmd_list_element **setlist,
393 struct cmd_list_element **showlist));
395 static void init_packet_config PARAMS ((struct packet_config * config));
397 static void set_remote_protocol_P_packet_cmd PARAMS ((char *args,
399 struct cmd_list_element * c));
401 static void show_remote_protocol_P_packet_cmd PARAMS ((char *args,
407 /* Define the target subroutine names */
409 void open_remote_target PARAMS ((char *, int, struct target_ops *, int));
411 void _initialize_remote PARAMS ((void));
415 static struct target_ops remote_ops;
417 static struct target_ops extended_remote_ops;
419 /* Temporary target ops. Just like the remote_ops and
420 extended_remote_ops, but with asynchronous support. */
421 static struct target_ops remote_async_ops;
423 static struct target_ops extended_async_remote_ops;
425 /* This was 5 seconds, which is a long time to sit and wait.
426 Unless this is going though some terminal server or multiplexer or
427 other form of hairy serial connection, I would think 2 seconds would
430 /* Changed to allow option to set timeout value.
431 was static int remote_timeout = 2; */
432 extern int remote_timeout;
434 /* This variable chooses whether to send a ^C or a break when the user
435 requests program interruption. Although ^C is usually what remote
436 systems expect, and that is the default here, sometimes a break is
437 preferable instead. */
439 static int remote_break;
441 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
442 remote_open knows that we don't have a file open when the program
444 static serial_t remote_desc = NULL;
446 /* This is set by the target (thru the 'S' message)
447 to denote that the target is in kernel mode. */
448 static int cisco_kernel_mode = 0;
450 /* This variable (available to the user via "set remotebinarydownload")
451 dictates whether downloads are sent in binary (via the 'X' packet).
452 We assume that the stub can, and attempt to do it. This will be cleared if
453 the stub does not understand it. This switch is still needed, though
454 in cases when the packet is supported in the stub, but the connection
455 does not allow it (i.e., 7-bit serial connection only). */
456 static int remote_binary_download = 1;
458 /* Have we already checked whether binary downloads work? */
459 static int remote_binary_checked;
461 /* Maximum number of bytes to read/write at once. The value here
462 is chosen to fill up a packet (the headers account for the 32). */
463 #define MAXBUFBYTES(N) (((N)-32)/2)
465 /* Having this larger than 400 causes us to be incompatible with m68k-stub.c
466 and i386-stub.c. Normally, no one would notice because it only matters
467 for writing large chunks of memory (e.g. in downloads). Also, this needs
468 to be more than 400 if required to hold the registers (see below, where
469 we round it up based on REGISTER_BYTES). */
470 /* Round up PBUFSIZ to hold all the registers, at least. */
471 #define PBUFSIZ ((REGISTER_BYTES > MAXBUFBYTES (400)) \
472 ? (REGISTER_BYTES * 2 + 32) \
476 /* This variable sets the number of bytes to be written to the target
477 in a single packet. Normally PBUFSIZ is satisfactory, but some
478 targets need smaller values (perhaps because the receiving end
481 static int remote_write_size;
483 /* This variable sets the number of bits in an address that are to be
484 sent in a memory ("M" or "m") packet. Normally, after stripping
485 leading zeros, the entire address would be sent. This variable
486 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
487 initial implementation of remote.c restricted the address sent in
488 memory packets to ``host::sizeof long'' bytes - (typically 32
489 bits). Consequently, for 64 bit targets, the upper 32 bits of an
490 address was never sent. Since fixing this bug may cause a break in
491 some remote targets this variable is principly provided to
492 facilitate backward compatibility. */
494 static int remote_address_size;
496 /* This is the size (in chars) of the first response to the `g' command. This
497 is used to limit the size of the memory read and write commands to prevent
498 stub buffers from overflowing. The size does not include headers and
499 trailers, it is only the payload size. */
501 static int remote_register_buf_size = 0;
503 /* Generic configuration support for packets the stub optionally
504 supports. Allows the user to specify the use of the packet as well
505 as allowing GDB to auto-detect support in the remote stub. */
509 PACKET_SUPPORT_UNKNOWN = 0,
516 PACKET_AUTO_DETECT = 0,
525 enum packet_detect detect;
526 enum packet_support support;
529 static char packet_support_auto[] = "auto";
530 static char packet_enable[] = "enable";
531 static char packet_disable[] = "disable";
532 static char *packet_support_enums[] =
541 set_packet_config_cmd (config, c)
542 struct packet_config *config;
543 struct cmd_list_element *c;
545 if (config->state == packet_enable)
547 config->detect = PACKET_MANUAL_DETECT;
548 config->support = PACKET_ENABLE;
550 else if (config->state == packet_disable)
552 config->detect = PACKET_MANUAL_DETECT;
553 config->support = PACKET_DISABLE;
555 else if (config->state == packet_support_auto)
557 config->detect = PACKET_AUTO_DETECT;
558 config->support = PACKET_SUPPORT_UNKNOWN;
561 fatal ("Bad enum value");
565 show_packet_config_cmd (config)
566 struct packet_config *config;
568 char *support = "internal-error";
569 switch (config->support)
575 support = "disabled";
577 case PACKET_SUPPORT_UNKNOWN:
581 switch (config->detect)
583 case PACKET_AUTO_DETECT:
584 printf_filtered ("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n",
585 config->name, config->title, support);
587 case PACKET_MANUAL_DETECT:
588 printf_filtered ("Support for remote protocol `%s' (%s) is currently %s.\n",
589 config->name, config->title, support);
594 add_packet_config_cmd (config, name, title, set_func, show_func,
596 struct packet_config *config;
599 void (*set_func) PARAMS ((char *args, int from_tty,
600 struct cmd_list_element * c));
601 void (*show_func) PARAMS ((char *name, int from_tty));
602 struct cmd_list_element **setlist;
603 struct cmd_list_element **showlist;
605 struct cmd_list_element *c;
610 config->title = title;
611 asprintf (&set_doc, "Set use of remote protocol `%s' (%s) packet",
613 asprintf (&show_doc, "Show current use of remote protocol `%s' (%s) packet",
615 asprintf (&full_name, "%s-packet", name);
616 c = add_set_enum_cmd (full_name,
617 class_obscure, packet_support_enums,
618 (char *) &config->state,
620 c->function.sfunc = set_func;
621 add_cmd (full_name, class_obscure, show_func, show_doc, showlist);
625 init_packet_config (config)
626 struct packet_config *config;
628 switch (config->detect)
630 case PACKET_AUTO_DETECT:
631 config->support = PACKET_SUPPORT_UNKNOWN;
633 case PACKET_MANUAL_DETECT:
634 /* let the user beware */
639 /* Should we try the 'P' (set register) request? */
641 static struct packet_config remote_protocol_P;
644 set_remote_protocol_P_packet_cmd (args, from_tty, c)
647 struct cmd_list_element *c;
649 set_packet_config_cmd (&remote_protocol_P, c);
653 show_remote_protocol_P_packet_cmd (args, from_tty)
657 show_packet_config_cmd (&remote_protocol_P);
661 /* Tokens for use by the asynchronous signal handlers for SIGINT */
662 PTR sigint_remote_twice_token;
663 PTR sigint_remote_token;
665 /* These are pointers to hook functions that may be set in order to
666 modify resume/wait behavior for a particular architecture. */
668 void (*target_resume_hook) PARAMS ((void));
669 void (*target_wait_loop_hook) PARAMS ((void));
673 /* These are the threads which we last sent to the remote system.
674 -1 for all or -2 for not sent yet. */
675 static int general_thread;
676 static int continue_thread;
678 /* Call this function as a result of
679 1) A halt indication (T packet) containing a thread id
680 2) A direct query of currthread
681 3) Successful execution of set thread
685 record_currthread (currthread)
688 general_thread = currthread;
690 /* If this is a new thread, add it to GDB's thread list.
691 If we leave it up to WFI to do this, bad things will happen. */
692 if (!in_thread_list (currthread))
694 add_thread (currthread);
695 printf_filtered ("[New %s]\n", target_pid_to_str (currthread));
699 #define MAGIC_NULL_PID 42000
706 char *buf = alloca (PBUFSIZ);
707 int state = gen ? general_thread : continue_thread;
713 buf[1] = gen ? 'g' : 'c';
714 if (th == MAGIC_NULL_PID)
720 sprintf (&buf[2], "-%x", -th);
722 sprintf (&buf[2], "%x", th);
728 continue_thread = th;
731 /* Return nonzero if the thread TH is still alive on the remote system. */
734 remote_thread_alive (tid)
740 sprintf (buf, "T-%08x", -tid);
742 sprintf (buf, "T%08x", tid);
745 return (buf[0] == 'O' && buf[1] == 'K');
748 /* About these extended threadlist and threadinfo packets. They are
749 variable length packets but, the fields within them are often fixed
750 length. They are redundent enough to send over UDP as is the
751 remote protocol in general. There is a matching unit test module
754 #define OPAQUETHREADBYTES 8
756 /* a 64 bit opaque identifier */
757 typedef unsigned char threadref[OPAQUETHREADBYTES];
759 /* WARNING: This threadref data structure comes from the remote O.S., libstub
760 protocol encoding, and remote.c. it is not particularly changable */
762 /* Right now, the internal structure is int. We want it to be bigger.
766 typedef int gdb_threadref; /* internal GDB thread reference */
768 /* gdb_ext_thread_info is an internal GDB data structure which is
769 equivalint to the reply of the remote threadinfo packet */
771 struct gdb_ext_thread_info
773 threadref threadid; /* External form of thread reference */
774 int active; /* Has state interesting to GDB? , regs, stack */
775 char display[256]; /* Brief state display, name, blocked/syspended */
776 char shortname[32]; /* To be used to name threads */
777 char more_display[256]; /* Long info, statistics, queue depth, whatever */
780 /* The volume of remote transfers can be limited by submitting
781 a mask containing bits specifying the desired information.
782 Use a union of these values as the 'selection' parameter to
783 get_thread_info. FIXME: Make these TAG names more thread specific.
786 #define TAG_THREADID 1
788 #define TAG_DISPLAY 4
789 #define TAG_THREADNAME 8
790 #define TAG_MOREDISPLAY 16
792 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
794 char *unpack_varlen_hex PARAMS ((char *buff, int *result));
796 static char *unpack_nibble PARAMS ((char *buf, int *val));
798 static char *pack_nibble PARAMS ((char *buf, int nibble));
800 static char *pack_hex_byte PARAMS ((char *pkt, int /*unsigned char */ byte));
802 static char *unpack_byte PARAMS ((char *buf, int *value));
804 static char *pack_int PARAMS ((char *buf, int value));
806 static char *unpack_int PARAMS ((char *buf, int *value));
808 static char *unpack_string PARAMS ((char *src, char *dest, int length));
810 static char *pack_threadid PARAMS ((char *pkt, threadref * id));
812 static char *unpack_threadid PARAMS ((char *inbuf, threadref * id));
814 void int_to_threadref PARAMS ((threadref * id, int value));
816 static int threadref_to_int PARAMS ((threadref * ref));
818 static void copy_threadref PARAMS ((threadref * dest, threadref * src));
820 static int threadmatch PARAMS ((threadref * dest, threadref * src));
822 static char *pack_threadinfo_request PARAMS ((char *pkt, int mode,
825 static int remote_unpack_thread_info_response PARAMS ((char *pkt,
826 threadref * expectedref,
827 struct gdb_ext_thread_info * info));
830 static int remote_get_threadinfo PARAMS ((threadref * threadid,
831 int fieldset, /*TAG mask */
832 struct gdb_ext_thread_info * info));
834 static int adapt_remote_get_threadinfo PARAMS ((gdb_threadref * ref,
836 struct gdb_ext_thread_info * info));
838 static char *pack_threadlist_request PARAMS ((char *pkt, int startflag,
840 threadref * nextthread));
842 static int parse_threadlist_response PARAMS ((char *pkt,
844 threadref * original_echo,
845 threadref * resultlist,
848 static int remote_get_threadlist PARAMS ((int startflag,
849 threadref * nextthread,
853 threadref * threadlist));
855 typedef int (*rmt_thread_action) (threadref * ref, void *context);
857 static int remote_threadlist_iterator PARAMS ((rmt_thread_action stepfunction,
858 void *context, int looplimit));
860 static int remote_newthread_step PARAMS ((threadref * ref, void *context));
862 /* encode 64 bits in 16 chars of hex */
864 static const char hexchars[] = "0123456789abcdef";
871 if ((ch >= 'a') && (ch <= 'f'))
873 *val = ch - 'a' + 10;
876 if ((ch >= 'A') && (ch <= 'F'))
878 *val = ch - 'A' + 10;
881 if ((ch >= '0') && (ch <= '9'))
893 if (ch >= 'a' && ch <= 'f')
894 return ch - 'a' + 10;
895 if (ch >= '0' && ch <= '9')
897 if (ch >= 'A' && ch <= 'F')
898 return ch - 'A' + 10;
903 stub_unpack_int (buff, fieldlength)
912 nibble = stubhex (*buff++);
916 retval = retval << 4;
922 unpack_varlen_hex (buff, result)
923 char *buff; /* packet to parse */
929 while (ishex (*buff, &nibble))
932 retval = retval << 4;
933 retval |= nibble & 0x0f;
940 unpack_nibble (buf, val)
949 pack_nibble (buf, nibble)
953 *buf++ = hexchars[(nibble & 0x0f)];
958 pack_hex_byte (pkt, byte)
962 *pkt++ = hexchars[(byte >> 4) & 0xf];
963 *pkt++ = hexchars[(byte & 0xf)];
968 unpack_byte (buf, value)
972 *value = stub_unpack_int (buf, 2);
977 pack_int (buf, value)
981 buf = pack_hex_byte (buf, (value >> 24) & 0xff);
982 buf = pack_hex_byte (buf, (value >> 16) & 0xff);
983 buf = pack_hex_byte (buf, (value >> 8) & 0x0ff);
984 buf = pack_hex_byte (buf, (value & 0xff));
989 unpack_int (buf, value)
993 *value = stub_unpack_int (buf, 8);
997 #if 0 /* currently unused, uncomment when needed */
998 static char *pack_string PARAMS ((char *pkt, char *string));
1001 pack_string (pkt, string)
1008 len = strlen (string);
1010 len = 200; /* Bigger than most GDB packets, junk??? */
1011 pkt = pack_hex_byte (pkt, len);
1015 if ((ch == '\0') || (ch == '#'))
1016 ch = '*'; /* Protect encapsulation */
1021 #endif /* 0 (unused) */
1024 unpack_string (src, dest, length)
1036 pack_threadid (pkt, id)
1041 unsigned char *altid;
1043 altid = (unsigned char *) id;
1044 limit = pkt + BUF_THREAD_ID_SIZE;
1046 pkt = pack_hex_byte (pkt, *altid++);
1052 unpack_threadid (inbuf, id)
1057 char *limit = inbuf + BUF_THREAD_ID_SIZE;
1060 altref = (char *) id;
1062 while (inbuf < limit)
1064 x = stubhex (*inbuf++);
1065 y = stubhex (*inbuf++);
1066 *altref++ = (x << 4) | y;
1071 /* Externally, threadrefs are 64 bits but internally, they are still
1072 ints. This is due to a mismatch of specifications. We would like
1073 to use 64bit thread references internally. This is an adapter
1077 int_to_threadref (id, value)
1081 unsigned char *scan;
1083 scan = (unsigned char *) id;
1089 *scan++ = (value >> 24) & 0xff;
1090 *scan++ = (value >> 16) & 0xff;
1091 *scan++ = (value >> 8) & 0xff;
1092 *scan++ = (value & 0xff);
1096 threadref_to_int (ref)
1100 unsigned char *scan;
1102 scan = (char *) ref;
1106 value = (value << 8) | ((*scan++) & 0xff);
1111 copy_threadref (dest, src)
1116 unsigned char *csrc, *cdest;
1118 csrc = (unsigned char *) src;
1119 cdest = (unsigned char *) dest;
1126 threadmatch (dest, src)
1130 /* things are broken right now, so just assume we got a match */
1132 unsigned char *srcp, *destp;
1134 srcp = (char *) src;
1135 destp = (char *) dest;
1139 result &= (*srcp++ == *destp++) ? 1 : 0;
1146 threadid:1, # always request threadid
1153 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1156 pack_threadinfo_request (pkt, mode, id)
1161 *pkt++ = 'q'; /* Info Query */
1162 *pkt++ = 'P'; /* process or thread info */
1163 pkt = pack_int (pkt, mode); /* mode */
1164 pkt = pack_threadid (pkt, id); /* threadid */
1165 *pkt = '\0'; /* terminate */
1169 /* These values tag the fields in a thread info response packet */
1170 /* Tagging the fields allows us to request specific fields and to
1171 add more fields as time goes by */
1173 #define TAG_THREADID 1 /* Echo the thread identifier */
1174 #define TAG_EXISTS 2 /* Is this process defined enough to
1175 fetch registers and its stack */
1176 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1177 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
1178 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1182 remote_unpack_thread_info_response (pkt, expectedref, info)
1184 threadref *expectedref;
1185 struct gdb_ext_thread_info *info;
1190 char *limit = pkt + PBUFSIZ; /* plausable parsing limit */
1193 /* info->threadid = 0; FIXME: implement zero_threadref */
1195 info->display[0] = '\0';
1196 info->shortname[0] = '\0';
1197 info->more_display[0] = '\0';
1199 /* Assume the characters indicating the packet type have been stripped */
1200 pkt = unpack_int (pkt, &mask); /* arg mask */
1201 pkt = unpack_threadid (pkt, &ref);
1204 warning ("Incomplete response to threadinfo request\n");
1205 if (!threadmatch (&ref, expectedref))
1206 { /* This is an answer to a different request */
1207 warning ("ERROR RMT Thread info mismatch\n");
1210 copy_threadref (&info->threadid, &ref);
1212 /* Loop on tagged fields , try to bail if somthing goes wrong */
1214 while ((pkt < limit) && mask && *pkt) /* packets are terminated with nulls */
1216 pkt = unpack_int (pkt, &tag); /* tag */
1217 pkt = unpack_byte (pkt, &length); /* length */
1218 if (!(tag & mask)) /* tags out of synch with mask */
1220 warning ("ERROR RMT: threadinfo tag mismatch\n");
1224 if (tag == TAG_THREADID)
1228 warning ("ERROR RMT: length of threadid is not 16\n");
1232 pkt = unpack_threadid (pkt, &ref);
1233 mask = mask & ~TAG_THREADID;
1236 if (tag == TAG_EXISTS)
1238 info->active = stub_unpack_int (pkt, length);
1240 mask = mask & ~(TAG_EXISTS);
1243 warning ("ERROR RMT: 'exists' length too long\n");
1249 if (tag == TAG_THREADNAME)
1251 pkt = unpack_string (pkt, &info->shortname[0], length);
1252 mask = mask & ~TAG_THREADNAME;
1255 if (tag == TAG_DISPLAY)
1257 pkt = unpack_string (pkt, &info->display[0], length);
1258 mask = mask & ~TAG_DISPLAY;
1261 if (tag == TAG_MOREDISPLAY)
1263 pkt = unpack_string (pkt, &info->more_display[0], length);
1264 mask = mask & ~TAG_MOREDISPLAY;
1267 warning ("ERROR RMT: unknown thread info tag\n");
1268 break; /* Not a tag we know about */
1274 remote_get_threadinfo (threadid, fieldset, info)
1275 threadref *threadid;
1276 int fieldset; /* TAG mask */
1277 struct gdb_ext_thread_info *info;
1280 char *threadinfo_pkt = alloca (PBUFSIZ);
1282 pack_threadinfo_request (threadinfo_pkt, fieldset, threadid);
1283 putpkt (threadinfo_pkt);
1284 getpkt (threadinfo_pkt, 0);
1285 result = remote_unpack_thread_info_response (threadinfo_pkt + 2, threadid,
1290 /* Unfortunately, 61 bit thread-ids are bigger than the internal
1291 representation of a threadid. */
1294 adapt_remote_get_threadinfo (ref, selection, info)
1297 struct gdb_ext_thread_info *info;
1301 int_to_threadref (&lclref, *ref);
1302 return remote_get_threadinfo (&lclref, selection, info);
1305 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1308 pack_threadlist_request (pkt, startflag, threadcount, nextthread)
1312 threadref *nextthread;
1314 *pkt++ = 'q'; /* info query packet */
1315 *pkt++ = 'L'; /* Process LIST or threadLIST request */
1316 pkt = pack_nibble (pkt, startflag); /* initflag 1 bytes */
1317 pkt = pack_hex_byte (pkt, threadcount); /* threadcount 2 bytes */
1318 pkt = pack_threadid (pkt, nextthread); /* 64 bit thread identifier */
1323 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1326 parse_threadlist_response (pkt, result_limit, original_echo, resultlist,
1330 threadref *original_echo;
1331 threadref *resultlist;
1335 int count, resultcount, done;
1338 /* Assume the 'q' and 'M chars have been stripped. */
1339 limit = pkt + (PBUFSIZ - BUF_THREAD_ID_SIZE); /* done parse past here */
1340 pkt = unpack_byte (pkt, &count); /* count field */
1341 pkt = unpack_nibble (pkt, &done);
1342 /* The first threadid is the argument threadid. */
1343 pkt = unpack_threadid (pkt, original_echo); /* should match query packet */
1344 while ((count-- > 0) && (pkt < limit))
1346 pkt = unpack_threadid (pkt, resultlist++);
1347 if (resultcount++ >= result_limit)
1356 remote_get_threadlist (startflag, nextthread, result_limit,
1357 done, result_count, threadlist)
1359 threadref *nextthread;
1363 threadref *threadlist;
1366 static threadref echo_nextthread;
1367 char *threadlist_packet = alloca (PBUFSIZ);
1368 char *t_response = alloca (PBUFSIZ);
1371 /* Trancate result limit to be smaller than the packet size */
1372 if ((((result_limit + 1) * BUF_THREAD_ID_SIZE) + 10) >= PBUFSIZ)
1373 result_limit = (PBUFSIZ / BUF_THREAD_ID_SIZE) - 2;
1375 pack_threadlist_request (threadlist_packet,
1376 startflag, result_limit, nextthread);
1377 putpkt (threadlist_packet);
1378 getpkt (t_response, 0);
1381 parse_threadlist_response (t_response + 2, result_limit, &echo_nextthread,
1384 if (!threadmatch (&echo_nextthread, nextthread))
1386 /* FIXME: This is a good reason to drop the packet */
1387 /* Possably, there is a duplicate response */
1389 retransmit immediatly - race conditions
1390 retransmit after timeout - yes
1392 wait for packet, then exit
1394 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1395 return 0; /* I choose simply exiting */
1397 if (*result_count <= 0)
1401 warning ("RMT ERROR : failed to get remote thread list\n");
1404 return result; /* break; */
1406 if (*result_count > result_limit)
1409 warning ("RMT ERROR: threadlist response longer than requested\n");
1415 /* This is the interface between remote and threads, remotes upper interface */
1417 /* remote_find_new_threads retrieves the thread list and for each
1418 thread in the list, looks up the thread in GDB's internal list,
1419 ading the thread if it does not already exist. This involves
1420 getting partial thread lists from the remote target so, polling the
1421 quit_flag is required. */
1424 /* About this many threadisds fit in a packet. */
1426 #define MAXTHREADLISTRESULTS 32
1429 remote_threadlist_iterator (stepfunction, context, looplimit)
1430 rmt_thread_action stepfunction;
1434 int done, i, result_count;
1438 static threadref nextthread;
1439 static threadref resultthreadlist[MAXTHREADLISTRESULTS];
1444 if (loopcount++ > looplimit)
1447 warning ("Remote fetch threadlist -infinite loop-\n");
1450 if (!remote_get_threadlist (startflag, &nextthread, MAXTHREADLISTRESULTS,
1451 &done, &result_count, resultthreadlist))
1456 /* clear for later iterations */
1458 /* Setup to resume next batch of thread references, set nextthread. */
1459 if (result_count >= 1)
1460 copy_threadref (&nextthread, &resultthreadlist[result_count - 1]);
1462 while (result_count--)
1463 if (!(result = (*stepfunction) (&resultthreadlist[i++], context)))
1470 remote_newthread_step (ref, context)
1476 pid = threadref_to_int (ref);
1477 if (!in_thread_list (pid))
1479 return 1; /* continue iterator */
1482 #define CRAZY_MAX_THREADS 1000
1485 remote_current_thread (oldpid)
1488 char *buf = alloca (PBUFSIZ);
1492 if (buf[0] == 'Q' && buf[1] == 'C')
1493 return strtol (&buf[2], NULL, 16);
1498 /* Find new threads for info threads command. */
1501 remote_find_new_threads ()
1503 remote_threadlist_iterator (remote_newthread_step, 0,
1505 if (inferior_pid == MAGIC_NULL_PID) /* ack ack ack */
1506 inferior_pid = remote_current_thread (inferior_pid);
1510 remote_threads_info (void)
1512 char *buf = alloca (PBUFSIZ);
1516 if (remote_desc == 0) /* paranoia */
1517 error ("Command can only be used when connected to the remote target.");
1519 putpkt ("qfThreadInfo");
1520 getpkt (bufp = buf, 0);
1521 if (bufp[0] == '\0') /* q packet not recognized! */
1522 { /* try old jmetzler method */
1523 remote_find_new_threads ();
1526 else /* try new 'q' method */
1527 while (*bufp++ == 'm') /* reply contains one or more TID */
1531 tid = strtol (bufp, &bufp, 16);
1532 if (tid != 0 && !in_thread_list (tid))
1535 while (*bufp++ == ','); /* comma-separated list */
1536 putpkt ("qsThreadInfo");
1537 getpkt (bufp = buf, 0);
1542 /* Restart the remote side; this is an extended protocol operation. */
1545 extended_remote_restart ()
1547 char *buf = alloca (PBUFSIZ);
1549 /* Send the restart command; for reasons I don't understand the
1550 remote side really expects a number after the "R". */
1552 sprintf (&buf[1], "%x", 0);
1555 /* Now query for status so this looks just like we restarted
1556 gdbserver from scratch. */
1561 /* Clean up connection to a remote debugger. */
1565 remote_close (quitting)
1569 SERIAL_CLOSE (remote_desc);
1573 /* Query the remote side for the text, data and bss offsets. */
1578 char *buf = alloca (PBUFSIZ);
1581 CORE_ADDR text_addr, data_addr, bss_addr;
1582 struct section_offsets *offs;
1584 putpkt ("qOffsets");
1588 if (buf[0] == '\000')
1589 return; /* Return silently. Stub doesn't support
1593 warning ("Remote failure reply: %s", buf);
1597 /* Pick up each field in turn. This used to be done with scanf, but
1598 scanf will make trouble if CORE_ADDR size doesn't match
1599 conversion directives correctly. The following code will work
1600 with any size of CORE_ADDR. */
1601 text_addr = data_addr = bss_addr = 0;
1605 if (strncmp (ptr, "Text=", 5) == 0)
1608 /* Don't use strtol, could lose on big values. */
1609 while (*ptr && *ptr != ';')
1610 text_addr = (text_addr << 4) + fromhex (*ptr++);
1615 if (!lose && strncmp (ptr, ";Data=", 6) == 0)
1618 while (*ptr && *ptr != ';')
1619 data_addr = (data_addr << 4) + fromhex (*ptr++);
1624 if (!lose && strncmp (ptr, ";Bss=", 5) == 0)
1627 while (*ptr && *ptr != ';')
1628 bss_addr = (bss_addr << 4) + fromhex (*ptr++);
1634 error ("Malformed response to offset query, %s", buf);
1636 if (symfile_objfile == NULL)
1639 offs = alloca (sizeof (struct section_offsets)
1640 + symfile_objfile->num_sections
1641 * sizeof (offs->offsets));
1642 memcpy (offs, symfile_objfile->section_offsets,
1643 sizeof (struct section_offsets)
1644 + symfile_objfile->num_sections
1645 * sizeof (offs->offsets));
1647 ANOFFSET (offs, SECT_OFF_TEXT) = text_addr;
1649 /* This is a temporary kludge to force data and bss to use the same offsets
1650 because that's what nlmconv does now. The real solution requires changes
1651 to the stub and remote.c that I don't have time to do right now. */
1653 ANOFFSET (offs, SECT_OFF_DATA) = data_addr;
1654 ANOFFSET (offs, SECT_OFF_BSS) = data_addr;
1656 objfile_relocate (symfile_objfile, offs);
1660 * Cisco version of section offsets:
1662 * Instead of having GDB query the target for the section offsets,
1663 * Cisco lets the target volunteer the information! It's also in
1664 * a different format, so here are the functions that will decode
1665 * a section offset packet from a Cisco target.
1669 * Function: remote_cisco_section_offsets
1671 * Returns: zero for success, non-zero for failure
1675 remote_cisco_section_offsets (text_addr, data_addr, bss_addr,
1676 text_offs, data_offs, bss_offs)
1680 bfd_signed_vma *text_offs;
1681 bfd_signed_vma *data_offs;
1682 bfd_signed_vma *bss_offs;
1684 bfd_vma text_base, data_base, bss_base;
1685 struct minimal_symbol *start;
1691 if (symfile_objfile == NULL)
1692 return -1; /* no can do nothin' */
1694 start = lookup_minimal_symbol ("_start", NULL, NULL);
1696 return -1; /* Can't find "_start" symbol */
1698 data_base = bss_base = 0;
1699 text_base = SYMBOL_VALUE_ADDRESS (start);
1701 abfd = symfile_objfile->obfd;
1702 for (sect = abfd->sections;
1706 p = (unsigned char *) bfd_get_section_name (abfd, sect);
1708 if (strcmp (p + len - 4, "data") == 0) /* ends in "data" */
1709 if (data_base == 0 ||
1710 data_base > bfd_get_section_vma (abfd, sect))
1711 data_base = bfd_get_section_vma (abfd, sect);
1712 if (strcmp (p + len - 3, "bss") == 0) /* ends in "bss" */
1713 if (bss_base == 0 ||
1714 bss_base > bfd_get_section_vma (abfd, sect))
1715 bss_base = bfd_get_section_vma (abfd, sect);
1717 *text_offs = text_addr - text_base;
1718 *data_offs = data_addr - data_base;
1719 *bss_offs = bss_addr - bss_base;
1724 sprintf (tmp, "VMA: text = 0x");
1725 sprintf_vma (tmp + strlen (tmp), text_addr);
1726 sprintf (tmp + strlen (tmp), " data = 0x");
1727 sprintf_vma (tmp + strlen (tmp), data_addr);
1728 sprintf (tmp + strlen (tmp), " bss = 0x");
1729 sprintf_vma (tmp + strlen (tmp), bss_addr);
1730 fprintf_filtered (gdb_stdlog, tmp);
1731 fprintf_filtered (gdb_stdlog,
1732 "Reloc offset: text = 0x%x data = 0x%x bss = 0x%x\n",
1733 (long) *text_offs, (long) *data_offs, (long) *bss_offs);
1740 * Function: remote_cisco_objfile_relocate
1742 * Relocate the symbol file for a remote target.
1746 remote_cisco_objfile_relocate (text_off, data_off, bss_off)
1747 bfd_signed_vma text_off;
1748 bfd_signed_vma data_off;
1749 bfd_signed_vma bss_off;
1751 struct section_offsets *offs;
1753 if (text_off != 0 || data_off != 0 || bss_off != 0)
1755 /* FIXME: This code assumes gdb-stabs.h is being used; it's
1756 broken for xcoff, dwarf, sdb-coff, etc. But there is no
1757 simple canonical representation for this stuff. */
1759 offs = ((struct section_offsets *)
1760 alloca (sizeof (struct section_offsets)
1761 + (symfile_objfile->num_sections
1762 * sizeof (offs->offsets))));
1764 memcpy (offs, symfile_objfile->section_offsets,
1765 (sizeof (struct section_offsets)
1766 + (symfile_objfile->num_sections
1767 * sizeof (offs->offsets))));
1769 ANOFFSET (offs, SECT_OFF_TEXT) = text_off;
1770 ANOFFSET (offs, SECT_OFF_DATA) = data_off;
1771 ANOFFSET (offs, SECT_OFF_BSS) = bss_off;
1773 /* First call the standard objfile_relocate. */
1774 objfile_relocate (symfile_objfile, offs);
1776 /* Now we need to fix up the section entries already attached to
1777 the exec target. These entries will control memory transfers
1778 from the exec file. */
1780 exec_set_section_offsets (text_off, data_off, bss_off);
1784 /* Stub for catch_errors. */
1787 remote_start_remote_dummy (dummy)
1790 start_remote (); /* Initialize gdb process mechanisms */
1795 remote_start_remote (dummy)
1798 immediate_quit = 1; /* Allow user to interrupt it */
1800 /* Ack any packet which the remote side has already sent. */
1801 SERIAL_WRITE (remote_desc, "+", 1);
1803 /* Let the stub know that we want it to return the thread. */
1806 inferior_pid = remote_current_thread (inferior_pid);
1808 get_offsets (); /* Get text, data & bss offsets */
1810 putpkt ("?"); /* initiate a query from remote machine */
1813 return remote_start_remote_dummy (dummy);
1816 /* Open a connection to a remote debugger.
1817 NAME is the filename used for communication. */
1820 remote_open (name, from_tty)
1824 remote_open_1 (name, from_tty, &remote_ops, 0);
1827 /* Just like remote_open, but with asynchronous support. */
1829 remote_async_open (name, from_tty)
1833 remote_async_open_1 (name, from_tty, &remote_async_ops, 0);
1836 /* Open a connection to a remote debugger using the extended
1837 remote gdb protocol. NAME is the filename used for communication. */
1840 extended_remote_open (name, from_tty)
1844 remote_open_1 (name, from_tty, &extended_remote_ops, 1 /*extended_p */ );
1847 /* Just like extended_remote_open, but with asynchronous support. */
1849 extended_remote_async_open (name, from_tty)
1853 remote_async_open_1 (name, from_tty, &extended_async_remote_ops, 1 /*extended_p */ );
1856 /* Generic code for opening a connection to a remote target. */
1858 static DCACHE *remote_dcache;
1861 remote_open_1 (name, from_tty, target, extended_p)
1864 struct target_ops *target;
1868 error ("To open a remote debug connection, you need to specify what\n\
1869 serial device is attached to the remote system (e.g. /dev/ttya).");
1871 target_preopen (from_tty);
1873 unpush_target (target);
1875 remote_dcache = dcache_init (remote_read_bytes, remote_write_bytes);
1877 remote_desc = SERIAL_OPEN (name);
1879 perror_with_name (name);
1881 if (baud_rate != -1)
1883 if (SERIAL_SETBAUDRATE (remote_desc, baud_rate))
1885 SERIAL_CLOSE (remote_desc);
1886 perror_with_name (name);
1890 SERIAL_RAW (remote_desc);
1892 /* If there is something sitting in the buffer we might take it as a
1893 response to a command, which would be bad. */
1894 SERIAL_FLUSH_INPUT (remote_desc);
1898 puts_filtered ("Remote debugging using ");
1899 puts_filtered (name);
1900 puts_filtered ("\n");
1902 push_target (target); /* Switch to using remote target now */
1904 init_packet_config (&remote_protocol_P);
1906 general_thread = -2;
1907 continue_thread = -2;
1909 /* Force remote_write_bytes to check whether target supports
1910 binary downloading. */
1911 remote_binary_checked = 0;
1913 /* Without this, some commands which require an active target (such
1914 as kill) won't work. This variable serves (at least) double duty
1915 as both the pid of the target process (if it has such), and as a
1916 flag indicating that a target is active. These functions should
1917 be split out into seperate variables, especially since GDB will
1918 someday have a notion of debugging several processes. */
1920 inferior_pid = MAGIC_NULL_PID;
1921 /* Start the remote connection; if error (0), discard this target.
1922 In particular, if the user quits, be sure to discard it
1923 (we'd be in an inconsistent state otherwise). */
1924 if (!catch_errors (remote_start_remote, NULL,
1925 "Couldn't establish connection to remote target\n",
1934 /* tell the remote that we're using the extended protocol. */
1935 char *buf = alloca (PBUFSIZ);
1941 /* Just like remote_open but with asynchronous support. */
1943 remote_async_open_1 (name, from_tty, target, extended_p)
1946 struct target_ops *target;
1950 error ("To open a remote debug connection, you need to specify what\n\
1951 serial device is attached to the remote system (e.g. /dev/ttya).");
1953 target_preopen (from_tty);
1955 unpush_target (target);
1957 remote_dcache = dcache_init (remote_read_bytes, remote_write_bytes);
1959 remote_desc = SERIAL_OPEN (name);
1961 perror_with_name (name);
1963 if (baud_rate != -1)
1965 if (SERIAL_SETBAUDRATE (remote_desc, baud_rate))
1967 SERIAL_CLOSE (remote_desc);
1968 perror_with_name (name);
1972 SERIAL_RAW (remote_desc);
1974 /* If there is something sitting in the buffer we might take it as a
1975 response to a command, which would be bad. */
1976 SERIAL_FLUSH_INPUT (remote_desc);
1980 puts_filtered ("Remote debugging using ");
1981 puts_filtered (name);
1982 puts_filtered ("\n");
1985 /* If running in asynchronous mode, register the target with the
1986 event loop. Set things up so that when there is an event on the
1987 file descriptor, the event loop will call fetch_inferior_event,
1988 which will do the proper analysis to determine what happened. */
1990 add_file_handler (remote_desc->fd, (file_handler_func *) fetch_inferior_event, 0);
1992 push_target (target); /* Switch to using remote target now */
1994 init_packet_config (&remote_protocol_P);
1996 general_thread = -2;
1997 continue_thread = -2;
1999 /* Force remote_write_bytes to check whether target supports
2000 binary downloading. */
2001 remote_binary_checked = 0;
2003 /* If running asynchronously, set things up for telling the target
2004 to use the extended protocol. This will happen only after the
2005 target has been connected to, in fetch_inferior_event. */
2006 if (extended_p && async_p)
2007 add_continuation (set_extended_protocol, NULL);
2009 /* Without this, some commands which require an active target (such
2010 as kill) won't work. This variable serves (at least) double duty
2011 as both the pid of the target process (if it has such), and as a
2012 flag indicating that a target is active. These functions should
2013 be split out into seperate variables, especially since GDB will
2014 someday have a notion of debugging several processes. */
2016 inferior_pid = MAGIC_NULL_PID;
2017 /* Start the remote connection; if error (0), discard this target.
2018 In particular, if the user quits, be sure to discard it
2019 (we'd be in an inconsistent state otherwise). */
2020 if (!catch_errors (remote_start_remote, NULL,
2021 "Couldn't establish connection to remote target\n",
2024 /* Unregister the file descriptor from the event loop. */
2026 delete_file_handler (remote_desc->fd);
2035 /* tell the remote that we're using the extended protocol. */
2036 char *buf = alloca (PBUFSIZ);
2043 /* This will be called by fetch_inferior_event, via the
2044 cmd_continuation pointer, only after the target has stopped. */
2046 set_extended_protocol (arg)
2047 struct continuation_arg *arg;
2049 /* tell the remote that we're using the extended protocol. */
2050 char *buf = alloca (PBUFSIZ);
2055 /* This takes a program previously attached to and detaches it. After
2056 this is done, GDB can be used to debug some other program. We
2057 better not have left any breakpoints in the target program or it'll
2058 die when it hits one. */
2061 remote_detach (args, from_tty)
2065 char *buf = alloca (PBUFSIZ);
2068 error ("Argument given to \"detach\" when remotely debugging.");
2070 /* Tell the remote target to detach. */
2076 puts_filtered ("Ending remote debugging.\n");
2079 /* Same as remote_detach, but with async support. */
2081 remote_async_detach (args, from_tty)
2085 char *buf = alloca (PBUFSIZ);
2088 error ("Argument given to \"detach\" when remotely debugging.");
2090 /* Tell the remote target to detach. */
2094 /* Unregister the file descriptor from the event loop. */
2096 delete_file_handler (remote_desc->fd);
2100 puts_filtered ("Ending remote debugging.\n");
2103 /* Convert hex digit A to a number. */
2109 if (a >= '0' && a <= '9')
2111 else if (a >= 'a' && a <= 'f')
2112 return a - 'a' + 10;
2113 else if (a >= 'A' && a <= 'F')
2114 return a - 'A' + 10;
2116 error ("Reply contains invalid hex digit %d", a);
2119 /* Convert number NIB to a hex digit. */
2128 return 'a' + nib - 10;
2131 /* Tell the remote machine to resume. */
2133 static enum target_signal last_sent_signal = TARGET_SIGNAL_0;
2135 static int last_sent_step;
2138 remote_resume (pid, step, siggnal)
2140 enum target_signal siggnal;
2142 char *buf = alloca (PBUFSIZ);
2145 set_thread (0, 0); /* run any thread */
2147 set_thread (pid, 0); /* run this thread */
2149 dcache_flush (remote_dcache);
2151 last_sent_signal = siggnal;
2152 last_sent_step = step;
2154 /* A hook for when we need to do something at the last moment before
2156 if (target_resume_hook)
2157 (*target_resume_hook) ();
2159 if (siggnal != TARGET_SIGNAL_0)
2161 buf[0] = step ? 'S' : 'C';
2162 buf[1] = tohex (((int) siggnal >> 4) & 0xf);
2163 buf[2] = tohex ((int) siggnal & 0xf);
2167 strcpy (buf, step ? "s" : "c");
2172 /* Same as remote_resume, but with async support. */
2174 remote_async_resume (pid, step, siggnal)
2176 enum target_signal siggnal;
2178 char *buf = alloca (PBUFSIZ);
2181 set_thread (0, 0); /* run any thread */
2183 set_thread (pid, 0); /* run this thread */
2185 dcache_flush (remote_dcache);
2187 last_sent_signal = siggnal;
2188 last_sent_step = step;
2190 /* A hook for when we need to do something at the last moment before
2192 if (target_resume_hook)
2193 (*target_resume_hook) ();
2195 /* Set things up before execution starts for async commands. */
2196 /* This function can be entered more than once for the same execution
2197 command, because it is also called by handle_inferior_event. So
2198 we make sure that we don't do the initialization for sync
2199 execution more than once. */
2200 if (async_p && !target_executing)
2202 target_executing = 1;
2204 /* If the command must look synchronous, fake it, by making gdb
2205 display an empty prompt after the command has completed. Also
2209 push_prompt ("", "", "");
2210 delete_file_handler (input_fd);
2211 initialize_sigint_signal_handler ();
2215 if (siggnal != TARGET_SIGNAL_0)
2217 buf[0] = step ? 'S' : 'C';
2218 buf[1] = tohex (((int) siggnal >> 4) & 0xf);
2219 buf[2] = tohex ((int) siggnal & 0xf);
2223 strcpy (buf, step ? "s" : "c");
2229 /* Set up the signal handler for SIGINT, while the target is
2230 executing, ovewriting the 'regular' SIGINT signal handler. */
2232 initialize_sigint_signal_handler ()
2234 sigint_remote_token =
2235 create_async_signal_handler (async_remote_interrupt, NULL);
2236 signal (SIGINT, handle_remote_sigint);
2239 /* Signal handler for SIGINT, while the target is executing. */
2241 handle_remote_sigint (sig)
2244 signal (sig, handle_remote_sigint_twice);
2245 sigint_remote_twice_token =
2246 create_async_signal_handler (async_remote_interrupt_twice, NULL);
2247 mark_async_signal_handler_wrapper (sigint_remote_token);
2250 /* Signal handler for SIGINT, installed after SIGINT has already been
2251 sent once. It will take effect the second time that the user sends
2254 handle_remote_sigint_twice (sig)
2257 signal (sig, handle_sigint);
2258 sigint_remote_twice_token =
2259 create_async_signal_handler (async_remote_interrupt, NULL);
2260 mark_async_signal_handler_wrapper (sigint_remote_twice_token);
2263 /* Perform the real interruption of hte target execution, in response
2266 async_remote_interrupt (arg)
2267 gdb_client_data arg;
2270 fprintf_unfiltered (gdb_stdlog, "remote_interrupt called\n");
2275 /* Perform interrupt, if the first attempt did not succeed. Just give
2276 up on the target alltogether. */
2278 async_remote_interrupt_twice (arg)
2279 gdb_client_data arg;
2282 signal (SIGINT, handle_remote_sigint);
2285 /* Reinstall the usual SIGINT handlers, after the target has
2288 cleanup_sigint_signal_handler ()
2290 signal (SIGINT, handle_sigint);
2291 if (sigint_remote_twice_token)
2292 delete_async_signal_handler ((async_signal_handler **) & sigint_remote_twice_token);
2293 if (sigint_remote_token)
2294 delete_async_signal_handler ((async_signal_handler **) & sigint_remote_token);
2297 /* Send ^C to target to halt it. Target will respond, and send us a
2299 static void (*ofunc) PARAMS ((int));
2301 /* The command line interface's stop routine. This function is installed
2302 as a signal handler for SIGINT. The first time a user requests a
2303 stop, we call remote_stop to send a break or ^C. If there is no
2304 response from the target (it didn't stop when the user requested it),
2305 we ask the user if he'd like to detach from the target. */
2307 remote_interrupt (signo)
2310 /* If this doesn't work, try more severe steps. */
2311 signal (signo, remote_interrupt_twice);
2314 fprintf_unfiltered (gdb_stdlog, "remote_interrupt called\n");
2319 /* The user typed ^C twice. */
2322 remote_interrupt_twice (signo)
2325 signal (signo, ofunc);
2327 signal (signo, remote_interrupt);
2330 /* This is the generic stop called via the target vector. When a target
2331 interrupt is requested, either by the command line or the GUI, we
2332 will eventually end up here. */
2336 /* Send a break or a ^C, depending on user preference. */
2338 fprintf_unfiltered (gdb_stdlog, "remote_stop called\n");
2341 SERIAL_SEND_BREAK (remote_desc);
2343 SERIAL_WRITE (remote_desc, "\003", 1);
2346 /* Ask the user what to do when an interrupt is received. */
2351 target_terminal_ours ();
2353 if (query ("Interrupted while waiting for the program.\n\
2354 Give up (and stop debugging it)? "))
2356 target_mourn_inferior ();
2357 return_to_top_level (RETURN_QUIT);
2360 target_terminal_inferior ();
2363 /* If nonzero, ignore the next kill. */
2368 remote_console_output (msg)
2373 for (p = msg; p[0] && p[1]; p += 2)
2376 char c = fromhex (p[0]) * 16 + fromhex (p[1]);
2379 fputs_unfiltered (tb, gdb_stdtarg);
2383 /* Wait until the remote machine stops, then return,
2384 storing status in STATUS just as `wait' would.
2385 Returns "pid", which in the case of a multi-threaded
2386 remote OS, is the thread-id. */
2389 remote_wait (pid, status)
2391 struct target_waitstatus *status;
2393 unsigned char *buf = alloca (PBUFSIZ);
2394 int thread_num = -1;
2396 status->kind = TARGET_WAITKIND_EXITED;
2397 status->value.integer = 0;
2403 ofunc = signal (SIGINT, remote_interrupt);
2404 getpkt ((char *) buf, 1);
2405 signal (SIGINT, ofunc);
2407 /* This is a hook for when we need to do something (perhaps the
2408 collection of trace data) every time the target stops. */
2409 if (target_wait_loop_hook)
2410 (*target_wait_loop_hook) ();
2414 case 'E': /* Error of some sort */
2415 warning ("Remote failure reply: %s", buf);
2417 case 'T': /* Status with PC, SP, FP, ... */
2421 char regs[MAX_REGISTER_RAW_SIZE];
2423 /* Expedited reply, containing Signal, {regno, reg} repeat */
2424 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2426 n... = register number
2427 r... = register contents
2429 p = &buf[3]; /* after Txx */
2436 /* Read the register number */
2437 regno = strtol ((const char *) p, &p_temp, 16);
2438 p1 = (unsigned char *) p_temp;
2440 if (p1 == p) /* No register number present here */
2442 p1 = (unsigned char *) strchr ((const char *) p, ':');
2444 warning ("Malformed packet(a) (missing colon): %s\n\
2447 if (strncmp ((const char *) p, "thread", p1 - p) == 0)
2449 p_temp = unpack_varlen_hex (++p1, &thread_num);
2450 record_currthread (thread_num);
2451 p = (unsigned char *) p_temp;
2459 warning ("Malformed packet(b) (missing colon): %s\n\
2463 if (regno >= NUM_REGS)
2464 warning ("Remote sent bad register number %ld: %s\n\
2468 for (i = 0; i < REGISTER_RAW_SIZE (regno); i++)
2470 if (p[0] == 0 || p[1] == 0)
2471 warning ("Remote reply is too short: %s", buf);
2472 regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
2475 supply_register (regno, regs);
2480 warning ("Remote register badly formatted: %s", buf);
2481 warning (" here: %s", p);
2486 case 'S': /* Old style status, just signal only */
2487 status->kind = TARGET_WAITKIND_STOPPED;
2488 status->value.sig = (enum target_signal)
2489 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2493 /* Export Cisco kernel mode as a convenience variable
2494 (so that it can be used in the GDB prompt if desired). */
2496 if (cisco_kernel_mode == 1)
2497 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2498 value_from_string ("PDEBUG-"));
2499 cisco_kernel_mode = 0;
2500 thread_num = strtol ((const char *) &buf[4], NULL, 16);
2501 record_currthread (thread_num);
2503 else if (buf[3] == 'k')
2505 /* Export Cisco kernel mode as a convenience variable
2506 (so that it can be used in the GDB prompt if desired). */
2508 if (cisco_kernel_mode == 1)
2509 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2510 value_from_string ("KDEBUG-"));
2511 cisco_kernel_mode = 1;
2514 case 'N': /* Cisco special: status and offsets */
2516 bfd_vma text_addr, data_addr, bss_addr;
2517 bfd_signed_vma text_off, data_off, bss_off;
2520 status->kind = TARGET_WAITKIND_STOPPED;
2521 status->value.sig = (enum target_signal)
2522 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2524 if (symfile_objfile == NULL)
2526 warning ("Relocation packet recieved with no symbol file. \
2531 /* Relocate object file. Buffer format is NAATT;DD;BB
2532 * where AA is the signal number, TT is the new text
2533 * address, DD * is the new data address, and BB is the
2534 * new bss address. */
2537 text_addr = strtoul (p, (char **) &p1, 16);
2538 if (p1 == p || *p1 != ';')
2539 warning ("Malformed relocation packet: Packet '%s'", buf);
2541 data_addr = strtoul (p, (char **) &p1, 16);
2542 if (p1 == p || *p1 != ';')
2543 warning ("Malformed relocation packet: Packet '%s'", buf);
2545 bss_addr = strtoul (p, (char **) &p1, 16);
2547 warning ("Malformed relocation packet: Packet '%s'", buf);
2549 if (remote_cisco_section_offsets (text_addr, data_addr, bss_addr,
2550 &text_off, &data_off, &bss_off)
2552 if (text_off != 0 || data_off != 0 || bss_off != 0)
2553 remote_cisco_objfile_relocate (text_off, data_off, bss_off);
2557 case 'W': /* Target exited */
2559 /* The remote process exited. */
2560 status->kind = TARGET_WAITKIND_EXITED;
2561 status->value.integer = (fromhex (buf[1]) << 4) + fromhex (buf[2]);
2565 status->kind = TARGET_WAITKIND_SIGNALLED;
2566 status->value.sig = (enum target_signal)
2567 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2571 case 'O': /* Console output */
2572 remote_console_output (buf + 1);
2575 if (last_sent_signal != TARGET_SIGNAL_0)
2577 /* Zero length reply means that we tried 'S' or 'C' and
2578 the remote system doesn't support it. */
2579 target_terminal_ours_for_output ();
2581 ("Can't send signals to this remote system. %s not sent.\n",
2582 target_signal_to_name (last_sent_signal));
2583 last_sent_signal = TARGET_SIGNAL_0;
2584 target_terminal_inferior ();
2586 strcpy ((char *) buf, last_sent_step ? "s" : "c");
2587 putpkt ((char *) buf);
2590 /* else fallthrough */
2592 warning ("Invalid remote reply: %s", buf);
2597 if (thread_num != -1)
2601 return inferior_pid;
2604 /* Async version of remote_wait. */
2606 remote_async_wait (pid, status)
2608 struct target_waitstatus *status;
2610 unsigned char *buf = alloca (PBUFSIZ);
2611 int thread_num = -1;
2613 status->kind = TARGET_WAITKIND_EXITED;
2614 status->value.integer = 0;
2621 ofunc = signal (SIGINT, remote_interrupt);
2622 getpkt ((char *) buf, 1);
2624 signal (SIGINT, ofunc);
2626 /* This is a hook for when we need to do something (perhaps the
2627 collection of trace data) every time the target stops. */
2628 if (target_wait_loop_hook)
2629 (*target_wait_loop_hook) ();
2633 case 'E': /* Error of some sort */
2634 warning ("Remote failure reply: %s", buf);
2636 case 'T': /* Status with PC, SP, FP, ... */
2640 char regs[MAX_REGISTER_RAW_SIZE];
2642 /* Expedited reply, containing Signal, {regno, reg} repeat */
2643 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2645 n... = register number
2646 r... = register contents
2648 p = &buf[3]; /* after Txx */
2655 /* Read the register number */
2656 regno = strtol ((const char *) p, &p_temp, 16);
2657 p1 = (unsigned char *) p_temp;
2659 if (p1 == p) /* No register number present here */
2661 p1 = (unsigned char *) strchr ((const char *) p, ':');
2663 warning ("Malformed packet(a) (missing colon): %s\n\
2666 if (strncmp ((const char *) p, "thread", p1 - p) == 0)
2668 p_temp = unpack_varlen_hex (++p1, &thread_num);
2669 record_currthread (thread_num);
2670 p = (unsigned char *) p_temp;
2678 warning ("Malformed packet(b) (missing colon): %s\n\
2682 if (regno >= NUM_REGS)
2683 warning ("Remote sent bad register number %ld: %s\n\
2687 for (i = 0; i < REGISTER_RAW_SIZE (regno); i++)
2689 if (p[0] == 0 || p[1] == 0)
2690 warning ("Remote reply is too short: %s", buf);
2691 regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
2694 supply_register (regno, regs);
2699 warning ("Remote register badly formatted: %s", buf);
2700 warning (" here: %s", p);
2705 case 'S': /* Old style status, just signal only */
2706 status->kind = TARGET_WAITKIND_STOPPED;
2707 status->value.sig = (enum target_signal)
2708 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2712 /* Export Cisco kernel mode as a convenience variable
2713 (so that it can be used in the GDB prompt if desired). */
2715 if (cisco_kernel_mode == 1)
2716 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2717 value_from_string ("PDEBUG-"));
2718 cisco_kernel_mode = 0;
2719 thread_num = strtol ((const char *) &buf[4], NULL, 16);
2720 record_currthread (thread_num);
2722 else if (buf[3] == 'k')
2724 /* Export Cisco kernel mode as a convenience variable
2725 (so that it can be used in the GDB prompt if desired). */
2727 if (cisco_kernel_mode == 1)
2728 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2729 value_from_string ("KDEBUG-"));
2730 cisco_kernel_mode = 1;
2733 case 'N': /* Cisco special: status and offsets */
2735 bfd_vma text_addr, data_addr, bss_addr;
2736 bfd_signed_vma text_off, data_off, bss_off;
2739 status->kind = TARGET_WAITKIND_STOPPED;
2740 status->value.sig = (enum target_signal)
2741 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2743 if (symfile_objfile == NULL)
2745 warning ("Relocation packet recieved with no symbol file. \
2750 /* Relocate object file. Buffer format is NAATT;DD;BB
2751 * where AA is the signal number, TT is the new text
2752 * address, DD * is the new data address, and BB is the
2753 * new bss address. */
2756 text_addr = strtoul (p, (char **) &p1, 16);
2757 if (p1 == p || *p1 != ';')
2758 warning ("Malformed relocation packet: Packet '%s'", buf);
2760 data_addr = strtoul (p, (char **) &p1, 16);
2761 if (p1 == p || *p1 != ';')
2762 warning ("Malformed relocation packet: Packet '%s'", buf);
2764 bss_addr = strtoul (p, (char **) &p1, 16);
2766 warning ("Malformed relocation packet: Packet '%s'", buf);
2768 if (remote_cisco_section_offsets (text_addr, data_addr, bss_addr,
2769 &text_off, &data_off, &bss_off)
2771 if (text_off != 0 || data_off != 0 || bss_off != 0)
2772 remote_cisco_objfile_relocate (text_off, data_off, bss_off);
2776 case 'W': /* Target exited */
2778 /* The remote process exited. */
2779 status->kind = TARGET_WAITKIND_EXITED;
2780 status->value.integer = (fromhex (buf[1]) << 4) + fromhex (buf[2]);
2784 status->kind = TARGET_WAITKIND_SIGNALLED;
2785 status->value.sig = (enum target_signal)
2786 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2790 case 'O': /* Console output */
2791 remote_console_output (buf + 1);
2794 if (last_sent_signal != TARGET_SIGNAL_0)
2796 /* Zero length reply means that we tried 'S' or 'C' and
2797 the remote system doesn't support it. */
2798 target_terminal_ours_for_output ();
2800 ("Can't send signals to this remote system. %s not sent.\n",
2801 target_signal_to_name (last_sent_signal));
2802 last_sent_signal = TARGET_SIGNAL_0;
2803 target_terminal_inferior ();
2805 strcpy ((char *) buf, last_sent_step ? "s" : "c");
2806 putpkt ((char *) buf);
2809 /* else fallthrough */
2811 warning ("Invalid remote reply: %s", buf);
2816 if (thread_num != -1)
2820 return inferior_pid;
2823 /* Number of bytes of registers this stub implements. */
2825 static int register_bytes_found;
2827 /* Read the remote registers into the block REGS. */
2828 /* Currently we just read all the registers, so we don't use regno. */
2832 remote_fetch_registers (regno)
2835 char *buf = alloca (PBUFSIZ);
2838 char regs[REGISTER_BYTES];
2840 set_thread (inferior_pid, 1);
2845 if (remote_register_buf_size == 0)
2846 remote_register_buf_size = strlen (buf);
2848 /* Unimplemented registers read as all bits zero. */
2849 memset (regs, 0, REGISTER_BYTES);
2851 /* We can get out of synch in various cases. If the first character
2852 in the buffer is not a hex character, assume that has happened
2853 and try to fetch another packet to read. */
2854 while ((buf[0] < '0' || buf[0] > '9')
2855 && (buf[0] < 'a' || buf[0] > 'f')
2856 && buf[0] != 'x') /* New: unavailable register value */
2859 fprintf_unfiltered (gdb_stdlog,
2860 "Bad register packet; fetching a new packet\n");
2864 /* Reply describes registers byte by byte, each byte encoded as two
2865 hex characters. Suck them all up, then supply them to the
2866 register cacheing/storage mechanism. */
2869 for (i = 0; i < REGISTER_BYTES; i++)
2875 warning ("Remote reply is of odd length: %s", buf);
2876 /* Don't change register_bytes_found in this case, and don't
2877 print a second warning. */
2880 if (p[0] == 'x' && p[1] == 'x')
2881 regs[i] = 0; /* 'x' */
2883 regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
2887 if (i != register_bytes_found)
2889 register_bytes_found = i;
2890 #ifdef REGISTER_BYTES_OK
2891 if (!REGISTER_BYTES_OK (i))
2892 warning ("Remote reply is too short: %s", buf);
2897 for (i = 0; i < NUM_REGS; i++)
2899 supply_register (i, ®s[REGISTER_BYTE (i)]);
2900 if (buf[REGISTER_BYTE (i) * 2] == 'x')
2901 register_valid[i] = -1; /* register value not available */
2905 /* Prepare to store registers. Since we may send them all (using a
2906 'G' request), we have to read out the ones we don't want to change
2910 remote_prepare_to_store ()
2912 /* Make sure the entire registers array is valid. */
2913 switch (remote_protocol_P.support)
2915 case PACKET_DISABLE:
2916 case PACKET_SUPPORT_UNKNOWN:
2917 read_register_bytes (0, (char *) NULL, REGISTER_BYTES);
2924 /* Helper: Attempt to store REGNO using the P packet. Return fail IFF
2925 packet was not recognized. */
2928 store_register_using_P (regno)
2931 /* Try storing a single register. */
2932 char *buf = alloca (PBUFSIZ);
2937 sprintf (buf, "P%x=", regno);
2938 p = buf + strlen (buf);
2939 regp = ®isters[REGISTER_BYTE (regno)];
2940 for (i = 0; i < REGISTER_RAW_SIZE (regno); ++i)
2942 *p++ = tohex ((regp[i] >> 4) & 0xf);
2943 *p++ = tohex (regp[i] & 0xf);
2948 return buf[0] != '\0';
2952 /* Store register REGNO, or all registers if REGNO == -1, from the contents
2953 of REGISTERS. FIXME: ignores errors. */
2956 remote_store_registers (regno)
2959 char *buf = alloca (PBUFSIZ);
2963 set_thread (inferior_pid, 1);
2967 switch (remote_protocol_P.support)
2969 case PACKET_DISABLE:
2972 if (store_register_using_P (regno))
2975 error ("Protocol error: P packet not recognized by stub");
2976 case PACKET_SUPPORT_UNKNOWN:
2977 if (store_register_using_P (regno))
2979 /* The stub recognized the 'P' packet. Remember this. */
2980 remote_protocol_P.support = PACKET_ENABLE;
2985 /* The stub does not support the 'P' packet. Use 'G'
2986 instead, and don't try using 'P' in the future (it
2987 will just waste our time). */
2988 remote_protocol_P.support = PACKET_DISABLE;
2996 /* Command describes registers byte by byte,
2997 each byte encoded as two hex characters. */
3000 /* remote_prepare_to_store insures that register_bytes_found gets set. */
3001 for (i = 0; i < register_bytes_found; i++)
3003 *p++ = tohex ((registers[i] >> 4) & 0xf);
3004 *p++ = tohex (registers[i] & 0xf);
3011 /* Use of the data cache *used* to be disabled because it loses for looking
3012 at and changing hardware I/O ports and the like. Accepting `volatile'
3013 would perhaps be one way to fix it. Another idea would be to use the
3014 executable file for the text segment (for all SEC_CODE sections?
3015 For all SEC_READONLY sections?). This has problems if you want to
3016 actually see what the memory contains (e.g. self-modifying code,
3017 clobbered memory, user downloaded the wrong thing).
3019 Because it speeds so much up, it's now enabled, if you're playing
3020 with registers you turn it of (set remotecache 0). */
3022 /* Read a word from remote address ADDR and return it.
3023 This goes through the data cache. */
3027 remote_fetch_word (addr)
3030 return dcache_fetch (remote_dcache, addr);
3033 /* Write a word WORD into remote address ADDR.
3034 This goes through the data cache. */
3037 remote_store_word (addr, word)
3041 dcache_poke (remote_dcache, addr, word);
3043 #endif /* 0 (unused?) */
3047 /* Return the number of hex digits in num. */
3055 for (i = 0; num != 0; i++)
3061 /* Set BUF to the hex digits representing NUM. */
3064 hexnumstr (buf, num)
3069 int len = hexnumlen (num);
3073 for (i = len - 1; i >= 0; i--)
3075 buf[i] = "0123456789abcdef"[(num & 0xf)];
3082 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
3085 remote_address_masked (addr)
3088 if (remote_address_size > 0
3089 && remote_address_size < (sizeof (ULONGEST) * 8))
3091 /* Only create a mask when that mask can safely be constructed
3092 in a ULONGEST variable. */
3094 mask = (mask << remote_address_size) - 1;
3100 /* Determine whether the remote target supports binary downloading.
3101 This is accomplished by sending a no-op memory write of zero length
3102 to the target at the specified address. It does not suffice to send
3103 the whole packet, since many stubs strip the eighth bit and subsequently
3104 compute a wrong checksum, which causes real havoc with remote_write_bytes.
3106 NOTE: This can still lose if the serial line is not eight-bit clean. In
3107 cases like this, the user should clear "remotebinarydownload". */
3109 check_binary_download (addr)
3112 if (remote_binary_download && !remote_binary_checked)
3114 char *buf = alloca (PBUFSIZ);
3116 remote_binary_checked = 1;
3120 p += hexnumstr (p, (ULONGEST) addr);
3122 p += hexnumstr (p, (ULONGEST) 0);
3126 putpkt_binary (buf, (int) (p - buf));
3130 remote_binary_download = 0;
3135 if (remote_binary_download)
3136 fprintf_unfiltered (gdb_stdlog,
3137 "binary downloading suppported by target\n");
3139 fprintf_unfiltered (gdb_stdlog,
3140 "binary downloading NOT suppported by target\n");
3144 /* Write memory data directly to the remote machine.
3145 This does not inform the data cache; the data cache uses this.
3146 MEMADDR is the address in the remote memory space.
3147 MYADDR is the address of the buffer in our space.
3148 LEN is the number of bytes.
3150 Returns number of bytes transferred, or 0 for error. */
3153 remote_write_bytes (memaddr, myaddr, len)
3158 unsigned char *buf = alloca (PBUFSIZ);
3159 int max_buf_size; /* Max size of packet output buffer */
3162 /* Verify that the target can support a binary download */
3163 check_binary_download (memaddr);
3165 /* Chop the transfer down if necessary */
3167 max_buf_size = min (remote_write_size, PBUFSIZ);
3168 if (remote_register_buf_size != 0)
3169 max_buf_size = min (max_buf_size, remote_register_buf_size);
3171 /* Subtract header overhead from max payload size - $M<memaddr>,<len>:#nn */
3172 max_buf_size -= 2 + hexnumlen (memaddr + len - 1) + 1 + hexnumlen (len) + 4;
3177 unsigned char *p, *plen;
3181 /* construct "M"<memaddr>","<len>":" */
3182 /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
3183 memaddr = remote_address_masked (memaddr);
3185 if (remote_binary_download)
3188 todo = min (len, max_buf_size);
3193 todo = min (len, max_buf_size / 2); /* num bytes that will fit */
3196 p += hexnumstr (p, (ULONGEST) memaddr);
3199 plen = p; /* remember where len field goes */
3200 p += hexnumstr (p, (ULONGEST) todo);
3204 /* We send target system values byte by byte, in increasing byte
3205 addresses, each byte encoded as two hex characters (or one
3206 binary character). */
3207 if (remote_binary_download)
3211 (i < todo) && (i + escaped) < (max_buf_size - 2);
3214 switch (myaddr[i] & 0xff)
3219 /* These must be escaped */
3222 *p++ = (myaddr[i] & 0xff) ^ 0x20;
3225 *p++ = myaddr[i] & 0xff;
3232 /* Escape chars have filled up the buffer prematurely,
3233 and we have actually sent fewer bytes than planned.
3234 Fix-up the length field of the packet. */
3236 /* FIXME: will fail if new len is a shorter string than
3239 plen += hexnumstr (plen, (ULONGEST) i);
3245 for (i = 0; i < todo; i++)
3247 *p++ = tohex ((myaddr[i] >> 4) & 0xf);
3248 *p++ = tohex (myaddr[i] & 0xf);
3253 putpkt_binary (buf, (int) (p - buf));
3258 /* There is no correspondance between what the remote protocol uses
3259 for errors and errno codes. We would like a cleaner way of
3260 representing errors (big enough to include errno codes, bfd_error
3261 codes, and others). But for now just return EIO. */
3266 /* Increment by i, not by todo, in case escape chars
3267 caused us to send fewer bytes than we'd planned. */
3275 /* Read memory data directly from the remote machine.
3276 This does not use the data cache; the data cache uses this.
3277 MEMADDR is the address in the remote memory space.
3278 MYADDR is the address of the buffer in our space.
3279 LEN is the number of bytes.
3281 Returns number of bytes transferred, or 0 for error. */
3284 remote_read_bytes (memaddr, myaddr, len)
3289 char *buf = alloca (PBUFSIZ);
3290 int max_buf_size; /* Max size of packet output buffer */
3293 /* Chop the transfer down if necessary */
3295 max_buf_size = min (remote_write_size, PBUFSIZ);
3296 if (remote_register_buf_size != 0)
3297 max_buf_size = min (max_buf_size, remote_register_buf_size);
3306 todo = min (len, max_buf_size / 2); /* num bytes that will fit */
3308 /* construct "m"<memaddr>","<len>" */
3309 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
3310 memaddr = remote_address_masked (memaddr);
3313 p += hexnumstr (p, (ULONGEST) memaddr);
3315 p += hexnumstr (p, (ULONGEST) todo);
3323 /* There is no correspondance between what the remote protocol uses
3324 for errors and errno codes. We would like a cleaner way of
3325 representing errors (big enough to include errno codes, bfd_error
3326 codes, and others). But for now just return EIO. */
3331 /* Reply describes memory byte by byte,
3332 each byte encoded as two hex characters. */
3335 for (i = 0; i < todo; i++)
3337 if (p[0] == 0 || p[1] == 0)
3338 /* Reply is short. This means that we were able to read
3339 only part of what we wanted to. */
3340 return i + (origlen - len);
3341 myaddr[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
3351 /* Read or write LEN bytes from inferior memory at MEMADDR,
3352 transferring to or from debugger address BUFFER. Write to inferior if
3353 SHOULD_WRITE is nonzero. Returns length of data written or read; 0
3356 #ifndef REMOTE_TRANSLATE_XFER_ADDRESS
3357 #define REMOTE_TRANSLATE_XFER_ADDRESS(MEM_ADDR, MEM_LEN, TARG_ADDR, TARG_LEN) \
3358 (*(TARG_ADDR) = (MEM_ADDR), *(TARG_LEN) = (MEM_LEN))
3363 remote_xfer_memory (mem_addr, buffer, mem_len, should_write, target)
3368 struct target_ops *target; /* ignored */
3370 CORE_ADDR targ_addr;
3372 REMOTE_TRANSLATE_XFER_ADDRESS (mem_addr, mem_len, &targ_addr, &targ_len);
3376 return dcache_xfer_memory (remote_dcache, targ_addr, buffer,
3377 targ_len, should_write);
3382 /* Enable after 4.12. */
3385 remote_search (len, data, mask, startaddr, increment, lorange, hirange
3386 addr_found, data_found)
3390 CORE_ADDR startaddr;
3394 CORE_ADDR *addr_found;
3397 if (increment == -4 && len == 4)
3399 long mask_long, data_long;
3400 long data_found_long;
3401 CORE_ADDR addr_we_found;
3402 char *buf = alloca (PBUFSIZ);
3403 long returned_long[2];
3406 mask_long = extract_unsigned_integer (mask, len);
3407 data_long = extract_unsigned_integer (data, len);
3408 sprintf (buf, "t%x:%x,%x", startaddr, data_long, mask_long);
3413 /* The stub doesn't support the 't' request. We might want to
3414 remember this fact, but on the other hand the stub could be
3415 switched on us. Maybe we should remember it only until
3416 the next "target remote". */
3417 generic_search (len, data, mask, startaddr, increment, lorange,
3418 hirange, addr_found, data_found);
3423 /* There is no correspondance between what the remote protocol uses
3424 for errors and errno codes. We would like a cleaner way of
3425 representing errors (big enough to include errno codes, bfd_error
3426 codes, and others). But for now just use EIO. */
3427 memory_error (EIO, startaddr);
3430 while (*p != '\0' && *p != ',')
3431 addr_we_found = (addr_we_found << 4) + fromhex (*p++);
3433 error ("Protocol error: short return for search");
3435 data_found_long = 0;
3436 while (*p != '\0' && *p != ',')
3437 data_found_long = (data_found_long << 4) + fromhex (*p++);
3438 /* Ignore anything after this comma, for future extensions. */
3440 if (addr_we_found < lorange || addr_we_found >= hirange)
3446 *addr_found = addr_we_found;
3447 *data_found = store_unsigned_integer (data_we_found, len);
3450 generic_search (len, data, mask, startaddr, increment, lorange,
3451 hirange, addr_found, data_found);
3456 remote_files_info (ignore)
3457 struct target_ops *ignore;
3459 puts_filtered ("Debugging a target over a serial line.\n");
3462 /* Stuff for dealing with the packets which are part of this protocol.
3463 See comment at top of file for details. */
3465 /* Read a single character from the remote end, masking it down to 7 bits. */
3473 ch = SERIAL_READCHAR (remote_desc, timeout);
3478 error ("Remote connection closed");
3480 perror_with_name ("Remote communication error");
3481 case SERIAL_TIMEOUT:
3488 /* Send the command in BUF to the remote machine, and read the reply
3489 into BUF. Report an error if we get an error reply. */
3499 error ("Remote failure reply: %s", buf);
3502 /* Display a null-terminated packet on stdout, for debugging, using C
3509 puts_filtered ("\"");
3510 fputstr_filtered (buf, '"', gdb_stdout);
3511 puts_filtered ("\"");
3518 return putpkt_binary (buf, strlen (buf));
3521 /* Send a packet to the remote machine, with error checking. The data
3522 of the packet is in BUF. The string in BUF can be at most PBUFSIZ - 5
3523 to account for the $, # and checksum, and for a possible /0 if we are
3524 debugging (remote_debug) and want to print the sent packet as a string */
3527 putpkt_binary (buf, cnt)
3532 unsigned char csum = 0;
3533 char *buf2 = alloca (PBUFSIZ);
3534 char *junkbuf = alloca (PBUFSIZ);
3540 /* Copy the packet into buffer BUF2, encapsulating it
3541 and giving it a checksum. */
3543 if (cnt > BUFSIZ - 5) /* Prosanity check */
3549 for (i = 0; i < cnt; i++)
3555 *p++ = tohex ((csum >> 4) & 0xf);
3556 *p++ = tohex (csum & 0xf);
3558 /* Send it over and over until we get a positive ack. */
3562 int started_error_output = 0;
3567 fprintf_unfiltered (gdb_stdlog, "Sending packet: ");
3568 fputstrn_unfiltered (buf2, p - buf2, 0, gdb_stdlog);
3569 fprintf_unfiltered (gdb_stdlog, "...", buf2);
3570 gdb_flush (gdb_stdlog);
3572 if (SERIAL_WRITE (remote_desc, buf2, p - buf2))
3573 perror_with_name ("putpkt: write failed");
3575 /* read until either a timeout occurs (-2) or '+' is read */
3578 ch = readchar (remote_timeout);
3585 case SERIAL_TIMEOUT:
3587 if (started_error_output)
3589 putchar_unfiltered ('\n');
3590 started_error_output = 0;
3599 fprintf_unfiltered (gdb_stdlog, "Ack\n");
3601 case SERIAL_TIMEOUT:
3605 break; /* Retransmit buffer */
3608 /* It's probably an old response, and we're out of sync.
3609 Just gobble up the packet and ignore it. */
3610 getpkt (junkbuf, 0);
3611 continue; /* Now, go look for + */
3616 if (!started_error_output)
3618 started_error_output = 1;
3619 fprintf_unfiltered (gdb_stdlog, "putpkt: Junk: ");
3621 fputc_unfiltered (ch & 0177, gdb_stdlog);
3625 break; /* Here to retransmit */
3629 /* This is wrong. If doing a long backtrace, the user should be
3630 able to get out next time we call QUIT, without anything as
3631 violent as interrupt_query. If we want to provide a way out of
3632 here without getting to the next QUIT, it should be based on
3633 hitting ^C twice as in remote_wait. */
3643 static int remote_cisco_mode;
3646 remote_cisco_expand (src, dest)
3657 repeat = (fromhex (src[1]) << 4) + fromhex (src[2]);
3658 for (i = 0; i < repeat; i++)
3660 *dest++ = *(src - 1);
3672 /* Come here after finding the start of the frame. Collect the rest
3673 into BUF, verifying the checksum, length, and handling run-length
3674 compression. Returns 0 on any error, 1 on success. */
3689 c = readchar (remote_timeout);
3693 case SERIAL_TIMEOUT:
3695 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog);
3699 fputs_filtered ("Saw new packet start in middle of old one\n",
3701 return 0; /* Start a new packet, count retries */
3704 unsigned char pktcsum;
3708 pktcsum = fromhex (readchar (remote_timeout)) << 4;
3709 pktcsum |= fromhex (readchar (remote_timeout));
3711 if (csum == pktcsum)
3713 if (remote_cisco_mode) /* variant run-length-encoding */
3715 char *tmp_buf = alloca (PBUFSIZ);
3717 remote_cisco_expand (buf, tmp_buf);
3718 strcpy (buf, tmp_buf);
3725 fprintf_filtered (gdb_stdlog,
3726 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
3728 fputs_filtered (buf, gdb_stdlog);
3729 fputs_filtered ("\n", gdb_stdlog);
3733 case '*': /* Run length encoding */
3734 if (remote_cisco_mode == 0) /* variant run-length-encoding */
3737 c = readchar (remote_timeout);
3739 c = c - ' ' + 3; /* Compute repeat count */
3741 if (c > 0 && c < 255 && bp + c - 1 < buf + PBUFSIZ - 1)
3743 memset (bp, *(bp - 1), c);
3749 printf_filtered ("Repeat count %d too large for buffer: ", c);
3750 puts_filtered (buf);
3751 puts_filtered ("\n");
3754 /* else fall thru to treat like default */
3756 if (bp < buf + PBUFSIZ - 1)
3764 puts_filtered ("Remote packet too long: ");
3765 puts_filtered (buf);
3766 puts_filtered ("\n");
3773 /* Read a packet from the remote machine, with error checking, and
3774 store it in BUF. BUF is expected to be of size PBUFSIZ. If
3775 FOREVER, wait forever rather than timing out; this is used while
3776 the target is executing user code. */
3779 getpkt (buf, forever)
3788 strcpy (buf, "timeout");
3792 timeout = watchdog > 0 ? watchdog : -1;
3796 timeout = remote_timeout;
3800 for (tries = 1; tries <= MAX_TRIES; tries++)
3802 /* This can loop forever if the remote side sends us characters
3803 continuously, but if it pauses, we'll get a zero from readchar
3804 because of timeout. Then we'll count that as a retry. */
3806 /* Note that we will only wait forever prior to the start of a packet.
3807 After that, we expect characters to arrive at a brisk pace. They
3808 should show up within remote_timeout intervals. */
3812 c = readchar (timeout);
3814 if (c == SERIAL_TIMEOUT)
3816 if (forever) /* Watchdog went off. Kill the target. */
3818 target_mourn_inferior ();
3819 error ("Watchdog has expired. Target detached.\n");
3822 fputs_filtered ("Timed out.\n", gdb_stdlog);
3828 /* We've found the start of a packet, now collect the data. */
3830 val = read_frame (buf);
3836 fprintf_unfiltered (gdb_stdlog, "Packet received: ");
3837 fputstr_unfiltered (buf, 0, gdb_stdlog);
3838 fprintf_unfiltered (gdb_stdlog, "\n");
3840 SERIAL_WRITE (remote_desc, "+", 1);
3844 /* Try the whole thing again. */
3846 SERIAL_WRITE (remote_desc, "-", 1);
3849 /* We have tried hard enough, and just can't receive the packet. Give up. */
3851 printf_unfiltered ("Ignoring packet error, continuing...\n");
3852 SERIAL_WRITE (remote_desc, "+", 1);
3858 /* For some mysterious reason, wait_for_inferior calls kill instead of
3859 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
3863 target_mourn_inferior ();
3867 /* Use catch_errors so the user can quit from gdb even when we aren't on
3868 speaking terms with the remote system. */
3869 catch_errors ((catch_errors_ftype *) putpkt, "k", "", RETURN_MASK_ERROR);
3871 /* Don't wait for it to die. I'm not really sure it matters whether
3872 we do or not. For the existing stubs, kill is a noop. */
3873 target_mourn_inferior ();
3876 /* Async version of remote_kill. */
3878 remote_async_kill ()
3880 /* Unregister the file descriptor from the event loop. */
3882 delete_file_handler (remote_desc->fd);
3884 /* For some mysterious reason, wait_for_inferior calls kill instead of
3885 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
3889 target_mourn_inferior ();
3893 /* Use catch_errors so the user can quit from gdb even when we aren't on
3894 speaking terms with the remote system. */
3895 catch_errors ((catch_errors_ftype *) putpkt, "k", "", RETURN_MASK_ERROR);
3897 /* Don't wait for it to die. I'm not really sure it matters whether
3898 we do or not. For the existing stubs, kill is a noop. */
3899 target_mourn_inferior ();
3905 remote_mourn_1 (&remote_ops);
3909 extended_remote_mourn ()
3911 /* We do _not_ want to mourn the target like this; this will
3912 remove the extended remote target from the target stack,
3913 and the next time the user says "run" it'll fail.
3915 FIXME: What is the right thing to do here? */
3917 remote_mourn_1 (&extended_remote_ops);
3921 /* Worker function for remote_mourn. */
3923 remote_mourn_1 (target)
3924 struct target_ops *target;
3926 unpush_target (target);
3927 generic_mourn_inferior ();
3930 /* In the extended protocol we want to be able to do things like
3931 "run" and have them basically work as expected. So we need
3932 a special create_inferior function.
3934 FIXME: One day add support for changing the exec file
3935 we're debugging, arguments and an environment. */
3938 extended_remote_create_inferior (exec_file, args, env)
3943 /* Rip out the breakpoints; we'll reinsert them after restarting
3944 the remote server. */
3945 remove_breakpoints ();
3947 /* Now restart the remote server. */
3948 extended_remote_restart ();
3950 /* Now put the breakpoints back in. This way we're safe if the
3951 restart function works via a unix fork on the remote side. */
3952 insert_breakpoints ();
3954 /* Clean up from the last time we were running. */
3955 clear_proceed_status ();
3957 /* Let the remote process run. */
3958 proceed (-1, TARGET_SIGNAL_0, 0);
3961 /* Async version of extended_remote_create_inferior. */
3963 extended_remote_async_create_inferior (exec_file, args, env)
3968 /* Rip out the breakpoints; we'll reinsert them after restarting
3969 the remote server. */
3970 remove_breakpoints ();
3972 /* If running asynchronously, register the target file descriptor
3973 with the event loop. */
3975 add_file_handler (remote_desc->fd, (file_handler_func *) fetch_inferior_event, 0);
3977 /* Now restart the remote server. */
3978 extended_remote_restart ();
3980 /* Now put the breakpoints back in. This way we're safe if the
3981 restart function works via a unix fork on the remote side. */
3982 insert_breakpoints ();
3984 /* Clean up from the last time we were running. */
3985 clear_proceed_status ();
3987 /* Let the remote process run. */
3988 proceed (-1, TARGET_SIGNAL_0, 0);
3992 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
3993 than other targets; in those use REMOTE_BREAKPOINT instead of just
3994 BREAKPOINT. Also, bi-endian targets may define LITTLE_REMOTE_BREAKPOINT
3995 and BIG_REMOTE_BREAKPOINT. If none of these are defined, we just call
3996 the standard routines that are in mem-break.c. */
3998 /* FIXME, these ought to be done in a more dynamic fashion. For instance,
3999 the choice of breakpoint instruction affects target program design and
4000 vice versa, and by making it user-tweakable, the special code here
4001 goes away and we need fewer special GDB configurations. */
4003 #if defined (LITTLE_REMOTE_BREAKPOINT) && defined (BIG_REMOTE_BREAKPOINT) && !defined(REMOTE_BREAKPOINT)
4004 #define REMOTE_BREAKPOINT
4007 #ifdef REMOTE_BREAKPOINT
4009 /* If the target isn't bi-endian, just pretend it is. */
4010 #if !defined (LITTLE_REMOTE_BREAKPOINT) && !defined (BIG_REMOTE_BREAKPOINT)
4011 #define LITTLE_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4012 #define BIG_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4015 static unsigned char big_break_insn[] = BIG_REMOTE_BREAKPOINT;
4016 static unsigned char little_break_insn[] = LITTLE_REMOTE_BREAKPOINT;
4018 #endif /* REMOTE_BREAKPOINT */
4020 /* Insert a breakpoint on targets that don't have any better breakpoint
4021 support. We read the contents of the target location and stash it,
4022 then overwrite it with a breakpoint instruction. ADDR is the target
4023 location in the target machine. CONTENTS_CACHE is a pointer to
4024 memory allocated for saving the target contents. It is guaranteed
4025 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
4026 is accomplished via BREAKPOINT_MAX). */
4029 remote_insert_breakpoint (addr, contents_cache)
4031 char *contents_cache;
4033 #ifdef REMOTE_BREAKPOINT
4036 val = target_read_memory (addr, contents_cache, sizeof big_break_insn);
4040 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
4041 val = target_write_memory (addr, (char *) big_break_insn,
4042 sizeof big_break_insn);
4044 val = target_write_memory (addr, (char *) little_break_insn,
4045 sizeof little_break_insn);
4050 return memory_insert_breakpoint (addr, contents_cache);
4051 #endif /* REMOTE_BREAKPOINT */
4055 remote_remove_breakpoint (addr, contents_cache)
4057 char *contents_cache;
4059 #ifdef REMOTE_BREAKPOINT
4060 return target_write_memory (addr, contents_cache, sizeof big_break_insn);
4062 return memory_remove_breakpoint (addr, contents_cache);
4063 #endif /* REMOTE_BREAKPOINT */
4066 /* Some targets are only capable of doing downloads, and afterwards
4067 they switch to the remote serial protocol. This function provides
4068 a clean way to get from the download target to the remote target.
4069 It's basically just a wrapper so that we don't have to expose any
4070 of the internal workings of remote.c.
4072 Prior to calling this routine, you should shutdown the current
4073 target code, else you will get the "A program is being debugged
4074 already..." message. Usually a call to pop_target() suffices. */
4077 push_remote_target (name, from_tty)
4081 printf_filtered ("Switching to remote protocol\n");
4082 remote_open (name, from_tty);
4085 /* Other targets want to use the entire remote serial module but with
4086 certain remote_ops overridden. */
4089 open_remote_target (name, from_tty, target, extended_p)
4092 struct target_ops *target;
4095 printf_filtered ("Selecting the %sremote protocol\n",
4096 (extended_p ? "extended-" : ""));
4097 remote_open_1 (name, from_tty, target, extended_p);
4100 /* Table used by the crc32 function to calcuate the checksum. */
4102 static unsigned long crc32_table[256] =
4105 static unsigned long
4106 crc32 (buf, len, crc)
4111 if (!crc32_table[1])
4113 /* Initialize the CRC table and the decoding table. */
4117 for (i = 0; i < 256; i++)
4119 for (c = i << 24, j = 8; j > 0; --j)
4120 c = c & 0x80000000 ? (c << 1) ^ 0x04c11db7 : (c << 1);
4127 crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ *buf) & 255];
4133 /* compare-sections command
4135 With no arguments, compares each loadable section in the exec bfd
4136 with the same memory range on the target, and reports mismatches.
4137 Useful for verifying the image on the target against the exec file.
4138 Depends on the target understanding the new "qCRC:" request. */
4141 compare_sections_command (args, from_tty)
4146 unsigned long host_crc, target_crc;
4147 extern bfd *exec_bfd;
4148 struct cleanup *old_chain;
4152 char *buf = alloca (PBUFSIZ);
4159 error ("command cannot be used without an exec file");
4160 if (!current_target.to_shortname ||
4161 strcmp (current_target.to_shortname, "remote") != 0)
4162 error ("command can only be used with remote target");
4164 for (s = exec_bfd->sections; s; s = s->next)
4166 if (!(s->flags & SEC_LOAD))
4167 continue; /* skip non-loadable section */
4169 size = bfd_get_section_size_before_reloc (s);
4171 continue; /* skip zero-length section */
4173 sectname = (char *) bfd_get_section_name (exec_bfd, s);
4174 if (args && strcmp (args, sectname) != 0)
4175 continue; /* not the section selected by user */
4177 matched = 1; /* do this section */
4179 /* FIXME: assumes lma can fit into long */
4180 sprintf (buf, "qCRC:%lx,%lx", (long) lma, (long) size);
4183 /* be clever; compute the host_crc before waiting for target reply */
4184 sectdata = xmalloc (size);
4185 old_chain = make_cleanup (free, sectdata);
4186 bfd_get_section_contents (exec_bfd, s, sectdata, 0, size);
4187 host_crc = crc32 ((unsigned char *) sectdata, size, 0xffffffff);
4191 error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
4192 sectname, lma, lma + size);
4194 error ("remote target does not support this operation");
4196 for (target_crc = 0, tmp = &buf[1]; *tmp; tmp++)
4197 target_crc = target_crc * 16 + fromhex (*tmp);
4199 printf_filtered ("Section %s, range 0x%08x -- 0x%08x: ",
4200 sectname, lma, lma + size);
4201 if (host_crc == target_crc)
4202 printf_filtered ("matched.\n");
4205 printf_filtered ("MIS-MATCHED!\n");
4209 do_cleanups (old_chain);
4212 warning ("One or more sections of the remote executable does not match\n\
4213 the loaded file\n");
4214 if (args && !matched)
4215 printf_filtered ("No loaded section named '%s'.\n", args);
4219 remote_query (query_type, buf, outbuf, bufsiz)
4226 char *buf2 = alloca (PBUFSIZ);
4227 char *p2 = &buf2[0];
4231 error ("null pointer to remote bufer size specified");
4233 /* minimum outbuf size is PBUFSIZ - if bufsiz is not large enough let
4234 the caller know and return what the minimum size is */
4235 /* Note: a zero bufsiz can be used to query the minimum buffer size */
4236 if (*bufsiz < PBUFSIZ)
4242 /* except for querying the minimum buffer size, target must be open */
4244 error ("remote query is only available after target open");
4246 /* we only take uppercase letters as query types, at least for now */
4247 if ((query_type < 'A') || (query_type > 'Z'))
4248 error ("invalid remote query type");
4251 error ("null remote query specified");
4254 error ("remote query requires a buffer to receive data");
4261 /* we used one buffer char for the remote protocol q command and another
4262 for the query type. As the remote protocol encapsulation uses 4 chars
4263 plus one extra in case we are debugging (remote_debug),
4264 we have PBUFZIZ - 7 left to pack the query string */
4266 while (buf[i] && (i < (PBUFSIZ - 8)))
4268 /* bad caller may have sent forbidden characters */
4269 if ((!isprint (buf[i])) || (buf[i] == '$') || (buf[i] == '#'))
4270 error ("illegal characters in query string");
4278 error ("query larger than available buffer");
4290 packet_command (args, from_tty)
4294 char *buf = alloca (PBUFSIZ);
4297 error ("command can only be used with remote target");
4300 error ("remote-packet command requires packet text as argument");
4302 puts_filtered ("sending: ");
4303 print_packet (args);
4304 puts_filtered ("\n");
4308 puts_filtered ("received: ");
4310 puts_filtered ("\n");
4314 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
4316 static void display_thread_info PARAMS ((struct gdb_ext_thread_info * info));
4318 static void threadset_test_cmd PARAMS ((char *cmd, int tty));
4320 static void threadalive_test PARAMS ((char *cmd, int tty));
4322 static void threadlist_test_cmd PARAMS ((char *cmd, int tty));
4324 int get_and_display_threadinfo PARAMS ((threadref * ref));
4326 static void threadinfo_test_cmd PARAMS ((char *cmd, int tty));
4328 static int thread_display_step PARAMS ((threadref * ref, void *context));
4330 static void threadlist_update_test_cmd PARAMS ((char *cmd, int tty));
4332 static void init_remote_threadtests PARAMS ((void));
4334 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
4337 threadset_test_cmd (cmd, tty)
4341 int sample_thread = SAMPLE_THREAD;
4343 printf_filtered ("Remote threadset test\n");
4344 set_thread (sample_thread, 1);
4349 threadalive_test (cmd, tty)
4353 int sample_thread = SAMPLE_THREAD;
4355 if (remote_thread_alive (sample_thread))
4356 printf_filtered ("PASS: Thread alive test\n");
4358 printf_filtered ("FAIL: Thread alive test\n");
4361 void output_threadid PARAMS ((char *title, threadref * ref));
4364 output_threadid (title, ref)
4370 pack_threadid (&hexid[0], ref); /* Convert threead id into hex */
4372 printf_filtered ("%s %s\n", title, (&hexid[0]));
4376 threadlist_test_cmd (cmd, tty)
4381 threadref nextthread;
4382 int done, result_count;
4383 threadref threadlist[3];
4385 printf_filtered ("Remote Threadlist test\n");
4386 if (!remote_get_threadlist (startflag, &nextthread, 3, &done,
4387 &result_count, &threadlist[0]))
4388 printf_filtered ("FAIL: threadlist test\n");
4391 threadref *scan = threadlist;
4392 threadref *limit = scan + result_count;
4394 while (scan < limit)
4395 output_threadid (" thread ", scan++);
4400 display_thread_info (info)
4401 struct gdb_ext_thread_info *info;
4403 output_threadid ("Threadid: ", &info->threadid);
4404 printf_filtered ("Name: %s\n ", info->shortname);
4405 printf_filtered ("State: %s\n", info->display);
4406 printf_filtered ("other: %s\n\n", info->more_display);
4410 get_and_display_threadinfo (ref)
4415 struct gdb_ext_thread_info threadinfo;
4417 set = TAG_THREADID | TAG_EXISTS | TAG_THREADNAME
4418 | TAG_MOREDISPLAY | TAG_DISPLAY;
4419 if (0 != (result = remote_get_threadinfo (ref, set, &threadinfo)))
4420 display_thread_info (&threadinfo);
4425 threadinfo_test_cmd (cmd, tty)
4429 int athread = SAMPLE_THREAD;
4433 int_to_threadref (&thread, athread);
4434 printf_filtered ("Remote Threadinfo test\n");
4435 if (!get_and_display_threadinfo (&thread))
4436 printf_filtered ("FAIL cannot get thread info\n");
4440 thread_display_step (ref, context)
4444 /* output_threadid(" threadstep ",ref); *//* simple test */
4445 return get_and_display_threadinfo (ref);
4449 threadlist_update_test_cmd (cmd, tty)
4453 printf_filtered ("Remote Threadlist update test\n");
4454 remote_threadlist_iterator (thread_display_step, 0, CRAZY_MAX_THREADS);
4458 init_remote_threadtests (void)
4460 add_com ("tlist", class_obscure, threadlist_test_cmd,
4461 "Fetch and print the remote list of thread identifiers, one pkt only");
4462 add_com ("tinfo", class_obscure, threadinfo_test_cmd,
4463 "Fetch and display info about one thread");
4464 add_com ("tset", class_obscure, threadset_test_cmd,
4465 "Test setting to a different thread");
4466 add_com ("tupd", class_obscure, threadlist_update_test_cmd,
4467 "Iterate through updating all remote thread info");
4468 add_com ("talive", class_obscure, threadalive_test,
4469 " Remote thread alive test ");
4477 remote_ops.to_shortname = "remote";
4478 remote_ops.to_longname = "Remote serial target in gdb-specific protocol";
4480 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
4481 Specify the serial device it is connected to (e.g. /dev/ttya).";
4482 remote_ops.to_open = remote_open;
4483 remote_ops.to_close = remote_close;
4484 remote_ops.to_detach = remote_detach;
4485 remote_ops.to_resume = remote_resume;
4486 remote_ops.to_wait = remote_wait;
4487 remote_ops.to_fetch_registers = remote_fetch_registers;
4488 remote_ops.to_store_registers = remote_store_registers;
4489 remote_ops.to_prepare_to_store = remote_prepare_to_store;
4490 remote_ops.to_xfer_memory = remote_xfer_memory;
4491 remote_ops.to_files_info = remote_files_info;
4492 remote_ops.to_insert_breakpoint = remote_insert_breakpoint;
4493 remote_ops.to_remove_breakpoint = remote_remove_breakpoint;
4494 remote_ops.to_kill = remote_kill;
4495 remote_ops.to_load = generic_load;
4496 remote_ops.to_mourn_inferior = remote_mourn;
4497 remote_ops.to_thread_alive = remote_thread_alive;
4498 remote_ops.to_find_new_threads = remote_threads_info;
4499 remote_ops.to_stop = remote_stop;
4500 remote_ops.to_query = remote_query;
4501 remote_ops.to_stratum = process_stratum;
4502 remote_ops.to_has_all_memory = 1;
4503 remote_ops.to_has_memory = 1;
4504 remote_ops.to_has_stack = 1;
4505 remote_ops.to_has_registers = 1;
4506 remote_ops.to_has_execution = 1;
4507 remote_ops.to_has_thread_control = tc_schedlock; /* can lock scheduler */
4508 remote_ops.to_magic = OPS_MAGIC;
4511 /* Set up the extended remote vector by making a copy of the standard
4512 remote vector and adding to it. */
4515 init_extended_remote_ops ()
4517 extended_remote_ops = remote_ops;
4519 extended_remote_ops.to_shortname = "extended-remote";
4520 extended_remote_ops.to_longname =
4521 "Extended remote serial target in gdb-specific protocol";
4522 extended_remote_ops.to_doc =
4523 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
4524 Specify the serial device it is connected to (e.g. /dev/ttya).",
4525 extended_remote_ops.to_open = extended_remote_open;
4526 extended_remote_ops.to_create_inferior = extended_remote_create_inferior;
4527 extended_remote_ops.to_mourn_inferior = extended_remote_mourn;
4531 * Command: info remote-process
4533 * This implements Cisco's version of the "info proc" command.
4535 * This query allows the target stub to return an arbitrary string
4536 * (or strings) giving arbitrary information about the target process.
4537 * This is optional; the target stub isn't required to implement it.
4539 * Syntax: qfProcessInfo request first string
4540 * qsProcessInfo request subsequent string
4541 * reply: 'O'<hex-encoded-string>
4542 * 'l' last reply (empty)
4546 remote_info_process (args, from_tty)
4550 char *buf = alloca (PBUFSIZ);
4552 if (remote_desc == 0)
4553 error ("Command can only be used when connected to the remote target.");
4555 putpkt ("qfProcessInfo");
4558 return; /* Silently: target does not support this feature. */
4561 error ("info proc: target error.");
4563 while (buf[0] == 'O') /* Capitol-O packet */
4565 remote_console_output (&buf[1]);
4566 putpkt ("qsProcessInfo");
4576 remote_cisco_open (name, from_tty)
4582 "To open a remote debug connection, you need to specify what \n\
4583 device is attached to the remote system (e.g. host:port).");
4585 target_preopen (from_tty);
4587 unpush_target (&remote_cisco_ops);
4589 remote_dcache = dcache_init (remote_read_bytes, remote_write_bytes);
4591 remote_desc = SERIAL_OPEN (name);
4593 perror_with_name (name);
4596 * If a baud rate was specified on the gdb command line it will
4597 * be greater than the initial value of -1. If it is, use it otherwise
4601 baud_rate = (baud_rate > 0) ? baud_rate : 9600;
4602 if (SERIAL_SETBAUDRATE (remote_desc, baud_rate))
4604 SERIAL_CLOSE (remote_desc);
4605 perror_with_name (name);
4608 SERIAL_RAW (remote_desc);
4610 /* If there is something sitting in the buffer we might take it as a
4611 response to a command, which would be bad. */
4612 SERIAL_FLUSH_INPUT (remote_desc);
4616 puts_filtered ("Remote debugging using ");
4617 puts_filtered (name);
4618 puts_filtered ("\n");
4621 remote_cisco_mode = 1;
4623 push_target (&remote_cisco_ops); /* Switch to using cisco target now */
4625 init_packet_config (&remote_protocol_P);
4627 general_thread = -2;
4628 continue_thread = -2;
4630 /* Force remote_write_bytes to check whether target supports
4631 binary downloading. */
4632 remote_binary_checked = 0;
4634 /* Without this, some commands which require an active target (such
4635 as kill) won't work. This variable serves (at least) double duty
4636 as both the pid of the target process (if it has such), and as a
4637 flag indicating that a target is active. These functions should
4638 be split out into seperate variables, especially since GDB will
4639 someday have a notion of debugging several processes. */
4640 inferior_pid = MAGIC_NULL_PID;
4642 /* Start the remote connection; if error (0), discard this target. */
4644 if (!catch_errors (remote_start_remote_dummy, (char *) 0,
4645 "Couldn't establish connection to remote target\n",
4654 remote_cisco_close (quitting)
4657 remote_cisco_mode = 0;
4658 remote_close (quitting);
4665 remote_mourn_1 (&remote_cisco_ops);
4677 /* shared between readsocket() and readtty() */
4678 static char *tty_input;
4680 static int escape_count;
4681 static int echo_check;
4682 extern int quit_flag;
4689 /* Loop until the socket doesn't have any more data */
4691 while ((data = readchar (0)) >= 0)
4693 /* Check for the escape sequence */
4696 /* If this is the fourth escape, get out */
4697 if (++escape_count == 4)
4702 { /* This is a '|', but not the fourth in a row.
4703 Continue without echoing it. If it isn't actually
4704 one of four in a row, it'll be echoed later. */
4711 /* Ensure any pending '|'s are flushed. */
4713 for (; escape_count > 0; escape_count--)
4717 if (data == '\r') /* If this is a return character, */
4718 continue; /* - just supress it. */
4720 if (echo_check != -1) /* Check for echo of user input. */
4722 if (tty_input[echo_check] == data)
4724 echo_check++; /* Character matched user input: */
4725 continue; /* Continue without echoing it. */
4727 else if ((data == '\n') && (tty_input[echo_check] == '\r'))
4728 { /* End of the line (and of echo checking). */
4729 echo_check = -1; /* No more echo supression */
4730 continue; /* Continue without echoing. */
4733 { /* Failed check for echo of user input.
4734 We now have some suppressed output to flush! */
4737 for (j = 0; j < echo_check; j++)
4738 putchar (tty_input[j]);
4742 putchar (data); /* Default case: output the char. */
4745 if (data == SERIAL_TIMEOUT) /* Timeout returned from readchar. */
4746 return READ_MORE; /* Try to read some more */
4748 return FATAL_ERROR; /* Trouble, bail out */
4757 /* First, read a buffer full from the terminal */
4758 tty_bytecount = read (fileno (stdin), tty_input, sizeof (tty_input) - 1);
4759 if (tty_bytecount == -1)
4761 perror ("readtty: read failed");
4765 /* Remove a quoted newline. */
4766 if (tty_input[tty_bytecount - 1] == '\n' &&
4767 tty_input[tty_bytecount - 2] == '\\') /* line ending in backslash */
4769 tty_input[--tty_bytecount] = 0; /* remove newline */
4770 tty_input[--tty_bytecount] = 0; /* remove backslash */
4773 /* Turn trailing newlines into returns */
4774 if (tty_input[tty_bytecount - 1] == '\n')
4775 tty_input[tty_bytecount - 1] = '\r';
4777 /* If the line consists of a ~, enter debugging mode. */
4778 if ((tty_input[0] == '~') && (tty_bytecount == 2))
4781 /* Make this a zero terminated string and write it out */
4782 tty_input[tty_bytecount] = 0;
4783 if (SERIAL_WRITE (remote_desc, tty_input, tty_bytecount))
4785 perror_with_name ("readtty: write failed");
4795 fd_set input; /* file descriptors for select */
4796 int tablesize; /* max number of FDs for select */
4800 extern int escape_count; /* global shared by readsocket */
4801 extern int echo_check; /* ditto */
4806 tablesize = 8 * sizeof (input);
4810 /* Check for anything from our socket - doesn't block. Note that
4811 this must be done *before* the select as there may be
4812 buffered I/O waiting to be processed. */
4814 if ((status = readsocket ()) == FATAL_ERROR)
4816 error ("Debugging terminated by communications error");
4818 else if (status != READ_MORE)
4823 fflush (stdout); /* Flush output before blocking */
4825 /* Now block on more socket input or TTY input */
4828 FD_SET (fileno (stdin), &input);
4829 FD_SET (remote_desc->fd, &input);
4831 status = select (tablesize, &input, 0, 0, 0);
4832 if ((status == -1) && (errno != EINTR))
4834 error ("Communications error on select %d", errno);
4837 /* Handle Control-C typed */
4841 if ((++quit_count) == 2)
4843 if (query ("Interrupt GDB? "))
4845 printf_filtered ("Interrupted by user.\n");
4846 return_to_top_level (RETURN_QUIT);
4853 SERIAL_SEND_BREAK (remote_desc);
4855 SERIAL_WRITE (remote_desc, "\003", 1);
4860 /* Handle console input */
4862 if (FD_ISSET (fileno (stdin), &input))
4866 status = readtty ();
4867 if (status == READ_MORE)
4870 return status; /* telnet session ended */
4876 remote_cisco_wait (pid, status)
4878 struct target_waitstatus *status;
4880 if (minitelnet () != ENTER_DEBUG)
4882 error ("Debugging session terminated by protocol error");
4885 return remote_wait (pid, status);
4889 init_remote_cisco_ops ()
4891 remote_cisco_ops.to_shortname = "cisco";
4892 remote_cisco_ops.to_longname = "Remote serial target in cisco-specific protocol";
4893 remote_cisco_ops.to_doc =
4894 "Use a remote machine via TCP, using a cisco-specific protocol.\n\
4895 Specify the serial device it is connected to (e.g. host:2020).";
4896 remote_cisco_ops.to_open = remote_cisco_open;
4897 remote_cisco_ops.to_close = remote_cisco_close;
4898 remote_cisco_ops.to_detach = remote_detach;
4899 remote_cisco_ops.to_resume = remote_resume;
4900 remote_cisco_ops.to_wait = remote_cisco_wait;
4901 remote_cisco_ops.to_fetch_registers = remote_fetch_registers;
4902 remote_cisco_ops.to_store_registers = remote_store_registers;
4903 remote_cisco_ops.to_prepare_to_store = remote_prepare_to_store;
4904 remote_cisco_ops.to_xfer_memory = remote_xfer_memory;
4905 remote_cisco_ops.to_files_info = remote_files_info;
4906 remote_cisco_ops.to_insert_breakpoint = remote_insert_breakpoint;
4907 remote_cisco_ops.to_remove_breakpoint = remote_remove_breakpoint;
4908 remote_cisco_ops.to_kill = remote_kill;
4909 remote_cisco_ops.to_load = generic_load;
4910 remote_cisco_ops.to_mourn_inferior = remote_cisco_mourn;
4911 remote_cisco_ops.to_thread_alive = remote_thread_alive;
4912 remote_cisco_ops.to_find_new_threads = remote_threads_info;
4913 remote_cisco_ops.to_stratum = process_stratum;
4914 remote_cisco_ops.to_has_all_memory = 1;
4915 remote_cisco_ops.to_has_memory = 1;
4916 remote_cisco_ops.to_has_stack = 1;
4917 remote_cisco_ops.to_has_registers = 1;
4918 remote_cisco_ops.to_has_execution = 1;
4919 remote_cisco_ops.to_magic = OPS_MAGIC;
4922 /* Target async and target extended-async.
4924 This are temporary targets, until it is all tested. Eventually
4925 async support will be incorporated int the usual 'remote'
4929 init_remote_async_ops ()
4931 remote_async_ops.to_shortname = "async";
4932 remote_async_ops.to_longname = "Remote serial target in async version of the gdb-specific protocol";
4933 remote_async_ops.to_doc =
4934 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
4935 Specify the serial device it is connected to (e.g. /dev/ttya).";
4936 remote_async_ops.to_open = remote_async_open;
4937 remote_async_ops.to_close = remote_close;
4938 remote_async_ops.to_detach = remote_async_detach;
4939 remote_async_ops.to_resume = remote_async_resume;
4940 remote_async_ops.to_wait = remote_async_wait;
4941 remote_async_ops.to_fetch_registers = remote_fetch_registers;
4942 remote_async_ops.to_store_registers = remote_store_registers;
4943 remote_async_ops.to_prepare_to_store = remote_prepare_to_store;
4944 remote_async_ops.to_xfer_memory = remote_xfer_memory;
4945 remote_async_ops.to_files_info = remote_files_info;
4946 remote_async_ops.to_insert_breakpoint = remote_insert_breakpoint;
4947 remote_async_ops.to_remove_breakpoint = remote_remove_breakpoint;
4948 remote_async_ops.to_kill = remote_async_kill;
4949 remote_async_ops.to_load = generic_load;
4950 remote_async_ops.to_mourn_inferior = remote_mourn;
4951 remote_async_ops.to_thread_alive = remote_thread_alive;
4952 remote_async_ops.to_find_new_threads = remote_threads_info;
4953 remote_async_ops.to_stop = remote_stop;
4954 remote_async_ops.to_query = remote_query;
4955 remote_async_ops.to_stratum = process_stratum;
4956 remote_async_ops.to_has_all_memory = 1;
4957 remote_async_ops.to_has_memory = 1;
4958 remote_async_ops.to_has_stack = 1;
4959 remote_async_ops.to_has_registers = 1;
4960 remote_async_ops.to_has_execution = 1;
4961 remote_async_ops.to_has_thread_control = tc_schedlock; /* can lock scheduler */
4962 remote_async_ops.to_has_async_exec = 1;
4963 remote_async_ops.to_magic = OPS_MAGIC;
4966 /* Set up the async extended remote vector by making a copy of the standard
4967 remote vector and adding to it. */
4970 init_extended_async_remote_ops ()
4972 extended_async_remote_ops = remote_async_ops;
4974 extended_async_remote_ops.to_shortname = "extended-async";
4975 extended_async_remote_ops.to_longname =
4976 "Extended remote serial target in async gdb-specific protocol";
4977 extended_async_remote_ops.to_doc =
4978 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
4979 Specify the serial device it is connected to (e.g. /dev/ttya).",
4980 extended_async_remote_ops.to_open = extended_remote_async_open;
4981 extended_async_remote_ops.to_create_inferior = extended_remote_async_create_inferior;
4982 extended_async_remote_ops.to_mourn_inferior = extended_remote_mourn;
4986 set_remote_cmd (args, from_tty)
4995 build_remote_gdbarch_data ()
4997 tty_input = xmalloc (PBUFSIZ);
5001 _initialize_remote ()
5003 static struct cmd_list_element *remote_set_cmdlist;
5004 static struct cmd_list_element *remote_show_cmdlist;
5006 /* architecture specific data */
5007 build_remote_gdbarch_data ();
5008 register_gdbarch_swap (&tty_input, sizeof (&tty_input), NULL);
5009 register_gdbarch_swap (NULL, 0, build_remote_gdbarch_data);
5011 /* runtime constants - we retain the value of remote_write_size
5012 across architecture swaps. */
5013 remote_write_size = PBUFSIZ;
5016 add_target (&remote_ops);
5018 init_extended_remote_ops ();
5019 add_target (&extended_remote_ops);
5021 init_remote_async_ops ();
5022 add_target (&remote_async_ops);
5024 init_extended_async_remote_ops ();
5025 add_target (&extended_async_remote_ops);
5027 init_remote_cisco_ops ();
5028 add_target (&remote_cisco_ops);
5031 init_remote_threadtests ();
5034 add_prefix_cmd ("remote", class_maintenance, set_remote_cmd, "\
5035 Remote protocol specific variables\n\
5036 Configure various remote-protocol specific variables such as\n\
5037 the packets being used",
5038 &remote_set_cmdlist, "remote ",
5039 0/*allow-unknown*/, &setlist);
5040 add_prefix_cmd ("remote", class_maintenance, set_remote_cmd, "\
5041 Remote protocol specific variables\n\
5042 Configure various remote-protocol specific variables such as\n\
5043 the packets being used",
5044 &remote_show_cmdlist, "remote ",
5045 0/*allow-unknown*/, &showlist);
5047 add_cmd ("compare-sections", class_obscure, compare_sections_command,
5048 "Compare section data on target to the exec file.\n\
5049 Argument is a single section name (default: all loaded sections).",
5052 add_cmd ("packet", class_maintenance, packet_command,
5053 "Send an arbitrary packet to a remote target.\n\
5054 maintenance packet TEXT\n\
5055 If GDB is talking to an inferior via the GDB serial protocol, then\n\
5056 this command sends the string TEXT to the inferior, and displays the\n\
5057 response packet. GDB supplies the initial `$' character, and the\n\
5058 terminating `#' character and checksum.",
5062 (add_set_cmd ("remotetimeout", no_class,
5063 var_integer, (char *) &remote_timeout,
5064 "Set timeout value for remote read.\n",
5069 (add_set_cmd ("remotebreak", no_class,
5070 var_boolean, (char *) &remote_break,
5071 "Set whether to send break if interrupted.\n",
5076 (add_set_cmd ("remotewritesize", no_class,
5077 var_integer, (char *) &remote_write_size,
5078 "Set the maximum number of bytes per memory write packet.\n",
5082 remote_address_size = TARGET_PTR_BIT;
5084 (add_set_cmd ("remoteaddresssize", class_obscure,
5085 var_integer, (char *) &remote_address_size,
5086 "Set the maximum size of the address (in bits) \
5087 in a memory packet.\n",
5092 (add_set_cmd ("remotebinarydownload", no_class,
5093 var_boolean, (char *) &remote_binary_download,
5094 "Set binary downloads.\n", &setlist),
5097 add_info ("remote-process", remote_info_process,
5098 "Query the remote system for process info.");
5100 add_packet_config_cmd (&remote_protocol_P, "P", "set-register",
5101 set_remote_protocol_P_packet_cmd,
5102 show_remote_protocol_P_packet_cmd,
5103 &remote_set_cmdlist, &remote_show_cmdlist);