1 /* Remote target communications for serial-line targets in custom GDB protocol
2 Copyright 1988, 1991-2000, 2001 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"
32 /*#include "terminal.h" */
35 #include "gdb-stabs.h"
36 #include "gdbthread.h"
42 #include <sys/types.h>
45 #include "event-loop.h"
46 #include "event-top.h"
52 /* Prototypes for local functions */
53 static void cleanup_sigint_signal_handler (void *dummy);
54 static void initialize_sigint_signal_handler (void);
55 static int getpkt_sane (char *buf, long sizeof_buf, int forever);
57 static void handle_remote_sigint (int);
58 static void handle_remote_sigint_twice (int);
59 static void async_remote_interrupt (gdb_client_data);
60 void async_remote_interrupt_twice (gdb_client_data);
62 static void build_remote_gdbarch_data (void);
64 static int remote_write_bytes (CORE_ADDR memaddr, char *myaddr, int len);
66 static int remote_read_bytes (CORE_ADDR memaddr, char *myaddr, int len);
68 static void remote_files_info (struct target_ops *ignore);
70 static int remote_xfer_memory (CORE_ADDR memaddr, char *myaddr,
71 int len, int should_write,
72 struct mem_attrib *attrib,
73 struct target_ops *target);
75 static void remote_prepare_to_store (void);
77 static void remote_fetch_registers (int regno);
79 static void remote_resume (int pid, int step, enum target_signal siggnal);
80 static void remote_async_resume (int pid, int step,
81 enum target_signal siggnal);
82 static int remote_start_remote (PTR);
84 static void remote_open (char *name, int from_tty);
85 static void remote_async_open (char *name, int from_tty);
87 static void extended_remote_open (char *name, int from_tty);
88 static void extended_remote_async_open (char *name, int from_tty);
90 static void remote_open_1 (char *, int, struct target_ops *, int extended_p);
91 static void remote_async_open_1 (char *, int, struct target_ops *,
94 static void remote_close (int quitting);
96 static void remote_store_registers (int regno);
98 static void remote_mourn (void);
99 static void remote_async_mourn (void);
101 static void extended_remote_restart (void);
103 static void extended_remote_mourn (void);
105 static void extended_remote_create_inferior (char *, char *, char **);
106 static void extended_remote_async_create_inferior (char *, char *, char **);
108 static void remote_mourn_1 (struct target_ops *);
110 static void remote_send (char *buf, long sizeof_buf);
112 static int readchar (int timeout);
114 static int remote_wait (int pid, struct target_waitstatus *status);
115 static int remote_async_wait (int pid, struct target_waitstatus *status);
117 static void remote_kill (void);
118 static void remote_async_kill (void);
120 static int tohex (int nib);
122 static void remote_detach (char *args, int from_tty);
123 static void remote_async_detach (char *args, int from_tty);
125 static void remote_interrupt (int signo);
127 static void remote_interrupt_twice (int signo);
129 static void interrupt_query (void);
131 static void set_thread (int, int);
133 static int remote_thread_alive (int);
135 static void get_offsets (void);
137 static long read_frame (char *buf, long sizeof_buf);
139 static int remote_insert_breakpoint (CORE_ADDR, char *);
141 static int remote_remove_breakpoint (CORE_ADDR, char *);
143 static int hexnumlen (ULONGEST num);
145 static void init_remote_ops (void);
147 static void init_extended_remote_ops (void);
149 static void init_remote_cisco_ops (void);
151 static struct target_ops remote_cisco_ops;
153 static void remote_stop (void);
155 static int ishex (int ch, int *val);
157 static int stubhex (int ch);
159 static int remote_query (int /*char */ , char *, char *, int *);
161 static int hexnumstr (char *, ULONGEST);
163 static int hexnumnstr (char *, ULONGEST, int);
165 static CORE_ADDR remote_address_masked (CORE_ADDR);
167 static void print_packet (char *);
169 static unsigned long crc32 (unsigned char *, int, unsigned int);
171 static void compare_sections_command (char *, int);
173 static void packet_command (char *, int);
175 static int stub_unpack_int (char *buff, int fieldlength);
177 static int remote_current_thread (int oldpid);
179 static void remote_find_new_threads (void);
181 static void record_currthread (int currthread);
183 /* exported functions */
185 extern int fromhex (int a);
187 static int putpkt_binary (char *buf, int cnt);
189 static void check_binary_download (CORE_ADDR addr);
191 struct packet_config;
193 static void show_packet_config_cmd (struct packet_config *config);
195 static void update_packet_config (struct packet_config *config);
197 /* Define the target subroutine names */
199 void open_remote_target (char *, int, struct target_ops *, int);
201 void _initialize_remote (void);
205 static struct target_ops remote_ops;
207 static struct target_ops extended_remote_ops;
209 /* Temporary target ops. Just like the remote_ops and
210 extended_remote_ops, but with asynchronous support. */
211 static struct target_ops remote_async_ops;
213 static struct target_ops extended_async_remote_ops;
215 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
216 ``forever'' still use the normal timeout mechanism. This is
217 currently used by the ASYNC code to guarentee that target reads
218 during the initial connect always time-out. Once getpkt has been
219 modified to return a timeout indication and, in turn
220 remote_wait()/wait_for_inferior() have gained a timeout parameter
222 static int wait_forever_enabled_p = 1;
225 /* This variable chooses whether to send a ^C or a break when the user
226 requests program interruption. Although ^C is usually what remote
227 systems expect, and that is the default here, sometimes a break is
228 preferable instead. */
230 static int remote_break;
232 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
233 remote_open knows that we don't have a file open when the program
235 static serial_t remote_desc = NULL;
237 /* This is set by the target (thru the 'S' message)
238 to denote that the target is in kernel mode. */
239 static int cisco_kernel_mode = 0;
241 /* This variable sets the number of bits in an address that are to be
242 sent in a memory ("M" or "m") packet. Normally, after stripping
243 leading zeros, the entire address would be sent. This variable
244 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
245 initial implementation of remote.c restricted the address sent in
246 memory packets to ``host::sizeof long'' bytes - (typically 32
247 bits). Consequently, for 64 bit targets, the upper 32 bits of an
248 address was never sent. Since fixing this bug may cause a break in
249 some remote targets this variable is principly provided to
250 facilitate backward compatibility. */
252 static int remote_address_size;
254 /* Tempoary to track who currently owns the terminal. See
255 target_async_terminal_* for more details. */
257 static int remote_async_terminal_ours_p;
260 /* This is the size (in chars) of the first response to the ``g''
261 packet. It is used as a heuristic when determining the maximum
262 size of memory-read and memory-write packets. A target will
263 typically only reserve a buffer large enough to hold the ``g''
264 packet. The size does not include packet overhead (headers and
267 static long actual_register_packet_size;
269 /* This is the maximum size (in chars) of a non read/write packet. It
270 is also used as a cap on the size of read/write packets. */
272 static long remote_packet_size;
274 #define PBUFSIZ (remote_packet_size)
276 /* User configurable variables for the number of characters in a
277 memory read/write packet. MIN (PBUFSIZ, g-packet-size) is the
278 default. Some targets need smaller values (fifo overruns, et.al.)
279 and some users need larger values (speed up transfers). The
280 variables ``preferred_*'' (the user request), ``current_*'' (what
281 was actually set) and ``forced_*'' (Positive - a soft limit,
282 negative - a hard limit). */
284 struct memory_packet_config
291 /* Compute the current size of a read/write packet. Since this makes
292 use of ``actual_register_packet_size'' the computation is dynamic. */
295 get_memory_packet_size (struct memory_packet_config *config)
297 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
298 law?) that some hosts don't cope very well with large alloca()
299 calls. Eventually the alloca() code will be replaced by calls to
300 xmalloc() and make_cleanups() allowing this restriction to either
301 be lifted or removed. */
302 #ifndef MAX_REMOTE_PACKET_SIZE
303 #define MAX_REMOTE_PACKET_SIZE 16384
305 /* NOTE: 16 is just chosen at random. */
306 #ifndef MIN_REMOTE_PACKET_SIZE
307 #define MIN_REMOTE_PACKET_SIZE 16
312 if (config->size <= 0)
313 what_they_get = MAX_REMOTE_PACKET_SIZE;
315 what_they_get = config->size;
319 what_they_get = remote_packet_size;
320 /* Limit the packet to the size specified by the user. */
322 && what_they_get > config->size)
323 what_they_get = config->size;
324 /* Limit it to the size of the targets ``g'' response. */
325 if (actual_register_packet_size > 0
326 && what_they_get > actual_register_packet_size)
327 what_they_get = actual_register_packet_size;
329 if (what_they_get > MAX_REMOTE_PACKET_SIZE)
330 what_they_get = MAX_REMOTE_PACKET_SIZE;
331 if (what_they_get < MIN_REMOTE_PACKET_SIZE)
332 what_they_get = MIN_REMOTE_PACKET_SIZE;
333 return what_they_get;
336 /* Update the size of a read/write packet. If they user wants
337 something really big then do a sanity check. */
340 set_memory_packet_size (char *args, struct memory_packet_config *config)
342 int fixed_p = config->fixed_p;
343 long size = config->size;
345 error ("Argument required (integer, `fixed' or `limited').");
346 else if (strcmp (args, "hard") == 0
347 || strcmp (args, "fixed") == 0)
349 else if (strcmp (args, "soft") == 0
350 || strcmp (args, "limit") == 0)
355 size = strtoul (args, &end, 0);
357 error ("Invalid %s (bad syntax).", config->name);
359 /* Instead of explicitly capping the size of a packet to
360 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
361 instead allowed to set the size to something arbitrarily
363 if (size > MAX_REMOTE_PACKET_SIZE)
364 error ("Invalid %s (too large).", config->name);
368 if (fixed_p && !config->fixed_p)
370 if (! query ("The target may not be able to correctly handle a %s\n"
371 "of %ld bytes. Change the packet size? ",
373 error ("Packet size not changed.");
375 /* Update the config. */
376 config->fixed_p = fixed_p;
381 show_memory_packet_size (struct memory_packet_config *config)
383 printf_filtered ("The %s is %ld. ", config->name, config->size);
385 printf_filtered ("Packets are fixed at %ld bytes.\n",
386 get_memory_packet_size (config));
388 printf_filtered ("Packets are limited to %ld bytes.\n",
389 get_memory_packet_size (config));
392 static struct memory_packet_config memory_write_packet_config =
394 "memory-write-packet-size",
398 set_memory_write_packet_size (char *args, int from_tty)
400 set_memory_packet_size (args, &memory_write_packet_config);
404 show_memory_write_packet_size (char *args, int from_tty)
406 show_memory_packet_size (&memory_write_packet_config);
410 get_memory_write_packet_size (void)
412 return get_memory_packet_size (&memory_write_packet_config);
415 static struct memory_packet_config memory_read_packet_config =
417 "memory-read-packet-size",
421 set_memory_read_packet_size (char *args, int from_tty)
423 set_memory_packet_size (args, &memory_read_packet_config);
427 show_memory_read_packet_size (char *args, int from_tty)
429 show_memory_packet_size (&memory_read_packet_config);
433 get_memory_read_packet_size (void)
435 long size = get_memory_packet_size (&memory_read_packet_config);
436 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
437 extra buffer size argument before the memory read size can be
438 increased beyond PBUFSIZ. */
444 /* Register packet size initialization. Since the bounds change when
445 the architecture changes (namely REGISTER_BYTES) this all needs to
449 register_remote_packet_sizes (void)
451 REGISTER_GDBARCH_SWAP (remote_packet_size);
452 REGISTER_GDBARCH_SWAP (actual_register_packet_size);
456 build_remote_packet_sizes (void)
458 /* Default maximum number of characters in a packet body. Many
459 remote stubs have a hardwired buffer size of 400 bytes
460 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
461 as the maximum packet-size to ensure that the packet and an extra
462 NUL character can always fit in the buffer. This stops GDB
463 trashing stubs that try to squeeze an extra NUL into what is
464 already a full buffer (As of 1999-12-04 that was most stubs. */
465 remote_packet_size = 400 - 1;
466 /* Should REGISTER_BYTES needs more space than the default, adjust
467 the size accordingly. Remember that each byte is encoded as two
468 characters. 32 is the overhead for the packet header /
469 footer. NOTE: cagney/1999-10-26: I suspect that 8
470 (``$NN:G...#NN'') is a better guess, the below has been padded a
472 if (REGISTER_BYTES > ((remote_packet_size - 32) / 2))
473 remote_packet_size = (REGISTER_BYTES * 2 + 32);
475 /* This one is filled in when a ``g'' packet is received. */
476 actual_register_packet_size = 0;
479 /* Generic configuration support for packets the stub optionally
480 supports. Allows the user to specify the use of the packet as well
481 as allowing GDB to auto-detect support in the remote stub. */
485 PACKET_SUPPORT_UNKNOWN = 0,
494 enum cmd_auto_boolean detect;
495 enum packet_support support;
498 /* Analyze a packet's return value and update the packet config
509 update_packet_config (struct packet_config *config)
511 switch (config->detect)
513 case CMD_AUTO_BOOLEAN_TRUE:
514 config->support = PACKET_ENABLE;
516 case CMD_AUTO_BOOLEAN_FALSE:
517 config->support = PACKET_DISABLE;
519 case CMD_AUTO_BOOLEAN_AUTO:
520 config->support = PACKET_SUPPORT_UNKNOWN;
526 show_packet_config_cmd (struct packet_config *config)
528 char *support = "internal-error";
529 switch (config->support)
535 support = "disabled";
537 case PACKET_SUPPORT_UNKNOWN:
541 switch (config->detect)
543 case CMD_AUTO_BOOLEAN_AUTO:
544 printf_filtered ("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n",
545 config->name, config->title, support);
547 case CMD_AUTO_BOOLEAN_TRUE:
548 case CMD_AUTO_BOOLEAN_FALSE:
549 printf_filtered ("Support for remote protocol `%s' (%s) packet is currently %s.\n",
550 config->name, config->title, support);
556 add_packet_config_cmd (struct packet_config *config,
559 void (*set_func) (char *args, int from_tty,
560 struct cmd_list_element *
562 void (*show_func) (char *name,
564 struct cmd_list_element **set_remote_list,
565 struct cmd_list_element **show_remote_list,
568 struct cmd_list_element *set_cmd;
569 struct cmd_list_element *show_cmd;
574 config->title = title;
575 config->detect = CMD_AUTO_BOOLEAN_AUTO;
576 config->support = PACKET_SUPPORT_UNKNOWN;
577 xasprintf (&set_doc, "Set use of remote protocol `%s' (%s) packet",
579 xasprintf (&show_doc, "Show current use of remote protocol `%s' (%s) packet",
581 /* set/show TITLE-packet {auto,on,off} */
582 xasprintf (&cmd_name, "%s-packet", title);
583 set_cmd = add_set_auto_boolean_cmd (cmd_name, class_obscure,
584 &config->detect, set_doc,
586 set_cmd->function.sfunc = set_func;
587 show_cmd = add_cmd (cmd_name, class_obscure, show_func, show_doc,
589 /* set/show remote NAME-packet {auto,on,off} -- legacy */
593 xasprintf (&legacy_name, "%s-packet", name);
594 add_alias_cmd (legacy_name, cmd_name, class_obscure, 0,
596 add_alias_cmd (legacy_name, cmd_name, class_obscure, 0,
601 static enum packet_result
602 packet_ok (const char *buf, struct packet_config *config)
606 /* The stub recognized the packet request. Check that the
607 operation succeeded. */
608 switch (config->support)
610 case PACKET_SUPPORT_UNKNOWN:
612 fprintf_unfiltered (gdb_stdlog,
613 "Packet %s (%s) is supported\n",
614 config->name, config->title);
615 config->support = PACKET_ENABLE;
618 internal_error ("packet_ok: attempt to use a disabled packet");
623 if (buf[0] == 'O' && buf[1] == 'K' && buf[2] == '\0')
624 /* "OK" - definitly OK. */
627 && isxdigit (buf[1]) && isxdigit (buf[2])
629 /* "Enn" - definitly an error. */
631 /* The packet may or may not be OK. Just assume it is */
636 /* The stub does not support the packet. */
637 switch (config->support)
640 if (config->detect == CMD_AUTO_BOOLEAN_AUTO)
641 /* If the stub previously indicated that the packet was
642 supported then there is a protocol error.. */
643 error ("Protocol error: %s (%s) conflicting enabled responses.",
644 config->name, config->title);
646 /* The user set it wrong. */
647 error ("Enabled packet %s (%s) not recognized by stub",
648 config->name, config->title);
650 case PACKET_SUPPORT_UNKNOWN:
652 fprintf_unfiltered (gdb_stdlog,
653 "Packet %s (%s) is NOT supported\n",
654 config->name, config->title);
655 config->support = PACKET_DISABLE;
660 return PACKET_UNKNOWN;
664 /* Should we try the 'P' (set register) request? */
666 static struct packet_config remote_protocol_P;
669 set_remote_protocol_P_packet_cmd (char *args, int from_tty,
670 struct cmd_list_element *c)
672 update_packet_config (&remote_protocol_P);
676 show_remote_protocol_P_packet_cmd (char *args, int from_tty)
678 show_packet_config_cmd (&remote_protocol_P);
681 /* Should we try one of the 'Z' requests? */
685 Z_PACKET_SOFTWARE_BP,
686 Z_PACKET_HARDWARE_BP,
693 static struct packet_config remote_protocol_Z[NR_Z_PACKET_TYPES];
695 /* FIXME: Instead of having all these boiler plate functions, the
696 command callback should include a context argument. */
699 set_remote_protocol_Z_software_bp_packet_cmd (char *args, int from_tty,
700 struct cmd_list_element *c)
702 update_packet_config (&remote_protocol_Z[Z_PACKET_SOFTWARE_BP]);
706 show_remote_protocol_Z_software_bp_packet_cmd (char *args, int from_tty)
708 show_packet_config_cmd (&remote_protocol_Z[Z_PACKET_SOFTWARE_BP]);
712 set_remote_protocol_Z_hardware_bp_packet_cmd (char *args, int from_tty,
713 struct cmd_list_element *c)
715 update_packet_config (&remote_protocol_Z[Z_PACKET_HARDWARE_BP]);
719 show_remote_protocol_Z_hardware_bp_packet_cmd (char *args, int from_tty)
721 show_packet_config_cmd (&remote_protocol_Z[Z_PACKET_HARDWARE_BP]);
725 set_remote_protocol_Z_write_wp_packet_cmd (char *args, int from_tty,
726 struct cmd_list_element *c)
728 update_packet_config (&remote_protocol_Z[Z_PACKET_WRITE_WP]);
732 show_remote_protocol_Z_write_wp_packet_cmd (char *args, int from_tty)
734 show_packet_config_cmd (&remote_protocol_Z[Z_PACKET_WRITE_WP]);
738 set_remote_protocol_Z_read_wp_packet_cmd (char *args, int from_tty,
739 struct cmd_list_element *c)
741 update_packet_config (&remote_protocol_Z[Z_PACKET_READ_WP]);
745 show_remote_protocol_Z_read_wp_packet_cmd (char *args, int from_tty)
747 show_packet_config_cmd (&remote_protocol_Z[Z_PACKET_READ_WP]);
751 set_remote_protocol_Z_access_wp_packet_cmd (char *args, int from_tty,
752 struct cmd_list_element *c)
754 update_packet_config (&remote_protocol_Z[Z_PACKET_ACCESS_WP]);
758 show_remote_protocol_Z_access_wp_packet_cmd (char *args, int from_tty)
760 show_packet_config_cmd (&remote_protocol_Z[Z_PACKET_ACCESS_WP]);
763 /* For compatibility with older distributions. Provide a ``set remote
764 Z-packet ...'' command that updates all the Z packet types. */
766 static enum cmd_auto_boolean remote_Z_packet_detect;
769 set_remote_protocol_Z_packet_cmd (char *args, int from_tty,
770 struct cmd_list_element *c)
773 for (i = 0; i < NR_Z_PACKET_TYPES; i++)
775 remote_protocol_Z[i].detect = remote_Z_packet_detect;
776 update_packet_config (&remote_protocol_Z[i]);
781 show_remote_protocol_Z_packet_cmd (char *args, int from_tty)
784 for (i = 0; i < NR_Z_PACKET_TYPES; i++)
786 show_packet_config_cmd (&remote_protocol_Z[i]);
790 /* Should we try the 'X' (remote binary download) packet?
792 This variable (available to the user via "set remote X-packet")
793 dictates whether downloads are sent in binary (via the 'X' packet).
794 We assume that the stub can, and attempt to do it. This will be
795 cleared if the stub does not understand it. This switch is still
796 needed, though in cases when the packet is supported in the stub,
797 but the connection does not allow it (i.e., 7-bit serial connection
800 static struct packet_config remote_protocol_binary_download;
802 /* Should we try the 'ThreadInfo' query packet?
804 This variable (NOT available to the user: auto-detect only!)
805 determines whether GDB will use the new, simpler "ThreadInfo"
806 query or the older, more complex syntax for thread queries.
807 This is an auto-detect variable (set to true at each connect,
808 and set to false when the target fails to recognize it). */
810 static int use_threadinfo_query;
811 static int use_threadextra_query;
814 set_remote_protocol_binary_download_cmd (char *args,
816 struct cmd_list_element *c)
818 update_packet_config (&remote_protocol_binary_download);
822 show_remote_protocol_binary_download_cmd (char *args,
825 show_packet_config_cmd (&remote_protocol_binary_download);
829 /* Tokens for use by the asynchronous signal handlers for SIGINT */
830 PTR sigint_remote_twice_token;
831 PTR sigint_remote_token;
833 /* These are pointers to hook functions that may be set in order to
834 modify resume/wait behavior for a particular architecture. */
836 void (*target_resume_hook) (void);
837 void (*target_wait_loop_hook) (void);
841 /* These are the threads which we last sent to the remote system.
842 -1 for all or -2 for not sent yet. */
843 static int general_thread;
844 static int continue_thread;
846 /* Call this function as a result of
847 1) A halt indication (T packet) containing a thread id
848 2) A direct query of currthread
849 3) Successful execution of set thread
853 record_currthread (int currthread)
855 general_thread = currthread;
857 /* If this is a new thread, add it to GDB's thread list.
858 If we leave it up to WFI to do this, bad things will happen. */
859 if (!in_thread_list (currthread))
861 add_thread (currthread);
863 ui_out_text (uiout, "[New ");
864 ui_out_text (uiout, target_pid_to_str (currthread));
865 ui_out_text (uiout, "]\n");
867 printf_filtered ("[New %s]\n", target_pid_to_str (currthread));
872 #define MAGIC_NULL_PID 42000
875 set_thread (int th, int gen)
877 char *buf = alloca (PBUFSIZ);
878 int state = gen ? general_thread : continue_thread;
884 buf[1] = gen ? 'g' : 'c';
885 if (th == MAGIC_NULL_PID)
891 sprintf (&buf[2], "-%x", -th);
893 sprintf (&buf[2], "%x", th);
895 getpkt (buf, PBUFSIZ, 0);
899 continue_thread = th;
902 /* Return nonzero if the thread TH is still alive on the remote system. */
905 remote_thread_alive (int tid)
910 sprintf (buf, "T-%08x", -tid);
912 sprintf (buf, "T%08x", tid);
914 getpkt (buf, sizeof (buf), 0);
915 return (buf[0] == 'O' && buf[1] == 'K');
918 /* About these extended threadlist and threadinfo packets. They are
919 variable length packets but, the fields within them are often fixed
920 length. They are redundent enough to send over UDP as is the
921 remote protocol in general. There is a matching unit test module
924 #define OPAQUETHREADBYTES 8
926 /* a 64 bit opaque identifier */
927 typedef unsigned char threadref[OPAQUETHREADBYTES];
929 /* WARNING: This threadref data structure comes from the remote O.S., libstub
930 protocol encoding, and remote.c. it is not particularly changable */
932 /* Right now, the internal structure is int. We want it to be bigger.
936 typedef int gdb_threadref; /* internal GDB thread reference */
938 /* gdb_ext_thread_info is an internal GDB data structure which is
939 equivalint to the reply of the remote threadinfo packet */
941 struct gdb_ext_thread_info
943 threadref threadid; /* External form of thread reference */
944 int active; /* Has state interesting to GDB? , regs, stack */
945 char display[256]; /* Brief state display, name, blocked/syspended */
946 char shortname[32]; /* To be used to name threads */
947 char more_display[256]; /* Long info, statistics, queue depth, whatever */
950 /* The volume of remote transfers can be limited by submitting
951 a mask containing bits specifying the desired information.
952 Use a union of these values as the 'selection' parameter to
953 get_thread_info. FIXME: Make these TAG names more thread specific.
956 #define TAG_THREADID 1
958 #define TAG_DISPLAY 4
959 #define TAG_THREADNAME 8
960 #define TAG_MOREDISPLAY 16
962 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES*2)
964 char *unpack_varlen_hex (char *buff, int *result);
966 static char *unpack_nibble (char *buf, int *val);
968 static char *pack_nibble (char *buf, int nibble);
970 static char *pack_hex_byte (char *pkt, int /*unsigned char */ byte);
972 static char *unpack_byte (char *buf, int *value);
974 static char *pack_int (char *buf, int value);
976 static char *unpack_int (char *buf, int *value);
978 static char *unpack_string (char *src, char *dest, int length);
980 static char *pack_threadid (char *pkt, threadref * id);
982 static char *unpack_threadid (char *inbuf, threadref * id);
984 void int_to_threadref (threadref * id, int value);
986 static int threadref_to_int (threadref * ref);
988 static void copy_threadref (threadref * dest, threadref * src);
990 static int threadmatch (threadref * dest, threadref * src);
992 static char *pack_threadinfo_request (char *pkt, int mode, threadref * id);
994 static int remote_unpack_thread_info_response (char *pkt,
995 threadref * expectedref,
996 struct gdb_ext_thread_info
1000 static int remote_get_threadinfo (threadref * threadid, int fieldset, /*TAG mask */
1001 struct gdb_ext_thread_info *info);
1003 static int adapt_remote_get_threadinfo (gdb_threadref * ref,
1005 struct gdb_ext_thread_info *info);
1007 static char *pack_threadlist_request (char *pkt, int startflag,
1009 threadref * nextthread);
1011 static int parse_threadlist_response (char *pkt,
1013 threadref * original_echo,
1014 threadref * resultlist, int *doneflag);
1016 static int remote_get_threadlist (int startflag,
1017 threadref * nextthread,
1020 int *result_count, threadref * threadlist);
1022 typedef int (*rmt_thread_action) (threadref * ref, void *context);
1024 static int remote_threadlist_iterator (rmt_thread_action stepfunction,
1025 void *context, int looplimit);
1027 static int remote_newthread_step (threadref * ref, void *context);
1029 /* encode 64 bits in 16 chars of hex */
1031 static const char hexchars[] = "0123456789abcdef";
1034 ishex (int ch, int *val)
1036 if ((ch >= 'a') && (ch <= 'f'))
1038 *val = ch - 'a' + 10;
1041 if ((ch >= 'A') && (ch <= 'F'))
1043 *val = ch - 'A' + 10;
1046 if ((ch >= '0') && (ch <= '9'))
1057 if (ch >= 'a' && ch <= 'f')
1058 return ch - 'a' + 10;
1059 if (ch >= '0' && ch <= '9')
1061 if (ch >= 'A' && ch <= 'F')
1062 return ch - 'A' + 10;
1067 stub_unpack_int (char *buff, int fieldlength)
1074 nibble = stubhex (*buff++);
1078 retval = retval << 4;
1084 unpack_varlen_hex (char *buff, /* packet to parse */
1090 while (ishex (*buff, &nibble))
1093 retval = retval << 4;
1094 retval |= nibble & 0x0f;
1101 unpack_nibble (char *buf, int *val)
1103 ishex (*buf++, val);
1108 pack_nibble (char *buf, int nibble)
1110 *buf++ = hexchars[(nibble & 0x0f)];
1115 pack_hex_byte (char *pkt, int byte)
1117 *pkt++ = hexchars[(byte >> 4) & 0xf];
1118 *pkt++ = hexchars[(byte & 0xf)];
1123 unpack_byte (char *buf, int *value)
1125 *value = stub_unpack_int (buf, 2);
1130 pack_int (char *buf, int value)
1132 buf = pack_hex_byte (buf, (value >> 24) & 0xff);
1133 buf = pack_hex_byte (buf, (value >> 16) & 0xff);
1134 buf = pack_hex_byte (buf, (value >> 8) & 0x0ff);
1135 buf = pack_hex_byte (buf, (value & 0xff));
1140 unpack_int (char *buf, int *value)
1142 *value = stub_unpack_int (buf, 8);
1146 #if 0 /* currently unused, uncomment when needed */
1147 static char *pack_string (char *pkt, char *string);
1150 pack_string (char *pkt, char *string)
1155 len = strlen (string);
1157 len = 200; /* Bigger than most GDB packets, junk??? */
1158 pkt = pack_hex_byte (pkt, len);
1162 if ((ch == '\0') || (ch == '#'))
1163 ch = '*'; /* Protect encapsulation */
1168 #endif /* 0 (unused) */
1171 unpack_string (char *src, char *dest, int length)
1180 pack_threadid (char *pkt, threadref *id)
1183 unsigned char *altid;
1185 altid = (unsigned char *) id;
1186 limit = pkt + BUF_THREAD_ID_SIZE;
1188 pkt = pack_hex_byte (pkt, *altid++);
1194 unpack_threadid (char *inbuf, threadref *id)
1197 char *limit = inbuf + BUF_THREAD_ID_SIZE;
1200 altref = (char *) id;
1202 while (inbuf < limit)
1204 x = stubhex (*inbuf++);
1205 y = stubhex (*inbuf++);
1206 *altref++ = (x << 4) | y;
1211 /* Externally, threadrefs are 64 bits but internally, they are still
1212 ints. This is due to a mismatch of specifications. We would like
1213 to use 64bit thread references internally. This is an adapter
1217 int_to_threadref (threadref *id, int value)
1219 unsigned char *scan;
1221 scan = (unsigned char *) id;
1227 *scan++ = (value >> 24) & 0xff;
1228 *scan++ = (value >> 16) & 0xff;
1229 *scan++ = (value >> 8) & 0xff;
1230 *scan++ = (value & 0xff);
1234 threadref_to_int (threadref *ref)
1237 unsigned char *scan;
1239 scan = (char *) ref;
1243 value = (value << 8) | ((*scan++) & 0xff);
1248 copy_threadref (threadref *dest, threadref *src)
1251 unsigned char *csrc, *cdest;
1253 csrc = (unsigned char *) src;
1254 cdest = (unsigned char *) dest;
1261 threadmatch (threadref *dest, threadref *src)
1263 /* things are broken right now, so just assume we got a match */
1265 unsigned char *srcp, *destp;
1267 srcp = (char *) src;
1268 destp = (char *) dest;
1272 result &= (*srcp++ == *destp++) ? 1 : 0;
1279 threadid:1, # always request threadid
1286 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
1289 pack_threadinfo_request (char *pkt, int mode, threadref *id)
1291 *pkt++ = 'q'; /* Info Query */
1292 *pkt++ = 'P'; /* process or thread info */
1293 pkt = pack_int (pkt, mode); /* mode */
1294 pkt = pack_threadid (pkt, id); /* threadid */
1295 *pkt = '\0'; /* terminate */
1299 /* These values tag the fields in a thread info response packet */
1300 /* Tagging the fields allows us to request specific fields and to
1301 add more fields as time goes by */
1303 #define TAG_THREADID 1 /* Echo the thread identifier */
1304 #define TAG_EXISTS 2 /* Is this process defined enough to
1305 fetch registers and its stack */
1306 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
1307 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is */
1308 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
1312 remote_unpack_thread_info_response (char *pkt, threadref *expectedref,
1313 struct gdb_ext_thread_info *info)
1318 char *limit = pkt + PBUFSIZ; /* plausable parsing limit */
1321 /* info->threadid = 0; FIXME: implement zero_threadref */
1323 info->display[0] = '\0';
1324 info->shortname[0] = '\0';
1325 info->more_display[0] = '\0';
1327 /* Assume the characters indicating the packet type have been stripped */
1328 pkt = unpack_int (pkt, &mask); /* arg mask */
1329 pkt = unpack_threadid (pkt, &ref);
1332 warning ("Incomplete response to threadinfo request\n");
1333 if (!threadmatch (&ref, expectedref))
1334 { /* This is an answer to a different request */
1335 warning ("ERROR RMT Thread info mismatch\n");
1338 copy_threadref (&info->threadid, &ref);
1340 /* Loop on tagged fields , try to bail if somthing goes wrong */
1342 while ((pkt < limit) && mask && *pkt) /* packets are terminated with nulls */
1344 pkt = unpack_int (pkt, &tag); /* tag */
1345 pkt = unpack_byte (pkt, &length); /* length */
1346 if (!(tag & mask)) /* tags out of synch with mask */
1348 warning ("ERROR RMT: threadinfo tag mismatch\n");
1352 if (tag == TAG_THREADID)
1356 warning ("ERROR RMT: length of threadid is not 16\n");
1360 pkt = unpack_threadid (pkt, &ref);
1361 mask = mask & ~TAG_THREADID;
1364 if (tag == TAG_EXISTS)
1366 info->active = stub_unpack_int (pkt, length);
1368 mask = mask & ~(TAG_EXISTS);
1371 warning ("ERROR RMT: 'exists' length too long\n");
1377 if (tag == TAG_THREADNAME)
1379 pkt = unpack_string (pkt, &info->shortname[0], length);
1380 mask = mask & ~TAG_THREADNAME;
1383 if (tag == TAG_DISPLAY)
1385 pkt = unpack_string (pkt, &info->display[0], length);
1386 mask = mask & ~TAG_DISPLAY;
1389 if (tag == TAG_MOREDISPLAY)
1391 pkt = unpack_string (pkt, &info->more_display[0], length);
1392 mask = mask & ~TAG_MOREDISPLAY;
1395 warning ("ERROR RMT: unknown thread info tag\n");
1396 break; /* Not a tag we know about */
1402 remote_get_threadinfo (threadref *threadid, int fieldset, /* TAG mask */
1403 struct gdb_ext_thread_info *info)
1406 char *threadinfo_pkt = alloca (PBUFSIZ);
1408 pack_threadinfo_request (threadinfo_pkt, fieldset, threadid);
1409 putpkt (threadinfo_pkt);
1410 getpkt (threadinfo_pkt, PBUFSIZ, 0);
1411 result = remote_unpack_thread_info_response (threadinfo_pkt + 2, threadid,
1416 /* Unfortunately, 61 bit thread-ids are bigger than the internal
1417 representation of a threadid. */
1420 adapt_remote_get_threadinfo (gdb_threadref *ref, int selection,
1421 struct gdb_ext_thread_info *info)
1425 int_to_threadref (&lclref, *ref);
1426 return remote_get_threadinfo (&lclref, selection, info);
1429 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
1432 pack_threadlist_request (char *pkt, int startflag, int threadcount,
1433 threadref *nextthread)
1435 *pkt++ = 'q'; /* info query packet */
1436 *pkt++ = 'L'; /* Process LIST or threadLIST request */
1437 pkt = pack_nibble (pkt, startflag); /* initflag 1 bytes */
1438 pkt = pack_hex_byte (pkt, threadcount); /* threadcount 2 bytes */
1439 pkt = pack_threadid (pkt, nextthread); /* 64 bit thread identifier */
1444 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
1447 parse_threadlist_response (char *pkt, int result_limit,
1448 threadref *original_echo, threadref *resultlist,
1452 int count, resultcount, done;
1455 /* Assume the 'q' and 'M chars have been stripped. */
1456 limit = pkt + (PBUFSIZ - BUF_THREAD_ID_SIZE); /* done parse past here */
1457 pkt = unpack_byte (pkt, &count); /* count field */
1458 pkt = unpack_nibble (pkt, &done);
1459 /* The first threadid is the argument threadid. */
1460 pkt = unpack_threadid (pkt, original_echo); /* should match query packet */
1461 while ((count-- > 0) && (pkt < limit))
1463 pkt = unpack_threadid (pkt, resultlist++);
1464 if (resultcount++ >= result_limit)
1473 remote_get_threadlist (int startflag, threadref *nextthread, int result_limit,
1474 int *done, int *result_count, threadref *threadlist)
1476 static threadref echo_nextthread;
1477 char *threadlist_packet = alloca (PBUFSIZ);
1478 char *t_response = alloca (PBUFSIZ);
1481 /* Trancate result limit to be smaller than the packet size */
1482 if ((((result_limit + 1) * BUF_THREAD_ID_SIZE) + 10) >= PBUFSIZ)
1483 result_limit = (PBUFSIZ / BUF_THREAD_ID_SIZE) - 2;
1485 pack_threadlist_request (threadlist_packet,
1486 startflag, result_limit, nextthread);
1487 putpkt (threadlist_packet);
1488 getpkt (t_response, PBUFSIZ, 0);
1491 parse_threadlist_response (t_response + 2, result_limit, &echo_nextthread,
1494 if (!threadmatch (&echo_nextthread, nextthread))
1496 /* FIXME: This is a good reason to drop the packet */
1497 /* Possably, there is a duplicate response */
1499 retransmit immediatly - race conditions
1500 retransmit after timeout - yes
1502 wait for packet, then exit
1504 warning ("HMM: threadlist did not echo arg thread, dropping it\n");
1505 return 0; /* I choose simply exiting */
1507 if (*result_count <= 0)
1511 warning ("RMT ERROR : failed to get remote thread list\n");
1514 return result; /* break; */
1516 if (*result_count > result_limit)
1519 warning ("RMT ERROR: threadlist response longer than requested\n");
1525 /* This is the interface between remote and threads, remotes upper interface */
1527 /* remote_find_new_threads retrieves the thread list and for each
1528 thread in the list, looks up the thread in GDB's internal list,
1529 ading the thread if it does not already exist. This involves
1530 getting partial thread lists from the remote target so, polling the
1531 quit_flag is required. */
1534 /* About this many threadisds fit in a packet. */
1536 #define MAXTHREADLISTRESULTS 32
1539 remote_threadlist_iterator (rmt_thread_action stepfunction, void *context,
1542 int done, i, result_count;
1546 static threadref nextthread;
1547 static threadref resultthreadlist[MAXTHREADLISTRESULTS];
1552 if (loopcount++ > looplimit)
1555 warning ("Remote fetch threadlist -infinite loop-\n");
1558 if (!remote_get_threadlist (startflag, &nextthread, MAXTHREADLISTRESULTS,
1559 &done, &result_count, resultthreadlist))
1564 /* clear for later iterations */
1566 /* Setup to resume next batch of thread references, set nextthread. */
1567 if (result_count >= 1)
1568 copy_threadref (&nextthread, &resultthreadlist[result_count - 1]);
1570 while (result_count--)
1571 if (!(result = (*stepfunction) (&resultthreadlist[i++], context)))
1578 remote_newthread_step (threadref *ref, void *context)
1582 pid = threadref_to_int (ref);
1583 if (!in_thread_list (pid))
1585 return 1; /* continue iterator */
1588 #define CRAZY_MAX_THREADS 1000
1591 remote_current_thread (int oldpid)
1593 char *buf = alloca (PBUFSIZ);
1596 getpkt (buf, PBUFSIZ, 0);
1597 if (buf[0] == 'Q' && buf[1] == 'C')
1598 return strtol (&buf[2], NULL, 16);
1603 /* Find new threads for info threads command.
1604 * Original version, using John Metzler's thread protocol.
1608 remote_find_new_threads (void)
1610 remote_threadlist_iterator (remote_newthread_step, 0,
1612 if (inferior_pid == MAGIC_NULL_PID) /* ack ack ack */
1613 inferior_pid = remote_current_thread (inferior_pid);
1617 * Find all threads for info threads command.
1618 * Uses new thread protocol contributed by Cisco.
1619 * Falls back and attempts to use the older method (above)
1620 * if the target doesn't respond to the new method.
1624 remote_threads_info (void)
1626 char *buf = alloca (PBUFSIZ);
1630 if (remote_desc == 0) /* paranoia */
1631 error ("Command can only be used when connected to the remote target.");
1633 if (use_threadinfo_query)
1635 putpkt ("qfThreadInfo");
1637 getpkt (bufp, PBUFSIZ, 0);
1638 if (bufp[0] != '\0') /* q packet recognized */
1640 while (*bufp++ == 'm') /* reply contains one or more TID */
1644 tid = strtol (bufp, &bufp, 16);
1645 if (tid != 0 && !in_thread_list (tid))
1648 while (*bufp++ == ','); /* comma-separated list */
1649 putpkt ("qsThreadInfo");
1651 getpkt (bufp, PBUFSIZ, 0);
1657 /* Else fall back to old method based on jmetzler protocol. */
1658 use_threadinfo_query = 0;
1659 remote_find_new_threads ();
1664 * Collect a descriptive string about the given thread.
1665 * The target may say anything it wants to about the thread
1666 * (typically info about its blocked / runnable state, name, etc.).
1667 * This string will appear in the info threads display.
1669 * Optional: targets are not required to implement this function.
1673 remote_threads_extra_info (struct thread_info *tp)
1678 struct gdb_ext_thread_info threadinfo;
1679 static char display_buf[100]; /* arbitrary... */
1680 char *bufp = alloca (PBUFSIZ);
1681 int n = 0; /* position in display_buf */
1683 if (remote_desc == 0) /* paranoia */
1684 internal_error ("remote_threads_extra_info");
1686 if (use_threadextra_query)
1688 sprintf (bufp, "qThreadExtraInfo,%x", tp->pid);
1690 getpkt (bufp, PBUFSIZ, 0);
1695 for (p = display_buf;
1696 p < display_buf + sizeof(display_buf) - 1 &&
1701 *p = fromhex (bufp[0]) * 16 + fromhex (bufp[1]);
1708 /* If the above query fails, fall back to the old method. */
1709 use_threadextra_query = 0;
1710 set = TAG_THREADID | TAG_EXISTS | TAG_THREADNAME
1711 | TAG_MOREDISPLAY | TAG_DISPLAY;
1712 int_to_threadref (&id, tp->pid);
1713 if (remote_get_threadinfo (&id, set, &threadinfo))
1714 if (threadinfo.active)
1716 if (*threadinfo.shortname)
1717 n += sprintf(&display_buf[0], " Name: %s,", threadinfo.shortname);
1718 if (*threadinfo.display)
1719 n += sprintf(&display_buf[n], " State: %s,", threadinfo.display);
1720 if (*threadinfo.more_display)
1721 n += sprintf(&display_buf[n], " Priority: %s",
1722 threadinfo.more_display);
1726 /* for purely cosmetic reasons, clear up trailing commas */
1727 if (',' == display_buf[n-1])
1728 display_buf[n-1] = ' ';
1737 /* Restart the remote side; this is an extended protocol operation. */
1740 extended_remote_restart (void)
1742 char *buf = alloca (PBUFSIZ);
1744 /* Send the restart command; for reasons I don't understand the
1745 remote side really expects a number after the "R". */
1747 sprintf (&buf[1], "%x", 0);
1750 /* Now query for status so this looks just like we restarted
1751 gdbserver from scratch. */
1753 getpkt (buf, PBUFSIZ, 0);
1756 /* Clean up connection to a remote debugger. */
1760 remote_close (int quitting)
1763 SERIAL_CLOSE (remote_desc);
1767 /* Query the remote side for the text, data and bss offsets. */
1772 char *buf = alloca (PBUFSIZ);
1775 CORE_ADDR text_addr, data_addr, bss_addr;
1776 struct section_offsets *offs;
1778 putpkt ("qOffsets");
1780 getpkt (buf, PBUFSIZ, 0);
1782 if (buf[0] == '\000')
1783 return; /* Return silently. Stub doesn't support
1787 warning ("Remote failure reply: %s", buf);
1791 /* Pick up each field in turn. This used to be done with scanf, but
1792 scanf will make trouble if CORE_ADDR size doesn't match
1793 conversion directives correctly. The following code will work
1794 with any size of CORE_ADDR. */
1795 text_addr = data_addr = bss_addr = 0;
1799 if (strncmp (ptr, "Text=", 5) == 0)
1802 /* Don't use strtol, could lose on big values. */
1803 while (*ptr && *ptr != ';')
1804 text_addr = (text_addr << 4) + fromhex (*ptr++);
1809 if (!lose && strncmp (ptr, ";Data=", 6) == 0)
1812 while (*ptr && *ptr != ';')
1813 data_addr = (data_addr << 4) + fromhex (*ptr++);
1818 if (!lose && strncmp (ptr, ";Bss=", 5) == 0)
1821 while (*ptr && *ptr != ';')
1822 bss_addr = (bss_addr << 4) + fromhex (*ptr++);
1828 error ("Malformed response to offset query, %s", buf);
1830 if (symfile_objfile == NULL)
1833 offs = (struct section_offsets *) alloca (SIZEOF_SECTION_OFFSETS);
1834 memcpy (offs, symfile_objfile->section_offsets, SIZEOF_SECTION_OFFSETS);
1836 offs->offsets[SECT_OFF_TEXT (symfile_objfile)] = text_addr;
1838 /* This is a temporary kludge to force data and bss to use the same offsets
1839 because that's what nlmconv does now. The real solution requires changes
1840 to the stub and remote.c that I don't have time to do right now. */
1842 offs->offsets[SECT_OFF_DATA (symfile_objfile)] = data_addr;
1843 offs->offsets[SECT_OFF_BSS (symfile_objfile)] = data_addr;
1845 objfile_relocate (symfile_objfile, offs);
1849 * Cisco version of section offsets:
1851 * Instead of having GDB query the target for the section offsets,
1852 * Cisco lets the target volunteer the information! It's also in
1853 * a different format, so here are the functions that will decode
1854 * a section offset packet from a Cisco target.
1858 * Function: remote_cisco_section_offsets
1860 * Returns: zero for success, non-zero for failure
1864 remote_cisco_section_offsets (bfd_vma text_addr,
1867 bfd_signed_vma *text_offs,
1868 bfd_signed_vma *data_offs,
1869 bfd_signed_vma *bss_offs)
1871 bfd_vma text_base, data_base, bss_base;
1872 struct minimal_symbol *start;
1878 if (symfile_objfile == NULL)
1879 return -1; /* no can do nothin' */
1881 start = lookup_minimal_symbol ("_start", NULL, NULL);
1883 return -1; /* Can't find "_start" symbol */
1885 data_base = bss_base = 0;
1886 text_base = SYMBOL_VALUE_ADDRESS (start);
1888 abfd = symfile_objfile->obfd;
1889 for (sect = abfd->sections;
1893 p = (unsigned char *) bfd_get_section_name (abfd, sect);
1895 if (strcmp (p + len - 4, "data") == 0) /* ends in "data" */
1896 if (data_base == 0 ||
1897 data_base > bfd_get_section_vma (abfd, sect))
1898 data_base = bfd_get_section_vma (abfd, sect);
1899 if (strcmp (p + len - 3, "bss") == 0) /* ends in "bss" */
1900 if (bss_base == 0 ||
1901 bss_base > bfd_get_section_vma (abfd, sect))
1902 bss_base = bfd_get_section_vma (abfd, sect);
1904 *text_offs = text_addr - text_base;
1905 *data_offs = data_addr - data_base;
1906 *bss_offs = bss_addr - bss_base;
1911 sprintf (tmp, "VMA: text = 0x");
1912 sprintf_vma (tmp + strlen (tmp), text_addr);
1913 sprintf (tmp + strlen (tmp), " data = 0x");
1914 sprintf_vma (tmp + strlen (tmp), data_addr);
1915 sprintf (tmp + strlen (tmp), " bss = 0x");
1916 sprintf_vma (tmp + strlen (tmp), bss_addr);
1917 fprintf_filtered (gdb_stdlog, tmp);
1918 fprintf_filtered (gdb_stdlog,
1919 "Reloc offset: text = 0x%s data = 0x%s bss = 0x%s\n",
1920 paddr_nz (*text_offs),
1921 paddr_nz (*data_offs),
1922 paddr_nz (*bss_offs));
1929 * Function: remote_cisco_objfile_relocate
1931 * Relocate the symbol file for a remote target.
1935 remote_cisco_objfile_relocate (bfd_signed_vma text_off, bfd_signed_vma data_off,
1936 bfd_signed_vma bss_off)
1938 struct section_offsets *offs;
1940 if (text_off != 0 || data_off != 0 || bss_off != 0)
1942 /* FIXME: This code assumes gdb-stabs.h is being used; it's
1943 broken for xcoff, dwarf, sdb-coff, etc. But there is no
1944 simple canonical representation for this stuff. */
1946 offs = (struct section_offsets *) alloca (SIZEOF_SECTION_OFFSETS);
1947 memcpy (offs, symfile_objfile->section_offsets, SIZEOF_SECTION_OFFSETS);
1949 offs->offsets[SECT_OFF_TEXT (symfile_objfile)] = text_off;
1950 offs->offsets[SECT_OFF_DATA (symfile_objfile)] = data_off;
1951 offs->offsets[SECT_OFF_BSS (symfile_objfile)] = bss_off;
1953 /* First call the standard objfile_relocate. */
1954 objfile_relocate (symfile_objfile, offs);
1956 /* Now we need to fix up the section entries already attached to
1957 the exec target. These entries will control memory transfers
1958 from the exec file. */
1960 exec_set_section_offsets (text_off, data_off, bss_off);
1964 /* Stub for catch_errors. */
1967 remote_start_remote_dummy (void *dummy)
1969 start_remote (); /* Initialize gdb process mechanisms */
1974 remote_start_remote (PTR dummy)
1976 immediate_quit++; /* Allow user to interrupt it */
1978 /* Ack any packet which the remote side has already sent. */
1979 SERIAL_WRITE (remote_desc, "+", 1);
1981 /* Let the stub know that we want it to return the thread. */
1984 inferior_pid = remote_current_thread (inferior_pid);
1986 get_offsets (); /* Get text, data & bss offsets */
1988 putpkt ("?"); /* initiate a query from remote machine */
1991 return remote_start_remote_dummy (dummy);
1994 /* Open a connection to a remote debugger.
1995 NAME is the filename used for communication. */
1998 remote_open (char *name, int from_tty)
2000 remote_open_1 (name, from_tty, &remote_ops, 0);
2003 /* Just like remote_open, but with asynchronous support. */
2005 remote_async_open (char *name, int from_tty)
2007 remote_async_open_1 (name, from_tty, &remote_async_ops, 0);
2010 /* Open a connection to a remote debugger using the extended
2011 remote gdb protocol. NAME is the filename used for communication. */
2014 extended_remote_open (char *name, int from_tty)
2016 remote_open_1 (name, from_tty, &extended_remote_ops, 1 /*extended_p */ );
2019 /* Just like extended_remote_open, but with asynchronous support. */
2021 extended_remote_async_open (char *name, int from_tty)
2023 remote_async_open_1 (name, from_tty, &extended_async_remote_ops, 1 /*extended_p */ );
2026 /* Generic code for opening a connection to a remote target. */
2029 init_all_packet_configs (void)
2032 update_packet_config (&remote_protocol_P);
2033 for (i = 0; i < NR_Z_PACKET_TYPES; i++)
2034 update_packet_config (&remote_protocol_Z[i]);
2035 /* Force remote_write_bytes to check whether target supports binary
2037 update_packet_config (&remote_protocol_binary_download);
2041 remote_open_1 (char *name, int from_tty, struct target_ops *target,
2045 error ("To open a remote debug connection, you need to specify what\n\
2046 serial device is attached to the remote system\n\
2047 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
2049 /* See FIXME above */
2050 wait_forever_enabled_p = 1;
2052 target_preopen (from_tty);
2054 unpush_target (target);
2056 remote_desc = SERIAL_OPEN (name);
2058 perror_with_name (name);
2060 if (baud_rate != -1)
2062 if (SERIAL_SETBAUDRATE (remote_desc, baud_rate))
2064 SERIAL_CLOSE (remote_desc);
2065 perror_with_name (name);
2069 SERIAL_RAW (remote_desc);
2071 /* If there is something sitting in the buffer we might take it as a
2072 response to a command, which would be bad. */
2073 SERIAL_FLUSH_INPUT (remote_desc);
2077 puts_filtered ("Remote debugging using ");
2078 puts_filtered (name);
2079 puts_filtered ("\n");
2081 push_target (target); /* Switch to using remote target now */
2083 init_all_packet_configs ();
2085 general_thread = -2;
2086 continue_thread = -2;
2088 /* Probe for ability to use "ThreadInfo" query, as required. */
2089 use_threadinfo_query = 1;
2090 use_threadextra_query = 1;
2092 /* Without this, some commands which require an active target (such
2093 as kill) won't work. This variable serves (at least) double duty
2094 as both the pid of the target process (if it has such), and as a
2095 flag indicating that a target is active. These functions should
2096 be split out into seperate variables, especially since GDB will
2097 someday have a notion of debugging several processes. */
2099 inferior_pid = MAGIC_NULL_PID;
2100 /* Start the remote connection; if error (0), discard this target.
2101 In particular, if the user quits, be sure to discard it
2102 (we'd be in an inconsistent state otherwise). */
2103 if (!catch_errors (remote_start_remote, NULL,
2104 "Couldn't establish connection to remote target\n",
2113 /* tell the remote that we're using the extended protocol. */
2114 char *buf = alloca (PBUFSIZ);
2116 getpkt (buf, PBUFSIZ, 0);
2120 /* Just like remote_open but with asynchronous support. */
2122 remote_async_open_1 (char *name, int from_tty, struct target_ops *target,
2126 error ("To open a remote debug connection, you need to specify what\n\
2127 serial device is attached to the remote system\n\
2128 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
2130 target_preopen (from_tty);
2132 unpush_target (target);
2134 remote_desc = SERIAL_OPEN (name);
2136 perror_with_name (name);
2138 if (baud_rate != -1)
2140 if (SERIAL_SETBAUDRATE (remote_desc, baud_rate))
2142 SERIAL_CLOSE (remote_desc);
2143 perror_with_name (name);
2147 SERIAL_RAW (remote_desc);
2149 /* If there is something sitting in the buffer we might take it as a
2150 response to a command, which would be bad. */
2151 SERIAL_FLUSH_INPUT (remote_desc);
2155 puts_filtered ("Remote debugging using ");
2156 puts_filtered (name);
2157 puts_filtered ("\n");
2160 push_target (target); /* Switch to using remote target now */
2162 init_all_packet_configs ();
2164 general_thread = -2;
2165 continue_thread = -2;
2167 /* Probe for ability to use "ThreadInfo" query, as required. */
2168 use_threadinfo_query = 1;
2169 use_threadextra_query = 1;
2171 /* Without this, some commands which require an active target (such
2172 as kill) won't work. This variable serves (at least) double duty
2173 as both the pid of the target process (if it has such), and as a
2174 flag indicating that a target is active. These functions should
2175 be split out into seperate variables, especially since GDB will
2176 someday have a notion of debugging several processes. */
2177 inferior_pid = MAGIC_NULL_PID;
2179 /* With this target we start out by owning the terminal. */
2180 remote_async_terminal_ours_p = 1;
2182 /* FIXME: cagney/1999-09-23: During the initial connection it is
2183 assumed that the target is already ready and able to respond to
2184 requests. Unfortunately remote_start_remote() eventually calls
2185 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
2186 around this. Eventually a mechanism that allows
2187 wait_for_inferior() to expect/get timeouts will be
2189 wait_forever_enabled_p = 0;
2191 /* Start the remote connection; if error (0), discard this target.
2192 In particular, if the user quits, be sure to discard it
2193 (we'd be in an inconsistent state otherwise). */
2194 if (!catch_errors (remote_start_remote, NULL,
2195 "Couldn't establish connection to remote target\n",
2199 wait_forever_enabled_p = 1;
2203 wait_forever_enabled_p = 1;
2207 /* tell the remote that we're using the extended protocol. */
2208 char *buf = alloca (PBUFSIZ);
2210 getpkt (buf, PBUFSIZ, 0);
2214 /* This takes a program previously attached to and detaches it. After
2215 this is done, GDB can be used to debug some other program. We
2216 better not have left any breakpoints in the target program or it'll
2217 die when it hits one. */
2220 remote_detach (char *args, int from_tty)
2222 char *buf = alloca (PBUFSIZ);
2225 error ("Argument given to \"detach\" when remotely debugging.");
2227 /* Tell the remote target to detach. */
2229 remote_send (buf, PBUFSIZ);
2231 target_mourn_inferior ();
2233 puts_filtered ("Ending remote debugging.\n");
2237 /* Same as remote_detach, but with async support. */
2239 remote_async_detach (char *args, int from_tty)
2241 char *buf = alloca (PBUFSIZ);
2244 error ("Argument given to \"detach\" when remotely debugging.");
2246 /* Tell the remote target to detach. */
2248 remote_send (buf, PBUFSIZ);
2250 /* Unregister the file descriptor from the event loop. */
2251 if (target_is_async_p ())
2252 SERIAL_ASYNC (remote_desc, NULL, 0);
2254 target_mourn_inferior ();
2256 puts_filtered ("Ending remote debugging.\n");
2259 /* Convert hex digit A to a number. */
2264 if (a >= '0' && a <= '9')
2266 else if (a >= 'a' && a <= 'f')
2267 return a - 'a' + 10;
2268 else if (a >= 'A' && a <= 'F')
2269 return a - 'A' + 10;
2271 error ("Reply contains invalid hex digit %d", a);
2274 /* Convert number NIB to a hex digit. */
2282 return 'a' + nib - 10;
2285 /* Tell the remote machine to resume. */
2287 static enum target_signal last_sent_signal = TARGET_SIGNAL_0;
2289 static int last_sent_step;
2292 remote_resume (int pid, int step, enum target_signal siggnal)
2294 char *buf = alloca (PBUFSIZ);
2297 set_thread (0, 0); /* run any thread */
2299 set_thread (pid, 0); /* run this thread */
2301 last_sent_signal = siggnal;
2302 last_sent_step = step;
2304 /* A hook for when we need to do something at the last moment before
2306 if (target_resume_hook)
2307 (*target_resume_hook) ();
2309 if (siggnal != TARGET_SIGNAL_0)
2311 buf[0] = step ? 'S' : 'C';
2312 buf[1] = tohex (((int) siggnal >> 4) & 0xf);
2313 buf[2] = tohex ((int) siggnal & 0xf);
2317 strcpy (buf, step ? "s" : "c");
2322 /* Same as remote_resume, but with async support. */
2324 remote_async_resume (int pid, int step, enum target_signal siggnal)
2326 char *buf = alloca (PBUFSIZ);
2329 set_thread (0, 0); /* run any thread */
2331 set_thread (pid, 0); /* run this thread */
2333 last_sent_signal = siggnal;
2334 last_sent_step = step;
2336 /* A hook for when we need to do something at the last moment before
2338 if (target_resume_hook)
2339 (*target_resume_hook) ();
2341 if (siggnal != TARGET_SIGNAL_0)
2343 buf[0] = step ? 'S' : 'C';
2344 buf[1] = tohex (((int) siggnal >> 4) & 0xf);
2345 buf[2] = tohex ((int) siggnal & 0xf);
2349 strcpy (buf, step ? "s" : "c");
2351 /* We are about to start executing the inferior, let's register it
2352 with the event loop. NOTE: this is the one place where all the
2353 execution commands end up. We could alternatively do this in each
2354 of the execution commands in infcmd.c.*/
2355 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
2356 into infcmd.c in order to allow inferior function calls to work
2357 NOT asynchronously. */
2358 if (event_loop_p && target_can_async_p ())
2359 target_async (inferior_event_handler, 0);
2360 /* Tell the world that the target is now executing. */
2361 /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
2362 this? Instead, should the client of target just assume (for
2363 async targets) that the target is going to start executing? Is
2364 this information already found in the continuation block? */
2365 if (target_is_async_p ())
2366 target_executing = 1;
2371 /* Set up the signal handler for SIGINT, while the target is
2372 executing, ovewriting the 'regular' SIGINT signal handler. */
2374 initialize_sigint_signal_handler (void)
2376 sigint_remote_token =
2377 create_async_signal_handler (async_remote_interrupt, NULL);
2378 signal (SIGINT, handle_remote_sigint);
2381 /* Signal handler for SIGINT, while the target is executing. */
2383 handle_remote_sigint (int sig)
2385 signal (sig, handle_remote_sigint_twice);
2386 sigint_remote_twice_token =
2387 create_async_signal_handler (async_remote_interrupt_twice, NULL);
2388 mark_async_signal_handler_wrapper (sigint_remote_token);
2391 /* Signal handler for SIGINT, installed after SIGINT has already been
2392 sent once. It will take effect the second time that the user sends
2395 handle_remote_sigint_twice (int sig)
2397 signal (sig, handle_sigint);
2398 sigint_remote_twice_token =
2399 create_async_signal_handler (inferior_event_handler_wrapper, NULL);
2400 mark_async_signal_handler_wrapper (sigint_remote_twice_token);
2403 /* Perform the real interruption of the target execution, in response
2406 async_remote_interrupt (gdb_client_data arg)
2409 fprintf_unfiltered (gdb_stdlog, "remote_interrupt called\n");
2414 /* Perform interrupt, if the first attempt did not succeed. Just give
2415 up on the target alltogether. */
2417 async_remote_interrupt_twice (gdb_client_data arg)
2420 fprintf_unfiltered (gdb_stdlog, "remote_interrupt_twice called\n");
2421 /* Do something only if the target was not killed by the previous
2423 if (target_executing)
2426 signal (SIGINT, handle_remote_sigint);
2430 /* Reinstall the usual SIGINT handlers, after the target has
2433 cleanup_sigint_signal_handler (void *dummy)
2435 signal (SIGINT, handle_sigint);
2436 if (sigint_remote_twice_token)
2437 delete_async_signal_handler ((struct async_signal_handler **) & sigint_remote_twice_token);
2438 if (sigint_remote_token)
2439 delete_async_signal_handler ((struct async_signal_handler **) & sigint_remote_token);
2442 /* Send ^C to target to halt it. Target will respond, and send us a
2444 static void (*ofunc) (int);
2446 /* The command line interface's stop routine. This function is installed
2447 as a signal handler for SIGINT. The first time a user requests a
2448 stop, we call remote_stop to send a break or ^C. If there is no
2449 response from the target (it didn't stop when the user requested it),
2450 we ask the user if he'd like to detach from the target. */
2452 remote_interrupt (int signo)
2454 /* If this doesn't work, try more severe steps. */
2455 signal (signo, remote_interrupt_twice);
2458 fprintf_unfiltered (gdb_stdlog, "remote_interrupt called\n");
2463 /* The user typed ^C twice. */
2466 remote_interrupt_twice (int signo)
2468 signal (signo, ofunc);
2470 signal (signo, remote_interrupt);
2473 /* This is the generic stop called via the target vector. When a target
2474 interrupt is requested, either by the command line or the GUI, we
2475 will eventually end up here. */
2479 /* Send a break or a ^C, depending on user preference. */
2481 fprintf_unfiltered (gdb_stdlog, "remote_stop called\n");
2484 SERIAL_SEND_BREAK (remote_desc);
2486 SERIAL_WRITE (remote_desc, "\003", 1);
2489 /* Ask the user what to do when an interrupt is received. */
2492 interrupt_query (void)
2494 target_terminal_ours ();
2496 if (query ("Interrupted while waiting for the program.\n\
2497 Give up (and stop debugging it)? "))
2499 target_mourn_inferior ();
2500 return_to_top_level (RETURN_QUIT);
2503 target_terminal_inferior ();
2506 /* Enable/disable target terminal ownership. Most targets can use
2507 terminal groups to control terminal ownership. Remote targets are
2508 different in that explicit transfer of ownership to/from GDB/target
2512 remote_async_terminal_inferior (void)
2514 /* FIXME: cagney/1999-09-27: Shouldn't need to test for
2515 sync_execution here. This function should only be called when
2516 GDB is resuming the inferior in the forground. A background
2517 resume (``run&'') should leave GDB in control of the terminal and
2518 consequently should not call this code. */
2519 if (!sync_execution)
2521 /* FIXME: cagney/1999-09-27: Closely related to the above. Make
2522 calls target_terminal_*() idenpotent. The event-loop GDB talking
2523 to an asynchronous target with a synchronous command calls this
2524 function from both event-top.c and infrun.c/infcmd.c. Once GDB
2525 stops trying to transfer the terminal to the target when it
2526 shouldn't this guard can go away. */
2527 if (!remote_async_terminal_ours_p)
2529 delete_file_handler (input_fd);
2530 remote_async_terminal_ours_p = 0;
2531 initialize_sigint_signal_handler ();
2532 /* NOTE: At this point we could also register our selves as the
2533 recipient of all input. Any characters typed could then be
2534 passed on down to the target. */
2538 remote_async_terminal_ours (void)
2540 /* See FIXME in remote_async_terminal_inferior. */
2541 if (!sync_execution)
2543 /* See FIXME in remote_async_terminal_inferior. */
2544 if (remote_async_terminal_ours_p)
2546 cleanup_sigint_signal_handler (NULL);
2547 add_file_handler (input_fd, stdin_event_handler, 0);
2548 remote_async_terminal_ours_p = 1;
2551 /* If nonzero, ignore the next kill. */
2556 remote_console_output (char *msg)
2560 for (p = msg; p[0] && p[1]; p += 2)
2563 char c = fromhex (p[0]) * 16 + fromhex (p[1]);
2566 fputs_unfiltered (tb, gdb_stdtarg);
2568 gdb_flush (gdb_stdtarg);
2571 /* Wait until the remote machine stops, then return,
2572 storing status in STATUS just as `wait' would.
2573 Returns "pid", which in the case of a multi-threaded
2574 remote OS, is the thread-id. */
2577 remote_wait (int pid, struct target_waitstatus *status)
2579 unsigned char *buf = alloca (PBUFSIZ);
2580 int thread_num = -1;
2582 status->kind = TARGET_WAITKIND_EXITED;
2583 status->value.integer = 0;
2589 ofunc = signal (SIGINT, remote_interrupt);
2590 getpkt (buf, PBUFSIZ, 1);
2591 signal (SIGINT, ofunc);
2593 /* This is a hook for when we need to do something (perhaps the
2594 collection of trace data) every time the target stops. */
2595 if (target_wait_loop_hook)
2596 (*target_wait_loop_hook) ();
2600 case 'E': /* Error of some sort */
2601 warning ("Remote failure reply: %s", buf);
2603 case 'T': /* Status with PC, SP, FP, ... */
2607 char regs[MAX_REGISTER_RAW_SIZE];
2609 /* Expedited reply, containing Signal, {regno, reg} repeat */
2610 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2612 n... = register number
2613 r... = register contents
2615 p = &buf[3]; /* after Txx */
2622 /* Read the register number */
2623 regno = strtol ((const char *) p, &p_temp, 16);
2624 p1 = (unsigned char *) p_temp;
2626 if (p1 == p) /* No register number present here */
2628 p1 = (unsigned char *) strchr ((const char *) p, ':');
2630 warning ("Malformed packet(a) (missing colon): %s\n\
2633 if (strncmp ((const char *) p, "thread", p1 - p) == 0)
2635 p_temp = unpack_varlen_hex (++p1, &thread_num);
2636 record_currthread (thread_num);
2637 p = (unsigned char *) p_temp;
2645 warning ("Malformed packet(b) (missing colon): %s\n\
2649 if (regno >= NUM_REGS)
2650 warning ("Remote sent bad register number %ld: %s\n\
2654 for (i = 0; i < REGISTER_RAW_SIZE (regno); i++)
2656 if (p[0] == 0 || p[1] == 0)
2657 warning ("Remote reply is too short: %s", buf);
2658 regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
2661 supply_register (regno, regs);
2666 warning ("Remote register badly formatted: %s", buf);
2667 warning (" here: %s", p);
2672 case 'S': /* Old style status, just signal only */
2673 status->kind = TARGET_WAITKIND_STOPPED;
2674 status->value.sig = (enum target_signal)
2675 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2679 /* Export Cisco kernel mode as a convenience variable
2680 (so that it can be used in the GDB prompt if desired). */
2682 if (cisco_kernel_mode == 1)
2683 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2684 value_from_string ("PDEBUG-"));
2685 cisco_kernel_mode = 0;
2686 thread_num = strtol ((const char *) &buf[4], NULL, 16);
2687 record_currthread (thread_num);
2689 else if (buf[3] == 'k')
2691 /* Export Cisco kernel mode as a convenience variable
2692 (so that it can be used in the GDB prompt if desired). */
2694 if (cisco_kernel_mode == 1)
2695 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2696 value_from_string ("KDEBUG-"));
2697 cisco_kernel_mode = 1;
2700 case 'N': /* Cisco special: status and offsets */
2702 bfd_vma text_addr, data_addr, bss_addr;
2703 bfd_signed_vma text_off, data_off, bss_off;
2706 status->kind = TARGET_WAITKIND_STOPPED;
2707 status->value.sig = (enum target_signal)
2708 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2710 if (symfile_objfile == NULL)
2712 warning ("Relocation packet received with no symbol file. \
2717 /* Relocate object file. Buffer format is NAATT;DD;BB
2718 * where AA is the signal number, TT is the new text
2719 * address, DD * is the new data address, and BB is the
2720 * new bss address. */
2723 text_addr = strtoul (p, (char **) &p1, 16);
2724 if (p1 == p || *p1 != ';')
2725 warning ("Malformed relocation packet: Packet '%s'", buf);
2727 data_addr = strtoul (p, (char **) &p1, 16);
2728 if (p1 == p || *p1 != ';')
2729 warning ("Malformed relocation packet: Packet '%s'", buf);
2731 bss_addr = strtoul (p, (char **) &p1, 16);
2733 warning ("Malformed relocation packet: Packet '%s'", buf);
2735 if (remote_cisco_section_offsets (text_addr, data_addr, bss_addr,
2736 &text_off, &data_off, &bss_off)
2738 if (text_off != 0 || data_off != 0 || bss_off != 0)
2739 remote_cisco_objfile_relocate (text_off, data_off, bss_off);
2743 case 'W': /* Target exited */
2745 /* The remote process exited. */
2746 status->kind = TARGET_WAITKIND_EXITED;
2747 status->value.integer = (fromhex (buf[1]) << 4) + fromhex (buf[2]);
2751 status->kind = TARGET_WAITKIND_SIGNALLED;
2752 status->value.sig = (enum target_signal)
2753 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2757 case 'O': /* Console output */
2758 remote_console_output (buf + 1);
2761 if (last_sent_signal != TARGET_SIGNAL_0)
2763 /* Zero length reply means that we tried 'S' or 'C' and
2764 the remote system doesn't support it. */
2765 target_terminal_ours_for_output ();
2767 ("Can't send signals to this remote system. %s not sent.\n",
2768 target_signal_to_name (last_sent_signal));
2769 last_sent_signal = TARGET_SIGNAL_0;
2770 target_terminal_inferior ();
2772 strcpy ((char *) buf, last_sent_step ? "s" : "c");
2773 putpkt ((char *) buf);
2776 /* else fallthrough */
2778 warning ("Invalid remote reply: %s", buf);
2783 if (thread_num != -1)
2787 return inferior_pid;
2790 /* Async version of remote_wait. */
2792 remote_async_wait (int pid, struct target_waitstatus *status)
2794 unsigned char *buf = alloca (PBUFSIZ);
2795 int thread_num = -1;
2797 status->kind = TARGET_WAITKIND_EXITED;
2798 status->value.integer = 0;
2804 if (!target_is_async_p ())
2805 ofunc = signal (SIGINT, remote_interrupt);
2806 /* FIXME: cagney/1999-09-27: If we're in async mode we should
2807 _never_ wait for ever -> test on target_is_async_p().
2808 However, before we do that we need to ensure that the caller
2809 knows how to take the target into/out of async mode. */
2810 getpkt (buf, PBUFSIZ, wait_forever_enabled_p);
2811 if (!target_is_async_p ())
2812 signal (SIGINT, ofunc);
2814 /* This is a hook for when we need to do something (perhaps the
2815 collection of trace data) every time the target stops. */
2816 if (target_wait_loop_hook)
2817 (*target_wait_loop_hook) ();
2821 case 'E': /* Error of some sort */
2822 warning ("Remote failure reply: %s", buf);
2824 case 'T': /* Status with PC, SP, FP, ... */
2828 char regs[MAX_REGISTER_RAW_SIZE];
2830 /* Expedited reply, containing Signal, {regno, reg} repeat */
2831 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
2833 n... = register number
2834 r... = register contents
2836 p = &buf[3]; /* after Txx */
2843 /* Read the register number */
2844 regno = strtol ((const char *) p, &p_temp, 16);
2845 p1 = (unsigned char *) p_temp;
2847 if (p1 == p) /* No register number present here */
2849 p1 = (unsigned char *) strchr ((const char *) p, ':');
2851 warning ("Malformed packet(a) (missing colon): %s\n\
2854 if (strncmp ((const char *) p, "thread", p1 - p) == 0)
2856 p_temp = unpack_varlen_hex (++p1, &thread_num);
2857 record_currthread (thread_num);
2858 p = (unsigned char *) p_temp;
2866 warning ("Malformed packet(b) (missing colon): %s\n\
2870 if (regno >= NUM_REGS)
2871 warning ("Remote sent bad register number %ld: %s\n\
2875 for (i = 0; i < REGISTER_RAW_SIZE (regno); i++)
2877 if (p[0] == 0 || p[1] == 0)
2878 warning ("Remote reply is too short: %s", buf);
2879 regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
2882 supply_register (regno, regs);
2887 warning ("Remote register badly formatted: %s", buf);
2888 warning (" here: %s", p);
2893 case 'S': /* Old style status, just signal only */
2894 status->kind = TARGET_WAITKIND_STOPPED;
2895 status->value.sig = (enum target_signal)
2896 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2900 /* Export Cisco kernel mode as a convenience variable
2901 (so that it can be used in the GDB prompt if desired). */
2903 if (cisco_kernel_mode == 1)
2904 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2905 value_from_string ("PDEBUG-"));
2906 cisco_kernel_mode = 0;
2907 thread_num = strtol ((const char *) &buf[4], NULL, 16);
2908 record_currthread (thread_num);
2910 else if (buf[3] == 'k')
2912 /* Export Cisco kernel mode as a convenience variable
2913 (so that it can be used in the GDB prompt if desired). */
2915 if (cisco_kernel_mode == 1)
2916 set_internalvar (lookup_internalvar ("cisco_kernel_mode"),
2917 value_from_string ("KDEBUG-"));
2918 cisco_kernel_mode = 1;
2921 case 'N': /* Cisco special: status and offsets */
2923 bfd_vma text_addr, data_addr, bss_addr;
2924 bfd_signed_vma text_off, data_off, bss_off;
2927 status->kind = TARGET_WAITKIND_STOPPED;
2928 status->value.sig = (enum target_signal)
2929 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2931 if (symfile_objfile == NULL)
2933 warning ("Relocation packet recieved with no symbol file. \
2938 /* Relocate object file. Buffer format is NAATT;DD;BB
2939 * where AA is the signal number, TT is the new text
2940 * address, DD * is the new data address, and BB is the
2941 * new bss address. */
2944 text_addr = strtoul (p, (char **) &p1, 16);
2945 if (p1 == p || *p1 != ';')
2946 warning ("Malformed relocation packet: Packet '%s'", buf);
2948 data_addr = strtoul (p, (char **) &p1, 16);
2949 if (p1 == p || *p1 != ';')
2950 warning ("Malformed relocation packet: Packet '%s'", buf);
2952 bss_addr = strtoul (p, (char **) &p1, 16);
2954 warning ("Malformed relocation packet: Packet '%s'", buf);
2956 if (remote_cisco_section_offsets (text_addr, data_addr, bss_addr,
2957 &text_off, &data_off, &bss_off)
2959 if (text_off != 0 || data_off != 0 || bss_off != 0)
2960 remote_cisco_objfile_relocate (text_off, data_off, bss_off);
2964 case 'W': /* Target exited */
2966 /* The remote process exited. */
2967 status->kind = TARGET_WAITKIND_EXITED;
2968 status->value.integer = (fromhex (buf[1]) << 4) + fromhex (buf[2]);
2972 status->kind = TARGET_WAITKIND_SIGNALLED;
2973 status->value.sig = (enum target_signal)
2974 (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
2978 case 'O': /* Console output */
2979 remote_console_output (buf + 1);
2980 /* Return immediately to the event loop. The event loop will
2981 still be waiting on the inferior afterwards. */
2982 status->kind = TARGET_WAITKIND_IGNORE;
2985 if (last_sent_signal != TARGET_SIGNAL_0)
2987 /* Zero length reply means that we tried 'S' or 'C' and
2988 the remote system doesn't support it. */
2989 target_terminal_ours_for_output ();
2991 ("Can't send signals to this remote system. %s not sent.\n",
2992 target_signal_to_name (last_sent_signal));
2993 last_sent_signal = TARGET_SIGNAL_0;
2994 target_terminal_inferior ();
2996 strcpy ((char *) buf, last_sent_step ? "s" : "c");
2997 putpkt ((char *) buf);
3000 /* else fallthrough */
3002 warning ("Invalid remote reply: %s", buf);
3007 if (thread_num != -1)
3011 return inferior_pid;
3014 /* Number of bytes of registers this stub implements. */
3016 static int register_bytes_found;
3018 /* Read the remote registers into the block REGS. */
3019 /* Currently we just read all the registers, so we don't use regno. */
3023 remote_fetch_registers (int regno)
3025 char *buf = alloca (PBUFSIZ);
3028 char *regs = alloca (REGISTER_BYTES);
3030 set_thread (inferior_pid, 1);
3033 remote_send (buf, PBUFSIZ);
3035 /* Save the size of the packet sent to us by the target. Its used
3036 as a heuristic when determining the max size of packets that the
3037 target can safely receive. */
3038 if (actual_register_packet_size == 0)
3039 actual_register_packet_size = strlen (buf);
3041 /* Unimplemented registers read as all bits zero. */
3042 memset (regs, 0, REGISTER_BYTES);
3044 /* We can get out of synch in various cases. If the first character
3045 in the buffer is not a hex character, assume that has happened
3046 and try to fetch another packet to read. */
3047 while ((buf[0] < '0' || buf[0] > '9')
3048 && (buf[0] < 'a' || buf[0] > 'f')
3049 && buf[0] != 'x') /* New: unavailable register value */
3052 fprintf_unfiltered (gdb_stdlog,
3053 "Bad register packet; fetching a new packet\n");
3054 getpkt (buf, PBUFSIZ, 0);
3057 /* Reply describes registers byte by byte, each byte encoded as two
3058 hex characters. Suck them all up, then supply them to the
3059 register cacheing/storage mechanism. */
3062 for (i = 0; i < REGISTER_BYTES; i++)
3068 warning ("Remote reply is of odd length: %s", buf);
3069 /* Don't change register_bytes_found in this case, and don't
3070 print a second warning. */
3073 if (p[0] == 'x' && p[1] == 'x')
3074 regs[i] = 0; /* 'x' */
3076 regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
3080 if (i != register_bytes_found)
3082 register_bytes_found = i;
3083 if (REGISTER_BYTES_OK_P ()
3084 && !REGISTER_BYTES_OK (i))
3085 warning ("Remote reply is too short: %s", buf);
3089 for (i = 0; i < NUM_REGS; i++)
3091 supply_register (i, ®s[REGISTER_BYTE (i)]);
3092 if (buf[REGISTER_BYTE (i) * 2] == 'x')
3093 set_register_cached (i, -1);
3097 /* Prepare to store registers. Since we may send them all (using a
3098 'G' request), we have to read out the ones we don't want to change
3102 remote_prepare_to_store (void)
3104 /* Make sure the entire registers array is valid. */
3105 switch (remote_protocol_P.support)
3107 case PACKET_DISABLE:
3108 case PACKET_SUPPORT_UNKNOWN:
3109 read_register_bytes (0, (char *) NULL, REGISTER_BYTES);
3116 /* Helper: Attempt to store REGNO using the P packet. Return fail IFF
3117 packet was not recognized. */
3120 store_register_using_P (int regno)
3122 /* Try storing a single register. */
3123 char *buf = alloca (PBUFSIZ);
3128 sprintf (buf, "P%x=", regno);
3129 p = buf + strlen (buf);
3130 regp = register_buffer (regno);
3131 for (i = 0; i < REGISTER_RAW_SIZE (regno); ++i)
3133 *p++ = tohex ((regp[i] >> 4) & 0xf);
3134 *p++ = tohex (regp[i] & 0xf);
3137 remote_send (buf, PBUFSIZ);
3139 return buf[0] != '\0';
3143 /* Store register REGNO, or all registers if REGNO == -1, from the contents
3144 of the register cache buffer. FIXME: ignores errors. */
3147 remote_store_registers (int regno)
3149 char *buf = alloca (PBUFSIZ);
3154 set_thread (inferior_pid, 1);
3158 switch (remote_protocol_P.support)
3160 case PACKET_DISABLE:
3163 if (store_register_using_P (regno))
3166 error ("Protocol error: P packet not recognized by stub");
3167 case PACKET_SUPPORT_UNKNOWN:
3168 if (store_register_using_P (regno))
3170 /* The stub recognized the 'P' packet. Remember this. */
3171 remote_protocol_P.support = PACKET_ENABLE;
3176 /* The stub does not support the 'P' packet. Use 'G'
3177 instead, and don't try using 'P' in the future (it
3178 will just waste our time). */
3179 remote_protocol_P.support = PACKET_DISABLE;
3187 /* Command describes registers byte by byte,
3188 each byte encoded as two hex characters. */
3190 regs = register_buffer (-1);
3192 /* remote_prepare_to_store insures that register_bytes_found gets set. */
3193 for (i = 0; i < register_bytes_found; i++)
3195 *p++ = tohex ((regs[i] >> 4) & 0xf);
3196 *p++ = tohex (regs[i] & 0xf);
3200 remote_send (buf, PBUFSIZ);
3204 /* Return the number of hex digits in num. */
3207 hexnumlen (ULONGEST num)
3211 for (i = 0; num != 0; i++)
3217 /* Set BUF to the minimum number of hex digits representing NUM. */
3220 hexnumstr (char *buf, ULONGEST num)
3222 int len = hexnumlen (num);
3223 return hexnumnstr (buf, num, len);
3227 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
3230 hexnumnstr (char *buf, ULONGEST num, int width)
3236 for (i = width - 1; i >= 0; i--)
3238 buf[i] = "0123456789abcdef"[(num & 0xf)];
3245 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
3248 remote_address_masked (CORE_ADDR addr)
3250 if (remote_address_size > 0
3251 && remote_address_size < (sizeof (ULONGEST) * 8))
3253 /* Only create a mask when that mask can safely be constructed
3254 in a ULONGEST variable. */
3256 mask = (mask << remote_address_size) - 1;
3262 /* Determine whether the remote target supports binary downloading.
3263 This is accomplished by sending a no-op memory write of zero length
3264 to the target at the specified address. It does not suffice to send
3265 the whole packet, since many stubs strip the eighth bit and subsequently
3266 compute a wrong checksum, which causes real havoc with remote_write_bytes.
3268 NOTE: This can still lose if the serial line is not eight-bit
3269 clean. In cases like this, the user should clear "remote
3273 check_binary_download (CORE_ADDR addr)
3275 switch (remote_protocol_binary_download.support)
3277 case PACKET_DISABLE:
3281 case PACKET_SUPPORT_UNKNOWN:
3283 char *buf = alloca (PBUFSIZ);
3288 p += hexnumstr (p, (ULONGEST) addr);
3290 p += hexnumstr (p, (ULONGEST) 0);
3294 putpkt_binary (buf, (int) (p - buf));
3295 getpkt (buf, PBUFSIZ, 0);
3300 fprintf_unfiltered (gdb_stdlog,
3301 "binary downloading NOT suppported by target\n");
3302 remote_protocol_binary_download.support = PACKET_DISABLE;
3307 fprintf_unfiltered (gdb_stdlog,
3308 "binary downloading suppported by target\n");
3309 remote_protocol_binary_download.support = PACKET_ENABLE;
3316 /* Write memory data directly to the remote machine.
3317 This does not inform the data cache; the data cache uses this.
3318 MEMADDR is the address in the remote memory space.
3319 MYADDR is the address of the buffer in our space.
3320 LEN is the number of bytes.
3322 Returns number of bytes transferred, or 0 (setting errno) for
3323 error. Only transfer a single packet. */
3326 remote_write_bytes (CORE_ADDR memaddr, char *myaddr, int len)
3329 int max_buf_size; /* Max size of packet output buffer */
3331 unsigned char *plen;
3337 /* Verify that the target can support a binary download */
3338 check_binary_download (memaddr);
3340 /* Determine the max packet size. */
3341 max_buf_size = get_memory_write_packet_size ();
3342 sizeof_buf = max_buf_size + 1; /* Space for trailing NUL */
3343 buf = alloca (sizeof_buf);
3345 /* Subtract header overhead from max payload size - $M<memaddr>,<len>:#nn */
3346 max_buf_size -= 2 + hexnumlen (memaddr + len - 1) + 1 + hexnumlen (len) + 4;
3348 /* construct "M"<memaddr>","<len>":" */
3349 /* sprintf (buf, "M%lx,%x:", (unsigned long) memaddr, todo); */
3352 /* Append [XM]. Compute a best guess of the number of bytes
3353 actually transfered. */
3354 switch (remote_protocol_binary_download.support)
3358 /* Best guess at number of bytes that will fit. */
3359 todo = min (len, max_buf_size);
3361 case PACKET_DISABLE:
3363 /* num bytes that will fit */
3364 todo = min (len, max_buf_size / 2);
3366 case PACKET_SUPPORT_UNKNOWN:
3367 internal_error ("%s:%d: remote_write_bytes: bad internal state",
3368 __FILE__, __LINE__);
3370 internal_error ("%s:%d: bad switch", __FILE__, __LINE__);
3373 /* Append <memaddr> */
3374 memaddr = remote_address_masked (memaddr);
3375 p += hexnumstr (p, (ULONGEST) memaddr);
3378 /* Append <len>. Retain the location/size of <len>. It may
3379 need to be adjusted once the packet body has been created. */
3381 plenlen = hexnumstr (p, (ULONGEST) todo);
3386 /* Append the packet body. */
3387 switch (remote_protocol_binary_download.support)
3390 /* Binary mode. Send target system values byte by byte, in
3391 increasing byte addresses. Only escape certain critical
3394 (nr_bytes < todo) && (p - buf) < (max_buf_size - 2);
3397 switch (myaddr[nr_bytes] & 0xff)
3402 /* These must be escaped */
3404 *p++ = (myaddr[nr_bytes] & 0xff) ^ 0x20;
3407 *p++ = myaddr[nr_bytes] & 0xff;
3411 if (nr_bytes < todo)
3413 /* Escape chars have filled up the buffer prematurely,
3414 and we have actually sent fewer bytes than planned.
3415 Fix-up the length field of the packet. Use the same
3416 number of characters as before. */
3418 plen += hexnumnstr (plen, (ULONGEST) nr_bytes, plenlen);
3419 *plen = ':'; /* overwrite \0 from hexnumnstr() */
3422 case PACKET_DISABLE:
3423 /* Normal mode: Send target system values byte by byte, in
3424 increasing byte addresses. Each byte is encoded as a two hex
3426 for (nr_bytes = 0; nr_bytes < todo; nr_bytes++)
3428 *p++ = tohex ((myaddr[nr_bytes] >> 4) & 0xf);
3429 *p++ = tohex (myaddr[nr_bytes] & 0xf);
3433 case PACKET_SUPPORT_UNKNOWN:
3434 internal_error ("%s:%d: remote_write_bytes: bad internal state",
3435 __FILE__, __LINE__);
3437 internal_error ("%s:%d: bad switch", __FILE__, __LINE__);
3440 putpkt_binary (buf, (int) (p - buf));
3441 getpkt (buf, sizeof_buf, 0);
3445 /* There is no correspondance between what the remote protocol
3446 uses for errors and errno codes. We would like a cleaner way
3447 of representing errors (big enough to include errno codes,
3448 bfd_error codes, and others). But for now just return EIO. */
3453 /* Return NR_BYTES, not TODO, in case escape chars caused us to send fewer
3454 bytes than we'd planned. */
3458 /* Read memory data directly from the remote machine.
3459 This does not use the data cache; the data cache uses this.
3460 MEMADDR is the address in the remote memory space.
3461 MYADDR is the address of the buffer in our space.
3462 LEN is the number of bytes.
3464 Returns number of bytes transferred, or 0 for error. */
3466 /* NOTE: cagney/1999-10-18: This function (and its siblings in other
3467 remote targets) shouldn't attempt to read the entire buffer.
3468 Instead it should read a single packet worth of data and then
3469 return the byte size of that packet to the caller. The caller (its
3470 caller and its callers caller ;-) already contains code for
3471 handling partial reads. */
3474 remote_read_bytes (CORE_ADDR memaddr, char *myaddr, int len)
3477 int max_buf_size; /* Max size of packet output buffer */
3481 /* Create a buffer big enough for this packet. */
3482 max_buf_size = get_memory_read_packet_size ();
3483 sizeof_buf = max_buf_size + 1; /* Space for trailing NUL */
3484 buf = alloca (sizeof_buf);
3493 todo = min (len, max_buf_size / 2); /* num bytes that will fit */
3495 /* construct "m"<memaddr>","<len>" */
3496 /* sprintf (buf, "m%lx,%x", (unsigned long) memaddr, todo); */
3497 memaddr = remote_address_masked (memaddr);
3500 p += hexnumstr (p, (ULONGEST) memaddr);
3502 p += hexnumstr (p, (ULONGEST) todo);
3506 getpkt (buf, sizeof_buf, 0);
3510 /* There is no correspondance between what the remote protocol uses
3511 for errors and errno codes. We would like a cleaner way of
3512 representing errors (big enough to include errno codes, bfd_error
3513 codes, and others). But for now just return EIO. */
3518 /* Reply describes memory byte by byte,
3519 each byte encoded as two hex characters. */
3522 for (i = 0; i < todo; i++)
3524 if (p[0] == 0 || p[1] == 0)
3525 /* Reply is short. This means that we were able to read
3526 only part of what we wanted to. */
3527 return i + (origlen - len);
3528 myaddr[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
3538 /* Read or write LEN bytes from inferior memory at MEMADDR,
3539 transferring to or from debugger address BUFFER. Write to inferior if
3540 SHOULD_WRITE is nonzero. Returns length of data written or read; 0
3541 for error. TARGET is unused. */
3545 remote_xfer_memory (CORE_ADDR mem_addr, char *buffer, int mem_len,
3547 struct mem_attrib *attrib ATTRIBUTE_UNUSED,
3548 struct target_ops *target)
3550 CORE_ADDR targ_addr;
3554 REMOTE_TRANSLATE_XFER_ADDRESS (mem_addr, mem_len, &targ_addr, &targ_len);
3559 res = remote_write_bytes (targ_addr, buffer, targ_len);
3561 res = remote_read_bytes (targ_addr, buffer, targ_len);
3568 /* Enable after 4.12. */
3571 remote_search (int len, char *data, char *mask, CORE_ADDR startaddr,
3572 int increment, CORE_ADDR lorange, CORE_ADDR hirange,
3573 CORE_ADDR *addr_found, char *data_found)
3575 if (increment == -4 && len == 4)
3577 long mask_long, data_long;
3578 long data_found_long;
3579 CORE_ADDR addr_we_found;
3580 char *buf = alloca (PBUFSIZ);
3581 long returned_long[2];
3584 mask_long = extract_unsigned_integer (mask, len);
3585 data_long = extract_unsigned_integer (data, len);
3586 sprintf (buf, "t%x:%x,%x", startaddr, data_long, mask_long);
3588 getpkt (buf, PBUFSIZ, 0);
3591 /* The stub doesn't support the 't' request. We might want to
3592 remember this fact, but on the other hand the stub could be
3593 switched on us. Maybe we should remember it only until
3594 the next "target remote". */
3595 generic_search (len, data, mask, startaddr, increment, lorange,
3596 hirange, addr_found, data_found);
3601 /* There is no correspondance between what the remote protocol uses
3602 for errors and errno codes. We would like a cleaner way of
3603 representing errors (big enough to include errno codes, bfd_error
3604 codes, and others). But for now just use EIO. */
3605 memory_error (EIO, startaddr);
3608 while (*p != '\0' && *p != ',')
3609 addr_we_found = (addr_we_found << 4) + fromhex (*p++);
3611 error ("Protocol error: short return for search");
3613 data_found_long = 0;
3614 while (*p != '\0' && *p != ',')
3615 data_found_long = (data_found_long << 4) + fromhex (*p++);
3616 /* Ignore anything after this comma, for future extensions. */
3618 if (addr_we_found < lorange || addr_we_found >= hirange)
3624 *addr_found = addr_we_found;
3625 *data_found = store_unsigned_integer (data_we_found, len);
3628 generic_search (len, data, mask, startaddr, increment, lorange,
3629 hirange, addr_found, data_found);
3634 remote_files_info (struct target_ops *ignore)
3636 puts_filtered ("Debugging a target over a serial line.\n");
3639 /* Stuff for dealing with the packets which are part of this protocol.
3640 See comment at top of file for details. */
3642 /* Read a single character from the remote end, masking it down to 7 bits. */
3645 readchar (int timeout)
3649 ch = SERIAL_READCHAR (remote_desc, timeout);
3654 switch ((enum serial_rc) ch)
3657 target_mourn_inferior ();
3658 error ("Remote connection closed");
3661 perror_with_name ("Remote communication error");
3663 case SERIAL_TIMEOUT:
3669 /* Send the command in BUF to the remote machine, and read the reply
3670 into BUF. Report an error if we get an error reply. */
3673 remote_send (char *buf,
3677 getpkt (buf, sizeof_buf, 0);
3680 error ("Remote failure reply: %s", buf);
3683 /* Display a null-terminated packet on stdout, for debugging, using C
3687 print_packet (char *buf)
3689 puts_filtered ("\"");
3690 fputstr_filtered (buf, '"', gdb_stdout);
3691 puts_filtered ("\"");
3697 return putpkt_binary (buf, strlen (buf));
3700 /* Send a packet to the remote machine, with error checking. The data
3701 of the packet is in BUF. The string in BUF can be at most PBUFSIZ - 5
3702 to account for the $, # and checksum, and for a possible /0 if we are
3703 debugging (remote_debug) and want to print the sent packet as a string */
3706 putpkt_binary (char *buf, int cnt)
3709 unsigned char csum = 0;
3710 char *buf2 = alloca (cnt + 6);
3711 long sizeof_junkbuf = PBUFSIZ;
3712 char *junkbuf = alloca (sizeof_junkbuf);
3718 /* Copy the packet into buffer BUF2, encapsulating it
3719 and giving it a checksum. */
3724 for (i = 0; i < cnt; i++)
3730 *p++ = tohex ((csum >> 4) & 0xf);
3731 *p++ = tohex (csum & 0xf);
3733 /* Send it over and over until we get a positive ack. */
3737 int started_error_output = 0;
3742 fprintf_unfiltered (gdb_stdlog, "Sending packet: ");
3743 fputstrn_unfiltered (buf2, p - buf2, 0, gdb_stdlog);
3744 fprintf_unfiltered (gdb_stdlog, "...");
3745 gdb_flush (gdb_stdlog);
3747 if (SERIAL_WRITE (remote_desc, buf2, p - buf2))
3748 perror_with_name ("putpkt: write failed");
3750 /* read until either a timeout occurs (-2) or '+' is read */
3753 ch = readchar (remote_timeout);
3761 case SERIAL_TIMEOUT:
3763 if (started_error_output)
3765 putchar_unfiltered ('\n');
3766 started_error_output = 0;
3775 fprintf_unfiltered (gdb_stdlog, "Ack\n");
3779 fprintf_unfiltered (gdb_stdlog, "Nak\n");
3780 case SERIAL_TIMEOUT:
3784 break; /* Retransmit buffer */
3788 fprintf_unfiltered (gdb_stdlog, "Packet instead of Ack, ignoring it\n");
3789 /* It's probably an old response, and we're out of sync.
3790 Just gobble up the packet and ignore it. */
3791 read_frame (junkbuf, sizeof_junkbuf);
3792 continue; /* Now, go look for + */
3797 if (!started_error_output)
3799 started_error_output = 1;
3800 fprintf_unfiltered (gdb_stdlog, "putpkt: Junk: ");
3802 fputc_unfiltered (ch & 0177, gdb_stdlog);
3806 break; /* Here to retransmit */
3810 /* This is wrong. If doing a long backtrace, the user should be
3811 able to get out next time we call QUIT, without anything as
3812 violent as interrupt_query. If we want to provide a way out of
3813 here without getting to the next QUIT, it should be based on
3814 hitting ^C twice as in remote_wait. */
3824 static int remote_cisco_mode;
3826 /* Come here after finding the start of the frame. Collect the rest
3827 into BUF, verifying the checksum, length, and handling run-length
3828 compression. No more than sizeof_buf-1 characters are read so that
3829 the buffer can be NUL terminated.
3831 Returns -1 on error, number of characters in buffer (ignoring the
3832 trailing NULL) on success. (could be extended to return one of the
3833 SERIAL status indications). */
3836 read_frame (char *buf,
3848 /* ASSERT (bc < sizeof_buf - 1) - space for trailing NUL */
3849 c = readchar (remote_timeout);
3852 case SERIAL_TIMEOUT:
3854 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog);
3858 fputs_filtered ("Saw new packet start in middle of old one\n",
3860 return -1; /* Start a new packet, count retries */
3863 unsigned char pktcsum;
3869 check_0 = readchar (remote_timeout);
3871 check_1 = readchar (remote_timeout);
3873 if (check_0 == SERIAL_TIMEOUT || check_1 == SERIAL_TIMEOUT)
3876 fputs_filtered ("Timeout in checksum, retrying\n", gdb_stdlog);
3879 else if (check_0 < 0 || check_1 < 0)
3882 fputs_filtered ("Communication error in checksum\n", gdb_stdlog);
3886 pktcsum = (fromhex (check_0) << 4) | fromhex (check_1);
3887 if (csum == pktcsum)
3892 fprintf_filtered (gdb_stdlog,
3893 "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
3895 fputs_filtered (buf, gdb_stdlog);
3896 fputs_filtered ("\n", gdb_stdlog);
3898 /* Number of characters in buffer ignoring trailing
3902 case '*': /* Run length encoding */
3907 if (remote_cisco_mode == 0)
3909 c = readchar (remote_timeout);
3911 repeat = c - ' ' + 3; /* Compute repeat count */
3915 /* Cisco's run-length encoding variant uses two
3916 hex chars to represent the repeat count. */
3918 c = readchar (remote_timeout);
3920 repeat = fromhex (c) << 4;
3921 c = readchar (remote_timeout);
3923 repeat += fromhex (c);
3926 /* The character before ``*'' is repeated. */
3928 if (repeat > 0 && repeat <= 255
3930 && bc + repeat < sizeof_buf - 1)
3932 memset (&buf[bc], buf[bc - 1], repeat);
3938 printf_filtered ("Repeat count %d too large for buffer: ", repeat);
3939 puts_filtered (buf);
3940 puts_filtered ("\n");
3944 if (bc < sizeof_buf - 1)
3952 puts_filtered ("Remote packet too long: ");
3953 puts_filtered (buf);
3954 puts_filtered ("\n");
3961 /* Read a packet from the remote machine, with error checking, and
3962 store it in BUF. If FOREVER, wait forever rather than timing out;
3963 this is used (in synchronous mode) to wait for a target that is is
3964 executing user code to stop. */
3965 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
3966 don't have to change all the calls to getpkt to deal with the
3967 return value, because at the moment I don't know what the right
3968 thing to do it for those. */
3976 timed_out = getpkt_sane (buf, sizeof_buf, forever);
3980 /* Read a packet from the remote machine, with error checking, and
3981 store it in BUF. If FOREVER, wait forever rather than timing out;
3982 this is used (in synchronous mode) to wait for a target that is is
3983 executing user code to stop. If FOREVER == 0, this function is
3984 allowed to time out gracefully and return an indication of this to
3987 getpkt_sane (char *buf,
3996 strcpy (buf, "timeout");
4000 timeout = watchdog > 0 ? watchdog : -1;
4004 timeout = remote_timeout;
4008 for (tries = 1; tries <= MAX_TRIES; tries++)
4010 /* This can loop forever if the remote side sends us characters
4011 continuously, but if it pauses, we'll get a zero from readchar
4012 because of timeout. Then we'll count that as a retry. */
4014 /* Note that we will only wait forever prior to the start of a packet.
4015 After that, we expect characters to arrive at a brisk pace. They
4016 should show up within remote_timeout intervals. */
4020 c = readchar (timeout);
4022 if (c == SERIAL_TIMEOUT)
4024 if (forever) /* Watchdog went off? Kill the target. */
4027 target_mourn_inferior ();
4028 error ("Watchdog has expired. Target detached.\n");
4031 fputs_filtered ("Timed out.\n", gdb_stdlog);
4037 /* We've found the start of a packet, now collect the data. */
4039 val = read_frame (buf, sizeof_buf);
4045 fprintf_unfiltered (gdb_stdlog, "Packet received: ");
4046 fputstr_unfiltered (buf, 0, gdb_stdlog);
4047 fprintf_unfiltered (gdb_stdlog, "\n");
4049 SERIAL_WRITE (remote_desc, "+", 1);
4053 /* Try the whole thing again. */
4055 SERIAL_WRITE (remote_desc, "-", 1);
4058 /* We have tried hard enough, and just can't receive the packet. Give up. */
4060 printf_unfiltered ("Ignoring packet error, continuing...\n");
4061 SERIAL_WRITE (remote_desc, "+", 1);
4068 /* For some mysterious reason, wait_for_inferior calls kill instead of
4069 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4073 target_mourn_inferior ();
4077 /* Use catch_errors so the user can quit from gdb even when we aren't on
4078 speaking terms with the remote system. */
4079 catch_errors ((catch_errors_ftype *) putpkt, "k", "", RETURN_MASK_ERROR);
4081 /* Don't wait for it to die. I'm not really sure it matters whether
4082 we do or not. For the existing stubs, kill is a noop. */
4083 target_mourn_inferior ();
4086 /* Async version of remote_kill. */
4088 remote_async_kill (void)
4090 /* Unregister the file descriptor from the event loop. */
4091 if (target_is_async_p ())
4092 SERIAL_ASYNC (remote_desc, NULL, 0);
4094 /* For some mysterious reason, wait_for_inferior calls kill instead of
4095 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
4099 target_mourn_inferior ();
4103 /* Use catch_errors so the user can quit from gdb even when we aren't on
4104 speaking terms with the remote system. */
4105 catch_errors ((catch_errors_ftype *) putpkt, "k", "", RETURN_MASK_ERROR);
4107 /* Don't wait for it to die. I'm not really sure it matters whether
4108 we do or not. For the existing stubs, kill is a noop. */
4109 target_mourn_inferior ();
4115 remote_mourn_1 (&remote_ops);
4119 remote_async_mourn (void)
4121 remote_mourn_1 (&remote_async_ops);
4125 extended_remote_mourn (void)
4127 /* We do _not_ want to mourn the target like this; this will
4128 remove the extended remote target from the target stack,
4129 and the next time the user says "run" it'll fail.
4131 FIXME: What is the right thing to do here? */
4133 remote_mourn_1 (&extended_remote_ops);
4137 /* Worker function for remote_mourn. */
4139 remote_mourn_1 (struct target_ops *target)
4141 unpush_target (target);
4142 generic_mourn_inferior ();
4145 /* In the extended protocol we want to be able to do things like
4146 "run" and have them basically work as expected. So we need
4147 a special create_inferior function.
4149 FIXME: One day add support for changing the exec file
4150 we're debugging, arguments and an environment. */
4153 extended_remote_create_inferior (char *exec_file, char *args, char **env)
4155 /* Rip out the breakpoints; we'll reinsert them after restarting
4156 the remote server. */
4157 remove_breakpoints ();
4159 /* Now restart the remote server. */
4160 extended_remote_restart ();
4162 /* Now put the breakpoints back in. This way we're safe if the
4163 restart function works via a unix fork on the remote side. */
4164 insert_breakpoints ();
4166 /* Clean up from the last time we were running. */
4167 clear_proceed_status ();
4169 /* Let the remote process run. */
4170 proceed (-1, TARGET_SIGNAL_0, 0);
4173 /* Async version of extended_remote_create_inferior. */
4175 extended_remote_async_create_inferior (char *exec_file, char *args, char **env)
4177 /* Rip out the breakpoints; we'll reinsert them after restarting
4178 the remote server. */
4179 remove_breakpoints ();
4181 /* If running asynchronously, register the target file descriptor
4182 with the event loop. */
4183 if (event_loop_p && target_can_async_p ())
4184 target_async (inferior_event_handler, 0);
4186 /* Now restart the remote server. */
4187 extended_remote_restart ();
4189 /* Now put the breakpoints back in. This way we're safe if the
4190 restart function works via a unix fork on the remote side. */
4191 insert_breakpoints ();
4193 /* Clean up from the last time we were running. */
4194 clear_proceed_status ();
4196 /* Let the remote process run. */
4197 proceed (-1, TARGET_SIGNAL_0, 0);
4201 /* On some machines, e.g. 68k, we may use a different breakpoint instruction
4202 than other targets; in those use REMOTE_BREAKPOINT instead of just
4203 BREAKPOINT. Also, bi-endian targets may define LITTLE_REMOTE_BREAKPOINT
4204 and BIG_REMOTE_BREAKPOINT. If none of these are defined, we just call
4205 the standard routines that are in mem-break.c. */
4207 /* FIXME, these ought to be done in a more dynamic fashion. For instance,
4208 the choice of breakpoint instruction affects target program design and
4209 vice versa, and by making it user-tweakable, the special code here
4210 goes away and we need fewer special GDB configurations. */
4212 #if defined (LITTLE_REMOTE_BREAKPOINT) && defined (BIG_REMOTE_BREAKPOINT) && !defined(REMOTE_BREAKPOINT)
4213 #define REMOTE_BREAKPOINT
4216 #ifdef REMOTE_BREAKPOINT
4218 /* If the target isn't bi-endian, just pretend it is. */
4219 #if !defined (LITTLE_REMOTE_BREAKPOINT) && !defined (BIG_REMOTE_BREAKPOINT)
4220 #define LITTLE_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4221 #define BIG_REMOTE_BREAKPOINT REMOTE_BREAKPOINT
4224 static unsigned char big_break_insn[] = BIG_REMOTE_BREAKPOINT;
4225 static unsigned char little_break_insn[] = LITTLE_REMOTE_BREAKPOINT;
4227 #endif /* REMOTE_BREAKPOINT */
4229 /* Insert a breakpoint on targets that don't have any better breakpoint
4230 support. We read the contents of the target location and stash it,
4231 then overwrite it with a breakpoint instruction. ADDR is the target
4232 location in the target machine. CONTENTS_CACHE is a pointer to
4233 memory allocated for saving the target contents. It is guaranteed
4234 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
4235 is accomplished via BREAKPOINT_MAX). */
4238 remote_insert_breakpoint (CORE_ADDR addr, char *contents_cache)
4240 #ifdef REMOTE_BREAKPOINT
4245 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
4246 If it succeeds, then set the support to PACKET_ENABLE. If it
4247 fails, and the user has explicitly requested the Z support then
4248 report an error, otherwise, mark it disabled and go on. */
4250 if (remote_protocol_Z[Z_PACKET_SOFTWARE_BP].support != PACKET_DISABLE)
4252 char *buf = alloca (PBUFSIZ);
4255 addr = remote_address_masked (addr);
4259 p += hexnumstr (p, (ULONGEST) addr);
4260 BREAKPOINT_FROM_PC (&addr, &bp_size);
4261 sprintf (p, ",%d", bp_size);
4264 getpkt (buf, PBUFSIZ, 0);
4266 switch (packet_ok (buf, &remote_protocol_Z[Z_PACKET_SOFTWARE_BP]))
4272 case PACKET_UNKNOWN:
4277 #ifdef REMOTE_BREAKPOINT
4278 val = target_read_memory (addr, contents_cache, sizeof big_break_insn);
4282 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
4283 val = target_write_memory (addr, (char *) big_break_insn,
4284 sizeof big_break_insn);
4286 val = target_write_memory (addr, (char *) little_break_insn,
4287 sizeof little_break_insn);
4292 return memory_insert_breakpoint (addr, contents_cache);
4293 #endif /* REMOTE_BREAKPOINT */
4297 remote_remove_breakpoint (CORE_ADDR addr, char *contents_cache)
4301 if (remote_protocol_Z[Z_PACKET_SOFTWARE_BP].support != PACKET_DISABLE)
4303 char *buf = alloca (PBUFSIZ);
4310 addr = remote_address_masked (addr);
4311 p += hexnumstr (p, (ULONGEST) addr);
4312 BREAKPOINT_FROM_PC (&addr, &bp_size);
4313 sprintf (p, ",%d", bp_size);
4316 getpkt (buf, PBUFSIZ, 0);
4318 return (buf[0] == 'E');
4321 #ifdef REMOTE_BREAKPOINT
4322 return target_write_memory (addr, contents_cache, sizeof big_break_insn);
4324 return memory_remove_breakpoint (addr, contents_cache);
4325 #endif /* REMOTE_BREAKPOINT */
4329 watchpoint_to_Z_packet (int type)
4343 internal_error ("hw_bp_to_z: bad watchpoint type %d", type);
4347 /* FIXME: This function should be static and a member of the remote
4351 remote_insert_watchpoint (CORE_ADDR addr, int len, int type)
4353 char *buf = alloca (PBUFSIZ);
4355 enum Z_packet_type packet = watchpoint_to_Z_packet (type);
4357 if (remote_protocol_Z[packet].support == PACKET_DISABLE)
4358 error ("Can't set hardware watchpoints without the '%s' (%s) packet\n",
4359 remote_protocol_Z[packet].name,
4360 remote_protocol_Z[packet].title);
4362 sprintf (buf, "Z%x,", packet);
4363 p = strchr (buf, '\0');
4364 addr = remote_address_masked (addr);
4365 p += hexnumstr (p, (ULONGEST) addr);
4366 sprintf (p, ",%x", len);
4369 getpkt (buf, PBUFSIZ, 0);
4371 switch (packet_ok (buf, &remote_protocol_Z[packet]))
4374 case PACKET_UNKNOWN:
4379 internal_error ("remote_insert_watchpoint: reached end of function");
4382 /* FIXME: This function should be static and a member of the remote
4386 remote_remove_watchpoint (CORE_ADDR addr, int len, int type)
4388 char *buf = alloca (PBUFSIZ);
4390 enum Z_packet_type packet = watchpoint_to_Z_packet (type);
4392 if (remote_protocol_Z[packet].support == PACKET_DISABLE)
4393 error ("Can't clear hardware watchpoints without the '%s' (%s) packet\n",
4394 remote_protocol_Z[packet].name,
4395 remote_protocol_Z[packet].title);
4397 sprintf (buf, "z%x,", packet);
4398 p = strchr (buf, '\0');
4399 addr = remote_address_masked (addr);
4400 p += hexnumstr (p, (ULONGEST) addr);
4401 sprintf (p, ",%x", len);
4403 getpkt (buf, PBUFSIZ, 0);
4405 switch (packet_ok (buf, &remote_protocol_Z[packet]))
4408 case PACKET_UNKNOWN:
4413 internal_error ("remote_remove_watchpoint: reached end of function");
4416 /* FIXME: This function should be static and a member of the remote
4420 remote_insert_hw_breakpoint (CORE_ADDR addr, int len)
4422 char *buf = alloca (PBUFSIZ);
4425 if (remote_protocol_Z[Z_PACKET_HARDWARE_BP].support == PACKET_DISABLE)
4426 error ("Can't set hardware breakpoint without the '%s' (%s) packet\n",
4427 remote_protocol_Z[Z_PACKET_HARDWARE_BP].name,
4428 remote_protocol_Z[Z_PACKET_HARDWARE_BP].title);
4434 addr = remote_address_masked (addr);
4435 p += hexnumstr (p, (ULONGEST) addr);
4436 sprintf (p, ",%x", len);
4439 getpkt (buf, PBUFSIZ, 0);
4441 switch (packet_ok (buf, &remote_protocol_Z[Z_PACKET_HARDWARE_BP]))
4444 case PACKET_UNKNOWN:
4449 internal_error ("remote_remove_watchpoint: reached end of function");
4452 /* FIXME: This function should be static and a member of the remote
4456 remote_remove_hw_breakpoint (CORE_ADDR addr, int len)
4458 char *buf = alloca (PBUFSIZ);
4461 if (remote_protocol_Z[Z_PACKET_HARDWARE_BP].support == PACKET_DISABLE)
4462 error ("Can't clear hardware breakpoint without the '%s' (%s) packet\n",
4463 remote_protocol_Z[Z_PACKET_HARDWARE_BP].name,
4464 remote_protocol_Z[Z_PACKET_HARDWARE_BP].title);
4470 addr = remote_address_masked (addr);
4471 p += hexnumstr (p, (ULONGEST) addr);
4472 sprintf (p, ",%x", len);
4475 getpkt (buf, PBUFSIZ, 0);
4477 switch (packet_ok (buf, &remote_protocol_Z[Z_PACKET_HARDWARE_BP]))
4480 case PACKET_UNKNOWN:
4485 internal_error ("remote_remove_watchpoint: reached end of function");
4488 /* Some targets are only capable of doing downloads, and afterwards
4489 they switch to the remote serial protocol. This function provides
4490 a clean way to get from the download target to the remote target.
4491 It's basically just a wrapper so that we don't have to expose any
4492 of the internal workings of remote.c.
4494 Prior to calling this routine, you should shutdown the current
4495 target code, else you will get the "A program is being debugged
4496 already..." message. Usually a call to pop_target() suffices. */
4499 push_remote_target (char *name, int from_tty)
4501 printf_filtered ("Switching to remote protocol\n");
4502 remote_open (name, from_tty);
4505 /* Other targets want to use the entire remote serial module but with
4506 certain remote_ops overridden. */
4509 open_remote_target (char *name, int from_tty, struct target_ops *target,
4512 printf_filtered ("Selecting the %sremote protocol\n",
4513 (extended_p ? "extended-" : ""));
4514 remote_open_1 (name, from_tty, target, extended_p);
4517 /* Table used by the crc32 function to calcuate the checksum. */
4519 static unsigned long crc32_table[256] =
4522 static unsigned long
4523 crc32 (unsigned char *buf, int len, unsigned int crc)
4525 if (!crc32_table[1])
4527 /* Initialize the CRC table and the decoding table. */
4531 for (i = 0; i < 256; i++)
4533 for (c = i << 24, j = 8; j > 0; --j)
4534 c = c & 0x80000000 ? (c << 1) ^ 0x04c11db7 : (c << 1);
4541 crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ *buf) & 255];
4547 /* compare-sections command
4549 With no arguments, compares each loadable section in the exec bfd
4550 with the same memory range on the target, and reports mismatches.
4551 Useful for verifying the image on the target against the exec file.
4552 Depends on the target understanding the new "qCRC:" request. */
4554 /* FIXME: cagney/1999-10-26: This command should be broken down into a
4555 target method (target verify memory) and generic version of the
4556 actual command. This will allow other high-level code (especially
4557 generic_load()) to make use of this target functionality. */
4560 compare_sections_command (char *args, int from_tty)
4563 unsigned long host_crc, target_crc;
4564 extern bfd *exec_bfd;
4565 struct cleanup *old_chain;
4569 char *buf = alloca (PBUFSIZ);
4576 error ("command cannot be used without an exec file");
4577 if (!current_target.to_shortname ||
4578 strcmp (current_target.to_shortname, "remote") != 0)
4579 error ("command can only be used with remote target");
4581 for (s = exec_bfd->sections; s; s = s->next)
4583 if (!(s->flags & SEC_LOAD))
4584 continue; /* skip non-loadable section */
4586 size = bfd_get_section_size_before_reloc (s);
4588 continue; /* skip zero-length section */
4590 sectname = (char *) bfd_get_section_name (exec_bfd, s);
4591 if (args && strcmp (args, sectname) != 0)
4592 continue; /* not the section selected by user */
4594 matched = 1; /* do this section */
4596 /* FIXME: assumes lma can fit into long */
4597 sprintf (buf, "qCRC:%lx,%lx", (long) lma, (long) size);
4600 /* be clever; compute the host_crc before waiting for target reply */
4601 sectdata = xmalloc (size);
4602 old_chain = make_cleanup (xfree, sectdata);
4603 bfd_get_section_contents (exec_bfd, s, sectdata, 0, size);
4604 host_crc = crc32 ((unsigned char *) sectdata, size, 0xffffffff);
4606 getpkt (buf, PBUFSIZ, 0);
4608 error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
4609 sectname, lma, lma + size);
4611 error ("remote target does not support this operation");
4613 for (target_crc = 0, tmp = &buf[1]; *tmp; tmp++)
4614 target_crc = target_crc * 16 + fromhex (*tmp);
4616 printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
4617 sectname, paddr (lma), paddr (lma + size));
4618 if (host_crc == target_crc)
4619 printf_filtered ("matched.\n");
4622 printf_filtered ("MIS-MATCHED!\n");
4626 do_cleanups (old_chain);
4629 warning ("One or more sections of the remote executable does not match\n\
4630 the loaded file\n");
4631 if (args && !matched)
4632 printf_filtered ("No loaded section named '%s'.\n", args);
4636 remote_query (int query_type, char *buf, char *outbuf, int *bufsiz)
4639 char *buf2 = alloca (PBUFSIZ);
4640 char *p2 = &buf2[0];
4643 error ("null pointer to remote bufer size specified");
4645 /* minimum outbuf size is PBUFSIZ - if bufsiz is not large enough let
4646 the caller know and return what the minimum size is */
4647 /* Note: a zero bufsiz can be used to query the minimum buffer size */
4648 if (*bufsiz < PBUFSIZ)
4654 /* except for querying the minimum buffer size, target must be open */
4656 error ("remote query is only available after target open");
4658 /* we only take uppercase letters as query types, at least for now */
4659 if ((query_type < 'A') || (query_type > 'Z'))
4660 error ("invalid remote query type");
4663 error ("null remote query specified");
4666 error ("remote query requires a buffer to receive data");
4673 /* we used one buffer char for the remote protocol q command and another
4674 for the query type. As the remote protocol encapsulation uses 4 chars
4675 plus one extra in case we are debugging (remote_debug),
4676 we have PBUFZIZ - 7 left to pack the query string */
4678 while (buf[i] && (i < (PBUFSIZ - 8)))
4680 /* bad caller may have sent forbidden characters */
4681 if ((!isprint (buf[i])) || (buf[i] == '$') || (buf[i] == '#'))
4682 error ("illegal characters in query string");
4690 error ("query larger than available buffer");
4696 getpkt (outbuf, *bufsiz, 0);
4702 remote_rcmd (char *command,
4703 struct ui_file *outbuf)
4706 char *buf = alloca (PBUFSIZ);
4710 error ("remote rcmd is only available after target open");
4712 /* Send a NULL command across as an empty command */
4713 if (command == NULL)
4716 /* The query prefix */
4717 strcpy (buf, "qRcmd,");
4718 p = strchr (buf, '\0');
4720 if ((strlen (buf) + strlen (command) * 2 + 8/*misc*/) > PBUFSIZ)
4721 error ("\"monitor\" command ``%s'' is too long\n", command);
4723 /* Encode the actual command */
4724 for (i = 0; command[i]; i++)
4726 *p++ = tohex ((command[i] >> 4) & 0xf);
4727 *p++ = tohex (command[i] & 0xf);
4731 if (putpkt (buf) < 0)
4732 error ("Communication problem with target\n");
4734 /* get/display the response */
4737 /* XXX - see also tracepoint.c:remote_get_noisy_reply() */
4739 getpkt (buf, PBUFSIZ, 0);
4741 error ("Target does not support this command\n");
4742 if (buf[0] == 'O' && buf[1] != 'K')
4744 remote_console_output (buf + 1); /* 'O' message from stub */
4747 if (strcmp (buf, "OK") == 0)
4749 if (strlen (buf) == 3 && buf[0] == 'E'
4750 && isdigit (buf[1]) && isdigit (buf[2]))
4752 error ("Protocol error with Rcmd");
4754 for (p = buf; p[0] != '\0' && p[1] != '\0'; p += 2)
4756 char c = (fromhex (p[0]) << 4) + fromhex (p[1]);
4757 fputc_unfiltered (c, outbuf);
4764 packet_command (char *args, int from_tty)
4766 char *buf = alloca (PBUFSIZ);
4769 error ("command can only be used with remote target");
4772 error ("remote-packet command requires packet text as argument");
4774 puts_filtered ("sending: ");
4775 print_packet (args);
4776 puts_filtered ("\n");
4779 getpkt (buf, PBUFSIZ, 0);
4780 puts_filtered ("received: ");
4782 puts_filtered ("\n");
4786 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------------- */
4788 static void display_thread_info (struct gdb_ext_thread_info *info);
4790 static void threadset_test_cmd (char *cmd, int tty);
4792 static void threadalive_test (char *cmd, int tty);
4794 static void threadlist_test_cmd (char *cmd, int tty);
4796 int get_and_display_threadinfo (threadref * ref);
4798 static void threadinfo_test_cmd (char *cmd, int tty);
4800 static int thread_display_step (threadref * ref, void *context);
4802 static void threadlist_update_test_cmd (char *cmd, int tty);
4804 static void init_remote_threadtests (void);
4806 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid */
4809 threadset_test_cmd (char *cmd, int tty)
4811 int sample_thread = SAMPLE_THREAD;
4813 printf_filtered ("Remote threadset test\n");
4814 set_thread (sample_thread, 1);
4819 threadalive_test (char *cmd, int tty)
4821 int sample_thread = SAMPLE_THREAD;
4823 if (remote_thread_alive (sample_thread))
4824 printf_filtered ("PASS: Thread alive test\n");
4826 printf_filtered ("FAIL: Thread alive test\n");
4829 void output_threadid (char *title, threadref * ref);
4832 output_threadid (char *title, threadref *ref)
4836 pack_threadid (&hexid[0], ref); /* Convert threead id into hex */
4838 printf_filtered ("%s %s\n", title, (&hexid[0]));
4842 threadlist_test_cmd (char *cmd, int tty)
4845 threadref nextthread;
4846 int done, result_count;
4847 threadref threadlist[3];
4849 printf_filtered ("Remote Threadlist test\n");
4850 if (!remote_get_threadlist (startflag, &nextthread, 3, &done,
4851 &result_count, &threadlist[0]))
4852 printf_filtered ("FAIL: threadlist test\n");
4855 threadref *scan = threadlist;
4856 threadref *limit = scan + result_count;
4858 while (scan < limit)
4859 output_threadid (" thread ", scan++);
4864 display_thread_info (struct gdb_ext_thread_info *info)
4866 output_threadid ("Threadid: ", &info->threadid);
4867 printf_filtered ("Name: %s\n ", info->shortname);
4868 printf_filtered ("State: %s\n", info->display);
4869 printf_filtered ("other: %s\n\n", info->more_display);
4873 get_and_display_threadinfo (threadref *ref)
4877 struct gdb_ext_thread_info threadinfo;
4879 set = TAG_THREADID | TAG_EXISTS | TAG_THREADNAME
4880 | TAG_MOREDISPLAY | TAG_DISPLAY;
4881 if (0 != (result = remote_get_threadinfo (ref, set, &threadinfo)))
4882 display_thread_info (&threadinfo);
4887 threadinfo_test_cmd (char *cmd, int tty)
4889 int athread = SAMPLE_THREAD;
4893 int_to_threadref (&thread, athread);
4894 printf_filtered ("Remote Threadinfo test\n");
4895 if (!get_and_display_threadinfo (&thread))
4896 printf_filtered ("FAIL cannot get thread info\n");
4900 thread_display_step (threadref *ref, void *context)
4902 /* output_threadid(" threadstep ",ref); *//* simple test */
4903 return get_and_display_threadinfo (ref);
4907 threadlist_update_test_cmd (char *cmd, int tty)
4909 printf_filtered ("Remote Threadlist update test\n");
4910 remote_threadlist_iterator (thread_display_step, 0, CRAZY_MAX_THREADS);
4914 init_remote_threadtests (void)
4916 add_com ("tlist", class_obscure, threadlist_test_cmd,
4917 "Fetch and print the remote list of thread identifiers, one pkt only");
4918 add_com ("tinfo", class_obscure, threadinfo_test_cmd,
4919 "Fetch and display info about one thread");
4920 add_com ("tset", class_obscure, threadset_test_cmd,
4921 "Test setting to a different thread");
4922 add_com ("tupd", class_obscure, threadlist_update_test_cmd,
4923 "Iterate through updating all remote thread info");
4924 add_com ("talive", class_obscure, threadalive_test,
4925 " Remote thread alive test ");
4931 init_remote_ops (void)
4933 remote_ops.to_shortname = "remote";
4934 remote_ops.to_longname = "Remote serial target in gdb-specific protocol";
4936 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
4937 Specify the serial device it is connected to\n\
4938 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
4939 remote_ops.to_open = remote_open;
4940 remote_ops.to_close = remote_close;
4941 remote_ops.to_detach = remote_detach;
4942 remote_ops.to_resume = remote_resume;
4943 remote_ops.to_wait = remote_wait;
4944 remote_ops.to_fetch_registers = remote_fetch_registers;
4945 remote_ops.to_store_registers = remote_store_registers;
4946 remote_ops.to_prepare_to_store = remote_prepare_to_store;
4947 remote_ops.to_xfer_memory = remote_xfer_memory;
4948 remote_ops.to_files_info = remote_files_info;
4949 remote_ops.to_insert_breakpoint = remote_insert_breakpoint;
4950 remote_ops.to_remove_breakpoint = remote_remove_breakpoint;
4951 remote_ops.to_kill = remote_kill;
4952 remote_ops.to_load = generic_load;
4953 remote_ops.to_mourn_inferior = remote_mourn;
4954 remote_ops.to_thread_alive = remote_thread_alive;
4955 remote_ops.to_find_new_threads = remote_threads_info;
4956 remote_ops.to_extra_thread_info = remote_threads_extra_info;
4957 remote_ops.to_stop = remote_stop;
4958 remote_ops.to_query = remote_query;
4959 remote_ops.to_rcmd = remote_rcmd;
4960 remote_ops.to_stratum = process_stratum;
4961 remote_ops.to_has_all_memory = 1;
4962 remote_ops.to_has_memory = 1;
4963 remote_ops.to_has_stack = 1;
4964 remote_ops.to_has_registers = 1;
4965 remote_ops.to_has_execution = 1;
4966 remote_ops.to_has_thread_control = tc_schedlock; /* can lock scheduler */
4967 remote_ops.to_magic = OPS_MAGIC;
4970 /* Set up the extended remote vector by making a copy of the standard
4971 remote vector and adding to it. */
4974 init_extended_remote_ops (void)
4976 extended_remote_ops = remote_ops;
4978 extended_remote_ops.to_shortname = "extended-remote";
4979 extended_remote_ops.to_longname =
4980 "Extended remote serial target in gdb-specific protocol";
4981 extended_remote_ops.to_doc =
4982 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
4983 Specify the serial device it is connected to (e.g. /dev/ttya).",
4984 extended_remote_ops.to_open = extended_remote_open;
4985 extended_remote_ops.to_create_inferior = extended_remote_create_inferior;
4986 extended_remote_ops.to_mourn_inferior = extended_remote_mourn;
4990 * Command: info remote-process
4992 * This implements Cisco's version of the "info proc" command.
4994 * This query allows the target stub to return an arbitrary string
4995 * (or strings) giving arbitrary information about the target process.
4996 * This is optional; the target stub isn't required to implement it.
4998 * Syntax: qfProcessInfo request first string
4999 * qsProcessInfo request subsequent string
5000 * reply: 'O'<hex-encoded-string>
5001 * 'l' last reply (empty)
5005 remote_info_process (char *args, int from_tty)
5007 char *buf = alloca (PBUFSIZ);
5009 if (remote_desc == 0)
5010 error ("Command can only be used when connected to the remote target.");
5012 putpkt ("qfProcessInfo");
5013 getpkt (buf, PBUFSIZ, 0);
5015 return; /* Silently: target does not support this feature. */
5018 error ("info proc: target error.");
5020 while (buf[0] == 'O') /* Capitol-O packet */
5022 remote_console_output (&buf[1]);
5023 putpkt ("qsProcessInfo");
5024 getpkt (buf, PBUFSIZ, 0);
5033 remote_cisco_open (char *name, int from_tty)
5037 "To open a remote debug connection, you need to specify what \n\
5038 device is attached to the remote system (e.g. host:port).");
5040 /* See FIXME above */
5041 wait_forever_enabled_p = 1;
5043 target_preopen (from_tty);
5045 unpush_target (&remote_cisco_ops);
5047 remote_desc = SERIAL_OPEN (name);
5049 perror_with_name (name);
5052 * If a baud rate was specified on the gdb command line it will
5053 * be greater than the initial value of -1. If it is, use it otherwise
5057 baud_rate = (baud_rate > 0) ? baud_rate : 9600;
5058 if (SERIAL_SETBAUDRATE (remote_desc, baud_rate))
5060 SERIAL_CLOSE (remote_desc);
5061 perror_with_name (name);
5064 SERIAL_RAW (remote_desc);
5066 /* If there is something sitting in the buffer we might take it as a
5067 response to a command, which would be bad. */
5068 SERIAL_FLUSH_INPUT (remote_desc);
5072 puts_filtered ("Remote debugging using ");
5073 puts_filtered (name);
5074 puts_filtered ("\n");
5077 remote_cisco_mode = 1;
5079 push_target (&remote_cisco_ops); /* Switch to using cisco target now */
5081 init_all_packet_configs ();
5083 general_thread = -2;
5084 continue_thread = -2;
5086 /* Probe for ability to use "ThreadInfo" query, as required. */
5087 use_threadinfo_query = 1;
5088 use_threadextra_query = 1;
5090 /* Without this, some commands which require an active target (such
5091 as kill) won't work. This variable serves (at least) double duty
5092 as both the pid of the target process (if it has such), and as a
5093 flag indicating that a target is active. These functions should
5094 be split out into seperate variables, especially since GDB will
5095 someday have a notion of debugging several processes. */
5096 inferior_pid = MAGIC_NULL_PID;
5098 /* Start the remote connection; if error (0), discard this target. */
5100 if (!catch_errors (remote_start_remote_dummy, (char *) 0,
5101 "Couldn't establish connection to remote target\n",
5110 remote_cisco_close (int quitting)
5112 remote_cisco_mode = 0;
5113 remote_close (quitting);
5117 remote_cisco_mourn (void)
5119 remote_mourn_1 (&remote_cisco_ops);
5131 /* shared between readsocket() and readtty() */
5132 static char *tty_input;
5134 static int escape_count;
5135 static int echo_check;
5136 extern int quit_flag;
5143 /* Loop until the socket doesn't have any more data */
5145 while ((data = readchar (0)) >= 0)
5147 /* Check for the escape sequence */
5150 /* If this is the fourth escape, get out */
5151 if (++escape_count == 4)
5156 { /* This is a '|', but not the fourth in a row.
5157 Continue without echoing it. If it isn't actually
5158 one of four in a row, it'll be echoed later. */
5165 /* Ensure any pending '|'s are flushed. */
5167 for (; escape_count > 0; escape_count--)
5171 if (data == '\r') /* If this is a return character, */
5172 continue; /* - just supress it. */
5174 if (echo_check != -1) /* Check for echo of user input. */
5176 if (tty_input[echo_check] == data)
5178 echo_check++; /* Character matched user input: */
5179 continue; /* Continue without echoing it. */
5181 else if ((data == '\n') && (tty_input[echo_check] == '\r'))
5182 { /* End of the line (and of echo checking). */
5183 echo_check = -1; /* No more echo supression */
5184 continue; /* Continue without echoing. */
5187 { /* Failed check for echo of user input.
5188 We now have some suppressed output to flush! */
5191 for (j = 0; j < echo_check; j++)
5192 putchar (tty_input[j]);
5196 putchar (data); /* Default case: output the char. */
5199 if (data == SERIAL_TIMEOUT) /* Timeout returned from readchar. */
5200 return READ_MORE; /* Try to read some more */
5202 return FATAL_ERROR; /* Trouble, bail out */
5210 /* First, read a buffer full from the terminal */
5211 tty_bytecount = read (fileno (stdin), tty_input, sizeof (tty_input) - 1);
5212 if (tty_bytecount == -1)
5214 perror ("readtty: read failed");
5218 /* Remove a quoted newline. */
5219 if (tty_input[tty_bytecount - 1] == '\n' &&
5220 tty_input[tty_bytecount - 2] == '\\') /* line ending in backslash */
5222 tty_input[--tty_bytecount] = 0; /* remove newline */
5223 tty_input[--tty_bytecount] = 0; /* remove backslash */
5226 /* Turn trailing newlines into returns */
5227 if (tty_input[tty_bytecount - 1] == '\n')
5228 tty_input[tty_bytecount - 1] = '\r';
5230 /* If the line consists of a ~, enter debugging mode. */
5231 if ((tty_input[0] == '~') && (tty_bytecount == 2))
5234 /* Make this a zero terminated string and write it out */
5235 tty_input[tty_bytecount] = 0;
5236 if (SERIAL_WRITE (remote_desc, tty_input, tty_bytecount))
5238 perror_with_name ("readtty: write failed");
5248 fd_set input; /* file descriptors for select */
5249 int tablesize; /* max number of FDs for select */
5253 extern int escape_count; /* global shared by readsocket */
5254 extern int echo_check; /* ditto */
5259 tablesize = 8 * sizeof (input);
5263 /* Check for anything from our socket - doesn't block. Note that
5264 this must be done *before* the select as there may be
5265 buffered I/O waiting to be processed. */
5267 if ((status = readsocket ()) == FATAL_ERROR)
5269 error ("Debugging terminated by communications error");
5271 else if (status != READ_MORE)
5276 fflush (stdout); /* Flush output before blocking */
5278 /* Now block on more socket input or TTY input */
5281 FD_SET (fileno (stdin), &input);
5282 FD_SET (DEPRECATED_SERIAL_FD (remote_desc), &input);
5284 status = select (tablesize, &input, 0, 0, 0);
5285 if ((status == -1) && (errno != EINTR))
5287 error ("Communications error on select %d", errno);
5290 /* Handle Control-C typed */
5294 if ((++quit_count) == 2)
5296 if (query ("Interrupt GDB? "))
5298 printf_filtered ("Interrupted by user.\n");
5299 return_to_top_level (RETURN_QUIT);
5306 SERIAL_SEND_BREAK (remote_desc);
5308 SERIAL_WRITE (remote_desc, "\003", 1);
5313 /* Handle console input */
5315 if (FD_ISSET (fileno (stdin), &input))
5319 status = readtty ();
5320 if (status == READ_MORE)
5323 return status; /* telnet session ended */
5329 remote_cisco_wait (int pid, struct target_waitstatus *status)
5331 if (minitelnet () != ENTER_DEBUG)
5333 error ("Debugging session terminated by protocol error");
5336 return remote_wait (pid, status);
5340 init_remote_cisco_ops (void)
5342 remote_cisco_ops.to_shortname = "cisco";
5343 remote_cisco_ops.to_longname = "Remote serial target in cisco-specific protocol";
5344 remote_cisco_ops.to_doc =
5345 "Use a remote machine via TCP, using a cisco-specific protocol.\n\
5346 Specify the serial device it is connected to (e.g. host:2020).";
5347 remote_cisco_ops.to_open = remote_cisco_open;
5348 remote_cisco_ops.to_close = remote_cisco_close;
5349 remote_cisco_ops.to_detach = remote_detach;
5350 remote_cisco_ops.to_resume = remote_resume;
5351 remote_cisco_ops.to_wait = remote_cisco_wait;
5352 remote_cisco_ops.to_fetch_registers = remote_fetch_registers;
5353 remote_cisco_ops.to_store_registers = remote_store_registers;
5354 remote_cisco_ops.to_prepare_to_store = remote_prepare_to_store;
5355 remote_cisco_ops.to_xfer_memory = remote_xfer_memory;
5356 remote_cisco_ops.to_files_info = remote_files_info;
5357 remote_cisco_ops.to_insert_breakpoint = remote_insert_breakpoint;
5358 remote_cisco_ops.to_remove_breakpoint = remote_remove_breakpoint;
5359 remote_cisco_ops.to_kill = remote_kill;
5360 remote_cisco_ops.to_load = generic_load;
5361 remote_cisco_ops.to_mourn_inferior = remote_cisco_mourn;
5362 remote_cisco_ops.to_thread_alive = remote_thread_alive;
5363 remote_cisco_ops.to_find_new_threads = remote_threads_info;
5364 remote_ops.to_extra_thread_info = remote_threads_extra_info;
5365 remote_cisco_ops.to_stratum = process_stratum;
5366 remote_cisco_ops.to_has_all_memory = 1;
5367 remote_cisco_ops.to_has_memory = 1;
5368 remote_cisco_ops.to_has_stack = 1;
5369 remote_cisco_ops.to_has_registers = 1;
5370 remote_cisco_ops.to_has_execution = 1;
5371 remote_cisco_ops.to_magic = OPS_MAGIC;
5375 remote_can_async_p (void)
5377 /* We're async whenever the serial device is. */
5378 return (current_target.to_async_mask_value) && SERIAL_CAN_ASYNC_P (remote_desc);
5382 remote_is_async_p (void)
5384 /* We're async whenever the serial device is. */
5385 return (current_target.to_async_mask_value) && SERIAL_IS_ASYNC_P (remote_desc);
5388 /* Pass the SERIAL event on and up to the client. One day this code
5389 will be able to delay notifying the client of an event until the
5390 point where an entire packet has been received. */
5392 static void (*async_client_callback) (enum inferior_event_type event_type, void *context);
5393 static void *async_client_context;
5394 static serial_event_ftype remote_async_serial_handler;
5397 remote_async_serial_handler (serial_t scb, void *context)
5399 /* Don't propogate error information up to the client. Instead let
5400 the client find out about the error by querying the target. */
5401 async_client_callback (INF_REG_EVENT, async_client_context);
5405 remote_async (void (*callback) (enum inferior_event_type event_type, void *context), void *context)
5407 if (current_target.to_async_mask_value == 0)
5408 internal_error ("Calling remote_async when async is masked");
5410 if (callback != NULL)
5412 SERIAL_ASYNC (remote_desc, remote_async_serial_handler, NULL);
5413 async_client_callback = callback;
5414 async_client_context = context;
5417 SERIAL_ASYNC (remote_desc, NULL, NULL);
5420 /* Target async and target extended-async.
5422 This are temporary targets, until it is all tested. Eventually
5423 async support will be incorporated int the usual 'remote'
5427 init_remote_async_ops (void)
5429 remote_async_ops.to_shortname = "async";
5430 remote_async_ops.to_longname = "Remote serial target in async version of the gdb-specific protocol";
5431 remote_async_ops.to_doc =
5432 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
5433 Specify the serial device it is connected to (e.g. /dev/ttya).";
5434 remote_async_ops.to_open = remote_async_open;
5435 remote_async_ops.to_close = remote_close;
5436 remote_async_ops.to_detach = remote_async_detach;
5437 remote_async_ops.to_resume = remote_async_resume;
5438 remote_async_ops.to_wait = remote_async_wait;
5439 remote_async_ops.to_fetch_registers = remote_fetch_registers;
5440 remote_async_ops.to_store_registers = remote_store_registers;
5441 remote_async_ops.to_prepare_to_store = remote_prepare_to_store;
5442 remote_async_ops.to_xfer_memory = remote_xfer_memory;
5443 remote_async_ops.to_files_info = remote_files_info;
5444 remote_async_ops.to_insert_breakpoint = remote_insert_breakpoint;
5445 remote_async_ops.to_remove_breakpoint = remote_remove_breakpoint;
5446 remote_async_ops.to_terminal_inferior = remote_async_terminal_inferior;
5447 remote_async_ops.to_terminal_ours = remote_async_terminal_ours;
5448 remote_async_ops.to_kill = remote_async_kill;
5449 remote_async_ops.to_load = generic_load;
5450 remote_async_ops.to_mourn_inferior = remote_async_mourn;
5451 remote_async_ops.to_thread_alive = remote_thread_alive;
5452 remote_async_ops.to_find_new_threads = remote_threads_info;
5453 remote_ops.to_extra_thread_info = remote_threads_extra_info;
5454 remote_async_ops.to_stop = remote_stop;
5455 remote_async_ops.to_query = remote_query;
5456 remote_async_ops.to_rcmd = remote_rcmd;
5457 remote_async_ops.to_stratum = process_stratum;
5458 remote_async_ops.to_has_all_memory = 1;
5459 remote_async_ops.to_has_memory = 1;
5460 remote_async_ops.to_has_stack = 1;
5461 remote_async_ops.to_has_registers = 1;
5462 remote_async_ops.to_has_execution = 1;
5463 remote_async_ops.to_has_thread_control = tc_schedlock; /* can lock scheduler */
5464 remote_async_ops.to_can_async_p = remote_can_async_p;
5465 remote_async_ops.to_is_async_p = remote_is_async_p;
5466 remote_async_ops.to_async = remote_async;
5467 remote_async_ops.to_async_mask_value = 1;
5468 remote_async_ops.to_magic = OPS_MAGIC;
5471 /* Set up the async extended remote vector by making a copy of the standard
5472 remote vector and adding to it. */
5475 init_extended_async_remote_ops (void)
5477 extended_async_remote_ops = remote_async_ops;
5479 extended_async_remote_ops.to_shortname = "extended-async";
5480 extended_async_remote_ops.to_longname =
5481 "Extended remote serial target in async gdb-specific protocol";
5482 extended_async_remote_ops.to_doc =
5483 "Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
5484 Specify the serial device it is connected to (e.g. /dev/ttya).",
5485 extended_async_remote_ops.to_open = extended_remote_async_open;
5486 extended_async_remote_ops.to_create_inferior = extended_remote_async_create_inferior;
5487 extended_async_remote_ops.to_mourn_inferior = extended_remote_mourn;
5491 set_remote_cmd (char *args, int from_tty)
5497 show_remote_cmd (char *args, int from_tty)
5499 show_remote_protocol_Z_packet_cmd (args, from_tty);
5500 show_remote_protocol_P_packet_cmd (args, from_tty);
5501 show_remote_protocol_binary_download_cmd (args, from_tty);
5505 build_remote_gdbarch_data (void)
5507 build_remote_packet_sizes ();
5510 tty_input = xmalloc (PBUFSIZ);
5511 remote_address_size = TARGET_PTR_BIT;
5515 _initialize_remote (void)
5517 static struct cmd_list_element *remote_set_cmdlist;
5518 static struct cmd_list_element *remote_show_cmdlist;
5519 struct cmd_list_element *tmpcmd;
5521 /* architecture specific data */
5522 build_remote_gdbarch_data ();
5523 register_gdbarch_swap (&tty_input, sizeof (&tty_input), NULL);
5524 register_remote_packet_sizes ();
5525 register_gdbarch_swap (&remote_address_size,
5526 sizeof (&remote_address_size), NULL);
5527 register_gdbarch_swap (NULL, 0, build_remote_gdbarch_data);
5530 add_target (&remote_ops);
5532 init_extended_remote_ops ();
5533 add_target (&extended_remote_ops);
5535 init_remote_async_ops ();
5536 add_target (&remote_async_ops);
5538 init_extended_async_remote_ops ();
5539 add_target (&extended_async_remote_ops);
5541 init_remote_cisco_ops ();
5542 add_target (&remote_cisco_ops);
5545 init_remote_threadtests ();
5548 /* set/show remote ... */
5550 add_prefix_cmd ("remote", class_maintenance, set_remote_cmd, "\
5551 Remote protocol specific variables\n\
5552 Configure various remote-protocol specific variables such as\n\
5553 the packets being used",
5554 &remote_set_cmdlist, "set remote ",
5555 0/*allow-unknown*/, &setlist);
5556 add_prefix_cmd ("remote", class_maintenance, show_remote_cmd, "\
5557 Remote protocol specific variables\n\
5558 Configure various remote-protocol specific variables such as\n\
5559 the packets being used",
5560 &remote_show_cmdlist, "show remote ",
5561 0/*allow-unknown*/, &showlist);
5563 add_cmd ("compare-sections", class_obscure, compare_sections_command,
5564 "Compare section data on target to the exec file.\n\
5565 Argument is a single section name (default: all loaded sections).",
5568 add_cmd ("packet", class_maintenance, packet_command,
5569 "Send an arbitrary packet to a remote target.\n\
5570 maintenance packet TEXT\n\
5571 If GDB is talking to an inferior via the GDB serial protocol, then\n\
5572 this command sends the string TEXT to the inferior, and displays the\n\
5573 response packet. GDB supplies the initial `$' character, and the\n\
5574 terminating `#' character and checksum.",
5578 (add_set_cmd ("remotebreak", no_class,
5579 var_boolean, (char *) &remote_break,
5580 "Set whether to send break if interrupted.\n",
5584 /* Install commands for configuring memory read/write packets. */
5586 add_cmd ("remotewritesize", no_class, set_memory_write_packet_size,
5587 "Set the maximum number of bytes per memory write packet (deprecated).\n",
5589 add_cmd ("remotewritesize", no_class, show_memory_write_packet_size,
5590 "Show the maximum number of bytes per memory write packet (deprecated).\n",
5592 add_cmd ("memory-write-packet-size", no_class,
5593 set_memory_write_packet_size,
5594 "Set the maximum number of bytes per memory-write packet.\n"
5595 "Specify the number of bytes in a packet or 0 (zero) for the\n"
5596 "default packet size. The actual limit is further reduced\n"
5597 "dependent on the target. Specify ``fixed'' to disable the\n"
5598 "further restriction and ``limit'' to enable that restriction\n",
5599 &remote_set_cmdlist);
5600 add_cmd ("memory-read-packet-size", no_class,
5601 set_memory_read_packet_size,
5602 "Set the maximum number of bytes per memory-read packet.\n"
5603 "Specify the number of bytes in a packet or 0 (zero) for the\n"
5604 "default packet size. The actual limit is further reduced\n"
5605 "dependent on the target. Specify ``fixed'' to disable the\n"
5606 "further restriction and ``limit'' to enable that restriction\n",
5607 &remote_set_cmdlist);
5608 add_cmd ("memory-write-packet-size", no_class,
5609 show_memory_write_packet_size,
5610 "Show the maximum number of bytes per memory-write packet.\n",
5611 &remote_show_cmdlist);
5612 add_cmd ("memory-read-packet-size", no_class,
5613 show_memory_read_packet_size,
5614 "Show the maximum number of bytes per memory-read packet.\n",
5615 &remote_show_cmdlist);
5618 (add_set_cmd ("remoteaddresssize", class_obscure,
5619 var_integer, (char *) &remote_address_size,
5620 "Set the maximum size of the address (in bits) \
5621 in a memory packet.\n",
5625 add_packet_config_cmd (&remote_protocol_binary_download,
5626 "X", "binary-download",
5627 set_remote_protocol_binary_download_cmd,
5628 show_remote_protocol_binary_download_cmd,
5629 &remote_set_cmdlist, &remote_show_cmdlist,
5632 /* XXXX - should ``set remotebinarydownload'' be retained for
5635 (add_set_cmd ("remotebinarydownload", no_class,
5636 var_boolean, (char *) &remote_binary_download,
5637 "Set binary downloads.\n", &setlist),
5641 add_info ("remote-process", remote_info_process,
5642 "Query the remote system for process info.");
5644 add_packet_config_cmd (&remote_protocol_P,
5645 "P", "set-register",
5646 set_remote_protocol_P_packet_cmd,
5647 show_remote_protocol_P_packet_cmd,
5648 &remote_set_cmdlist, &remote_show_cmdlist,
5651 add_packet_config_cmd (&remote_protocol_Z[Z_PACKET_SOFTWARE_BP],
5652 "Z0", "software-breakpoint",
5653 set_remote_protocol_Z_software_bp_packet_cmd,
5654 show_remote_protocol_Z_software_bp_packet_cmd,
5655 &remote_set_cmdlist, &remote_show_cmdlist,
5658 add_packet_config_cmd (&remote_protocol_Z[Z_PACKET_HARDWARE_BP],
5659 "Z1", "hardware-breakpoint",
5660 set_remote_protocol_Z_hardware_bp_packet_cmd,
5661 show_remote_protocol_Z_hardware_bp_packet_cmd,
5662 &remote_set_cmdlist, &remote_show_cmdlist,
5665 add_packet_config_cmd (&remote_protocol_Z[Z_PACKET_WRITE_WP],
5666 "Z2", "write-watchpoint",
5667 set_remote_protocol_Z_write_wp_packet_cmd,
5668 show_remote_protocol_Z_write_wp_packet_cmd,
5669 &remote_set_cmdlist, &remote_show_cmdlist,
5672 add_packet_config_cmd (&remote_protocol_Z[Z_PACKET_READ_WP],
5673 "Z3", "read-watchpoint",
5674 set_remote_protocol_Z_read_wp_packet_cmd,
5675 show_remote_protocol_Z_read_wp_packet_cmd,
5676 &remote_set_cmdlist, &remote_show_cmdlist,
5679 add_packet_config_cmd (&remote_protocol_Z[Z_PACKET_ACCESS_WP],
5680 "Z4", "access-watchpoint",
5681 set_remote_protocol_Z_access_wp_packet_cmd,
5682 show_remote_protocol_Z_access_wp_packet_cmd,
5683 &remote_set_cmdlist, &remote_show_cmdlist,
5686 /* Keep the old ``set remote Z-packet ...'' working. */
5687 tmpcmd = add_set_auto_boolean_cmd ("Z-packet", class_obscure,
5688 &remote_Z_packet_detect,
5690 Set use of remote protocol `Z' packets", &remote_set_cmdlist);
5691 tmpcmd->function.sfunc = set_remote_protocol_Z_packet_cmd;
5692 add_cmd ("Z-packet", class_obscure, show_remote_protocol_Z_packet_cmd,
5693 "Show use of remote protocol `Z' packets ",
5694 &remote_show_cmdlist);