1 /* Remote target communications for serial-line targets in custom GDB protocol
2 Copyright 1988, 1991-2000 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* See the GDB User Guide for details of the GDB remote protocol. */
24 #include "gdb_string.h"
33 /*#include "terminal.h" */
36 #include "gdb-stabs.h"
37 #include "gdbthread.h"
45 #include <sys/types.h>
48 #include "event-loop.h"
49 #include "event-top.h"
55 /* Prototypes for local functions */
56 static void cleanup_sigint_signal_handler (void *dummy);
57 static void initialize_sigint_signal_handler (void);
58 static int getpkt_sane (char *buf, long sizeof_buf, int forever);
60 static void handle_remote_sigint PARAMS ((int));
61 static void handle_remote_sigint_twice PARAMS ((int));
62 static void async_remote_interrupt PARAMS ((gdb_client_data));
63 void async_remote_interrupt_twice PARAMS ((gdb_client_data));
65 static void build_remote_gdbarch_data PARAMS ((void));
67 static int remote_write_bytes (CORE_ADDR memaddr, char *myaddr, int len);
69 static int remote_read_bytes PARAMS ((CORE_ADDR memaddr,
70 char *myaddr, int len));
72 static void remote_files_info PARAMS ((struct target_ops * ignore));
74 static int remote_xfer_memory PARAMS ((CORE_ADDR memaddr, char *myaddr,
75 int len, int should_write,
76 struct target_ops * target));
78 static void remote_prepare_to_store PARAMS ((void));
80 static void remote_fetch_registers PARAMS ((int regno));
82 static void remote_resume PARAMS ((int pid, int step,
83 enum target_signal siggnal));
84 static void remote_async_resume PARAMS ((int pid, int step,
85 enum target_signal siggnal));
86 static int remote_start_remote PARAMS ((PTR));
88 static void remote_open PARAMS ((char *name, int from_tty));
89 static void remote_async_open PARAMS ((char *name, int from_tty));
91 static void extended_remote_open PARAMS ((char *name, int from_tty));
92 static void extended_remote_async_open PARAMS ((char *name, int from_tty));
94 static void remote_open_1 PARAMS ((char *, int, struct target_ops *,
96 static void remote_async_open_1 PARAMS ((char *, int, struct target_ops *,
99 static void remote_close PARAMS ((int quitting));
101 static void remote_store_registers PARAMS ((int regno));
103 static void remote_mourn PARAMS ((void));
104 static void remote_async_mourn PARAMS ((void));
106 static void extended_remote_restart PARAMS ((void));
108 static void extended_remote_mourn PARAMS ((void));
110 static void extended_remote_create_inferior PARAMS ((char *, char *, char **));
111 static void extended_remote_async_create_inferior PARAMS ((char *, char *, char **));
113 static void remote_mourn_1 PARAMS ((struct target_ops *));
115 static void remote_send (char *buf, long sizeof_buf);
117 static int readchar PARAMS ((int timeout));
119 static int remote_wait PARAMS ((int pid, struct target_waitstatus * status));
120 static int remote_async_wait PARAMS ((int pid, struct target_waitstatus * status));
122 static void remote_kill PARAMS ((void));
123 static void remote_async_kill PARAMS ((void));
125 static int tohex PARAMS ((int nib));
127 static void remote_detach PARAMS ((char *args, int from_tty));
128 static void remote_async_detach PARAMS ((char *args, int from_tty));
130 static void remote_interrupt PARAMS ((int signo));
132 static void remote_interrupt_twice PARAMS ((int signo));
134 static void interrupt_query PARAMS ((void));
136 static void set_thread PARAMS ((int, int));
138 static int remote_thread_alive PARAMS ((int));
140 static void get_offsets PARAMS ((void));
142 static long read_frame (char *buf, long sizeof_buf);
144 static int remote_insert_breakpoint PARAMS ((CORE_ADDR, char *));
146 static int remote_remove_breakpoint PARAMS ((CORE_ADDR, char *));
148 static int hexnumlen PARAMS ((ULONGEST num));
150 static void init_remote_ops PARAMS ((void));
152 static void init_extended_remote_ops PARAMS ((void));
154 static void init_remote_cisco_ops PARAMS ((void));
156 static struct target_ops remote_cisco_ops;
158 static void remote_stop PARAMS ((void));
160 static int ishex PARAMS ((int ch, int *val));
162 static int stubhex PARAMS ((int ch));
164 static int remote_query PARAMS ((int /*char */ , char *, char *, int *));
166 static int hexnumstr PARAMS ((char *, ULONGEST));
168 static int hexnumnstr PARAMS ((char *, ULONGEST, int));
170 static CORE_ADDR remote_address_masked PARAMS ((CORE_ADDR));
172 static void print_packet PARAMS ((char *));
174 static unsigned long crc32 PARAMS ((unsigned char *, int, unsigned int));
176 static void compare_sections_command PARAMS ((char *, int));
178 static void packet_command PARAMS ((char *, int));
180 static int stub_unpack_int PARAMS ((char *buff, int fieldlength));
182 static int remote_current_thread PARAMS ((int oldpid));
184 static void remote_find_new_threads PARAMS ((void));
186 static void record_currthread PARAMS ((int currthread));
188 /* exported functions */
190 extern int fromhex PARAMS ((int a));
192 static int putpkt_binary PARAMS ((char *buf, int cnt));
194 static void check_binary_download PARAMS ((CORE_ADDR addr));
196 struct packet_config;
198 static void show_packet_config_cmd PARAMS ((struct packet_config * config));
200 static void set_packet_config_cmd PARAMS ((struct packet_config * config,
201 struct cmd_list_element * c));
203 static void add_packet_config_cmd PARAMS ((struct packet_config * config,
206 void (*set_func) (char *args, int from_tty, struct cmd_list_element * c),
207 void (*show_func) (char *name, int from_tty),
208 struct cmd_list_element **setlist,
209 struct cmd_list_element **showlist));
211 static void init_packet_config PARAMS ((struct packet_config * config));
213 static void set_remote_protocol_P_packet_cmd PARAMS ((char *args,
215 struct cmd_list_element * c));
217 static void show_remote_protocol_P_packet_cmd PARAMS ((char *args,
220 static void set_remote_protocol_Z_packet_cmd PARAMS ((char *args,
222 struct cmd_list_element * c));
224 static void show_remote_protocol_Z_packet_cmd PARAMS ((char *args,
230 /* Define the target subroutine names */
232 void open_remote_target PARAMS ((char *, int, struct target_ops *, int));
234 void _initialize_remote PARAMS ((void));
238 static struct target_ops remote_ops;
240 static struct target_ops extended_remote_ops;
242 /* Temporary target ops. Just like the remote_ops and
243 extended_remote_ops, but with asynchronous support. */
244 static struct target_ops remote_async_ops;
246 static struct target_ops extended_async_remote_ops;
248 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
249 ``forever'' still use the normal timeout mechanism. This is
250 currently used by the ASYNC code to guarentee that target reads
251 during the initial connect always time-out. Once getpkt has been
252 modified to return a timeout indication and, in turn
253 remote_wait()/wait_for_inferior() have gained a timeout parameter
255 static int wait_forever_enabled_p = 1;
258 /* This variable chooses whether to send a ^C or a break when the user
259 requests program interruption. Although ^C is usually what remote
260 systems expect, and that is the default here, sometimes a break is
261 preferable instead. */
263 static int remote_break;
265 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
266 remote_open knows that we don't have a file open when the program
268 static serial_t remote_desc = NULL;
270 /* This is set by the target (thru the 'S' message)
271 to denote that the target is in kernel mode. */
272 static int cisco_kernel_mode = 0;
274 /* This variable sets the number of bits in an address that are to be
275 sent in a memory ("M" or "m") packet. Normally, after stripping
276 leading zeros, the entire address would be sent. This variable
277 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
278 initial implementation of remote.c restricted the address sent in
279 memory packets to ``host::sizeof long'' bytes - (typically 32
280 bits). Consequently, for 64 bit targets, the upper 32 bits of an
281 address was never sent. Since fixing this bug may cause a break in
282 some remote targets this variable is principly provided to
283 facilitate backward compatibility. */
285 static int remote_address_size;
287 /* Tempoary to track who currently owns the terminal. See
288 target_async_terminal_* for more details. */
290 static int remote_async_terminal_ours_p;
293 /* This is the size (in chars) of the first response to the ``g''
294 packet. It is used as a heuristic when determining the maximum
295 size of memory-read and memory-write packets. A target will
296 typically only reserve a buffer large enough to hold the ``g''
297 packet. The size does not include packet overhead (headers and
300 static long actual_register_packet_size;
302 /* This is the maximum size (in chars) of a non read/write packet. It
303 is also used as a cap on the size of read/write packets. */
305 static long remote_packet_size;
307 #define PBUFSIZ (remote_packet_size)
309 /* User configurable variables for the number of characters in a
310 memory read/write packet. MIN (PBUFSIZ, g-packet-size) is the
311 default. Some targets need smaller values (fifo overruns, et.al.)
312 and some users need larger values (speed up transfers). The
313 variables ``preferred_*'' (the user request), ``current_*'' (what
314 was actually set) and ``forced_*'' (Positive - a soft limit,
315 negative - a hard limit). */
317 struct memory_packet_config
324 /* Compute the current size of a read/write packet. Since this makes
325 use of ``actual_register_packet_size'' the computation is dynamic. */
328 get_memory_packet_size (struct memory_packet_config *config)
330 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
331 law?) that some hosts don't cope very well with large alloca()
332 calls. Eventually the alloca() code will be replaced by calls to
333 xmalloc() and make_cleanups() allowing this restriction to either
334 be lifted or removed. */
335 #ifndef MAX_REMOTE_PACKET_SIZE
336 #define MAX_REMOTE_PACKET_SIZE 16384
338 /* NOTE: 16 is just chosen at random. */
339 #ifndef MIN_REMOTE_PACKET_SIZE
340 #define MIN_REMOTE_PACKET_SIZE 16
345 if (config->size <= 0)
346 what_they_get = MAX_REMOTE_PACKET_SIZE;
348 what_they_get = config->size;
352 what_they_get = remote_packet_size;
353 /* Limit the packet to the size specified by the user. */
355 && what_they_get > config->size)
356 what_they_get = config->size;
357 /* Limit it to the size of the targets ``g'' response. */
358 if (actual_register_packet_size > 0
359 && what_they_get > actual_register_packet_size)
360 what_they_get = actual_register_packet_size;
362 if (what_they_get > MAX_REMOTE_PACKET_SIZE)
363 what_they_get = MAX_REMOTE_PACKET_SIZE;
364 if (what_they_get < MIN_REMOTE_PACKET_SIZE)
365 what_they_get = MIN_REMOTE_PACKET_SIZE;
366 return what_they_get;
369 /* Update the size of a read/write packet. If they user wants
370 something really big then do a sanity check. */
373 set_memory_packet_size (char *args, struct memory_packet_config *config)
375 int fixed_p = config->fixed_p;
376 long size = config->size;
378 error ("Argument required (integer, `fixed' or `limited').");
379 else if (strcmp (args, "hard") == 0
380 || strcmp (args, "fixed") == 0)
382 else if (strcmp (args, "soft") == 0
383 || strcmp (args, "limit") == 0)
388 size = strtoul (args, &end, 0);
390 error ("Invalid %s (bad syntax).", config->name);
392 /* Instead of explicitly capping the size of a packet to
393 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
394 instead allowed to set the size to something arbitrarily
396 if (size > MAX_REMOTE_PACKET_SIZE)
397 error ("Invalid %s (too large).", config->name);
401 if (fixed_p && !config->fixed_p)
403 if (! query ("The target may not be able to correctly handle a %s\n"
404 "of %ld bytes. Change the packet size? ",
406 error ("Packet size not changed.");
408 /* Update the config. */
409 config->fixed_p = fixed_p;
414 show_memory_packet_size (struct memory_packet_config *config)
416 printf_filtered ("The %s is %ld. ", config->name, config->size);
418 printf_filtered ("Packets are fixed at %ld bytes.\n",
419 get_memory_packet_size (config));
421 printf_filtered ("Packets are limited to %ld bytes.\n",
422 get_memory_packet_size (config));
425 static struct memory_packet_config memory_write_packet_config =
427 "memory-write-packet-size",
431 set_memory_write_packet_size (char *args, int from_tty)
433 set_memory_packet_size (args, &memory_write_packet_config);
437 show_memory_write_packet_size (char *args, int from_tty)
439 show_memory_packet_size (&memory_write_packet_config);
443 get_memory_write_packet_size (void)
445 return get_memory_packet_size (&memory_write_packet_config);
448 static struct memory_packet_config memory_read_packet_config =
450 "memory-read-packet-size",
454 set_memory_read_packet_size (char *args, int from_tty)
456 set_memory_packet_size (args, &memory_read_packet_config);
460 show_memory_read_packet_size (char *args, int from_tty)
462 show_memory_packet_size (&memory_read_packet_config);
466 get_memory_read_packet_size (void)
468 long size = get_memory_packet_size (&memory_read_packet_config);
469 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
470 extra buffer size argument before the memory read size can be
471 increased beyond PBUFSIZ. */
477 /* Register packet size initialization. Since the bounds change when
478 the architecture changes (namely REGISTER_BYTES) this all needs to
482 register_remote_packet_sizes (void)
484 REGISTER_GDBARCH_SWAP (remote_packet_size);
485 REGISTER_GDBARCH_SWAP (actual_register_packet_size);
489 build_remote_packet_sizes (void)
491 /* Default maximum number of characters in a packet body. Many
492 remote stubs have a hardwired buffer size of 400 bytes
493 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
494 as the maximum packet-size to ensure that the packet and an extra
495 NUL character can always fit in the buffer. This stops GDB
496 trashing stubs that try to squeeze an extra NUL into what is
497 already a full buffer (As of 1999-12-04 that was most stubs. */
498 remote_packet_size = 400 - 1;
499 /* Should REGISTER_BYTES needs more space than the default, adjust
500 the size accordingly. Remember that each byte is encoded as two
501 characters. 32 is the overhead for the packet header /
502 footer. NOTE: cagney/1999-10-26: I suspect that 8
503 (``$NN:G...#NN'') is a better guess, the below has been padded a
505 if (REGISTER_BYTES > ((remote_packet_size - 32) / 2))
506 remote_packet_size = (REGISTER_BYTES * 2 + 32);
508 /* This one is filled in when a ``g'' packet is received. */
509 actual_register_packet_size = 0;
512 /* Generic configuration support for packets the stub optionally
513 supports. Allows the user to specify the use of the packet as well
514 as allowing GDB to auto-detect support in the remote stub. */
518 PACKET_SUPPORT_UNKNOWN = 0,
525 PACKET_AUTO_DETECT = 0,
534 enum packet_detect detect;
535 enum packet_support support;
538 static char packet_support_auto[] = "auto";
539 static char packet_enable[] = "enable";
540 static char packet_disable[] = "disable";
541 static char *packet_support_enums[] =
550 set_packet_config_cmd (config, c)
551 struct packet_config *config;
552 struct cmd_list_element *c;
554 if (config->state == packet_enable)
556 config->detect = PACKET_MANUAL_DETECT;
557 config->support = PACKET_ENABLE;
559 else if (config->state == packet_disable)
561 config->detect = PACKET_MANUAL_DETECT;
562 config->support = PACKET_DISABLE;
564 else if (config->state == packet_support_auto)
566 config->detect = PACKET_AUTO_DETECT;
567 config->support = PACKET_SUPPORT_UNKNOWN;
570 internal_error ("Bad enum value");
574 show_packet_config_cmd (config)
575 struct packet_config *config;
577 char *support = "internal-error";
578 switch (config->support)
584 support = "disabled";
586 case PACKET_SUPPORT_UNKNOWN:
590 switch (config->detect)
592 case PACKET_AUTO_DETECT:
593 printf_filtered ("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n",
594 config->name, config->title, support);
596 case PACKET_MANUAL_DETECT:
597 printf_filtered ("Support for remote protocol `%s' (%s) is currently %s.\n",
598 config->name, config->title, support);
603 add_packet_config_cmd (config, name, title, set_func, show_func,
605 struct packet_config *config;
608 void (*set_func) PARAMS ((char *args, int from_tty,
609 struct cmd_list_element * c));
610 void (*show_func) PARAMS ((char *name, int from_tty));
611 struct cmd_list_element **setlist;
612 struct cmd_list_element **showlist;
614 struct cmd_list_element *c;
619 config->title = title;
620 asprintf (&set_doc, "Set use of remote protocol `%s' (%s) packet",
622 asprintf (&show_doc, "Show current use of remote protocol `%s' (%s) packet",
624 asprintf (&full_name, "%s-packet", name);
625 c = add_set_enum_cmd (full_name,
626 class_obscure, packet_support_enums,
629 c->function.sfunc = set_func;
630 add_cmd (full_name, class_obscure, show_func, show_doc, showlist);
634 init_packet_config (config)
635 struct packet_config *config;
637 switch (config->detect)
639 case PACKET_AUTO_DETECT:
640 config->support = PACKET_SUPPORT_UNKNOWN;
642 case PACKET_MANUAL_DETECT:
643 /* let the user beware */
648 /* Should we try the 'P' (set register) request? */
650 static struct packet_config remote_protocol_P;
653 set_remote_protocol_P_packet_cmd (args, from_tty, c)
656 struct cmd_list_element *c;
658 set_packet_config_cmd (&remote_protocol_P, c);
662 show_remote_protocol_P_packet_cmd (args, from_tty)
666 show_packet_config_cmd (&remote_protocol_P);
669 /* Should we try the 'Z' (set breakpoint) request? */
671 static struct packet_config remote_protocol_Z;
674 set_remote_protocol_Z_packet_cmd (args, from_tty, c)
677 struct cmd_list_element *c;
679 set_packet_config_cmd (&remote_protocol_Z, c);
683 show_remote_protocol_Z_packet_cmd (args, from_tty)
687 show_packet_config_cmd (&remote_protocol_Z);
690 /* Should we try the 'X' (remote binary download) packet?
692 This variable (available to the user via "set remote X-packet")
693 dictates whether downloads are sent in binary (via the 'X' packet).
694 We assume that the stub can, and attempt to do it. This will be
695 cleared if the stub does not understand it. This switch is still
696 needed, though in cases when the packet is supported in the stub,
697 but the connection does not allow it (i.e., 7-bit serial connection
700 static struct packet_config remote_protocol_binary_download;
702 /* Should we try the 'ThreadInfo' query packet?
704 This variable (NOT available to the user: auto-detect only!)
705 determines whether GDB will use the new, simpler "ThreadInfo"
706 query or the older, more complex syntax for thread queries.
707 This is an auto-detect variable (set to true at each connect,
708 and set to false when the target fails to recognize it). */
710 static int use_threadinfo_query;
711 static int use_threadextra_query;
714 set_remote_protocol_binary_download_cmd (char *args,
716 struct cmd_list_element *c)
718 set_packet_config_cmd (&remote_protocol_binary_download, c);
722 show_remote_protocol_binary_download_cmd (char *args,
725 show_packet_config_cmd (&remote_protocol_binary_download);
729 /* Tokens for use by the asynchronous signal handlers for SIGINT */
730 PTR sigint_remote_twice_token;
731 PTR sigint_remote_token;
733 /* These are pointers to hook functions that may be set in order to
734 modify resume/wait behavior for a particular architecture. */
736 void (*target_resume_hook) PARAMS ((void));
737 void (*target_wait_loop_hook) PARAMS ((void));
741 /* These are the threads which we last sent to the remote system.
742 -1 for all or -2 for not sent yet. */
743 static int general_thread;
744 static int continue_thread;
746 /* Call this function as a result of
747 1) A halt indication (T packet) containing a thread id
748 2) A direct query of currthread
749 3) Successful execution of set thread
753 record_currthread (currthread)
756 general_thread = currthread;
758 /* If this is a new thread, add it to GDB's thread list.
759 If we leave it up to WFI to do this, bad things will happen. */
760 if (!in_thread_list (currthread))
762 add_thread (currthread);
764 ui_out_text (uiout, "[New ");
765 ui_out_text (uiout, target_pid_to_str (currthread));
766 ui_out_text (uiout, "]\n");
768 printf_filtered ("[New %s]\n", target_pid_to_str (currthread));
773 #define MAGIC_NULL_PID 42000
780 char *buf = alloca (PBUFSIZ);
781 int state = gen ? general_thread : continue_thread;
787 buf[1] = gen ? 'g' : 'c';
788 if (th == MAGIC_NULL_PID)
794 sprintf (&buf[2], "-%x", -th);
796 sprintf (&buf[2], "%x", th);
798 getpkt (buf, PBUFSIZ, 0);
802 continue_thread = th;
805 /* Return nonzero if the thread TH is still alive on the remote system. */
808 remote_thread_alive (tid)
814 sprintf (buf, "T-%08x", -tid);
816 sprintf (buf, "T%08x", tid);
818 getpkt (buf, sizeof (buf), 0);
819 return (buf[0] == 'O' && buf[1] == 'K');
822 /* About these extended threadlist and threadinfo packets. They are
823 variable length packets but, the fields within them are often fixed
824 length. They are redundent enough to send over UDP as is the
825 remote protocol in general. There is a matching unit test module
828 #define OPAQUETHREADBYTES 8
830 /* a 64 bit opaque identifier */
831 typedef unsigned char threadref[OPAQUETHREADBYTES];
833 /* WARNING: This threadref data structure comes from the remote O.S., libstub
834 protocol encoding, and remote.c. it is not particularly changable */
836 /* Right now, the internal structure is int. We want it to be bigger.
840 typedef int gdb_threadref; /* internal GDB thread reference */
842 /* gdb_ext_thread_info is an internal GDB data structure which is
843 equivalint to the reply of the remote threadinfo packet */
845 struct gdb_ext_thread_info
847 threadref threadid; /* External form of thread reference */
848 int active; /* Has state interesting to GDB? , regs, stack */
849 char display[256]; /* Brief state display, name, blocked/syspended */
850 char shortname[32]; /* To be used to name threads */
851 char more_display[256]; /* Long info, statistics, queue depth, whatever */
854 /* The volume of remote transfers can be limited by submitting
855 a mask containing bits specifying the desired information.
856 Use a union of these values as the 'selection' parameter to
857 get_thread_info. FIXME: Make these TAG names more thread specific.
860 #define TAG_THREADID 1
862 #define TAG_DISPLAY 4
863 #define TAG_THREADNAME 8
864 #define TAG_MOREDISPLAY 16
866 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
868 char *unpack_varlen_hex PARAMS ((char *buff, int *result));
870 static char *unpack_nibble PARAMS ((char *buf, int *val));
872 static char *pack_nibble PARAMS ((char *buf, int nibble));
874 static char *pack_hex_byte PARAMS ((char *pkt, int /*unsigned char */ byte));
876 static char *unpack_byte PARAMS ((char *buf, int *value));
878 static char *pack_int PARAMS ((char *buf, int value));
880 static char *unpack_int PARAMS ((char *buf, int *value));
882 static char *unpack_string PARAMS ((char *src, char *dest, int length));
884 static char *pack_threadid PARAMS ((char *pkt, threadref * id));
886 static char *unpack_threadid PARAMS ((char *inbuf, threadref * id));
888 void int_to_threadref PARAMS ((threadref * id, int value));
890 static int threadref_to_int PARAMS ((threadref * ref));
892 static void copy_threadref PARAMS ((threadref * dest, threadref * src));
894 static int threadmatch PARAMS ((threadref * dest, threadref * src));
896 static char *pack_threadinfo_request PARAMS ((char *pkt, int mode,
899 static int remote_unpack_thread_info_response PARAMS ((char *pkt,
900 threadref * expectedref,
901 struct gdb_ext_thread_info * info));
904 static int remote_get_threadinfo PARAMS ((threadref * threadid,
905 int fieldset, /*TAG mask */
906 struct gdb_ext_thread_info * info));
908 static int adapt_remote_get_threadinfo PARAMS ((gdb_threadref * ref,
910 struct gdb_ext_thread_info * info));
912 static char *pack_threadlist_request PARAMS ((char *pkt, int startflag,
914 threadref * nextthread));
916 static int parse_threadlist_response PARAMS ((char *pkt,
918 threadref * original_echo,
919 threadref * resultlist,
922 static int remote_get_threadlist PARAMS ((int startflag,
923 threadref * nextthread,
927 threadref * threadlist));
929 typedef int (*rmt_thread_action) (threadref * ref, void *context);
931 static int remote_threadlist_iterator PARAMS ((rmt_thread_action stepfunction,
932 void *context, int looplimit));
934 static int remote_newthread_step PARAMS ((threadref * ref, void *context));
936 /* encode 64 bits in 16 chars of hex */
938 static const char hexchars[] = "0123456789abcdef";
945 if ((ch >= 'a') && (ch <= 'f'))
947 *val = ch - 'a' + 10;
950 if ((ch >= 'A') && (ch <= 'F'))
952 *val = ch - 'A' + 10;
955 if ((ch >= '0') && (ch <= '9'))
967 if (ch >= 'a' && ch <= 'f')
968 return ch - 'a' + 10;
969 if (ch >= '0' && ch <= '9')
971 if (ch >= 'A' && ch <= 'F')
972 return ch - 'A' + 10;
977 stub_unpack_int (buff, fieldlength)
986 nibble = stubhex (*buff++);
990 retval = retval << 4;
996 unpack_varlen_hex (buff, result)
997 char *buff; /* packet to parse */
1003 while (ishex (*buff, &nibble))
1006 retval = retval << 4;
1007 retval |= nibble & 0x0f;
1014 unpack_nibble (buf, val)
1018 ishex (*buf++, val);
1023 pack_nibble (buf, nibble)
1027 *buf++ = hexchars[(nibble & 0x0f)];
1032 pack_hex_byte (pkt, byte)
1036 *pkt++ = hexchars[(byte >> 4) & 0xf];
1037 *pkt++ = hexchars[(byte & 0xf)];
1042 unpack_byte (buf, value)
1046 *value = stub_unpack_int (buf, 2);
1051 pack_int (buf, value)
1055 buf = pack_hex_byte (buf, (value >> 24) & 0xff);
1056 buf = pack_hex_byte (buf, (value >> 16) & 0xff);
1057 buf = pack_hex_byte (buf, (value >> 8) & 0x0ff);
1058 buf = pack_hex_byte (buf, (value & 0xff));
1063 unpack_int (buf, value)
1067 *value = stub_unpack_int (buf, 8);
1071 #if 0 /* currently unused, uncomment when needed */
1072 static char *pack_string PARAMS ((char *pkt, char *string));
1075 pack_string (pkt, string)
1082 len = strlen (string);
1084 len = 200; /* Bigger than most GDB packets, junk??? */
1085 pkt = pack_hex_byte (pkt, len);
1089 if ((ch == '\0') || (ch == '#'))
1090 ch = '*'; /* Protect encapsulation */
1095 #endif /* 0 (unused) */
1098 unpack_string (src, dest, length)
1110 pack_threadid (pkt, id)
1115 unsigned char *altid;
1117 altid = (unsigned char *) id;
1118 limit = pkt + BUF_THREAD_ID_SIZE;
1120 pkt = pack_hex_byte (pkt, *altid++);
1126 unpack_threadid (inbuf, id)
1131 char *limit = inbuf + BUF_THREAD_ID_SIZE;
1134 altref = (char *) id;
1136 while (inbuf < limit)
1138 x = stubhex (*inbuf++);
1139 y = stubhex (*inbuf++);
1140 *altref++ = (x << 4) | y;
1145 /* Externally, threadrefs are 64 bits but internally, they are still
1146 ints. This is due to a mismatch of specifications. We would like
1147 to use 64bit thread references internally. This is an adapter
1151 int_to_threadref (id, value)
1155 unsigned char *scan;
1157 scan = (unsigned char *) id;
1163 *scan++ = (value >> 24) & 0xff;
1164 *scan++ = (value >> 16) & 0xff;
1165 *scan++ = (value >> 8) & 0xff;
1166 *scan++ = (value & 0xff);
1170 threadref_to_int (ref)
1174 unsigned char *scan;
1176 scan = (char *) ref;
1180 value = (value << 8) | ((*scan++) & 0xff);
1185 copy_threadref (dest, src)
1190 unsigned char *csrc, *cdest;
1192 csrc = (unsigned char *) src;
1193 cdest = (unsigned char *) dest;
1200 threadmatch (dest, src)
1204 /* things are broken right now, so just assume we got a match */
1206 unsigned char *srcp, *destp;
1208 srcp = (char *) src;
1209 destp = (char *) dest;
1213 result &= (*srcp++ == *destp++) ? 1 : 0;
1220 threadid:1, # always request threadid
1227 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1230 pack_threadinfo_request (pkt, mode, id)
1235 *pkt++ = 'q'; /* Info Query */
1236 *pkt++ = 'P'; /* process or thread info */
1237 pkt = pack_int (pkt, mode); /* mode */
1238 pkt = pack_threadid (pkt, id); /* threadid */
1239 *pkt = '\0'; /* terminate */
1243 /* These values tag the fields in a thread info response packet */
1244 /* Tagging the fields allows us to request specific fields and to
1245 add more fields as time goes by */
1247 #define TAG_THREADID 1 /* Echo the thread identifier */
1248 #define TAG_EXISTS 2 /* Is this process defined enough to
1249 fetch registers and its stack */
1250 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1251 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
1252 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1256 remote_unpack_thread_info_response (pkt, expectedref, info)
1258 threadref *expectedref;
1259 struct gdb_ext_thread_info *info;
1264 char *limit = pkt + PBUFSIZ; /* plausable parsing limit */
1267 /* info->threadid = 0; FIXME: implement zero_threadref */
1269 info->display[0] = '\0';
1270 info->shortname[0] = '\0';
1271 info->more_display[0] = '\0';
1273 /* Assume the characters indicating the packet type have been stripped */
1274 pkt = unpack_int (pkt, &mask); /* arg mask */
1275 pkt = unpack_threadid (pkt, &ref);
1278 warning ("Incomplete response to threadinfo request\n");
1279 if (!threadmatch (&ref, expectedref))
1280 { /* This is an answer to a different request */
1281 warning ("ERROR RMT Thread info mismatch\n");
1284 copy_threadref (&info->threadid, &ref);
1286 /* Loop on tagged fields , try to bail if somthing goes wrong */
1288 while ((pkt < limit) && mask && *pkt) /* packets are terminated with nulls */
1290 pkt = unpack_int (pkt, &tag); /* tag */
1291 pkt = unpack_byte (pkt, &length); /* length */
1292 if (!(tag & mask)) /* tags out of synch with mask */
1294 warning ("ERROR RMT: threadinfo tag mismatch\n");
1298 if (tag == TAG_THREADID)
1302 warning ("ERROR RMT: length of threadid is not 16\n");
1306 pkt = unpack_threadid (pkt, &ref);
1307 mask = mask & ~TAG_THREADID;
1310 if (tag == TAG_EXISTS)
1312 info->active = stub_unpack_int (pkt, length);
1314 mask = mask & ~(TAG_EXISTS);
1317 warning ("ERROR RMT: 'exists' length too long\n");
1323 if (tag == TAG_THREADNAME)
1325 pkt = unpack_string (pkt, &info->shortname[0], length);
1326 mask = mask & ~TAG_THREADNAME;
1329 if (tag == TAG_DISPLAY)
1331 pkt = unpack_string (pkt, &info->display[0], length);
1332 mask = mask & ~TAG_DISPLAY;
1335 if (tag == TAG_MOREDISPLAY)
1337 pkt = unpack_string (pkt, &info->more_display[0], length);
1338 mask = mask & ~TAG_MOREDISPLAY;
1341 warning ("ERROR RMT: unknown thread info tag\n");
1342 break; /* Not a tag we know about */
1348 remote_get_threadinfo (threadid, fieldset, info)
1349 threadref *threadid;
1350 int fieldset; /* TAG mask */
1351 struct gdb_ext_thread_info *info;
1354 char *threadinfo_pkt = alloca (PBUFSIZ);
1356 pack_threadinfo_request (threadinfo_pkt, fieldset, threadid);
1357 putpkt (threadinfo_pkt);
1358 getpkt (threadinfo_pkt, PBUFSIZ, 0);
1359 result = remote_unpack_thread_info_response (threadinfo_pkt + 2, threadid,
1364 /* Unfortunately, 61 bit thread-ids are bigger than the internal
1365 representation of a threadid. */
1368 adapt_remote_get_threadinfo (ref, selection, info)
1371 struct gdb_ext_thread_info *info;
1375 int_to_threadref (&lclref, *ref);
1376 return remote_get_threadinfo (&lclref, selection, info);
1379 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1382 pack_threadlist_request (pkt, startflag, threadcount, nextthread)
1386 threadref *nextthread;
1388 *pkt++ = 'q'; /* info query packet */
1389 *pkt++ = 'L'; /* Process LIST or threadLIST request */
1390 pkt = pack_nibble (pkt, startflag); /* initflag 1 bytes */
1391 pkt = pack_hex_byte (pkt, threadcount); /* threadcount 2 bytes */
1392 pkt = pack_threadid (pkt, nextthread); /* 64 bit thread identifier */
1397 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1400 parse_threadlist_response (pkt, result_limit, original_echo, resultlist,
1404 threadref *original_echo;
1405 threadref *resultlist;
1409 int count, resultcount, done;
1412 /* Assume the 'q' and 'M chars have been stripped. */
1413 limit = pkt + (PBUFSIZ - BUF_THREAD_ID_SIZE); /* done parse past here */
1414 pkt = unpack_byte (pkt, &count); /* count field */
1415 pkt = unpack_nibble (pkt, &done);
1416 /* The first threadid is the argument threadid. */
1417 pkt = unpack_threadid (pkt, original_echo); /* should match query packet */
1418 while ((count-- > 0) && (pkt < limit))
1420 pkt = unpack_threadid (pkt, resultlist++);
1421 if (resultcount++ >= result_limit)
1430 remote_get_threadlist (startflag, nextthread, result_limit,
1431 done, result_count, threadlist)
1433 threadref *nextthread;
1437 threadref *threadlist;
1440 static threadref echo_nextthread;
1441 char *threadlist_packet = alloca (PBUFSIZ);
1442 char *t_response = alloca (PBUFSIZ);
1445 /* Trancate result limit to be smaller than the packet size */
1446 if ((((result_limit + 1) * BUF_THREAD_ID_SIZE) + 10) >= PBUFSIZ)
1447 result_limit = (PBUFSIZ / BUF_THREAD_ID_SIZE) - 2;
1449 pack_threadlist_request (threadlist_packet,
1450 startflag, result_limit, nextthread);
1451 putpkt (threadlist_packet);
1452 getpkt (t_response, PBUFSIZ, 0);
1455 parse_threadlist_response (t_response + 2, result_limit, &echo_nextthread,
1458 if (!threadmatch (&echo_nextthread, nextthread))
1460 /* FIXME: This is a good reason to drop the packet */
1461 /* Possably, there is a duplicate response */
1463 retransmit immediatly - race conditions
1464 retransmit after timeout - yes
1466 wait for packet, then exit
1468 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1469 return 0; /* I choose simply exiting */
1471 if (*result_count <= 0)
1475 warning ("RMT ERROR : failed to get remote thread list\n");
1478 return result; /* break; */
1480 if (*result_count > result_limit)
1483 warning ("RMT ERROR: threadlist response longer than requested\n");
1489 /* This is the interface between remote and threads, remotes upper interface */
1491 /* remote_find_new_threads retrieves the thread list and for each
1492 thread in the list, looks up the thread in GDB's internal list,
1493 ading the thread if it does not already exist. This involves
1494 getting partial thread lists from the remote target so, polling the
1495 quit_flag is required. */
1498 /* About this many threadisds fit in a packet. */
1500 #define MAXTHREADLISTRESULTS 32
1503 remote_threadlist_iterator (stepfunction, context, looplimit)
1504 rmt_thread_action stepfunction;
1508 int done, i, result_count;
1512 static threadref nextthread;
1513 static threadref resultthreadlist[MAXTHREADLISTRESULTS];
1518 if (loopcount++ > looplimit)
1521 warning ("Remote fetch threadlist -infinite loop-\n");
1524 if (!remote_get_threadlist (startflag, &nextthread, MAXTHREADLISTRESULTS,
1525 &done, &result_count, resultthreadlist))
1530 /* clear for later iterations */
1532 /* Setup to resume next batch of thread references, set nextthread. */
1533 if (result_count >= 1)
1534 copy_threadref (&nextthread, &resultthreadlist[result_count - 1]);
1536 while (result_count--)
1537 if (!(result = (*stepfunction) (&resultthreadlist[i++], context)))
1544 remote_newthread_step (ref, context)
1550 pid = threadref_to_int (ref);
1551 if (!in_thread_list (pid))
1553 return 1; /* continue iterator */
1556 #define CRAZY_MAX_THREADS 1000
1559 remote_current_thread (oldpid)
1562 char *buf = alloca (PBUFSIZ);
1565 getpkt (buf, PBUFSIZ, 0);
1566 if (buf[0] == 'Q' && buf[1] == 'C')
1567 return strtol (&buf[2], NULL, 16);
1572 /* Find new threads for info threads command.
1573 * Original version, using John Metzler's thread protocol.
1577 remote_find_new_threads ()
1579 remote_threadlist_iterator (remote_newthread_step, 0,
1581 if (inferior_pid == MAGIC_NULL_PID) /* ack ack ack */
1582 inferior_pid = remote_current_thread (inferior_pid);
1586 * Find all threads for info threads command.
1587 * Uses new thread protocol contributed by Cisco.
1588 * Falls back and attempts to use the older method (above)
1589 * if the target doesn't respond to the new method.
1593 remote_threads_info (void)
1595 char *buf = alloca (PBUFSIZ);
1599 if (remote_desc == 0) /* paranoia */
1600 error ("Command can only be used when connected to the remote target.");
1602 if (use_threadinfo_query)
1604 putpkt ("qfThreadInfo");
1606 getpkt (bufp, PBUFSIZ, 0);
1607 if (bufp[0] != '\0') /* q packet recognized */
1609 while (*bufp++ == 'm') /* reply contains one or more TID */
1613 tid = strtol (bufp, &bufp, 16);
1614 if (tid != 0 && !in_thread_list (tid))
1617 while (*bufp++ == ','); /* comma-separated list */
1618 putpkt ("qsThreadInfo");
1620 getpkt (bufp, PBUFSIZ, 0);
1626 /* Else fall back to old method based on jmetzler protocol. */
1627 use_threadinfo_query = 0;
1628 remote_find_new_threads ();
1633 * Collect a descriptive string about the given thread.
1634 * The target may say anything it wants to about the thread
1635 * (typically info about its blocked / runnable state, name, etc.).
1636 * This string will appear in the info threads display.
1638 * Optional: targets are not required to implement this function.
1642 remote_threads_extra_info (struct thread_info *tp)
1647 struct gdb_ext_thread_info threadinfo;
1648 static char display_buf[100]; /* arbitrary... */
1649 char *bufp = alloca (PBUFSIZ);
1650 int n = 0; /* position in display_buf */
1652 if (remote_desc == 0) /* paranoia */
1653 internal_error ("remote_threads_extra_info");
1655 if (use_threadextra_query)
1657 sprintf (bufp, "qThreadExtraInfo,%x", tp->pid);
1659 getpkt (bufp, PBUFSIZ, 0);
1664 for (p = display_buf;
1665 p < display_buf + sizeof(display_buf) - 1 &&
1670 *p = fromhex (bufp[0]) * 16 + fromhex (bufp[1]);
1677 /* If the above query fails, fall back to the old method. */
1678 use_threadextra_query = 0;
1679 set = TAG_THREADID | TAG_EXISTS | TAG_THREADNAME
1680 | TAG_MOREDISPLAY | TAG_DISPLAY;
1681 int_to_threadref (&id, tp->pid);
1682 if (remote_get_threadinfo (&id, set, &threadinfo))
1683 if (threadinfo.active)
1685 if (*threadinfo.shortname)
1686 n += sprintf(&display_buf[0], " Name: %s,", threadinfo.shortname);
1687 if (*threadinfo.display)
1688 n += sprintf(&display_buf[n], " State: %s,", threadinfo.display);
1689 if (*threadinfo.more_display)
1690 n += sprintf(&display_buf[n], " Priority: %s",
1691 threadinfo.more_display);
1695 /* for purely cosmetic reasons, clear up trailing commas */
1696 if (',' == display_buf[n-1])
1697 display_buf[n-1] = ' ';
1706 /* Restart the remote side; this is an extended protocol operation. */
1709 extended_remote_restart ()
1711 char *buf = alloca (PBUFSIZ);
1713 /* Send the restart command; for reasons I don't understand the
1714 remote side really expects a number after the "R". */
1716 sprintf (&buf[1], "%x", 0);
1719 /* Now query for status so this looks just like we restarted
1720 gdbserver from scratch. */
1722 getpkt (buf, PBUFSIZ, 0);
1725 /* Clean up connection to a remote debugger. */
1729 remote_close (quitting)
1733 SERIAL_CLOSE (remote_desc);
1737 /* Query the remote side for the text, data and bss offsets. */
1742 char *buf = alloca (PBUFSIZ);
1745 CORE_ADDR text_addr, data_addr, bss_addr;
1746 struct section_offsets *offs;
1748 putpkt ("qOffsets");
1750 getpkt (buf, PBUFSIZ, 0);
1752 if (buf[0] == '\000')
1753 return; /* Return silently. Stub doesn't support
1757 warning ("Remote failure reply: %s", buf);
1761 /* Pick up each field in turn. This used to be done with scanf, but
1762 scanf will make trouble if CORE_ADDR size doesn't match
1763 conversion directives correctly. The following code will work
1764 with any size of CORE_ADDR. */
1765 text_addr = data_addr = bss_addr = 0;
1769 if (strncmp (ptr, "Text=", 5) == 0)
1772 /* Don't use strtol, could lose on big values. */
1773 while (*ptr && *ptr != ';')
1774 text_addr = (text_addr << 4) + fromhex (*ptr++);
1779 if (!lose && strncmp (ptr, ";Data=", 6) == 0)
1782 while (*ptr && *ptr != ';')
1783 data_addr = (data_addr << 4) + fromhex (*ptr++);
1788 if (!lose && strncmp (ptr, ";Bss=", 5) == 0)
1791 while (*ptr && *ptr != ';')
1792 bss_addr = (bss_addr << 4) + fromhex (*ptr++);
1798 error ("Malformed response to offset query, %s", buf);
1800 if (symfile_objfile == NULL)
1803 offs = (struct section_offsets *) alloca (SIZEOF_SECTION_OFFSETS);
1804 memcpy (offs, symfile_objfile->section_offsets, SIZEOF_SECTION_OFFSETS);
1806 ANOFFSET (offs, SECT_OFF_TEXT (symfile_objfile)) = text_addr;
1808 /* This is a temporary kludge to force data and bss to use the same offsets
1809 because that's what nlmconv does now. The real solution requires changes
1810 to the stub and remote.c that I don't have time to do right now. */
1812 ANOFFSET (offs, SECT_OFF_DATA (symfile_objfile)) = data_addr;
1813 ANOFFSET (offs, SECT_OFF_BSS (symfile_objfile)) = data_addr;
1815 objfile_relocate (symfile_objfile, offs);
1819 * Cisco version of section offsets:
1821 * Instead of having GDB query the target for the section offsets,
1822 * Cisco lets the target volunteer the information! It's also in
1823 * a different format, so here are the functions that will decode
1824 * a section offset packet from a Cisco target.
1828 * Function: remote_cisco_section_offsets
1830 * Returns: zero for success, non-zero for failure
1834 remote_cisco_section_offsets (bfd_vma text_addr,
1837 bfd_signed_vma *text_offs,
1838 bfd_signed_vma *data_offs,
1839 bfd_signed_vma *bss_offs)
1841 bfd_vma text_base, data_base, bss_base;
1842 struct minimal_symbol *start;
1848 if (symfile_objfile == NULL)
1849 return -1; /* no can do nothin' */
1851 start = lookup_minimal_symbol ("_start", NULL, NULL);
1853 return -1; /* Can't find "_start" symbol */
1855 data_base = bss_base = 0;
1856 text_base = SYMBOL_VALUE_ADDRESS (start);
1858 abfd = symfile_objfile->obfd;
1859 for (sect = abfd->sections;
1863 p = (unsigned char *) bfd_get_section_name (abfd, sect);
1865 if (strcmp (p + len - 4, "data") == 0) /* ends in "data" */
1866 if (data_base == 0 ||
1867 data_base > bfd_get_section_vma (abfd, sect))
1868 data_base = bfd_get_section_vma (abfd, sect);
1869 if (strcmp (p + len - 3, "bss") == 0) /* ends in "bss" */
1870 if (bss_base == 0 ||
1871 bss_base > bfd_get_section_vma (abfd, sect))
1872 bss_base = bfd_get_section_vma (abfd, sect);
1874 *text_offs = text_addr - text_base;
1875 *data_offs = data_addr - data_base;
1876 *bss_offs = bss_addr - bss_base;
1881 sprintf (tmp, "VMA: text = 0x");
1882 sprintf_vma (tmp + strlen (tmp), text_addr);
1883 sprintf (tmp + strlen (tmp), " data = 0x");
1884 sprintf_vma (tmp + strlen (tmp), data_addr);
1885 sprintf (tmp + strlen (tmp), " bss = 0x");
1886 sprintf_vma (tmp + strlen (tmp), bss_addr);
1887 fprintf_filtered (gdb_stdlog, tmp);
1888 fprintf_filtered (gdb_stdlog,
1889 "Reloc offset: text = 0x%s data = 0x%s bss = 0x%s\n",
1890 paddr_nz (*text_offs),
1891 paddr_nz (*data_offs),
1892 paddr_nz (*bss_offs));
1899 * Function: remote_cisco_objfile_relocate
1901 * Relocate the symbol file for a remote target.
1905 remote_cisco_objfile_relocate (text_off, data_off, bss_off)
1906 bfd_signed_vma text_off;
1907 bfd_signed_vma data_off;
1908 bfd_signed_vma bss_off;
1910 struct section_offsets *offs;
1912 if (text_off != 0 || data_off != 0 || bss_off != 0)
1914 /* FIXME: This code assumes gdb-stabs.h is being used; it's
1915 broken for xcoff, dwarf, sdb-coff, etc. But there is no
1916 simple canonical representation for this stuff. */
1918 offs = (struct section_offsets *) alloca (SIZEOF_SECTION_OFFSETS);
1919 memcpy (offs, symfile_objfile->section_offsets, SIZEOF_SECTION_OFFSETS);
1921 ANOFFSET (offs, SECT_OFF_TEXT (symfile_objfile)) = text_off;
1922 ANOFFSET (offs, SECT_OFF_DATA (symfile_objfile)) = data_off;
1923 ANOFFSET (offs, SECT_OFF_BSS (symfile_objfile)) = bss_off;
1925 /* First call the standard objfile_relocate. */
1926 objfile_relocate (symfile_objfile, offs);
1928 /* Now we need to fix up the section entries already attached to
1929 the exec target. These entries will control memory transfers
1930 from the exec file. */
1932 exec_set_section_offsets (text_off, data_off, bss_off);
1936 /* Stub for catch_errors. */
1939 remote_start_remote_dummy (void *dummy)
1941 start_remote (); /* Initialize gdb process mechanisms */
1946 remote_start_remote (dummy)
1949 immediate_quit = 1; /* Allow user to interrupt it */
1951 /* Ack any packet which the remote side has already sent. */
1952 SERIAL_WRITE (remote_desc, "+", 1);
1954 /* Let the stub know that we want it to return the thread. */
1957 inferior_pid = remote_current_thread (inferior_pid);
1959 get_offsets (); /* Get text, data & bss offsets */
1961 putpkt ("?"); /* initiate a query from remote machine */
1964 return remote_start_remote_dummy (dummy);
1967 /* Open a connection to a remote debugger.
1968 NAME is the filename used for communication. */
1971 remote_open (name, from_tty)
1975 remote_open_1 (name, from_tty, &remote_ops, 0);
1978 /* Just like remote_open, but with asynchronous support. */
1980 remote_async_open (name, from_tty)
1984 remote_async_open_1 (name, from_tty, &remote_async_ops, 0);
1987 /* Open a connection to a remote debugger using the extended
1988 remote gdb protocol. NAME is the filename used for communication. */
1991 extended_remote_open (name, from_tty)
1995 remote_open_1 (name, from_tty, &extended_remote_ops, 1 /*extended_p */ );
1998 /* Just like extended_remote_open, but with asynchronous support. */
2000 extended_remote_async_open (name, from_tty)
2004 remote_async_open_1 (name, from_tty, &extended_async_remote_ops, 1 /*extended_p */ );
2007 /* Generic code for opening a connection to a remote target. */
2009 static DCACHE *remote_dcache;
2012 remote_open_1 (name, from_tty, target, extended_p)
2015 struct target_ops *target;
2019 error ("To open a remote debug connection, you need to specify what\n\
2020 serial device is attached to the remote system\n\
2021 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
2023 /* See FIXME above */
2024 wait_forever_enabled_p = 1;
2026 target_preopen (from_tty);
2028 unpush_target (target);
2030 remote_dcache = dcache_init (remote_read_bytes, remote_write_bytes);
2032 remote_desc = SERIAL_OPEN (name);
2034 perror_with_name (name);
2036 if (baud_rate != -1)
2038 if (SERIAL_SETBAUDRATE (remote_desc, baud_rate))
2040 SERIAL_CLOSE (remote_desc);
2041 perror_with_name (name);
2045 SERIAL_RAW (remote_desc);
2047 /* If there is something sitting in the buffer we might take it as a
2048 response to a command, which would be bad. */
2049 SERIAL_FLUSH_INPUT (remote_desc);
2053 puts_filtered ("Remote debugging using ");
2054 puts_filtered (name);
2055 puts_filtered ("\n");
2057 push_target (target); /* Switch to using remote target now */
2059 init_packet_config (&remote_protocol_P);
2060 init_packet_config (&remote_protocol_Z);
2062 general_thread = -2;
2063 continue_thread = -2;
2065 /* Force remote_write_bytes to check whether target supports
2066 binary downloading. */
2067 init_packet_config (&remote_protocol_binary_download);
2069 /* Probe for ability to use "ThreadInfo" query, as required. */
2070 use_threadinfo_query = 1;
2071 use_threadextra_query = 1;
2073 /* Without this, some commands which require an active target (such
2074 as kill) won't work. This variable serves (at least) double duty
2075 as both the pid of the target process (if it has such), and as a
2076 flag indicating that a target is active. These functions should
2077 be split out into seperate variables, especially since GDB will
2078 someday have a notion of debugging several processes. */
2080 inferior_pid = MAGIC_NULL_PID;
2081 /* Start the remote connection; if error (0), discard this target.
2082 In particular, if the user quits, be sure to discard it
2083 (we'd be in an inconsistent state otherwise). */
2084 if (!catch_errors (remote_start_remote, NULL,
2085 "Couldn't establish connection to remote target\n",
2094 /* tell the remote that we're using the extended protocol. */
2095 char *buf = alloca (PBUFSIZ);
2097 getpkt (buf, PBUFSIZ, 0);
2101 /* Just like remote_open but with asynchronous support. */
2103 remote_async_open_1 (name, from_tty, target, extended_p)
2106 struct target_ops *target;
2110 error ("To open a remote debug connection, you need to specify what\n\
2111 serial device is attached to the remote system\n\
2112 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
2114 target_preopen (from_tty);
2116 unpush_target (target);
2118 remote_dcache = dcache_init (remote_read_bytes, remote_write_bytes);
2120 remote_desc = SERIAL_OPEN (name);
2122 perror_with_name (name);
2124 if (baud_rate != -1)
2126 if (SERIAL_SETBAUDRATE (remote_desc, baud_rate))
2128 SERIAL_CLOSE (remote_desc);
2129 perror_with_name (name);
2133 SERIAL_RAW (remote_desc);
2135 /* If there is something sitting in the buffer we might take it as a
2136 response to a command, which would be bad. */
2137 SERIAL_FLUSH_INPUT (remote_desc);
2141 puts_filtered ("Remote debugging using ");
2142 puts_filtered (name);
2143 puts_filtered ("\n");
2146 push_target (target); /* Switch to using remote target now */
2148 init_packet_config (&remote_protocol_P);
2149 init_packet_config (&remote_protocol_Z);
2151 general_thread = -2;
2152 continue_thread = -2;
2154 /* Force remote_write_bytes to check whether target supports
2155 binary downloading. */
2156 init_packet_config (&remote_protocol_binary_download);
2158 /* Probe for ability to use "ThreadInfo" query, as required. */
2159 use_threadinfo_query = 1;
2160 use_threadextra_query = 1;
2162 /* Without this, some commands which require an active target (such
2163 as kill) won't work. This variable serves (at least) double duty
2164 as both the pid of the target process (if it has such), and as a
2165 flag indicating that a target is active. These functions should
2166 be split out into seperate variables, especially since GDB will
2167 someday have a notion of debugging several processes. */
2168 inferior_pid = MAGIC_NULL_PID;
2170 /* With this target we start out by owning the terminal. */
2171 remote_async_terminal_ours_p = 1;
2173 /* FIXME: cagney/1999-09-23: During the initial connection it is
2174 assumed that the target is already ready and able to respond to
2175 requests. Unfortunatly remote_start_remote() eventually calls
2176 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
2177 around this. Eventually a mechanism that allows
2178 wait_for_inferior() to expect/get timeouts will be
2180 wait_forever_enabled_p = 0;
2182 /* Start the remote connection; if error (0), discard this target.
2183 In particular, if the user quits, be sure to discard it
2184 (we'd be in an inconsistent state otherwise). */
2185 if (!catch_errors (remote_start_remote, NULL,
2186 "Couldn't establish connection to remote target\n",
2190 wait_forever_enabled_p = 1;
2194 wait_forever_enabled_p = 1;
2198 /* tell the remote that we're using the extended protocol. */
2199 char *buf = alloca (PBUFSIZ);
2201 getpkt (buf, PBUFSIZ, 0);
2205 /* This takes a program previously attached to and detaches it. After
2206 this is done, GDB can be used to debug some other program. We
2207 better not have left any breakpoints in the target program or it'll
2208 die when it hits one. */
2211 remote_detach (args, from_tty)
2215 char *buf = alloca (PBUFSIZ);
2218 error ("Argument given to \"detach\" when remotely debugging.");
2220 /* Tell the remote target to detach. */
2222 remote_send (buf, PBUFSIZ);
2224 target_mourn_inferior ();
2226 puts_filtered ("Ending remote debugging.\n");
2230 /* Same as remote_detach, but with async support. */
2232 remote_async_detach (args, from_tty)
2236 char *buf = alloca (PBUFSIZ);
2239 error ("Argument given to \"detach\" when remotely debugging.");
2241 /* Tell the remote target to detach. */
2243 remote_send (buf, PBUFSIZ);
2245 /* Unregister the file descriptor from the event loop. */
2246 if (target_is_async_p ())
2247 SERIAL_ASYNC (remote_desc, NULL, 0);
2249 target_mourn_inferior ();
2251 puts_filtered ("Ending remote debugging.\n");
2254 /* Convert hex digit A to a number. */
2260 if (a >= '0' && a <= '9')
2262 else if (a >= 'a' && a <= 'f')
2263 return a - 'a' + 10;
2264 else if (a >= 'A' && a <= 'F')
2265 return a - 'A' + 10;
2267 error ("Reply contains invalid hex digit %d", a);
2270 /* Convert number NIB to a hex digit. */
2279 return 'a' + nib - 10;
2282 /* Tell the remote machine to resume. */
2284 static enum target_signal last_sent_signal = TARGET_SIGNAL_0;
2286 static int last_sent_step;
2289 remote_resume (pid, step, siggnal)
2291 enum target_signal siggnal;
2293 char *buf = alloca (PBUFSIZ);
2296 set_thread (0, 0); /* run any thread */
2298 set_thread (pid, 0); /* run this thread */
2300 dcache_flush (remote_dcache);
2302 last_sent_signal = siggnal;
2303 last_sent_step = step;
2305 /* A hook for when we need to do something at the last moment before
2307 if (target_resume_hook)
2308 (*target_resume_hook) ();
2310 if (siggnal != TARGET_SIGNAL_0)
2312 buf[0] = step ? 'S' : 'C';
2313 buf[1] = tohex (((int) siggnal >> 4) & 0xf);
2314 buf[2] = tohex ((int) siggnal & 0xf);
2318 strcpy (buf, step ? "s" : "c");
2323 /* Same as remote_resume, but with async support. */
2325 remote_async_resume (pid, step, siggnal)
2327 enum target_signal siggnal;
2329 char *buf = alloca (PBUFSIZ);
2332 set_thread (0, 0); /* run any thread */
2334 set_thread (pid, 0); /* run this thread */
2336 dcache_flush (remote_dcache);
2338 last_sent_signal = siggnal;
2339 last_sent_step = step;
2341 /* A hook for when we need to do something at the last moment before
2343 if (target_resume_hook)
2344 (*target_resume_hook) ();
2346 if (siggnal != TARGET_SIGNAL_0)
2348 buf[0] = step ? 'S' : 'C';
2349 buf[1] = tohex (((int) siggnal >> 4) & 0xf);
2350 buf[2] = tohex ((int) siggnal & 0xf);
2354 strcpy (buf, step ? "s" : "c");
2356 /* We are about to start executing the inferior, let's register it
2357 with the event loop. NOTE: this is the one place where all the
2358 execution commands end up. We could alternatively do this in each
2359 of the execution commands in infcmd.c.*/
2360 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
2361 into infcmd.c in order to allow inferior function calls to work
2362 NOT asynchronously. */
2363 if (event_loop_p && target_can_async_p ())
2364 target_async (inferior_event_handler, 0);
2365 /* Tell the world that the target is now executing. */
2366 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
2367 this? Instead, should the client of target just assume (for
2368 async targets) that the target is going to start executing? Is
2369 this information already found in the continuation block? */
2370 if (target_is_async_p ())
2371 target_executing = 1;
2376 /* Set up the signal handler for SIGINT, while the target is
2377 executing, ovewriting the 'regular' SIGINT signal handler. */
2379 initialize_sigint_signal_handler ()
2381 sigint_remote_token =
2382 create_async_signal_handler (async_remote_interrupt, NULL);
2383 signal (SIGINT, handle_remote_sigint);
2386 /* Signal handler for SIGINT, while the target is executing. */
2388 handle_remote_sigint (sig)
2391 signal (sig, handle_remote_sigint_twice);
2392 sigint_remote_twice_token =
2393 create_async_signal_handler (async_remote_interrupt_twice, NULL);
2394 mark_async_signal_handler_wrapper (sigint_remote_token);
2397 /* Signal handler for SIGINT, installed after SIGINT has already been
2398 sent once. It will take effect the second time that the user sends
2401 handle_remote_sigint_twice (sig)
2404 signal (sig, handle_sigint);
2405 sigint_remote_twice_token =
2406 create_async_signal_handler (inferior_event_handler_wrapper, NULL);
2407 mark_async_signal_handler_wrapper (sigint_remote_twice_token);
2410 /* Perform the real interruption of the target execution, in response
2413 async_remote_interrupt (arg)
2414 gdb_client_data arg;
2417 fprintf_unfiltered (gdb_stdlog, "remote_interrupt called\n");
2422 /* Perform interrupt, if the first attempt did not succeed. Just give
2423 up on the target alltogether. */
2425 async_remote_interrupt_twice (arg)
2426 gdb_client_data arg;
2429 fprintf_unfiltered (gdb_stdlog, "remote_interrupt_twice called\n");
2430 /* Do something only if the target was not killed by the previous
2432 if (target_executing)
2435 signal (SIGINT, handle_remote_sigint);
2439 /* Reinstall the usual SIGINT handlers, after the target has
2442 cleanup_sigint_signal_handler (void *dummy)
2444 signal (SIGINT, handle_sigint);
2445 if (sigint_remote_twice_token)
2446 delete_async_signal_handler ((struct async_signal_handler **) & sigint_remote_twice_token);
2447 if (sigint_remote_token)
2448 delete_async_signal_handler ((struct async_signal_handler **) & sigint_remote_token);
2451 /* Send ^C to target to halt it. Target will respond, and send us a
2453 static void (*ofunc) PARAMS ((int));
2455 /* The command line interface's stop routine. This function is installed
2456 as a signal handler for SIGINT. The first time a user requests a
2457 stop, we call remote_stop to send a break or ^C. If there is no
2458 response from the target (it didn't stop when the user requested it),
2459 we ask the user if he'd like to detach from the target. */
2461 remote_interrupt (signo)
2464 /* If this doesn't work, try more severe steps. */
2465 signal (signo, remote_interrupt_twice);
2468 fprintf_unfiltered (gdb_stdlog, "remote_interrupt called\n");
2473 /* The user typed ^C twice. */
2476 remote_interrupt_twice (signo)
2479 signal (signo, ofunc);
2481 signal (signo, remote_interrupt);
2484 /* This is the generic stop called via the target vector. When a target
2485 interrupt is requested, either by the command line or the GUI, we
2486 will eventually end up here. */
2490 /* Send a break or a ^C, depending on user preference. */
2492 fprintf_unfiltered (gdb_stdlog, "remote_stop called\n");
2495 SERIAL_SEND_BREAK (remote_desc);
2497 SERIAL_WRITE (remote_desc, "\003", 1);
2500 /* Ask the user what to do when an interrupt is received. */
2505 target_terminal_ours ();
2507 if (query ("Interrupted while waiting for the program.\n\
2508 Give up (and stop debugging it)? "))
2510 target_mourn_inferior ();
2511 return_to_top_level (RETURN_QUIT);
2514 target_terminal_inferior ();
2517 /* Enable/disable target terminal ownership. Most targets can use
2518 terminal groups to control terminal ownership. Remote targets are
2519 different in that explicit transfer of ownership to/from GDB/target
2523 remote_async_terminal_inferior (void)
2525 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
2526 sync_execution here. This function should only be called when
2527 GDB is resuming the inferior in the forground. A background
2528 resume (``run&'') should leave GDB in control of the terminal and
2529 consequently should not call this code. */
2530 if (!sync_execution)
2532 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
2533 calls target_terminal_*() idenpotent. The event-loop GDB talking
2534 to an asynchronous target with a synchronous command calls this
2535 function from both event-top.c and infrun.c/infcmd.c. Once GDB
2536 stops trying to transfer the terminal to the target when it
2537 shouldn't this guard can go away. */
2538 if (!remote_async_terminal_ours_p)
2540 delete_file_handler (input_fd);
2541 remote_async_terminal_ours_p = 0;
2542 initialize_sigint_signal_handler ();
2543 /* NOTE: At this point we could also register our selves as the
2544 recipient of all input. Any characters typed could then be
2545 passed on down to the target. */
2549 remote_async_terminal_ours (void)
2551 /* See FIXME in remote_async_terminal_inferior. */
2552 if (!sync_execution)
2554 /* See FIXME in remote_async_terminal_inferior. */
2555 if (remote_async_terminal_ours_p)
2557 cleanup_sigint_signal_handler (NULL);
2558 add_file_handler (input_fd, stdin_event_handler, 0);
2559 remote_async_terminal_ours_p = 1;
2562 /* If nonzero, ignore the next kill. */
2567 remote_console_output (char *msg)
2571 for (p = msg; p[0] && p[1]; p += 2)
2574 char c = fromhex (p[0]) * 16 + fromhex (p[1]);
2577 fputs_unfiltered (tb, gdb_stdtarg);
2579 gdb_flush (gdb_stdtarg);
2582 /* Wait until the remote machine stops, then return,
2583 storing status in STATUS just as `wait' would.
2584 Returns "pid", which in the case of a multi-threaded
2585 remote OS, is the thread-id. */
2588 remote_wait (pid, status)
2590 struct target_waitstatus *status;
2592 unsigned char *buf = alloca (PBUFSIZ);
2593 int thread_num = -1;
2595 status->kind = TARGET_WAITKIND_EXITED;
2596 status->value.integer = 0;
2602 ofunc = signal (SIGINT, remote_interrupt);
2603 getpkt (buf, PBUFSIZ, 1);
2604 signal (SIGINT, ofunc);
2606 /* This is a hook for when we need to do something (perhaps the
2607 collection of trace data) every time the target stops. */
2608 if (target_wait_loop_hook)
2609 (*target_wait_loop_hook) ();
2613 case 'E': /* Error of some sort */
2614 warning ("Remote failure reply: %s", buf);
2616 case 'T': /* Status with PC, SP, FP, ... */
2620 char regs[MAX_REGISTER_RAW_SIZE];
2622 /* Expedited reply, containing Signal, {regno, reg} repeat */
2623 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2625 n... = register number
2626 r... = register contents
2628 p = &buf[3]; /* after Txx */
2635 /* Read the register number */
2636 regno = strtol ((const char *) p, &p_temp, 16);
2637 p1 = (unsigned char *) p_temp;
2639 if (p1 == p) /* No register number present here */
2641 p1 = (unsigned char *) strchr ((const char *) p, ':');
2643 warning ("Malformed packet(a) (missing colon): %s\n\
2646 if (strncmp ((const char *) p, "thread", p1 - p) == 0)
2648 p_temp = unpack_varlen_hex (++p1, &thread_num);
2649 record_currthread (thread_num);
2650 p = (unsigned char *) p_temp;
2658 warning ("Malformed packet(b) (missing colon): %s\n\
2662 if (regno >= NUM_REGS)
2663 warning ("Remote sent bad register number %ld: %s\n\
2667 for (i = 0; i < REGISTER_RAW_SIZE (regno); i++)
2669 if (p[0] == 0 || p[1] == 0)
2670 warning ("Remote reply is too short: %s", buf);
2671 regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
2674 supply_register (regno, regs);
2679 warning ("Remote register badly formatted: %s", buf);
2680 warning (" here: %s", p);
2685 case 'S': /* Old style status, just signal only */
2686 status->kind = TARGET_WAITKIND_STOPPED;
2687 status->value.sig = (enum target_signal)
2688 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2692 /* Export Cisco kernel mode as a convenience variable
2693 (so that it can be used in the GDB prompt if desired). */
2695 if (cisco_kernel_mode == 1)
2696 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2697 value_from_string ("PDEBUG-"));
2698 cisco_kernel_mode = 0;
2699 thread_num = strtol ((const char *) &buf[4], NULL, 16);
2700 record_currthread (thread_num);
2702 else if (buf[3] == 'k')
2704 /* Export Cisco kernel mode as a convenience variable
2705 (so that it can be used in the GDB prompt if desired). */
2707 if (cisco_kernel_mode == 1)
2708 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2709 value_from_string ("KDEBUG-"));
2710 cisco_kernel_mode = 1;
2713 case 'N': /* Cisco special: status and offsets */
2715 bfd_vma text_addr, data_addr, bss_addr;
2716 bfd_signed_vma text_off, data_off, bss_off;
2719 status->kind = TARGET_WAITKIND_STOPPED;
2720 status->value.sig = (enum target_signal)
2721 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2723 if (symfile_objfile == NULL)
2725 warning ("Relocation packet received with no symbol file. \
2730 /* Relocate object file. Buffer format is NAATT;DD;BB
2731 * where AA is the signal number, TT is the new text
2732 * address, DD * is the new data address, and BB is the
2733 * new bss address. */
2736 text_addr = strtoul (p, (char **) &p1, 16);
2737 if (p1 == p || *p1 != ';')
2738 warning ("Malformed relocation packet: Packet '%s'", buf);
2740 data_addr = strtoul (p, (char **) &p1, 16);
2741 if (p1 == p || *p1 != ';')
2742 warning ("Malformed relocation packet: Packet '%s'", buf);
2744 bss_addr = strtoul (p, (char **) &p1, 16);
2746 warning ("Malformed relocation packet: Packet '%s'", buf);
2748 if (remote_cisco_section_offsets (text_addr, data_addr, bss_addr,
2749 &text_off, &data_off, &bss_off)
2751 if (text_off != 0 || data_off != 0 || bss_off != 0)
2752 remote_cisco_objfile_relocate (text_off, data_off, bss_off);
2756 case 'W': /* Target exited */
2758 /* The remote process exited. */
2759 status->kind = TARGET_WAITKIND_EXITED;
2760 status->value.integer = (fromhex (buf[1]) << 4) + fromhex (buf[2]);
2764 status->kind = TARGET_WAITKIND_SIGNALLED;
2765 status->value.sig = (enum target_signal)
2766 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2770 case 'O': /* Console output */
2771 remote_console_output (buf + 1);
2774 if (last_sent_signal != TARGET_SIGNAL_0)
2776 /* Zero length reply means that we tried 'S' or 'C' and
2777 the remote system doesn't support it. */
2778 target_terminal_ours_for_output ();
2780 ("Can't send signals to this remote system. %s not sent.\n",
2781 target_signal_to_name (last_sent_signal));
2782 last_sent_signal = TARGET_SIGNAL_0;
2783 target_terminal_inferior ();
2785 strcpy ((char *) buf, last_sent_step ? "s" : "c");
2786 putpkt ((char *) buf);
2789 /* else fallthrough */
2791 warning ("Invalid remote reply: %s", buf);
2796 if (thread_num != -1)
2800 return inferior_pid;
2803 /* Async version of remote_wait. */
2805 remote_async_wait (pid, status)
2807 struct target_waitstatus *status;
2809 unsigned char *buf = alloca (PBUFSIZ);
2810 int thread_num = -1;
2812 status->kind = TARGET_WAITKIND_EXITED;
2813 status->value.integer = 0;
2819 if (!target_is_async_p ())
2820 ofunc = signal (SIGINT, remote_interrupt);
2821 /* FIXME: cagney/1999-09-27: If we're in async mode we should
2822 _never_ wait for ever -> test on target_is_async_p().
2823 However, before we do that we need to ensure that the caller
2824 knows how to take the target into/out of async mode. */
2825 getpkt (buf, PBUFSIZ, wait_forever_enabled_p);
2826 if (!target_is_async_p ())
2827 signal (SIGINT, ofunc);
2829 /* This is a hook for when we need to do something (perhaps the
2830 collection of trace data) every time the target stops. */
2831 if (target_wait_loop_hook)
2832 (*target_wait_loop_hook) ();
2836 case 'E': /* Error of some sort */
2837 warning ("Remote failure reply: %s", buf);
2839 case 'T': /* Status with PC, SP, FP, ... */
2843 char regs[MAX_REGISTER_RAW_SIZE];
2845 /* Expedited reply, containing Signal, {regno, reg} repeat */
2846 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2848 n... = register number
2849 r... = register contents
2851 p = &buf[3]; /* after Txx */
2858 /* Read the register number */
2859 regno = strtol ((const char *) p, &p_temp, 16);
2860 p1 = (unsigned char *) p_temp;
2862 if (p1 == p) /* No register number present here */
2864 p1 = (unsigned char *) strchr ((const char *) p, ':');
2866 warning ("Malformed packet(a) (missing colon): %s\n\
2869 if (strncmp ((const char *) p, "thread", p1 - p) == 0)
2871 p_temp = unpack_varlen_hex (++p1, &thread_num);
2872 record_currthread (thread_num);
2873 p = (unsigned char *) p_temp;
2881 warning ("Malformed packet(b) (missing colon): %s\n\
2885 if (regno >= NUM_REGS)
2886 warning ("Remote sent bad register number %ld: %s\n\
2890 for (i = 0; i < REGISTER_RAW_SIZE (regno); i++)
2892 if (p[0] == 0 || p[1] == 0)
2893 warning ("Remote reply is too short: %s", buf);
2894 regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
2897 supply_register (regno, regs);
2902 warning ("Remote register badly formatted: %s", buf);
2903 warning (" here: %s", p);
2908 case 'S': /* Old style status, just signal only */
2909 status->kind = TARGET_WAITKIND_STOPPED;
2910 status->value.sig = (enum target_signal)
2911 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2915 /* Export Cisco kernel mode as a convenience variable
2916 (so that it can be used in the GDB prompt if desired). */
2918 if (cisco_kernel_mode == 1)
2919 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2920 value_from_string ("PDEBUG-"));
2921 cisco_kernel_mode = 0;
2922 thread_num = strtol ((const char *) &buf[4], NULL, 16);
2923 record_currthread (thread_num);
2925 else if (buf[3] == 'k')
2927 /* Export Cisco kernel mode as a convenience variable
2928 (so that it can be used in the GDB prompt if desired). */
2930 if (cisco_kernel_mode == 1)
2931 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2932 value_from_string ("KDEBUG-"));
2933 cisco_kernel_mode = 1;
2936 case 'N': /* Cisco special: status and offsets */
2938 bfd_vma text_addr, data_addr, bss_addr;
2939 bfd_signed_vma text_off, data_off, bss_off;
2942 status->kind = TARGET_WAITKIND_STOPPED;
2943 status->value.sig = (enum target_signal)
2944 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2946 if (symfile_objfile == NULL)
2948 warning ("Relocation packet recieved with no symbol file. \
2953 /* Relocate object file. Buffer format is NAATT;DD;BB
2954 * where AA is the signal number, TT is the new text
2955 * address, DD * is the new data address, and BB is the
2956 * new bss address. */
2959 text_addr = strtoul (p, (char **) &p1, 16);
2960 if (p1 == p || *p1 != ';')
2961 warning ("Malformed relocation packet: Packet '%s'", buf);
2963 data_addr = strtoul (p, (char **) &p1, 16);
2964 if (p1 == p || *p1 != ';')
2965 warning ("Malformed relocation packet: Packet '%s'", buf);
2967 bss_addr = strtoul (p, (char **) &p1, 16);
2969 warning ("Malformed relocation packet: Packet '%s'", buf);
2971 if (remote_cisco_section_offsets (text_addr, data_addr, bss_addr,
2972 &text_off, &data_off, &bss_off)
2974 if (text_off != 0 || data_off != 0 || bss_off != 0)
2975 remote_cisco_objfile_relocate (text_off, data_off, bss_off);
2979 case 'W': /* Target exited */
2981 /* The remote process exited. */
2982 status->kind = TARGET_WAITKIND_EXITED;
2983 status->value.integer = (fromhex (buf[1]) << 4) + fromhex (buf[2]);
2987 status->kind = TARGET_WAITKIND_SIGNALLED;
2988 status->value.sig = (enum target_signal)
2989 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2993 case 'O': /* Console output */
2994 remote_console_output (buf + 1);
2995 /* Return immediately to the event loop. The event loop will
2996 still be waiting on the inferior afterwards. */
2997 status->kind = TARGET_WAITKIND_IGNORE;
3000 if (last_sent_signal != TARGET_SIGNAL_0)
3002 /* Zero length reply means that we tried 'S' or 'C' and
3003 the remote system doesn't support it. */
3004 target_terminal_ours_for_output ();
3006 ("Can't send signals to this remote system. %s not sent.\n",
3007 target_signal_to_name (last_sent_signal));
3008 last_sent_signal = TARGET_SIGNAL_0;
3009 target_terminal_inferior ();
3011 strcpy ((char *) buf, last_sent_step ? "s" : "c");
3012 putpkt ((char *) buf);
3015 /* else fallthrough */
3017 warning ("Invalid remote reply: %s", buf);
3022 if (thread_num != -1)
3026 return inferior_pid;
3029 /* Number of bytes of registers this stub implements. */
3031 static int register_bytes_found;
3033 /* Read the remote registers into the block REGS. */
3034 /* Currently we just read all the registers, so we don't use regno. */
3038 remote_fetch_registers (regno)
3041 char *buf = alloca (PBUFSIZ);
3044 char regs[REGISTER_BYTES];
3046 set_thread (inferior_pid, 1);
3049 remote_send (buf, PBUFSIZ);
3051 /* Save the size of the packet sent to us by the target. Its used
3052 as a heuristic when determining the max size of packets that the
3053 target can safely receive. */
3054 if (actual_register_packet_size == 0)
3055 actual_register_packet_size = strlen (buf);
3057 /* Unimplemented registers read as all bits zero. */
3058 memset (regs, 0, REGISTER_BYTES);
3060 /* We can get out of synch in various cases. If the first character
3061 in the buffer is not a hex character, assume that has happened
3062 and try to fetch another packet to read. */
3063 while ((buf[0] < '0' || buf[0] > '9')
3064 && (buf[0] < 'a' || buf[0] > 'f')
3065 && buf[0] != 'x') /* New: unavailable register value */
3068 fprintf_unfiltered (gdb_stdlog,
3069 "Bad register packet; fetching a new packet\n");
3070 getpkt (buf, PBUFSIZ, 0);
3073 /* Reply describes registers byte by byte, each byte encoded as two
3074 hex characters. Suck them all up, then supply them to the
3075 register cacheing/storage mechanism. */
3078 for (i = 0; i < REGISTER_BYTES; i++)
3084 warning ("Remote reply is of odd length: %s", buf);
3085 /* Don't change register_bytes_found in this case, and don't
3086 print a second warning. */
3089 if (p[0] == 'x' && p[1] == 'x')
3090 regs[i] = 0; /* 'x' */
3092 regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
3096 if (i != register_bytes_found)
3098 register_bytes_found = i;
3099 #ifdef REGISTER_BYTES_OK
3100 if (!REGISTER_BYTES_OK (i))
3101 warning ("Remote reply is too short: %s", buf);
3106 for (i = 0; i < NUM_REGS; i++)
3108 supply_register (i, ®s[REGISTER_BYTE (i)]);
3109 if (buf[REGISTER_BYTE (i) * 2] == 'x')
3110 register_valid[i] = -1; /* register value not available */
3114 /* Prepare to store registers. Since we may send them all (using a
3115 'G' request), we have to read out the ones we don't want to change
3119 remote_prepare_to_store ()
3121 /* Make sure the entire registers array is valid. */
3122 switch (remote_protocol_P.support)
3124 case PACKET_DISABLE:
3125 case PACKET_SUPPORT_UNKNOWN:
3126 read_register_bytes (0, (char *) NULL, REGISTER_BYTES);
3133 /* Helper: Attempt to store REGNO using the P packet. Return fail IFF
3134 packet was not recognized. */
3137 store_register_using_P (int regno)
3139 /* Try storing a single register. */
3140 char *buf = alloca (PBUFSIZ);
3145 sprintf (buf, "P%x=", regno);
3146 p = buf + strlen (buf);
3147 regp = ®isters[REGISTER_BYTE (regno)];
3148 for (i = 0; i < REGISTER_RAW_SIZE (regno); ++i)
3150 *p++ = tohex ((regp[i] >> 4) & 0xf);
3151 *p++ = tohex (regp[i] & 0xf);
3154 remote_send (buf, PBUFSIZ);
3156 return buf[0] != '\0';
3160 /* Store register REGNO, or all registers if REGNO == -1, from the contents
3161 of REGISTERS. FIXME: ignores errors. */
3164 remote_store_registers (regno)
3167 char *buf = alloca (PBUFSIZ);
3171 set_thread (inferior_pid, 1);
3175 switch (remote_protocol_P.support)
3177 case PACKET_DISABLE:
3180 if (store_register_using_P (regno))
3183 error ("Protocol error: P packet not recognized by stub");
3184 case PACKET_SUPPORT_UNKNOWN:
3185 if (store_register_using_P (regno))
3187 /* The stub recognized the 'P' packet. Remember this. */
3188 remote_protocol_P.support = PACKET_ENABLE;
3193 /* The stub does not support the 'P' packet. Use 'G'
3194 instead, and don't try using 'P' in the future (it
3195 will just waste our time). */
3196 remote_protocol_P.support = PACKET_DISABLE;
3204 /* Command describes registers byte by byte,
3205 each byte encoded as two hex characters. */
3208 /* remote_prepare_to_store insures that register_bytes_found gets set. */
3209 for (i = 0; i < register_bytes_found; i++)
3211 *p++ = tohex ((registers[i] >> 4) & 0xf);
3212 *p++ = tohex (registers[i] & 0xf);
3216 remote_send (buf, PBUFSIZ);
3219 /* Use of the data cache *used* to be disabled because it loses for looking
3220 at and changing hardware I/O ports and the like. Accepting `volatile'
3221 would perhaps be one way to fix it. Another idea would be to use the
3222 executable file for the text segment (for all SEC_CODE sections?
3223 For all SEC_READONLY sections?). This has problems if you want to
3224 actually see what the memory contains (e.g. self-modifying code,
3225 clobbered memory, user downloaded the wrong thing).
3227 Because it speeds so much up, it's now enabled, if you're playing
3228 with registers you turn it of (set remotecache 0). */
3230 /* Read a word from remote address ADDR and return it.
3231 This goes through the data cache. */
3235 remote_fetch_word (addr)
3238 return dcache_fetch (remote_dcache, addr);
3241 /* Write a word WORD into remote address ADDR.
3242 This goes through the data cache. */
3245 remote_store_word (addr, word)
3249 dcache_poke (remote_dcache, addr, word);
3251 #endif /* 0 (unused?) */
3255 /* Return the number of hex digits in num. */
3263 for (i = 0; num != 0; i++)
3269 /* Set BUF to the minimum number of hex digits representing NUM. */
3272 hexnumstr (buf, num)
3276 int len = hexnumlen (num);
3277 return hexnumnstr (buf, num, len);
3281 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
3284 hexnumnstr (buf, num, width)
3293 for (i = width - 1; i >= 0; i--)
3295 buf[i] = "0123456789abcdef"[(num & 0xf)];
3302 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
3305 remote_address_masked (addr)
3308 if (remote_address_size > 0
3309 && remote_address_size < (sizeof (ULONGEST) * 8))
3311 /* Only create a mask when that mask can safely be constructed
3312 in a ULONGEST variable. */
3314 mask = (mask << remote_address_size) - 1;
3320 /* Determine whether the remote target supports binary downloading.
3321 This is accomplished by sending a no-op memory write of zero length
3322 to the target at the specified address. It does not suffice to send
3323 the whole packet, since many stubs strip the eighth bit and subsequently
3324 compute a wrong checksum, which causes real havoc with remote_write_bytes.
3326 NOTE: This can still lose if the serial line is not eight-bit
3327 clean. In cases like this, the user should clear "remote
3331 check_binary_download (addr)
3334 switch (remote_protocol_binary_download.support)
3336 case PACKET_DISABLE:
3340 case PACKET_SUPPORT_UNKNOWN:
3342 char *buf = alloca (PBUFSIZ);
3347 p += hexnumstr (p, (ULONGEST) addr);
3349 p += hexnumstr (p, (ULONGEST) 0);
3353 putpkt_binary (buf, (int) (p - buf));
3354 getpkt (buf, PBUFSIZ, 0);
3359 fprintf_unfiltered (gdb_stdlog,
3360 "binary downloading NOT suppported by target\n");
3361 remote_protocol_binary_download.support = PACKET_DISABLE;
3366 fprintf_unfiltered (gdb_stdlog,
3367 "binary downloading suppported by target\n");
3368 remote_protocol_binary_download.support = PACKET_ENABLE;
3375 /* Write memory data directly to the remote machine.
3376 This does not inform the data cache; the data cache uses this.
3377 MEMADDR is the address in the remote memory space.
3378 MYADDR is the address of the buffer in our space.
3379 LEN is the number of bytes.
3381 Returns number of bytes transferred, or 0 (setting errno) for
3382 error. Only transfer a single packet. */
3385 remote_write_bytes (CORE_ADDR memaddr, char *myaddr, int len)
3388 int max_buf_size; /* Max size of packet output buffer */
3390 unsigned char *plen;
3396 /* Verify that the target can support a binary download */
3397 check_binary_download (memaddr);
3399 /* Determine the max packet size. */
3400 max_buf_size = get_memory_write_packet_size ();
3401 sizeof_buf = max_buf_size + 1; /* Space for trailing NUL */
3402 buf = alloca (sizeof_buf);
3404 /* Subtract header overhead from max payload size - $M<memaddr>,<len>:#nn */
3405 max_buf_size -= 2 + hexnumlen (memaddr + len - 1) + 1 + hexnumlen (len) + 4;
3407 /* construct "M"<memaddr>","<len>":" */
3408 /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
3411 /* Append [XM]. Compute a best guess of the number of bytes
3412 actually transfered. */
3413 switch (remote_protocol_binary_download.support)
3417 /* Best guess at number of bytes that will fit. */
3418 todo = min (len, max_buf_size);
3420 case PACKET_DISABLE:
3422 /* num bytes that will fit */
3423 todo = min (len, max_buf_size / 2);
3425 case PACKET_SUPPORT_UNKNOWN:
3426 internal_error ("remote_write_bytes: bad switch");
3429 /* Append <memaddr> */
3430 memaddr = remote_address_masked (memaddr);
3431 p += hexnumstr (p, (ULONGEST) memaddr);
3434 /* Append <len>. Retain the location/size of <len>. It may
3435 need to be adjusted once the packet body has been created. */
3437 plenlen = hexnumstr (p, (ULONGEST) todo);
3442 /* Append the packet body. */
3443 switch (remote_protocol_binary_download.support)
3446 /* Binary mode. Send target system values byte by byte, in
3447 increasing byte addresses. Only escape certain critical
3450 (nr_bytes < todo) && (p - buf) < (max_buf_size - 2);
3453 switch (myaddr[nr_bytes] & 0xff)
3458 /* These must be escaped */
3460 *p++ = (myaddr[nr_bytes] & 0xff) ^ 0x20;
3463 *p++ = myaddr[nr_bytes] & 0xff;
3467 if (nr_bytes < todo)
3469 /* Escape chars have filled up the buffer prematurely,
3470 and we have actually sent fewer bytes than planned.
3471 Fix-up the length field of the packet. Use the same
3472 number of characters as before. */
3474 plen += hexnumnstr (plen, (ULONGEST) nr_bytes, plenlen);
3475 *plen = ':'; /* overwrite \0 from hexnumnstr() */
3478 case PACKET_DISABLE:
3479 /* Normal mode: Send target system values byte by byte, in
3480 increasing byte addresses. Each byte is encoded as a two hex
3482 for (nr_bytes = 0; nr_bytes < todo; nr_bytes++)
3484 *p++ = tohex ((myaddr[nr_bytes] >> 4) & 0xf);
3485 *p++ = tohex (myaddr[nr_bytes] & 0xf);
3489 case PACKET_SUPPORT_UNKNOWN:
3490 internal_error ("remote_write_bytes: bad switch");
3493 putpkt_binary (buf, (int) (p - buf));
3494 getpkt (buf, sizeof_buf, 0);
3498 /* There is no correspondance between what the remote protocol
3499 uses for errors and errno codes. We would like a cleaner way
3500 of representing errors (big enough to include errno codes,
3501 bfd_error codes, and others). But for now just return EIO. */
3506 /* Return NR_BYTES, not TODO, in case escape chars caused us to send fewer
3507 bytes than we'd planned. */
3511 /* Read memory data directly from the remote machine.
3512 This does not use the data cache; the data cache uses this.
3513 MEMADDR is the address in the remote memory space.
3514 MYADDR is the address of the buffer in our space.
3515 LEN is the number of bytes.
3517 Returns number of bytes transferred, or 0 for error. */
3519 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
3520 remote targets) shouldn't attempt to read the entire buffer.
3521 Instead it should read a single packet worth of data and then
3522 return the byte size of that packet to the caller. The caller (its
3523 caller and its callers caller ;-) already contains code for
3524 handling partial reads. */
3527 remote_read_bytes (memaddr, myaddr, len)
3533 int max_buf_size; /* Max size of packet output buffer */
3537 /* Create a buffer big enough for this packet. */
3538 max_buf_size = get_memory_read_packet_size ();
3539 sizeof_buf = max_buf_size + 1; /* Space for trailing NUL */
3540 buf = alloca (sizeof_buf);
3549 todo = min (len, max_buf_size / 2); /* num bytes that will fit */
3551 /* construct "m"<memaddr>","<len>" */
3552 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
3553 memaddr = remote_address_masked (memaddr);
3556 p += hexnumstr (p, (ULONGEST) memaddr);
3558 p += hexnumstr (p, (ULONGEST) todo);
3562 getpkt (buf, sizeof_buf, 0);
3566 /* There is no correspondance between what the remote protocol uses
3567 for errors and errno codes. We would like a cleaner way of
3568 representing errors (big enough to include errno codes, bfd_error
3569 codes, and others). But for now just return EIO. */
3574 /* Reply describes memory byte by byte,
3575 each byte encoded as two hex characters. */
3578 for (i = 0; i < todo; i++)
3580 if (p[0] == 0 || p[1] == 0)
3581 /* Reply is short. This means that we were able to read
3582 only part of what we wanted to. */
3583 return i + (origlen - len);
3584 myaddr[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
3594 /* Read or write LEN bytes from inferior memory at MEMADDR,
3595 transferring to or from debugger address BUFFER. Write to inferior if
3596 SHOULD_WRITE is nonzero. Returns length of data written or read; 0
3601 remote_xfer_memory (mem_addr, buffer, mem_len, should_write, target)
3606 struct target_ops *target; /* ignored */
3608 CORE_ADDR targ_addr;
3610 REMOTE_TRANSLATE_XFER_ADDRESS (mem_addr, mem_len, &targ_addr, &targ_len);
3614 return dcache_xfer_memory (remote_dcache, targ_addr, buffer,
3615 targ_len, should_write);
3620 /* Enable after 4.12. */
3623 remote_search (len, data, mask, startaddr, increment, lorange, hirange
3624 addr_found, data_found)
3628 CORE_ADDR startaddr;
3632 CORE_ADDR *addr_found;
3635 if (increment == -4 && len == 4)
3637 long mask_long, data_long;
3638 long data_found_long;
3639 CORE_ADDR addr_we_found;
3640 char *buf = alloca (PBUFSIZ);
3641 long returned_long[2];
3644 mask_long = extract_unsigned_integer (mask, len);
3645 data_long = extract_unsigned_integer (data, len);
3646 sprintf (buf, "t%x:%x,%x", startaddr, data_long, mask_long);
3648 getpkt (buf, PBUFSIZ, 0);
3651 /* The stub doesn't support the 't' request. We might want to
3652 remember this fact, but on the other hand the stub could be
3653 switched on us. Maybe we should remember it only until
3654 the next "target remote". */
3655 generic_search (len, data, mask, startaddr, increment, lorange,
3656 hirange, addr_found, data_found);
3661 /* There is no correspondance between what the remote protocol uses
3662 for errors and errno codes. We would like a cleaner way of
3663 representing errors (big enough to include errno codes, bfd_error
3664 codes, and others). But for now just use EIO. */
3665 memory_error (EIO, startaddr);
3668 while (*p != '\0' && *p != ',')
3669 addr_we_found = (addr_we_found << 4) + fromhex (*p++);
3671 error ("Protocol error: short return for search");
3673 data_found_long = 0;
3674 while (*p != '\0' && *p != ',')
3675 data_found_long = (data_found_long << 4) + fromhex (*p++);
3676 /* Ignore anything after this comma, for future extensions. */
3678 if (addr_we_found < lorange || addr_we_found >= hirange)
3684 *addr_found = addr_we_found;
3685 *data_found = store_unsigned_integer (data_we_found, len);
3688 generic_search (len, data, mask, startaddr, increment, lorange,
3689 hirange, addr_found, data_found);
3694 remote_files_info (ignore)
3695 struct target_ops *ignore;
3697 puts_filtered ("Debugging a target over a serial line.\n");
3700 /* Stuff for dealing with the packets which are part of this protocol.
3701 See comment at top of file for details. */
3703 /* Read a single character from the remote end, masking it down to 7 bits. */
3711 ch = SERIAL_READCHAR (remote_desc, timeout);
3716 switch ((enum serial_rc) ch)
3719 target_mourn_inferior ();
3720 error ("Remote connection closed");
3723 perror_with_name ("Remote communication error");
3725 case SERIAL_TIMEOUT:
3731 /* Send the command in BUF to the remote machine, and read the reply
3732 into BUF. Report an error if we get an error reply. */
3735 remote_send (char *buf,
3739 getpkt (buf, sizeof_buf, 0);
3742 error ("Remote failure reply: %s", buf);
3745 /* Display a null-terminated packet on stdout, for debugging, using C
3752 puts_filtered ("\"");
3753 fputstr_filtered (buf, '"', gdb_stdout);
3754 puts_filtered ("\"");
3761 return putpkt_binary (buf, strlen (buf));
3764 /* Send a packet to the remote machine, with error checking. The data
3765 of the packet is in BUF. The string in BUF can be at most PBUFSIZ - 5
3766 to account for the $, # and checksum, and for a possible /0 if we are
3767 debugging (remote_debug) and want to print the sent packet as a string */
3770 putpkt_binary (buf, cnt)
3775 unsigned char csum = 0;
3776 char *buf2 = alloca (cnt + 6);
3777 long sizeof_junkbuf = PBUFSIZ;
3778 char *junkbuf = alloca (sizeof_junkbuf);
3784 /* Copy the packet into buffer BUF2, encapsulating it
3785 and giving it a checksum. */
3790 for (i = 0; i < cnt; i++)
3796 *p++ = tohex ((csum >> 4) & 0xf);
3797 *p++ = tohex (csum & 0xf);
3799 /* Send it over and over until we get a positive ack. */
3803 int started_error_output = 0;
3808 fprintf_unfiltered (gdb_stdlog, "Sending packet: ");
3809 fputstrn_unfiltered (buf2, p - buf2, 0, gdb_stdlog);
3810 fprintf_unfiltered (gdb_stdlog, "...");
3811 gdb_flush (gdb_stdlog);
3813 if (SERIAL_WRITE (remote_desc, buf2, p - buf2))
3814 perror_with_name ("putpkt: write failed");
3816 /* read until either a timeout occurs (-2) or '+' is read */
3819 ch = readchar (remote_timeout);
3827 case SERIAL_TIMEOUT:
3829 if (started_error_output)
3831 putchar_unfiltered ('\n');
3832 started_error_output = 0;
3841 fprintf_unfiltered (gdb_stdlog, "Ack\n");
3845 fprintf_unfiltered (gdb_stdlog, "Nak\n");
3846 case SERIAL_TIMEOUT:
3850 break; /* Retransmit buffer */
3853 /* It's probably an old response, and we're out of sync.
3854 Just gobble up the packet and ignore it. */
3855 getpkt (junkbuf, sizeof_junkbuf, 0);
3856 continue; /* Now, go look for + */
3861 if (!started_error_output)
3863 started_error_output = 1;
3864 fprintf_unfiltered (gdb_stdlog, "putpkt: Junk: ");
3866 fputc_unfiltered (ch & 0177, gdb_stdlog);
3870 break; /* Here to retransmit */
3874 /* This is wrong. If doing a long backtrace, the user should be
3875 able to get out next time we call QUIT, without anything as
3876 violent as interrupt_query. If we want to provide a way out of
3877 here without getting to the next QUIT, it should be based on
3878 hitting ^C twice as in remote_wait. */
3888 static int remote_cisco_mode;
3890 /* Come here after finding the start of the frame. Collect the rest
3891 into BUF, verifying the checksum, length, and handling run-length
3892 compression. No more than sizeof_buf-1 characters are read so that
3893 the buffer can be NUL terminated.
3895 Returns -1 on error, number of characters in buffer (ignoring the
3896 trailing NULL) on success. (could be extended to return one of the
3897 SERIAL status indications). */
3900 read_frame (char *buf,
3912 /* ASSERT (bc < sizeof_buf - 1) - space for trailing NUL */
3913 c = readchar (remote_timeout);
3916 case SERIAL_TIMEOUT:
3918 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog);
3922 fputs_filtered ("Saw new packet start in middle of old one\n",
3924 return -1; /* Start a new packet, count retries */
3927 unsigned char pktcsum;
3931 pktcsum = fromhex (readchar (remote_timeout)) << 4;
3932 pktcsum |= fromhex (readchar (remote_timeout));
3934 if (csum == pktcsum)
3939 fprintf_filtered (gdb_stdlog,
3940 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
3942 fputs_filtered (buf, gdb_stdlog);
3943 fputs_filtered ("\n", gdb_stdlog);
3945 /* Number of characters in buffer ignoring trailing
3949 case '*': /* Run length encoding */
3954 if (remote_cisco_mode == 0)
3956 c = readchar (remote_timeout);
3958 repeat = c - ' ' + 3; /* Compute repeat count */
3962 /* Cisco's run-length encoding variant uses two
3963 hex chars to represent the repeat count. */
3965 c = readchar (remote_timeout);
3967 repeat = fromhex (c) << 4;
3968 c = readchar (remote_timeout);
3970 repeat += fromhex (c);
3973 /* The character before ``*'' is repeated. */
3975 if (repeat > 0 && repeat <= 255
3977 && bc + repeat < sizeof_buf - 1)
3979 memset (&buf[bc], buf[bc - 1], repeat);
3985 printf_filtered ("Repeat count %d too large for buffer: ", repeat);
3986 puts_filtered (buf);
3987 puts_filtered ("\n");
3991 if (bc < sizeof_buf - 1)
3999 puts_filtered ("Remote packet too long: ");
4000 puts_filtered (buf);
4001 puts_filtered ("\n");
4008 /* Read a packet from the remote machine, with error checking, and
4009 store it in BUF. If FOREVER, wait forever rather than timing out;
4010 this is used (in synchronous mode) to wait for a target that is is
4011 executing user code to stop. */
4012 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
4013 don't have to change all the calls to getpkt to deal with the
4014 return value, because at the moment I don't know what the right
4015 thing to do it for those. */
4023 timed_out = getpkt_sane (buf, sizeof_buf, forever);
4027 /* Read a packet from the remote machine, with error checking, and
4028 store it in BUF. If FOREVER, wait forever rather than timing out;
4029 this is used (in synchronous mode) to wait for a target that is is
4030 executing user code to stop. If FOREVER == 0, this function is
4031 allowed to time out gracefully and return an indication of this to
4034 getpkt_sane (char *buf,
4043 strcpy (buf, "timeout");
4047 timeout = watchdog > 0 ? watchdog : -1;
4051 timeout = remote_timeout;
4055 for (tries = 1; tries <= MAX_TRIES; tries++)
4057 /* This can loop forever if the remote side sends us characters
4058 continuously, but if it pauses, we'll get a zero from readchar
4059 because of timeout. Then we'll count that as a retry. */
4061 /* Note that we will only wait forever prior to the start of a packet.
4062 After that, we expect characters to arrive at a brisk pace. They
4063 should show up within remote_timeout intervals. */
4067 c = readchar (timeout);
4069 if (c == SERIAL_TIMEOUT)
4071 if (forever) /* Watchdog went off? Kill the target. */
4074 target_mourn_inferior ();
4075 error ("Watchdog has expired. Target detached.\n");
4078 fputs_filtered ("Timed out.\n", gdb_stdlog);
4084 /* We've found the start of a packet, now collect the data. */
4086 val = read_frame (buf, sizeof_buf);
4092 fprintf_unfiltered (gdb_stdlog, "Packet received: ");
4093 fputstr_unfiltered (buf, 0, gdb_stdlog);
4094 fprintf_unfiltered (gdb_stdlog, "\n");
4096 SERIAL_WRITE (remote_desc, "+", 1);
4100 /* Try the whole thing again. */
4102 SERIAL_WRITE (remote_desc, "-", 1);
4105 /* We have tried hard enough, and just can't receive the packet. Give up. */
4107 printf_unfiltered ("Ignoring packet error, continuing...\n");
4108 SERIAL_WRITE (remote_desc, "+", 1);
4115 /* For some mysterious reason, wait_for_inferior calls kill instead of
4116 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4120 target_mourn_inferior ();
4124 /* Use catch_errors so the user can quit from gdb even when we aren't on
4125 speaking terms with the remote system. */
4126 catch_errors ((catch_errors_ftype *) putpkt, "k", "", RETURN_MASK_ERROR);
4128 /* Don't wait for it to die. I'm not really sure it matters whether
4129 we do or not. For the existing stubs, kill is a noop. */
4130 target_mourn_inferior ();
4133 /* Async version of remote_kill. */
4135 remote_async_kill ()
4137 /* Unregister the file descriptor from the event loop. */
4138 if (target_is_async_p ())
4139 SERIAL_ASYNC (remote_desc, NULL, 0);
4141 /* For some mysterious reason, wait_for_inferior calls kill instead of
4142 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4146 target_mourn_inferior ();
4150 /* Use catch_errors so the user can quit from gdb even when we aren't on
4151 speaking terms with the remote system. */
4152 catch_errors ((catch_errors_ftype *) putpkt, "k", "", RETURN_MASK_ERROR);
4154 /* Don't wait for it to die. I'm not really sure it matters whether
4155 we do or not. For the existing stubs, kill is a noop. */
4156 target_mourn_inferior ();
4162 remote_mourn_1 (&remote_ops);
4166 remote_async_mourn ()
4168 remote_mourn_1 (&remote_async_ops);
4172 extended_remote_mourn ()
4174 /* We do _not_ want to mourn the target like this; this will
4175 remove the extended remote target from the target stack,
4176 and the next time the user says "run" it'll fail.
4178 FIXME: What is the right thing to do here? */
4180 remote_mourn_1 (&extended_remote_ops);
4184 /* Worker function for remote_mourn. */
4186 remote_mourn_1 (target)
4187 struct target_ops *target;
4189 unpush_target (target);
4190 generic_mourn_inferior ();
4193 /* In the extended protocol we want to be able to do things like
4194 "run" and have them basically work as expected. So we need
4195 a special create_inferior function.
4197 FIXME: One day add support for changing the exec file
4198 we're debugging, arguments and an environment. */
4201 extended_remote_create_inferior (exec_file, args, env)
4206 /* Rip out the breakpoints; we'll reinsert them after restarting
4207 the remote server. */
4208 remove_breakpoints ();
4210 /* Now restart the remote server. */
4211 extended_remote_restart ();
4213 /* Now put the breakpoints back in. This way we're safe if the
4214 restart function works via a unix fork on the remote side. */
4215 insert_breakpoints ();
4217 /* Clean up from the last time we were running. */
4218 clear_proceed_status ();
4220 /* Let the remote process run. */
4221 proceed (-1, TARGET_SIGNAL_0, 0);
4224 /* Async version of extended_remote_create_inferior. */
4226 extended_remote_async_create_inferior (exec_file, args, env)
4231 /* Rip out the breakpoints; we'll reinsert them after restarting
4232 the remote server. */
4233 remove_breakpoints ();
4235 /* If running asynchronously, register the target file descriptor
4236 with the event loop. */
4237 if (event_loop_p && target_can_async_p ())
4238 target_async (inferior_event_handler, 0);
4240 /* Now restart the remote server. */
4241 extended_remote_restart ();
4243 /* Now put the breakpoints back in. This way we're safe if the
4244 restart function works via a unix fork on the remote side. */
4245 insert_breakpoints ();
4247 /* Clean up from the last time we were running. */
4248 clear_proceed_status ();
4250 /* Let the remote process run. */
4251 proceed (-1, TARGET_SIGNAL_0, 0);
4255 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
4256 than other targets; in those use REMOTE_BREAKPOINT instead of just
4257 BREAKPOINT. Also, bi-endian targets may define LITTLE_REMOTE_BREAKPOINT
4258 and BIG_REMOTE_BREAKPOINT. If none of these are defined, we just call
4259 the standard routines that are in mem-break.c. */
4261 /* FIXME, these ought to be done in a more dynamic fashion. For instance,
4262 the choice of breakpoint instruction affects target program design and
4263 vice versa, and by making it user-tweakable, the special code here
4264 goes away and we need fewer special GDB configurations. */
4266 #if defined (LITTLE_REMOTE_BREAKPOINT) && defined (BIG_REMOTE_BREAKPOINT) && !defined(REMOTE_BREAKPOINT)
4267 #define REMOTE_BREAKPOINT
4270 #ifdef REMOTE_BREAKPOINT
4272 /* If the target isn't bi-endian, just pretend it is. */
4273 #if !defined (LITTLE_REMOTE_BREAKPOINT) && !defined (BIG_REMOTE_BREAKPOINT)
4274 #define LITTLE_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4275 #define BIG_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4278 static unsigned char big_break_insn[] = BIG_REMOTE_BREAKPOINT;
4279 static unsigned char little_break_insn[] = LITTLE_REMOTE_BREAKPOINT;
4281 #endif /* REMOTE_BREAKPOINT */
4283 /* Insert a breakpoint on targets that don't have any better breakpoint
4284 support. We read the contents of the target location and stash it,
4285 then overwrite it with a breakpoint instruction. ADDR is the target
4286 location in the target machine. CONTENTS_CACHE is a pointer to
4287 memory allocated for saving the target contents. It is guaranteed
4288 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
4289 is accomplished via BREAKPOINT_MAX). */
4292 remote_insert_breakpoint (addr, contents_cache)
4294 char *contents_cache;
4296 #ifdef REMOTE_BREAKPOINT
4301 /* Try the "Z" packet if it is not already disabled.
4302 If it succeeds, then set the support to PACKET_ENABLE.
4303 If it fails, and the user has explicitly requested the Z support
4304 then report an error, otherwise, mark it disabled and go on. */
4306 if ((remote_protocol_Z.support == PACKET_ENABLE)
4307 || (remote_protocol_Z.support == PACKET_SUPPORT_UNKNOWN))
4309 char *buf = alloca (PBUFSIZ);
4312 addr = remote_address_masked (addr);
4316 p += hexnumstr (p, (ULONGEST) addr);
4317 BREAKPOINT_FROM_PC (&addr, &bp_size);
4318 sprintf (p, ",%d", bp_size);
4321 getpkt (buf, PBUFSIZ, 0);
4325 remote_protocol_Z.support = PACKET_ENABLE;
4326 return (buf[0] == 'E');
4329 /* The stub does not support the 'Z' request. If the user has
4330 explicitly requested the Z support, or if the stub previously
4331 said it supported the packet, this is an error,
4332 otherwise, mark it disabled. */
4334 else if (remote_protocol_Z.support == PACKET_ENABLE)
4336 error ("Protocol error: Z packet not recognized by stub");
4340 remote_protocol_Z.support = PACKET_DISABLE;
4344 #ifdef REMOTE_BREAKPOINT
4345 val = target_read_memory (addr, contents_cache, sizeof big_break_insn);
4349 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
4350 val = target_write_memory (addr, (char *) big_break_insn,
4351 sizeof big_break_insn);
4353 val = target_write_memory (addr, (char *) little_break_insn,
4354 sizeof little_break_insn);
4359 return memory_insert_breakpoint (addr, contents_cache);
4360 #endif /* REMOTE_BREAKPOINT */
4364 remote_remove_breakpoint (addr, contents_cache)
4366 char *contents_cache;
4370 if ((remote_protocol_Z.support == PACKET_ENABLE)
4371 || (remote_protocol_Z.support == PACKET_SUPPORT_UNKNOWN))
4373 char *buf = alloca (PBUFSIZ);
4380 addr = remote_address_masked (addr);
4381 p += hexnumstr (p, (ULONGEST) addr);
4382 BREAKPOINT_FROM_PC (&addr, &bp_size);
4383 sprintf (p, ",%d", bp_size);
4386 getpkt (buf, PBUFSIZ, 0);
4388 return (buf[0] == 'E');
4391 #ifdef REMOTE_BREAKPOINT
4392 return target_write_memory (addr, contents_cache, sizeof big_break_insn);
4394 return memory_remove_breakpoint (addr, contents_cache);
4395 #endif /* REMOTE_BREAKPOINT */
4398 #ifdef TARGET_HAS_HARDWARE_WATCHPOINTS
4400 remote_insert_watchpoint (addr, len, type)
4405 char *buf = alloca (PBUFSIZ);
4408 if (remote_protocol_Z.support == PACKET_DISABLE)
4409 error ("Can't set hardware watchpoints without the 'Z' packet\n");
4411 sprintf (buf, "Z%x,", type + 2 );
4412 p = strchr (buf, '\0');
4413 addr = remote_address_masked (addr);
4414 p += hexnumstr (p, (ULONGEST) addr);
4415 sprintf (p, ",%x", len);
4418 getpkt (buf, PBUFSIZ, 0);
4420 if (buf[0] == '\0' || buf [0] == 'E')
4427 remote_remove_watchpoint (addr, len, type)
4432 char *buf = alloca (PBUFSIZ);
4435 sprintf (buf, "z%x,", type + 2 );
4436 p = strchr (buf, '\0');
4437 addr = remote_address_masked (addr);
4438 p += hexnumstr (p, (ULONGEST) addr);
4439 sprintf (p, ",%x", len);
4441 getpkt (buf, PBUFSIZ, 0);
4443 if (buf[0] == '\0' || buf [0] == 'E')
4450 remote_insert_hw_breakpoint (addr, len)
4454 char *buf = alloca (PBUFSIZ);
4457 if (remote_protocol_Z.support == PACKET_DISABLE)
4458 error ("Can't set hardware breakpoints without the 'Z' packet\n");
4464 addr = remote_address_masked (addr);
4465 p += hexnumstr (p, (ULONGEST) addr);
4469 getpkt (buf, PBUFSIZ, 0);
4471 if (buf[0] == '\0' || buf [0] == 'E')
4478 remote_remove_hw_breakpoint (addr, len)
4482 char *buf = alloca (PBUFSIZ);
4489 addr = remote_address_masked (addr);
4490 p += hexnumstr (p, (ULONGEST) addr);
4494 getpkt (buf, PBUFSIZ, 0);
4496 if (buf[0] == '\0' || buf [0] == 'E')
4503 /* Some targets are only capable of doing downloads, and afterwards
4504 they switch to the remote serial protocol. This function provides
4505 a clean way to get from the download target to the remote target.
4506 It's basically just a wrapper so that we don't have to expose any
4507 of the internal workings of remote.c.
4509 Prior to calling this routine, you should shutdown the current
4510 target code, else you will get the "A program is being debugged
4511 already..." message. Usually a call to pop_target() suffices. */
4514 push_remote_target (name, from_tty)
4518 printf_filtered ("Switching to remote protocol\n");
4519 remote_open (name, from_tty);
4522 /* Other targets want to use the entire remote serial module but with
4523 certain remote_ops overridden. */
4526 open_remote_target (name, from_tty, target, extended_p)
4529 struct target_ops *target;
4532 printf_filtered ("Selecting the %sremote protocol\n",
4533 (extended_p ? "extended-" : ""));
4534 remote_open_1 (name, from_tty, target, extended_p);
4537 /* Table used by the crc32 function to calcuate the checksum. */
4539 static unsigned long crc32_table[256] =
4542 static unsigned long
4543 crc32 (buf, len, crc)
4548 if (!crc32_table[1])
4550 /* Initialize the CRC table and the decoding table. */
4554 for (i = 0; i < 256; i++)
4556 for (c = i << 24, j = 8; j > 0; --j)
4557 c = c & 0x80000000 ? (c << 1) ^ 0x04c11db7 : (c << 1);
4564 crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ *buf) & 255];
4570 /* compare-sections command
4572 With no arguments, compares each loadable section in the exec bfd
4573 with the same memory range on the target, and reports mismatches.
4574 Useful for verifying the image on the target against the exec file.
4575 Depends on the target understanding the new "qCRC:" request. */
4577 /* FIXME: cagney/1999-10-26: This command should be broken down into a
4578 target method (target verify memory) and generic version of the
4579 actual command. This will allow other high-level code (especially
4580 generic_load()) to make use of this target functionality. */
4583 compare_sections_command (args, from_tty)
4588 unsigned long host_crc, target_crc;
4589 extern bfd *exec_bfd;
4590 struct cleanup *old_chain;
4594 char *buf = alloca (PBUFSIZ);
4601 error ("command cannot be used without an exec file");
4602 if (!current_target.to_shortname ||
4603 strcmp (current_target.to_shortname, "remote") != 0)
4604 error ("command can only be used with remote target");
4606 for (s = exec_bfd->sections; s; s = s->next)
4608 if (!(s->flags & SEC_LOAD))
4609 continue; /* skip non-loadable section */
4611 size = bfd_get_section_size_before_reloc (s);
4613 continue; /* skip zero-length section */
4615 sectname = (char *) bfd_get_section_name (exec_bfd, s);
4616 if (args && strcmp (args, sectname) != 0)
4617 continue; /* not the section selected by user */
4619 matched = 1; /* do this section */
4621 /* FIXME: assumes lma can fit into long */
4622 sprintf (buf, "qCRC:%lx,%lx", (long) lma, (long) size);
4625 /* be clever; compute the host_crc before waiting for target reply */
4626 sectdata = xmalloc (size);
4627 old_chain = make_cleanup (free, sectdata);
4628 bfd_get_section_contents (exec_bfd, s, sectdata, 0, size);
4629 host_crc = crc32 ((unsigned char *) sectdata, size, 0xffffffff);
4631 getpkt (buf, PBUFSIZ, 0);
4633 error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
4634 sectname, lma, lma + size);
4636 error ("remote target does not support this operation");
4638 for (target_crc = 0, tmp = &buf[1]; *tmp; tmp++)
4639 target_crc = target_crc * 16 + fromhex (*tmp);
4641 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
4642 sectname, paddr (lma), paddr (lma + size));
4643 if (host_crc == target_crc)
4644 printf_filtered ("matched.\n");
4647 printf_filtered ("MIS-MATCHED!\n");
4651 do_cleanups (old_chain);
4654 warning ("One or more sections of the remote executable does not match\n\
4655 the loaded file\n");
4656 if (args && !matched)
4657 printf_filtered ("No loaded section named '%s'.\n", args);
4661 remote_query (query_type, buf, outbuf, bufsiz)
4668 char *buf2 = alloca (PBUFSIZ);
4669 char *p2 = &buf2[0];
4672 error ("null pointer to remote bufer size specified");
4674 /* minimum outbuf size is PBUFSIZ - if bufsiz is not large enough let
4675 the caller know and return what the minimum size is */
4676 /* Note: a zero bufsiz can be used to query the minimum buffer size */
4677 if (*bufsiz < PBUFSIZ)
4683 /* except for querying the minimum buffer size, target must be open */
4685 error ("remote query is only available after target open");
4687 /* we only take uppercase letters as query types, at least for now */
4688 if ((query_type < 'A') || (query_type > 'Z'))
4689 error ("invalid remote query type");
4692 error ("null remote query specified");
4695 error ("remote query requires a buffer to receive data");
4702 /* we used one buffer char for the remote protocol q command and another
4703 for the query type. As the remote protocol encapsulation uses 4 chars
4704 plus one extra in case we are debugging (remote_debug),
4705 we have PBUFZIZ - 7 left to pack the query string */
4707 while (buf[i] && (i < (PBUFSIZ - 8)))
4709 /* bad caller may have sent forbidden characters */
4710 if ((!isprint (buf[i])) || (buf[i] == '$') || (buf[i] == '#'))
4711 error ("illegal characters in query string");
4719 error ("query larger than available buffer");
4725 getpkt (outbuf, *bufsiz, 0);
4731 remote_rcmd (char *command,
4732 struct ui_file *outbuf)
4735 char *buf = alloca (PBUFSIZ);
4739 error ("remote rcmd is only available after target open");
4741 /* Send a NULL command across as an empty command */
4742 if (command == NULL)
4745 /* The query prefix */
4746 strcpy (buf, "qRcmd,");
4747 p = strchr (buf, '\0');
4749 if ((strlen (buf) + strlen (command) * 2 + 8/*misc*/) > PBUFSIZ)
4750 error ("\"monitor\" command ``%s'' is too long\n", command);
4752 /* Encode the actual command */
4753 for (i = 0; command[i]; i++)
4755 *p++ = tohex ((command[i] >> 4) & 0xf);
4756 *p++ = tohex (command[i] & 0xf);
4760 if (putpkt (buf) < 0)
4761 error ("Communication problem with target\n");
4763 /* get/display the response */
4766 /* XXX - see also tracepoint.c:remote_get_noisy_reply() */
4768 getpkt (buf, PBUFSIZ, 0);
4770 error ("Target does not support this command\n");
4771 if (buf[0] == 'O' && buf[1] != 'K')
4773 remote_console_output (buf + 1); /* 'O' message from stub */
4776 if (strcmp (buf, "OK") == 0)
4778 if (strlen (buf) == 3 && buf[0] == 'E'
4779 && isdigit (buf[1]) && isdigit (buf[2]))
4781 error ("Protocol error with Rcmd");
4783 for (p = buf; p[0] != '\0' && p[1] != '\0'; p += 2)
4785 char c = (fromhex (p[0]) << 4) + fromhex (p[1]);
4786 fputc_unfiltered (c, outbuf);
4793 packet_command (args, from_tty)
4797 char *buf = alloca (PBUFSIZ);
4800 error ("command can only be used with remote target");
4803 error ("remote-packet command requires packet text as argument");
4805 puts_filtered ("sending: ");
4806 print_packet (args);
4807 puts_filtered ("\n");
4810 getpkt (buf, PBUFSIZ, 0);
4811 puts_filtered ("received: ");
4813 puts_filtered ("\n");
4817 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
4819 static void display_thread_info PARAMS ((struct gdb_ext_thread_info * info));
4821 static void threadset_test_cmd PARAMS ((char *cmd, int tty));
4823 static void threadalive_test PARAMS ((char *cmd, int tty));
4825 static void threadlist_test_cmd PARAMS ((char *cmd, int tty));
4827 int get_and_display_threadinfo PARAMS ((threadref * ref));
4829 static void threadinfo_test_cmd PARAMS ((char *cmd, int tty));
4831 static int thread_display_step PARAMS ((threadref * ref, void *context));
4833 static void threadlist_update_test_cmd PARAMS ((char *cmd, int tty));
4835 static void init_remote_threadtests PARAMS ((void));
4837 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
4840 threadset_test_cmd (cmd, tty)
4844 int sample_thread = SAMPLE_THREAD;
4846 printf_filtered ("Remote threadset test\n");
4847 set_thread (sample_thread, 1);
4852 threadalive_test (cmd, tty)
4856 int sample_thread = SAMPLE_THREAD;
4858 if (remote_thread_alive (sample_thread))
4859 printf_filtered ("PASS: Thread alive test\n");
4861 printf_filtered ("FAIL: Thread alive test\n");
4864 void output_threadid PARAMS ((char *title, threadref * ref));
4867 output_threadid (title, ref)
4873 pack_threadid (&hexid[0], ref); /* Convert threead id into hex */
4875 printf_filtered ("%s %s\n", title, (&hexid[0]));
4879 threadlist_test_cmd (cmd, tty)
4884 threadref nextthread;
4885 int done, result_count;
4886 threadref threadlist[3];
4888 printf_filtered ("Remote Threadlist test\n");
4889 if (!remote_get_threadlist (startflag, &nextthread, 3, &done,
4890 &result_count, &threadlist[0]))
4891 printf_filtered ("FAIL: threadlist test\n");
4894 threadref *scan = threadlist;
4895 threadref *limit = scan + result_count;
4897 while (scan < limit)
4898 output_threadid (" thread ", scan++);
4903 display_thread_info (info)
4904 struct gdb_ext_thread_info *info;
4906 output_threadid ("Threadid: ", &info->threadid);
4907 printf_filtered ("Name: %s\n ", info->shortname);
4908 printf_filtered ("State: %s\n", info->display);
4909 printf_filtered ("other: %s\n\n", info->more_display);
4913 get_and_display_threadinfo (ref)
4918 struct gdb_ext_thread_info threadinfo;
4920 set = TAG_THREADID | TAG_EXISTS | TAG_THREADNAME
4921 | TAG_MOREDISPLAY | TAG_DISPLAY;
4922 if (0 != (result = remote_get_threadinfo (ref, set, &threadinfo)))
4923 display_thread_info (&threadinfo);
4928 threadinfo_test_cmd (cmd, tty)
4932 int athread = SAMPLE_THREAD;
4936 int_to_threadref (&thread, athread);
4937 printf_filtered ("Remote Threadinfo test\n");
4938 if (!get_and_display_threadinfo (&thread))
4939 printf_filtered ("FAIL cannot get thread info\n");
4943 thread_display_step (ref, context)
4947 /* output_threadid(" threadstep ",ref); *//* simple test */
4948 return get_and_display_threadinfo (ref);
4952 threadlist_update_test_cmd (cmd, tty)
4956 printf_filtered ("Remote Threadlist update test\n");
4957 remote_threadlist_iterator (thread_display_step, 0, CRAZY_MAX_THREADS);
4961 init_remote_threadtests (void)
4963 add_com ("tlist", class_obscure, threadlist_test_cmd,
4964 "Fetch and print the remote list of thread identifiers, one pkt only");
4965 add_com ("tinfo", class_obscure, threadinfo_test_cmd,
4966 "Fetch and display info about one thread");
4967 add_com ("tset", class_obscure, threadset_test_cmd,
4968 "Test setting to a different thread");
4969 add_com ("tupd", class_obscure, threadlist_update_test_cmd,
4970 "Iterate through updating all remote thread info");
4971 add_com ("talive", class_obscure, threadalive_test,
4972 " Remote thread alive test ");
4980 remote_ops.to_shortname = "remote";
4981 remote_ops.to_longname = "Remote serial target in gdb-specific protocol";
4983 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
4984 Specify the serial device it is connected to\n\
4985 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
4986 remote_ops.to_open = remote_open;
4987 remote_ops.to_close = remote_close;
4988 remote_ops.to_detach = remote_detach;
4989 remote_ops.to_resume = remote_resume;
4990 remote_ops.to_wait = remote_wait;
4991 remote_ops.to_fetch_registers = remote_fetch_registers;
4992 remote_ops.to_store_registers = remote_store_registers;
4993 remote_ops.to_prepare_to_store = remote_prepare_to_store;
4994 remote_ops.to_xfer_memory = remote_xfer_memory;
4995 remote_ops.to_files_info = remote_files_info;
4996 remote_ops.to_insert_breakpoint = remote_insert_breakpoint;
4997 remote_ops.to_remove_breakpoint = remote_remove_breakpoint;
4998 remote_ops.to_kill = remote_kill;
4999 remote_ops.to_load = generic_load;
5000 remote_ops.to_mourn_inferior = remote_mourn;
5001 remote_ops.to_thread_alive = remote_thread_alive;
5002 remote_ops.to_find_new_threads = remote_threads_info;
5003 remote_ops.to_extra_thread_info = remote_threads_extra_info;
5004 remote_ops.to_stop = remote_stop;
5005 remote_ops.to_query = remote_query;
5006 remote_ops.to_rcmd = remote_rcmd;
5007 remote_ops.to_stratum = process_stratum;
5008 remote_ops.to_has_all_memory = 1;
5009 remote_ops.to_has_memory = 1;
5010 remote_ops.to_has_stack = 1;
5011 remote_ops.to_has_registers = 1;
5012 remote_ops.to_has_execution = 1;
5013 remote_ops.to_has_thread_control = tc_schedlock; /* can lock scheduler */
5014 remote_ops.to_magic = OPS_MAGIC;
5017 /* Set up the extended remote vector by making a copy of the standard
5018 remote vector and adding to it. */
5021 init_extended_remote_ops ()
5023 extended_remote_ops = remote_ops;
5025 extended_remote_ops.to_shortname = "extended-remote";
5026 extended_remote_ops.to_longname =
5027 "Extended remote serial target in gdb-specific protocol";
5028 extended_remote_ops.to_doc =
5029 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5030 Specify the serial device it is connected to (e.g. /dev/ttya).",
5031 extended_remote_ops.to_open = extended_remote_open;
5032 extended_remote_ops.to_create_inferior = extended_remote_create_inferior;
5033 extended_remote_ops.to_mourn_inferior = extended_remote_mourn;
5037 * Command: info remote-process
5039 * This implements Cisco's version of the "info proc" command.
5041 * This query allows the target stub to return an arbitrary string
5042 * (or strings) giving arbitrary information about the target process.
5043 * This is optional; the target stub isn't required to implement it.
5045 * Syntax: qfProcessInfo request first string
5046 * qsProcessInfo request subsequent string
5047 * reply: 'O'<hex-encoded-string>
5048 * 'l' last reply (empty)
5052 remote_info_process (char *args, int from_tty)
5054 char *buf = alloca (PBUFSIZ);
5056 if (remote_desc == 0)
5057 error ("Command can only be used when connected to the remote target.");
5059 putpkt ("qfProcessInfo");
5060 getpkt (buf, PBUFSIZ, 0);
5062 return; /* Silently: target does not support this feature. */
5065 error ("info proc: target error.");
5067 while (buf[0] == 'O') /* Capitol-O packet */
5069 remote_console_output (&buf[1]);
5070 putpkt ("qsProcessInfo");
5071 getpkt (buf, PBUFSIZ, 0);
5080 remote_cisco_open (char *name, int from_tty)
5084 "To open a remote debug connection, you need to specify what \n\
5085 device is attached to the remote system (e.g. host:port).");
5087 /* See FIXME above */
5088 wait_forever_enabled_p = 1;
5090 target_preopen (from_tty);
5092 unpush_target (&remote_cisco_ops);
5094 remote_dcache = dcache_init (remote_read_bytes, remote_write_bytes);
5096 remote_desc = SERIAL_OPEN (name);
5098 perror_with_name (name);
5101 * If a baud rate was specified on the gdb command line it will
5102 * be greater than the initial value of -1. If it is, use it otherwise
5106 baud_rate = (baud_rate > 0) ? baud_rate : 9600;
5107 if (SERIAL_SETBAUDRATE (remote_desc, baud_rate))
5109 SERIAL_CLOSE (remote_desc);
5110 perror_with_name (name);
5113 SERIAL_RAW (remote_desc);
5115 /* If there is something sitting in the buffer we might take it as a
5116 response to a command, which would be bad. */
5117 SERIAL_FLUSH_INPUT (remote_desc);
5121 puts_filtered ("Remote debugging using ");
5122 puts_filtered (name);
5123 puts_filtered ("\n");
5126 remote_cisco_mode = 1;
5128 push_target (&remote_cisco_ops); /* Switch to using cisco target now */
5130 init_packet_config (&remote_protocol_P);
5131 init_packet_config (&remote_protocol_Z);
5133 general_thread = -2;
5134 continue_thread = -2;
5136 /* Force remote_write_bytes to check whether target supports
5137 binary downloading. */
5138 init_packet_config (&remote_protocol_binary_download);
5140 /* Probe for ability to use "ThreadInfo" query, as required. */
5141 use_threadinfo_query = 1;
5142 use_threadextra_query = 1;
5144 /* Without this, some commands which require an active target (such
5145 as kill) won't work. This variable serves (at least) double duty
5146 as both the pid of the target process (if it has such), and as a
5147 flag indicating that a target is active. These functions should
5148 be split out into seperate variables, especially since GDB will
5149 someday have a notion of debugging several processes. */
5150 inferior_pid = MAGIC_NULL_PID;
5152 /* Start the remote connection; if error (0), discard this target. */
5154 if (!catch_errors (remote_start_remote_dummy, (char *) 0,
5155 "Couldn't establish connection to remote target\n",
5164 remote_cisco_close (int quitting)
5166 remote_cisco_mode = 0;
5167 remote_close (quitting);
5174 remote_mourn_1 (&remote_cisco_ops);
5186 /* shared between readsocket() and readtty() */
5187 static char *tty_input;
5189 static int escape_count;
5190 static int echo_check;
5191 extern int quit_flag;
5198 /* Loop until the socket doesn't have any more data */
5200 while ((data = readchar (0)) >= 0)
5202 /* Check for the escape sequence */
5205 /* If this is the fourth escape, get out */
5206 if (++escape_count == 4)
5211 { /* This is a '|', but not the fourth in a row.
5212 Continue without echoing it. If it isn't actually
5213 one of four in a row, it'll be echoed later. */
5220 /* Ensure any pending '|'s are flushed. */
5222 for (; escape_count > 0; escape_count--)
5226 if (data == '\r') /* If this is a return character, */
5227 continue; /* - just supress it. */
5229 if (echo_check != -1) /* Check for echo of user input. */
5231 if (tty_input[echo_check] == data)
5233 echo_check++; /* Character matched user input: */
5234 continue; /* Continue without echoing it. */
5236 else if ((data == '\n') && (tty_input[echo_check] == '\r'))
5237 { /* End of the line (and of echo checking). */
5238 echo_check = -1; /* No more echo supression */
5239 continue; /* Continue without echoing. */
5242 { /* Failed check for echo of user input.
5243 We now have some suppressed output to flush! */
5246 for (j = 0; j < echo_check; j++)
5247 putchar (tty_input[j]);
5251 putchar (data); /* Default case: output the char. */
5254 if (data == SERIAL_TIMEOUT) /* Timeout returned from readchar. */
5255 return READ_MORE; /* Try to read some more */
5257 return FATAL_ERROR; /* Trouble, bail out */
5265 /* First, read a buffer full from the terminal */
5266 tty_bytecount = read (fileno (stdin), tty_input, sizeof (tty_input) - 1);
5267 if (tty_bytecount == -1)
5269 perror ("readtty: read failed");
5273 /* Remove a quoted newline. */
5274 if (tty_input[tty_bytecount - 1] == '\n' &&
5275 tty_input[tty_bytecount - 2] == '\\') /* line ending in backslash */
5277 tty_input[--tty_bytecount] = 0; /* remove newline */
5278 tty_input[--tty_bytecount] = 0; /* remove backslash */
5281 /* Turn trailing newlines into returns */
5282 if (tty_input[tty_bytecount - 1] == '\n')
5283 tty_input[tty_bytecount - 1] = '\r';
5285 /* If the line consists of a ~, enter debugging mode. */
5286 if ((tty_input[0] == '~') && (tty_bytecount == 2))
5289 /* Make this a zero terminated string and write it out */
5290 tty_input[tty_bytecount] = 0;
5291 if (SERIAL_WRITE (remote_desc, tty_input, tty_bytecount))
5293 perror_with_name ("readtty: write failed");
5303 fd_set input; /* file descriptors for select */
5304 int tablesize; /* max number of FDs for select */
5308 extern int escape_count; /* global shared by readsocket */
5309 extern int echo_check; /* ditto */
5314 tablesize = 8 * sizeof (input);
5318 /* Check for anything from our socket - doesn't block. Note that
5319 this must be done *before* the select as there may be
5320 buffered I/O waiting to be processed. */
5322 if ((status = readsocket ()) == FATAL_ERROR)
5324 error ("Debugging terminated by communications error");
5326 else if (status != READ_MORE)
5331 fflush (stdout); /* Flush output before blocking */
5333 /* Now block on more socket input or TTY input */
5336 FD_SET (fileno (stdin), &input);
5337 FD_SET (DEPRECATED_SERIAL_FD (remote_desc), &input);
5339 status = select (tablesize, &input, 0, 0, 0);
5340 if ((status == -1) && (errno != EINTR))
5342 error ("Communications error on select %d", errno);
5345 /* Handle Control-C typed */
5349 if ((++quit_count) == 2)
5351 if (query ("Interrupt GDB? "))
5353 printf_filtered ("Interrupted by user.\n");
5354 return_to_top_level (RETURN_QUIT);
5361 SERIAL_SEND_BREAK (remote_desc);
5363 SERIAL_WRITE (remote_desc, "\003", 1);
5368 /* Handle console input */
5370 if (FD_ISSET (fileno (stdin), &input))
5374 status = readtty ();
5375 if (status == READ_MORE)
5378 return status; /* telnet session ended */
5384 remote_cisco_wait (int pid, struct target_waitstatus *status)
5386 if (minitelnet () != ENTER_DEBUG)
5388 error ("Debugging session terminated by protocol error");
5391 return remote_wait (pid, status);
5395 init_remote_cisco_ops ()
5397 remote_cisco_ops.to_shortname = "cisco";
5398 remote_cisco_ops.to_longname = "Remote serial target in cisco-specific protocol";
5399 remote_cisco_ops.to_doc =
5400 "Use a remote machine via TCP, using a cisco-specific protocol.\n\
5401 Specify the serial device it is connected to (e.g. host:2020).";
5402 remote_cisco_ops.to_open = remote_cisco_open;
5403 remote_cisco_ops.to_close = remote_cisco_close;
5404 remote_cisco_ops.to_detach = remote_detach;
5405 remote_cisco_ops.to_resume = remote_resume;
5406 remote_cisco_ops.to_wait = remote_cisco_wait;
5407 remote_cisco_ops.to_fetch_registers = remote_fetch_registers;
5408 remote_cisco_ops.to_store_registers = remote_store_registers;
5409 remote_cisco_ops.to_prepare_to_store = remote_prepare_to_store;
5410 remote_cisco_ops.to_xfer_memory = remote_xfer_memory;
5411 remote_cisco_ops.to_files_info = remote_files_info;
5412 remote_cisco_ops.to_insert_breakpoint = remote_insert_breakpoint;
5413 remote_cisco_ops.to_remove_breakpoint = remote_remove_breakpoint;
5414 remote_cisco_ops.to_kill = remote_kill;
5415 remote_cisco_ops.to_load = generic_load;
5416 remote_cisco_ops.to_mourn_inferior = remote_cisco_mourn;
5417 remote_cisco_ops.to_thread_alive = remote_thread_alive;
5418 remote_cisco_ops.to_find_new_threads = remote_threads_info;
5419 remote_ops.to_extra_thread_info = remote_threads_extra_info;
5420 remote_cisco_ops.to_stratum = process_stratum;
5421 remote_cisco_ops.to_has_all_memory = 1;
5422 remote_cisco_ops.to_has_memory = 1;
5423 remote_cisco_ops.to_has_stack = 1;
5424 remote_cisco_ops.to_has_registers = 1;
5425 remote_cisco_ops.to_has_execution = 1;
5426 remote_cisco_ops.to_magic = OPS_MAGIC;
5430 remote_can_async_p (void)
5432 /* We're async whenever the serial device is. */
5433 return (current_target.to_async_mask_value) && SERIAL_CAN_ASYNC_P (remote_desc);
5437 remote_is_async_p (void)
5439 /* We're async whenever the serial device is. */
5440 return (current_target.to_async_mask_value) && SERIAL_IS_ASYNC_P (remote_desc);
5443 /* Pass the SERIAL event on and up to the client. One day this code
5444 will be able to delay notifying the client of an event until the
5445 point where an entire packet has been received. */
5447 static void (*async_client_callback) (enum inferior_event_type event_type, void *context);
5448 static void *async_client_context;
5449 static serial_event_ftype remote_async_serial_handler;
5452 remote_async_serial_handler (serial_t scb, void *context)
5454 /* Don't propogate error information up to the client. Instead let
5455 the client find out about the error by querying the target. */
5456 async_client_callback (INF_REG_EVENT, async_client_context);
5460 remote_async (void (*callback) (enum inferior_event_type event_type, void *context), void *context)
5462 if (current_target.to_async_mask_value == 0)
5463 internal_error ("Calling remote_async when async is masked");
5465 if (callback != NULL)
5467 SERIAL_ASYNC (remote_desc, remote_async_serial_handler, NULL);
5468 async_client_callback = callback;
5469 async_client_context = context;
5472 SERIAL_ASYNC (remote_desc, NULL, NULL);
5475 /* Target async and target extended-async.
5477 This are temporary targets, until it is all tested. Eventually
5478 async support will be incorporated int the usual 'remote'
5482 init_remote_async_ops (void)
5484 remote_async_ops.to_shortname = "async";
5485 remote_async_ops.to_longname = "Remote serial target in async version of the gdb-specific protocol";
5486 remote_async_ops.to_doc =
5487 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5488 Specify the serial device it is connected to (e.g. /dev/ttya).";
5489 remote_async_ops.to_open = remote_async_open;
5490 remote_async_ops.to_close = remote_close;
5491 remote_async_ops.to_detach = remote_async_detach;
5492 remote_async_ops.to_resume = remote_async_resume;
5493 remote_async_ops.to_wait = remote_async_wait;
5494 remote_async_ops.to_fetch_registers = remote_fetch_registers;
5495 remote_async_ops.to_store_registers = remote_store_registers;
5496 remote_async_ops.to_prepare_to_store = remote_prepare_to_store;
5497 remote_async_ops.to_xfer_memory = remote_xfer_memory;
5498 remote_async_ops.to_files_info = remote_files_info;
5499 remote_async_ops.to_insert_breakpoint = remote_insert_breakpoint;
5500 remote_async_ops.to_remove_breakpoint = remote_remove_breakpoint;
5501 remote_async_ops.to_terminal_inferior = remote_async_terminal_inferior;
5502 remote_async_ops.to_terminal_ours = remote_async_terminal_ours;
5503 remote_async_ops.to_kill = remote_async_kill;
5504 remote_async_ops.to_load = generic_load;
5505 remote_async_ops.to_mourn_inferior = remote_async_mourn;
5506 remote_async_ops.to_thread_alive = remote_thread_alive;
5507 remote_async_ops.to_find_new_threads = remote_threads_info;
5508 remote_ops.to_extra_thread_info = remote_threads_extra_info;
5509 remote_async_ops.to_stop = remote_stop;
5510 remote_async_ops.to_query = remote_query;
5511 remote_async_ops.to_rcmd = remote_rcmd;
5512 remote_async_ops.to_stratum = process_stratum;
5513 remote_async_ops.to_has_all_memory = 1;
5514 remote_async_ops.to_has_memory = 1;
5515 remote_async_ops.to_has_stack = 1;
5516 remote_async_ops.to_has_registers = 1;
5517 remote_async_ops.to_has_execution = 1;
5518 remote_async_ops.to_has_thread_control = tc_schedlock; /* can lock scheduler */
5519 remote_async_ops.to_can_async_p = remote_can_async_p;
5520 remote_async_ops.to_is_async_p = remote_is_async_p;
5521 remote_async_ops.to_async = remote_async;
5522 remote_async_ops.to_async_mask_value = 1;
5523 remote_async_ops.to_magic = OPS_MAGIC;
5526 /* Set up the async extended remote vector by making a copy of the standard
5527 remote vector and adding to it. */
5530 init_extended_async_remote_ops (void)
5532 extended_async_remote_ops = remote_async_ops;
5534 extended_async_remote_ops.to_shortname = "extended-async";
5535 extended_async_remote_ops.to_longname =
5536 "Extended remote serial target in async gdb-specific protocol";
5537 extended_async_remote_ops.to_doc =
5538 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
5539 Specify the serial device it is connected to (e.g. /dev/ttya).",
5540 extended_async_remote_ops.to_open = extended_remote_async_open;
5541 extended_async_remote_ops.to_create_inferior = extended_remote_async_create_inferior;
5542 extended_async_remote_ops.to_mourn_inferior = extended_remote_mourn;
5546 set_remote_cmd (char *args, int from_tty)
5553 build_remote_gdbarch_data ()
5555 build_remote_packet_sizes ();
5558 tty_input = xmalloc (PBUFSIZ);
5559 remote_address_size = TARGET_PTR_BIT;
5563 _initialize_remote ()
5565 static struct cmd_list_element *remote_set_cmdlist;
5566 static struct cmd_list_element *remote_show_cmdlist;
5567 struct cmd_list_element *tmpcmd;
5569 /* architecture specific data */
5570 build_remote_gdbarch_data ();
5571 register_gdbarch_swap (&tty_input, sizeof (&tty_input), NULL);
5572 register_remote_packet_sizes ();
5573 register_gdbarch_swap (&remote_address_size,
5574 sizeof (&remote_address_size), NULL);
5575 register_gdbarch_swap (NULL, 0, build_remote_gdbarch_data);
5578 add_target (&remote_ops);
5580 init_extended_remote_ops ();
5581 add_target (&extended_remote_ops);
5583 init_remote_async_ops ();
5584 add_target (&remote_async_ops);
5586 init_extended_async_remote_ops ();
5587 add_target (&extended_async_remote_ops);
5589 init_remote_cisco_ops ();
5590 add_target (&remote_cisco_ops);
5593 init_remote_threadtests ();
5596 add_prefix_cmd ("remote", class_maintenance, set_remote_cmd, "\
5597 Remote protocol specific variables\n\
5598 Configure various remote-protocol specific variables such as\n\
5599 the packets being used",
5600 &remote_set_cmdlist, "set remote ",
5601 0/*allow-unknown*/, &setlist);
5602 add_prefix_cmd ("remote", class_maintenance, set_remote_cmd, "\
5603 Remote protocol specific variables\n\
5604 Configure various remote-protocol specific variables such as\n\
5605 the packets being used",
5606 &remote_show_cmdlist, "show remote ",
5607 0/*allow-unknown*/, &showlist);
5609 add_cmd ("compare-sections", class_obscure, compare_sections_command,
5610 "Compare section data on target to the exec file.\n\
5611 Argument is a single section name (default: all loaded sections).",
5614 add_cmd ("packet", class_maintenance, packet_command,
5615 "Send an arbitrary packet to a remote target.\n\
5616 maintenance packet TEXT\n\
5617 If GDB is talking to an inferior via the GDB serial protocol, then\n\
5618 this command sends the string TEXT to the inferior, and displays the\n\
5619 response packet. GDB supplies the initial `$' character, and the\n\
5620 terminating `#' character and checksum.",
5624 (add_set_cmd ("remotebreak", no_class,
5625 var_boolean, (char *) &remote_break,
5626 "Set whether to send break if interrupted.\n",
5630 /* Install commands for configuring memory read/write packets. */
5632 add_cmd ("remotewritesize", no_class, set_memory_write_packet_size,
5633 "Set the maximum number of bytes per memory write packet (deprecated).\n",
5635 add_cmd ("remotewritesize", no_class, set_memory_write_packet_size,
5636 "Show the maximum number of bytes per memory write packet (deprecated).\n",
5638 add_cmd ("memory-write-packet-size", no_class,
5639 set_memory_write_packet_size,
5640 "Set the maximum number of bytes per memory-write packet.\n"
5641 "Specify the number of bytes in a packet or 0 (zero) for the\n"
5642 "default packet size. The actual limit is further reduced\n"
5643 "dependent on the target. Specify ``fixed'' to disable the\n"
5644 "further restriction and ``limit'' to enable that restriction\n",
5645 &remote_set_cmdlist);
5646 add_cmd ("memory-read-packet-size", no_class,
5647 set_memory_read_packet_size,
5648 "Set the maximum number of bytes per memory-read packet.\n"
5649 "Specify the number of bytes in a packet or 0 (zero) for the\n"
5650 "default packet size. The actual limit is further reduced\n"
5651 "dependent on the target. Specify ``fixed'' to disable the\n"
5652 "further restriction and ``limit'' to enable that restriction\n",
5653 &remote_set_cmdlist);
5654 add_cmd ("memory-write-packet-size", no_class,
5655 show_memory_write_packet_size,
5656 "Show the maximum number of bytes per memory-write packet.\n",
5657 &remote_show_cmdlist);
5658 add_cmd ("memory-read-packet-size", no_class,
5659 show_memory_read_packet_size,
5660 "Show the maximum number of bytes per memory-read packet.\n",
5661 &remote_show_cmdlist);
5664 (add_set_cmd ("remoteaddresssize", class_obscure,
5665 var_integer, (char *) &remote_address_size,
5666 "Set the maximum size of the address (in bits) \
5667 in a memory packet.\n",
5671 add_packet_config_cmd (&remote_protocol_binary_download,
5672 "X", "binary-download",
5673 set_remote_protocol_binary_download_cmd,
5674 show_remote_protocol_binary_download_cmd,
5675 &remote_set_cmdlist, &remote_show_cmdlist);
5677 /* XXXX - should ``set remotebinarydownload'' be retained for
5680 (add_set_cmd ("remotebinarydownload", no_class,
5681 var_boolean, (char *) &remote_binary_download,
5682 "Set binary downloads.\n", &setlist),
5686 add_info ("remote-process", remote_info_process,
5687 "Query the remote system for process info.");
5689 add_packet_config_cmd (&remote_protocol_P, "P", "set-register",
5690 set_remote_protocol_P_packet_cmd,
5691 show_remote_protocol_P_packet_cmd,
5692 &remote_set_cmdlist, &remote_show_cmdlist);
5694 add_packet_config_cmd (&remote_protocol_Z, "Z", "breakpoint",
5695 set_remote_protocol_Z_packet_cmd,
5696 show_remote_protocol_Z_packet_cmd,
5697 &remote_set_cmdlist, &remote_show_cmdlist);